|
1 /** |
|
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
|
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
|
4 * (C) 2000 Stefan Schimanski (1Stein@gmx.de) |
|
5 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. |
|
6 * |
|
7 * This library is free software; you can redistribute it and/or |
|
8 * modify it under the terms of the GNU Library 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 * Library General Public License for more details. |
|
16 * |
|
17 * You should have received a copy of the GNU Library General Public License |
|
18 * along with this library; see the file COPYING.LIB. If not, write to |
|
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
20 * Boston, MA 02110-1301, USA. |
|
21 */ |
|
22 |
|
23 #include "config.h" |
|
24 #include "HTMLPlugInElement.h" |
|
25 |
|
26 #include "Attribute.h" |
|
27 #include "Chrome.h" |
|
28 #include "ChromeClient.h" |
|
29 #include "CSSPropertyNames.h" |
|
30 #include "Document.h" |
|
31 #include "Frame.h" |
|
32 #include "FrameLoader.h" |
|
33 #include "FrameTree.h" |
|
34 #include "HTMLNames.h" |
|
35 #include "Page.h" |
|
36 #include "RenderEmbeddedObject.h" |
|
37 #include "RenderWidget.h" |
|
38 #include "ScriptController.h" |
|
39 #include "Settings.h" |
|
40 #include "Widget.h" |
|
41 |
|
42 #if ENABLE(NETSCAPE_PLUGIN_API) |
|
43 #include "npruntime_impl.h" |
|
44 #endif |
|
45 |
|
46 namespace WebCore { |
|
47 |
|
48 using namespace HTMLNames; |
|
49 |
|
50 HTMLPlugInElement::HTMLPlugInElement(const QualifiedName& tagName, Document* doc) |
|
51 : HTMLFrameOwnerElement(tagName, doc) |
|
52 #if ENABLE(NETSCAPE_PLUGIN_API) |
|
53 , m_NPObject(0) |
|
54 , m_isCapturingMouseEvents(false) |
|
55 #endif |
|
56 { |
|
57 } |
|
58 |
|
59 HTMLPlugInElement::~HTMLPlugInElement() |
|
60 { |
|
61 ASSERT(!m_instance); // cleared in detach() |
|
62 |
|
63 #if ENABLE(NETSCAPE_PLUGIN_API) |
|
64 if (m_NPObject) { |
|
65 _NPN_ReleaseObject(m_NPObject); |
|
66 m_NPObject = 0; |
|
67 } |
|
68 #endif |
|
69 } |
|
70 |
|
71 void HTMLPlugInElement::detach() |
|
72 { |
|
73 m_instance.clear(); |
|
74 |
|
75 if (m_isCapturingMouseEvents) { |
|
76 if (Frame* frame = document()->frame()) |
|
77 frame->eventHandler()->setCapturingMouseEventsNode(0); |
|
78 m_isCapturingMouseEvents = false; |
|
79 } |
|
80 |
|
81 HTMLFrameOwnerElement::detach(); |
|
82 } |
|
83 |
|
84 PassScriptInstance HTMLPlugInElement::getInstance() const |
|
85 { |
|
86 Frame* frame = document()->frame(); |
|
87 if (!frame) |
|
88 return 0; |
|
89 |
|
90 // If the host dynamically turns off JavaScript (or Java) we will still return |
|
91 // the cached allocated Bindings::Instance. Not supporting this edge-case is OK. |
|
92 if (m_instance) |
|
93 return m_instance; |
|
94 |
|
95 RenderWidget* renderWidget = renderWidgetForJSBindings(); |
|
96 if (renderWidget && renderWidget->widget()) |
|
97 m_instance = frame->script()->createScriptInstanceForWidget(renderWidget->widget()); |
|
98 |
|
99 return m_instance; |
|
100 } |
|
101 |
|
102 bool HTMLPlugInElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const |
|
103 { |
|
104 if (attrName == widthAttr || |
|
105 attrName == heightAttr || |
|
106 attrName == vspaceAttr || |
|
107 attrName == hspaceAttr) { |
|
108 result = eUniversal; |
|
109 return false; |
|
110 } |
|
111 |
|
112 if (attrName == alignAttr) { |
|
113 result = eReplaced; // Share with <img> since the alignment behavior is the same. |
|
114 return false; |
|
115 } |
|
116 |
|
117 return HTMLFrameOwnerElement::mapToEntry(attrName, result); |
|
118 } |
|
119 |
|
120 void HTMLPlugInElement::parseMappedAttribute(Attribute* attr) |
|
121 { |
|
122 if (attr->name() == widthAttr) |
|
123 addCSSLength(attr, CSSPropertyWidth, attr->value()); |
|
124 else if (attr->name() == heightAttr) |
|
125 addCSSLength(attr, CSSPropertyHeight, attr->value()); |
|
126 else if (attr->name() == vspaceAttr) { |
|
127 addCSSLength(attr, CSSPropertyMarginTop, attr->value()); |
|
128 addCSSLength(attr, CSSPropertyMarginBottom, attr->value()); |
|
129 } else if (attr->name() == hspaceAttr) { |
|
130 addCSSLength(attr, CSSPropertyMarginLeft, attr->value()); |
|
131 addCSSLength(attr, CSSPropertyMarginRight, attr->value()); |
|
132 } else if (attr->name() == alignAttr) |
|
133 addHTMLAlignment(attr); |
|
134 else |
|
135 HTMLFrameOwnerElement::parseMappedAttribute(attr); |
|
136 } |
|
137 |
|
138 bool HTMLPlugInElement::checkDTD(const Node* newChild) |
|
139 { |
|
140 return newChild->hasTagName(paramTag) || HTMLFrameOwnerElement::checkDTD(newChild); |
|
141 } |
|
142 |
|
143 void HTMLPlugInElement::defaultEventHandler(Event* event) |
|
144 { |
|
145 // Firefox seems to use a fake event listener to dispatch events to plug-in (tested with mouse events only). |
|
146 // This is observable via different order of events - in Firefox, event listeners specified in HTML attributes fires first, then an event |
|
147 // gets dispatched to plug-in, and only then other event listeners fire. Hopefully, this difference does not matter in practice. |
|
148 |
|
149 // FIXME: Mouse down and scroll events are passed down to plug-in via custom code in EventHandler; these code paths should be united. |
|
150 |
|
151 RenderObject* r = renderer(); |
|
152 if (r && r->isEmbeddedObject() && toRenderEmbeddedObject(r)->showsMissingPluginIndicator()) { |
|
153 toRenderEmbeddedObject(r)->handleMissingPluginIndicatorEvent(event); |
|
154 return; |
|
155 } |
|
156 |
|
157 if (!r || !r->isWidget()) |
|
158 return; |
|
159 Widget* widget = toRenderWidget(r)->widget(); |
|
160 if (!widget) |
|
161 return; |
|
162 widget->handleEvent(event); |
|
163 } |
|
164 |
|
165 #if ENABLE(NETSCAPE_PLUGIN_API) |
|
166 |
|
167 NPObject* HTMLPlugInElement::getNPObject() |
|
168 { |
|
169 ASSERT(document()->frame()); |
|
170 if (!m_NPObject) |
|
171 m_NPObject = document()->frame()->script()->createScriptObjectForPluginElement(this); |
|
172 return m_NPObject; |
|
173 } |
|
174 |
|
175 #endif /* ENABLE(NETSCAPE_PLUGIN_API) */ |
|
176 |
|
177 void HTMLPlugInElement::updateWidgetCallback(Node* n) |
|
178 { |
|
179 static_cast<HTMLPlugInElement*>(n)->updateWidget(); |
|
180 } |
|
181 |
|
182 } |