From 51c3d06e09b5e501ed7536504053c02366b2df0d Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 4 Jun 2010 10:33:36 +0200 Subject: Updated WebKit to de1e909b06cbc981d63e0fc0f6a3f84002dd1e80 Integrated changes: || || [Qt] GraphicsLayer: warnings when reloading page || || || [Qt] Flash Plugin is not working on mac-cocoa-32 || || || REGRESSION(58615): Scroll events are sent twice per keypress for ports that don't have a platformWidget scrollbar || || || [Qt, Gtk] Allows build-webkit script to receive an install prefix as parameter || || || [Qt] Add documentation to the QtWebkit bridge || || || [Qt] The FIRST letter in the PASSWORD field is taken in UPPERCASE by DEFAULT in gmail.com web page || --- src/3rdparty/webkit/.tag | 2 +- src/3rdparty/webkit/VERSION | 2 +- src/3rdparty/webkit/WebCore/ChangeLog | 79 ++ src/3rdparty/webkit/WebCore/WebCore.gypi | 2 +- src/3rdparty/webkit/WebCore/WebCore.pro | 15 +- src/3rdparty/webkit/WebCore/page/FrameView.cpp | 4 + src/3rdparty/webkit/WebCore/page/FrameView.h | 3 +- .../webkit/WebCore/platform/ScrollView.cpp | 2 +- src/3rdparty/webkit/WebCore/platform/ScrollView.h | 2 +- .../platform/graphics/qt/GraphicsLayerQt.cpp | 9 +- .../webkit/WebCore/plugins/mac/PluginViewMac.cpp | 830 -------------------- .../webkit/WebCore/plugins/mac/PluginViewMac.mm | 833 +++++++++++++++++++++ src/3rdparty/webkit/WebKit/qt/ChangeLog | 24 + .../WebKit/qt/WebCoreSupport/EditorClientQt.cpp | 6 +- .../webkit/WebKit/qt/docs/qtwebkit-bridge.qdoc | 425 +++++++++++ src/3rdparty/webkit/WebKit/qt/docs/qtwebkit.qdoc | 5 +- .../webkitsnippets/qtwebkit_bridge_snippets.cpp | 83 ++ 17 files changed, 1479 insertions(+), 847 deletions(-) delete mode 100644 src/3rdparty/webkit/WebCore/plugins/mac/PluginViewMac.cpp create mode 100644 src/3rdparty/webkit/WebCore/plugins/mac/PluginViewMac.mm create mode 100644 src/3rdparty/webkit/WebKit/qt/docs/qtwebkit-bridge.qdoc create mode 100644 src/3rdparty/webkit/WebKit/qt/docs/webkitsnippets/qtwebkit_bridge_snippets.cpp diff --git a/src/3rdparty/webkit/.tag b/src/3rdparty/webkit/.tag index cc67d1b..24fdc2a 100644 --- a/src/3rdparty/webkit/.tag +++ b/src/3rdparty/webkit/.tag @@ -1 +1 @@ -de1e909b06cbc981d63e0fc0f6a3f84002dd1e80 +903617844b4341f7098b63b54e5be16cd83af647 diff --git a/src/3rdparty/webkit/VERSION b/src/3rdparty/webkit/VERSION index f37c367..211921d 100644 --- a/src/3rdparty/webkit/VERSION +++ b/src/3rdparty/webkit/VERSION @@ -4,4 +4,4 @@ This is a snapshot of the Qt port of WebKit from and has the sha1 checksum - 9a83f22bc41a2016b6bbf495bfd32b3a659038c8 + de1e909b06cbc981d63e0fc0f6a3f84002dd1e80 diff --git a/src/3rdparty/webkit/WebCore/ChangeLog b/src/3rdparty/webkit/WebCore/ChangeLog index e907167..57e0e44 100644 --- a/src/3rdparty/webkit/WebCore/ChangeLog +++ b/src/3rdparty/webkit/WebCore/ChangeLog @@ -1,3 +1,82 @@ +2010-06-03 Tor Arne Vestbø + + Reviewed by Simon Hausmann. + + [Qt] Fix NPAPI support on Mac OS X/Cocoa-32 + + qt_mac_window_for() returns a NSWindow on Cocoa, so we were + passing in a NSWindow instead of a WindowRef as part of the + NP_CGContext. + + https://bugs.webkit.org/show_bug.cgi?id=38762 + + * WebCore.gypi: Reflect rename + * WebCore.pro: Reflect rename + * plugins/mac/PluginViewMac.cpp: Renamed to PluginViewMac.mm + and fix bug by getting the Carbon windowRef from the NSWindow. + * wscript: Reflect rename + +2010-06-02 Nico Weber + + Reviewed by Simon Fraser. + + Scroll events are sent twice per keypress for ports that don't have a platformWidget scrollbar + https://bugs.webkit.org/show_bug.cgi?id=39918 + + This was regressed by http://trac.webkit.org/changeset/58615 . Fix this by slightly tweaking + that patch. + + Test: editing/input/page-up-down-scrolls.html + + * page/FrameView.cpp: + (WebCore::FrameView::scrollPositionChanged): + * page/FrameView.h: + * platform/ScrollView.cpp: + (WebCore::ScrollView::valueChanged): + * platform/ScrollView.h: + (WebCore::ScrollView::repaintFixedElementsAfterScrolling): + +2010-06-02 Jocelyn Turcotte + + Reviewed by Simon Hausmann. + + [Qt] Fix make install on Symbian for headers in package builds when INSTALL_HEADERS is not defined + + First we wrote inst_headers.output with $$[QT_INSTALL_HEADERS] and then + overwrote it with the $$INSTALL_HEADERS variant without checking if the + variable was set. + + Fixed and cleaned up the logic of falling back to $$[QT_INSTALL_HEADERS]. + + * WebCore.pro: + +2010-06-01 No'am Rosenthal + + Reviewed by Kenneth Rohde Christiansen. + + [Qt] GraphicsLayer: warnings when reloading page + https://bugs.webkit.org/show_bug.cgi?id=39694 + + Made sure recaching and masks aren't attempted on zero-size layers. + + No new tests. Old tests (e.g. LayoutTests/compositing/masks) show the problem. + + * platform/graphics/qt/GraphicsLayerQt.cpp: + (WebCore::MaskEffectQt::draw): + (WebCore::GraphicsLayerQtImpl::recache): + +2010-05-10 Rodrigo Belem + + Reviewed by Kenneth Christiansen , Simon Hausmann and Gustavo Noronha. + + [Qt, Gtk] Allows build-webkit script to receive an install prefix as parameter + https://bugs.webkit.org/show_bug.cgi?id=26224 + + This patch adds the ability, in the QtWebkit build system, to change + the installation path. + + * WebCore.pro: + 2010-06-01 Simon Hausmann Reviewed by Laszlo Gombos. diff --git a/src/3rdparty/webkit/WebCore/WebCore.gypi b/src/3rdparty/webkit/WebCore/WebCore.gypi index 1e92f1f..94a6052 100644 --- a/src/3rdparty/webkit/WebCore/WebCore.gypi +++ b/src/3rdparty/webkit/WebCore/WebCore.gypi @@ -2920,7 +2920,7 @@ 'plugins/gtk/xembed.h', 'plugins/mac/PluginDataMac.mm', 'plugins/mac/PluginPackageMac.cpp', - 'plugins/mac/PluginViewMac.cpp', + 'plugins/mac/PluginViewMac.mm', 'plugins/qt/PluginDataQt.cpp', 'plugins/qt/PluginPackageQt.cpp', 'plugins/qt/PluginViewQt.cpp', diff --git a/src/3rdparty/webkit/WebCore/WebCore.pro b/src/3rdparty/webkit/WebCore/WebCore.pro index 2a1536c..ba669bd 100644 --- a/src/3rdparty/webkit/WebCore/WebCore.pro +++ b/src/3rdparty/webkit/WebCore/WebCore.pro @@ -2166,7 +2166,7 @@ contains(DEFINES, ENABLE_NETSCAPE_PLUGIN_API=1) { mac { SOURCES += \ plugins/mac/PluginPackageMac.cpp \ - plugins/mac/PluginViewMac.cpp + plugins/mac/PluginViewMac.mm OBJECTIVE_SOURCES += \ platform/text/mac/StringImplMac.mm \ platform/mac/WebCoreNSStringExtras.mm @@ -2852,8 +2852,12 @@ CONFIG(QTDIR_build) { !symbian { headers.files = $$WEBKIT_INSTALL_HEADERS - headers.path = $$[QT_INSTALL_HEADERS]/QtWebKit - target.path = $$[QT_INSTALL_LIBS] + + !isEmpty(INSTALL_HEADERS): headers.path = $$INSTALL_HEADERS/QtWebKit + else: headers.path = $$[QT_INSTALL_HEADERS]/QtWebKit + + !isEmpty(INSTALL_LIBS): target.path = $$INSTALL_LIBS + else: target.path = $$[QT_INSTALL_LIBS] modfile.files = $$moduleFile modfile.path = $$[QMAKE_MKSPECS]/modules @@ -2863,7 +2867,10 @@ CONFIG(QTDIR_build) { # INSTALLS is not implemented in qmake's s60 generators, copy headers manually inst_headers.commands = $$QMAKE_COPY ${QMAKE_FILE_NAME} ${QMAKE_FILE_OUT} inst_headers.input = WEBKIT_INSTALL_HEADERS - inst_headers.output = $$[QT_INSTALL_HEADERS]/QtWebKit/${QMAKE_FILE_BASE}${QMAKE_FILE_EXT} + + !isEmpty(INSTALL_HEADERS): inst_headers.output = $$INSTALL_HEADERS/QtWebKit/${QMAKE_FILE_BASE}${QMAKE_FILE_EXT} + else: inst_headers.output = $$[QT_INSTALL_HEADERS]/QtWebKit/${QMAKE_FILE_BASE}${QMAKE_FILE_EXT} + QMAKE_EXTRA_COMPILERS += inst_headers inst_modfile.commands = $$inst_headers.commands diff --git a/src/3rdparty/webkit/WebCore/page/FrameView.cpp b/src/3rdparty/webkit/WebCore/page/FrameView.cpp index 39c92de..bc0519f 100644 --- a/src/3rdparty/webkit/WebCore/page/FrameView.cpp +++ b/src/3rdparty/webkit/WebCore/page/FrameView.cpp @@ -1060,7 +1060,11 @@ void FrameView::setScrollPosition(const IntPoint& scrollPoint) void FrameView::scrollPositionChanged() { frame()->eventHandler()->sendScrollEvent(); + repaintFixedElementsAfterScrolling(); +} +void FrameView::repaintFixedElementsAfterScrolling() +{ // For fixed position elements, update widget positions and compositing layers after scrolling, // but only if we're not inside of layout. // FIXME: we could skip this if we knew the page had no fixed position elements. diff --git a/src/3rdparty/webkit/WebCore/page/FrameView.h b/src/3rdparty/webkit/WebCore/page/FrameView.h index 7119975..71e2966 100644 --- a/src/3rdparty/webkit/WebCore/page/FrameView.h +++ b/src/3rdparty/webkit/WebCore/page/FrameView.h @@ -139,7 +139,8 @@ public: virtual void scrollRectIntoViewRecursively(const IntRect&); virtual void setScrollPosition(const IntPoint&); - virtual void scrollPositionChanged(); + void scrollPositionChanged(); + virtual void repaintFixedElementsAfterScrolling(); String mediaType() const; void setMediaType(const String&); diff --git a/src/3rdparty/webkit/WebCore/platform/ScrollView.cpp b/src/3rdparty/webkit/WebCore/platform/ScrollView.cpp index e50ab55..5753e1d 100644 --- a/src/3rdparty/webkit/WebCore/platform/ScrollView.cpp +++ b/src/3rdparty/webkit/WebCore/platform/ScrollView.cpp @@ -292,7 +292,7 @@ void ScrollView::valueChanged(Scrollbar* scrollbar) if (scrollbarsSuppressed()) return; - scrollPositionChanged(); + repaintFixedElementsAfterScrolling(); scrollContents(scrollDelta); } diff --git a/src/3rdparty/webkit/WebCore/platform/ScrollView.h b/src/3rdparty/webkit/WebCore/platform/ScrollView.h index 118a310..0f79fa8 100644 --- a/src/3rdparty/webkit/WebCore/platform/ScrollView.h +++ b/src/3rdparty/webkit/WebCore/platform/ScrollView.h @@ -303,7 +303,7 @@ private: void updateScrollbars(const IntSize& desiredOffset); // Called when the scroll position within this view changes. FrameView overrides this to generate repaint invalidations. - virtual void scrollPositionChanged() {} + virtual void repaintFixedElementsAfterScrolling() {} void platformInit(); void platformDestroy(); diff --git a/src/3rdparty/webkit/WebCore/platform/graphics/qt/GraphicsLayerQt.cpp b/src/3rdparty/webkit/WebCore/platform/graphics/qt/GraphicsLayerQt.cpp index 02bf25e..43c9245 100644 --- a/src/3rdparty/webkit/WebCore/platform/graphics/qt/GraphicsLayerQt.cpp +++ b/src/3rdparty/webkit/WebCore/platform/graphics/qt/GraphicsLayerQt.cpp @@ -57,7 +57,12 @@ public: // It's more efficient to do it this way because // (a) we don't need the QBrush abstraction - we always end up using QGraphicsItem::paint from the mask layer // (b) QGraphicsOpacityEffect detaches the pixmap, which is inefficient on OpenGL. - QPixmap maskPixmap(sourceBoundingRect().toAlignedRect().size()); + const QSize maskSize = sourceBoundingRect().toAlignedRect().size(); + if (!maskSize.isValid() || maskSize.isEmpty()) { + drawSource(painter); + return; + } + QPixmap maskPixmap(maskSize); // we need to do this so the pixmap would have hasAlpha() maskPixmap.fill(Qt::transparent); @@ -294,7 +299,7 @@ const GraphicsLayerQtImpl* GraphicsLayerQtImpl::rootLayer() const QPixmap GraphicsLayerQtImpl::recache(const QRegion& regionToUpdate) { - if (!m_layer->drawsContent()) + if (!m_layer->drawsContent() || m_size.isEmpty() ||!m_size.isValid()) return QPixmap(); QRegion region = regionToUpdate; diff --git a/src/3rdparty/webkit/WebCore/plugins/mac/PluginViewMac.cpp b/src/3rdparty/webkit/WebCore/plugins/mac/PluginViewMac.cpp deleted file mode 100644 index 1fd4676..0000000 --- a/src/3rdparty/webkit/WebCore/plugins/mac/PluginViewMac.cpp +++ /dev/null @@ -1,830 +0,0 @@ -/* - * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. - * Copyright (C) 2008 Collabora Ltd. All rights reserved. - * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) - * Copyright (C) 2009 Girish Ramakrishnan - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "PluginView.h" - -#include "Bridge.h" -#include "Document.h" -#include "DocumentLoader.h" -#include "Element.h" -#include "EventNames.h" -#include "FocusController.h" -#include "FrameLoader.h" -#include "FrameLoadRequest.h" -#include "FrameTree.h" -#include "Frame.h" -#include "FrameView.h" -#include "GraphicsContext.h" -#include "HostWindow.h" -#include "HTMLNames.h" -#include "HTMLPlugInElement.h" -#include "Image.h" -#include "JSDOMBinding.h" -#include "KeyboardEvent.h" -#include "MouseEvent.h" -#include "NotImplemented.h" -#include "Page.h" -#include "PlatformMouseEvent.h" -#include "PlatformKeyboardEvent.h" -#include "PluginDebug.h" -#include "PluginPackage.h" -#include "PluginMainThreadScheduler.h" -#include "RenderLayer.h" -#include "ScriptController.h" -#include "Settings.h" -#include "npruntime_impl.h" -#include "runtime_root.h" -#include -#include -#include - - -using JSC::ExecState; -using JSC::Interpreter; -using JSC::JSLock; -using JSC::JSObject; -using JSC::JSValue; -using JSC::UString; - -#if PLATFORM(QT) -#include -#include -#include -#include "QWebPageClient.h" -QT_BEGIN_NAMESPACE -extern Q_GUI_EXPORT OSWindowRef qt_mac_window_for(const QWidget* w); -QT_END_NAMESPACE -#endif - -#if PLATFORM(WX) -#include -#include -#endif - -using std::min; - -using namespace WTF; - -namespace WebCore { - -using namespace HTMLNames; - -#ifndef NP_NO_CARBON -static int modifiersForEvent(UIEventWithKeyState *event); -#endif - -static inline WindowRef nativeWindowFor(PlatformWidget widget) -{ -#if PLATFORM(QT) - if (widget) - return static_cast(qt_mac_window_for(widget)); -#endif -#if PLATFORM(WX) - if (widget) - return (WindowRef)widget->MacGetTopLevelWindowRef(); -#endif - return 0; -} - -static inline CGContextRef cgHandleFor(PlatformWidget widget) -{ -#if PLATFORM(QT) - if (widget) - return (CGContextRef)widget->macCGHandle(); -#endif -#if PLATFORM(WX) - if (widget) - return (CGContextRef)widget->MacGetCGContextRef(); -#endif - return 0; -} - -static inline IntPoint topLevelOffsetFor(PlatformWidget widget) -{ -#if PLATFORM(QT) - if (widget) { - PlatformWidget topLevel = widget->window(); - return widget->mapTo(topLevel, QPoint(0, 0)) + topLevel->geometry().topLeft() - topLevel->pos(); - } -#endif -#if PLATFORM(WX) - if (widget) { - PlatformWidget toplevel = wxGetTopLevelParent(widget); - return toplevel->ScreenToClient(widget->GetScreenPosition()); - } -#endif - return IntPoint(); -} - -// --------------- Lifetime management ----------------- - -bool PluginView::platformStart() -{ - ASSERT(m_isStarted); - ASSERT(m_status == PluginStatusLoadedSuccessfully); - - if (m_drawingModel == NPDrawingModel(-1)) { - // We default to QuickDraw, even though we don't support it, - // since that's what Safari does, and some plugins expect this - // behavior and never set the drawing model explicitly. -#ifndef NP_NO_QUICKDRAW - m_drawingModel = NPDrawingModelQuickDraw; -#else - // QuickDraw not available, so we have to default to CoreGraphics - m_drawingModel = NPDrawingModelCoreGraphics; -#endif - } - - if (m_eventModel == NPEventModel(-1)) { - // If the plug-in did not specify an event model - // we default to Carbon, when it is available. -#ifndef NP_NO_CARBON - m_eventModel = NPEventModelCarbon; -#else - m_eventModel = NPEventModelCocoa; -#endif - } - - // Gracefully handle unsupported drawing or event models. We can do this - // now since the drawing and event model can only be set during NPP_New. -#ifndef NP_NO_CARBON - NPBool eventModelSupported; - if (getValueStatic(NPNVariable(NPNVsupportsCarbonBool + m_eventModel), &eventModelSupported) != NPERR_NO_ERROR - || !eventModelSupported) { -#endif - m_status = PluginStatusCanNotLoadPlugin; - LOG(Plugins, "Plug-in '%s' uses unsupported event model %s", - m_plugin->name().utf8().data(), prettyNameForEventModel(m_eventModel)); - return false; -#ifndef NP_NO_CARBON - } -#endif - -#ifndef NP_NO_QUICKDRAW - NPBool drawingModelSupported; - if (getValueStatic(NPNVariable(NPNVsupportsQuickDrawBool + m_drawingModel), &drawingModelSupported) != NPERR_NO_ERROR - || !drawingModelSupported) { -#endif - m_status = PluginStatusCanNotLoadPlugin; - LOG(Plugins, "Plug-in '%s' uses unsupported drawing model %s", - m_plugin->name().utf8().data(), prettyNameForDrawingModel(m_drawingModel)); - return false; -#ifndef NP_NO_QUICKDRAW - } -#endif - -#if PLATFORM(QT) - // Set the platformPluginWidget only in the case of QWebView so that the context menu appears in the right place. - // In all other cases, we use off-screen rendering - if (QWebPageClient* client = m_parentFrame->view()->hostWindow()->platformPageClient()) { - if (QWidget* widget = qobject_cast(client->pluginParent())) - setPlatformPluginWidget(widget); - } -#endif -#if PLATFORM(WX) - if (wxWindow* widget = m_parentFrame->view()->hostWindow()->platformPageClient()) - setPlatformPluginWidget(widget); -#endif - - // Create a fake window relative to which all events will be sent when using offscreen rendering - if (!platformPluginWidget()) { -#ifndef NP_NO_CARBON - // Make the default size really big. It is unclear why this is required but with a smaller size, mouse move - // events don't get processed. Resizing the fake window to flash's size doesn't help. - ::Rect windowBounds = { 0, 0, 1000, 1000 }; - CreateNewWindow(kDocumentWindowClass, kWindowStandardDocumentAttributes, &windowBounds, &m_fakeWindow); - // Flash requires the window to be hilited to process mouse move events. - HiliteWindow(m_fakeWindow, true); -#endif - } - - show(); - - // TODO: Implement null timer throttling depending on plugin activation - m_nullEventTimer.set(new Timer(this, &PluginView::nullEventTimerFired)); - m_nullEventTimer->startRepeating(0.02); - - m_lastMousePos.h = m_lastMousePos.v = 0; - - return true; -} - -void PluginView::platformDestroy() -{ - if (platformPluginWidget()) - setPlatformPluginWidget(0); - else { - CGContextRelease(m_contextRef); -#ifndef NP_NO_CARBON - if (m_fakeWindow) - DisposeWindow(m_fakeWindow); -#endif - } -} - -// Used before the plugin view has been initialized properly, and as a -// fallback for variables that do not require a view to resolve. -bool PluginView::platformGetValueStatic(NPNVariable variable, void* value, NPError* result) -{ - switch (variable) { - case NPNVToolkit: - *static_cast(value) = 0; - *result = NPERR_NO_ERROR; - return true; - - case NPNVjavascriptEnabledBool: - *static_cast(value) = true; - *result = NPERR_NO_ERROR; - return true; - -#ifndef NP_NO_CARBON - case NPNVsupportsCarbonBool: - *static_cast(value) = true; - *result = NPERR_NO_ERROR; - return true; - -#endif - case NPNVsupportsCocoaBool: - *static_cast(value) = false; - *result = NPERR_NO_ERROR; - return true; - - // CoreGraphics is the only drawing model we support - case NPNVsupportsCoreGraphicsBool: - *static_cast(value) = true; - *result = NPERR_NO_ERROR; - return true; - -#ifndef NP_NO_QUICKDRAW - // QuickDraw is deprecated in 10.5 and not supported on 64-bit - case NPNVsupportsQuickDrawBool: -#endif - case NPNVsupportsOpenGLBool: - case NPNVsupportsCoreAnimationBool: - *static_cast(value) = false; - *result = NPERR_NO_ERROR; - return true; - - default: - return false; - } -} - -// Used only for variables that need a view to resolve -bool PluginView::platformGetValue(NPNVariable variable, void* value, NPError* error) -{ - return false; -} - -void PluginView::setParent(ScrollView* parent) -{ - LOG(Plugins, "PluginView::setParent(%p)", parent); - - Widget::setParent(parent); - - if (parent) - init(); -} - -// -------------- Geometry and painting ---------------- - -void PluginView::show() -{ - LOG(Plugins, "PluginView::show()"); - - setSelfVisible(true); - - Widget::show(); -} - -void PluginView::hide() -{ - LOG(Plugins, "PluginView::hide()"); - - setSelfVisible(false); - - Widget::hide(); -} - -void PluginView::setFocus() -{ - LOG(Plugins, "PluginView::setFocus()"); - - if (platformPluginWidget()) -#if PLATFORM(QT) - platformPluginWidget()->setFocus(Qt::OtherFocusReason); -#else - platformPluginWidget()->SetFocus(); -#endif - else - Widget::setFocus(); - - // TODO: Also handle and pass on blur events (focus lost) - -#ifndef NP_NO_CARBON - EventRecord record; - record.what = getFocusEvent; - record.message = 0; - record.when = TickCount(); - record.where = globalMousePosForPlugin(); - record.modifiers = GetCurrentKeyModifiers(); - - if (!dispatchNPEvent(record)) - LOG(Events, "PluginView::setFocus(): Get-focus event not accepted"); -#endif -} - -void PluginView::setParentVisible(bool visible) -{ - if (isParentVisible() == visible) - return; - - Widget::setParentVisible(visible); -} - -void PluginView::setNPWindowRect(const IntRect&) -{ - setNPWindowIfNeeded(); -} - -void PluginView::setNPWindowIfNeeded() -{ - if (!m_isStarted || !parent() || !m_plugin->pluginFuncs()->setwindow) - return; - - CGContextRef newContextRef = 0; - WindowRef newWindowRef = 0; - if (platformPluginWidget()) { - newContextRef = cgHandleFor(platformPluginWidget()); - newWindowRef = nativeWindowFor(platformPluginWidget()); - m_npWindow.type = NPWindowTypeWindow; - } else { - newContextRef = m_contextRef; - newWindowRef = m_fakeWindow; - m_npWindow.type = NPWindowTypeDrawable; - } - - if (!newContextRef || !newWindowRef) - return; - - m_npWindow.window = (void*)&m_npCgContext; -#ifndef NP_NO_CARBON - m_npCgContext.window = newWindowRef; -#endif - m_npCgContext.context = newContextRef; - - m_npWindow.x = m_windowRect.x(); - m_npWindow.y = m_windowRect.y(); - m_npWindow.width = m_windowRect.width(); - m_npWindow.height = m_windowRect.height(); - - // TODO: (also clip against scrollbars, etc.) - m_npWindow.clipRect.left = max(0, m_windowRect.x()); - m_npWindow.clipRect.top = max(0, m_windowRect.y()); - m_npWindow.clipRect.right = m_windowRect.x() + m_windowRect.width(); - m_npWindow.clipRect.bottom = m_windowRect.y() + m_windowRect.height(); - - LOG(Plugins, "PluginView::setNPWindowIfNeeded(): window=%p, context=%p," - " window.x:%d window.y:%d window.width:%d window.height:%d window.clipRect size:%dx%d", - newWindowRef, newContextRef, m_npWindow.x, m_npWindow.y, m_npWindow.width, m_npWindow.height, - m_npWindow.clipRect.right - m_npWindow.clipRect.left, m_npWindow.clipRect.bottom - m_npWindow.clipRect.top); - - PluginView::setCurrentPluginView(this); - JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly); - setCallingPlugin(true); - m_plugin->pluginFuncs()->setwindow(m_instance, &m_npWindow); - setCallingPlugin(false); - PluginView::setCurrentPluginView(0); -} - -void PluginView::updatePluginWidget() -{ - if (!parent()) - return; - - ASSERT(parent()->isFrameView()); - FrameView* frameView = static_cast(parent()); - - IntRect oldWindowRect = m_windowRect; - IntRect oldClipRect = m_clipRect; - - m_windowRect = frameView->contentsToWindow(frameRect()); - IntPoint offset = topLevelOffsetFor(platformPluginWidget()); - m_windowRect.move(offset.x(), offset.y()); - - if (!platformPluginWidget()) { - if (m_windowRect.size() != oldWindowRect.size()) { - CGContextRelease(m_contextRef); -#if PLATFORM(QT) - m_pixmap = QPixmap(m_windowRect.size()); - m_pixmap.fill(Qt::transparent); - m_contextRef = m_pixmap.isNull() ? 0 : qt_mac_cg_context(&m_pixmap); -#endif - } - } - - m_clipRect = windowClipRect(); - m_clipRect.move(-m_windowRect.x(), -m_windowRect.y()); - - if (platformPluginWidget() && (m_windowRect != oldWindowRect || m_clipRect != oldClipRect)) - setNPWindowIfNeeded(); -} - -void PluginView::paint(GraphicsContext* context, const IntRect& rect) -{ - if (!m_isStarted || m_status != PluginStatusLoadedSuccessfully) { - paintMissingPluginIcon(context, rect); - return; - } - - if (context->paintingDisabled()) - return; - - setNPWindowIfNeeded(); - - CGContextRef cgContext = m_npCgContext.context; - if (!cgContext) - return; - - CGContextSaveGState(cgContext); - if (platformPluginWidget()) { - IntPoint offset = frameRect().location(); - CGContextTranslateCTM(cgContext, offset.x(), offset.y()); - } - - IntRect targetRect(frameRect()); - targetRect.intersects(rect); - - // clip the context so that plugin only updates the interested area. - CGRect r; - r.origin.x = targetRect.x() - frameRect().x(); - r.origin.y = targetRect.y() - frameRect().y(); - r.size.width = targetRect.width(); - r.size.height = targetRect.height(); - CGContextClipToRect(cgContext, r); - - if (!platformPluginWidget() && m_isTransparent) { // clean the pixmap in transparent mode -#if PLATFORM(QT) - QPainter painter(&m_pixmap); - painter.setCompositionMode(QPainter::CompositionMode_Clear); - painter.fillRect(QRectF(r.origin.x, r.origin.y, r.size.width, r.size.height), Qt::transparent); -#endif - } - -#ifndef NP_NO_CARBON - EventRecord event; - event.what = updateEvt; - event.message = (long unsigned int)m_npCgContext.window; - event.when = TickCount(); - event.where.h = 0; - event.where.v = 0; - event.modifiers = GetCurrentKeyModifiers(); - - if (!dispatchNPEvent(event)) - LOG(Events, "PluginView::paint(): Paint event not accepted"); -#endif - - CGContextRestoreGState(cgContext); - - if (!platformPluginWidget()) { -#if PLATFORM(QT) - QPainter* painter = context->platformContext(); - painter->drawPixmap(targetRect.x(), targetRect.y(), m_pixmap, - targetRect.x() - frameRect().x(), targetRect.y() - frameRect().y(), targetRect.width(), targetRect.height()); -#endif - } -} - -void PluginView::invalidateRect(const IntRect& rect) -{ - if (platformPluginWidget()) -#if PLATFORM(QT) - platformPluginWidget()->update(convertToContainingWindow(rect)); -#else - platformPluginWidget()->RefreshRect(convertToContainingWindow(rect)); -#endif - else - invalidateWindowlessPluginRect(rect); -} - -void PluginView::invalidateRect(NPRect* rect) -{ - IntRect r(rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top); - invalidateRect(r); -} - -void PluginView::invalidateRegion(NPRegion region) -{ - // TODO: optimize - invalidate(); -} - -void PluginView::forceRedraw() -{ - notImplemented(); -} - - -// ----------------- Event handling -------------------- - -void PluginView::handleMouseEvent(MouseEvent* event) -{ - if (!m_isStarted) - return; - -#ifndef NP_NO_CARBON - EventRecord record; - - if (event->type() == eventNames().mousemoveEvent) { - // Mouse movement is handled by null timer events - m_lastMousePos = mousePosForPlugin(event); - return; - } else if (event->type() == eventNames().mouseoverEvent) { - record.what = adjustCursorEvent; - } else if (event->type() == eventNames().mouseoutEvent) { - record.what = adjustCursorEvent; - } else if (event->type() == eventNames().mousedownEvent) { - record.what = mouseDown; - // The plugin needs focus to receive keyboard events - if (Page* page = m_parentFrame->page()) - page->focusController()->setFocusedFrame(m_parentFrame); - m_parentFrame->document()->setFocusedNode(m_element); - } else if (event->type() == eventNames().mouseupEvent) { - record.what = mouseUp; - } else { - return; - } - record.where = mousePosForPlugin(event); - record.modifiers = modifiersForEvent(event); - - if (!event->buttonDown()) - record.modifiers |= btnState; - - if (event->button() == 2) - record.modifiers |= controlKey; - - if (!dispatchNPEvent(record)) { - if (record.what == adjustCursorEvent) - return; // Signals that the plugin wants a normal cursor - - LOG(Events, "PluginView::handleMouseEvent(): Mouse event type %d at %d,%d not accepted", - record.what, record.where.h, record.where.v); - } else { - event->setDefaultHandled(); - } -#endif -} - -void PluginView::handleKeyboardEvent(KeyboardEvent* event) -{ - if (!m_isStarted) - return; - - LOG(Plugins, "PluginView::handleKeyboardEvent() ----------------- "); - - LOG(Plugins, "PV::hKE(): KE.keyCode: 0x%02X, KE.charCode: %d", - event->keyCode(), event->charCode()); - -#ifndef NP_NO_CARBON - EventRecord record; - - if (event->type() == eventNames().keydownEvent) { - // This event is the result of a PlatformKeyboardEvent::KeyDown which - // was disambiguated into a PlatformKeyboardEvent::RawKeyDown. Since - // we don't have access to the text here, we return, and wait for the - // corresponding event based on PlatformKeyboardEvent::Char. - return; - } else if (event->type() == eventNames().keypressEvent) { - // Which would be this one. This event was disambiguated from the same - // PlatformKeyboardEvent::KeyDown, but to a PlatformKeyboardEvent::Char, - // which retains the text from the original event. So, we can safely pass - // on the event as a key-down event to the plugin. - record.what = keyDown; - } else if (event->type() == eventNames().keyupEvent) { - // PlatformKeyboardEvent::KeyUp events always have the text, so nothing - // fancy here. - record.what = keyUp; - } else { - return; - } - - const PlatformKeyboardEvent* platformEvent = event->keyEvent(); - int keyCode = platformEvent->nativeVirtualKeyCode(); - - const String text = platformEvent->text(); - if (text.length() < 1) { - event->setDefaultHandled(); - return; - } - - WTF::RetainPtr cfText(WTF::AdoptCF, text.createCFString()); - - LOG(Plugins, "PV::hKE(): PKE.text: %s, PKE.unmodifiedText: %s, PKE.keyIdentifier: %s", - text.ascii().data(), platformEvent->unmodifiedText().ascii().data(), - platformEvent->keyIdentifier().ascii().data()); - - char charCodes[2] = { 0, 0 }; - if (!CFStringGetCString(cfText.get(), charCodes, 2, CFStringGetSystemEncoding())) { - LOG_ERROR("Could not resolve character code using system encoding."); - event->setDefaultHandled(); - return; - } - - record.where = globalMousePosForPlugin(); - record.modifiers = modifiersForEvent(event); - record.message = ((keyCode & 0xFF) << 8) | (charCodes[0] & 0xFF); - record.when = TickCount(); - - LOG(Plugins, "PV::hKE(): record.modifiers: %d", record.modifiers); - -#if PLATFORM(QT) - LOG(Plugins, "PV::hKE(): PKE.qtEvent()->nativeVirtualKey: 0x%02X, charCode: %d", - keyCode, int(uchar(charCodes[0]))); -#endif - - if (!dispatchNPEvent(record)) - LOG(Events, "PluginView::handleKeyboardEvent(): Keyboard event type %d not accepted", record.what); - else - event->setDefaultHandled(); -#endif -} - -#ifndef NP_NO_CARBON -void PluginView::nullEventTimerFired(Timer*) -{ - EventRecord record; - - record.what = nullEvent; - record.message = 0; - record.when = TickCount(); - record.where = m_lastMousePos; - record.modifiers = GetCurrentKeyModifiers(); - if (!Button()) - record.modifiers |= btnState; - - if (!dispatchNPEvent(record)) - LOG(Events, "PluginView::nullEventTimerFired(): Null event not accepted"); -} -#endif - -#ifndef NP_NO_CARBON -static int modifiersForEvent(UIEventWithKeyState* event) -{ - int modifiers = 0; - - if (event->ctrlKey()) - modifiers |= controlKey; - - if (event->altKey()) - modifiers |= optionKey; - - if (event->metaKey()) - modifiers |= cmdKey; - - if (event->shiftKey()) - modifiers |= shiftKey; - - return modifiers; -} -#endif - -#ifndef NP_NO_CARBON -static bool tigerOrBetter() -{ - static SInt32 systemVersion = 0; - - if (!systemVersion) { - if (Gestalt(gestaltSystemVersion, &systemVersion) != noErr) - return false; - } - - return systemVersion >= 0x1040; -} -#endif - -#ifndef NP_NO_CARBON -Point PluginView::globalMousePosForPlugin() const -{ - Point pos; - GetGlobalMouse(&pos); - - float scaleFactor = tigerOrBetter() ? HIGetScaleFactor() : 1; - - pos.h = short(pos.h * scaleFactor); - pos.v = short(pos.v * scaleFactor); - -#if PLATFORM(WX) - // make sure the titlebar/toolbar size is included - WindowRef windowRef = nativeWindowFor(platformPluginWidget()); - ::Rect content, structure; - - GetWindowBounds(windowRef, kWindowStructureRgn, &structure); - GetWindowBounds(windowRef, kWindowContentRgn, &content); - - int top = content.top - structure.top; - pos.v -= top; -#endif - - return pos; -} -#endif - -#ifndef NP_NO_CARBON -Point PluginView::mousePosForPlugin(MouseEvent* event) const -{ - ASSERT(event); - if (platformPluginWidget()) - return globalMousePosForPlugin(); - - if (event->button() == 2) { - // always pass the global position for right-click since Flash uses it to position the context menu - return globalMousePosForPlugin(); - } - - Point pos; - IntPoint postZoomPos = roundedIntPoint(m_element->renderer()->absoluteToLocal(event->absoluteLocation())); - pos.h = postZoomPos.x() + m_windowRect.x(); - // The number 22 is the height of the title bar. As to why it figures in the calculation below - // is left as an exercise to the reader :-) - pos.v = postZoomPos.y() + m_windowRect.y() - 22; - return pos; -} -#endif - -#ifndef NP_NO_CARBON -bool PluginView::dispatchNPEvent(NPEvent& event) -{ - PluginView::setCurrentPluginView(this); - JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly); - setCallingPlugin(true); - - bool accepted = m_plugin->pluginFuncs()->event(m_instance, &event); - - setCallingPlugin(false); - PluginView::setCurrentPluginView(0); - return accepted; -} -#endif - -// ------------------- Miscellaneous ------------------ - -NPError PluginView::handlePostReadFile(Vector& buffer, uint32 len, const char* buf) -{ - String filename(buf, len); - - if (filename.startsWith("file:///")) - filename = filename.substring(8); - - if (!fileExists(filename)) - return NPERR_FILE_NOT_FOUND; - - FILE* fileHandle = fopen((filename.utf8()).data(), "r"); - - if (fileHandle == 0) - return NPERR_FILE_NOT_FOUND; - - int bytesRead = fread(buffer.data(), 1, 0, fileHandle); - - fclose(fileHandle); - - if (bytesRead <= 0) - return NPERR_FILE_NOT_FOUND; - - return NPERR_NO_ERROR; -} - -void PluginView::halt() -{ -} - -void PluginView::restart() -{ -} - -} // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/plugins/mac/PluginViewMac.mm b/src/3rdparty/webkit/WebCore/plugins/mac/PluginViewMac.mm new file mode 100644 index 0000000..57d74ab --- /dev/null +++ b/src/3rdparty/webkit/WebCore/plugins/mac/PluginViewMac.mm @@ -0,0 +1,833 @@ +/* + * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2008 Collabora Ltd. All rights reserved. + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2009 Girish Ramakrishnan + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "PluginView.h" + +#include "Bridge.h" +#include "Document.h" +#include "DocumentLoader.h" +#include "Element.h" +#include "EventNames.h" +#include "FocusController.h" +#include "FrameLoader.h" +#include "FrameLoadRequest.h" +#include "FrameTree.h" +#include "Frame.h" +#include "FrameView.h" +#include "GraphicsContext.h" +#include "HostWindow.h" +#include "HTMLNames.h" +#include "HTMLPlugInElement.h" +#include "Image.h" +#include "JSDOMBinding.h" +#include "KeyboardEvent.h" +#include "MouseEvent.h" +#include "NotImplemented.h" +#include "Page.h" +#include "PlatformMouseEvent.h" +#include "PlatformKeyboardEvent.h" +#include "PluginDebug.h" +#include "PluginPackage.h" +#include "PluginMainThreadScheduler.h" +#include "RenderLayer.h" +#include "ScriptController.h" +#include "Settings.h" +#include "npruntime_impl.h" +#include "runtime_root.h" +#include +#include +#include + + +using JSC::ExecState; +using JSC::Interpreter; +using JSC::JSLock; +using JSC::JSObject; +using JSC::JSValue; +using JSC::UString; + +#if PLATFORM(QT) +#include +#include +#include +#include "QWebPageClient.h" +QT_BEGIN_NAMESPACE +extern Q_GUI_EXPORT OSWindowRef qt_mac_window_for(const QWidget* w); +QT_END_NAMESPACE +#endif + +#if PLATFORM(WX) +#include +#include +#endif + +using std::min; + +using namespace WTF; + +namespace WebCore { + +using namespace HTMLNames; + +#ifndef NP_NO_CARBON +static int modifiersForEvent(UIEventWithKeyState *event); +#endif + +static inline WindowRef nativeWindowFor(PlatformWidget widget) +{ +#if PLATFORM(QT) + if (widget) +#if QT_MAC_USE_COCOA + return static_cast([qt_mac_window_for(widget) windowRef]); +#else + return static_cast(qt_mac_window_for(widget)); +#endif +#elif PLATFORM(WX) + if (widget) + return (WindowRef)widget->MacGetTopLevelWindowRef(); +#endif + return 0; +} + +static inline CGContextRef cgHandleFor(PlatformWidget widget) +{ +#if PLATFORM(QT) + if (widget) + return (CGContextRef)widget->macCGHandle(); +#endif +#if PLATFORM(WX) + if (widget) + return (CGContextRef)widget->MacGetCGContextRef(); +#endif + return 0; +} + +static inline IntPoint topLevelOffsetFor(PlatformWidget widget) +{ +#if PLATFORM(QT) + if (widget) { + PlatformWidget topLevel = widget->window(); + return widget->mapTo(topLevel, QPoint(0, 0)) + topLevel->geometry().topLeft() - topLevel->pos(); + } +#endif +#if PLATFORM(WX) + if (widget) { + PlatformWidget toplevel = wxGetTopLevelParent(widget); + return toplevel->ScreenToClient(widget->GetScreenPosition()); + } +#endif + return IntPoint(); +} + +// --------------- Lifetime management ----------------- + +bool PluginView::platformStart() +{ + ASSERT(m_isStarted); + ASSERT(m_status == PluginStatusLoadedSuccessfully); + + if (m_drawingModel == NPDrawingModel(-1)) { + // We default to QuickDraw, even though we don't support it, + // since that's what Safari does, and some plugins expect this + // behavior and never set the drawing model explicitly. +#ifndef NP_NO_QUICKDRAW + m_drawingModel = NPDrawingModelQuickDraw; +#else + // QuickDraw not available, so we have to default to CoreGraphics + m_drawingModel = NPDrawingModelCoreGraphics; +#endif + } + + if (m_eventModel == NPEventModel(-1)) { + // If the plug-in did not specify an event model + // we default to Carbon, when it is available. +#ifndef NP_NO_CARBON + m_eventModel = NPEventModelCarbon; +#else + m_eventModel = NPEventModelCocoa; +#endif + } + + // Gracefully handle unsupported drawing or event models. We can do this + // now since the drawing and event model can only be set during NPP_New. +#ifndef NP_NO_CARBON + NPBool eventModelSupported; + if (getValueStatic(NPNVariable(NPNVsupportsCarbonBool + m_eventModel), &eventModelSupported) != NPERR_NO_ERROR + || !eventModelSupported) { +#endif + m_status = PluginStatusCanNotLoadPlugin; + LOG(Plugins, "Plug-in '%s' uses unsupported event model %s", + m_plugin->name().utf8().data(), prettyNameForEventModel(m_eventModel)); + return false; +#ifndef NP_NO_CARBON + } +#endif + +#ifndef NP_NO_QUICKDRAW + NPBool drawingModelSupported; + if (getValueStatic(NPNVariable(NPNVsupportsQuickDrawBool + m_drawingModel), &drawingModelSupported) != NPERR_NO_ERROR + || !drawingModelSupported) { +#endif + m_status = PluginStatusCanNotLoadPlugin; + LOG(Plugins, "Plug-in '%s' uses unsupported drawing model %s", + m_plugin->name().utf8().data(), prettyNameForDrawingModel(m_drawingModel)); + return false; +#ifndef NP_NO_QUICKDRAW + } +#endif + +#if PLATFORM(QT) + // Set the platformPluginWidget only in the case of QWebView so that the context menu appears in the right place. + // In all other cases, we use off-screen rendering + if (QWebPageClient* client = m_parentFrame->view()->hostWindow()->platformPageClient()) { + if (QWidget* widget = qobject_cast(client->pluginParent())) + setPlatformPluginWidget(widget); + } +#endif +#if PLATFORM(WX) + if (wxWindow* widget = m_parentFrame->view()->hostWindow()->platformPageClient()) + setPlatformPluginWidget(widget); +#endif + + // Create a fake window relative to which all events will be sent when using offscreen rendering + if (!platformPluginWidget()) { +#ifndef NP_NO_CARBON + // Make the default size really big. It is unclear why this is required but with a smaller size, mouse move + // events don't get processed. Resizing the fake window to flash's size doesn't help. + ::Rect windowBounds = { 0, 0, 1000, 1000 }; + CreateNewWindow(kDocumentWindowClass, kWindowStandardDocumentAttributes, &windowBounds, &m_fakeWindow); + // Flash requires the window to be hilited to process mouse move events. + HiliteWindow(m_fakeWindow, true); +#endif + } + + show(); + + // TODO: Implement null timer throttling depending on plugin activation + m_nullEventTimer.set(new Timer(this, &PluginView::nullEventTimerFired)); + m_nullEventTimer->startRepeating(0.02); + + m_lastMousePos.h = m_lastMousePos.v = 0; + + return true; +} + +void PluginView::platformDestroy() +{ + if (platformPluginWidget()) + setPlatformPluginWidget(0); + else { + CGContextRelease(m_contextRef); +#ifndef NP_NO_CARBON + if (m_fakeWindow) + DisposeWindow(m_fakeWindow); +#endif + } +} + +// Used before the plugin view has been initialized properly, and as a +// fallback for variables that do not require a view to resolve. +bool PluginView::platformGetValueStatic(NPNVariable variable, void* value, NPError* result) +{ + switch (variable) { + case NPNVToolkit: + *static_cast(value) = 0; + *result = NPERR_NO_ERROR; + return true; + + case NPNVjavascriptEnabledBool: + *static_cast(value) = true; + *result = NPERR_NO_ERROR; + return true; + +#ifndef NP_NO_CARBON + case NPNVsupportsCarbonBool: + *static_cast(value) = true; + *result = NPERR_NO_ERROR; + return true; + +#endif + case NPNVsupportsCocoaBool: + *static_cast(value) = false; + *result = NPERR_NO_ERROR; + return true; + + // CoreGraphics is the only drawing model we support + case NPNVsupportsCoreGraphicsBool: + *static_cast(value) = true; + *result = NPERR_NO_ERROR; + return true; + +#ifndef NP_NO_QUICKDRAW + // QuickDraw is deprecated in 10.5 and not supported on 64-bit + case NPNVsupportsQuickDrawBool: +#endif + case NPNVsupportsOpenGLBool: + case NPNVsupportsCoreAnimationBool: + *static_cast(value) = false; + *result = NPERR_NO_ERROR; + return true; + + default: + return false; + } +} + +// Used only for variables that need a view to resolve +bool PluginView::platformGetValue(NPNVariable variable, void* value, NPError* error) +{ + return false; +} + +void PluginView::setParent(ScrollView* parent) +{ + LOG(Plugins, "PluginView::setParent(%p)", parent); + + Widget::setParent(parent); + + if (parent) + init(); +} + +// -------------- Geometry and painting ---------------- + +void PluginView::show() +{ + LOG(Plugins, "PluginView::show()"); + + setSelfVisible(true); + + Widget::show(); +} + +void PluginView::hide() +{ + LOG(Plugins, "PluginView::hide()"); + + setSelfVisible(false); + + Widget::hide(); +} + +void PluginView::setFocus() +{ + LOG(Plugins, "PluginView::setFocus()"); + + if (platformPluginWidget()) +#if PLATFORM(QT) + platformPluginWidget()->setFocus(Qt::OtherFocusReason); +#else + platformPluginWidget()->SetFocus(); +#endif + else + Widget::setFocus(); + + // TODO: Also handle and pass on blur events (focus lost) + +#ifndef NP_NO_CARBON + EventRecord record; + record.what = getFocusEvent; + record.message = 0; + record.when = TickCount(); + record.where = globalMousePosForPlugin(); + record.modifiers = GetCurrentKeyModifiers(); + + if (!dispatchNPEvent(record)) + LOG(Events, "PluginView::setFocus(): Get-focus event not accepted"); +#endif +} + +void PluginView::setParentVisible(bool visible) +{ + if (isParentVisible() == visible) + return; + + Widget::setParentVisible(visible); +} + +void PluginView::setNPWindowRect(const IntRect&) +{ + setNPWindowIfNeeded(); +} + +void PluginView::setNPWindowIfNeeded() +{ + if (!m_isStarted || !parent() || !m_plugin->pluginFuncs()->setwindow) + return; + + CGContextRef newContextRef = 0; + WindowRef newWindowRef = 0; + if (platformPluginWidget()) { + newContextRef = cgHandleFor(platformPluginWidget()); + newWindowRef = nativeWindowFor(platformPluginWidget()); + m_npWindow.type = NPWindowTypeWindow; + } else { + newContextRef = m_contextRef; + newWindowRef = m_fakeWindow; + m_npWindow.type = NPWindowTypeDrawable; + } + + if (!newContextRef || !newWindowRef) + return; + + m_npWindow.window = (void*)&m_npCgContext; +#ifndef NP_NO_CARBON + m_npCgContext.window = newWindowRef; +#endif + m_npCgContext.context = newContextRef; + + m_npWindow.x = m_windowRect.x(); + m_npWindow.y = m_windowRect.y(); + m_npWindow.width = m_windowRect.width(); + m_npWindow.height = m_windowRect.height(); + + // TODO: (also clip against scrollbars, etc.) + m_npWindow.clipRect.left = max(0, m_windowRect.x()); + m_npWindow.clipRect.top = max(0, m_windowRect.y()); + m_npWindow.clipRect.right = m_windowRect.x() + m_windowRect.width(); + m_npWindow.clipRect.bottom = m_windowRect.y() + m_windowRect.height(); + + LOG(Plugins, "PluginView::setNPWindowIfNeeded(): window=%p, context=%p," + " window.x:%d window.y:%d window.width:%d window.height:%d window.clipRect size:%dx%d", + newWindowRef, newContextRef, m_npWindow.x, m_npWindow.y, m_npWindow.width, m_npWindow.height, + m_npWindow.clipRect.right - m_npWindow.clipRect.left, m_npWindow.clipRect.bottom - m_npWindow.clipRect.top); + + PluginView::setCurrentPluginView(this); + JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly); + setCallingPlugin(true); + m_plugin->pluginFuncs()->setwindow(m_instance, &m_npWindow); + setCallingPlugin(false); + PluginView::setCurrentPluginView(0); +} + +void PluginView::updatePluginWidget() +{ + if (!parent()) + return; + + ASSERT(parent()->isFrameView()); + FrameView* frameView = static_cast(parent()); + + IntRect oldWindowRect = m_windowRect; + IntRect oldClipRect = m_clipRect; + + m_windowRect = frameView->contentsToWindow(frameRect()); + IntPoint offset = topLevelOffsetFor(platformPluginWidget()); + m_windowRect.move(offset.x(), offset.y()); + + if (!platformPluginWidget()) { + if (m_windowRect.size() != oldWindowRect.size()) { + CGContextRelease(m_contextRef); +#if PLATFORM(QT) + m_pixmap = QPixmap(m_windowRect.size()); + m_pixmap.fill(Qt::transparent); + m_contextRef = m_pixmap.isNull() ? 0 : qt_mac_cg_context(&m_pixmap); +#endif + } + } + + m_clipRect = windowClipRect(); + m_clipRect.move(-m_windowRect.x(), -m_windowRect.y()); + + if (platformPluginWidget() && (m_windowRect != oldWindowRect || m_clipRect != oldClipRect)) + setNPWindowIfNeeded(); +} + +void PluginView::paint(GraphicsContext* context, const IntRect& rect) +{ + if (!m_isStarted || m_status != PluginStatusLoadedSuccessfully) { + paintMissingPluginIcon(context, rect); + return; + } + + if (context->paintingDisabled()) + return; + + setNPWindowIfNeeded(); + + CGContextRef cgContext = m_npCgContext.context; + if (!cgContext) + return; + + CGContextSaveGState(cgContext); + if (platformPluginWidget()) { + IntPoint offset = frameRect().location(); + CGContextTranslateCTM(cgContext, offset.x(), offset.y()); + } + + IntRect targetRect(frameRect()); + targetRect.intersects(rect); + + // clip the context so that plugin only updates the interested area. + CGRect r; + r.origin.x = targetRect.x() - frameRect().x(); + r.origin.y = targetRect.y() - frameRect().y(); + r.size.width = targetRect.width(); + r.size.height = targetRect.height(); + CGContextClipToRect(cgContext, r); + + if (!platformPluginWidget() && m_isTransparent) { // clean the pixmap in transparent mode +#if PLATFORM(QT) + QPainter painter(&m_pixmap); + painter.setCompositionMode(QPainter::CompositionMode_Clear); + painter.fillRect(QRectF(r.origin.x, r.origin.y, r.size.width, r.size.height), Qt::transparent); +#endif + } + +#ifndef NP_NO_CARBON + EventRecord event; + event.what = updateEvt; + event.message = (long unsigned int)m_npCgContext.window; + event.when = TickCount(); + event.where.h = 0; + event.where.v = 0; + event.modifiers = GetCurrentKeyModifiers(); + + if (!dispatchNPEvent(event)) + LOG(Events, "PluginView::paint(): Paint event not accepted"); +#endif + + CGContextRestoreGState(cgContext); + + if (!platformPluginWidget()) { +#if PLATFORM(QT) + QPainter* painter = context->platformContext(); + painter->drawPixmap(targetRect.x(), targetRect.y(), m_pixmap, + targetRect.x() - frameRect().x(), targetRect.y() - frameRect().y(), targetRect.width(), targetRect.height()); +#endif + } +} + +void PluginView::invalidateRect(const IntRect& rect) +{ + if (platformPluginWidget()) +#if PLATFORM(QT) + platformPluginWidget()->update(convertToContainingWindow(rect)); +#else + platformPluginWidget()->RefreshRect(convertToContainingWindow(rect)); +#endif + else + invalidateWindowlessPluginRect(rect); +} + +void PluginView::invalidateRect(NPRect* rect) +{ + IntRect r(rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top); + invalidateRect(r); +} + +void PluginView::invalidateRegion(NPRegion region) +{ + // TODO: optimize + invalidate(); +} + +void PluginView::forceRedraw() +{ + notImplemented(); +} + + +// ----------------- Event handling -------------------- + +void PluginView::handleMouseEvent(MouseEvent* event) +{ + if (!m_isStarted) + return; + +#ifndef NP_NO_CARBON + EventRecord record; + + if (event->type() == eventNames().mousemoveEvent) { + // Mouse movement is handled by null timer events + m_lastMousePos = mousePosForPlugin(event); + return; + } else if (event->type() == eventNames().mouseoverEvent) { + record.what = adjustCursorEvent; + } else if (event->type() == eventNames().mouseoutEvent) { + record.what = adjustCursorEvent; + } else if (event->type() == eventNames().mousedownEvent) { + record.what = mouseDown; + // The plugin needs focus to receive keyboard events + if (Page* page = m_parentFrame->page()) + page->focusController()->setFocusedFrame(m_parentFrame); + m_parentFrame->document()->setFocusedNode(m_element); + } else if (event->type() == eventNames().mouseupEvent) { + record.what = mouseUp; + } else { + return; + } + record.where = mousePosForPlugin(event); + record.modifiers = modifiersForEvent(event); + + if (!event->buttonDown()) + record.modifiers |= btnState; + + if (event->button() == 2) + record.modifiers |= controlKey; + + if (!dispatchNPEvent(record)) { + if (record.what == adjustCursorEvent) + return; // Signals that the plugin wants a normal cursor + + LOG(Events, "PluginView::handleMouseEvent(): Mouse event type %d at %d,%d not accepted", + record.what, record.where.h, record.where.v); + } else { + event->setDefaultHandled(); + } +#endif +} + +void PluginView::handleKeyboardEvent(KeyboardEvent* event) +{ + if (!m_isStarted) + return; + + LOG(Plugins, "PluginView::handleKeyboardEvent() ----------------- "); + + LOG(Plugins, "PV::hKE(): KE.keyCode: 0x%02X, KE.charCode: %d", + event->keyCode(), event->charCode()); + +#ifndef NP_NO_CARBON + EventRecord record; + + if (event->type() == eventNames().keydownEvent) { + // This event is the result of a PlatformKeyboardEvent::KeyDown which + // was disambiguated into a PlatformKeyboardEvent::RawKeyDown. Since + // we don't have access to the text here, we return, and wait for the + // corresponding event based on PlatformKeyboardEvent::Char. + return; + } else if (event->type() == eventNames().keypressEvent) { + // Which would be this one. This event was disambiguated from the same + // PlatformKeyboardEvent::KeyDown, but to a PlatformKeyboardEvent::Char, + // which retains the text from the original event. So, we can safely pass + // on the event as a key-down event to the plugin. + record.what = keyDown; + } else if (event->type() == eventNames().keyupEvent) { + // PlatformKeyboardEvent::KeyUp events always have the text, so nothing + // fancy here. + record.what = keyUp; + } else { + return; + } + + const PlatformKeyboardEvent* platformEvent = event->keyEvent(); + int keyCode = platformEvent->nativeVirtualKeyCode(); + + const String text = platformEvent->text(); + if (text.length() < 1) { + event->setDefaultHandled(); + return; + } + + WTF::RetainPtr cfText(WTF::AdoptCF, text.createCFString()); + + LOG(Plugins, "PV::hKE(): PKE.text: %s, PKE.unmodifiedText: %s, PKE.keyIdentifier: %s", + text.ascii().data(), platformEvent->unmodifiedText().ascii().data(), + platformEvent->keyIdentifier().ascii().data()); + + char charCodes[2] = { 0, 0 }; + if (!CFStringGetCString(cfText.get(), charCodes, 2, CFStringGetSystemEncoding())) { + LOG_ERROR("Could not resolve character code using system encoding."); + event->setDefaultHandled(); + return; + } + + record.where = globalMousePosForPlugin(); + record.modifiers = modifiersForEvent(event); + record.message = ((keyCode & 0xFF) << 8) | (charCodes[0] & 0xFF); + record.when = TickCount(); + + LOG(Plugins, "PV::hKE(): record.modifiers: %d", record.modifiers); + +#if PLATFORM(QT) + LOG(Plugins, "PV::hKE(): PKE.qtEvent()->nativeVirtualKey: 0x%02X, charCode: %d", + keyCode, int(uchar(charCodes[0]))); +#endif + + if (!dispatchNPEvent(record)) + LOG(Events, "PluginView::handleKeyboardEvent(): Keyboard event type %d not accepted", record.what); + else + event->setDefaultHandled(); +#endif +} + +#ifndef NP_NO_CARBON +void PluginView::nullEventTimerFired(Timer*) +{ + EventRecord record; + + record.what = nullEvent; + record.message = 0; + record.when = TickCount(); + record.where = m_lastMousePos; + record.modifiers = GetCurrentKeyModifiers(); + if (!Button()) + record.modifiers |= btnState; + + if (!dispatchNPEvent(record)) + LOG(Events, "PluginView::nullEventTimerFired(): Null event not accepted"); +} +#endif + +#ifndef NP_NO_CARBON +static int modifiersForEvent(UIEventWithKeyState* event) +{ + int modifiers = 0; + + if (event->ctrlKey()) + modifiers |= controlKey; + + if (event->altKey()) + modifiers |= optionKey; + + if (event->metaKey()) + modifiers |= cmdKey; + + if (event->shiftKey()) + modifiers |= shiftKey; + + return modifiers; +} +#endif + +#ifndef NP_NO_CARBON +static bool tigerOrBetter() +{ + static SInt32 systemVersion = 0; + + if (!systemVersion) { + if (Gestalt(gestaltSystemVersion, &systemVersion) != noErr) + return false; + } + + return systemVersion >= 0x1040; +} +#endif + +#ifndef NP_NO_CARBON +Point PluginView::globalMousePosForPlugin() const +{ + Point pos; + GetGlobalMouse(&pos); + + float scaleFactor = tigerOrBetter() ? HIGetScaleFactor() : 1; + + pos.h = short(pos.h * scaleFactor); + pos.v = short(pos.v * scaleFactor); + +#if PLATFORM(WX) + // make sure the titlebar/toolbar size is included + WindowRef windowRef = nativeWindowFor(platformPluginWidget()); + ::Rect content, structure; + + GetWindowBounds(windowRef, kWindowStructureRgn, &structure); + GetWindowBounds(windowRef, kWindowContentRgn, &content); + + int top = content.top - structure.top; + pos.v -= top; +#endif + + return pos; +} +#endif + +#ifndef NP_NO_CARBON +Point PluginView::mousePosForPlugin(MouseEvent* event) const +{ + ASSERT(event); + if (platformPluginWidget()) + return globalMousePosForPlugin(); + + if (event->button() == 2) { + // always pass the global position for right-click since Flash uses it to position the context menu + return globalMousePosForPlugin(); + } + + Point pos; + IntPoint postZoomPos = roundedIntPoint(m_element->renderer()->absoluteToLocal(event->absoluteLocation())); + pos.h = postZoomPos.x() + m_windowRect.x(); + // The number 22 is the height of the title bar. As to why it figures in the calculation below + // is left as an exercise to the reader :-) + pos.v = postZoomPos.y() + m_windowRect.y() - 22; + return pos; +} +#endif + +#ifndef NP_NO_CARBON +bool PluginView::dispatchNPEvent(NPEvent& event) +{ + PluginView::setCurrentPluginView(this); + JSC::JSLock::DropAllLocks dropAllLocks(JSC::SilenceAssertionsOnly); + setCallingPlugin(true); + + bool accepted = m_plugin->pluginFuncs()->event(m_instance, &event); + + setCallingPlugin(false); + PluginView::setCurrentPluginView(0); + return accepted; +} +#endif + +// ------------------- Miscellaneous ------------------ + +NPError PluginView::handlePostReadFile(Vector& buffer, uint32 len, const char* buf) +{ + String filename(buf, len); + + if (filename.startsWith("file:///")) + filename = filename.substring(8); + + if (!fileExists(filename)) + return NPERR_FILE_NOT_FOUND; + + FILE* fileHandle = fopen((filename.utf8()).data(), "r"); + + if (fileHandle == 0) + return NPERR_FILE_NOT_FOUND; + + int bytesRead = fread(buffer.data(), 1, 0, fileHandle); + + fclose(fileHandle); + + if (bytesRead <= 0) + return NPERR_FILE_NOT_FOUND; + + return NPERR_NO_ERROR; +} + +void PluginView::halt() +{ +} + +void PluginView::restart() +{ +} + +} // namespace WebCore diff --git a/src/3rdparty/webkit/WebKit/qt/ChangeLog b/src/3rdparty/webkit/WebKit/qt/ChangeLog index 39f2cf3..61cee76 100644 --- a/src/3rdparty/webkit/WebKit/qt/ChangeLog +++ b/src/3rdparty/webkit/WebKit/qt/ChangeLog @@ -1,3 +1,27 @@ +2010-03-24 Viatcheslav Ostapenko + + Reviewed by Laszlo Gombos. + + Auto-uppercase and predictive text need to be disabled for S60 (as for maemo) + https://bugs.webkit.org/show_bug.cgi?id=33176 + + * WebCoreSupport/EditorClientQt.cpp: + +2010-06-01 Noam Rosenthal + + Reviewed by Kenneth Rohde Christiansen. + + [Qt] Add documentation to the QtWebkit bridge + https://bugs.webkit.org/show_bug.cgi?id=35861 + + This patch includes comprehensive qdoc documentation for the QtWebkit bridge. + + * docs/qtwebkit-bridge.qdoc: Added. + * docs/qtwebkit.qdoc: + * docs/webkitsnippets/doc_src_qtscript.qdoc: Added. + * docs/webkitsnippets/qtwebkit_bridge_snippets.cpp: Added. + (wrapInFunction): + 2010-06-01 Simon Hausmann Reviewed by Laszlo Gombos. diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/EditorClientQt.cpp b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/EditorClientQt.cpp index 7b7f610..0ce6383 100644 --- a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/EditorClientQt.cpp +++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/EditorClientQt.cpp @@ -613,11 +613,11 @@ void EditorClientQt::setInputMethodState(bool active) } } webPageClient->setInputMethodHint(Qt::ImhHiddenText, isPasswordField); -#ifdef Q_WS_MAEMO_5 - // Maemo 5 MicroB Browser disables auto-uppercase and predictive text, thus, so do we. +#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN) + // disables auto-uppercase and predictive text for mobile devices webPageClient->setInputMethodHint(Qt::ImhNoAutoUppercase, true); webPageClient->setInputMethodHint(Qt::ImhNoPredictiveText, true); -#endif // Q_WS_MAEMO_5 +#endif // Q_WS_MAEMO_5 || Q_OS_SYMBIAN #endif // QT_VERSION check webPageClient->setInputMethodEnabled(active); } diff --git a/src/3rdparty/webkit/WebKit/qt/docs/qtwebkit-bridge.qdoc b/src/3rdparty/webkit/WebKit/qt/docs/qtwebkit-bridge.qdoc new file mode 100644 index 0000000..4f41d29 --- /dev/null +++ b/src/3rdparty/webkit/WebKit/qt/docs/qtwebkit-bridge.qdoc @@ -0,0 +1,425 @@ +/*! + \inmodule QtWebKit + \page qtwebkit-bridge.html + \title The QtWebKit Bridge + \contentspage QtWebKit + \section1 Overview + \section2 The technology + + The QtWebKit bridge is a mechanism that extends WebKit's JavaScript environment to access native + objects that are represented as QObjects. It takes advantage of the inherent introspection of the + \l{Qt Object Model}, which has a natural alignment to the way JavaScript worked. + + For example, both JavaScript and QObjects have properties: a construct that represent a getter/setter + pair under one name. + + \section2 Use Cases + + There are two main use cases for the QtWebKit bridge. Web content in a native application, and Thin Client. + + \section3 Web Content in a Native Application + + This is a common use case in classic Qt application, and a design pattern used by several modern + applications. For example, an application that contains both a media-player, playlist manager, and + a music store. The playlist manager is usually best authored as a classic desktop application, + with the native-looking robust \l{QWidget}s helping with producing that application. + The media-player control, which usually looks custom, can be written using \l{The Graphics View framework} + or with in a declarative way with \l{QtDeclarative}. The music store, which shows dynamic content + from the internet, and gets modified rapidly, is best authored in HTML and maintained on the server. + + With the QtWebKit bridge, that music store component can interact with native parts of the application, + for example, if a file needs to be saved to a specific location. + + \section3 Thin Client + + Another use case is using Qt as a native backend to a full web application, + referred to here as a thin client. In this use-case, the entire UI is driven by + HTML, JavaScript and CSS, and native Qt-based components are used to allow that application + access to native features not usually exposed to the web, or to enable helper components that + are best written with C++. + + An example for such client is a UI for a video-on-demand service on a TV. The entire content and + UI can be kept on the server, served dynamically through HTTP and rendered with WebKit, with additional + native components for accessing hardware-specific features like extracting the list of images + out of the video. + + \section2 Difference from Other Bridge Technologies + + Of course QtWebKit is not the only bridge technology out there. NPAPI, for example, + is a long-time standard or web-native bridging. Due to Qt's meta-object system, full applications + built partially with web-technologies are much easier to develop. NPAPI, however, is more geared + towards cross-browser plugins, due to it being an accepted standard. + + When developing a plugin for a browser, NPAPI is recommended. When developing a full application + that utilizes HTML-rendering, the QtWebKit bridge is recommended. + + \section2 Relationship with QtScript + + The QtWebKit bridge is similar to \l{QtScript}, especially to some of the features described in the + \l{Making Applications Scriptable} page. However, as of Qt 4.7, full QtScript API is not supported for web applications. + That is planned as an enhancement for future versions. You might notice that some of the features + described here are an exact copy of the ones described in the \l{Making Applications Scriptable} page. That is because + the QtWebKit bridge is a subset of that functionality, and this page tries to capture the full + capabilities available through the QtWebKit bridge specifically. + + \section1 Accessing QObjects + + \section2 Creating the link via QWebFrame + + By default, no QObjects are accessible through the web environment, for security reasons. + To enable web content access to a native QObject, the application has to explicitly grant it access, + using the following call: + + \snippet webkitsnippets/qtwebkit_bridge_snippets.cpp 0 + + See \l{QWebFrame::addToJavaScriptWindowObject()} for more information. + + \section2 Using Signals and Slots + + Qt Script adapts Qt's central \l{Signals and Slots} feature for + scripting. There are three principal ways to use signals and slots + with Qt Script: + + \list + \i \bold{Hybrid C++/script}: C++ application code connects a + signal to a script function. The script function can, for example, be + a function that the user has typed in, or one that you have read from a + file. This approach is useful if you have a QObject but don't want + to expose the object itself to the scripting environment; you just + want a script to be able to define how a signal should be reacted + to, and leave it up to the C++ side of your application to establish + the connection. + + \i \bold{Hybrid script/C++}: A script can connect signals and slots + to establish connections between pre-defined objects that the + application exposes to the scripting environment. In this scenario, + the slots themselves are still written in C++, but the definition of + the connections is fully dynamic (script-defined). + + \i \bold{Purely script-defined}: A script can both define signal + handler functions (effectively "slots written in Qt Script"), + \e{and} set up the connections that utilize those handlers. For + example, a script can define a function that will handle the + QLineEdit::returnPressed() signal, and then connect that signal to the + script function. + \endlist + + Note that QtScript functions such as qScriptConnect are unavilable in the web environment. + + \section3 Signal to Function Connections + + \c{connect(function)} + + In this form of connection, the argument to \c{connect()} is the + function to connect to the signal. + + \snippet webkitsnippets/doc_src_qtscript.qdoc 2 + + The argument can be a Qt Script function, as in the above + example, or it can be a QObject slot, as in + the following example: + + \snippet webkitsnippets/doc_src_qtscript.qdoc 3 + + When the argument is a QObject slot, the argument types of the + signal and slot do not necessarily have to be compatible; + the QtWebKit bridge will, if necessary, perform conversion of the signal + arguments to match the argument types of the slot. + + To disconnect from a signal, you invoke the signal's + \c{disconnect()} function, passing the function to disconnect + as argument: + + \snippet webkitsnippets/doc_src_qtscript.qdoc 4 + + When a script function is invoked in response to a signal, the + \c this object will be the Global Object. + + \section3 Signal to Member Function Connections + + \c{connect(thisObject, function)} + + In this form of the \c{connect()} function, the first argument + is the object that will be bound to the variable, \c this, when + the function specified using the second argument is invoked. + + If you have a push button in a form, you typically want to do + something involving the form in response to the button's + \c{clicked} signal; passing the form as the \c this object + makes sense in such a case. + + \snippet webkitsnippets/doc_src_qtscript.qdoc 5 + + To disconnect from the signal, pass the same arguments to \c{disconnect()}: + + \snippet webkitsnippets/doc_src_qtscript.qdoc 6 + + \section3 Signal to Named Member Function Connections + + \c{connect(thisObject, functionName)} + + In this form of the \c{connect()} function, the first argument is + the object that will be bound to the variable, \c this, when + a function is invoked in response to the signal. The second argument + specifies the name of a function that is connected to the signal, + and this refers to a member function of the object passed as the + first argument (\c thisObject in the above scheme). + + Note that the function is resolved when the connection is made, not + when the signal is emitted. + + \snippet webkitsnippets/doc_src_qtscript.qdoc 7 + + To disconnect from the signal, pass the same arguments to \c{disconnect()}: + + \snippet webkitsnippets/doc_src_qtscript.qdoc 8 + + \section3 Error Handling + + When \c{connect()} or \c{disconnect()} succeeds, the function will + return \c{undefined}; otherwise, it will throw a script exception. + You can obtain an error message from the resulting \c{Error} object. + Example: + + \snippet webkitsnippets/doc_src_qtscript.qdoc 9 + + \section3 Emitting Signals from Scripts + + To emit a signal from script code, you simply invoke the signal + function, passing the relevant arguments: + + \snippet webkitsnippets/doc_src_qtscript.qdoc 10 + + It is currently not possible to define a new signal in a script; + i.e., all signals must be defined by C++ classes. + + \section3 Overloaded Signals and Slots + + When a signal or slot is overloaded, the QtWebKit bridge will attempt to + pick the right overload based on the actual types of the QScriptValue arguments + involved in the function invocation. For example, if your class has slots + \c{myOverloadedSlot(int)} and \c{myOverloadedSlot(QString)}, the following + script code will behave reasonably: + + \snippet webkitsnippets/doc_src_qtscript.qdoc 11 + + You can specify a particular overload by using array-style property access + with the \l{QMetaObject::normalizedSignature()}{normalized signature} of + the C++ function as the property name: + + \snippet webkitsnippets/doc_src_qtscript.qdoc 12 + + If the overloads have different number of arguments, the QtWebKit bridge will + pick the overload with the argument count that best matches the + actual number of arguments passed to the slot. + + For overloaded signals, JavaScript will throw an error if you try to connect + to the signal by name; you have to refer to the signal with the full + normalized signature of the particular overload you want to connect to. + + \section3 Invokable Methods + + Both slots and signals are invokable from script by default. In addition, it's also + possible to define a method that's invokable from script without it being a signal or a slot. + This is especially useful for functions with return types, as slots normally do not return anything + (it would be meaningless to return values from a slot, as the connected signals don't handle the returned data). + To make a non-slot method invokable, simply add the Q_INVOKABLE macro before its definition: + + \snippet webkitsnippets/doc_src_qtscript.qdoc 20 + + \section2 Accessing Properties + + The properties of the QObject are available as properties + of the corresponding JavaScript object. When you manipulate + a property in script code, the C++ get/set method for that + property will automatically be invoked. For example, if your + C++ class has a property declared as follows: + + \snippet webkitsnippets/doc_src_qtscript.qdoc 13 + + then script code can do things like the following: + + \snippet webkitsnippets/doc_src_qtscript.qdoc 14 + + \section2 Accessing Child QObjects + + Every named child of the QObject (that is, for which + QObject::objectName() is not an empty string) is by default available as + a property of the JavaScript wrapper object. For example, + if you have a QDialog with a child widget whose \c{objectName} property is + \c{"okButton"}, you can access this object in script code through + the expression + + \snippet webkitsnippets/doc_src_qtscript.qdoc 15 + + Since \c{objectName} is itself a Q_PROPERTY, you can manipulate + the name in script code to, for example, rename an object: + + \snippet webkitsnippets/doc_src_qtscript.qdoc 16 + + \section2 Data types + + When calling slots, receiving signals or accessing properties, usually some payload is involved. + For example, a property "text" might return a \l{QString} parameter. + The QtWebKit bridge does the job of converting between a given JavaScript data-type, and the + expected or given Qt type. Each Qt type has a coresponding set of rules of how JavaScript treats it. + + The data type conversions are also applicable for the data returned from non-void invokable methods. + + \section3 Numbers + + All Qt numeric data types are converted to or from a JavaScript number. These include int, short, float, + double, and the porable Qt types (qreal, qint etc). A special case is \l{QChar}; + If a slot expects a QChar, the QtWebKit bridge would use the unicode value in case of a number, + or the first character in a string. + + Note that non-standard (typedefed) number types are not automatically converted to + or from a JavaScript number - it's advised to use standard number types for signal, slots + and properties. + + When a non-number is passed as an argument to a method or property that expects a number, + the appropriate JavaScript conversion function (parseInt / parseFloat) would be used. + + \section3 Strings + + When JavaScript accesses methods or properties that expect a \l{QString}, the QtWebKit bridge + will automatically convert the value to a string (if it's not already a string), using the + built-in JavaScript toString method. + + When a QString is passed to JavaScript from a signal or a property, The QtWebKit bridge will + convert it into a JavaScript string. + + \section3 Date & Time + + Both \l{QDate}, \l{QTime} and \l{QDateTime} are automatically translated to or from the JavaScript + Date object. If a number is passed as an argument to a method that expects one of the date/time + types, the QtWebKit bridge would treat it as a timestamp. If a sting is passed, QtWebKit would + try different Qt date parsing functions to find the right one. + + \section3 Regular Expressions + + The QtWebKit bridge would automatically convert JavaScript RegEx object to a \l{QRegExp}. + If a string is passed to a method expecting a \l{QRegExp}, the string would be converted + to that \l{QRegExp}. + + \section3 Lists + + The QtWebKit bridge treats several types of lists in a special way: \l{QVariantList}, \l{QStringList}, + \l{QObjectList} and \l{QList}. When a slot or property expects one of those list types, + the QtWebKit bridge would try to convert a JavaScript array into that type, converting each of + the array's elements to the single-element type of the list. + + The most useful type of list is perhaps \l{QVariantList}, which can be converted to from any + JavaScript array. + + \section3 Compound (JSON) objects + + JavaScript compound objects, also known as JSON objects, are variables which hold a list + of key-value pairs, where all the keys are strings and the values can have any type. + This translates very well to \l{QVariantMap}, which is nothing more than a \l{QMap} of \l{QString} + to \l{QVariant}. + + The seamless conversion between JSON objects and \l{QVariantMap} allows for a very convenient + way of passing arbitrary structured data between C++ and the JavaScript environment. The native \l{QObject} has + to make sure that compound values are converted to \l{QVariantMap}s and \l{QVariantList}s, and JavaScript is + guaranteed to receive them in a meaningful way. + + Note that types that are not supported by JSON, such as JavaScript functions and getters/setters, + are not converted. + + \section3 QVariants + + When a slot or property accepts a \l{QVariant}, the QtWebKit bridge would create a \l{QVariant} that best + matches the argument passed by JavaScript. A string, for example, would become a \l{QVariant} holding a \l{QString}, + a normal JSON object would become a \l{QVariantMap}, and a JavaScript array would become a \l{QVariantList}. + + Using \l{QVariant}s generously in C++ in that way makes C++ programming feel a bit more like JavaScript programming, + as it adds another level of indirection - passing \l{QVariant}s around is very flexible, as the program can figure out + the type of argument in runtime just like JavaScript would do, but it also takes away from the type-safety and robust + nature of C++. It's recommended to use \l{QVariant}s only for convenience high-level functions, and to keep most of your + \l{QObject}s somewhat type-safe. + + \section3 QObjects + + A pointer to a \l{QObject} or a \l{QWidget} can be passed as payload in signals, slots and properties. That object + can then be used like an object that's exposed directly; i.e. its slots can be invoked, its signals connected to etc. + However, this functionality is fairly limited - the type used has to be \l{QObject}* or \l{QWidget}*. If the type + specified is a pointer to a non-\l{QWidget} subclass of \l{QObject}, the QtWebKit bridge would not recognize it to be + a \l{QObject}. + + In general its advised to use care when passing \l{QObject}s as arguments, as those objects don't become owned by + the Javascipt engine; That means that the application developer has to be extra careful not to try to access + \l{QObject}s that have already been deleted by the native environment. + + \section3 Pixmaps and Images + + \since 4.7 + + The QtWebKit bridge handles \l{QPixmap}s and \l{QImage}s in a special way. Since QtWebKit stores \l{QPixmap}s to + represent HTML images, \l{QPixmap}s coming from the native environment can be used directly inside WebKit. + A \l{QImage} or a \l{QPixmap} coming from the Qt environment would convert to an intermediate JavaScript object, + that can be represented like this: + + \snippet webkitsnippets/qtwebkit_bridge_snippets.cpp 1 + + The JavaScript environment can then use the pixmap it gets from Qt and display it inside the HTML environment, + by assigning it to an existing element using assignToHTMLImageElement. It can also use the toDataURL() function, + which allows using the pixmap as the src attribute of an image or as a background-image url. Note that the toDataURL() + function is costly and should be used with caution. + + Example code: + + C++: + \snippet webkitsnippets/qtwebkit_bridge_snippets.cpp 2 + + HTML: + \snippet webkitsnippets/qtwebkit_bridge_snippets.cpp 3 + + When a Qt object expects a \l{QImage} or a \l{QPixmap} as input, and the argument passed is an HTML image element, + the QtWebKit bridge would convert the pixmap assigned to that image element into a \l{QPixmap} or a \l{QImage}. + + \since 4.7 + + \section3 QWebElement + + A signal, slot or property that expects or returns a \l{QWebElement} can work seamlessly with JavaScript references + to DOM elements. The JavaScript environment can select DOM elements, keep them in variables, then pass them to Qt as + a \l{QWebElement}, and receive them back. Example: + + C++: + \snippet webkitsnippets/qtwebkit_bridge_snippets.cpp 4 + + HTML: + \snippet webkitsnippets/qtwebkit_bridge_snippets.cpp 5 + + This is specifically useful to create custom renderers or extensions to the web environment. Instead of forcing Qt + to select the element, the web environment already selects the element and then send the selected element directly to Qt. + + Note that \l{QWebElement}s are not thread safe - an object handling them has to live in the UI thread. + + \section1 Architecture issues + + \section2 Limiting the Scope of the Hybrid Layer + + When using QtWebKit's hybrid features, it's a common pitfall to make the API exposed to JavaScript very rich and + use all its features. This, however, leads to complexity and can create bugs that are hard to trace. + Instead, it's advisable to keep the hybrid layer small and manageable: create a gate only when + there's an actual need for it, i.e. there's a new native enabler that requires a direct interface + to the application layer. Sometimes new functionality is better handled internally in the native layer + or in the web layer; simplicity is your friend. + + This usually becomes more apparent when the hybrid layer can create or destroy objects, or uses + signals slots or properties with a \l{QObject}* argument. It's advised to be very careful and to treat + an exposed \l{QObject} as a system - with careful attention to memory management and object ownership. + + \section2 Internet Security + + When exposing native object to an open web environment, it's important to understand the security + implications. Think whether the exposed object enables the web environment access to things that + shouldn't be open, and whether the web content loaded by that web page comes from a trusted. In general, when + exposing native QObjects that give the web environment access to private information or to functionality + that's potentially harmful to the client, such exposure should be balanced by limiting the web page's + access to trusted URLs only with HTTPS and other security measures. + + +*/ diff --git a/src/3rdparty/webkit/WebKit/qt/docs/qtwebkit.qdoc b/src/3rdparty/webkit/WebKit/qt/docs/qtwebkit.qdoc index c6dd550..d3f5502 100644 --- a/src/3rdparty/webkit/WebKit/qt/docs/qtwebkit.qdoc +++ b/src/3rdparty/webkit/WebKit/qt/docs/qtwebkit.qdoc @@ -20,8 +20,9 @@ scripted with JavaScript. A bridge between the JavaScript execution environment and the Qt object - model makes it possible for custom QObjects to be scripted. Integration - with the Qt networking module enables Web pages to be transparently loaded + model makes it possible for custom QObjects to be scripted. For detailed + documentation see \l{The QtWebkit Bridge}. + Integration with the Qt networking module enables Web pages to be transparently loaded from Web servers, the local file system or even the Qt resource system. In addition to providing pure rendering features, HTML documents can be diff --git a/src/3rdparty/webkit/WebKit/qt/docs/webkitsnippets/qtwebkit_bridge_snippets.cpp b/src/3rdparty/webkit/WebKit/qt/docs/webkitsnippets/qtwebkit_bridge_snippets.cpp new file mode 100644 index 0000000..d83ab3f --- /dev/null +++ b/src/3rdparty/webkit/WebKit/qt/docs/webkitsnippets/qtwebkit_bridge_snippets.cpp @@ -0,0 +1,83 @@ + +void wrapInFunction() +{ + +//! [0] + // ... + QWebFrame *frame = myWebPage->mainFrame(); + frame->addToJavaScriptWindowObject("someNameForMyObject", myObject); + // ... +//! [0] +#if 0 + //! [1] + { + width: ..., + height: ..., + toDataURL: function() { ... }, + assignToHTMLImageElement: function(element) { ... } + } + //! [1] +#endif + //! [2] + class MyObject : QObject { + Q_OBJECT + Q_PROPERTY(QPixmap myPixmap READ getPixmap) + + public: + QPixmap getPixmap() const; + }; + + /* ... */ + + MyObject myObject; + myWebPage.mainFrame()->addToJavaScriptWindowObject("myObject", &myObject); + + //! [2] + #if 0 + //! [3] + + + + + + + + + //! [3] + #endif + //! [4] + class MyObject : QObject { + Q_OBJECT + + public slots: + void doSomethingWithWebElement(const QWebElement&); + }; + + /* ... */ + + MyObject myObject; + myWebPage.mainFrame()->addToJavaScriptWindowObject("myObject", &myObject); + + //! [4] + #if 0 + //! [5] + + + + + + Text + + + //! [5] + #endif +} + -- cgit v0.12 From fec2bc79158a4d0c5aebf99429cfdd945d4e8341 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 4 Jun 2010 17:11:09 +0200 Subject: Updated WebKit to 903617844b4341f7098b63b54e5be16cd83af647 || || [Qt] Compilation fails when compiling against Qt 4.7 and Qt Mobility is installed || --- src/3rdparty/webkit/.tag | 2 +- src/3rdparty/webkit/VERSION | 2 +- src/3rdparty/webkit/WebCore/ChangeLog | 12 ++++++++++++ src/3rdparty/webkit/WebCore/WebCore.pro | 8 ++++++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/3rdparty/webkit/.tag b/src/3rdparty/webkit/.tag index 24fdc2a..67436cf 100644 --- a/src/3rdparty/webkit/.tag +++ b/src/3rdparty/webkit/.tag @@ -1 +1 @@ -903617844b4341f7098b63b54e5be16cd83af647 +6db5de6d18c3ab8b74809303e4d79abacfc570a8 diff --git a/src/3rdparty/webkit/VERSION b/src/3rdparty/webkit/VERSION index 211921d..df9a5e8 100644 --- a/src/3rdparty/webkit/VERSION +++ b/src/3rdparty/webkit/VERSION @@ -4,4 +4,4 @@ This is a snapshot of the Qt port of WebKit from and has the sha1 checksum - de1e909b06cbc981d63e0fc0f6a3f84002dd1e80 + 903617844b4341f7098b63b54e5be16cd83af647 diff --git a/src/3rdparty/webkit/WebCore/ChangeLog b/src/3rdparty/webkit/WebCore/ChangeLog index 57e0e44..9d1d1b9 100644 --- a/src/3rdparty/webkit/WebCore/ChangeLog +++ b/src/3rdparty/webkit/WebCore/ChangeLog @@ -1,3 +1,15 @@ +2010-06-04 Simon Hausmann + + Reviewed by Tor Arne Vestbø. + + [Qt] Compilation fails when compiling against Qt 4.7 and Qt Mobility is installed + https://bugs.webkit.org/show_bug.cgi?id=40116 + + CONFIG += mobility has the side-effect of pulling in mobility includes, which conflict + with Qt 4.7's bearer managenent includes and break the build. + + * WebCore.pro: + 2010-06-03 Tor Arne Vestbø Reviewed by Simon Hausmann. diff --git a/src/3rdparty/webkit/WebCore/WebCore.pro b/src/3rdparty/webkit/WebCore/WebCore.pro index ba669bd..048fc93 100644 --- a/src/3rdparty/webkit/WebCore/WebCore.pro +++ b/src/3rdparty/webkit/WebCore/WebCore.pro @@ -2496,8 +2496,12 @@ contains(DEFINES, ENABLE_QT_BEARER=1) { SOURCES += \ platform/network/qt/NetworkStateNotifierQt.cpp - CONFIG += mobility - MOBILITY += bearer + # Bearer management is part of Qt 4.7, so don't accidentially + # pull in Qt Mobility when building against >= 4.7 + !greaterThan(QT_MINOR_VERSION, 6) { + CONFIG += mobility + MOBILITY += bearer + } } contains(DEFINES, ENABLE_SVG=1) { -- cgit v0.12