diff options
Diffstat (limited to 'WebKit/qt/WebCoreSupport')
-rw-r--r-- | WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp | 26 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h | 42 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/EditorClientQt.cpp | 251 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp | 15 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h | 3 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/InspectorServerQt.h | 2 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/WebPlatformStrategies.cpp | 5 | ||||
-rw-r--r-- | WebKit/qt/WebCoreSupport/WebPlatformStrategies.h | 1 |
8 files changed, 212 insertions, 133 deletions
diff --git a/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp b/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp index 754b20a..e958751 100644 --- a/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp +++ b/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp @@ -82,6 +82,27 @@ using namespace WebCore; QMap<int, QWebScriptWorld*> m_worldMap; +QDRTNode::QDRTNode() + : m_node(0) +{ +} + +QDRTNode::QDRTNode(WebCore::Node* node) + : m_node(0) +{ + if (node) { + m_node = node; + m_node->ref(); + } +} + +QDRTNode::~QDRTNode() +{ + if (m_node) + m_node->deref(); +} + + DumpRenderTreeSupportQt::DumpRenderTreeSupportQt() { } @@ -854,7 +875,10 @@ QVariantList DumpRenderTreeSupportQt::nodesFromRect(const QWebElement& document, for (int i = 0; i < nodes->length(); i++) { QVariant v; // QWebElement will be null if the Node is not an HTML Element - v.setValue(QWebElement(nodes->item(i))); + if (nodes->item(i)->isHTMLElement()) + v.setValue(QWebElement(nodes->item(i))); + else + v.setValue(QDRTNode(nodes->item(i))); res << v; } return res; diff --git a/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h b/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h index e08d962..6917039 100644 --- a/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h +++ b/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h @@ -26,6 +26,26 @@ #include "qwebkitglobal.h" #include <QVariant> +namespace WebCore { +class Text; +class Node; +} + + +#if defined(WTF_USE_V8) && WTF_USE_V8 +namespace V8 { +namespace Bindings { +class QtDRTNodeRuntime; +} +} +#else +namespace JSC { +namespace Bindings { +class QtDRTNodeRuntime; +} +} +#endif + class QWebElement; class QWebFrame; class QWebPage; @@ -34,6 +54,28 @@ class QWebScriptWorld; extern QMap<int, QWebScriptWorld*> m_worldMap; +// Used to pass WebCore::Node's to layout tests using LayoutTestController +class QWEBKIT_EXPORT QDRTNode { +public: + QDRTNode(); + ~QDRTNode(); + +private: + explicit QDRTNode(WebCore::Node*); + + friend class DumpRenderTreeSupportQt; + +#if defined(WTF_USE_V8) && WTF_USE_V8 + friend class V8::Bindings::QtDRTNodeRuntime; +#else + friend class JSC::Bindings::QtDRTNodeRuntime; +#endif + + WebCore::Node* m_node; +}; + +Q_DECLARE_METATYPE(QDRTNode) + class QWEBKIT_EXPORT DumpRenderTreeSupportQt { public: diff --git a/WebKit/qt/WebCoreSupport/EditorClientQt.cpp b/WebKit/qt/WebCoreSupport/EditorClientQt.cpp index 3fbc83d..534e334 100644 --- a/WebKit/qt/WebCoreSupport/EditorClientQt.cpp +++ b/WebKit/qt/WebCoreSupport/EditorClientQt.cpp @@ -346,6 +346,60 @@ void EditorClientQt::toggleGrammarChecking() notImplemented(); } +static const unsigned CtrlKey = 1 << 0; +static const unsigned AltKey = 1 << 1; +static const unsigned ShiftKey = 1 << 2; + +struct KeyDownEntry { + unsigned virtualKey; + unsigned modifiers; + const char* editorCommand; +}; + +// Handle here key down events that are needed for spatial navigation and caret browsing, or +// are not handled by QWebPage. +static const KeyDownEntry keyDownEntries[] = { + // Ones that do not have an associated QAction: + { VK_DELETE, 0, "DeleteForward" }, + { VK_BACK, ShiftKey, "DeleteBackward" }, + { VK_BACK, 0, "DeleteBackward" }, + // Ones that need special handling for caret browsing: + { VK_PRIOR, 0, "MovePageUp" }, + { VK_PRIOR, ShiftKey, "MovePageUpAndModifySelection" }, + { VK_NEXT, 0, "MovePageDown" }, + { VK_NEXT, ShiftKey, "MovePageDownAndModifySelection" }, + // Ones that need special handling for spatial navigation: + { VK_LEFT, 0, "MoveLeft" }, + { VK_RIGHT, 0, "MoveRight" }, + { VK_UP, 0, "MoveUp" }, + { VK_DOWN, 0, "MoveDown" }, +}; + +const char* editorCommandForKeyDownEvent(const KeyboardEvent* event) +{ + if (event->type() != eventNames().keydownEvent) + return ""; + + static HashMap<int, const char*> keyDownCommandsMap; + if (keyDownCommandsMap.isEmpty()) { + + unsigned numEntries = sizeof(keyDownEntries) / sizeof((keyDownEntries)[0]); + for (unsigned i = 0; i < numEntries; i++) + keyDownCommandsMap.set(keyDownEntries[i].modifiers << 16 | keyDownEntries[i].virtualKey, keyDownEntries[i].editorCommand); + } + + unsigned modifiers = 0; + if (event->shiftKey()) + modifiers |= ShiftKey; + if (event->altKey()) + modifiers |= AltKey; + if (event->ctrlKey()) + modifiers |= CtrlKey; + + int mapKey = modifiers << 16 | event->keyCode(); + return mapKey ? keyDownCommandsMap.get(mapKey) : 0; +} + void EditorClientQt::handleKeyboardEvent(KeyboardEvent* event) { Frame* frame = m_page->d->page->focusController()->focusedOrMainFrame(); @@ -387,150 +441,85 @@ void EditorClientQt::handleKeyboardEvent(KeyboardEvent* event) return; m_page->triggerAction(action); - } else + event->setDefaultHandled(); + return; + } else { #endif // QT_NO_SHORTCUT - switch (kevent->windowsVirtualKeyCode()) { - case VK_BACK: - frame->editor()->deleteWithDirection(SelectionController::DirectionBackward, - CharacterGranularity, false, true); - break; - case VK_DELETE: - frame->editor()->deleteWithDirection(SelectionController::DirectionForward, - CharacterGranularity, false, true); - break; - case VK_LEFT: - if (kevent->shiftKey()) - frame->editor()->command("MoveLeftAndModifySelection").execute(); - else if (!frame->editor()->command("MoveLeft").execute()) - return; - break; - case VK_RIGHT: - if (kevent->shiftKey()) - frame->editor()->command("MoveRightAndModifySelection").execute(); - else if (!frame->editor()->command("MoveRight").execute()) - return; - break; - case VK_UP: - if (kevent->shiftKey()) - frame->editor()->command("MoveUpAndModifySelection").execute(); - else if (!frame->editor()->command("MoveUp").execute()) + String commandName = editorCommandForKeyDownEvent(event); + if (!commandName.isEmpty()) { + if (frame->editor()->command(commandName).execute()) // Event handled. + event->setDefaultHandled(); return; - break; - case VK_DOWN: - if (kevent->shiftKey()) - frame->editor()->command("MoveDownAndModifySelection").execute(); - else if (!frame->editor()->command("MoveDown").execute()) + } + + if (kevent->windowsVirtualKeyCode() == VK_TAB) { + // Do not handle TAB text insertion here. return; - break; - case VK_PRIOR: // PageUp - if (kevent->shiftKey()) - frame->editor()->command("MovePageUpAndModifySelection").execute(); - else - frame->editor()->command("MovePageUp").execute(); - break; - case VK_NEXT: // PageDown - if (kevent->shiftKey()) - frame->editor()->command("MovePageDownAndModifySelection").execute(); - else - frame->editor()->command("MovePageDown").execute(); - break; - case VK_TAB: - return; - default: - if (kevent->type() != PlatformKeyboardEvent::KeyDown && !kevent->ctrlKey() + } + + // Text insertion. + bool shouldInsertText = false; + if (kevent->type() != PlatformKeyboardEvent::KeyDown && !kevent->text().isEmpty()) { + + if (kevent->ctrlKey()) { + if (kevent->altKey()) + shouldInsertText = true; + } else { #ifndef Q_WS_MAC // We need to exclude checking for Alt because it is just a different Shift - && !kevent->altKey() + if (!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_I: - frame->editor()->command("ToggleItalic").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; + shouldInsertText = true; + } - } else + } + + if (shouldInsertText) { + frame->editor()->insertText(kevent->text(), event); + event->setDefaultHandled(); return; + } } - } else { - if (m_page->handle()->page->settings()->caretBrowsingEnabled()) { - switch (kevent->windowsVirtualKeyCode()) { - case VK_LEFT: - if (kevent->shiftKey() && kevent->ctrlKey()) - frame->editor()->command("MoveWordBackwardAndModifySelection").execute(); - else if (kevent->shiftKey()) - frame->editor()->command("MoveLeftAndModifySelection").execute(); - else if (kevent->ctrlKey()) - frame->editor()->command("MoveWordBackward").execute(); - else - frame->editor()->command("MoveLeft").execute(); - break; - case VK_RIGHT: - if (kevent->shiftKey() && kevent->ctrlKey()) - frame->editor()->command("MoveWordForwardAndModifySelection").execute(); - else if (kevent->shiftKey()) - frame->editor()->command("MoveRightAndModifySelection").execute(); - else if (kevent->ctrlKey()) - frame->editor()->command("MoveWordForward").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_HOME: - if (kevent->shiftKey()) - frame->editor()->command("MoveToBeginningOfLineAndModifySelection").execute(); - else - frame->editor()->command("MoveToBeginningOfLine").execute(); - break; - case VK_END: - if (kevent->shiftKey()) - frame->editor()->command("MoveToEndOfLineAndModifySelection").execute(); - else - frame->editor()->command("MoveToEndOfLine").execute(); - break; - default: - break; + + // Event not handled. + return; + } + + // Non editable content. + if (m_page->handle()->page->settings()->caretBrowsingEnabled()) { + switch (kevent->windowsVirtualKeyCode()) { + case VK_LEFT: + case VK_RIGHT: + case VK_UP: + case VK_DOWN: + case VK_HOME: + case VK_END: + { + QWebPage::WebAction action = QWebPagePrivate::editorActionForKeyEvent(kevent->qtEvent()); + ASSERT(action != QWebPage::NoWebAction); + m_page->triggerAction(action); + event->setDefaultHandled(); + return; + } + case VK_PRIOR: // PageUp + case VK_NEXT: // PageDown + { + String commandName = editorCommandForKeyDownEvent(event); + ASSERT(!commandName.isEmpty()); + frame->editor()->command(commandName).execute(); + event->setDefaultHandled(); + return; } } + } + #ifndef QT_NO_SHORTCUT - if (kevent->qtEvent() == QKeySequence::Copy) - m_page->triggerAction(QWebPage::Copy); - else -#endif // QT_NO_SHORTCUT - return; + if (kevent->qtEvent() == QKeySequence::Copy) { + m_page->triggerAction(QWebPage::Copy); + event->setDefaultHandled(); + return; } - event->setDefaultHandled(); +#endif // QT_NO_SHORTCUT } void EditorClientQt::handleInputMethodKeydown(KeyboardEvent*) diff --git a/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp b/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp index 849958f..e83d5ef 100644 --- a/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp +++ b/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp @@ -295,6 +295,14 @@ void FrameLoaderClientQt::transitionToCommittedForNewPage() m_frame->view()->setActualVisibleContentRect(IntRect(IntPoint::zero(), currentVisibleContentSize)); } +void FrameLoaderClientQt::didSaveToPageCache() +{ +} + +void FrameLoaderClientQt::didRestoreFromPageCache() +{ +} + void FrameLoaderClientQt::dispatchDidBecomeFrameset(bool) { } @@ -1437,7 +1445,12 @@ public: graphicsWidget->hide(); } private: - QtPluginGraphicsWidget(QGraphicsWidget* w = 0): Widget(0), graphicsWidget(w) {} + QtPluginGraphicsWidget(QGraphicsWidget* w = 0) + : Widget(0) + , graphicsWidget(w) + { + setBindingObject(graphicsWidget); + } QGraphicsWidget* graphicsWidget; }; diff --git a/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h b/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h index 275b0e8..3d93eaf 100644 --- a/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h +++ b/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.h @@ -193,6 +193,9 @@ public: virtual void transitionToCommittedFromCachedFrame(WebCore::CachedFrame*); virtual void transitionToCommittedForNewPage(); + virtual void didSaveToPageCache(); + virtual void didRestoreFromPageCache(); + virtual void dispatchDidBecomeFrameset(bool); virtual bool canCachePage() const; diff --git a/WebKit/qt/WebCoreSupport/InspectorServerQt.h b/WebKit/qt/WebCoreSupport/InspectorServerQt.h index 74e8c2f..922b63e 100644 --- a/WebKit/qt/WebCoreSupport/InspectorServerQt.h +++ b/WebKit/qt/WebCoreSupport/InspectorServerQt.h @@ -27,8 +27,10 @@ #include <QString> #include <wtf/Forward.h> +QT_BEGIN_NAMESPACE class QTcpServer; class QTcpSocket; +QT_END_NAMESPACE class QWebPage; namespace WebCore { diff --git a/WebKit/qt/WebCoreSupport/WebPlatformStrategies.cpp b/WebKit/qt/WebCoreSupport/WebPlatformStrategies.cpp index 7cd255f..c67ec2f 100644 --- a/WebKit/qt/WebCoreSupport/WebPlatformStrategies.cpp +++ b/WebKit/qt/WebCoreSupport/WebPlatformStrategies.cpp @@ -290,6 +290,11 @@ String WebPlatformStrategies::contextMenuItemTagPaste() return QCoreApplication::translate("QWebPage", "Paste", "Paste context menu item"); } +String WebPlatformStrategies::contextMenuItemTagSelectAll() +{ + return QCoreApplication::translate("QWebPage", "Select All", "Select All context menu item"); +} + String WebPlatformStrategies::contextMenuItemTagNoGuessesFound() { return QCoreApplication::translate("QWebPage", "No Guesses Found", "No Guesses Found context menu item"); diff --git a/WebKit/qt/WebCoreSupport/WebPlatformStrategies.h b/WebKit/qt/WebCoreSupport/WebPlatformStrategies.h index ea366e0..5f72f46 100644 --- a/WebKit/qt/WebCoreSupport/WebPlatformStrategies.h +++ b/WebKit/qt/WebCoreSupport/WebPlatformStrategies.h @@ -74,6 +74,7 @@ private: virtual WTF::String contextMenuItemTagReload(); virtual WTF::String contextMenuItemTagCut(); virtual WTF::String contextMenuItemTagPaste(); + virtual WTF::String contextMenuItemTagSelectAll(); virtual WTF::String contextMenuItemTagNoGuessesFound(); virtual WTF::String contextMenuItemTagIgnoreSpelling(); virtual WTF::String contextMenuItemTagLearnSpelling(); |