[SCM] WebKit Debian packaging branch, debian/experimental, updated. debian/1.3.8-1-1049-g2e11a8e

tonikitoo at webkit.org tonikitoo at webkit.org
Fri Jan 21 14:51:45 UTC 2011


The following commit has been merged in the debian/experimental branch:
commit a872ac656bc625907459ba1b05a588c1e7ee0f64
Author: tonikitoo at webkit.org <tonikitoo at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Jan 3 16:04:08 2011 +0000

    2011-01-02  Antonio Gomes  <agomes at rim.com>
    
            Reviewed by Kenneth Rohde Christiansen.
    
            [Qt] Refactor EditorClientQt::handleKeyboardEvent
            https://bugs.webkit.org/show_bug.cgi?id=51306
    
            EditorClientQt::handleKeyboardEvent relies on QWebPagePrivate::editorActionForKeyEvent()
            to handle all editor commands that have a QAction associted with it.
            In practice, that covers most of editor commands (as one can see in editorCommandWebActions,
            in qwebpage.cpp). However, there are some key down events that are associated to no QAction
            or need special handling when features like spatial navigation or
            caret browsing are enabled. Currently, these cases are being handled with confusing
            and nested if/else switch's statements in EditorClientQt::handleKeyboardEvent(),
            and the code is hardly readable.
    
            This patch introduces a mapping hash for those cases, simplifying much
            the code. Basically, nested switches statements mixed with if/else's were
            refactored, and early returns were added right after an event gets consumed
            by the Editor.
    
            Since it is a refactor only patch, there is no funcionality change at
            all, and then no new tests are being added.
    
            * WebCoreSupport/EditorClientQt.cpp:
            (WebCore::interpretKeyEvent):
            (WebCore::EditorClientQt::handleKeyboardEvent):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@74891 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/qt/ChangeLog b/WebKit/qt/ChangeLog
index bc59d9f..fb68283 100644
--- a/WebKit/qt/ChangeLog
+++ b/WebKit/qt/ChangeLog
@@ -1,3 +1,31 @@
+2011-01-02  Antonio Gomes  <agomes at rim.com>
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        [Qt] Refactor EditorClientQt::handleKeyboardEvent
+        https://bugs.webkit.org/show_bug.cgi?id=51306
+
+        EditorClientQt::handleKeyboardEvent relies on QWebPagePrivate::editorActionForKeyEvent()
+        to handle all editor commands that have a QAction associted with it.
+        In practice, that covers most of editor commands (as one can see in editorCommandWebActions,
+        in qwebpage.cpp). However, there are some key down events that are associated to no QAction
+        or need special handling when features like spatial navigation or
+        caret browsing are enabled. Currently, these cases are being handled with confusing
+        and nested if/else switch's statements in EditorClientQt::handleKeyboardEvent(),
+        and the code is hardly readable.
+
+        This patch introduces a mapping hash for those cases, simplifying much
+        the code. Basically, nested switches statements mixed with if/else's were
+        refactored, and early returns were added right after an event gets consumed
+        by the Editor.
+
+        Since it is a refactor only patch, there is no funcionality change at
+        all, and then no new tests are being added.
+
+        * WebCoreSupport/EditorClientQt.cpp:
+        (WebCore::interpretKeyEvent):
+        (WebCore::EditorClientQt::handleKeyboardEvent):
+
 2011-01-01  Adam Barth  <abarth at webkit.org>
 
         Reviewed by Eric Seidel.
diff --git a/WebKit/qt/WebCoreSupport/EditorClientQt.cpp b/WebKit/qt/WebCoreSupport/EditorClientQt.cpp
index 9c2027b..bff5267 100644
--- a/WebKit/qt/WebCoreSupport/EditorClientQt.cpp
+++ b/WebKit/qt/WebCoreSupport/EditorClientQt.cpp
@@ -346,6 +346,59 @@ 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)
+{
+    ASSERT(event->type() == eventNames().keydownEvent);
+
+    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 +440,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(DirectionBackward,
-                    CharacterGranularity, false, true);
-            break;
-        case VK_DELETE:
-            frame->editor()->deleteWithDirection(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*)

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list