1cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block/* 2a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch Copyright (C) 2009, 2010 Nokia Corporation and/or its subsidiary(-ies) 3cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 4cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block This library is free software; you can redistribute it and/or 5cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block modify it under the terms of the GNU Library General Public 6cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block License as published by the Free Software Foundation; either 7cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block version 2 of the License, or (at your option) any later version. 8cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 9cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block This library is distributed in the hope that it will be useful, 10cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block but WITHOUT ANY WARRANTY; without even the implied warranty of 11cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block Library General Public License for more details. 13cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 14cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block You should have received a copy of the GNU Library General Public License 15cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block along with this library; see the file COPYING.LIB. If not, write to 16cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block Boston, MA 02110-1301, USA. 18cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block*/ 19cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "config.h" 20cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "PluginView.h" 21cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 2253733164eb6cabab5a1eddcabb42e4ce27eb0e44Ben Murdoch#include "BridgeJSC.h" 23cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "Document.h" 24cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "DocumentLoader.h" 25cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "Element.h" 26cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "FocusController.h" 27cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "Frame.h" 28cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "FrameLoadRequest.h" 29cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "FrameLoader.h" 30cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "FrameTree.h" 31cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "FrameView.h" 32cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "GraphicsContext.h" 33cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "HTMLNames.h" 34cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "HTMLPlugInElement.h" 35d0825bca7fe65beaee391d30da42e937db621564Steve Block#include "HostWindow.h" 36cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "Image.h" 37cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "JSDOMBinding.h" 38cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "KeyboardEvent.h" 39cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "MouseEvent.h" 40cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "NotImplemented.h" 41cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "Page.h" 42cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "PlatformKeyboardEvent.h" 43cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "PlatformMouseEvent.h" 44cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "PluginContainerSymbian.h" 45cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "PluginDebug.h" 46cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "PluginMainThreadScheduler.h" 47cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "PluginPackage.h" 481325a8463a7f9bc2ec969c7728aba33e3de91a17Steve Block#include "QWebPageClient.h" 49cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "RenderLayer.h" 50cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "ScriptController.h" 51cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "Settings.h" 521325a8463a7f9bc2ec969c7728aba33e3de91a17Steve Block#include "npfunctions.h" 531325a8463a7f9bc2ec969c7728aba33e3de91a17Steve Block#include "npinterface.h" 54cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "npruntime_impl.h" 55dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#include "qgraphicswebview.h" 5665f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch#include "qwebframe.h" 5765f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch#include "qwebframe_p.h" 58cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include "runtime_root.h" 59dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#include <QGraphicsProxyWidget> 60cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include <QKeyEvent> 615e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block#include <QPixmap> 62cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include <QRegion> 63cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include <QVector> 64cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include <QWidget> 65cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include <runtime/JSLock.h> 66cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#include <runtime/JSValue.h> 67cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 6865f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdochtypedef void (*_qtwebkit_page_plugin_created)(QWebFrame*, void*, void*); // frame, plugin instance, plugin functions 6965f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdochstatic _qtwebkit_page_plugin_created qtwebkit_page_plugin_created = 0; 7065f03d4f644ce73618e5f4f50dd694b26f55ae12Ben MurdochQWEBKIT_EXPORT void qtwebkit_setPluginCreatedCallback(_qtwebkit_page_plugin_created cb) 7165f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch{ 7265f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch qtwebkit_page_plugin_created = cb; 7365f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch} 7465f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch 75cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockusing JSC::ExecState; 76cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockusing JSC::Interpreter; 77cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockusing JSC::JSLock; 78cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockusing JSC::JSObject; 79cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockusing JSC::UString; 80cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 81cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockusing namespace std; 82cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 83cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockusing namespace WTF; 84cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 85cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blocknamespace WebCore { 86cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 87cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockusing namespace HTMLNames; 88cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 89cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid PluginView::updatePluginWidget() 90cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 91cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (!parent()) 92cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return; 93cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block ASSERT(parent()->isFrameView()); 94cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block FrameView* frameView = static_cast<FrameView*>(parent()); 95cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block IntRect oldWindowRect = m_windowRect; 96cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block IntRect oldClipRect = m_clipRect; 97cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 98cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_windowRect = IntRect(frameView->contentsToWindow(frameRect().location()), frameRect().size()); 99dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block 100cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_clipRect = windowClipRect(); 101cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_clipRect.move(-m_windowRect.x(), -m_windowRect.y()); 102cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (m_windowRect == oldWindowRect && m_clipRect == oldClipRect) 103cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return; 104cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 1052daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch setNPWindowIfNeeded(); 106cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 107cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 10821939df44de1705786c545cd1bf519d47250322dBen Murdochvoid PluginView::setFocus(bool focused) 109cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 11021939df44de1705786c545cd1bf519d47250322dBen Murdoch if (platformPluginWidget()) { 11121939df44de1705786c545cd1bf519d47250322dBen Murdoch if (focused) 11221939df44de1705786c545cd1bf519d47250322dBen Murdoch platformPluginWidget()->setFocus(Qt::OtherFocusReason); 11321939df44de1705786c545cd1bf519d47250322dBen Murdoch } else { 11421939df44de1705786c545cd1bf519d47250322dBen Murdoch Widget::setFocus(focused); 11521939df44de1705786c545cd1bf519d47250322dBen Murdoch } 116cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 117cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 118cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid PluginView::show() 119cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 120cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block setSelfVisible(true); 121cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 122cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (isParentVisible() && platformPluginWidget()) 123cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block platformPluginWidget()->setVisible(true); 124cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 125cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 126cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid PluginView::hide() 127cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 128cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block setSelfVisible(false); 129cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 130cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (isParentVisible() && platformPluginWidget()) 131cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block platformPluginWidget()->setVisible(false); 132cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 133cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 134cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid PluginView::paint(GraphicsContext* context, const IntRect& rect) 135cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 136cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (!m_isStarted) { 137cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block paintMissingPluginIcon(context, rect); 138cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return; 139cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block } 140cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 141cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (context->paintingDisabled()) 142cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return; 143cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_npWindow.ws_info = (void*)(context->platformContext()); 144cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block setNPWindowIfNeeded(); 145cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 146cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (m_isWindowed && platformPluginWidget()) 147cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block static_cast<PluginContainerSymbian*>(platformPluginWidget())->adjustGeometry(); 148cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 149cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (m_isWindowed) 150cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return; 151cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 152cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block context->save(); 153cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block IntRect clipRect(rect); 154cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block clipRect.intersect(frameRect()); 155cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block context->clip(clipRect); 156cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block context->translate(frameRect().location().x(), frameRect().location().y()); 157cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 158cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block QPaintEvent ev(rect); 159cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block QEvent& npEvent = ev; 160cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block dispatchNPEvent(npEvent); 161cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 162cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block context->restore(); 163cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 164cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 165cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block// TODO: Unify across ports. 166cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockbool PluginView::dispatchNPEvent(NPEvent& event) 167cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 168cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (!m_plugin->pluginFuncs()->event) 169cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return false; 170cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 171cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block PluginView::setCurrentPluginView(this); 172cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly); 173cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 174cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block setCallingPlugin(true); 175cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block bool accepted = m_plugin->pluginFuncs()->event(m_instance, &event); 176cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block setCallingPlugin(false); 177cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block PluginView::setCurrentPluginView(0); 178cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 179cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return accepted; 180cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 181cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 182cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid PluginView::handleKeyboardEvent(KeyboardEvent* event) 183cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 184cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (m_isWindowed) 185cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return; 186cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 187a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch ASSERT(event->keyEvent()->qtEvent()); 188cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block QEvent& npEvent = *(event->keyEvent()->qtEvent()); 189cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (!dispatchNPEvent(npEvent)) 190cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block event->setDefaultHandled(); 191cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 192cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 193cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid PluginView::handleMouseEvent(MouseEvent* event) 194cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 195cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (m_isWindowed) 196cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return; 197cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 198cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (event->type() == eventNames().mousedownEvent) { 199cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block // Give focus to the plugin on click 200cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (Page* page = m_parentFrame->page()) 201cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block page->focusController()->setActive(true); 202cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 203cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block focusPluginElement(); 204cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block } 205cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 206cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block QEvent::Type type; 207cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (event->type() == eventNames().mousedownEvent) 208cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block type = QEvent::MouseButtonPress; 209cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block else if (event->type() == eventNames().mousemoveEvent) 210cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block type = QEvent::MouseMove; 211cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block else if (event->type() == eventNames().mouseupEvent) 212cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block type = QEvent::MouseButtonRelease; 213cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block else 214cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return; 215cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 216cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block QPoint position(event->offsetX(), event->offsetY()); 217cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block Qt::MouseButton button; 218cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block switch (event->which()) { 219cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block case 1: 220cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block button = Qt::LeftButton; 221cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block break; 222cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block case 2: 223cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block button = Qt::MidButton; 224cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block break; 225cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block case 3: 226cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block button = Qt::RightButton; 227cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block break; 228cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block default: 229cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block button = Qt::NoButton; 230cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block } 231cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block Qt::KeyboardModifiers modifiers = 0; 232cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (event->ctrlKey()) 233cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block modifiers |= Qt::ControlModifier; 234cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (event->altKey()) 235cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block modifiers |= Qt::AltModifier; 236cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (event->shiftKey()) 237cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block modifiers |= Qt::ShiftModifier; 238cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (event->metaKey()) 239cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block modifiers |= Qt::MetaModifier; 240cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block QMouseEvent mouseEvent(type, position, button, button, modifiers); 241cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block QEvent& npEvent = mouseEvent; 242cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (!dispatchNPEvent(npEvent)) 243cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block event->setDefaultHandled(); 244cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 245cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 246cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid PluginView::setParent(ScrollView* parent) 247cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 248cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block Widget::setParent(parent); 249cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 250f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick if (parent) { 251cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block init(); 252f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick if (m_status == PluginStatusLoadedSuccessfully) 253f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick updatePluginWidget(); 254f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick } 255cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 256cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 257cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid PluginView::setNPWindowRect(const IntRect&) 258cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 259cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (!m_isWindowed) 260cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block setNPWindowIfNeeded(); 261cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 262cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 263cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid PluginView::setNPWindowIfNeeded() 264cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 265cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (!m_isStarted || !parent() || !m_plugin->pluginFuncs()->setwindow) 266cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return; 267cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (m_isWindowed) { 268cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block ASSERT(platformPluginWidget()); 269cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block platformPluginWidget()->setGeometry(m_windowRect); 270cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block // if setMask is set with an empty QRegion, no clipping will 271cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block // be performed, so in that case we hide the plugin view 272cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block platformPluginWidget()->setVisible(!m_clipRect.isEmpty()); 273cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block platformPluginWidget()->setMask(QRegion(m_clipRect)); 274cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 275cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_npWindow.x = m_windowRect.x(); 276cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_npWindow.y = m_windowRect.y(); 277cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 278ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block m_npWindow.clipRect.left = max(0, m_clipRect.x()); 279ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block m_npWindow.clipRect.top = max(0, m_clipRect.y()); 280ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block m_npWindow.clipRect.right = m_clipRect.x() + m_clipRect.width(); 281ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block m_npWindow.clipRect.bottom = m_clipRect.y() + m_clipRect.height(); 282cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 283cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block } else { 284cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block // always call this method before painting. 28565f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch m_npWindow.x = m_windowRect.x(); 28665f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch m_npWindow.y = m_windowRect.y(); 287cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 288cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_npWindow.clipRect.left = 0; 289cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_npWindow.clipRect.top = 0; 290cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_npWindow.clipRect.right = m_windowRect.width(); 291cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_npWindow.clipRect.bottom = m_windowRect.height(); 292cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_npWindow.window = 0; 293cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block } 294cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 295cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_npWindow.width = m_windowRect.width(); 296cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_npWindow.height = m_windowRect.height(); 297cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 298cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block PluginView::setCurrentPluginView(this); 299cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly); 300cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block setCallingPlugin(true); 301cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_plugin->pluginFuncs()->setwindow(m_instance, &m_npWindow); 302cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block setCallingPlugin(false); 303cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block PluginView::setCurrentPluginView(0); 304cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 305cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 306cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid PluginView::setParentVisible(bool visible) 307cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 308cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (isParentVisible() == visible) 309cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return; 310cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 311cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block Widget::setParentVisible(visible); 312cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 313cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (isSelfVisible() && platformPluginWidget()) 314cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block platformPluginWidget()->setVisible(visible); 315cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 316cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 31721939df44de1705786c545cd1bf519d47250322dBen MurdochNPError PluginView::handlePostReadFile(Vector<char>& buffer, uint32_t len, const char* buf) 318cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 319cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block notImplemented(); 320cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return NPERR_NO_ERROR; 321cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 322cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 323dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockbool PluginView::platformGetValueStatic(NPNVariable variable, void* value, NPError* result) 324cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 325cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block switch (variable) { 326cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block case NPNVjavascriptEnabledBool: 327cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block *static_cast<NPBool*>(value) = true; 328dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block *result = NPERR_NO_ERROR; 329dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block return true; 330cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 331cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block case NPNVSupportsWindowless: 332cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block *static_cast<NPBool*>(value) = true; 333dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block *result = NPERR_NO_ERROR; 334dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block return true; 335cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 336cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block default: 337dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block return false; 338cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block } 339cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 340cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 341dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockbool PluginView::platformGetValue(NPNVariable, void*, NPError*) 342cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 343dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block return false; 344cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 345cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 346cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid PluginView::invalidateRect(const IntRect& rect) 347cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 348cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (m_isWindowed) { 349cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block platformWidget()->update(rect); 350cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return; 351cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block } 352cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 353cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block invalidateWindowlessPluginRect(rect); 354cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 355cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 356cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid PluginView::invalidateRect(NPRect* rect) 357cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 358cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (m_isWindowed) 359cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return; 360cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (!rect) { 361cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block invalidate(); 362cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return; 363cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block } 364cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block IntRect r(rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top); 365cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_invalidRects.append(r); 366cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (!m_invalidateTimer.isActive()) 367cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_invalidateTimer.startOneShot(0.001); 368cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 369cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 370cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid PluginView::invalidateRegion(NPRegion region) 371cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 372cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (m_isWindowed) 373cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return; 374cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 375cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (!region) 376cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return; 377cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 378cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block QVector<QRect> rects = region->rects(); 379cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block for (int i = 0; i < rects.size(); ++i) { 380cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block const QRect& qRect = rects.at(i); 381cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_invalidRects.append(qRect); 382cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (!m_invalidateTimer.isActive()) 383cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_invalidateTimer.startOneShot(0.001); 384cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block } 385cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 386cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 387cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid PluginView::forceRedraw() 388cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 389cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (m_isWindowed) 390cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return; 391cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block invalidate(); 392cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 393cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 394cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockbool PluginView::platformStart() 395cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 396cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block ASSERT(m_isStarted); 397cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block ASSERT(m_status == PluginStatusLoadedSuccessfully); 398cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 399cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block show(); 400cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 401cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block if (m_isWindowed) { 402cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block QWebPageClient* client = m_parentFrame->view()->hostWindow()->platformPageClient(); 403dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block QGraphicsProxyWidget* proxy = 0; 404dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block if (QGraphicsWebView *webView = qobject_cast<QGraphicsWebView*>(client->pluginParent())) 405dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block proxy = new QGraphicsProxyWidget(webView); 406dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block 407dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block PluginContainerSymbian* container = new PluginContainerSymbian(this, proxy ? 0 : client->ownerWidget(), proxy); 408dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block setPlatformWidget(container); 409dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block if (proxy) 410dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block proxy->setWidget(container); 411dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block 412cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_npWindow.type = NPWindowTypeWindow; 413cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_npWindow.window = (void*)platformPluginWidget(); 414cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 415cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block } else { 416cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block setPlatformWidget(0); 417cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_npWindow.type = NPWindowTypeDrawable; 418cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block m_npWindow.window = 0; // Not used? 419cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block } 420a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch updatePluginWidget(); 421cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block setNPWindowIfNeeded(); 42265f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch 42365f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch if (qtwebkit_page_plugin_created) 42465f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch qtwebkit_page_plugin_created(QWebFramePrivate::kit(m_parentFrame.get()), m_instance, (void*)(m_plugin->pluginFuncs())); 42565f03d4f644ce73618e5f4f50dd694b26f55ae12Ben Murdoch 426cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block return true; 427cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 428cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 429cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid PluginView::platformDestroy() 430cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 43121939df44de1705786c545cd1bf519d47250322dBen Murdoch if (platformPluginWidget()) { 43221939df44de1705786c545cd1bf519d47250322dBen Murdoch PluginContainerSymbian* container = static_cast<PluginContainerSymbian*>(platformPluginWidget()); 433ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block if (container && container->proxy()) 434ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block delete container->proxy(); 435ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block else 436ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block delete container; 43721939df44de1705786c545cd1bf519d47250322dBen Murdoch } 438cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 439cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 440cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid PluginView::halt() 441cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 442cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 443cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 444cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Blockvoid PluginView::restart() 445cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{ 446cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} 447cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block 448cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block} // namespace WebCore 449