2008-08-05 Tor Arne Vestbø <tavestbo@trolltech.com>
authorvestbo@webkit.org <vestbo@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Aug 2008 13:40:57 +0000 (13:40 +0000)
committervestbo@webkit.org <vestbo@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Aug 2008 13:40:57 +0000 (13:40 +0000)
        Reviewed by Simon.

        Move event handling of the return-key from EditorClientQt to QWebPage.

        https://bugs.webkit.org/show_bug.cgi?id=20191

        This is a first step in refactoring the big switch block
        in EditorClientQt::handleKeyboardEvent to using WebActions
        instead.

        The new logic uses two new StandardKeys from QKeySequence:

        - InsertParagraphSeparator
        - InsertLineSeparator

        Which translate to the commands InsertNewline and InsertLineBreak
        respectivly. On Windows/X11 pressing the shift modifier will invoke
        the latter action. For Mac this is triggered by pressing the meta
        modifier (Ctrl).

        Initial patch by: Erik Bunce

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@35558 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/qt/Api/qwebpage.cpp
WebKit/qt/Api/qwebpage.h
WebKit/qt/ChangeLog
WebKit/qt/WebCoreSupport/EditorClientQt.cpp

index 08471db2473a484a9fe28adc1bed7036629a08de..9796bf73e39a23ed478c0d55f7a9e17227ebfca9 100644 (file)
@@ -154,6 +154,9 @@ static const char* editorCommandWebActions[] =
     
     0, // InspectElement,
 
+    "InsertNewline", // InsertParagraphSeparator
+    "InsertLineBreak", // InsertLineSeparator
+
     0 // WebActionCount
 };
 
@@ -592,7 +595,7 @@ static QWebPage::WebAction editorActionForKeyEvent(QKeyEvent* event)
     static struct {
         QKeySequence::StandardKey standardKey;
         QWebPage::WebAction action;
-    } editorActions[32] = {
+    } editorActions[] = {
         { QKeySequence::Cut, QWebPage::Cut },
         { QKeySequence::Copy, QWebPage::Copy },
         { QKeySequence::Paste, QWebPage::Paste },
@@ -624,6 +627,10 @@ static QWebPage::WebAction editorActionForKeyEvent(QKeyEvent* event)
         { QKeySequence::SelectEndOfDocument, QWebPage::SelectEndOfDocument },
         { QKeySequence::DeleteStartOfWord, QWebPage::DeleteStartOfWord },
         { QKeySequence::DeleteEndOfWord, QWebPage::DeleteEndOfWord },
+#if QT_VERSION >= 0x040500
+        { QKeySequence::InsertParagraphSeparator, QWebPage::InsertParagraphSeparator },
+        { QKeySequence::InsertLineSeparator, QWebPage::InsertLineSeparator },
+#endif
         { QKeySequence::UnknownKey, QWebPage::NoWebAction }
     };
 
@@ -1042,6 +1049,8 @@ QVariant QWebPage::inputMethodQuery(Qt::InputMethodQuery property) const
     \value ToggleItalic Toggle the formatting between italic and normal style.
     \value ToggleUnderline Toggle underlining.
     \value InspectElement Show the Web Inspector with the currently highlighted HTML element.
+    \value InsertParagraphSeparator Insert a new paragraph.
+    \value InsertLineSeparator Insert a new line.
     \omitvalue WebActionCount
 
 */
index 197222af6db6ff5cc646b5e229811bb63570d5ce..ad15f46e37f3fa639ce660cc18b209cdcea22245 100644 (file)
@@ -142,6 +142,9 @@ public:
 
         InspectElement,
 
+        InsertParagraphSeparator,
+        InsertLineSeparator,
+
         WebActionCount
     };
 
index f79051f85797f58f8987168b66177b6727a87ed8..3989f89b68f1b81b9050dd407b974b21fca35139 100644 (file)
@@ -1,3 +1,33 @@
+2008-08-05  Tor Arne Vestbø  <tavestbo@trolltech.com>
+
+        Reviewed by Simon.
+
+        Move event handling of the return-key from EditorClientQt to QWebPage.
+        
+        https://bugs.webkit.org/show_bug.cgi?id=20191
+        
+        This is a first step in refactoring the big switch block
+        in EditorClientQt::handleKeyboardEvent to using WebActions
+        instead.
+        
+        The new logic uses two new StandardKeys from QKeySequence:
+        
+        - InsertParagraphSeparator
+        - InsertLineSeparator
+        
+        Which translate to the commands InsertNewline and InsertLineBreak
+        respectivly. On Windows/X11 pressing the shift modifier will invoke
+        the latter action. For Mac this is triggered by pressing the meta
+        modifier (Ctrl).
+        
+        Initial patch by: Erik Bunce
+
+        * Api/qwebpage.cpp:
+        (editorActionForKeyEvent):
+        * Api/qwebpage.h:
+        * WebCoreSupport/EditorClientQt.cpp:
+        (WebCore::EditorClientQt::handleKeyboardEvent):
+
 2008-08-04  Erik Bunce  <elbunce@thehive.com>
 
         Reviewed by Simon.
index 1abc542c5e012e6a0aff24a2ec98a92535ad3cea..68280208afc427df25a68839b42cec549a34e06d 100644 (file)
@@ -344,9 +344,18 @@ void EditorClientQt::handleKeyboardEvent(KeyboardEvent* event)
     // FIXME: refactor all of this to use Actions or something like them
     if (start->isContentEditable()) {
         switch (kevent->windowsVirtualKeyCode()) {
+#if QT_VERSION < 0x040500
             case VK_RETURN:
-                frame->editor()->command("InsertLineBreak").execute();
+#ifdef QT_WS_MAC
+                if (kevent->shiftKey() || kevent->metaKey())
+#else
+                if (kevent->shiftKey())
+#endif
+                    frame->editor()->command("InsertLineBreak").execute();
+                else
+                    frame->editor()->command("InsertNewline").execute();
                 break;
+#endif
             case VK_BACK:
                 frame->editor()->deleteWithDirection(SelectionController::BACKWARD,
                         CharacterGranularity, false, true);