diff options
author | Jocelyn Turcotte <jocelyn.turcotte@nokia.com> | 2010-04-06 12:36:47 +0200 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@nokia.com> | 2010-04-06 12:36:47 +0200 |
commit | bb35b65bbfba82e0dd0ac306d3dab54436cdaff6 (patch) | |
tree | 8174cb262a960ff7b2e4aa8f1aaf154db71d2636 /src/3rdparty/webkit/WebKit/qt/WebCoreSupport | |
parent | 4b27d0d887269583a0f76e922948f8c25e96ab88 (diff) | |
download | qt4-tools-bb35b65bbfba82e0dd0ac306d3dab54436cdaff6.tar.gz |
Update src/3rdparty/webkit from trunk.
Imported from 839d8709327f925aacb3b6362c06152594def97e
in branch qtwebkit-2.0 of repository
git://gitorious.org/+qtwebkit-developers/webkit/qtwebkit.git
Rubber-stamped-by: Simon Hausmann
Diffstat (limited to 'src/3rdparty/webkit/WebKit/qt/WebCoreSupport')
13 files changed, 1058 insertions, 257 deletions
diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp index 0c5df4a794..45986b38b5 100644 --- a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp +++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp @@ -25,6 +25,7 @@ * (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 "ChromeClientQt.h" @@ -35,11 +36,23 @@ #include "FrameLoaderClientQt.h" #include "FrameView.h" #include "HitTestResult.h" +#include "Icon.h" #include "NotImplemented.h" +#include "ScrollbarTheme.h" #include "WindowFeatures.h" #include "DatabaseTracker.h" -#include "SecurityOrigin.h" +#if defined(Q_WS_MAEMO_5) +#include "QtMaemoWebPopup.h" +#else +#include "QtFallbackWebPopup.h" +#endif #include "QWebPageClient.h" +#include "SecurityOrigin.h" + +#include <qdebug.h> +#include <qeventloop.h> +#include <qtextdocument.h> +#include <qtooltip.h> #include "qwebpage.h" #include "qwebpage_p.h" @@ -48,22 +61,23 @@ #include "qwebsecurityorigin_p.h" #include "qwebview.h" -#include <qtooltip.h> -#include <qtextdocument.h> - -namespace WebCore -{ +#if USE(ACCELERATED_COMPOSITING) +#include "GraphicsLayerQt.h" +#endif +namespace WebCore { ChromeClientQt::ChromeClientQt(QWebPage* webPage) : m_webPage(webPage) + , m_eventLoop(0) { toolBarsVisible = statusBarVisible = menuBarVisible = true; } ChromeClientQt::~ChromeClientQt() { - + if (m_eventLoop) + m_eventLoop->exit(); } void ChromeClientQt::setWindowRect(const FloatRect& rect) @@ -141,6 +155,11 @@ void ChromeClientQt::takeFocus(FocusDirection) } +void ChromeClientQt::focusedNodeChanged(WebCore::Node*) +{ +} + + Page* ChromeClientQt::createWindow(Frame*, const FrameLoadRequest& request, const WindowFeatures& features) { QWebPage *newPage = m_webPage->createWindow(features.dialog ? QWebPage::WebModalDialog : QWebPage::WebBrowserWindow); @@ -163,14 +182,16 @@ void ChromeClientQt::show() bool ChromeClientQt::canRunModal() { - notImplemented(); - return false; + return true; } void ChromeClientQt::runModal() { - notImplemented(); + m_eventLoop = new QEventLoop(); + QEventLoop* eventLoop = m_eventLoop; + m_eventLoop->exec(); + delete eventLoop; } @@ -309,26 +330,62 @@ bool ChromeClientQt::tabsToLinks() const IntRect ChromeClientQt::windowResizerRect() const { - return IntRect(); + if (!m_webPage) + return IntRect(); + + QWebPageClient* pageClient = platformPageClient(); + if (!pageClient) + return IntRect(); + + QWidget* ownerWidget = pageClient->ownerWidget(); + if (!ownerWidget) + return IntRect(); + + QWidget* topLevelWidget = ownerWidget->topLevelWidget(); + QRect topLevelGeometry(topLevelWidget->geometry()); + + // There's no API in Qt to query for the size of the resizer, so we assume + // it has the same width and height as the scrollbar thickness. + int scollbarThickness = ScrollbarTheme::nativeTheme()->scrollbarThickness(); + + // There's no API in Qt to query for the position of the resizer. Sometimes + // it's drawn by the system, and sometimes it's a QSizeGrip. For RTL locales + // it might even be on the lower left side of the window, but in WebKit we + // always draw scrollbars on the right hand side, so we assume this to be the + // location when computing the resize rect to reserve for WebKit. + QPoint resizeCornerTopLeft = ownerWidget->mapFrom(topLevelWidget, + QPoint(topLevelGeometry.width(), topLevelGeometry.height()) + - QPoint(scollbarThickness, scollbarThickness)); + + QRect resizeCornerRect = QRect(resizeCornerTopLeft, QSize(scollbarThickness, scollbarThickness)); + return resizeCornerRect.intersected(pageClient->geometryRelativeToOwnerWidget()); +} + +void ChromeClientQt::invalidateWindow(const IntRect&, bool) +{ + notImplemented(); } -void ChromeClientQt::repaint(const IntRect& windowRect, bool contentChanged, bool, bool) +void ChromeClientQt::invalidateContentsAndWindow(const IntRect& windowRect, bool immediate) { // No double buffer, so only update the QWidget if content changed. - if (contentChanged) { - if (platformPageClient()) { - QRect rect(windowRect); - rect = rect.intersected(QRect(QPoint(0, 0), m_webPage->viewportSize())); - if (!rect.isEmpty()) - platformPageClient()->update(rect); - } - emit m_webPage->repaintRequested(windowRect); + if (platformPageClient()) { + QRect rect(windowRect); + rect = rect.intersected(QRect(QPoint(0, 0), m_webPage->viewportSize())); + if (!rect.isEmpty()) + platformPageClient()->update(rect); } + emit m_webPage->repaintRequested(windowRect); // FIXME: There is no "immediate" support for window painting. This should be done always whenever the flag // is set. } +void ChromeClientQt::invalidateContentsForSlowScroll(const IntRect& windowRect, bool immediate) +{ + invalidateContentsAndWindow(windowRect, immediate); +} + void ChromeClientQt::scroll(const IntSize& delta, const IntRect& scrollViewRect, const IntRect&) { if (platformPageClient()) @@ -448,6 +505,11 @@ void ChromeClientQt::runOpenPanel(Frame* frame, PassRefPtr<FileChooser> prpFileC } } +void ChromeClientQt::chooseIconForFiles(const Vector<String>& filenames, PassRefPtr<FileChooser> chooser) +{ + chooser->iconLoaded(Icon::createIconForFiles(filenames)); +} + bool ChromeClientQt::setCursor(PlatformCursorHandle) { notImplemented(); @@ -460,4 +522,57 @@ void ChromeClientQt::requestGeolocationPermissionForFrame(Frame*, Geolocation*) notImplemented(); } +#if USE(ACCELERATED_COMPOSITING) +void ChromeClientQt::attachRootGraphicsLayer(Frame* frame, GraphicsLayer* graphicsLayer) +{ + if (platformPageClient()) + platformPageClient()->setRootGraphicsLayer(graphicsLayer ? graphicsLayer->nativeLayer() : 0); +} + +void ChromeClientQt::setNeedsOneShotDrawingSynchronization() +{ + // we want the layers to synchronize next time we update the screen anyway + if (platformPageClient()) + platformPageClient()->markForSync(false); +} + +void ChromeClientQt::scheduleCompositingLayerSync() +{ + // we want the layers to synchronize ASAP + if (platformPageClient()) + platformPageClient()->markForSync(true); +} +#endif + +QtAbstractWebPopup* ChromeClientQt::createSelectPopup() +{ +#if defined(Q_WS_MAEMO_5) + return new QtMaemoWebPopup; +#else + return new QtFallbackWebPopup; +#endif +} + +#if ENABLE(WIDGETS_10_SUPPORT) +bool ChromeClientQt::isDocked() +{ + return m_webPage->d->viewMode == "mini"; +} + +bool ChromeClientQt::isFloating() +{ + return m_webPage->d->viewMode == "floating"; +} + +bool ChromeClientQt::isApplication() +{ + return m_webPage->d->viewMode == "application"; +} + +bool ChromeClientQt::isFullscreen() +{ + return m_webPage->d->viewMode == "fullscreen"; +} +#endif + } diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/ChromeClientQt.h b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/ChromeClientQt.h index 196c4fcd0a..90ad29e313 100644 --- a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/ChromeClientQt.h +++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/ChromeClientQt.h @@ -34,6 +34,7 @@ #include "KURL.h" #include "PlatformString.h" +class QEventLoop; class QWebPage; namespace WebCore { @@ -42,6 +43,7 @@ namespace WebCore { class FloatRect; class Page; struct FrameLoadRequest; + class QtAbstractWebPopup; class ChromeClientQt : public ChromeClient { @@ -63,6 +65,8 @@ namespace WebCore { virtual bool canTakeFocus(FocusDirection); virtual void takeFocus(FocusDirection); + virtual void focusedNodeChanged(Node*); + virtual Page* createWindow(Frame*, const FrameLoadRequest&, const WindowFeatures&); virtual void show(); @@ -101,8 +105,11 @@ namespace WebCore { virtual bool tabsToLinks() const; virtual IntRect windowResizerRect() const; - virtual void repaint(const IntRect&, bool contentChanged, bool immediate = false, bool repaintContentOnly = false); + virtual void invalidateWindow(const IntRect&, bool); + virtual void invalidateContentsAndWindow(const IntRect&, bool); + virtual void invalidateContentsForSlowScroll(const IntRect&, bool); virtual void scroll(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect); + virtual IntPoint screenToWindow(const IntPoint&) const; virtual IntRect windowToScreen(const IntRect&) const; virtual PlatformPageClient platformPageClient() const; @@ -120,7 +127,21 @@ namespace WebCore { #if ENABLE(OFFLINE_WEB_APPLICATIONS) virtual void reachedMaxAppCacheSize(int64_t spaceNeeded); #endif + +#if USE(ACCELERATED_COMPOSITING) + // see ChromeClient.h + // this is a hook for WebCore to tell us what we need to do with the GraphicsLayers + virtual void attachRootGraphicsLayer(Frame*, GraphicsLayer*); + virtual void setNeedsOneShotDrawingSynchronization(); + virtual void scheduleCompositingLayerSync(); +#endif + +#if ENABLE(TOUCH_EVENTS) + virtual void needTouchEvents(bool) { } +#endif + virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>); + virtual void chooseIconForFiles(const Vector<String>&, PassRefPtr<FileChooser>); virtual void formStateDidChange(const Node*) { } @@ -131,6 +152,16 @@ namespace WebCore { virtual void scrollRectIntoView(const IntRect&, const ScrollView*) const {} virtual void requestGeolocationPermissionForFrame(Frame*, Geolocation*); + virtual void cancelGeolocationPermissionRequestForFrame(Frame*) { } + +#if ENABLE(WIDGETS_10_SUPPORT) + virtual bool isDocked(); + virtual bool isFloating(); + virtual bool isApplication(); + virtual bool isFullscreen(); +#endif + + QtAbstractWebPopup* createSelectPopup(); QWebPage* m_webPage; WebCore::KURL lastHoverURL; @@ -140,6 +171,7 @@ namespace WebCore { bool toolBarsVisible; bool statusBarVisible; bool menuBarVisible; + QEventLoop* m_eventLoop; }; } diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/DragClientQt.cpp b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/DragClientQt.cpp index 99e438d50f..e48c3e3ab7 100644 --- a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/DragClientQt.cpp +++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/DragClientQt.cpp @@ -27,6 +27,8 @@ #include "DragClientQt.h" #include "ClipboardQt.h" +#include "Frame.h" +#include "PlatformMouseEvent.h" #include "qwebpage.h" #include <QDrag> @@ -35,6 +37,32 @@ namespace WebCore { +static inline Qt::DropActions dragOperationsToDropActions(unsigned op) +{ + Qt::DropActions result = Qt::IgnoreAction; + if (op & DragOperationCopy) + result = Qt::CopyAction; + if (op & DragOperationMove) + result |= Qt::MoveAction; + if (op & DragOperationGeneric) + result |= Qt::MoveAction; + if (op & DragOperationLink) + result |= Qt::LinkAction; + return result; +} + +static inline DragOperation dropActionToDragOperation(Qt::DropActions action) +{ + DragOperation result = DragOperationNone; + if (action & Qt::CopyAction) + result = DragOperationCopy; + if (action & Qt::LinkAction) + result = DragOperationLink; + if (action & Qt::MoveAction) + result = DragOperationMove; + return result; +} + DragDestinationAction DragClientQt::actionMaskForDrag(DragData*) { return DragDestinationActionAny; @@ -58,7 +86,7 @@ void DragClientQt::willPerformDragSourceAction(DragSourceAction, const IntPoint& { } -void DragClientQt::startDrag(DragImageRef, const IntPoint&, const IntPoint&, Clipboard* clipboard, Frame*, bool) +void DragClientQt::startDrag(DragImageRef, const IntPoint&, const IntPoint&, Clipboard* clipboard, Frame* frame, bool) { #ifndef QT_NO_DRAGANDDROP QMimeData* clipboardData = static_cast<ClipboardQt*>(clipboard)->clipboardData(); @@ -66,10 +94,15 @@ void DragClientQt::startDrag(DragImageRef, const IntPoint&, const IntPoint&, Cli QWidget* view = m_webPage->view(); if (view) { QDrag *drag = new QDrag(view); - if (clipboardData->hasImage()) + if (clipboardData && clipboardData->hasImage()) drag->setPixmap(qvariant_cast<QPixmap>(clipboardData->imageData())); + DragOperation dragOperationMask = clipboard->sourceOperation(); drag->setMimeData(clipboardData); - drag->start(); + Qt::DropAction actualDropAction = drag->exec(dragOperationsToDropActions(dragOperationMask)); + + // Send dragEnd event + PlatformMouseEvent me(m_webPage->view()->mapFromGlobal(QCursor::pos()), QCursor::pos(), LeftButton, MouseEventMoved, 0, false, false, false, false, 0); + frame->eventHandler()->dragSourceEndedAt(me, dropActionToDragOperation(actualDropAction)); } #endif } diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/EditCommandQt.cpp b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/EditCommandQt.cpp index a16684083a..756ba4c46e 100644 --- a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/EditCommandQt.cpp +++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/EditCommandQt.cpp @@ -18,7 +18,6 @@ */ #include "config.h" -#include <wtf/Platform.h> #include "EditCommandQt.h" using namespace WebCore; diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/EditorClientQt.cpp b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/EditorClientQt.cpp index 2d1a1ebf8d..7b7f61038a 100644 --- a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/EditorClientQt.cpp +++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/EditorClientQt.cpp @@ -384,18 +384,6 @@ void EditorClientQt::handleKeyboardEvent(KeyboardEvent* event) } else #endif // QT_NO_SHORTCUT switch (kevent->windowsVirtualKeyCode()) { -#if QT_VERSION < 0x040500 - case VK_RETURN: -#ifdef QT_WS_MAC - if (kevent->shiftKey() || kevent->metaKey()) -#else - if (kevent->shiftKey()) -#endif - frame->editor()->command("InsertLineBreak").execute(); - else - frame->editor()->command("InsertNewline").execute(); - break; -#endif case VK_BACK: frame->editor()->deleteWithDirection(SelectionController::BACKWARD, CharacterGranularity, false, true); @@ -407,28 +395,38 @@ void EditorClientQt::handleKeyboardEvent(KeyboardEvent* event) case VK_LEFT: if (kevent->shiftKey()) frame->editor()->command("MoveLeftAndModifySelection").execute(); - else frame->editor()->command("MoveLeft").execute(); + else + frame->editor()->command("MoveLeft").execute(); break; case VK_RIGHT: if (kevent->shiftKey()) frame->editor()->command("MoveRightAndModifySelection").execute(); - else frame->editor()->command("MoveRight").execute(); + else + frame->editor()->command("MoveRight").execute(); break; case VK_UP: if (kevent->shiftKey()) frame->editor()->command("MoveUpAndModifySelection").execute(); - else frame->editor()->command("MoveUp").execute(); + else + frame->editor()->command("MoveUp").execute(); break; case VK_DOWN: if (kevent->shiftKey()) frame->editor()->command("MoveDownAndModifySelection").execute(); - else frame->editor()->command("MoveDown").execute(); + else + frame->editor()->command("MoveDown").execute(); break; case VK_PRIOR: // PageUp - frame->editor()->command("MovePageUp").execute(); + if (kevent->shiftKey()) + frame->editor()->command("MovePageUpAndModifySelection").execute(); + else + frame->editor()->command("MovePageUp").execute(); break; case VK_NEXT: // PageDown - frame->editor()->command("MovePageDown").execute(); + if (kevent->shiftKey()) + frame->editor()->command("MovePageDownAndModifySelection").execute(); + else + frame->editor()->command("MovePageDown").execute(); break; case VK_TAB: return; diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp index 5cabca04e3..c5c5739e46 100644 --- a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp +++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp @@ -1,9 +1,10 @@ /* * Copyright (C) 2006 Zack Rusin <zack@kde.org> * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. - * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) * Copyright (C) 2008 Collabora Ltd. All rights reserved. * Coypright (C) 2008 Holger Hans Peter Freyther + * Coypright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in> * * All rights reserved. * @@ -37,7 +38,6 @@ #include "FrameTree.h" #include "FrameView.h" #include "DocumentLoader.h" -#include "JSDOMWindowBase.h" #include "MIMETypeRegistry.h" #include "ResourceResponse.h" #include "Page.h" @@ -50,12 +50,14 @@ #include "HTMLAppletElement.h" #include "HTMLFormElement.h" #include "HTMLPlugInElement.h" +#include "HTTPParsers.h" #include "NotImplemented.h" #include "QNetworkReplyHandler.h" #include "ResourceHandleInternal.h" #include "ResourceHandle.h" -#include "Settings.h" +#include "ScriptController.h" #include "ScriptString.h" +#include "Settings.h" #include "QWebPageClient.h" #include "qwebpage.h" @@ -69,14 +71,10 @@ #include <QCoreApplication> #include <QDebug> -#if QT_VERSION >= 0x040400 #include <QGraphicsScene> #include <QGraphicsWidget> #include <QNetworkRequest> #include <QNetworkReply> -#else -#include "qwebnetworkinterface_p.h" -#endif #include "qwebhistory_p.h" static bool dumpFrameLoaderCallbacks = false; @@ -146,9 +144,9 @@ namespace WebCore FrameLoaderClientQt::FrameLoaderClientQt() : m_frame(0) , m_webFrame(0) + , m_firstData(false) , m_pluginView(0) , m_hasSentResponseToPlugin(false) - , m_firstData(false) , m_loadError (ResourceError()) { } @@ -308,11 +306,32 @@ void FrameLoaderClientQt::dispatchDidChangeLocationWithinPage() m_webFrame->page()->d->updateNavigationActions(); } +void FrameLoaderClientQt::dispatchDidPushStateWithinPage() +{ + if (dumpFrameLoaderCallbacks) + printf("%s - dispatchDidPushStateWithinPage\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); + + notImplemented(); +} -void FrameLoaderClientQt::dispatchWillClose() +void FrameLoaderClientQt::dispatchDidReplaceStateWithinPage() { if (dumpFrameLoaderCallbacks) - printf("%s - willCloseFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); + printf("%s - dispatchDidReplaceStateWithinPage\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); + + notImplemented(); +} + +void FrameLoaderClientQt::dispatchDidPopStateWithinPage() +{ + if (dumpFrameLoaderCallbacks) + printf("%s - dispatchDidPopStateWithinPage\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); + + notImplemented(); +} + +void FrameLoaderClientQt::dispatchWillClose() +{ } @@ -579,9 +598,6 @@ String FrameLoaderClientQt::userAgent(const KURL& url) void FrameLoaderClientQt::dispatchDidReceiveIcon() { - if (dumpFrameLoaderCallbacks) - printf("%s - didReceiveIconForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); - if (m_webFrame) { emit m_webFrame->iconChanged(); } @@ -601,10 +617,10 @@ bool FrameLoaderClientQt::canHandleRequest(const WebCore::ResourceRequest&) cons return true; } -void FrameLoaderClientQt::windowObjectCleared() +void FrameLoaderClientQt::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld* world) { - if (dumpFrameLoaderCallbacks) - printf("%s - didClearWindowObjectForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); + if (world != mainThreadNormalWorld()) + return; if (m_webFrame) emit m_webFrame->javaScriptWindowObjectCleared(); @@ -643,13 +659,31 @@ bool FrameLoaderClientQt::shouldGoToHistoryItem(WebCore::HistoryItem *) const return true; } +void FrameLoaderClientQt::dispatchDidAddBackForwardItem(WebCore::HistoryItem*) const +{ +} + +void FrameLoaderClientQt::dispatchDidRemoveBackForwardItem(WebCore::HistoryItem*) const +{ +} + +void FrameLoaderClientQt::dispatchDidChangeBackForwardIndex() const +{ +} + void FrameLoaderClientQt::didDisplayInsecureContent() { + if (dumpFrameLoaderCallbacks) + printf("didDisplayInsecureContent\n"); + notImplemented(); } void FrameLoaderClientQt::didRunInsecureContent(WebCore::SecurityOrigin*) { + if (dumpFrameLoaderCallbacks) + printf("didRunInsecureContent\n"); + notImplemented(); } @@ -771,22 +805,13 @@ bool FrameLoaderClientQt::shouldFallBack(const WebCore::ResourceError&) WTF::PassRefPtr<WebCore::DocumentLoader> FrameLoaderClientQt::createDocumentLoader(const WebCore::ResourceRequest& request, const SubstituteData& substituteData) { RefPtr<DocumentLoader> loader = DocumentLoader::create(request, substituteData); - if (substituteData.isValid()) { + if (substituteData.isValid()) loader->setDeferMainResourceDataLoad(false); - // Use the default timeout interval for JS as the HTML tokenizer delay. This ensures - // that long-running JavaScript will still allow setHtml() to be synchronous, while - // still giving a reasonable timeout to prevent deadlock. - double delay = JSDOMWindowBase::commonJSGlobalData()->timeoutChecker.timeoutInterval() / 1000.0f; - m_frame->page()->setCustomHTMLTokenizerTimeDelay(delay); - } else { - m_frame->page()->setCustomHTMLTokenizerTimeDelay(-1); - } return loader.release(); } void FrameLoaderClientQt::download(WebCore::ResourceHandle* handle, const WebCore::ResourceRequest&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&) { -#if QT_VERSION >= 0x040400 if (!m_webFrame) return; @@ -795,11 +820,10 @@ void FrameLoaderClientQt::download(WebCore::ResourceHandle* handle, const WebCor if (reply) { QWebPage *page = m_webFrame->page(); if (page->forwardUnsupportedContent()) - emit m_webFrame->page()->unsupportedContent(reply); + emit page->unsupportedContent(reply); else reply->abort(); } -#endif } void FrameLoaderClientQt::assignIdentifierToInitialRequest(unsigned long identifier, WebCore::DocumentLoader*, const WebCore::ResourceRequest& request) @@ -943,7 +967,9 @@ WebCore::Frame* FrameLoaderClientQt::dispatchCreatePage() void FrameLoaderClientQt::dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const WebCore::String& MIMEType, const WebCore::ResourceRequest&) { // we need to call directly here - if (canShowMIMEType(MIMEType)) + if (WebCore::shouldTreatAsAttachment(m_frame->loader()->activeDocumentLoader()->response())) + callPolicyFunction(function, PolicyDownload); + else if (canShowMIMEType(MIMEType)) callPolicyFunction(function, PolicyUse); else callPolicyFunction(function, PolicyDownload); @@ -952,11 +978,7 @@ void FrameLoaderClientQt::dispatchDecidePolicyForMIMEType(FramePolicyFunction fu void FrameLoaderClientQt::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const WebCore::NavigationAction& action, const WebCore::ResourceRequest& request, PassRefPtr<WebCore::FormState>, const WebCore::String&) { Q_ASSERT(m_webFrame); -#if QT_VERSION < 0x040400 - QWebNetworkRequest r(request); -#else QNetworkRequest r(request.toNetworkRequest(m_webFrame)); -#endif QWebPage* page = m_webFrame->page(); if (!page->d->acceptNavigationRequest(0, r, QWebPage::NavigationType(action.type()))) { @@ -977,11 +999,7 @@ void FrameLoaderClientQt::dispatchDecidePolicyForNewWindowAction(FramePolicyFunc void FrameLoaderClientQt::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const WebCore::NavigationAction& action, const WebCore::ResourceRequest& request, PassRefPtr<WebCore::FormState>) { Q_ASSERT(m_webFrame); -#if QT_VERSION < 0x040400 - QWebNetworkRequest r(request); -#else QNetworkRequest r(request.toNetworkRequest(m_webFrame)); -#endif QWebPage*page = m_webFrame->page(); if (!page->d->acceptNavigationRequest(m_webFrame, r, QWebPage::NavigationType(action.type()))) { @@ -1006,12 +1024,10 @@ void FrameLoaderClientQt::dispatchUnableToImplementPolicy(const WebCore::Resourc void FrameLoaderClientQt::startDownload(const WebCore::ResourceRequest& request) { -#if QT_VERSION >= 0x040400 if (!m_webFrame) return; emit m_webFrame->page()->downloadRequested(request.toNetworkRequest(m_webFrame)); -#endif } PassRefPtr<Frame> FrameLoaderClientQt::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement, @@ -1021,7 +1037,12 @@ PassRefPtr<Frame> FrameLoaderClientQt::createFrame(const KURL& url, const String return 0; QWebFrameData frameData(m_frame->page(), m_frame, ownerElement, name); - frameData.url = url; + + if (url.isEmpty()) + frameData.url = blankURL(); + else + frameData.url = url; + frameData.referrer = referrer; frameData.allowsScrolling = allowsScrolling; frameData.marginWidth = marginWidth; @@ -1048,6 +1069,24 @@ PassRefPtr<Frame> FrameLoaderClientQt::createFrame(const KURL& url, const String return frameData.frame.release(); } +void FrameLoaderClientQt::didTransferChildFrameToNewDocument() +{ + ASSERT(m_frame->ownerElement()); + + if (!m_webFrame) + return; + + Frame* parentFrame = m_webFrame->d->frame->tree()->parent(); + ASSERT(parentFrame); + + if (QWebFrame* parent = QWebFramePrivate::kit(parentFrame)) { + m_webFrame->d->setPage(parent->page()); + + if (m_webFrame->parent() != qobject_cast<QObject*>(parent)) + m_webFrame->setParent(parent); + } +} + ObjectContentType FrameLoaderClientQt::objectContentType(const KURL& url, const String& _mimeType) { // qDebug()<<" ++++++++++++++++ url is "<<url.prettyURL()<<", mime = "<<_mimeType; @@ -1097,11 +1136,7 @@ const unsigned numqStyleSheetProperties = sizeof(qstyleSheetProperties) / sizeof class QtPluginWidget: public Widget { public: - QtPluginWidget(QWidget* w = 0) - : Widget(w) - , m_visible(false) - {} - + QtPluginWidget(QWidget* w = 0): Widget(w) {} ~QtPluginWidget() { if (platformWidget()) @@ -1135,25 +1170,16 @@ public: handleVisibility(); } - virtual void hide() - { - m_visible = false; - Widget::hide(); - } - virtual void show() { - m_visible = true; - if (!platformWidget()) - return; - - handleVisibility(); + Widget::show(); + handleVisibility(); } private: void handleVisibility() { - if (!m_visible) + if (!isVisible()) return; // if setMask is set with an empty QRegion, no clipping will @@ -1161,8 +1187,6 @@ private: QRegion mask = platformWidget()->mask(); platformWidget()->setVisible(!mask.isEmpty()); } - - bool m_visible; }; #if QT_VERSION >= 0x040600 @@ -1262,13 +1286,11 @@ PassRefPtr<Widget> FrameLoaderClientQt::createPlugin(const IntSize& pluginSize, #endif // QT_NO_STYLE_STYLESHEET } -#if QT_VERSION >= 0x040400 if (!object) { QWebPluginFactory* factory = m_webFrame->page()->pluginFactory(); if (factory) object = factory->create(mimeType, qurl, params, values); } -#endif if (object) { QWidget* widget = qobject_cast<QWidget*>(object); @@ -1303,8 +1325,23 @@ PassRefPtr<Widget> FrameLoaderClientQt::createPlugin(const IntSize& pluginSize, // FIXME: make things work for widgetless plugins as well delete object; } else { // NPAPI Plugins + Vector<String> params = paramNames; + Vector<String> values = paramValues; + if (mimeType == "application/x-shockwave-flash") { + QWebPageClient* client = m_webFrame->page()->d->client; + if (!client || !qobject_cast<QWidget*>(client->pluginParent())) { + // inject wmode=opaque when there is no client or the client is not a QWebView + size_t wmodeIndex = params.find("wmode"); + if (wmodeIndex == -1) { + params.append("wmode"); + values.append("opaque"); + } else + values[wmodeIndex] = "opaque"; + } + } + RefPtr<PluginView> pluginView = PluginView::create(m_frame, pluginSize, element, url, - paramNames, paramValues, mimeType, loadManually); + params, values, mimeType, loadManually); return pluginView; } diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h index 66c4252866..adeb31c8ba 100644 --- a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h +++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h @@ -103,6 +103,9 @@ namespace WebCore { virtual void dispatchDidCancelClientRedirect(); virtual void dispatchWillPerformClientRedirect(const KURL&, double interval, double fireDate); virtual void dispatchDidChangeLocationWithinPage(); + virtual void dispatchDidPushStateWithinPage(); + virtual void dispatchDidReplaceStateWithinPage(); + virtual void dispatchDidPopStateWithinPage(); virtual void dispatchWillClose(); virtual void dispatchDidReceiveIcon(); virtual void dispatchDidStartProvisionalLoad(); @@ -148,7 +151,9 @@ namespace WebCore { virtual void updateGlobalHistory(); virtual void updateGlobalHistoryRedirectLinks(); virtual bool shouldGoToHistoryItem(HistoryItem*) const; - + virtual void dispatchDidAddBackForwardItem(HistoryItem*) const; + virtual void dispatchDidRemoveBackForwardItem(HistoryItem*) const; + virtual void dispatchDidChangeBackForwardIndex() const; virtual void didDisplayInsecureContent(); virtual void didRunInsecureContent(SecurityOrigin*); @@ -189,6 +194,7 @@ namespace WebCore { virtual PassRefPtr<Frame> createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement, const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight) ; + virtual void didTransferChildFrameToNewDocument(); virtual PassRefPtr<Widget> createPlugin(const IntSize&, HTMLPlugInElement*, const KURL&, const Vector<String>&, const Vector<String>&, const String&, bool); virtual void redirectDataToPlugin(Widget* pluginWidget); @@ -197,7 +203,7 @@ namespace WebCore { virtual ObjectContentType objectContentType(const KURL& url, const String& mimeType); virtual String overrideMediaType() const; - virtual void windowObjectCleared(); + virtual void dispatchDidClearWindowObjectInWorld(DOMWrapperWorld*); virtual void documentElementAvailable(); virtual void didPerformFirstNavigation() const; diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/InspectorClientQt.cpp b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/InspectorClientQt.cpp index 5fbc876a8e..139499d119 100644 --- a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/InspectorClientQt.cpp +++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/InspectorClientQt.cpp @@ -50,17 +50,16 @@ namespace WebCore { static const QLatin1String settingStoragePrefix("Qt/QtWebKit/QWebInspector/"); static const QLatin1String settingStorageTypeSuffix(".type"); -static InspectorController::Setting variantToSetting(const QVariant& qvariant); -static QVariant settingToVariant(const InspectorController::Setting& icSetting); +static String variantToSetting(const QVariant& qvariant); +static QVariant settingToVariant(const String& value); class InspectorClientWebPage : public QWebPage { Q_OBJECT friend class InspectorClientQt; public: InspectorClientWebPage(QObject* parent = 0) - : QWebPage(parent) + : QWebPage(parent) { - settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, false); } QWebPage* createWindow(QWebPage::WebWindowType) @@ -82,190 +81,159 @@ void InspectorClientQt::inspectorDestroyed() delete this; } -Page* InspectorClientQt::createPage() + +void InspectorClientQt::openInspectorFrontend(WebCore::InspectorController*) { QWebView* inspectorView = new QWebView; InspectorClientWebPage* inspectorPage = new InspectorClientWebPage(inspectorView); inspectorView->setPage(inspectorPage); - m_inspectorView.set(inspectorView); - inspectorPage->mainFrame()->load(QString::fromLatin1("qrc:/webkit/inspector/inspector.html")); + QUrl inspectorUrl = m_inspectedWebPage->settings()->inspectorUrl(); + if (!inspectorUrl.isValid()) + inspectorUrl = QUrl("qrc:/webkit/inspector/inspector.html"); + inspectorView->page()->mainFrame()->load(inspectorUrl); m_inspectedWebPage->d->inspectorFrontend = inspectorView; m_inspectedWebPage->d->getOrCreateInspector()->d->setFrontend(inspectorView); - return m_inspectorView->page()->d->page; + inspectorView->page()->d->page->inspectorController()->setInspectorFrontendClient(new InspectorFrontendClientQt(m_inspectedWebPage, inspectorView)); } -String InspectorClientQt::localizedStringsURL() +void InspectorClientQt::highlight(Node*) { notImplemented(); - return String(); } -String InspectorClientQt::hiddenPanels() +void InspectorClientQt::hideHighlight() { notImplemented(); - return String(); } -void InspectorClientQt::showWindow() +void InspectorClientQt::populateSetting(const String& key, String* setting) { - updateWindowTitle(); + QSettings qsettings; + if (qsettings.status() == QSettings::AccessError) { + // QCoreApplication::setOrganizationName and QCoreApplication::setApplicationName haven't been called + qWarning("QWebInspector: QSettings couldn't read configuration setting [%s].", + qPrintable(static_cast<QString>(key))); + return; + } - m_inspectedWebPage->d->inspectorController()->setWindowVisible(true, true); - // We don't allow the inspector to ask for widget visibility itself because showWindow is - // not always called when we want. - // Inspecting an element or calling QWebInspector::show() should already have made the - // widget visible. + QString settingKey(settingStoragePrefix + QString(key)); + QString storedValueType = qsettings.value(settingKey + settingStorageTypeSuffix).toString(); + QVariant storedValue = qsettings.value(settingKey); + storedValue.convert(QVariant::nameToType(storedValueType.toAscii().data())); + *setting = variantToSetting(storedValue); } -void InspectorClientQt::closeWindow() +void InspectorClientQt::storeSetting(const String& key, const String& setting) { - if (m_inspectedWebPage->d->inspector) - m_inspectedWebPage->d->inspector->close(); -} + QSettings qsettings; + if (qsettings.status() == QSettings::AccessError) { + qWarning("QWebInspector: QSettings couldn't persist configuration setting [%s].", + qPrintable(static_cast<QString>(key))); + return; + } -void InspectorClientQt::attachWindow() -{ - notImplemented(); + QVariant valueToStore = settingToVariant(setting); + QString settingKey(settingStoragePrefix + QString(key)); + qsettings.setValue(settingKey, valueToStore); + qsettings.setValue(settingKey + settingStorageTypeSuffix, QVariant::typeToName(valueToStore.type())); } -void InspectorClientQt::detachWindow() +static String variantToSetting(const QVariant& qvariant) { - notImplemented(); + String retVal; + + switch (qvariant.type()) { + case QVariant::Bool: + retVal = qvariant.toBool() ? "true" : "false"; + case QVariant::String: + retVal = qvariant.toString(); + } + + return retVal; } -void InspectorClientQt::setAttachedWindowHeight(unsigned) +static QVariant settingToVariant(const String& setting) { - notImplemented(); + QVariant retVal; + retVal.setValue(static_cast<QString>(setting)); + return retVal; } -void InspectorClientQt::highlight(Node*) +InspectorFrontendClientQt::InspectorFrontendClientQt(QWebPage* inspectedWebPage, PassOwnPtr<QWebView> inspectorView) + : InspectorFrontendClientLocal(inspectedWebPage->d->page->inspectorController(), inspectorView->page()->d->page) + , m_inspectedWebPage(inspectedWebPage) + , m_inspectorView(inspectorView) + , m_destroyingInspectorView(false) { - notImplemented(); } -void InspectorClientQt::hideHighlight() +void InspectorFrontendClientQt::frontendLoaded() { - notImplemented(); + InspectorFrontendClientLocal::frontendLoaded(); + setAttachedWindow(true); } -void InspectorClientQt::inspectedURLChanged(const String& newURL) +String InspectorFrontendClientQt::localizedStringsURL() { - m_inspectedURL = newURL; - updateWindowTitle(); + notImplemented(); + return String(); } -void InspectorClientQt::inspectorWindowObjectCleared() +String InspectorFrontendClientQt::hiddenPanels() { notImplemented(); + return String(); } -void InspectorClientQt::updateWindowTitle() +void InspectorFrontendClientQt::bringToFront() { - if (m_inspectedWebPage->d->inspector) { - QString caption = QCoreApplication::translate("QWebPage", "Web Inspector - %2").arg(m_inspectedURL); - m_inspectedWebPage->d->inspector->setWindowTitle(caption); - } + updateWindowTitle(); } -void InspectorClientQt::populateSetting(const String& key, InspectorController::Setting& setting) +void InspectorFrontendClientQt::closeWindow() { - QSettings qsettings; - if (qsettings.status() == QSettings::AccessError) { - // QCoreApplication::setOrganizationName and QCoreApplication::setApplicationName haven't been called - qWarning("QWebInspector: QSettings couldn't read configuration setting [%s].", - qPrintable(static_cast<QString>(key))); + if (m_destroyingInspectorView) return; - } + m_destroyingInspectorView = true; - QString settingKey(settingStoragePrefix + QString(key)); - QString storedValueType = qsettings.value(settingKey + settingStorageTypeSuffix).toString(); - QVariant storedValue = qsettings.value(settingKey); - storedValue.convert(QVariant::nameToType(storedValueType.toAscii().data())); - setting = variantToSetting(storedValue); + // Clear reference from QWebInspector to the frontend view. + m_inspectedWebPage->d->getOrCreateInspector()->d->setFrontend(0); +#if ENABLE(INSPECTOR) + m_inspectedWebPage->d->inspectorController()->disconnectFrontend(); +#endif + // Clear pointer before deleting WebView to avoid recursive calls to its destructor. + delete m_inspectorView.release(); } -void InspectorClientQt::storeSetting(const String& key, const InspectorController::Setting& setting) +void InspectorFrontendClientQt::attachWindow() { - QSettings qsettings; - if (qsettings.status() == QSettings::AccessError) { - qWarning("QWebInspector: QSettings couldn't persist configuration setting [%s].", - qPrintable(static_cast<QString>(key))); - return; - } - - QVariant valueToStore = settingToVariant(setting); - QString settingKey(settingStoragePrefix + QString(key)); - qsettings.setValue(settingKey, valueToStore); - qsettings.setValue(settingKey + settingStorageTypeSuffix, QVariant::typeToName(valueToStore.type())); + notImplemented(); } -void InspectorClientQt::removeSetting(const String&) +void InspectorFrontendClientQt::detachWindow() { notImplemented(); } -static InspectorController::Setting variantToSetting(const QVariant& qvariant) +void InspectorFrontendClientQt::setAttachedWindowHeight(unsigned) { - InspectorController::Setting retVal; - - switch (qvariant.type()) { - case QVariant::Bool: - retVal.set(qvariant.toBool()); - break; - case QVariant::Double: - retVal.set(qvariant.toDouble()); - break; - case QVariant::Int: - retVal.set((long)qvariant.toInt()); - break; - case QVariant::String: - retVal.set(qvariant.toString()); - break; - case QVariant::StringList: { - QStringList qsList = qvariant.toStringList(); - int listCount = qsList.count(); - Vector<String> vector(listCount); - for (int i = 0; i < listCount; ++i) - vector[i] = qsList[i]; - retVal.set(vector); - break; - } - } - - return retVal; + notImplemented(); } -static QVariant settingToVariant(const InspectorController::Setting& icSetting) +void InspectorFrontendClientQt::inspectedURLChanged(const String& newURL) { - QVariant retVal; + m_inspectedURL = newURL; + updateWindowTitle(); +} - switch (icSetting.type()) { - case InspectorController::Setting::StringType: - retVal.setValue(static_cast<QString>(icSetting.string())); - break; - case InspectorController::Setting::StringVectorType: { - const Vector<String>& vector = icSetting.stringVector(); - Vector<String>::const_iterator iter; - QStringList qsList; - for (iter = vector.begin(); iter != vector.end(); ++iter) - qsList << *iter; - retVal.setValue(qsList); - break; - } - case InspectorController::Setting::DoubleType: - retVal.setValue(icSetting.doubleValue()); - break; - case InspectorController::Setting::IntegerType: - retVal.setValue((int)icSetting.integerValue()); - break; - case InspectorController::Setting::BooleanType: - retVal.setValue(icSetting.booleanValue()); - break; +void InspectorFrontendClientQt::updateWindowTitle() +{ + if (m_inspectedWebPage->d->inspector) { + QString caption = QCoreApplication::translate("QWebPage", "Web Inspector - %2").arg(m_inspectedURL); + m_inspectedWebPage->d->inspector->setWindowTitle(caption); } - - return retVal; } } diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/InspectorClientQt.h b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/InspectorClientQt.h index ccf8b69b46..4beadabe98 100644 --- a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/InspectorClientQt.h +++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/InspectorClientQt.h @@ -31,53 +31,64 @@ #define InspectorClientQt_h #include "InspectorClient.h" +#include "InspectorFrontendClientLocal.h" #include "OwnPtr.h" +#include "PassOwnPtr.h" #include <QtCore/QString> class QWebPage; class QWebView; namespace WebCore { - class Node; - class Page; - class String; +class Node; +class Page; +class String; - class InspectorClientQt : public InspectorClient { - public: - InspectorClientQt(QWebPage*); +class InspectorClientQt : public InspectorClient { +public: + InspectorClientQt(QWebPage*); - virtual void inspectorDestroyed(); + virtual void inspectorDestroyed(); - virtual Page* createPage(); + virtual void openInspectorFrontend(WebCore::InspectorController*); - virtual String localizedStringsURL(); + virtual void highlight(Node*); + virtual void hideHighlight(); - virtual String hiddenPanels(); + virtual void populateSetting(const String& key, String* value); + virtual void storeSetting(const String& key, const String& value); - virtual void showWindow(); - virtual void closeWindow(); +private: + QWebPage* m_inspectedWebPage; +}; - virtual void attachWindow(); - virtual void detachWindow(); +class InspectorFrontendClientQt : public InspectorFrontendClientLocal { +public: + InspectorFrontendClientQt(QWebPage* inspectedWebPage, PassOwnPtr<QWebView> inspectorView); - virtual void setAttachedWindowHeight(unsigned height); + virtual void frontendLoaded(); - virtual void highlight(Node*); - virtual void hideHighlight(); - virtual void inspectedURLChanged(const String& newURL); + virtual String localizedStringsURL(); - virtual void populateSetting(const String& key, InspectorController::Setting&); - virtual void storeSetting(const String& key, const InspectorController::Setting&); - virtual void removeSetting(const String& key); + virtual String hiddenPanels(); - virtual void inspectorWindowObjectCleared(); + virtual void bringToFront(); + virtual void closeWindow(); - private: - void updateWindowTitle(); - QWebPage* m_inspectedWebPage; - OwnPtr<QWebView> m_inspectorView; - QString m_inspectedURL; - }; + virtual void attachWindow(); + virtual void detachWindow(); + + virtual void setAttachedWindowHeight(unsigned height); + + virtual void inspectedURLChanged(const String& newURL); + +private: + void updateWindowTitle(); + QWebPage* m_inspectedWebPage; + OwnPtr<QWebView> m_inspectorView; + QString m_inspectedURL; + bool m_destroyingInspectorView; +}; } #endif diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.cpp b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.cpp new file mode 100644 index 0000000000..65a28fef59 --- /dev/null +++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.cpp @@ -0,0 +1,225 @@ +/* + * Copyright (C) 2010 Girish Ramakrishnan <girish@forwardbias.in> + * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ +#include "config.h" +#include "QtFallbackWebPopup.h" + +#include "HostWindow.h" +#include "PopupMenuClient.h" +#include "QWebPageClient.h" +#include "qgraphicswebview.h" +#include <QAbstractItemView> +#include <QApplication> +#include <QGraphicsProxyWidget> +#include <QGraphicsScene> +#include <QGraphicsView> +#include <QInputContext> +#include <QMouseEvent> +#include <QStandardItemModel> + +#if ENABLE(SYMBIAN_DIALOG_PROVIDERS) +#include <BrCtlDialogsProvider.h> +#include <BrowserDialogsProvider.h> // S60 platform private header file +#include <e32base.h> +#endif + +namespace WebCore { + +QtFallbackWebPopupCombo::QtFallbackWebPopupCombo(QtFallbackWebPopup& ownerPopup) + : m_ownerPopup(ownerPopup) +{ +} + +void QtFallbackWebPopupCombo::showPopup() +{ + QComboBox::showPopup(); + m_ownerPopup.m_popupVisible = true; +} + +void QtFallbackWebPopupCombo::hidePopup() +{ + QWidget* activeFocus = QApplication::focusWidget(); + if (activeFocus && activeFocus == QComboBox::view() + && activeFocus->testAttribute(Qt::WA_InputMethodEnabled)) { + QInputContext* qic = activeFocus->inputContext(); + if (qic) { + qic->reset(); + qic->setFocusWidget(0); + } + } + + QComboBox::hidePopup(); + + if (QGraphicsProxyWidget* proxy = graphicsProxyWidget()) + proxy->setVisible(false); + + if (!m_ownerPopup.m_popupVisible) + return; + + m_ownerPopup.m_popupVisible = false; + m_ownerPopup.popupDidHide(); +} + +// QtFallbackWebPopup + +QtFallbackWebPopup::QtFallbackWebPopup() + : QtAbstractWebPopup() + , m_popupVisible(false) + , m_combo(new QtFallbackWebPopupCombo(*this)) + , m_proxy(0) +{ + connect(m_combo, SIGNAL(activated(int)), + SLOT(activeChanged(int)), Qt::QueuedConnection); +} + +QtFallbackWebPopup::~QtFallbackWebPopup() +{ + // If we create a proxy, then the deletion of the proxy and the + // combo will be done by the proxy's parent (QGraphicsWebView) + if (!m_proxy) + delete m_combo; +} + +void QtFallbackWebPopup::show() +{ + if (!pageClient()) + return; + +#if ENABLE(SYMBIAN_DIALOG_PROVIDERS) + TRAP_IGNORE(showS60BrowserDialog()); +#else + populate(); + m_combo->setCurrentIndex(currentIndex()); + + QRect rect = geometry(); + if (QGraphicsWebView *webView = qobject_cast<QGraphicsWebView*>(pageClient()->pluginParent())) { + if (!m_proxy) { + m_proxy = new QGraphicsProxyWidget(webView); + m_proxy->setWidget(m_combo); + } else + m_proxy->setVisible(true); + m_proxy->setGeometry(rect); + } else { + m_combo->setParent(pageClient()->ownerWidget()); + m_combo->setGeometry(QRect(rect.left(), rect.top(), + rect.width(), m_combo->sizeHint().height())); + + } + + QMouseEvent event(QEvent::MouseButtonPress, QCursor::pos(), Qt::LeftButton, + Qt::LeftButton, Qt::NoModifier); + QCoreApplication::sendEvent(m_combo, &event); +#endif +} + +#if ENABLE(SYMBIAN_DIALOG_PROVIDERS) + +static void ResetAndDestroy(TAny* aPtr) +{ + RPointerArray<HBufC>* items = reinterpret_cast<RPointerArray<HBufC>* >(aPtr); + items->ResetAndDestroy(); +} + +void QtFallbackWebPopup::showS60BrowserDialog() +{ + static MBrCtlDialogsProvider* dialogs = CBrowserDialogsProvider::NewL(0); + if (!dialogs) + return; + + int size = itemCount(); + CArrayFix<TBrCtlSelectOptionData>* options = new CArrayFixFlat<TBrCtlSelectOptionData>(qMax(1, size)); + RPointerArray<HBufC> items(qMax(1, size)); + CleanupStack::PushL(TCleanupItem(&ResetAndDestroy, &items)); + + for (int i = 0; i < size; i++) { + if (itemType(i) == Separator) { + TBrCtlSelectOptionData data(_L("----------"), false, false, false); + options->AppendL(data); + } else { + HBufC16* itemStr = HBufC16::NewL(itemText(i).length()); + itemStr->Des().Copy((const TUint16*)itemText(i).utf16(), itemText(i).length()); + CleanupStack::PushL(itemStr); + TBrCtlSelectOptionData data(*itemStr, i == currentIndex(), false, itemIsEnabled(i)); + options->AppendL(data); + items.AppendL(itemStr); + CleanupStack::Pop(); + } + } + + dialogs->DialogSelectOptionL(KNullDesC(), (TBrCtlSelectOptionType)(ESelectTypeSingle | ESelectTypeWithFindPane), *options); + + CleanupStack::PopAndDestroy(&items); + + int newIndex; + for (newIndex = 0; newIndex < options->Count() && !options->At(newIndex).IsSelected(); newIndex++) {} + if (newIndex == options->Count()) + newIndex = currentIndex(); + + m_popupVisible = false; + popupDidHide(); + + if (currentIndex() != newIndex && newIndex >= 0) + valueChanged(newIndex); + + delete options; +} +#endif + +void QtFallbackWebPopup::hide() +{ + m_combo->hidePopup(); +} + +void QtFallbackWebPopup::populate() +{ + m_combo->clear(); + + QStandardItemModel* model = qobject_cast<QStandardItemModel*>(m_combo->model()); + Q_ASSERT(model); + +#if !defined(Q_WS_S60) + m_combo->setFont(font()); +#endif + for (int i = 0; i < itemCount(); ++i) { + switch (itemType(i)) { + case Separator: + m_combo->insertSeparator(i); + break; + case Group: + m_combo->insertItem(i, itemText(i)); + model->item(i)->setEnabled(false); + break; + case Option: + m_combo->insertItem(i, itemText(i)); + model->item(i)->setEnabled(itemIsEnabled(i)); + break; + } + } +} + +void QtFallbackWebPopup::activeChanged(int index) +{ + if (index < 0) + return; + + valueChanged(index); +} + +} diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.h b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.h new file mode 100644 index 0000000000..9d1183f8a8 --- /dev/null +++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/QtFallbackWebPopup.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ +#ifndef QtFallbackWebPopup_h +#define QtFallbackWebPopup_h + +#include "QtAbstractWebPopup.h" +#include <QComboBox> + +class QGraphicsProxyWidget; + +namespace WebCore { + +class QtFallbackWebPopupCombo; + +class QtFallbackWebPopup : public QObject, public QtAbstractWebPopup { + Q_OBJECT +public: + QtFallbackWebPopup(); + ~QtFallbackWebPopup(); + + virtual void show(); + virtual void hide(); + +private slots: + void activeChanged(int); + +private: + friend class QtFallbackWebPopupCombo; + bool m_popupVisible; + QtFallbackWebPopupCombo* m_combo; + QGraphicsProxyWidget* m_proxy; + + void populate(); +#if ENABLE(SYMBIAN_DIALOG_PROVIDERS) + void showS60BrowserDialog(); +#endif +}; + +class QtFallbackWebPopupCombo : public QComboBox { +public: + QtFallbackWebPopupCombo(QtFallbackWebPopup& ownerPopup); + virtual void showPopup(); + virtual void hidePopup(); + +private: + QtFallbackWebPopup& m_ownerPopup; +}; + +} + +#endif // QtFallbackWebPopup_h diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/QtMaemoWebPopup.cpp b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/QtMaemoWebPopup.cpp new file mode 100644 index 0000000000..29a16cb8cd --- /dev/null +++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/QtMaemoWebPopup.cpp @@ -0,0 +1,220 @@ +/* + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ +#include "config.h" +#include "QtMaemoWebPopup.h" + +#include <QHBoxLayout> +#include <QListWidget> +#include <QListWidgetItem> +#include <QPainter> +#include <QPushButton> +#include <QStyledItemDelegate> +#include <QVBoxLayout> + +#include <libintl.h> + + +namespace WebCore { + +static const int gMaemoListItemSize = 70; +static const int gMaemoListPadding = 38; +static const int gMaemoMaxVisibleItems = 5; + +void Maemo5Popup::populateList() +{ + QListWidgetItem* listItem; + for (int i = 0; i < m_data.itemCount(); ++i) { + if (m_data.itemType(i) == QtAbstractWebPopup::Option) { + listItem = new QListWidgetItem(m_data.itemText(i)); + m_list->addItem(listItem); + listItem->setSelected(m_data.itemIsSelected(i)); + } else if (m_data.itemType(i) == QtAbstractWebPopup::Group) { + listItem = new QListWidgetItem(m_data.itemText(i)); + m_list->addItem(listItem); + listItem->setSelected(false); + listItem->setFlags(Qt::NoItemFlags); + } + } + connect(m_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(onItemSelected(QListWidgetItem*))); +} + +void Maemo5Popup::onItemSelected(QListWidgetItem* item) +{ + if (item->flags() != Qt::NoItemFlags) + emit itemClicked(m_list->row(item)); +} + +QtMaemoWebPopup::QtMaemoWebPopup() + : QtAbstractWebPopup() + , m_popup(0) +{ +} + +QtMaemoWebPopup::~QtMaemoWebPopup() +{ + if (m_popup) + m_popup->deleteLater(); +} + +Maemo5Popup* QtMaemoWebPopup::createSingleSelectionPopup() +{ + return new Maemo5SingleSelectionPopup(*this); +} + +Maemo5Popup* QtMaemoWebPopup::createMultipleSelectionPopup() +{ + return new Maemo5MultipleSelectionPopup(*this); +} + +Maemo5Popup* QtMaemoWebPopup::createPopup() +{ + Maemo5Popup* result = multiple() ? createMultipleSelectionPopup() : createSingleSelectionPopup(); + connect(result, SIGNAL(finished(int)), this, SLOT(popupClosed())); + connect(result, SIGNAL(itemClicked(int)), this, SLOT(itemClicked(int))); + return result; +} + +void QtMaemoWebPopup::show() +{ + if (!pageClient() || m_popup) + return; + + m_popup = createPopup(); + m_popup->show(); +} + +void QtMaemoWebPopup::hide() +{ + if (!m_popup) + return; + + m_popup->accept(); +} + +void QtMaemoWebPopup::popupClosed() +{ + if (!m_popup) + return; + + m_popup->deleteLater(); + m_popup = 0; + popupDidHide(); +} + +void QtMaemoWebPopup::itemClicked(int idx) +{ + selectItem(idx, true, false); +} + +Maemo5SingleSelectionPopup::Maemo5SingleSelectionPopup(QtAbstractWebPopup& data) + : Maemo5Popup(data) +{ + // we try to get the standard list title the web browser is using + const char* title = ::dgettext("osso-browser-ui", "weba_ti_texlist_single"); + if (qstrcmp(title, "weba_ti_texlist_single")) + setWindowTitle(QString::fromUtf8(title)); + else + setWindowTitle("Select item"); + + QHBoxLayout* hLayout = new QHBoxLayout(this); + hLayout->setContentsMargins(0, 0, 0, 0); + + m_list = new QListWidget(this); + populateList(); + + hLayout->addSpacing(gMaemoListPadding); + hLayout->addWidget(m_list); + hLayout->addSpacing(gMaemoListPadding); + + connect(m_list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(accept())); + + const int visibleItemCount = (m_list->count() > gMaemoMaxVisibleItems) ? gMaemoMaxVisibleItems : m_list->count(); + resize(size().width(), visibleItemCount * gMaemoListItemSize); +} + + +class MultipleItemListDelegate : public QStyledItemDelegate { +public: + MultipleItemListDelegate(QObject* parent = 0) + : QStyledItemDelegate(parent) + { + tickMark = QIcon::fromTheme("widgets_tickmark_list").pixmap(48, 48); + } + + void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const + { + QStyledItemDelegate::paint(painter, option, index); + + if (option.state & QStyle::State_Selected) + painter->drawPixmap(option.rect.width() - tickMark.rect().width(), option.rect.y() + (option.rect.height() / 2 - tickMark.rect().height() / 2), tickMark); + } + +private: + QPixmap tickMark; +}; + +Maemo5MultipleSelectionPopup::Maemo5MultipleSelectionPopup(QtAbstractWebPopup& data) + : Maemo5Popup(data) +{ + // we try to get the standard list title the web browser is using + const char* title = ::dgettext("osso-browser-ui", "weba_ti_textlist_multi"); + if (qstrcmp(title, "weba_ti_textlist_multi")) + setWindowTitle(QString::fromUtf8(title)); + else + setWindowTitle("Select items"); + + QHBoxLayout* hLayout = new QHBoxLayout(this); + hLayout->setContentsMargins(0, 0, 0, 0); + + m_list = new QListWidget(this); + m_list->setSelectionMode(QAbstractItemView::MultiSelection); + populateList(); + + MultipleItemListDelegate* delegate = new MultipleItemListDelegate(this); + m_list->setItemDelegate(delegate); + + hLayout->addSpacing(gMaemoListPadding); + hLayout->addWidget(m_list); + + QVBoxLayout* vLayout = new QVBoxLayout(); + + const int visibleItemCount = (m_list->count() > gMaemoMaxVisibleItems) ? gMaemoMaxVisibleItems : m_list->count(); + vLayout->addSpacing((visibleItemCount - 1) * gMaemoListItemSize); + + // we try to get the standard Done button title + QPushButton* done = new QPushButton(this); + title = ::dgettext("hildon-libs", "wdgt_bd_done"); + if (qstrcmp(title, "wdgt_bd_done")) + done->setText(QString::fromUtf8(title)); + else + done->setText("Done"); + + done->setMinimumWidth(178); + vLayout->addWidget(done); + + hLayout->addSpacing(8); + hLayout->addLayout(vLayout); + hLayout->addSpacing(18); + + connect(done, SIGNAL(clicked()), this, SLOT(accept())); + resize(size().width(), visibleItemCount * gMaemoListItemSize); +} + +} diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/QtMaemoWebPopup.h b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/QtMaemoWebPopup.h new file mode 100644 index 0000000000..a163a20d3b --- /dev/null +++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/QtMaemoWebPopup.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ +#ifndef QtMaemoWebPopup_h +#define QtMaemoWebPopup_h + +#include "QtAbstractWebPopup.h" + +#include <QDialog> + +class QListWidgetItem; +class QListWidget; + + +namespace WebCore { + +class Maemo5Popup : public QDialog { + Q_OBJECT +public: + Maemo5Popup(QtAbstractWebPopup& data) : m_data(data) {} + +signals: + void itemClicked(int idx); + +protected slots: + void onItemSelected(QListWidgetItem* item); + +protected: + void populateList(); + + QtAbstractWebPopup& m_data; + QListWidget* m_list; +}; + + +class QtMaemoWebPopup : public QObject, public QtAbstractWebPopup { + Q_OBJECT +public: + QtMaemoWebPopup(); + ~QtMaemoWebPopup(); + + virtual void show(); + virtual void hide(); + +private slots: + void popupClosed(); + void itemClicked(int idx); + +private: + Maemo5Popup* m_popup; + + Maemo5Popup* createPopup(); + Maemo5Popup* createSingleSelectionPopup(); + Maemo5Popup* createMultipleSelectionPopup(); +}; + + +class Maemo5SingleSelectionPopup : public Maemo5Popup { + Q_OBJECT +public: + Maemo5SingleSelectionPopup(QtAbstractWebPopup& data); +}; + + +class Maemo5MultipleSelectionPopup : public Maemo5Popup { + Q_OBJECT +public: + Maemo5MultipleSelectionPopup(QtAbstractWebPopup& data); +}; + +} + +#endif // QtMaemoWebPopup_h |