author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:17:34 +0300 | |
changeset 19 | fcece45ef507 |
parent 18 | 2f34d5167611 |
child 22 | 79de32ba3296 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) |
|
3 |
||
4 |
This library is free software; you can redistribute it and/or |
|
5 |
modify it under the terms of the GNU Library General Public |
|
6 |
License as published by the Free Software Foundation; either |
|
7 |
version 2 of the License, or (at your option) any later version. |
|
8 |
||
9 |
This library is distributed in the hope that it will be useful, |
|
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 |
Library General Public License for more details. |
|
13 |
||
14 |
You should have received a copy of the GNU Library General Public License |
|
15 |
along with this library; see the file COPYING.LIB. If not, write to |
|
16 |
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
17 |
Boston, MA 02110-1301, USA. |
|
18 |
*/ |
|
19 |
#include "config.h" |
|
20 |
#include "PluginView.h" |
|
21 |
||
22 |
#include "Document.h" |
|
23 |
#include "DocumentLoader.h" |
|
24 |
#include "Element.h" |
|
25 |
#include "FocusController.h" |
|
26 |
#include "Frame.h" |
|
27 |
#include "FrameLoadRequest.h" |
|
28 |
#include "FrameLoader.h" |
|
29 |
#include "FrameTree.h" |
|
30 |
#include "FrameView.h" |
|
31 |
#include "GraphicsContext.h" |
|
32 |
#include "HTMLNames.h" |
|
33 |
#include "HTMLPlugInElement.h" |
|
34 |
#include "Image.h" |
|
35 |
#include "JSDOMBinding.h" |
|
36 |
#include "KeyboardEvent.h" |
|
37 |
#include "MouseEvent.h" |
|
38 |
#include "NotImplemented.h" |
|
39 |
#include "npfunctions.h" |
|
40 |
#include "npinterface.h" |
|
41 |
#include "Page.h" |
|
42 |
#include "PlatformKeyboardEvent.h" |
|
43 |
#include "PlatformMouseEvent.h" |
|
44 |
#include "PluginContainerSymbian.h" |
|
45 |
#include "PluginDebug.h" |
|
46 |
#include "PluginMainThreadScheduler.h" |
|
47 |
#include "PluginPackage.h" |
|
48 |
#include "RenderLayer.h" |
|
49 |
#include "ScriptController.h" |
|
50 |
#include "Settings.h" |
|
51 |
#include "npruntime_impl.h" |
|
52 |
#include "runtime.h" |
|
53 |
#include "runtime_root.h" |
|
54 |
#include "QWebPageClient.h" |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
55 |
#include "qgraphicswebview.h" |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
56 |
#include <QGraphicsProxyWidget> |
0 | 57 |
#include <QKeyEvent> |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
58 |
#include <QPixmap> |
0 | 59 |
#include <QRegion> |
60 |
#include <QVector> |
|
61 |
#include <QWidget> |
|
62 |
#include <runtime/JSLock.h> |
|
63 |
#include <runtime/JSValue.h> |
|
64 |
||
65 |
using JSC::ExecState; |
|
66 |
using JSC::Interpreter; |
|
67 |
using JSC::JSLock; |
|
68 |
using JSC::JSObject; |
|
69 |
using JSC::UString; |
|
70 |
||
71 |
using namespace std; |
|
72 |
||
73 |
using namespace WTF; |
|
74 |
||
75 |
namespace WebCore { |
|
76 |
||
77 |
using namespace HTMLNames; |
|
78 |
||
79 |
void PluginView::updatePluginWidget() |
|
80 |
{ |
|
81 |
if (!parent()) |
|
82 |
return; |
|
83 |
ASSERT(parent()->isFrameView()); |
|
84 |
FrameView* frameView = static_cast<FrameView*>(parent()); |
|
85 |
IntRect oldWindowRect = m_windowRect; |
|
86 |
IntRect oldClipRect = m_clipRect; |
|
87 |
||
88 |
m_windowRect = IntRect(frameView->contentsToWindow(frameRect().location()), frameRect().size()); |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
89 |
|
0 | 90 |
m_clipRect = windowClipRect(); |
91 |
m_clipRect.move(-m_windowRect.x(), -m_windowRect.y()); |
|
92 |
if (m_windowRect == oldWindowRect && m_clipRect == oldClipRect) |
|
93 |
return; |
|
94 |
||
95 |
// in order to move/resize the plugin window at the same time as the rest of frame |
|
96 |
// during e.g. scrolling, we set the mask and geometry in the paint() function, but |
|
97 |
// as paint() isn't called when the plugin window is outside the frame which can |
|
98 |
// be caused by a scroll, we need to move/resize immediately. |
|
99 |
if (!m_windowRect.intersects(frameView->frameRect())) |
|
100 |
setNPWindowIfNeeded(); |
|
101 |
} |
|
102 |
||
103 |
void PluginView::setFocus() |
|
104 |
{ |
|
105 |
if (platformPluginWidget()) |
|
106 |
platformPluginWidget()->setFocus(Qt::OtherFocusReason); |
|
107 |
else |
|
108 |
Widget::setFocus(); |
|
109 |
} |
|
110 |
||
111 |
void PluginView::show() |
|
112 |
{ |
|
113 |
setSelfVisible(true); |
|
114 |
||
115 |
if (isParentVisible() && platformPluginWidget()) |
|
116 |
platformPluginWidget()->setVisible(true); |
|
117 |
} |
|
118 |
||
119 |
void PluginView::hide() |
|
120 |
{ |
|
121 |
setSelfVisible(false); |
|
122 |
||
123 |
if (isParentVisible() && platformPluginWidget()) |
|
124 |
platformPluginWidget()->setVisible(false); |
|
125 |
} |
|
126 |
||
127 |
void PluginView::paint(GraphicsContext* context, const IntRect& rect) |
|
128 |
{ |
|
129 |
if (!m_isStarted) { |
|
130 |
paintMissingPluginIcon(context, rect); |
|
131 |
return; |
|
132 |
} |
|
133 |
||
134 |
if (context->paintingDisabled()) |
|
135 |
return; |
|
136 |
m_npWindow.ws_info = (void*)(context->platformContext()); |
|
137 |
setNPWindowIfNeeded(); |
|
138 |
||
139 |
if (m_isWindowed && platformPluginWidget()) |
|
140 |
static_cast<PluginContainerSymbian*>(platformPluginWidget())->adjustGeometry(); |
|
141 |
||
142 |
if (m_isWindowed) |
|
143 |
return; |
|
144 |
||
145 |
context->save(); |
|
146 |
IntRect clipRect(rect); |
|
147 |
clipRect.intersect(frameRect()); |
|
148 |
context->clip(clipRect); |
|
149 |
context->translate(frameRect().location().x(), frameRect().location().y()); |
|
150 |
||
151 |
QPaintEvent ev(rect); |
|
152 |
QEvent& npEvent = ev; |
|
153 |
dispatchNPEvent(npEvent); |
|
154 |
||
155 |
context->restore(); |
|
156 |
} |
|
157 |
||
158 |
// TODO: Unify across ports. |
|
159 |
bool PluginView::dispatchNPEvent(NPEvent& event) |
|
160 |
{ |
|
161 |
if (!m_plugin->pluginFuncs()->event) |
|
162 |
return false; |
|
163 |
||
164 |
PluginView::setCurrentPluginView(this); |
|
165 |
JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly); |
|
166 |
||
167 |
setCallingPlugin(true); |
|
168 |
bool accepted = m_plugin->pluginFuncs()->event(m_instance, &event); |
|
169 |
setCallingPlugin(false); |
|
170 |
PluginView::setCurrentPluginView(0); |
|
171 |
||
172 |
return accepted; |
|
173 |
} |
|
174 |
||
175 |
void PluginView::handleKeyboardEvent(KeyboardEvent* event) |
|
176 |
{ |
|
177 |
if (m_isWindowed) |
|
178 |
return; |
|
179 |
||
180 |
QEvent& npEvent = *(event->keyEvent()->qtEvent()); |
|
181 |
if (!dispatchNPEvent(npEvent)) |
|
182 |
event->setDefaultHandled(); |
|
183 |
} |
|
184 |
||
185 |
void PluginView::handleMouseEvent(MouseEvent* event) |
|
186 |
{ |
|
187 |
if (m_isWindowed) |
|
188 |
return; |
|
189 |
||
190 |
if (event->type() == eventNames().mousedownEvent) { |
|
191 |
// Give focus to the plugin on click |
|
192 |
if (Page* page = m_parentFrame->page()) |
|
193 |
page->focusController()->setActive(true); |
|
194 |
||
195 |
focusPluginElement(); |
|
196 |
} |
|
197 |
||
198 |
QEvent::Type type; |
|
199 |
if (event->type() == eventNames().mousedownEvent) |
|
200 |
type = QEvent::MouseButtonPress; |
|
201 |
else if (event->type() == eventNames().mousemoveEvent) |
|
202 |
type = QEvent::MouseMove; |
|
203 |
else if (event->type() == eventNames().mouseupEvent) |
|
204 |
type = QEvent::MouseButtonRelease; |
|
205 |
else |
|
206 |
return; |
|
207 |
||
208 |
QPoint position(event->offsetX(), event->offsetY()); |
|
209 |
Qt::MouseButton button; |
|
210 |
switch (event->which()) { |
|
211 |
case 1: |
|
212 |
button = Qt::LeftButton; |
|
213 |
break; |
|
214 |
case 2: |
|
215 |
button = Qt::MidButton; |
|
216 |
break; |
|
217 |
case 3: |
|
218 |
button = Qt::RightButton; |
|
219 |
break; |
|
220 |
default: |
|
221 |
button = Qt::NoButton; |
|
222 |
} |
|
223 |
Qt::KeyboardModifiers modifiers = 0; |
|
224 |
if (event->ctrlKey()) |
|
225 |
modifiers |= Qt::ControlModifier; |
|
226 |
if (event->altKey()) |
|
227 |
modifiers |= Qt::AltModifier; |
|
228 |
if (event->shiftKey()) |
|
229 |
modifiers |= Qt::ShiftModifier; |
|
230 |
if (event->metaKey()) |
|
231 |
modifiers |= Qt::MetaModifier; |
|
232 |
QMouseEvent mouseEvent(type, position, button, button, modifiers); |
|
233 |
QEvent& npEvent = mouseEvent; |
|
234 |
if (!dispatchNPEvent(npEvent)) |
|
235 |
event->setDefaultHandled(); |
|
236 |
} |
|
237 |
||
238 |
void PluginView::setParent(ScrollView* parent) |
|
239 |
{ |
|
240 |
Widget::setParent(parent); |
|
241 |
||
242 |
if (parent) |
|
243 |
init(); |
|
244 |
} |
|
245 |
||
246 |
void PluginView::setNPWindowRect(const IntRect&) |
|
247 |
{ |
|
248 |
if (!m_isWindowed) |
|
249 |
setNPWindowIfNeeded(); |
|
250 |
} |
|
251 |
||
252 |
void PluginView::setNPWindowIfNeeded() |
|
253 |
{ |
|
254 |
if (!m_isStarted || !parent() || !m_plugin->pluginFuncs()->setwindow) |
|
255 |
return; |
|
256 |
if (m_isWindowed) { |
|
257 |
ASSERT(platformPluginWidget()); |
|
258 |
platformPluginWidget()->setGeometry(m_windowRect); |
|
259 |
// if setMask is set with an empty QRegion, no clipping will |
|
260 |
// be performed, so in that case we hide the plugin view |
|
261 |
platformPluginWidget()->setVisible(!m_clipRect.isEmpty()); |
|
262 |
platformPluginWidget()->setMask(QRegion(m_clipRect)); |
|
263 |
||
264 |
m_npWindow.x = m_windowRect.x(); |
|
265 |
m_npWindow.y = m_windowRect.y(); |
|
266 |
||
267 |
m_npWindow.clipRect.left = m_clipRect.x(); |
|
268 |
m_npWindow.clipRect.top = m_clipRect.y(); |
|
269 |
m_npWindow.clipRect.right = m_clipRect.width(); |
|
270 |
m_npWindow.clipRect.bottom = m_clipRect.height(); |
|
271 |
||
272 |
} else { |
|
273 |
// always call this method before painting. |
|
274 |
m_npWindow.x = 0; |
|
275 |
m_npWindow.y = 0; |
|
276 |
||
277 |
m_npWindow.clipRect.left = 0; |
|
278 |
m_npWindow.clipRect.top = 0; |
|
279 |
m_npWindow.clipRect.right = m_windowRect.width(); |
|
280 |
m_npWindow.clipRect.bottom = m_windowRect.height(); |
|
281 |
m_npWindow.window = 0; |
|
282 |
} |
|
283 |
||
284 |
m_npWindow.width = m_windowRect.width(); |
|
285 |
m_npWindow.height = m_windowRect.height(); |
|
286 |
||
287 |
PluginView::setCurrentPluginView(this); |
|
288 |
JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly); |
|
289 |
setCallingPlugin(true); |
|
290 |
m_plugin->pluginFuncs()->setwindow(m_instance, &m_npWindow); |
|
291 |
setCallingPlugin(false); |
|
292 |
PluginView::setCurrentPluginView(0); |
|
293 |
} |
|
294 |
||
295 |
void PluginView::setParentVisible(bool visible) |
|
296 |
{ |
|
297 |
if (isParentVisible() == visible) |
|
298 |
return; |
|
299 |
||
300 |
Widget::setParentVisible(visible); |
|
301 |
||
302 |
if (isSelfVisible() && platformPluginWidget()) |
|
303 |
platformPluginWidget()->setVisible(visible); |
|
304 |
} |
|
305 |
||
306 |
NPError PluginView::handlePostReadFile(Vector<char>& buffer, uint32 len, const char* buf) |
|
307 |
{ |
|
308 |
notImplemented(); |
|
309 |
return NPERR_NO_ERROR; |
|
310 |
} |
|
311 |
||
312 |
NPError PluginView::getValueStatic(NPNVariable variable, void* value) |
|
313 |
{ |
|
314 |
LOG(Plugins, "PluginView::getValueStatic(%s)", prettyNameForNPNVariable(variable).data()); |
|
315 |
||
316 |
switch (variable) { |
|
317 |
case NPNVjavascriptEnabledBool: |
|
318 |
*static_cast<NPBool*>(value) = true; |
|
319 |
return NPERR_NO_ERROR; |
|
320 |
||
321 |
case NPNVSupportsWindowless: |
|
322 |
*static_cast<NPBool*>(value) = true; |
|
323 |
return NPERR_NO_ERROR; |
|
324 |
||
325 |
default: |
|
326 |
return NPERR_GENERIC_ERROR; |
|
327 |
} |
|
328 |
} |
|
329 |
||
330 |
NPError PluginView::getValue(NPNVariable variable, void* value) |
|
331 |
{ |
|
332 |
LOG(Plugins, "PluginView::getValue(%s)", prettyNameForNPNVariable(variable).data()); |
|
333 |
||
334 |
switch (variable) { |
|
335 |
case NPNVWindowNPObject: { |
|
336 |
if (m_isJavaScriptPaused) |
|
337 |
return NPERR_GENERIC_ERROR; |
|
338 |
||
339 |
NPObject* windowScriptObject = m_parentFrame->script()->windowScriptNPObject(); |
|
340 |
||
341 |
// Return value is expected to be retained, as described here: <http://www.mozilla.org/projects/plugin/npruntime.html> |
|
342 |
if (windowScriptObject) |
|
343 |
_NPN_RetainObject(windowScriptObject); |
|
344 |
||
345 |
void** v = (void**)value; |
|
346 |
*v = windowScriptObject; |
|
347 |
||
348 |
return NPERR_NO_ERROR; |
|
349 |
} |
|
350 |
||
351 |
case NPNVPluginElementNPObject: { |
|
352 |
if (m_isJavaScriptPaused) |
|
353 |
return NPERR_GENERIC_ERROR; |
|
354 |
||
355 |
NPObject* pluginScriptObject = 0; |
|
356 |
||
357 |
if (m_element->hasTagName(appletTag) || m_element->hasTagName(embedTag) || m_element->hasTagName(objectTag)) |
|
358 |
pluginScriptObject = static_cast<HTMLPlugInElement*>(m_element)->getNPObject(); |
|
359 |
||
360 |
// Return value is expected to be retained, as described here: <http://www.mozilla.org/projects/plugin/npruntime.html> |
|
361 |
if (pluginScriptObject) |
|
362 |
_NPN_RetainObject(pluginScriptObject); |
|
363 |
||
364 |
void** v = (void**)value; |
|
365 |
*v = pluginScriptObject; |
|
366 |
||
367 |
return NPERR_NO_ERROR; |
|
368 |
} |
|
369 |
default: |
|
370 |
return getValueStatic(variable, value); |
|
371 |
} |
|
372 |
} |
|
373 |
||
374 |
void PluginView::invalidateRect(const IntRect& rect) |
|
375 |
{ |
|
376 |
if (m_isWindowed) { |
|
377 |
platformWidget()->update(rect); |
|
378 |
return; |
|
379 |
} |
|
380 |
||
381 |
invalidateWindowlessPluginRect(rect); |
|
382 |
} |
|
383 |
||
384 |
void PluginView::invalidateRect(NPRect* rect) |
|
385 |
{ |
|
386 |
if (m_isWindowed) |
|
387 |
return; |
|
388 |
if (!rect) { |
|
389 |
invalidate(); |
|
390 |
return; |
|
391 |
} |
|
392 |
IntRect r(rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top); |
|
393 |
m_invalidRects.append(r); |
|
394 |
if (!m_invalidateTimer.isActive()) |
|
395 |
m_invalidateTimer.startOneShot(0.001); |
|
396 |
} |
|
397 |
||
398 |
void PluginView::invalidateRegion(NPRegion region) |
|
399 |
{ |
|
400 |
if (m_isWindowed) |
|
401 |
return; |
|
402 |
||
403 |
if (!region) |
|
404 |
return; |
|
405 |
||
406 |
QVector<QRect> rects = region->rects(); |
|
407 |
for (int i = 0; i < rects.size(); ++i) { |
|
408 |
const QRect& qRect = rects.at(i); |
|
409 |
m_invalidRects.append(qRect); |
|
410 |
if (!m_invalidateTimer.isActive()) |
|
411 |
m_invalidateTimer.startOneShot(0.001); |
|
412 |
} |
|
413 |
} |
|
414 |
||
415 |
void PluginView::forceRedraw() |
|
416 |
{ |
|
417 |
if (m_isWindowed) |
|
418 |
return; |
|
419 |
invalidate(); |
|
420 |
} |
|
421 |
||
422 |
bool PluginView::platformStart() |
|
423 |
{ |
|
424 |
ASSERT(m_isStarted); |
|
425 |
ASSERT(m_status == PluginStatusLoadedSuccessfully); |
|
426 |
||
427 |
show(); |
|
428 |
||
429 |
if (m_isWindowed) { |
|
430 |
QWebPageClient* client = m_parentFrame->view()->hostWindow()->platformPageClient(); |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
431 |
QGraphicsProxyWidget* proxy = 0; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
432 |
if (QGraphicsWebView *webView = qobject_cast<QGraphicsWebView*>(client->pluginParent())) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
433 |
proxy = new QGraphicsProxyWidget(webView); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
434 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
435 |
PluginContainerSymbian* container = new PluginContainerSymbian(this, proxy ? 0 : client->ownerWidget(), proxy); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
436 |
setPlatformWidget(container); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
437 |
if (proxy) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
438 |
proxy->setWidget(container); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
439 |
|
0 | 440 |
m_npWindow.type = NPWindowTypeWindow; |
441 |
m_npWindow.window = (void*)platformPluginWidget(); |
|
442 |
||
443 |
} else { |
|
444 |
setPlatformWidget(0); |
|
445 |
m_npWindow.type = NPWindowTypeDrawable; |
|
446 |
m_npWindow.window = 0; // Not used? |
|
447 |
} |
|
448 |
setNPWindowIfNeeded(); |
|
449 |
||
450 |
return true; |
|
451 |
} |
|
452 |
||
453 |
void PluginView::platformDestroy() |
|
454 |
{ |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
455 |
QWebPageClient* client = m_parentFrame->view()->hostWindow()->platformPageClient(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
456 |
if (QGraphicsWebView *webView = qobject_cast<QGraphicsWebView*>(client->pluginParent())) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
457 |
delete static_cast<PluginContainerSymbian*>(platformPluginWidget())->proxy(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
458 |
else |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
459 |
delete platformPluginWidget(); |
0 | 460 |
} |
461 |
||
462 |
void PluginView::halt() |
|
463 |
{ |
|
464 |
} |
|
465 |
||
466 |
void PluginView::restart() |
|
467 |
{ |
|
468 |
} |
|
469 |
||
470 |
} // namespace WebCore |