~ubuntu-branches/ubuntu/maverick/webkit/maverick

« back to all changes in this revision

Viewing changes to WebCore/bindings/js/kjs_html.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mike Hommey
  • Date: 2007-08-19 15:54:12 UTC
  • Revision ID: james.westby@ubuntu.com-20070819155412-uxxg1h9plpghmtbi
Tags: upstream-0~svn25144
ImportĀ upstreamĀ versionĀ 0~svn25144

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- c-basic-offset: 4 -*-
 
2
/*
 
3
 *  This file is part of the KDE libraries
 
4
 *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
 
5
 *  Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
 
6
 *
 
7
 *  This library is free software; you can redistribute it and/or
 
8
 *  modify it under the terms of the GNU Lesser General Public
 
9
 *  License as published by the Free Software Foundation; either
 
10
 *  version 2 of the License, or (at your option) any later version.
 
11
 *
 
12
 *  This library is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 *  Lesser General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU Lesser General Public
 
18
 *  License along with this library; if not, write to the Free Software
 
19
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
#include "kjs_html.h"
 
24
 
 
25
#include "Frame.h"
 
26
#include "FrameLoader.h"
 
27
#include "JSHTMLElement.h"
 
28
#include "HTMLDocument.h"
 
29
#include "HTMLImageElement.h"
 
30
#include "kjs_proxy.h"
 
31
 
 
32
namespace WebCore {
 
33
 
 
34
using namespace KJS;
 
35
 
 
36
ImageConstructorImp::ImageConstructorImp(ExecState* exec, Document* doc)
 
37
    : m_doc(doc)
 
38
{
 
39
    setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
 
40
}
 
41
 
 
42
JSObject* ImageConstructorImp::construct(ExecState*  exec, const List& list)
 
43
{
 
44
    bool widthSet = false;
 
45
    bool heightSet = false;
 
46
    int width = 0;
 
47
    int height = 0;
 
48
 
 
49
    if (list.size() > 0) {
 
50
        widthSet = true;
 
51
        JSValue* w = list.at(0);
 
52
        width = w->toInt32(exec);
 
53
    }
 
54
 
 
55
    if (list.size() > 1) {
 
56
        heightSet = true;
 
57
        JSValue* h = list.at(1);
 
58
        height = h->toInt32(exec);
 
59
    }
 
60
 
 
61
    HTMLImageElement* image = new HTMLImageElement(m_doc.get());
 
62
    JSObject* result = static_cast<JSObject*>(toJS(exec, image));
 
63
 
 
64
    if (widthSet)
 
65
        image->setWidth(width);
 
66
    if (heightSet)
 
67
        image->setHeight(height);
 
68
 
 
69
    return result;
 
70
}
 
71
 
 
72
// -------------------------------------------------------------------------
 
73
 
 
74
// Runtime object support code for JSHTMLAppletElement, JSHTMLEmbedElement and JSHTMLObjectElement.
 
75
 
 
76
JSValue* runtimeObjectGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
 
77
{
 
78
    JSHTMLElement* thisObj = static_cast<JSHTMLElement*>(slot.slotBase());
 
79
    HTMLElement* element = static_cast<HTMLElement*>(thisObj->impl());
 
80
 
 
81
    return getRuntimeObject(exec, element);
 
82
}
 
83
 
 
84
JSValue* runtimeObjectPropertyGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
 
85
{
 
86
    JSHTMLElement* thisObj = static_cast<JSHTMLElement*>(slot.slotBase());
 
87
    HTMLElement* element = static_cast<HTMLElement*>(thisObj->impl());
 
88
 
 
89
    if (JSValue* runtimeObject = getRuntimeObject(exec, element))
 
90
        return static_cast<JSObject*>(runtimeObject)->get(exec, propertyName);
 
91
    return jsUndefined();
 
92
}
 
93
 
 
94
bool runtimeObjectCustomGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot, WebCore::JSHTMLElement* originalObj, HTMLElement* thisImp)
 
95
{
 
96
    JSValue* runtimeObject = getRuntimeObject(exec, thisImp);
 
97
    if (runtimeObject) {
 
98
        JSObject* imp = static_cast<JSObject*>(runtimeObject);
 
99
        if (imp->hasProperty(exec, propertyName)) {
 
100
            slot.setCustom(originalObj, runtimeObjectPropertyGetter);
 
101
            return true;
 
102
        }
 
103
    }
 
104
 
 
105
    return false;
 
106
}
 
107
 
 
108
bool runtimeObjectCustomPut(ExecState* exec, const Identifier& propertyName, JSValue* value, int /*attr*/, HTMLElement* thisImp)
 
109
{
 
110
    if (JSValue* runtimeObject = getRuntimeObject(exec, thisImp)) {
 
111
        JSObject* imp = static_cast<JSObject*>(runtimeObject);
 
112
        if (imp->canPut(exec, propertyName)) {
 
113
            imp->put(exec, propertyName, value);
 
114
            return true;
 
115
        }
 
116
    }
 
117
 
 
118
    return false;
 
119
}
 
120
 
 
121
bool runtimeObjectImplementsCall(HTMLElement* thisImp)
 
122
{
 
123
    Frame* frame = thisImp->document()->frame();
 
124
    if (!frame)
 
125
        return false;
 
126
    KJSProxy* proxy = frame->scriptProxy();
 
127
    ExecState* exec = proxy->interpreter()->globalExec();
 
128
    if (JSValue* runtimeObject = getRuntimeObject(exec, thisImp))
 
129
        return static_cast<JSObject*>(runtimeObject)->implementsCall();
 
130
 
 
131
    return false;
 
132
}
 
133
 
 
134
JSValue* runtimeObjectCallAsFunction(ExecState* exec, JSObject* thisObj, const List& args, HTMLElement* thisImp)
 
135
{
 
136
    if (JSValue* runtimeObject = getRuntimeObject(exec, thisImp))
 
137
        return static_cast<JSObject*>(runtimeObject)->call(exec, thisObj, args);
 
138
    return jsUndefined();
 
139
}
 
140
 
 
141
} // namespace WebCore