diff options
Diffstat (limited to 'WebKit/qt/WebCoreSupport')
-rw-r--r-- | WebKit/qt/WebCoreSupport/ChromeClientQt.cpp | 396 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/ChromeClientQt.h | 131 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/ContextMenuClientQt.cpp | 81 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/ContextMenuClientQt.h | 52 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/DragClientQt.cpp | 80 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/DragClientQt.h | 46 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/EditCommandQt.cpp | 57 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/EditCommandQt.h | 50 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/EditorClientQt.cpp | 593 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/EditorClientQt.h | 120 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp | 1125 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h | 218 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/InspectorClientQt.cpp | 206 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/InspectorClientQt.h | 80 |
14 files changed, 3235 insertions, 0 deletions
diff --git a/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp b/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp new file mode 100644 index 0000000..8a4de6b --- /dev/null +++ b/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp @@ -0,0 +1,396 @@ +/* + * Copyright (C) 2006 Zack Rusin <zack@kde.org> + * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * + * All rights reserved. + * + * 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 "ChromeClientQt.h" + +#include "FileChooser.h" +#include "Frame.h" +#include "FrameLoadRequest.h" +#include "FrameLoader.h" +#include "FrameLoaderClientQt.h" +#include "FrameView.h" +#include "HitTestResult.h" +#include "NotImplemented.h" +#include "WindowFeatures.h" + +#include "qwebpage.h" +#include "qwebpage_p.h" +#include "qwebframe_p.h" + +#include <qtooltip.h> + +namespace WebCore +{ + + +ChromeClientQt::ChromeClientQt(QWebPage* webPage) + : m_webPage(webPage) +{ + toolBarsVisible = statusBarVisible = menuBarVisible = true; +} + +ChromeClientQt::~ChromeClientQt() +{ + +} + +void ChromeClientQt::setWindowRect(const FloatRect& rect) +{ + if (!m_webPage) + return; + emit m_webPage->geometryChangeRequested(QRect(qRound(rect.x()), qRound(rect.y()), + qRound(rect.width()), qRound(rect.height()))); +} + + +FloatRect ChromeClientQt::windowRect() +{ + if (!m_webPage) + return FloatRect(); + + QWidget* view = m_webPage->view(); + if (!view) + return FloatRect(); + return IntRect(view->topLevelWidget()->geometry()); +} + + +FloatRect ChromeClientQt::pageRect() +{ + if (!m_webPage) + return FloatRect(); + return FloatRect(QRectF(QPointF(0,0), m_webPage->viewportSize())); +} + + +float ChromeClientQt::scaleFactor() +{ + notImplemented(); + return 1; +} + + +void ChromeClientQt::focus() +{ + if (!m_webPage) + return; + QWidget* view = m_webPage->view(); + if (!view) + return; + + view->setFocus(); +} + + +void ChromeClientQt::unfocus() +{ + if (!m_webPage) + return; + QWidget* view = m_webPage->view(); + if (!view) + return; + view->clearFocus(); +} + +bool ChromeClientQt::canTakeFocus(FocusDirection) +{ + // This is called when cycling through links/focusable objects and we + // reach the last focusable object. Then we want to claim that we can + // take the focus to avoid wrapping. + return true; +} + +void ChromeClientQt::takeFocus(FocusDirection) +{ + // don't do anything. This is only called when cycling to links/focusable objects, + // which in turn is called from focusNextPrevChild. We let focusNextPrevChild + // call QWidget::focusNextPrevChild accordingly, so there is no need to do anything + // here. +} + + +Page* ChromeClientQt::createWindow(Frame*, const FrameLoadRequest& request, const WindowFeatures& features) +{ + QWebPage *newPage = m_webPage->createWindow(features.dialog ? QWebPage::WebModalDialog : QWebPage::WebBrowserWindow); + if (!newPage) + return 0; + newPage->mainFrame()->load(request.resourceRequest().url()); + return newPage->d->page; +} + +void ChromeClientQt::show() +{ + if (!m_webPage) + return; + QWidget* view = m_webPage->view(); + if (!view) + return; + view->topLevelWidget()->show(); +} + + +bool ChromeClientQt::canRunModal() +{ + notImplemented(); + return false; +} + + +void ChromeClientQt::runModal() +{ + notImplemented(); +} + + +void ChromeClientQt::setToolbarsVisible(bool visible) +{ + toolBarsVisible = visible; + emit m_webPage->toolBarVisibilityChangeRequested(visible); +} + + +bool ChromeClientQt::toolbarsVisible() +{ + return toolBarsVisible; +} + + +void ChromeClientQt::setStatusbarVisible(bool visible) +{ + emit m_webPage->statusBarVisibilityChangeRequested(visible); + statusBarVisible = visible; +} + + +bool ChromeClientQt::statusbarVisible() +{ + return statusBarVisible; + return false; +} + + +void ChromeClientQt::setScrollbarsVisible(bool) +{ + notImplemented(); +} + + +bool ChromeClientQt::scrollbarsVisible() +{ + notImplemented(); + return true; +} + + +void ChromeClientQt::setMenubarVisible(bool visible) +{ + menuBarVisible = visible; + emit m_webPage->menuBarVisibilityChangeRequested(visible); +} + +bool ChromeClientQt::menubarVisible() +{ + return menuBarVisible; +} + +void ChromeClientQt::setResizable(bool) +{ + notImplemented(); +} + +void ChromeClientQt::addMessageToConsole(const String& message, unsigned int lineNumber, + const String& sourceID) +{ + QString x = message; + QString y = sourceID; + m_webPage->javaScriptConsoleMessage(x, lineNumber, y); +} + +void ChromeClientQt::chromeDestroyed() +{ + delete this; +} + +bool ChromeClientQt::canRunBeforeUnloadConfirmPanel() +{ + return true; +} + +bool ChromeClientQt::runBeforeUnloadConfirmPanel(const String& message, Frame* frame) +{ + return runJavaScriptConfirm(frame, message); +} + +void ChromeClientQt::closeWindowSoon() +{ + m_webPage->mainFrame()->d->frame->loader()->stopAllLoaders(); + emit m_webPage->windowCloseRequested(); +} + +void ChromeClientQt::runJavaScriptAlert(Frame* f, const String& msg) +{ + QString x = msg; + FrameLoaderClientQt *fl = static_cast<FrameLoaderClientQt*>(f->loader()->client()); + m_webPage->javaScriptAlert(fl->webFrame(), x); +} + +bool ChromeClientQt::runJavaScriptConfirm(Frame* f, const String& msg) +{ + QString x = msg; + FrameLoaderClientQt *fl = static_cast<FrameLoaderClientQt*>(f->loader()->client()); + return m_webPage->javaScriptConfirm(fl->webFrame(), x); +} + +bool ChromeClientQt::runJavaScriptPrompt(Frame* f, const String& message, const String& defaultValue, String& result) +{ + QString x = result; + FrameLoaderClientQt *fl = static_cast<FrameLoaderClientQt*>(f->loader()->client()); + bool rc = m_webPage->javaScriptPrompt(fl->webFrame(), (QString)message, (QString)defaultValue, &x); + result = x; + return rc; +} + +void ChromeClientQt::setStatusbarText(const String& msg) +{ + QString x = msg; + emit m_webPage->statusBarMessage(x); +} + +bool ChromeClientQt::shouldInterruptJavaScript() +{ + notImplemented(); + return false; +} + +bool ChromeClientQt::tabsToLinks() const +{ + return m_webPage->settings()->testAttribute(QWebSettings::LinksIncludedInFocusChain); +} + +IntRect ChromeClientQt::windowResizerRect() const +{ + return IntRect(); +} + +void ChromeClientQt::repaint(const IntRect& windowRect, bool contentChanged, bool immediate, bool repaintContentOnly) +{ + // No double buffer, so only update the QWidget if content changed. + if (contentChanged) { + QWidget* view = m_webPage->view(); + if (view) { + QRect rect(windowRect); + rect = rect.intersected(QRect(QPoint(0, 0), m_webPage->viewportSize())); + if (!windowRect.isEmpty()) + view->update(windowRect); + } + 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::scroll(const IntSize& delta, const IntRect& scrollViewRect, const IntRect&) +{ + QWidget* view = m_webPage->view(); + if (view) + view->scroll(delta.width(), delta.height(), scrollViewRect); + emit m_webPage->scrollRequested(delta.width(), delta.height(), scrollViewRect); +} + +IntRect ChromeClientQt::windowToScreen(const IntRect& rect) const +{ + notImplemented(); + return rect; +} + +IntPoint ChromeClientQt::screenToWindow(const IntPoint& point) const +{ + notImplemented(); + return point; +} + +PlatformWidget ChromeClientQt::platformWindow() const +{ + return m_webPage->view(); +} + +void ChromeClientQt::mouseDidMoveOverElement(const HitTestResult& result, unsigned modifierFlags) +{ + if (result.absoluteLinkURL() != lastHoverURL + || result.title() != lastHoverTitle + || result.textContent() != lastHoverContent) { + lastHoverURL = result.absoluteLinkURL(); + lastHoverTitle = result.title(); + lastHoverContent = result.textContent(); + emit m_webPage->linkHovered(lastHoverURL.prettyURL(), + lastHoverTitle, lastHoverContent); + } +} + +void ChromeClientQt::setToolTip(const String &tip) +{ +#ifndef QT_NO_TOOLTIP + QWidget* view = m_webPage->view(); + if (!view) + return; + + if (tip.isEmpty()) { + view->setToolTip(QString()); + QToolTip::hideText(); + } else { + QString dtip = QLatin1String("<p>") + tip + QLatin1String("</p>"); + view->setToolTip(dtip); + } +#else + Q_UNUSED(tip); +#endif +} + +void ChromeClientQt::print(Frame *frame) +{ + emit m_webPage->printRequested(QWebFramePrivate::kit(frame)); +} + +void ChromeClientQt::exceededDatabaseQuota(Frame*, const String&) +{ + notImplemented(); +} + +void ChromeClientQt::runOpenPanel(Frame* frame, PassRefPtr<FileChooser> prpFileChooser) +{ + // FIXME: Support multiple files. + + RefPtr<FileChooser> fileChooser = prpFileChooser; + QString suggestedFile = fileChooser->filenames()[0]; + QString file = m_webPage->chooseFile(QWebFramePrivate::kit(frame), suggestedFile); + if (!file.isEmpty()) + fileChooser->chooseFile(file); +} + +} diff --git a/WebKit/qt/WebCoreSupport/ChromeClientQt.h b/WebKit/qt/WebCoreSupport/ChromeClientQt.h new file mode 100644 index 0000000..440f29e --- /dev/null +++ b/WebKit/qt/WebCoreSupport/ChromeClientQt.h @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2006 Zack Rusin <zack@kde.org> + * + * All rights reserved. + * + * 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. + */ + +#ifndef ChromeClientQt_H +#define ChromeClientQt_H + +#include "ChromeClient.h" +#include "FloatRect.h" +#include "RefCounted.h" +#include "KURL.h" +#include "PlatformString.h" + +class QWebPage; + +namespace WebCore { + + class FileChooser; + class FloatRect; + class Page; + struct FrameLoadRequest; + + class ChromeClientQt : public ChromeClient + { + public: + ChromeClientQt(QWebPage* webPage); + virtual ~ChromeClientQt(); + virtual void chromeDestroyed(); + + virtual void setWindowRect(const FloatRect&); + virtual FloatRect windowRect(); + + virtual FloatRect pageRect(); + + virtual float scaleFactor(); + + virtual void focus(); + virtual void unfocus(); + + virtual bool canTakeFocus(FocusDirection); + virtual void takeFocus(FocusDirection); + + virtual Page* createWindow(Frame*, const FrameLoadRequest&, const WindowFeatures&); + virtual void show(); + + virtual bool canRunModal(); + virtual void runModal(); + + virtual void setToolbarsVisible(bool); + virtual bool toolbarsVisible(); + + virtual void setStatusbarVisible(bool); + virtual bool statusbarVisible(); + + virtual void setScrollbarsVisible(bool); + virtual bool scrollbarsVisible(); + + virtual void setMenubarVisible(bool); + virtual bool menubarVisible(); + + virtual void setResizable(bool); + + virtual void addMessageToConsole(const String& message, unsigned int lineNumber, + const String& sourceID); + + virtual bool canRunBeforeUnloadConfirmPanel(); + virtual bool runBeforeUnloadConfirmPanel(const String& message, Frame* frame); + + virtual void closeWindowSoon(); + + virtual void runJavaScriptAlert(Frame*, const String&); + virtual bool runJavaScriptConfirm(Frame*, const String&); + virtual bool runJavaScriptPrompt(Frame*, const String& message, const String& defaultValue, String& result); + virtual bool shouldInterruptJavaScript(); + + virtual void setStatusbarText(const String&); + + virtual bool tabsToLinks() const; + virtual IntRect windowResizerRect() const; + + virtual void repaint(const IntRect&, bool contentChanged, bool immediate = false, bool repaintContentOnly = false); + 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 PlatformWidget platformWindow() const; + + virtual void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags); + + virtual void setToolTip(const String&); + + virtual void print(Frame*); + + virtual void exceededDatabaseQuota(Frame*, const String&); + + virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>); + + QWebPage* m_webPage; + WebCore::KURL lastHoverURL; + WebCore::String lastHoverTitle; + WebCore::String lastHoverContent; + + bool toolBarsVisible; + bool statusBarVisible; + bool menuBarVisible; + }; +} + +#endif diff --git a/WebKit/qt/WebCoreSupport/ContextMenuClientQt.cpp b/WebKit/qt/WebCoreSupport/ContextMenuClientQt.cpp new file mode 100644 index 0000000..ae9d718 --- /dev/null +++ b/WebKit/qt/WebCoreSupport/ContextMenuClientQt.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2006 Zack Rusin <zack@kde.org> + * + * 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 "ContextMenuClientQt.h" + +#include "ContextMenu.h" +#include "HitTestResult.h" +#include "KURL.h" +#include "RefCounted.h" +#include "NotImplemented.h" + +#include <stdio.h> + +namespace WebCore { + +void ContextMenuClientQt::contextMenuDestroyed() +{ + delete this; +} + +PlatformMenuDescription ContextMenuClientQt::getCustomMenuFromDefaultItems(ContextMenu* menu) +{ + // warning: this transfers the ownership to the caller + return menu->releasePlatformDescription(); +} + +void ContextMenuClientQt::contextMenuItemSelected(ContextMenuItem*, const ContextMenu*) +{ + notImplemented(); +} + +void ContextMenuClientQt::downloadURL(const KURL& url) +{ + notImplemented(); +} + +void ContextMenuClientQt::lookUpInDictionary(Frame*) +{ + notImplemented(); +} + +void ContextMenuClientQt::speak(const String&) +{ + notImplemented(); +} + +void ContextMenuClientQt::stopSpeaking() +{ + notImplemented(); +} + +void ContextMenuClientQt::searchWithGoogle(const Frame*) +{ + notImplemented(); +} + +} + diff --git a/WebKit/qt/WebCoreSupport/ContextMenuClientQt.h b/WebKit/qt/WebCoreSupport/ContextMenuClientQt.h new file mode 100644 index 0000000..ad6bfae --- /dev/null +++ b/WebKit/qt/WebCoreSupport/ContextMenuClientQt.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2006 Zack Rusin <zack@kde.org> + * + * 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. + */ + +#ifndef ContextMenuClientQt_h +#define ContextMenuClientQt_h + +#include "ContextMenuClient.h" + +#include <RefCounted.h> + +namespace WebCore { + class ContextMenu; + + class ContextMenuClientQt : public ContextMenuClient + { + public: + virtual void contextMenuDestroyed(); + + virtual PlatformMenuDescription getCustomMenuFromDefaultItems(ContextMenu*); + virtual void contextMenuItemSelected(ContextMenuItem*, const ContextMenu*); + + virtual void downloadURL(const KURL& url); + virtual void lookUpInDictionary(Frame*); + virtual void speak(const String&); + virtual void stopSpeaking(); + virtual void searchWithGoogle(const Frame*); + }; +} + +#endif diff --git a/WebKit/qt/WebCoreSupport/DragClientQt.cpp b/WebKit/qt/WebCoreSupport/DragClientQt.cpp new file mode 100644 index 0000000..b719868 --- /dev/null +++ b/WebKit/qt/WebCoreSupport/DragClientQt.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * 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 "DragClientQt.h" + +#include "ClipboardQt.h" +#include "qwebpage.h" + +#include <QDrag> +#include <QMimeData> + + +namespace WebCore { + +DragDestinationAction DragClientQt::actionMaskForDrag(DragData*) +{ + return DragDestinationActionAny; +} + +void DragClientQt::willPerformDragDestinationAction(DragDestinationAction, DragData*) +{ +} + +void DragClientQt::dragControllerDestroyed() +{ + delete this; +} + +DragSourceAction DragClientQt::dragSourceActionMaskForPoint(const IntPoint&) +{ + return DragSourceActionAny; +} + +void DragClientQt::willPerformDragSourceAction(DragSourceAction, const IntPoint&, Clipboard*) +{ +} + +void DragClientQt::startDrag(DragImageRef, const IntPoint&, const IntPoint&, Clipboard* clipboard, Frame*, bool) +{ +#ifndef QT_NO_DRAGANDDROP + QMimeData* clipboardData = static_cast<ClipboardQt*>(clipboard)->clipboardData(); + static_cast<ClipboardQt*>(clipboard)->invalidateWritableData(); + QWidget* view = m_webPage->view(); + if (view) { + QDrag *drag = new QDrag(view); + drag->setMimeData(clipboardData); + drag->start(); + } +#endif +} + + +DragImageRef DragClientQt::createDragImageForLink(KURL&, const String&, Frame*) +{ + return 0; +} + +} // namespace WebCore diff --git a/WebKit/qt/WebCoreSupport/DragClientQt.h b/WebKit/qt/WebCoreSupport/DragClientQt.h new file mode 100644 index 0000000..4c83191 --- /dev/null +++ b/WebKit/qt/WebCoreSupport/DragClientQt.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * 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 "DragClient.h" +class QWebPage; +namespace WebCore { + +class DragClientQt : public DragClient { +public: + DragClientQt(QWebPage* webPage) : m_webPage(webPage) {}; + virtual void willPerformDragDestinationAction(DragDestinationAction, + DragData*); + virtual WebCore::DragDestinationAction actionMaskForDrag(DragData*); + virtual void dragControllerDestroyed(); + virtual DragSourceAction dragSourceActionMaskForPoint(const IntPoint&); + virtual void willPerformDragSourceAction(DragSourceAction, const IntPoint&, Clipboard*); + virtual void startDrag(DragImageRef dragImage, const IntPoint& dragImageOrigin, const IntPoint& eventPos, Clipboard*, Frame*, bool linkDrag = false); + virtual DragImageRef createDragImageForLink(KURL&, const String& label, Frame*); +private: + QWebPage* m_webPage; +}; + +} + diff --git a/WebKit/qt/WebCoreSupport/EditCommandQt.cpp b/WebKit/qt/WebCoreSupport/EditCommandQt.cpp new file mode 100644 index 0000000..1532388 --- /dev/null +++ b/WebKit/qt/WebCoreSupport/EditCommandQt.cpp @@ -0,0 +1,57 @@ +/* + Copyright (C) 2007 Staikos Computing Services Inc. + + 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 <wtf/Platform.h> +#include "EditCommandQt.h" + +using namespace WebCore; + +EditCommandQt::EditCommandQt(WTF::RefPtr<EditCommand> cmd, QUndoCommand *parent) +: +#ifndef QT_NO_UNDOCOMMAND + QUndoCommand(parent), +#endif + _cmd(cmd), _first(true) +{ +} + + +EditCommandQt::~EditCommandQt() { +} + + +void EditCommandQt::redo() { + if (_first) { + _first = false; + return; + } + if (_cmd) { + _cmd->reapply(); + } +} + + +void EditCommandQt::undo() { + if (_cmd) { + _cmd->unapply(); + } +} + + +// vim: ts=4 sw=4 et diff --git a/WebKit/qt/WebCoreSupport/EditCommandQt.h b/WebKit/qt/WebCoreSupport/EditCommandQt.h new file mode 100644 index 0000000..ae6ea51 --- /dev/null +++ b/WebKit/qt/WebCoreSupport/EditCommandQt.h @@ -0,0 +1,50 @@ +/* + Copyright (C) 2007 Staikos Computing Services Inc. + + 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 EDITCOMMANDQT_H +#define EDITCOMMANDQT_H + +#include <qglobal.h> +QT_BEGIN_NAMESPACE +class QUndoCommand; +QT_END_NAMESPACE + +#include <QUndoCommand> +#include <EditCommand.h> + +class EditCommandQt +#ifndef QT_NO_UNDOCOMMAND + : public QUndoCommand +#endif +{ + public: + EditCommandQt(WTF::RefPtr<WebCore::EditCommand> cmd, QUndoCommand *parent = 0); + ~EditCommandQt(); + + void redo(); + void undo(); + + private: + WTF::RefPtr<WebCore::EditCommand> _cmd; + bool _first; +}; + +#endif + +// vim: ts=4 sw=4 et diff --git a/WebKit/qt/WebCoreSupport/EditorClientQt.cpp b/WebKit/qt/WebCoreSupport/EditorClientQt.cpp new file mode 100644 index 0000000..a25ff18 --- /dev/null +++ b/WebKit/qt/WebCoreSupport/EditorClientQt.cpp @@ -0,0 +1,593 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2006 Zack Rusin <zack@kde.org> + * Copyright (C) 2006 Apple Computer, Inc. + * + * All rights reserved. + * + * 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 "EditorClientQt.h" + +#include "qwebpage.h" +#include "qwebpage_p.h" + +#include "Document.h" +#include "EditCommandQt.h" +#include "Page.h" +#include "Editor.h" +#include "FocusController.h" +#include "Frame.h" +#include "KeyboardCodes.h" +#include "KeyboardEvent.h" +#include "Page.h" +#include "PlatformKeyboardEvent.h" +#include "NotImplemented.h" +#include "Node.h" +#include "Range.h" + +#include <stdio.h> + +#include <QUndoStack> +#define methodDebug() qDebug("EditorClientQt: %s", __FUNCTION__); + +static bool dumpEditingCallbacks = false; +static bool drt_run = false; +static bool acceptsEditing = true; +void QWEBKIT_EXPORT qt_dump_editing_callbacks(bool b) +{ + dumpEditingCallbacks = b; +} +void QWEBKIT_EXPORT qt_drt_run(bool b) +{ + drt_run = b; +} + +void QWEBKIT_EXPORT qt_dump_set_accepts_editing(bool b) +{ + acceptsEditing = b; +} + + +static QString dumpPath(WebCore::Node *node) +{ + QString str = node->nodeName(); + + WebCore::Node *parent = node->parentNode(); + while (parent) { + str.append(QLatin1String(" > ")); + str.append(parent->nodeName()); + parent = parent->parentNode(); + } + return str; +} + +static QString dumpRange(WebCore::Range *range) +{ + if (!range) + return QLatin1String("(null)"); + QString str; + WebCore::ExceptionCode code; + str.sprintf("range from %ld of %ls to %ld of %ls", + range->startOffset(code), dumpPath(range->startContainer(code)).unicode(), + range->endOffset(code), dumpPath(range->endContainer(code)).unicode()); + return str; +} + + +namespace WebCore { + + +bool EditorClientQt::shouldDeleteRange(Range* range) +{ + if (dumpEditingCallbacks) + printf("EDITING DELEGATE: shouldDeleteDOMRange:%s\n", dumpRange(range).toUtf8().constData()); + + return true; +} + +bool EditorClientQt::shouldShowDeleteInterface(HTMLElement* element) +{ + if (drt_run) + return element->className() == "needsDeletionUI"; + return false; +} + +bool EditorClientQt::isContinuousSpellCheckingEnabled() +{ + return false; +} + +bool EditorClientQt::isGrammarCheckingEnabled() +{ + return false; +} + +int EditorClientQt::spellCheckerDocumentTag() +{ + return 0; +} + +bool EditorClientQt::shouldBeginEditing(WebCore::Range* range) +{ + if (dumpEditingCallbacks) + printf("EDITING DELEGATE: shouldBeginEditingInDOMRange:%s\n", dumpRange(range).toUtf8().constData()); + return true; +} + +bool EditorClientQt::shouldEndEditing(WebCore::Range* range) +{ + if (dumpEditingCallbacks) + printf("EDITING DELEGATE: shouldEndEditingInDOMRange:%s\n", dumpRange(range).toUtf8().constData()); + return true; +} + +bool EditorClientQt::shouldInsertText(const String& string, Range* range, EditorInsertAction action) +{ + if (dumpEditingCallbacks) { + static const char *insertactionstring[] = { + "WebViewInsertActionTyped", + "WebViewInsertActionPasted", + "WebViewInsertActionDropped", + }; + + printf("EDITING DELEGATE: shouldInsertText:%s replacingDOMRange:%s givenAction:%s\n", + QString(string).toUtf8().constData(), dumpRange(range).toUtf8().constData(), insertactionstring[action]); + } + return acceptsEditing; +} + +bool EditorClientQt::shouldChangeSelectedRange(Range* currentRange, Range* proposedRange, EAffinity selectionAffinity, bool stillSelecting) +{ + if (dumpEditingCallbacks) { + static const char *affinitystring[] = { + "NSSelectionAffinityUpstream", + "NSSelectionAffinityDownstream" + }; + static const char *boolstring[] = { + "FALSE", + "TRUE" + }; + + printf("EDITING DELEGATE: shouldChangeSelectedDOMRange:%s toDOMRange:%s affinity:%s stillSelecting:%s\n", + dumpRange(currentRange).toUtf8().constData(), + dumpRange(proposedRange).toUtf8().constData(), + affinitystring[selectionAffinity], boolstring[stillSelecting]); + } + return acceptsEditing; +} + +bool EditorClientQt::shouldApplyStyle(WebCore::CSSStyleDeclaration* style, + WebCore::Range* range) +{ + if (dumpEditingCallbacks) + printf("EDITING DELEGATE: shouldApplyStyle:%s toElementsInDOMRange:%s\n", + QString(style->cssText()).toUtf8().constData(), dumpRange(range).toUtf8().constData()); + return acceptsEditing; +} + +bool EditorClientQt::shouldMoveRangeAfterDelete(WebCore::Range*, WebCore::Range*) +{ + notImplemented(); + return true; +} + +void EditorClientQt::didBeginEditing() +{ + if (dumpEditingCallbacks) + printf("EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification\n"); + m_editing = true; +} + +void EditorClientQt::respondToChangedContents() +{ + if (dumpEditingCallbacks) + printf("EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n"); + m_page->d->updateEditorActions(); + + emit m_page->contentsChanged(); +} + +void EditorClientQt::respondToChangedSelection() +{ + if (dumpEditingCallbacks) + printf("EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification\n"); +// const Selection &selection = m_page->d->page->selection(); +// char buffer[1024]; +// selection.formatForDebugger(buffer, sizeof(buffer)); +// printf("%s\n", buffer); + + m_page->d->updateEditorActions(); + emit m_page->selectionChanged(); + emit m_page->microFocusChanged(); +} + +void EditorClientQt::didEndEditing() +{ + if (dumpEditingCallbacks) + printf("EDITING DELEGATE: webViewDidEndEditing:WebViewDidEndEditingNotification\n"); + m_editing = false; +} + +void EditorClientQt::didWriteSelectionToPasteboard() +{ +} + +void EditorClientQt::didSetSelectionTypesForPasteboard() +{ +} + +bool EditorClientQt::selectWordBeforeMenuEvent() +{ + notImplemented(); + return false; +} + +bool EditorClientQt::isEditable() +{ + return m_page->isEditable(); +} + +void EditorClientQt::registerCommandForUndo(WTF::PassRefPtr<WebCore::EditCommand> cmd) +{ +#ifndef QT_NO_UNDOSTACK + Frame* frame = m_page->d->page->focusController()->focusedOrMainFrame(); + if (m_inUndoRedo || (frame && !frame->editor()->lastEditCommand() /* HACK!! Don't recreate undos */)) { + return; + } + m_page->undoStack()->push(new EditCommandQt(cmd)); +#endif // QT_NO_UNDOSTACK +} + +void EditorClientQt::registerCommandForRedo(WTF::PassRefPtr<WebCore::EditCommand>) +{ +} + +void EditorClientQt::clearUndoRedoOperations() +{ +#ifndef QT_NO_UNDOSTACK + return m_page->undoStack()->clear(); +#endif +} + +bool EditorClientQt::canUndo() const +{ +#ifdef QT_NO_UNDOSTACK + return false; +#else + return m_page->undoStack()->canUndo(); +#endif +} + +bool EditorClientQt::canRedo() const +{ +#ifdef QT_NO_UNDOSTACK + return false; +#else + return m_page->undoStack()->canRedo(); +#endif +} + +void EditorClientQt::undo() +{ +#ifndef QT_NO_UNDOSTACK + m_inUndoRedo = true; + m_page->undoStack()->undo(); + m_inUndoRedo = false; +#endif +} + +void EditorClientQt::redo() +{ +#ifndef QT_NO_UNDOSTACK + m_inUndoRedo = true; + m_page->undoStack()->redo(); + m_inUndoRedo = false; +#endif +} + +bool EditorClientQt::shouldInsertNode(Node* node, Range* range, EditorInsertAction action) +{ + if (dumpEditingCallbacks) { + static const char *insertactionstring[] = { + "WebViewInsertActionTyped", + "WebViewInsertActionPasted", + "WebViewInsertActionDropped", + }; + + printf("EDITING DELEGATE: shouldInsertNode:%s replacingDOMRange:%s givenAction:%s\n", dumpPath(node).toUtf8().constData(), + dumpRange(range).toUtf8().constData(), insertactionstring[action]); + } + return acceptsEditing; +} + +void EditorClientQt::pageDestroyed() +{ + delete this; +} + +bool EditorClientQt::smartInsertDeleteEnabled() +{ + notImplemented(); + return false; +} + +void EditorClientQt::toggleContinuousSpellChecking() +{ + notImplemented(); +} + +void EditorClientQt::toggleGrammarChecking() +{ + notImplemented(); +} + +void EditorClientQt::handleKeyboardEvent(KeyboardEvent* event) +{ + Frame* frame = m_page->d->page->focusController()->focusedOrMainFrame(); + if (!frame || !frame->document()->focusedNode()) + return; + + const PlatformKeyboardEvent* kevent = event->keyEvent(); + if (!kevent || kevent->type() == PlatformKeyboardEvent::KeyUp) + return; + + Node* start = frame->selection()->start().node(); + if (!start) + return; + + // FIXME: refactor all of this to use Actions or something like them + if (start->isContentEditable()) { + 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); + break; + case VK_DELETE: + frame->editor()->deleteWithDirection(SelectionController::FORWARD, + CharacterGranularity, false, true); + break; + case VK_LEFT: + if (kevent->shiftKey()) + frame->editor()->command("MoveLeftAndModifySelection").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(); + break; + case VK_UP: + if (kevent->shiftKey()) + frame->editor()->command("MoveUpAndModifySelection").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(); + break; + case VK_PRIOR: // PageUp + frame->editor()->command("MovePageUp").execute(); + break; + case VK_NEXT: // PageDown + frame->editor()->command("MovePageDown").execute(); + break; + case VK_TAB: + return; + default: + if (kevent->type() != PlatformKeyboardEvent::KeyDown && !kevent->ctrlKey() +#ifndef Q_WS_MAC + // We need to exclude checking for Alt because it is just a different Shift + && !kevent->altKey() +#endif + && !kevent->text().isEmpty()) { + frame->editor()->insertText(kevent->text(), event); + } else if (kevent->ctrlKey()) { + switch (kevent->windowsVirtualKeyCode()) { + case VK_A: + frame->editor()->command("SelectAll").execute(); + break; + case VK_B: + frame->editor()->command("ToggleBold").execute(); + break; + case VK_C: + frame->editor()->command("Copy").execute(); + break; + case VK_I: + frame->editor()->command("ToggleItalic").execute(); + break; + case VK_V: + frame->editor()->command("Paste").execute(); + break; + case VK_X: + frame->editor()->command("Cut").execute(); + break; + case VK_Y: + frame->editor()->command("Redo").execute(); + break; + case VK_Z: + frame->editor()->command("Undo").execute(); + break; + default: + // catch combination AltGr+key or Ctrl+Alt+key + if (kevent->type() != PlatformKeyboardEvent::KeyDown && kevent->altKey() && !kevent->text().isEmpty()) { + frame->editor()->insertText(kevent->text(), event); + break; + } + return; + } + } else return; + } + } else { + switch (kevent->windowsVirtualKeyCode()) { + case VK_UP: + frame->editor()->command("MoveUp").execute(); + break; + case VK_DOWN: + frame->editor()->command("MoveDown").execute(); + break; + case VK_PRIOR: // PageUp + frame->editor()->command("MovePageUp").execute(); + break; + case VK_NEXT: // PageDown + frame->editor()->command("MovePageDown").execute(); + break; + case VK_HOME: + if (kevent->ctrlKey()) + frame->editor()->command("MoveToBeginningOfDocument").execute(); + break; + case VK_END: + if (kevent->ctrlKey()) + frame->editor()->command("MoveToEndOfDocument").execute(); + break; + default: + if (kevent->ctrlKey()) { + switch (kevent->windowsVirtualKeyCode()) { + case VK_A: + frame->editor()->command("SelectAll").execute(); + break; + case VK_C: case VK_X: + frame->editor()->command("Copy").execute(); + break; + default: + return; + } + } else return; + } + } + event->setDefaultHandled(); +} + +void EditorClientQt::handleInputMethodKeydown(KeyboardEvent*) +{ +} + +EditorClientQt::EditorClientQt(QWebPage* page) + : m_page(page), m_editing(false), m_inUndoRedo(false) +{ +} + +void EditorClientQt::textFieldDidBeginEditing(Element*) +{ + m_editing = true; +} + +void EditorClientQt::textFieldDidEndEditing(Element*) +{ + m_editing = false; +} + +void EditorClientQt::textDidChangeInTextField(Element*) +{ +} + +bool EditorClientQt::doTextFieldCommandFromEvent(Element*, KeyboardEvent*) +{ + return false; +} + +void EditorClientQt::textWillBeDeletedInTextField(Element*) +{ +} + +void EditorClientQt::textDidChangeInTextArea(Element*) +{ +} + +void EditorClientQt::ignoreWordInSpellDocument(const String&) +{ + notImplemented(); +} + +void EditorClientQt::learnWord(const String&) +{ + notImplemented(); +} + +void EditorClientQt::checkSpellingOfString(const UChar*, int, int*, int*) +{ + notImplemented(); +} + +void EditorClientQt::checkGrammarOfString(const UChar*, int, Vector<GrammarDetail>&, int*, int*) +{ + notImplemented(); +} + +void EditorClientQt::updateSpellingUIWithGrammarString(const String&, const GrammarDetail&) +{ + notImplemented(); +} + +void EditorClientQt::updateSpellingUIWithMisspelledWord(const String&) +{ + notImplemented(); +} + +void EditorClientQt::showSpellingUI(bool) +{ + notImplemented(); +} + +bool EditorClientQt::spellingUIIsShowing() +{ + notImplemented(); + return false; +} + +void EditorClientQt::getGuessesForWord(const String&, Vector<String>&) +{ + notImplemented(); +} + +bool EditorClientQt::isEditing() const +{ + return m_editing; +} + +void EditorClientQt::setInputMethodState(bool active) +{ + QWidget *view = m_page->view(); + if (view) { + view->setAttribute(Qt::WA_InputMethodEnabled, active); + emit m_page->microFocusChanged(); + } +} + +} + +// vim: ts=4 sw=4 et diff --git a/WebKit/qt/WebCoreSupport/EditorClientQt.h b/WebKit/qt/WebCoreSupport/EditorClientQt.h new file mode 100644 index 0000000..35020b2 --- /dev/null +++ b/WebKit/qt/WebCoreSupport/EditorClientQt.h @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2006 Zack Rusin <zack@kde.org> + * Copyright (C) 2006 Apple Computer, Inc. + * + * All rights reserved. + * + * 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. + */ + +#ifndef EditorClientQt_H +#define EditorClientQt_H + +#include "EditorClient.h" +#include "RefCounted.h" + +#include <wtf/Forward.h> + +class QWebPage; + +namespace WebCore { + +class EditorClientQt : public EditorClient { +public: + EditorClientQt(QWebPage* page); + + virtual void pageDestroyed(); + + virtual bool shouldDeleteRange(Range*); + virtual bool shouldShowDeleteInterface(HTMLElement*); + virtual bool smartInsertDeleteEnabled(); + virtual bool isContinuousSpellCheckingEnabled(); + virtual void toggleContinuousSpellChecking(); + virtual bool isGrammarCheckingEnabled(); + virtual void toggleGrammarChecking(); + virtual int spellCheckerDocumentTag(); + + virtual bool selectWordBeforeMenuEvent(); + virtual bool isEditable(); + + virtual bool shouldBeginEditing(Range*); + virtual bool shouldEndEditing(Range*); + virtual bool shouldInsertNode(Node*, Range*, EditorInsertAction); + virtual bool shouldInsertText(const String&, Range*, EditorInsertAction); + virtual bool shouldChangeSelectedRange(Range* fromRange, Range* toRange, EAffinity, bool stillSelecting); + + virtual bool shouldApplyStyle(CSSStyleDeclaration*, Range*); + + virtual bool shouldMoveRangeAfterDelete(Range*, Range*); + + virtual void didBeginEditing(); + virtual void respondToChangedContents(); + virtual void respondToChangedSelection(); + virtual void didEndEditing(); + virtual void didWriteSelectionToPasteboard(); + virtual void didSetSelectionTypesForPasteboard(); + + virtual void registerCommandForUndo(PassRefPtr<EditCommand>); + virtual void registerCommandForRedo(PassRefPtr<EditCommand>); + virtual void clearUndoRedoOperations(); + + virtual bool canUndo() const; + virtual bool canRedo() const; + + virtual void undo(); + virtual void redo(); + + virtual void handleKeyboardEvent(KeyboardEvent*); + virtual void handleInputMethodKeydown(KeyboardEvent*); + + virtual void textFieldDidBeginEditing(Element*); + virtual void textFieldDidEndEditing(Element*); + virtual void textDidChangeInTextField(Element*); + virtual bool doTextFieldCommandFromEvent(Element*, KeyboardEvent*); + virtual void textWillBeDeletedInTextField(Element*); + virtual void textDidChangeInTextArea(Element*); + + virtual void ignoreWordInSpellDocument(const String&); + virtual void learnWord(const String&); + virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength); + virtual void checkGrammarOfString(const UChar*, int length, Vector<GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength); + virtual void updateSpellingUIWithGrammarString(const String&, const GrammarDetail&); + virtual void updateSpellingUIWithMisspelledWord(const String&); + virtual void showSpellingUI(bool show); + virtual bool spellingUIIsShowing(); + virtual void getGuessesForWord(const String&, Vector<String>& guesses); + virtual void setInputMethodState(bool enabled); + + bool isEditing() const; + +private: + QWebPage* m_page; + bool m_editing; + bool m_inUndoRedo; // our undo stack works differently - don't re-enter! +}; + +} + +#endif + +// vim: ts=4 sw=4 et diff --git a/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp b/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp new file mode 100644 index 0000000..6235ed6 --- /dev/null +++ b/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp @@ -0,0 +1,1125 @@ +/* + * 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) 2008 Collabora Ltd. All rights reserved. + * + * All rights reserved. + * + * 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 "CSSComputedStyleDeclaration.h" +#include "CSSPropertyNames.h" +#include "FrameLoaderClientQt.h" +#include "FrameTree.h" +#include "FrameView.h" +#include "DocumentLoader.h" +#include "MIMETypeRegistry.h" +#include "ResourceResponse.h" +#include "Page.h" +#include "PluginData.h" +#include "PluginDatabase.h" +#include "ProgressTracker.h" +#include "RenderPart.h" +#include "ResourceRequest.h" +#include "HistoryItem.h" +#include "HTMLFormElement.h" +#include "NotImplemented.h" +#include "QNetworkReplyHandler.h" +#include "ResourceHandleInternal.h" +#include "ResourceHandle.h" + +#include "qwebpage.h" +#include "qwebframe.h" +#include "qwebframe_p.h" +#include "qwebhistoryinterface.h" +#include "qwebpluginfactory.h" + +#include <qfileinfo.h> + +#include <QCoreApplication> +#include <QDebug> +#if QT_VERSION >= 0x040400 +#include <QNetworkRequest> +#include <QNetworkReply> +#else +#include "qwebnetworkinterface_p.h" +#endif +#include "qwebhistory_p.h" + +static bool dumpFrameLoaderCallbacks = false; +static bool dumpResourceLoadCallbacks = false; + +static QMap<unsigned long, QString> dumpAssignedUrls; + +void QWEBKIT_EXPORT qt_dump_frame_loader(bool b) +{ + dumpFrameLoaderCallbacks = b; +} + +void QWEBKIT_EXPORT qt_dump_resource_load_callbacks(bool b) +{ + dumpResourceLoadCallbacks = b; +} + +// Compare with WebKitTools/DumpRenderTree/mac/FrameLoadDelegate.mm +static QString drtDescriptionSuitableForTestResult(WebCore::Frame* _frame) +{ + QWebFrame* frame = QWebFramePrivate::kit(_frame); + QString name = frame->frameName(); + + bool isMainFrame = frame == frame->page()->mainFrame(); + if (isMainFrame) { + if (!name.isEmpty()) + return QString::fromLatin1("main frame \"%1\"").arg(name); + return QLatin1String("main frame"); + } else { + if (!name.isEmpty()) + return QString::fromLatin1("frame \"%1\"").arg(name); + return QLatin1String("frame (anonymous)"); + } +} + +static QString drtDescriptionSuitableForTestResult(const WebCore::KURL& _url) +{ + QUrl url = _url; + return url.toString(); +} + +static QString drtDescriptionSuitableForTestResult(const WebCore::ResourceError& error) +{ + QString failingURL = error.failingURL(); + return QString::fromLatin1("<NSError domain NSURLErrorDomain, code %1, failing URL \"%2\">").arg(error.errorCode()).arg(failingURL); +} + +static QString drtDescriptionSuitableForTestResult(const WebCore::ResourceRequest& request) +{ + QString url = request.url().string(); + return QString::fromLatin1("<NSURLRequest %1>").arg(url); +} + +static QString drtDescriptionSuitableForTestResult(const WebCore::ResourceResponse& response) +{ + QString text = response.httpStatusText(); + if (text.isEmpty()) + return QLatin1String("(null)"); + + return text; +} + + +namespace WebCore +{ + +FrameLoaderClientQt::FrameLoaderClientQt() + : m_frame(0) + , m_webFrame(0) + , m_pluginView(0) + , m_hasSentResponseToPlugin(false) + , m_firstData(false) + , m_policyFunction(0) + , m_loadSucceeded(false) +{ + connect(this, SIGNAL(sigCallPolicyFunction(int)), this, SLOT(slotCallPolicyFunction(int)), Qt::QueuedConnection); +} + + +FrameLoaderClientQt::~FrameLoaderClientQt() +{ +} + +void FrameLoaderClientQt::setFrame(QWebFrame* webFrame, Frame* frame) +{ + m_webFrame = webFrame; + m_frame = frame; + if (!m_webFrame || !m_webFrame->page()) { + qWarning("FrameLoaderClientQt::setFrame frame without Page!"); + return; + } + + connect(this, SIGNAL(loadStarted()), + m_webFrame->page(), SIGNAL(loadStarted())); + connect(this, SIGNAL(loadProgress(int)), + m_webFrame->page(), SIGNAL(loadProgress(int))); + connect(this, SIGNAL(loadFinished(bool)), + m_webFrame->page(), SIGNAL(loadFinished(bool))); + connect(this, SIGNAL(titleChanged(const QString&)), + m_webFrame, SIGNAL(titleChanged(const QString&))); +} + +QWebFrame* FrameLoaderClientQt::webFrame() const +{ + return m_webFrame; +} + +void FrameLoaderClientQt::callPolicyFunction(FramePolicyFunction function, PolicyAction action) +{ + ASSERT(!m_policyFunction); + ASSERT(function); + + m_policyFunction = function; + emit sigCallPolicyFunction(action); +} + +void FrameLoaderClientQt::slotCallPolicyFunction(int action) +{ + if (!m_frame || !m_policyFunction) + return; + FramePolicyFunction function = m_policyFunction; + m_policyFunction = 0; + (m_frame->loader()->*function)(WebCore::PolicyAction(action)); +} + +bool FrameLoaderClientQt::hasWebView() const +{ + //notImplemented(); + return true; +} + +void FrameLoaderClientQt::savePlatformDataToCachedPage(CachedPage*) +{ + notImplemented(); +} + +void FrameLoaderClientQt::transitionToCommittedFromCachedPage(CachedPage*) +{ +} + +void FrameLoaderClientQt::transitionToCommittedForNewPage() +{ + ASSERT(m_frame); + ASSERT(m_webFrame); + + Page* page = m_frame->page(); + ASSERT(page); + + bool isMainFrame = m_frame == page->mainFrame(); + + m_frame->setView(0); + + FrameView* frameView; + if (isMainFrame) + frameView = new FrameView(m_frame, m_webFrame->page()->viewportSize()); + else + frameView = new FrameView(m_frame); + + m_frame->setView(frameView); + // FrameViews are created with a ref count of 1. Release this ref since we've assigned it to frame. + frameView->deref(); + + if (m_webFrame && m_webFrame->page()) + m_webFrame->d->updateBackground(); + + if (m_frame->ownerRenderer()) + m_frame->ownerRenderer()->setWidget(frameView); +} + + +void FrameLoaderClientQt::makeRepresentation(DocumentLoader*) +{ + // don't need this for now I think. +} + + +void FrameLoaderClientQt::forceLayout() +{ + m_frame->forceLayout(true); +} + + +void FrameLoaderClientQt::forceLayoutForNonHTML() +{ +} + + +void FrameLoaderClientQt::setCopiesOnScroll() +{ + // apparently mac specific +} + + +void FrameLoaderClientQt::detachedFromParent2() +{ +} + + +void FrameLoaderClientQt::detachedFromParent3() +{ +} + +void FrameLoaderClientQt::dispatchDidHandleOnloadEvents() +{ + // don't need this one + if (dumpFrameLoaderCallbacks) + printf("%s - didHandleOnloadEventsForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); + +} + + +void FrameLoaderClientQt::dispatchDidReceiveServerRedirectForProvisionalLoad() +{ + if (dumpFrameLoaderCallbacks) + printf("%s - didReceiveServerRedirectForProvisionalLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); + + notImplemented(); +} + + +void FrameLoaderClientQt::dispatchDidCancelClientRedirect() +{ + if (dumpFrameLoaderCallbacks) + printf("%s - didCancelClientRedirectForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); + + notImplemented(); +} + + +void FrameLoaderClientQt::dispatchWillPerformClientRedirect(const KURL& url, + double interval, + double fireDate) +{ + if (dumpFrameLoaderCallbacks) + printf("%s - willPerformClientRedirectToURL: %s \n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)), qPrintable(drtDescriptionSuitableForTestResult(url))); + + notImplemented(); +} + + +void FrameLoaderClientQt::dispatchDidChangeLocationWithinPage() +{ + if (dumpFrameLoaderCallbacks) + printf("%s - didChangeLocationWithinPageForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); + + notImplemented(); +} + + +void FrameLoaderClientQt::dispatchWillClose() +{ + if (dumpFrameLoaderCallbacks) + printf("%s - willCloseFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); +} + + +void FrameLoaderClientQt::dispatchDidStartProvisionalLoad() +{ + if (dumpFrameLoaderCallbacks) + printf("%s - didStartProvisionalLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); + + if (m_webFrame) + emit m_webFrame->provisionalLoad(); +} + + +void FrameLoaderClientQt::dispatchDidReceiveTitle(const String& title) +{ + if (dumpFrameLoaderCallbacks) + printf("%s - didReceiveTitle: %s\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)), qPrintable(QString(title))); + + if (!m_webFrame) + return; + + + + // ### hack + emit m_webFrame->urlChanged(m_webFrame->url()); + emit titleChanged(title); +} + + +void FrameLoaderClientQt::dispatchDidCommitLoad() +{ + if (dumpFrameLoaderCallbacks) + printf("%s - didCommitLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); + + if (m_frame->tree()->parent() || !m_webFrame) + return; + + m_webFrame->page()->d->updateNavigationActions(); + + // We should assume first the frame has no title. If it has, then the above dispatchDidReceiveTitle() + // will be called very soon with the correct title. + // This properly resets the title when we navigate to a URI without a title. + emit titleChanged(String()); +} + + +void FrameLoaderClientQt::dispatchDidFinishDocumentLoad() +{ + if (dumpFrameLoaderCallbacks) + printf("%s - didFinishDocumentLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); + + if (m_frame->tree()->parent() || !m_webFrame) + return; + + m_webFrame->page()->d->updateNavigationActions(); +} + + +void FrameLoaderClientQt::dispatchDidFinishLoad() +{ + if (dumpFrameLoaderCallbacks) + printf("%s - didFinishLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); + + m_loadSucceeded = true; + + if (m_frame->tree()->parent() || !m_webFrame) + return; + m_webFrame->page()->d->updateNavigationActions(); +} + + +void FrameLoaderClientQt::dispatchDidFirstLayout() +{ + if (m_webFrame) + emit m_webFrame->initialLayoutCompleted(); +} + + +void FrameLoaderClientQt::dispatchShow() +{ + notImplemented(); +} + + +void FrameLoaderClientQt::cancelPolicyCheck() +{ +// qDebug() << "FrameLoaderClientQt::cancelPolicyCheck"; + m_policyFunction = 0; +} + + +void FrameLoaderClientQt::dispatchWillSubmitForm(FramePolicyFunction function, + PassRefPtr<FormState>) +{ + notImplemented(); + Q_ASSERT(!m_policyFunction); + // FIXME: This is surely too simple + callPolicyFunction(function, PolicyUse); +} + + +void FrameLoaderClientQt::dispatchDidLoadMainResource(DocumentLoader*) +{ +} + + +void FrameLoaderClientQt::revertToProvisionalState(DocumentLoader*) +{ + notImplemented(); +} + + +void FrameLoaderClientQt::postProgressStartedNotification() +{ + if (m_webFrame && m_frame->page()) { + emit loadStarted(); + postProgressEstimateChangedNotification(); + } + if (m_frame->tree()->parent() || !m_webFrame) + return; + m_webFrame->page()->d->updateNavigationActions(); +} + +void FrameLoaderClientQt::postProgressEstimateChangedNotification() +{ + if (m_webFrame && m_frame->page()) + emit loadProgress(qRound(m_frame->page()->progress()->estimatedProgress() * 100)); +} + +void FrameLoaderClientQt::postProgressFinishedNotification() +{ + // send a mousemove event to + // (1) update the cursor to change according to whatever is underneath the mouse cursor right now + // (2) display the tool tip if the mouse hovers a node which has a tool tip + if (m_frame && m_frame->eventHandler() && m_webFrame->page()) { + QWidget* view = m_webFrame->page()->view(); + if (view && view->hasFocus()) { + QPoint localPos = view->mapFromGlobal(QCursor::pos()); + if (view->rect().contains(localPos)) { + QMouseEvent event(QEvent::MouseMove, localPos, Qt::NoButton, Qt::NoButton, Qt::NoModifier); + m_frame->eventHandler()->mouseMoved(PlatformMouseEvent(&event, 0)); + } + } + } + + if (m_webFrame && m_frame->page()) + emit loadFinished(m_loadSucceeded); +} + +void FrameLoaderClientQt::setMainFrameDocumentReady(bool b) +{ + // this is only interesting once we provide an external API for the DOM +} + + +void FrameLoaderClientQt::willChangeTitle(DocumentLoader*) +{ + // no need for, dispatchDidReceiveTitle is the right callback +} + + +void FrameLoaderClientQt::didChangeTitle(DocumentLoader *) +{ + // no need for, dispatchDidReceiveTitle is the right callback +} + + +void FrameLoaderClientQt::finishedLoading(DocumentLoader* loader) +{ + if (!m_pluginView) { + if(m_firstData) { + FrameLoader *fl = loader->frameLoader(); + fl->setEncoding(m_response.textEncodingName(), false); + m_firstData = false; + } + } + else { + m_pluginView->didFinishLoading(); + m_pluginView = 0; + m_hasSentResponseToPlugin = false; + } +} + + +bool FrameLoaderClientQt::canShowMIMEType(const String& MIMEType) const +{ + if (MIMETypeRegistry::isSupportedImageMIMEType(MIMEType)) + return true; + + if (MIMETypeRegistry::isSupportedNonImageMIMEType(MIMEType)) + return true; + + if (PluginDatabase::installedPlugins()->isMIMETypeRegistered(MIMEType)) + return true; + + return false; +} + +bool FrameLoaderClientQt::representationExistsForURLScheme(const String& URLScheme) const +{ + return false; +} + + +String FrameLoaderClientQt::generatedMIMETypeForURLScheme(const String& URLScheme) const +{ + notImplemented(); + return String(); +} + + +void FrameLoaderClientQt::frameLoadCompleted() +{ + // Note: Can be called multiple times. + // Even if already complete, we might have set a previous item on a frame that + // didn't do any data loading on the past transaction. Make sure to clear these out. + m_frame->loader()->setPreviousHistoryItem(0); +} + + +void FrameLoaderClientQt::restoreViewState() +{ + notImplemented(); +} + + +void FrameLoaderClientQt::provisionalLoadStarted() +{ + // don't need to do anything here +} + + +void FrameLoaderClientQt::didFinishLoad() +{ +// notImplemented(); +} + + +void FrameLoaderClientQt::prepareForDataSourceReplacement() +{ + m_frame->loader()->detachChildren(); +} + +void FrameLoaderClientQt::setTitle(const String&, const KURL&) +{ + // no need for, dispatchDidReceiveTitle is the right callback +} + + +String FrameLoaderClientQt::userAgent(const KURL& url) +{ + if (m_webFrame) { + return m_webFrame->page()->userAgentForUrl(url); + } + return String(); +} + +void FrameLoaderClientQt::dispatchDidReceiveIcon() +{ + if (dumpFrameLoaderCallbacks) + printf("%s - didReceiveIconForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); + + if (m_webFrame) { + emit m_webFrame->iconChanged(); + } +} + +void FrameLoaderClientQt::frameLoaderDestroyed() +{ + delete m_webFrame; + m_frame = 0; + m_webFrame = 0; + + delete this; +} + +bool FrameLoaderClientQt::canHandleRequest(const WebCore::ResourceRequest&) const +{ + return true; +} + +void FrameLoaderClientQt::windowObjectCleared() +{ + if (dumpFrameLoaderCallbacks) + printf("%s - didClearWindowObjectForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); + + if (m_webFrame) + emit m_webFrame->javaScriptWindowObjectCleared(); +} + +void FrameLoaderClientQt::didPerformFirstNavigation() const +{ + if (m_frame->tree()->parent() || !m_webFrame) + return; + m_webFrame->page()->d->updateNavigationActions(); +} + +void FrameLoaderClientQt::registerForIconNotification(bool) +{ + notImplemented(); +} + +void FrameLoaderClientQt::updateGlobalHistory(const WebCore::KURL& url) +{ + QWebHistoryInterface *history = QWebHistoryInterface::defaultInterface(); + if (history) + history->addHistoryEntry(url.prettyURL()); +} + +bool FrameLoaderClientQt::shouldGoToHistoryItem(WebCore::HistoryItem *item) const +{ + return true; +} + +void FrameLoaderClientQt::saveViewStateToItem(WebCore::HistoryItem* item) +{ + QWebHistoryItem historyItem(new QWebHistoryItemPrivate(item)); + emit m_webFrame->aboutToUpdateHistory(&historyItem); +} + +bool FrameLoaderClientQt::canCachePage() const +{ + return true; +} + +void FrameLoaderClientQt::setMainDocumentError(WebCore::DocumentLoader* loader, const WebCore::ResourceError& error) +{ + if (!m_pluginView) { + if (m_firstData) { + loader->frameLoader()->setEncoding(m_response.textEncodingName(), false); + m_firstData = false; + } + } else { + m_pluginView->didFail(error); + m_pluginView = 0; + m_hasSentResponseToPlugin = false; + } +} + +void FrameLoaderClientQt::committedLoad(WebCore::DocumentLoader* loader, const char* data, int length) +{ + if (!m_pluginView) { + if (!m_frame) + return; + FrameLoader *fl = loader->frameLoader(); + if (m_firstData) { + fl->setEncoding(m_response.textEncodingName(), false); + m_firstData = false; + } + fl->addData(data, length); + } + + // We re-check here as the plugin can have been created + if (m_pluginView) { + if (!m_hasSentResponseToPlugin) { + m_pluginView->didReceiveResponse(loader->response()); + m_hasSentResponseToPlugin = true; + } + m_pluginView->didReceiveData(data, length); + } +} + +WebCore::ResourceError FrameLoaderClientQt::cancelledError(const WebCore::ResourceRequest& request) +{ + return ResourceError("Error", -999, request.url().prettyURL(), + QCoreApplication::translate("QWebFrame", "Request cancelled", 0, QCoreApplication::UnicodeUTF8)); +} + +// copied from WebKit/Misc/WebKitErrors[Private].h +enum { + WebKitErrorCannotShowMIMEType = 100, + WebKitErrorCannotShowURL = 101, + WebKitErrorFrameLoadInterruptedByPolicyChange = 102, + WebKitErrorCannotUseRestrictedPort = 103, + WebKitErrorCannotFindPlugIn = 200, + WebKitErrorCannotLoadPlugIn = 201, + WebKitErrorJavaUnavailable = 202, +}; + +WebCore::ResourceError FrameLoaderClientQt::blockedError(const WebCore::ResourceRequest& request) +{ + return ResourceError("Error", WebKitErrorCannotUseRestrictedPort, request.url().prettyURL(), + QCoreApplication::translate("QWebFrame", "Request blocked", 0, QCoreApplication::UnicodeUTF8)); +} + + +WebCore::ResourceError FrameLoaderClientQt::cannotShowURLError(const WebCore::ResourceRequest& request) +{ + return ResourceError("Error", WebKitErrorCannotShowURL, request.url().string(), + QCoreApplication::translate("QWebFrame", "Cannot show URL", 0, QCoreApplication::UnicodeUTF8)); +} + +WebCore::ResourceError FrameLoaderClientQt::interruptForPolicyChangeError(const WebCore::ResourceRequest& request) +{ + return ResourceError("Error", WebKitErrorFrameLoadInterruptedByPolicyChange, request.url().string(), + QCoreApplication::translate("QWebFrame", "Frame load interruped by policy change", 0, QCoreApplication::UnicodeUTF8)); +} + +WebCore::ResourceError FrameLoaderClientQt::cannotShowMIMETypeError(const WebCore::ResourceResponse& response) +{ + return ResourceError("Error", WebKitErrorCannotShowMIMEType, response.url().string(), + QCoreApplication::translate("QWebFrame", "Cannot show mimetype", 0, QCoreApplication::UnicodeUTF8)); +} + +WebCore::ResourceError FrameLoaderClientQt::fileDoesNotExistError(const WebCore::ResourceResponse& response) +{ + return ResourceError("Error", -998 /* ### */, response.url().string(), + QCoreApplication::translate("QWebFrame", "File does not exist", 0, QCoreApplication::UnicodeUTF8)); +} + +WebCore::ResourceError FrameLoaderClientQt::pluginWillHandleLoadError(const WebCore::ResourceResponse& response) +{ + notImplemented(); + return ResourceError(); +} + +bool FrameLoaderClientQt::shouldFallBack(const WebCore::ResourceError&) +{ + notImplemented(); + return false; +} + +WTF::PassRefPtr<WebCore::DocumentLoader> FrameLoaderClientQt::createDocumentLoader(const WebCore::ResourceRequest& request, const SubstituteData& substituteData) +{ + RefPtr<DocumentLoader> loader = DocumentLoader::create(request, substituteData); + if (substituteData.isValid()) + loader->setDeferMainResourceDataLoad(false); + 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; + + QNetworkReplyHandler* handler = handle->getInternal()->m_job; + QNetworkReply* reply = handler->release(); + if (reply) { + QWebPage *page = m_webFrame->page(); + if (page->forwardUnsupportedContent()) + emit m_webFrame->page()->unsupportedContent(reply); + else + reply->abort(); + } +#endif +} + +void FrameLoaderClientQt::assignIdentifierToInitialRequest(unsigned long identifier, WebCore::DocumentLoader* loader, const WebCore::ResourceRequest& request) +{ + if (dumpResourceLoadCallbacks) + dumpAssignedUrls[identifier] = drtDescriptionSuitableForTestResult(request.url()); +} + +void FrameLoaderClientQt::dispatchWillSendRequest(WebCore::DocumentLoader*, unsigned long identifier, WebCore::ResourceRequest& newRequest, const WebCore::ResourceResponse& redirectResponse) +{ + if (dumpResourceLoadCallbacks) + printf("%s - willSendRequest %s redirectResponse %s\n", + qPrintable(dumpAssignedUrls[identifier]), + qPrintable(drtDescriptionSuitableForTestResult(newRequest)), + qPrintable(drtDescriptionSuitableForTestResult(redirectResponse))); + + // seems like the Mac code doesn't do anything here by default neither + //qDebug() << "FrameLoaderClientQt::dispatchWillSendRequest" << request.isNull() << request.url().string`(); +} + +void FrameLoaderClientQt::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&) +{ + notImplemented(); +} + +void FrameLoaderClientQt::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&) +{ + notImplemented(); +} + +void FrameLoaderClientQt::dispatchDidReceiveResponse(WebCore::DocumentLoader*, unsigned long, const WebCore::ResourceResponse& response) +{ + + m_response = response; + m_firstData = true; + //qDebug() << " got response from" << response.url().string(); +} + +void FrameLoaderClientQt::dispatchDidReceiveContentLength(WebCore::DocumentLoader*, unsigned long, int) +{ +} + +void FrameLoaderClientQt::dispatchDidFinishLoading(WebCore::DocumentLoader* loader, unsigned long) +{ +} + +void FrameLoaderClientQt::dispatchDidFailLoading(WebCore::DocumentLoader* loader, unsigned long identifier, const WebCore::ResourceError& error) +{ + if (dumpResourceLoadCallbacks) + printf("%s - didFailLoadingWithError: %s\n", qPrintable(dumpAssignedUrls[identifier]), qPrintable(drtDescriptionSuitableForTestResult(error))); + + if (m_firstData) { + FrameLoader *fl = loader->frameLoader(); + fl->setEncoding(m_response.textEncodingName(), false); + m_firstData = false; + } +} + +bool FrameLoaderClientQt::dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int) +{ + notImplemented(); + return false; +} + +void FrameLoaderClientQt::dispatchDidFailProvisionalLoad(const WebCore::ResourceError&) +{ + if (dumpFrameLoaderCallbacks) + printf("%s - didFailProvisionalLoadWithError\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); + + m_loadSucceeded = false; +} + +void FrameLoaderClientQt::dispatchDidFailLoad(const WebCore::ResourceError&) +{ + if (dumpFrameLoaderCallbacks) + printf("%s - didFailLoadWithError\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); + + m_loadSucceeded = false; +} + +WebCore::Frame* FrameLoaderClientQt::dispatchCreatePage() +{ + if (!m_webFrame) + return 0; + QWebPage *newPage = m_webFrame->page()->createWindow(QWebPage::WebBrowserWindow); + if (!newPage) + return 0; + return newPage->mainFrame()->d->frame; +} + +void FrameLoaderClientQt::dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const WebCore::String& MIMEType, const WebCore::ResourceRequest&) +{ + // we need to call directly here + Q_ASSERT(!m_policyFunction); + m_policyFunction = function; + if (canShowMIMEType(MIMEType)) + slotCallPolicyFunction(PolicyUse); + else + slotCallPolicyFunction(PolicyDownload); +} + +void FrameLoaderClientQt::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const WebCore::NavigationAction& action, const WebCore::ResourceRequest& request, PassRefPtr<WebCore::FormState>, const WebCore::String&) +{ + Q_ASSERT(!m_policyFunction); + Q_ASSERT(m_webFrame); + m_policyFunction = function; +#if QT_VERSION < 0x040400 + QWebNetworkRequest r(request); +#else + QNetworkRequest r(request.toNetworkRequest()); +#endif + QWebPage* page = m_webFrame->page(); + + if (!page->d->acceptNavigationRequest(0, r, QWebPage::NavigationType(action.type()))) { + if (action.type() == NavigationTypeFormSubmitted || action.type() == NavigationTypeFormResubmitted) + m_frame->loader()->resetMultipleFormSubmissionProtection(); + slotCallPolicyFunction(PolicyIgnore); + return; + } + slotCallPolicyFunction(PolicyUse); +} + +void FrameLoaderClientQt::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const WebCore::NavigationAction& action, const WebCore::ResourceRequest& request, PassRefPtr<WebCore::FormState>) +{ + Q_ASSERT(!m_policyFunction); + Q_ASSERT(m_webFrame); + m_policyFunction = function; +#if QT_VERSION < 0x040400 + QWebNetworkRequest r(request); +#else + QNetworkRequest r(request.toNetworkRequest()); +#endif + QWebPage*page = m_webFrame->page(); + + if (!page->d->acceptNavigationRequest(m_webFrame, r, QWebPage::NavigationType(action.type()))) { + if (action.type() == NavigationTypeFormSubmitted || action.type() == NavigationTypeFormResubmitted) + m_frame->loader()->resetMultipleFormSubmissionProtection(); + slotCallPolicyFunction(PolicyIgnore); + return; + } + slotCallPolicyFunction(PolicyUse); +} + +void FrameLoaderClientQt::dispatchUnableToImplementPolicy(const WebCore::ResourceError&) +{ + notImplemented(); +} + +void FrameLoaderClientQt::startDownload(const WebCore::ResourceRequest& request) +{ +#if QT_VERSION >= 0x040400 + if (!m_webFrame) + return; + + QWebPage *page = m_webFrame->page(); + emit m_webFrame->page()->downloadRequested(request.toNetworkRequest()); +#endif +} + +PassRefPtr<Frame> FrameLoaderClientQt::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement, + const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight) +{ + if (!m_webFrame) + return 0; + + QWebFrameData frameData; + frameData.url = url; + frameData.name = name; + frameData.ownerElement = ownerElement; + frameData.referrer = referrer; + frameData.allowsScrolling = allowsScrolling; + frameData.marginWidth = marginWidth; + frameData.marginHeight = marginHeight; + + QWebFrame* webFrame = new QWebFrame(m_webFrame, &frameData); + emit m_webFrame->page()->frameCreated(webFrame); + + RefPtr<Frame> childFrame = adoptRef(webFrame->d->frame); + + // FIXME: All of the below should probably be moved over into WebCore + childFrame->tree()->setName(name); + m_frame->tree()->appendChild(childFrame); + // ### set override encoding if we have one + + FrameLoadType loadType = m_frame->loader()->loadType(); + FrameLoadType childLoadType = FrameLoadTypeRedirectWithLockedHistory; + + childFrame->loader()->loadURL(frameData.url, frameData.referrer, String(), childLoadType, 0, 0); + + // The frame's onload handler may have removed it from the document. + if (!childFrame->tree()->parent()) + return 0; + + return childFrame.release(); +} + +ObjectContentType FrameLoaderClientQt::objectContentType(const KURL& url, const String& _mimeType) +{ +// qDebug()<<" ++++++++++++++++ url is "<<url.prettyURL()<<", mime = "<<_mimeType; + if (_mimeType == "application/x-qt-plugin" || _mimeType == "application/x-qt-styled-widget") + return ObjectContentOtherPlugin; + + if (url.isEmpty() && !_mimeType.length()) + return ObjectContentNone; + + String mimeType = _mimeType; + if (!mimeType.length()) { + QFileInfo fi(url.path()); + mimeType = MIMETypeRegistry::getMIMETypeForExtension(fi.suffix()); + } + + if (!mimeType.length()) + return ObjectContentFrame; + + if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType)) + return ObjectContentImage; + + if (PluginDatabase::installedPlugins()->isMIMETypeRegistered(mimeType)) + return ObjectContentNetscapePlugin; + + if (m_frame->page() && m_frame->page()->pluginData()->supportsMimeType(mimeType)) + return ObjectContentOtherPlugin; + + if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType)) + return ObjectContentFrame; + + if (url.protocol() == "about") + return ObjectContentFrame; + + return ObjectContentNone; +} + +static const CSSPropertyID qstyleSheetProperties[] = { + CSSPropertyColor, + CSSPropertyFontFamily, + CSSPropertyFontSize, + CSSPropertyFontStyle, + CSSPropertyFontWeight +}; + +const unsigned numqStyleSheetProperties = sizeof(qstyleSheetProperties) / sizeof(qstyleSheetProperties[0]); + +class QtPluginWidget: public Widget +{ +public: + QtPluginWidget(QWidget* w = 0): Widget(w) {} + virtual void invalidateRect(const IntRect& r) + { + if (platformWidget()) + platformWidget()->update(r); + } +}; + +Widget* FrameLoaderClientQt::createPlugin(const IntSize& pluginSize, Element* element, const KURL& url, const Vector<String>& paramNames, + const Vector<String>& paramValues, const String& mimeType, bool loadManually) +{ +// qDebug()<<"------ Creating plugin in FrameLoaderClientQt::createPlugin for "<<url.prettyURL() << mimeType; +// qDebug()<<"------\t url = "<<url.prettyURL(); + + if (!m_webFrame) + return 0; + + QStringList params; + QStringList values; + QString classid(element->getAttribute("classid")); + + for (int i = 0; i < paramNames.size(); ++i) { + params.append(paramNames[i]); + if (paramNames[i] == "classid") + classid = paramValues[i]; + } + for (int i = 0; i < paramValues.size(); ++i) + values.append(paramValues[i]); + + QString urlStr(url.string()); + QUrl qurl = urlStr; + + QObject *object = 0; + + if (mimeType == "application/x-qt-plugin" || mimeType == "application/x-qt-styled-widget") { + object = m_webFrame->page()->createPlugin(classid, qurl, params, values); +#ifndef QT_NO_STYLE_STYLESHEET + QWidget *widget = qobject_cast<QWidget *>(object); + if (widget && mimeType == "application/x-qt-styled-widget") { + + QString styleSheet = element->getAttribute("style"); + if (!styleSheet.isEmpty()) + styleSheet += QLatin1Char(';'); + + for (int i = 0; i < numqStyleSheetProperties; ++i) { + CSSPropertyID property = qstyleSheetProperties[i]; + + styleSheet += QString::fromLatin1(::getPropertyName(property)); + styleSheet += QLatin1Char(':'); + styleSheet += computedStyle(element)->getPropertyValue(property); + styleSheet += QLatin1Char(';'); + } + + widget->setStyleSheet(styleSheet); + } +#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); + QWidget *view = m_webFrame->page()->view(); + if (widget && view) { + widget->setParent(view); + QtPluginWidget* w= new QtPluginWidget(); + w->setPlatformWidget(widget); + return w; + } + // FIXME: make things work for widgetless plugins as well + delete object; + } else { // NPAPI Plugins + PluginView* pluginView = PluginView::create(m_frame, pluginSize, element, url, + paramNames, paramValues, mimeType, loadManually); + return pluginView; + } + + return 0; +} + +void FrameLoaderClientQt::redirectDataToPlugin(Widget* pluginWidget) +{ + ASSERT(!m_pluginView); + m_pluginView = static_cast<PluginView*>(pluginWidget); + m_hasSentResponseToPlugin = false; +} + +Widget* FrameLoaderClientQt::createJavaAppletWidget(const IntSize&, Element*, const KURL& baseURL, + const Vector<String>& paramNames, const Vector<String>& paramValues) +{ + notImplemented(); + return 0; +} + +String FrameLoaderClientQt::overrideMediaType() const +{ + return String(); +} + +QString FrameLoaderClientQt::chooseFile(const QString& oldFile) +{ + return webFrame()->page()->chooseFile(webFrame(), oldFile); +} + +} + +#include "moc_FrameLoaderClientQt.cpp" diff --git a/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h b/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h new file mode 100644 index 0000000..0156412 --- /dev/null +++ b/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h @@ -0,0 +1,218 @@ +/* + * 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) 2008 Collabora Ltd. All rights reserved. + * + * All rights reserved. + * + * 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. + */ +#ifndef FrameLoaderClientQt_H +#define FrameLoaderClientQt_H + +#include <qobject.h> +#include <QUrl> + +#include "FrameLoaderClient.h" +#include "KURL.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "RefCounted.h" +#include "ResourceResponse.h" +#include "PluginView.h" +class QWebFrame; + +namespace WebCore { + + class AuthenticationChallenge; + class DocumentLoader; + class Element; + class FormState; + class NavigationAction; + class String; + class ResourceLoader; + + struct LoadErrorResetToken; + + class FrameLoaderClientQt : public QObject, public FrameLoaderClient { + Q_OBJECT + + friend class ::QWebFrame; + void callPolicyFunction(FramePolicyFunction function, PolicyAction action); + private slots: + void slotCallPolicyFunction(int); + signals: + void sigCallPolicyFunction(int); + void loadStarted(); + void loadProgress(int d); + void loadFinished(bool); + void titleChanged(const QString& title); + + public: + FrameLoaderClientQt(); + ~FrameLoaderClientQt(); + virtual void frameLoaderDestroyed(); + + void setFrame(QWebFrame* webFrame, Frame* frame); + QWebFrame* webFrame() const; + + virtual bool hasWebView() const; // mainly for assertions + + virtual void makeRepresentation(DocumentLoader*); + virtual void forceLayout(); + virtual void forceLayoutForNonHTML(); + + virtual void setCopiesOnScroll(); + + virtual void detachedFromParent2(); + virtual void detachedFromParent3(); + + virtual void assignIdentifierToInitialRequest(unsigned long identifier, WebCore::DocumentLoader*, const WebCore::ResourceRequest&); + + virtual void dispatchWillSendRequest(WebCore::DocumentLoader*, unsigned long, WebCore::ResourceRequest&, const WebCore::ResourceResponse&); + virtual void dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&); + virtual void dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&); + virtual void dispatchDidReceiveResponse(WebCore::DocumentLoader*, unsigned long, const WebCore::ResourceResponse&); + virtual void dispatchDidReceiveContentLength(WebCore::DocumentLoader*, unsigned long, int); + virtual void dispatchDidFinishLoading(WebCore::DocumentLoader*, unsigned long); + virtual void dispatchDidFailLoading(WebCore::DocumentLoader*, unsigned long, const WebCore::ResourceError&); + virtual bool dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int); + + virtual void dispatchDidHandleOnloadEvents(); + virtual void dispatchDidReceiveServerRedirectForProvisionalLoad(); + virtual void dispatchDidCancelClientRedirect(); + virtual void dispatchWillPerformClientRedirect(const KURL&, double interval, double fireDate); + virtual void dispatchDidChangeLocationWithinPage(); + virtual void dispatchWillClose(); + virtual void dispatchDidReceiveIcon(); + virtual void dispatchDidStartProvisionalLoad(); + virtual void dispatchDidReceiveTitle(const String& title); + virtual void dispatchDidCommitLoad(); + virtual void dispatchDidFailProvisionalLoad(const ResourceError&); + virtual void dispatchDidFailLoad(const WebCore::ResourceError&); + virtual void dispatchDidFinishDocumentLoad(); + virtual void dispatchDidFinishLoad(); + virtual void dispatchDidFirstLayout(); + + virtual WebCore::Frame* dispatchCreatePage(); + virtual void dispatchShow(); + + virtual void dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const WebCore::String&, const WebCore::ResourceRequest&); + virtual void dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const WebCore::NavigationAction&, const WebCore::ResourceRequest&, PassRefPtr<FormState>, const WebCore::String&); + virtual void dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const WebCore::NavigationAction&, const WebCore::ResourceRequest&, PassRefPtr<FormState>); + virtual void cancelPolicyCheck(); + + virtual void dispatchUnableToImplementPolicy(const WebCore::ResourceError&); + + virtual void dispatchWillSubmitForm(FramePolicyFunction, PassRefPtr<FormState>); + + virtual void dispatchDidLoadMainResource(DocumentLoader*); + virtual void revertToProvisionalState(DocumentLoader*); + virtual void setMainDocumentError(DocumentLoader*, const ResourceError&); + + virtual void postProgressStartedNotification(); + virtual void postProgressEstimateChangedNotification(); + virtual void postProgressFinishedNotification(); + + virtual void setMainFrameDocumentReady(bool); + + virtual void startDownload(const WebCore::ResourceRequest&); + + virtual void willChangeTitle(DocumentLoader*); + virtual void didChangeTitle(DocumentLoader*); + + virtual void committedLoad(WebCore::DocumentLoader*, const char*, int); + virtual void finishedLoading(DocumentLoader*); + + virtual void updateGlobalHistory(const KURL&); + virtual bool shouldGoToHistoryItem(HistoryItem*) const; + + virtual ResourceError cancelledError(const ResourceRequest&); + virtual ResourceError blockedError(const ResourceRequest&); + virtual ResourceError cannotShowURLError(const ResourceRequest&); + virtual ResourceError interruptForPolicyChangeError(const ResourceRequest&); + + virtual ResourceError cannotShowMIMETypeError(const ResourceResponse&); + virtual ResourceError fileDoesNotExistError(const ResourceResponse&); + virtual ResourceError pluginWillHandleLoadError(const ResourceResponse&); + + virtual bool shouldFallBack(const ResourceError&); + + virtual bool canHandleRequest(const WebCore::ResourceRequest&) const; + virtual bool canShowMIMEType(const String& MIMEType) const; + virtual bool representationExistsForURLScheme(const String& URLScheme) const; + virtual String generatedMIMETypeForURLScheme(const String& URLScheme) const; + + virtual void frameLoadCompleted(); + virtual void saveViewStateToItem(WebCore::HistoryItem*); + virtual void restoreViewState(); + virtual void provisionalLoadStarted(); + virtual void didFinishLoad(); + virtual void prepareForDataSourceReplacement(); + + virtual WTF::PassRefPtr<WebCore::DocumentLoader> createDocumentLoader(const WebCore::ResourceRequest&, const WebCore::SubstituteData&); + virtual void setTitle(const String& title, const KURL&); + + virtual String userAgent(const WebCore::KURL&); + + virtual void savePlatformDataToCachedPage(WebCore::CachedPage*); + virtual void transitionToCommittedFromCachedPage(WebCore::CachedPage*); + virtual void transitionToCommittedForNewPage(); + + virtual bool canCachePage() const; + virtual void download(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&); + + virtual PassRefPtr<Frame> createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement, + const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight) ; + virtual Widget* createPlugin(const IntSize&, Element*, const KURL&, const Vector<String>&, const Vector<String>&, const String&, bool); + virtual void redirectDataToPlugin(Widget* pluginWidget); + + virtual Widget* createJavaAppletWidget(const IntSize&, Element*, const KURL& baseURL, const Vector<String>& paramNames, const Vector<String>& paramValues); + + virtual ObjectContentType objectContentType(const KURL& url, const String& mimeType); + virtual String overrideMediaType() const; + + virtual void windowObjectCleared(); + virtual void didPerformFirstNavigation() const; + + virtual void registerForIconNotification(bool); + + QString chooseFile(const QString& oldFile); + + private: + Frame *m_frame; + QWebFrame *m_webFrame; + ResourceResponse m_response; + bool m_firstData; + FramePolicyFunction m_policyFunction; + + // Plugin view to redirect data to + WebCore::PluginView* m_pluginView; + bool m_hasSentResponseToPlugin; + + bool m_loadSucceeded; + }; + +} + +#endif diff --git a/WebKit/qt/WebCoreSupport/InspectorClientQt.cpp b/WebKit/qt/WebCoreSupport/InspectorClientQt.cpp new file mode 100644 index 0000000..7335280 --- /dev/null +++ b/WebKit/qt/WebCoreSupport/InspectorClientQt.cpp @@ -0,0 +1,206 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2008 Holger Hans Peter Freyther + * + * 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 OR ITS 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 "InspectorClientQt.h" + +#include "qwebpage.h" +#include "qwebpage_p.h" +#include "qwebview.h" + +#include <QtCore/QCoreApplication> + +#include "InspectorController.h" +#include "NotImplemented.h" +#include "Page.h" +#include "PlatformString.h" + +namespace WebCore { + +class InspectorClientWebPage : public QWebPage +{ + Q_OBJECT + friend class InspectorClientQt; +public: + QWebPage* createWindow(QWebPage::WebWindowType) + { + QWidget *w = new QWebView(0); + QWebPage *page = new QWebPage(w); + page->setView(w); + connect(page, SIGNAL(destroyed()), w, SLOT(deleteLater())); + return page; + } + +Q_SIGNALS: + void attachRequested(); + void detachRequested(); +}; + + +class InspectorClientView : public QWebView { +public: + InspectorClientView(InspectorController* controller) + : QWebView(0) + , m_controller(controller) + { + setPage(new InspectorClientWebPage); + connect(page(), SIGNAL(destroyed()), SLOT(deleteLater())); + } + +protected: + + void closeEvent(QCloseEvent* ev) + { + QWidget::closeEvent(ev); + m_controller->setWindowVisible(false); + } + +private: + InspectorController* m_controller; +}; + + +InspectorClientQt::InspectorClientQt(QWebPage* page) + : m_inspectedWebPage(page) +{} + +void InspectorClientQt::inspectorDestroyed() +{ + delete this; +} + +Page* InspectorClientQt::createPage() +{ + if (m_webPage) + return m_webPage->d->page; + + InspectorClientView* view = new InspectorClientView(m_inspectedWebPage->d->page->inspectorController()); + m_webPage.set(qobject_cast<InspectorClientWebPage*>(view->page())); + m_webPage->mainFrame()->load(QString::fromLatin1("qrc:/webkit/inspector/inspector.html")); + m_webPage->view()->setMinimumSize(400,300); + return m_webPage->d->page; +} + +String InspectorClientQt::localizedStringsURL() +{ + notImplemented(); + return String(); +} + +void InspectorClientQt::showWindow() +{ + if (!m_webPage) + return; + + updateWindowTitle(); + m_webPage->view()->show(); + m_inspectedWebPage->d->page->inspectorController()->setWindowVisible(true); +} + +void InspectorClientQt::closeWindow() +{ + if (!m_webPage) + return; + + m_webPage->view()->hide(); + m_inspectedWebPage->d->page->inspectorController()->setWindowVisible(false); +} + +bool InspectorClientQt::windowVisible() +{ + if (!m_webPage) + return false; + return m_webPage->view()->isVisible(); +} + +void InspectorClientQt::attachWindow() +{ + if (!m_webPage) + return; + + emit m_webPage->attachRequested(); +} + +void InspectorClientQt::detachWindow() +{ + if (!m_webPage) + return; + + emit m_webPage->detachRequested(); +} + +void InspectorClientQt::setAttachedWindowHeight(unsigned height) +{ + notImplemented(); +} + +void InspectorClientQt::highlight(Node* node) +{ + notImplemented(); +} + +void InspectorClientQt::hideHighlight() +{ + notImplemented(); +} + +void InspectorClientQt::inspectedURLChanged(const String& newURL) +{ + m_inspectedURL = newURL; + updateWindowTitle(); +} + +void InspectorClientQt::updateWindowTitle() +{ + if (!m_webPage) + return; + + QString caption = QCoreApplication::translate("QWebPage", "Web Inspector - %2"); + m_webPage->view()->setWindowTitle(caption.arg(m_inspectedURL)); +} + +void InspectorClientQt::populateSetting(const String& key, InspectorController::Setting& setting) +{ + notImplemented(); +} + +void InspectorClientQt::storeSetting(const String& key, const InspectorController::Setting& setting) +{ + notImplemented(); +} + +void InspectorClientQt::removeSetting(const String& key) +{ + notImplemented(); +} + +} + +#include "InspectorClientQt.moc" diff --git a/WebKit/qt/WebCoreSupport/InspectorClientQt.h b/WebKit/qt/WebCoreSupport/InspectorClientQt.h new file mode 100644 index 0000000..49c2d56 --- /dev/null +++ b/WebKit/qt/WebCoreSupport/InspectorClientQt.h @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * + * 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 OR ITS 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. + */ + +#ifndef InspectorClientQt_h +#define InspectorClientQt_h + +#include "InspectorClient.h" +#include "OwnPtr.h" +#include <QtCore/QString> + +class QWebPage; + +namespace WebCore { + class Node; + class Page; + class String; + class InspectorClientWebPage; + + class InspectorClientQt : public InspectorClient { + public: + InspectorClientQt(QWebPage*); + + virtual void inspectorDestroyed(); + + virtual Page* createPage(); + + virtual String localizedStringsURL(); + + virtual void showWindow(); + virtual void closeWindow(); + virtual bool windowVisible(); + + virtual void attachWindow(); + virtual void detachWindow(); + + virtual void setAttachedWindowHeight(unsigned height); + + virtual void highlight(Node*); + virtual void hideHighlight(); + virtual void inspectedURLChanged(const String& newURL); + + virtual void populateSetting(const String& key, InspectorController::Setting&); + virtual void storeSetting(const String& key, const InspectorController::Setting&); + virtual void removeSetting(const String& key); + + private: + void updateWindowTitle(); + QWebPage* m_inspectedWebPage; + OwnPtr<InspectorClientWebPage> m_webPage; + QString m_inspectedURL; + }; +} + +#endif |