2 * This file is part of the DOM implementation for KDE.
4 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5 * (C) 1999 Antti Koivisto (koivisto@kde.org)
6 * (C) 2000 Stefan Schimanski (1Stein@gmx.de)
7 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
25 #include "HTMLPlugInElement.h"
27 #include "CSSPropertyNames.h"
30 #include "FrameLoader.h"
31 #include "FrameTree.h"
32 #include "HTMLNames.h"
34 #include "RenderWidget.h"
38 #include "kjs_proxy.h"
41 #include <bindings/NP_jsobject.h>
42 #include <bindings/npruntime_impl.h>
43 #include <bindings/runtime_root.h>
49 using KJS::Bindings::RootObject;
53 using namespace HTMLNames;
55 HTMLPlugInElement::HTMLPlugInElement(const QualifiedName& tagName, Document* doc)
56 : HTMLFrameOwnerElement(tagName, doc)
63 HTMLPlugInElement::~HTMLPlugInElement()
67 _NPN_ReleaseObject(m_NPObject);
73 String HTMLPlugInElement::align() const
75 return getAttribute(alignAttr);
78 void HTMLPlugInElement::setAlign(const String& value)
80 setAttribute(alignAttr, value);
83 String HTMLPlugInElement::height() const
85 return getAttribute(heightAttr);
88 void HTMLPlugInElement::setHeight(const String& value)
90 setAttribute(heightAttr, value);
93 String HTMLPlugInElement::name() const
95 return getAttribute(nameAttr);
98 void HTMLPlugInElement::setName(const String& value)
100 setAttribute(nameAttr, value);
103 String HTMLPlugInElement::width() const
105 return getAttribute(widthAttr);
108 void HTMLPlugInElement::setWidth(const String& value)
110 setAttribute(widthAttr, value);
113 bool HTMLPlugInElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
115 if (attrName == widthAttr ||
116 attrName == heightAttr ||
117 attrName == vspaceAttr ||
118 attrName == hspaceAttr) {
123 if (attrName == alignAttr) {
124 result = eReplaced; // Share with <img> since the alignment behavior is the same.
128 return HTMLFrameOwnerElement::mapToEntry(attrName, result);
131 void HTMLPlugInElement::parseMappedAttribute(MappedAttribute* attr)
133 if (attr->name() == widthAttr)
134 addCSSLength(attr, CSS_PROP_WIDTH, attr->value());
135 else if (attr->name() == heightAttr)
136 addCSSLength(attr, CSS_PROP_HEIGHT, attr->value());
137 else if (attr->name() == vspaceAttr) {
138 addCSSLength(attr, CSS_PROP_MARGIN_TOP, attr->value());
139 addCSSLength(attr, CSS_PROP_MARGIN_BOTTOM, attr->value());
140 } else if (attr->name() == hspaceAttr) {
141 addCSSLength(attr, CSS_PROP_MARGIN_LEFT, attr->value());
142 addCSSLength(attr, CSS_PROP_MARGIN_RIGHT, attr->value());
143 } else if (attr->name() == alignAttr)
144 addHTMLAlignment(attr);
146 HTMLFrameOwnerElement::parseMappedAttribute(attr);
149 bool HTMLPlugInElement::checkDTD(const Node* newChild)
151 return newChild->hasTagName(paramTag) || HTMLFrameOwnerElement::checkDTD(newChild);
154 void HTMLPlugInElement::defaultEventHandler(Event* event)
156 RenderObject* r = renderer();
157 if (!r || !r->isWidget())
160 if (Widget* widget = static_cast<RenderWidget*>(r)->widget())
161 widget->handleEvent(event);
166 NPObject* HTMLPlugInElement::createNPObject()
168 Frame* frame = document()->frame();
170 // This shouldn't ever happen, but might as well check anyway.
171 ASSERT_NOT_REACHED();
172 return _NPN_CreateNoScriptObject();
175 Settings* settings = frame->settings();
177 // This shouldn't ever happen, but might as well check anyway.
178 ASSERT_NOT_REACHED();
179 return _NPN_CreateNoScriptObject();
182 // Can't create NPObjects when JavaScript is disabled
183 if (!settings->isJavaScriptEnabled())
184 return _NPN_CreateNoScriptObject();
186 // Create a JSObject bound to this element
188 ExecState *exec = frame->scriptProxy()->globalObject()->globalExec();
189 JSValue* jsElementValue = toJS(exec, this);
190 if (!jsElementValue || !jsElementValue->isObject())
191 return _NPN_CreateNoScriptObject();
193 // Wrap the JSObject in an NPObject
194 RootObject* rootObject = frame->bindingRootObject();
195 return _NPN_CreateScriptObject(0, jsElementValue->getObject(), rootObject);
198 NPObject* HTMLPlugInElement::getNPObject()
201 m_NPObject = createNPObject();
205 #endif /* USE(NPOBJECT) */
207 void HTMLPlugInElement::updateWidgetCallback(Node* n)
209 static_cast<HTMLPlugInElement*>(n)->updateWidget();