diff options
Diffstat (limited to 'WebKit/qt/WebCoreSupport')
-rw-r--r-- | WebKit/qt/WebCoreSupport/ChromeClientQt.cpp | 356 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/ChromeClientQt.h | 121 | ||||
-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 | 52 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/EditCommandQt.h | 42 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/EditorClientQt.cpp | 551 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/EditorClientQt.h | 120 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp | 1023 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h | 228 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/InspectorClientQt.cpp | 187 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/InspectorClientQt.h | 74 |
14 files changed, 3013 insertions, 0 deletions
diff --git a/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp b/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp new file mode 100644 index 0000000..a106f03 --- /dev/null +++ b/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp @@ -0,0 +1,356 @@ +/* + * 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 "Frame.h" +#include "FrameLoadRequest.h" +#include "FrameLoader.h" +#include "FrameLoaderClientQt.h" +#include "FrameView.h" +#include "PlatformScrollBar.h" +#include "HitTestResult.h" +#include "NotImplemented.h" +#include "WindowFeatures.h" + +#include "qwebpage.h" +#include "qwebpage_p.h" +#include "qwebframe_p.h" + +namespace WebCore +{ + + +ChromeClientQt::ChromeClientQt(QWebPage* webPage) + : m_webPage(webPage) +{ + +} + + +ChromeClientQt::~ChromeClientQt() +{ + +} + +void ChromeClientQt::setWindowRect(const FloatRect& rect) +{ + if (!m_webPage) + return; + emit m_webPage->geometryChangeRequest(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 = features.dialog ? m_webPage->createModalDialog() : m_webPage->createWindow(); + 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) +{ + notImplemented(); +} + + +bool ChromeClientQt::toolbarsVisible() +{ + notImplemented(); + return false; +} + + +void ChromeClientQt::setStatusbarVisible(bool) +{ + notImplemented(); +} + + +bool ChromeClientQt::statusbarVisible() +{ + notImplemented(); + return false; +} + + +void ChromeClientQt::setScrollbarsVisible(bool) +{ + notImplemented(); +} + + +bool ChromeClientQt::scrollbarsVisible() +{ + notImplemented(); + return true; +} + + +void ChromeClientQt::setMenubarVisible(bool) +{ + notImplemented(); +} + +bool ChromeClientQt::menubarVisible() +{ + notImplemented(); + return false; +} + +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(); + m_webPage->deleteLater(); +} + +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->statusBarTextChanged(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::addToDirtyRegion(const IntRect& r) +{ + QWidget* view = m_webPage->view(); + if (view) { + QRect rect(r); + rect = rect.intersected(QRect(QPoint(0, 0), m_webPage->viewportSize())); + if (!r.isEmpty()) + view->update(r); + } +} + +void ChromeClientQt::scrollBackingStore(int dx, int dy, const IntRect& scrollViewRect, const IntRect& clipRect) +{ + QWidget* view = m_webPage->view(); + if (view) + view->scroll(dx, dy, scrollViewRect); +} + +void ChromeClientQt::updateBackingStore() +{ +} + +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->hoveringOverLink(lastHoverURL.prettyURL(), + lastHoverTitle, lastHoverContent); + } +} + +void ChromeClientQt::setToolTip(const String &tip) +{ +#ifndef QT_NO_TOOLTIP + QWidget* view = m_webPage->view(); + if (view) + view->setToolTip(tip); +#else + Q_UNUSED(tip); +#endif +} + +void ChromeClientQt::print(Frame*) +{ + notImplemented(); +} + +void ChromeClientQt::exceededDatabaseQuota(Frame*, const String&) +{ + notImplemented(); +} + +} + + diff --git a/WebKit/qt/WebCoreSupport/ChromeClientQt.h b/WebKit/qt/WebCoreSupport/ChromeClientQt.h new file mode 100644 index 0000000..31d492b --- /dev/null +++ b/WebKit/qt/WebCoreSupport/ChromeClientQt.h @@ -0,0 +1,121 @@ +/* + * 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 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 addToDirtyRegion(const IntRect&); + virtual void scrollBackingStore(int, int, const IntRect&, const IntRect&); + virtual void updateBackingStore(); + + virtual void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags); + + virtual void setToolTip(const String&); + + virtual void print(Frame*); + + virtual void exceededDatabaseQuota(Frame*, const String&); + + QWebPage* m_webPage; + WebCore::KURL lastHoverURL; + WebCore::String lastHoverTitle; + WebCore::String lastHoverContent; + }; +} + +#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..e316a16 --- /dev/null +++ b/WebKit/qt/WebCoreSupport/EditCommandQt.cpp @@ -0,0 +1,52 @@ +/* + 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) +: QUndoCommand(parent), _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..dd7c85a --- /dev/null +++ b/WebKit/qt/WebCoreSupport/EditCommandQt.h @@ -0,0 +1,42 @@ +/* + 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 <QUndoCommand> +#include <EditCommand.h> + +class EditCommandQt : public QUndoCommand { + 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..fced385 --- /dev/null +++ b/WebKit/qt/WebCoreSupport/EditorClientQt.cpp @@ -0,0 +1,551 @@ +/* + * 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(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->modified = true; +} + +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(); +} + +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() +{ + // FIXME: should be controllable by a setting in QWebPage + return false; +} + +void EditorClientQt::registerCommandForUndo(WTF::PassRefPtr<WebCore::EditCommand> cmd) +{ + 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)); +} + +void EditorClientQt::registerCommandForRedo(WTF::PassRefPtr<WebCore::EditCommand>) +{ +} + +void EditorClientQt::clearUndoRedoOperations() +{ + return m_page->undoStack()->clear(); +} + +bool EditorClientQt::canUndo() const +{ + return m_page->undoStack()->canUndo(); +} + +bool EditorClientQt::canRedo() const +{ + return m_page->undoStack()->canRedo(); +} + +void EditorClientQt::undo() +{ + m_inUndoRedo = true; + m_page->undoStack()->undo(); + m_inUndoRedo = false; +} + +void EditorClientQt::redo() +{ + m_inUndoRedo = true; + m_page->undoStack()->redo(); + m_inUndoRedo = false; +} + +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->selectionController()->start().node(); + if (!start) + return; + + // FIXME: refactor all of this to use Actions or something like them + if (start->isContentEditable()) { + switch (kevent->windowsVirtualKeyCode()) { + case VK_RETURN: + frame->editor()->command("InsertLineBreak").execute(); + break; + 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->ctrlKey() && !kevent->altKey() && !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: + 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) +{ +} + +} + +// 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..41147b6 --- /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(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..ed91b86 --- /dev/null +++ b/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp @@ -0,0 +1,1023 @@ +/* + * Copyright (C) 2006 Zack Rusin <zack@kde.org> + * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2007 Trolltech ASA + * + * 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 "ProgressTracker.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 <qfileinfo.h> + +#include <QCoreApplication> +#include <QDebug> +#if QT_VERSION >= 0x040400 +#include <QNetworkRequest> +#include <QNetworkReply> +#else +#include "qwebnetworkinterface_p.h" +#include "qwebobjectplugin_p.h" +#endif + +namespace WebCore +{ + +FrameLoaderClientQt::FrameLoaderClientQt() + : m_frame(0) + , m_webFrame(0) + , m_firstData(false) + , m_policyFunction(0) +{ + 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, SIGNAL(loadStarted())); + connect(this, SIGNAL(loadProgressChanged(int)), + m_webFrame->page(), SIGNAL(loadProgressChanged(int))); + connect(this, SIGNAL(loadFinished()), + m_webFrame, SIGNAL(loadFinished())); + 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; +} + + +bool FrameLoaderClientQt::hasFrameView() const +{ + //notImplemented(); + return true; +} + + +bool FrameLoaderClientQt::hasBackForwardList() const +{ + notImplemented(); + return false; +} + + +void FrameLoaderClientQt::resetBackForwardList() +{ + notImplemented(); +} + + +bool FrameLoaderClientQt::provisionalItemIsTarget() const +{ + notImplemented(); + return false; +} + + +bool FrameLoaderClientQt::loadProvisionalItemFromPageCache() +{ + notImplemented(); + return false; +} + + +void FrameLoaderClientQt::invalidateCurrentItemPageCache() +{ + notImplemented(); +} + +void FrameLoaderClientQt::savePlatformDataToCachedPage(CachedPage*) +{ + notImplemented(); +} + +void FrameLoaderClientQt::transitionToCommittedFromCachedPage(CachedPage*) +{ + notImplemented(); +} + +void FrameLoaderClientQt::transitionToCommittedForNewPage() +{ +// qDebug() << "FrameLoaderClientQt::makeDocumentView" << m_frame->document(); + +// if (!m_frame->document()) +// m_frame->loader()->createEmptyDocument(); +} + + +void FrameLoaderClientQt::makeRepresentation(DocumentLoader*) +{ + // don't need this for now I think. +} + + +void FrameLoaderClientQt::forceLayout() +{ + m_frame->view()->setNeedsLayout(); + m_frame->view()->layout(); +} + + +void FrameLoaderClientQt::forceLayoutForNonHTML() +{ +} + + +void FrameLoaderClientQt::setCopiesOnScroll() +{ + // apparently mac specific +} + + +LoadErrorResetToken* FrameLoaderClientQt::tokenForLoadErrorReset() +{ + notImplemented(); + return 0; +} + + +void FrameLoaderClientQt::resetAfterLoadError(LoadErrorResetToken*) +{ + notImplemented(); +} + + +void FrameLoaderClientQt::doNotResetAfterLoadError(LoadErrorResetToken*) +{ + notImplemented(); +} + + +void FrameLoaderClientQt::willCloseDocument() +{ + notImplemented(); +} + +void FrameLoaderClientQt::detachedFromParent2() +{ +} + + +void FrameLoaderClientQt::detachedFromParent3() +{ +} + + +void FrameLoaderClientQt::detachedFromParent4() +{ + if (!m_webFrame) + return; + m_webFrame->d->frame = 0; + m_webFrame->d->frameView = 0; + m_webFrame = 0; + m_frame = 0; +} + + +void FrameLoaderClientQt::loadedFromCachedPage() +{ + notImplemented(); +} + + +void FrameLoaderClientQt::dispatchDidHandleOnloadEvents() +{ + // don't need this one +} + + +void FrameLoaderClientQt::dispatchDidReceiveServerRedirectForProvisionalLoad() +{ + notImplemented(); +} + + +void FrameLoaderClientQt::dispatchDidCancelClientRedirect() +{ + notImplemented(); +} + + +void FrameLoaderClientQt::dispatchWillPerformClientRedirect(const KURL&, + double interval, + double fireDate) +{ + notImplemented(); +} + + +void FrameLoaderClientQt::dispatchDidChangeLocationWithinPage() +{ + notImplemented(); +} + + +void FrameLoaderClientQt::dispatchWillClose() +{ +} + + +void FrameLoaderClientQt::dispatchDidStartProvisionalLoad() +{ + if (m_webFrame) + emit m_webFrame->provisionalLoad(); +} + + +void FrameLoaderClientQt::dispatchDidReceiveTitle(const String& title) +{ + // ### hack + emit m_webFrame->urlChanged(m_webFrame->url()); + emit titleChanged(title); +} + + +void FrameLoaderClientQt::dispatchDidCommitLoad() +{ + if (m_frame->tree()->parent()) + return; + m_webFrame->page()->d->updateNavigationActions(); +} + + +void FrameLoaderClientQt::dispatchDidFinishDocumentLoad() +{ + if (m_frame->tree()->parent()) + return; + m_webFrame->page()->d->updateNavigationActions(); +} + + +void FrameLoaderClientQt::dispatchDidFinishLoad() +{ + if (m_webFrame) + emit m_webFrame->loadDone(true); + if (m_frame->tree()->parent()) + return; + m_webFrame->page()->d->updateNavigationActions(); +} + + +void FrameLoaderClientQt::dispatchDidFirstLayout() +{ + if (m_webFrame) + emit m_webFrame->initialLayoutComplete(); +} + + +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::clearLoadingFromPageCache(DocumentLoader*) +{ + notImplemented(); +} + + +bool FrameLoaderClientQt::isLoadingFromPageCache(DocumentLoader*) +{ + notImplemented(); + return false; +} + + +void FrameLoaderClientQt::revertToProvisionalState(DocumentLoader*) +{ + notImplemented(); +} + + +void FrameLoaderClientQt::clearUnarchivingState(DocumentLoader*) +{ + notImplemented(); +} + + +void FrameLoaderClientQt::postProgressStartedNotification() +{ + if (m_webFrame && m_frame->page()) + emit loadStarted(); + if (m_frame->tree()->parent()) + return; + m_webFrame->page()->d->updateNavigationActions(); +} + +void FrameLoaderClientQt::postProgressEstimateChangedNotification() +{ + if (m_webFrame && m_frame->page()) + emit loadProgressChanged(qRound(m_frame->page()->progress()->estimatedProgress() * 100)); +} + +void FrameLoaderClientQt::postProgressFinishedNotification() +{ + if (m_webFrame && m_frame->page()) + emit loadFinished(); +} + +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_firstData) { + FrameLoader *fl = loader->frameLoader(); + fl->setEncoding(m_response.textEncodingName(), false); + m_firstData = false; + } +} + + +void FrameLoaderClientQt::finalSetupForReplace(DocumentLoader*) +{ + notImplemented(); +} + + +void FrameLoaderClientQt::setDefersLoading(bool) +{ + notImplemented(); +} + + +bool FrameLoaderClientQt::isArchiveLoadPending(ResourceLoader*) const +{ + return false; +} + + +void FrameLoaderClientQt::cancelPendingArchiveLoad(ResourceLoader*) +{ + notImplemented(); +} + + +void FrameLoaderClientQt::clearArchivedResources() +{ + // don't think we need to do anything here currently +} + + +bool FrameLoaderClientQt::canShowMIMEType(const String& MIMEType) const +{ + if (MIMETypeRegistry::isSupportedImageMIMEType(MIMEType)) + return true; + + if (MIMETypeRegistry::isSupportedNonImageMIMEType(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 +} + + +bool FrameLoaderClientQt::shouldTreatURLAsSameAsCurrent(const KURL&) const +{ + notImplemented(); + return false; +} + + +void FrameLoaderClientQt::addHistoryItemForFragmentScroll() +{ + notImplemented(); +} + + +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()->userAgentFor(QUrl((QString)url.string())); + } + return String(); +} + +void FrameLoaderClientQt::dispatchDidReceiveIcon() +{ + if (m_webFrame) { + emit m_webFrame->iconLoaded(); + } +} + +void FrameLoaderClientQt::frameLoaderDestroyed() +{ + Q_ASSERT(m_webFrame == 0); + Q_ASSERT(m_frame == 0); + delete this; +} + +bool FrameLoaderClientQt::canHandleRequest(const WebCore::ResourceRequest&) const +{ + return true; +} + +void FrameLoaderClientQt::windowObjectCleared() +{ + if (m_webFrame) + emit m_webFrame->cleared(); +} + +void FrameLoaderClientQt::didPerformFirstNavigation() const +{ + if (m_frame->tree()->parent()) + 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 +{ + if (item) { + return true; + } + return false; +} + +void FrameLoaderClientQt::saveViewStateToItem(WebCore::HistoryItem*) +{ + notImplemented(); +} + +bool FrameLoaderClientQt::canCachePage() const +{ + // don't do any caching for now + return false; +} + +void FrameLoaderClientQt::setMainDocumentError(WebCore::DocumentLoader* loader, const WebCore::ResourceError& error) +{ + if (m_firstData) { + loader->frameLoader()->setEncoding(m_response.textEncodingName(), false); + m_firstData = false; + } +} + +void FrameLoaderClientQt::committedLoad(WebCore::DocumentLoader* loader, const char* data, int length) +{ + if (!m_frame) + return; + FrameLoader *fl = loader->frameLoader(); + if (m_firstData) { + fl->setEncoding(m_response.textEncodingName(), false); + m_firstData = false; + } + fl->addData(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)); +} + +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 = new DocumentLoader(request, substituteData); + return loader.release(); +} + +void FrameLoaderClientQt::download(WebCore::ResourceHandle* handle, const WebCore::ResourceRequest&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&) +{ +#if QT_VERSION >= 0x040400 + QNetworkReplyHandler* handler = handle->getInternal()->m_job; + QNetworkReply* reply = handler->release(); + if (reply) { + QWebPage *page = m_webFrame->page(); + if (page->receivers(SIGNAL(handleUnsupportedContent(QNetworkReply *)))) + emit m_webFrame->page()->handleUnsupportedContent(reply); + else + reply->abort(); + } +#endif +} + +void FrameLoaderClientQt::assignIdentifierToInitialRequest(unsigned long identifier, WebCore::DocumentLoader*, const WebCore::ResourceRequest&) +{ +} + +void FrameLoaderClientQt::dispatchWillSendRequest(WebCore::DocumentLoader*, unsigned long, WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response) +{ + // 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, const WebCore::ResourceError&) +{ + 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 (m_webFrame) + emit m_webFrame->loadDone(false); +} + +void FrameLoaderClientQt::dispatchDidFailLoad(const WebCore::ResourceError&) +{ + if (m_webFrame) + emit m_webFrame->loadDone(false); +} + +WebCore::Frame* FrameLoaderClientQt::dispatchCreatePage() +{ + if (!m_webFrame) + return 0; + QWebPage *newPage = m_webFrame->page()->createWindow(); + if (!newPage) + return 0; + return newPage->mainFrame()->d->frame.get(); +} + +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&, const WebCore::ResourceRequest&, const WebCore::String&) +{ + Q_ASSERT(!m_policyFunction); + m_policyFunction = function; + slotCallPolicyFunction(PolicyUse); +} + +void FrameLoaderClientQt::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const WebCore::NavigationAction& action, const WebCore::ResourceRequest& request) +{ + Q_ASSERT(!m_policyFunction); + m_policyFunction = function; + if (m_webFrame) { +#if QT_VERSION < 0x040400 + QWebNetworkRequest r(request); +#else + QNetworkRequest r(request.toNetworkRequest()); +#endif + QWebPage *page = m_webFrame->page(); + + if (page->d->navigationRequested(m_webFrame, r, QWebPage::NavigationType(action.type())) == + QWebPage::IgnoreNavigationRequest) { + slotCallPolicyFunction(PolicyIgnore); + return; + } + } + slotCallPolicyFunction(PolicyUse); + return; +} + +void FrameLoaderClientQt::dispatchUnableToImplementPolicy(const WebCore::ResourceError&) +{ + notImplemented(); +} + +void FrameLoaderClientQt::startDownload(const WebCore::ResourceRequest& request) +{ +#if QT_VERSION >= 0x040400 + QWebPage *page = m_webFrame->page(); + emit m_webFrame->page()->download(request.toNetworkRequest()); +#endif +} + +bool FrameLoaderClientQt::willUseArchive(WebCore::ResourceLoader*, const WebCore::ResourceRequest&, const WebCore::KURL&) const +{ + return false; +} + +PassRefPtr<Frame> FrameLoaderClientQt::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement, + const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight) +{ + 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.get()); + + // 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()->load(frameData.url, frameData.referrer, childLoadType, + String(), 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()) + 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; + + // ### FIXME Qt 4.4 +#if QT_VERSION < 0x040400 + if (QWebFactoryLoader::self()->supportsMimeType(mimeType)) + return ObjectContentNetscapePlugin; +#endif + + if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType)) + return ObjectContentFrame; + + if (url.protocol() == "about") + return ObjectContentFrame; + + return ObjectContentNone; +} + +static const CSSPropertyID qstyleSheetProperties[] = { + CSS_PROP_COLOR, + CSS_PROP_FONT_FAMILY, + CSS_PROP_FONT_SIZE, + CSS_PROP_FONT_STYLE, + CSS_PROP_FONT_WEIGHT +}; + +const unsigned numqStyleSheetProperties = sizeof(qstyleSheetProperties) / sizeof(qstyleSheetProperties[0]); + +Widget* FrameLoaderClientQt::createPlugin(const IntSize&, 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(); + QStringList params; + QStringList values; + for (int i = 0; i < paramNames.size(); ++i) + params.append(paramNames[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(element->getAttribute("classid"), qurl, params, values); + QWidget *widget = qobject_cast<QWidget *>(object); + if (widget && mimeType == "application/x-qt-styled-widget") { + CSSComputedStyleDeclaration cssDecl(element); + + QString styleSheet = element->getAttribute("style"); + if (!styleSheet.isEmpty()) + styleSheet += QLatin1Char(';'); + + for (int i = 0; i < numqStyleSheetProperties; ++i) { + CSSPropertyID property = qstyleSheetProperties[i]; + + styleSheet += ::getPropertyName(property); + styleSheet += QLatin1Char(':'); + styleSheet += cssDecl.getPropertyValue(property); + styleSheet += QLatin1Char(';'); + } + + widget->setStyleSheet(styleSheet); + } + } + + // ### FIXME: qt 4.4 +#if QT_VERSION < 0x040400 + if (!object) + object = QWebFactoryLoader::self()->create(m_webFrame, qurl, mimeType, params, values); +#endif + + if (object) { + QWidget *widget = qobject_cast<QWidget *>(object); + QWidget *view = m_webFrame->page()->view(); + if (widget && view) { + widget->setParent(view); + Widget* w= new Widget(); + w->setNativeWidget(widget); + return w; + } + // FIXME: make things work for widgetless plugins as well + delete object; + } + + return 0; +} + +void FrameLoaderClientQt::redirectDataToPlugin(Widget* pluginWidget) +{ + notImplemented(); + return; +} + +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..3dd5ac9 --- /dev/null +++ b/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h @@ -0,0 +1,228 @@ +/* + * 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. + */ +#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" +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 + + void callPolicyFunction(FramePolicyFunction function, PolicyAction action); + private slots: + void slotCallPolicyFunction(int); + signals: + void sigCallPolicyFunction(int); + void loadStarted(); + void loadProgressChanged(int d); + void loadFinished(); + void titleChanged(const QString& title); + + public: + FrameLoaderClientQt(); + ~FrameLoaderClientQt(); + void setFrame(QWebFrame* webFrame, Frame* frame); + QWebFrame* webFrame() const; + + virtual bool hasWebView() const; // mainly for assertions + virtual bool hasFrameView() const; // ditto + + virtual bool hasBackForwardList() const; + virtual void resetBackForwardList(); + + virtual bool provisionalItemIsTarget() const; + virtual bool loadProvisionalItemFromPageCache(); + virtual void invalidateCurrentItemPageCache(); + + virtual void makeRepresentation(DocumentLoader*); + virtual void forceLayout(); + virtual void forceLayoutForNonHTML(); + + virtual void setCopiesOnScroll(); + + virtual LoadErrorResetToken* tokenForLoadErrorReset(); + virtual void resetAfterLoadError(LoadErrorResetToken*); + virtual void doNotResetAfterLoadError(LoadErrorResetToken*); + + virtual void willCloseDocument(); + + virtual void detachedFromParent2(); + virtual void detachedFromParent3(); + virtual void detachedFromParent4(); + + virtual void loadedFromCachedPage(); + + virtual void frameLoaderDestroyed(); + virtual bool canHandleRequest(const WebCore::ResourceRequest&) const; + + 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 dispatchDidFinishDocumentLoad(); + virtual void dispatchDidFinishLoad(); + virtual void dispatchDidFirstLayout(); + + virtual void dispatchShow(); + virtual void cancelPolicyCheck(); + + virtual void dispatchWillSubmitForm(FramePolicyFunction, PassRefPtr<FormState>); + + virtual void dispatchDidLoadMainResource(DocumentLoader*); + virtual void clearLoadingFromPageCache(DocumentLoader*); + virtual bool isLoadingFromPageCache(DocumentLoader*); + virtual void revertToProvisionalState(DocumentLoader*); + virtual void clearUnarchivingState(DocumentLoader*); + + virtual void setMainFrameDocumentReady(bool); + virtual void willChangeTitle(DocumentLoader*); + virtual void didChangeTitle(DocumentLoader*); + virtual void finishedLoading(DocumentLoader*); + virtual void finalSetupForReplace(DocumentLoader*); + + virtual void setDefersLoading(bool); + virtual bool isArchiveLoadPending(ResourceLoader*) const; + virtual void cancelPendingArchiveLoad(ResourceLoader*); + virtual void clearArchivedResources(); + 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 restoreViewState(); + virtual void provisionalLoadStarted(); + virtual bool shouldTreatURLAsSameAsCurrent(const KURL&) const; + virtual void addHistoryItemForFragmentScroll(); + virtual void didFinishLoad(); + virtual void prepareForDataSourceReplacement(); + 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 void updateGlobalHistory(const WebCore::KURL&); + virtual bool shouldGoToHistoryItem(WebCore::HistoryItem*) const; + virtual void saveViewStateToItem(WebCore::HistoryItem*); + virtual bool canCachePage() const; + + virtual void setMainDocumentError(WebCore::DocumentLoader*, const WebCore::ResourceError&); + virtual void committedLoad(WebCore::DocumentLoader*, const char*, int); + virtual WebCore::ResourceError cancelledError(const WebCore::ResourceRequest&); + virtual WebCore::ResourceError blockedError(const WebCore::ResourceRequest&); + virtual WebCore::ResourceError cannotShowURLError(const WebCore::ResourceRequest&); + virtual WebCore::ResourceError interruptForPolicyChangeError(const WebCore::ResourceRequest&); + virtual WebCore::ResourceError cannotShowMIMETypeError(const WebCore::ResourceResponse&); + virtual WebCore::ResourceError fileDoesNotExistError(const WebCore::ResourceResponse&); + virtual bool shouldFallBack(const WebCore::ResourceError&); + virtual WTF::PassRefPtr<WebCore::DocumentLoader> createDocumentLoader(const WebCore::ResourceRequest&, const WebCore::SubstituteData&); + virtual void download(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&); + + 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 dispatchDidFailProvisionalLoad(const WebCore::ResourceError&); + virtual void dispatchDidFailLoad(const WebCore::ResourceError&); + virtual WebCore::Frame* dispatchCreatePage(); + virtual void dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const WebCore::String&, const WebCore::ResourceRequest&); + virtual void dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const WebCore::NavigationAction&, const WebCore::ResourceRequest&, const WebCore::String&); + virtual void dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const WebCore::NavigationAction&, const WebCore::ResourceRequest&); + virtual void dispatchUnableToImplementPolicy(const WebCore::ResourceError&); + + virtual void startDownload(const WebCore::ResourceRequest&); + virtual bool willUseArchive(WebCore::ResourceLoader*, const WebCore::ResourceRequest&, const WebCore::KURL&) const; + + virtual void postProgressStartedNotification(); + virtual void postProgressEstimateChangedNotification(); + virtual void postProgressFinishedNotification(); + + 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; + }; + +} + +#endif diff --git a/WebKit/qt/WebCoreSupport/InspectorClientQt.cpp b/WebKit/qt/WebCoreSupport/InspectorClientQt.cpp new file mode 100644 index 0000000..4e8f5a5 --- /dev/null +++ b/WebKit/qt/WebCoreSupport/InspectorClientQt.cpp @@ -0,0 +1,187 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * Copyright (C) 2007 Trolltech ASA + * + * 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 +{ +public: + QWebPage* createWindow() + { + QWidget *w = new QWebView(0); + QWebPage *page = new QWebPage(w); + page->setView(w); + connect(page, SIGNAL(destroyed()), w, SLOT(deleteLater())); + return page; + } +}; + + +class InspectorClientView : public QWebView { +public: + InspectorClientView(InspectorController* controller) + : QWebView(0) + , m_controller(controller) + { + setPage(new InspectorClientWebPage); + connect(page(), SIGNAL(destroyed()), SLOT(deleteLater())); + } + +protected: + void hideEvent(QHideEvent* ev) + { + QWidget::hideEvent(ev); + m_controller->setWindowVisible(false); + } + + void closeEvent(QCloseEvent* ev) + { + QWidget::closeEvent(ev); + m_controller->setWindowVisible(false); + } + +private: + InspectorController* m_controller; +}; + + +InspectorClientQt::InspectorClientQt(QWebPage* page) + : m_inspectedWebPage(page) + , m_attached(false) +{} + +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(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() +{ + ASSERT(m_inspectedWebPage); + ASSERT(m_webPage); + ASSERT(!m_attached); + + m_attached = true; + notImplemented(); +} + +void InspectorClientQt::detachWindow() +{ + ASSERT(m_inspectedWebPage); + ASSERT(m_webPage); + ASSERT(m_attached); + + m_attached = false; + 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)); +} + +} diff --git a/WebKit/qt/WebCoreSupport/InspectorClientQt.h b/WebKit/qt/WebCoreSupport/InspectorClientQt.h new file mode 100644 index 0000000..bc0fccd --- /dev/null +++ b/WebKit/qt/WebCoreSupport/InspectorClientQt.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * Copyright (C) 2007 Trolltech ASA + * + * 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 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 highlight(Node*); + virtual void hideHighlight(); + virtual void inspectedURLChanged(const String& newURL); + + private: + void updateWindowTitle(); + QWebPage* m_inspectedWebPage; + OwnPtr<QWebPage> m_webPage; + bool m_attached; + QString m_inspectedURL; + }; +} + +#endif |