Patch for https://bugs.webkit.org/show_bug.cgi?id=43013
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Jul 2010 23:06:34 +0000 (23:06 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Jul 2010 23:06:34 +0000 (23:06 +0000)
Part of <rdar://problem/8152434>
Add support for scrolling using the keyboard in WebKit2

Reviewed by Anders Carlsson.

WebCore:

Add a new export and make WindowsKeyboardCodes private.

* WebCore.exp.in:
* WebCore.xcodeproj/project.pbxproj:

WebKit2:

* WebProcess/WebPage/WebPage.cpp:
(WebKit::getScrollMapping):
(WebKit::WebPage::keyEvent):
Scroll the page in response to keyDown.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/mac/WebPageMac.mm:
Use WindowsKeyboardCodes.h instead of redefining the constants.

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

WebCore/ChangeLog
WebCore/WebCore.exp.in
WebCore/WebCore.xcodeproj/project.pbxproj
WebKit2/ChangeLog
WebKit2/WebProcess/WebPage/WebPage.cpp
WebKit2/WebProcess/WebPage/mac/WebPageMac.mm

index bf05a0d..c888f54 100644 (file)
@@ -1,3 +1,16 @@
+2010-07-26  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Anders Carlsson.
+
+        Patch for https://bugs.webkit.org/show_bug.cgi?id=43013
+        Part of <rdar://problem/8152434>
+        Add support for scrolling using the keyboard in WebKit2
+
+        Add a new export and make WindowsKeyboardCodes private.
+
+        * WebCore.exp.in:
+        * WebCore.xcodeproj/project.pbxproj:
+
 2010-07-26  Darin Adler  <darin@apple.com>
 
         Reviewed by Eric Carlson.
index 580f4f7..665dab4 100644 (file)
@@ -215,6 +215,7 @@ __ZN7WebCore12EventHandler14currentNSEventEv
 __ZN7WebCore12EventHandler14scrollOverflowENS_15ScrollDirectionENS_17ScrollGranularityEPNS_4NodeE
 __ZN7WebCore12EventHandler15sendScrollEventEv
 __ZN7WebCore12EventHandler16handleWheelEventERNS_18PlatformWheelEventE
+__ZN7WebCore12EventHandler17scrollRecursivelyENS_15ScrollDirectionENS_17ScrollGranularityEPNS_4NodeE
 __ZN7WebCore12EventHandler20handleTextInputEventERKNS_6StringEPNS_5EventEbb
 __ZN7WebCore12EventHandler20hitTestResultAtPointERKNS_8IntPointEbbNS_17HitTestScrollbarsEj
 __ZN7WebCore12EventHandler21handleMousePressEventERKNS_18PlatformMouseEventE
index fbdeec2..3d5bf32 100644 (file)
                E1C8BE5D0E8BD15A0064CB7D /* JSWorker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1C8BE5C0E8BD15A0064CB7D /* JSWorker.cpp */; };
                E1CA5CBC0E8CDCAF00E8EF90 /* JSWorkerCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1CA5CBB0E8CDCAF00E8EF90 /* JSWorkerCustom.cpp */; };
                E1CAA5C60E8BD23600A73ECA /* JSWorker.h in Headers */ = {isa = PBXBuildFile; fileRef = E1CAA5C50E8BD23600A73ECA /* JSWorker.h */; };
-               E1E1BF00115FF6FB006F52CA /* WindowsKeyboardCodes.h in Headers */ = {isa = PBXBuildFile; fileRef = E1E1BEFF115FF6FB006F52CA /* WindowsKeyboardCodes.h */; };
+               E1E1BF00115FF6FB006F52CA /* WindowsKeyboardCodes.h in Headers */ = {isa = PBXBuildFile; fileRef = E1E1BEFF115FF6FB006F52CA /* WindowsKeyboardCodes.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E1E6EEA40B628DA8005F2F70 /* JSHTMLSelectElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1E6EEA30B628DA8005F2F70 /* JSHTMLSelectElement.cpp */; };
                E1E6EEA80B628DB3005F2F70 /* JSHTMLSelectElement.h in Headers */ = {isa = PBXBuildFile; fileRef = E1E6EEA70B628DB3005F2F70 /* JSHTMLSelectElement.h */; };
                E1EBBBD40AAC9B87001FE8E2 /* CSSCharsetRule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1EBBBD30AAC9B87001FE8E2 /* CSSCharsetRule.cpp */; };
index 2f36a9e..6ed4b07 100644 (file)
@@ -1,3 +1,19 @@
+2010-07-26  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Anders Carlsson.
+
+        Patch for https://bugs.webkit.org/show_bug.cgi?id=43013
+        Part of <rdar://problem/8152434>
+        Add support for scrolling using the keyboard in WebKit2
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::getScrollMapping):
+        (WebKit::WebPage::keyEvent):
+        Scroll the page in response to keyDown.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        Use WindowsKeyboardCodes.h instead of redefining the constants.
+
 2010-07-26  Ada Chan  <adachan@apple.com>
 
         Fix Windows build.
index 7206072..fe25ea2 100644 (file)
@@ -57,6 +57,7 @@
 #include <WebCore/RenderTreeAsText.h>
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/Settings.h>
+#include <WebCore/WindowsKeyboardCodes.h>
 #include <runtime/JSLock.h>
 #include <runtime/JSValue.h>
 
@@ -343,6 +344,51 @@ void WebPage::wheelEvent(const WebWheelEvent& wheelEvent)
     m_mainFrame->coreFrame()->eventHandler()->handleWheelEvent(platformWheelEvent);
 }
 
+static bool getScrollMapping(const WebKeyboardEvent& event, ScrollDirection& direction, ScrollGranularity& granularity)
+{
+    if (event.type() != WebEvent::KeyDown && event.type() != WebEvent::RawKeyDown)
+        return false;
+
+    switch (event.windowsVirtualKeyCode()) {
+    case VK_LEFT:
+        granularity = ScrollByLine;
+        direction = ScrollLeft;
+        break;
+    case VK_RIGHT:
+        granularity = ScrollByLine;
+        direction = ScrollRight;
+        break;
+    case VK_UP:
+        granularity = ScrollByLine;
+        direction = ScrollUp;
+        break;
+    case VK_DOWN:
+        granularity = ScrollByLine;
+        direction = ScrollDown;
+        break;
+    case VK_HOME:
+        granularity = ScrollByDocument;
+        direction = ScrollUp;
+        break;
+    case VK_END:
+        granularity = ScrollByDocument;
+        direction = ScrollDown;
+        break;
+    case VK_PRIOR:
+        granularity = ScrollByPage;
+        direction = ScrollUp;
+        break;
+    case VK_NEXT:
+        granularity = ScrollByPage;
+        direction = ScrollDown;
+        break;
+    default:
+        return false;
+    }
+
+    return true;
+}
+
 void WebPage::keyEvent(const WebKeyboardEvent& keyboardEvent)
 {
     CurrentEvent currentEvent(keyboardEvent);
@@ -353,7 +399,14 @@ void WebPage::keyEvent(const WebKeyboardEvent& keyboardEvent)
         return;
 
     PlatformKeyboardEvent platformKeyboardEvent = platform(keyboardEvent);
-    m_page->focusController()->focusedOrMainFrame()->eventHandler()->keyEvent(platformKeyboardEvent);
+
+    Frame* frame = m_page->focusController()->focusedOrMainFrame();
+    frame->eventHandler()->keyEvent(platformKeyboardEvent);
+
+    ScrollDirection direction;
+    ScrollGranularity granularity;
+    if (getScrollMapping(keyboardEvent, direction, granularity))
+        frame->eventHandler()->scrollRecursively(direction, granularity);
 }
 
 void WebPage::setActive(bool isActive)
index ff7929b..52a2183 100644 (file)
@@ -28,6 +28,7 @@
 #include <WebCore/KeyboardEvent.h>
 #include <WebCore/Page.h>
 #include <WebCore/PlatformKeyboardEvent.h>
+#include <WebCore/WindowsKeyboardCodes.h>
 
 using namespace WebCore;
 
@@ -45,22 +46,6 @@ static const unsigned AltKey    = 1 << 1;
 static const unsigned ShiftKey  = 1 << 2;
 static const unsigned MetaKey   = 1 << 3;
 
-static const unsigned VKEY_BACK         = 0x08;
-static const unsigned VKEY_TAB          = 0x09;
-static const unsigned VKEY_RETURN       = 0x0D;
-static const unsigned VKEY_ESCAPE       = 0x1B;
-static const unsigned VKEY_PRIOR        = 0x21;
-static const unsigned VKEY_NEXT         = 0x22;
-static const unsigned VKEY_END          = 0x23;
-static const unsigned VKEY_HOME         = 0x24;
-static const unsigned VKEY_LEFT         = 0x25;
-static const unsigned VKEY_UP           = 0x26;
-static const unsigned VKEY_RIGHT        = 0x27;
-static const unsigned VKEY_DOWN         = 0x28;
-static const unsigned VKEY_INSERT       = 0x2D;
-static const unsigned VKEY_DELETE       = 0x2E;
-static const unsigned VKEY_OEM_PERIOD   = 0xBE;
-
 // Keys with special meaning. These will be delegated to the editor using
 // the execCommand() method
 struct KeyDownEntry {
@@ -76,63 +61,63 @@ struct KeyPressEntry {
 };
 
 static const KeyDownEntry keyDownEntries[] = {
-    { VKEY_LEFT,   0,                   "MoveLeft"                                      },
-    { VKEY_LEFT,   ShiftKey,            "MoveLeftAndModifySelection"                    },
-    { VKEY_LEFT,   AltKey,              "MoveWordLeft"                                  },
-    { VKEY_LEFT,   AltKey | ShiftKey,   "MoveWordLeftAndModifySelection"                },
-    { VKEY_RIGHT,  0,                   "MoveRight"                                     },
-    { VKEY_RIGHT,  ShiftKey,            "MoveRightAndModifySelection"                   },
-    { VKEY_RIGHT,  AltKey,              "MoveWordRight"                                 },
-    { VKEY_RIGHT,  AltKey | ShiftKey,   "MoveWordRightAndModifySelection"               },
-    { VKEY_UP,     0,                   "MoveUp"                                        },
-    { VKEY_UP,     ShiftKey,            "MoveUpAndModifySelection"                      },
-    { VKEY_PRIOR,  ShiftKey,            "MovePageUpAndModifySelection"                  },
-    { VKEY_DOWN,   0,                   "MoveDown"                                      },
-    { VKEY_DOWN,   ShiftKey,            "MoveDownAndModifySelection"                    },
-    { VKEY_NEXT,   ShiftKey,            "MovePageDownAndModifySelection"                },
-    { VKEY_PRIOR,  0,                   "MovePageUp"                                    },
-    { VKEY_NEXT,   0,                   "MovePageDown"                                  },
-
-    { VKEY_HOME,   0,                   "MoveToBeginningOfLine"                         },
-    { VKEY_HOME,   ShiftKey,            "MoveToBeginningOfLineAndModifySelection"       },
-    { VKEY_LEFT,   MetaKey,             "MoveToBeginningOfLine"                         },
-    { VKEY_LEFT,   MetaKey | ShiftKey,  "MoveToBeginningOfLineAndModifySelection"       },
-    { VKEY_UP,     MetaKey,             "MoveToBeginningOfDocument"                     },
-    { VKEY_UP,     MetaKey | ShiftKey,  "MoveToBeginningOfDocumentAndModifySelection"   },
-
-    { VKEY_END,    0,                   "MoveToEndOfLine"                               },
-    { VKEY_END,    ShiftKey,            "MoveToEndOfLineAndModifySelection"             },
-    { VKEY_DOWN,   MetaKey,             "MoveToEndOfDocument"                           },
-    { VKEY_DOWN,   MetaKey | ShiftKey,  "MoveToEndOfDocumentAndModifySelection"         },
-    { VKEY_RIGHT,  MetaKey,             "MoveToEndOfLine"                               },
-    { VKEY_RIGHT,  MetaKey | ShiftKey,  "MoveToEndOfLineAndModifySelection"             },
-
-    { VKEY_BACK,   0,                   "DeleteBackward"                                },
-    { VKEY_BACK,   ShiftKey,            "DeleteBackward"                                },
-    { VKEY_DELETE, 0,                   "DeleteForward"                                 },
-    { VKEY_BACK,   AltKey,              "DeleteWordBackward"                            },
-    { VKEY_DELETE, AltKey,              "DeleteWordForward"                             },
+    { VK_LEFT,     0,                   "MoveLeft"                                      },
+    { VK_LEFT,     ShiftKey,            "MoveLeftAndModifySelection"                    },
+    { VK_LEFT,     AltKey,              "MoveWordLeft"                                  },
+    { VK_LEFT,     AltKey | ShiftKey,   "MoveWordLeftAndModifySelection"                },
+    { VK_RIGHT,    0,                   "MoveRight"                                     },
+    { VK_RIGHT,    ShiftKey,            "MoveRightAndModifySelection"                   },
+    { VK_RIGHT,    AltKey,              "MoveWordRight"                                 },
+    { VK_RIGHT,    AltKey | ShiftKey,   "MoveWordRightAndModifySelection"               },
+    { VK_UP,       0,                   "MoveUp"                                        },
+    { VK_UP,       ShiftKey,            "MoveUpAndModifySelection"                      },
+    { VK_PRIOR,    ShiftKey,            "MovePageUpAndModifySelection"                  },
+    { VK_DOWN,     0,                   "MoveDown"                                      },
+    { VK_DOWN,     ShiftKey,            "MoveDownAndModifySelection"                    },
+    { VK_NEXT,     ShiftKey,            "MovePageDownAndModifySelection"                },
+    { VK_PRIOR,    0,                   "MovePageUp"                                    },
+    { VK_NEXT,     0,                   "MovePageDown"                                  },
+
+    { VK_HOME,     0,                   "MoveToBeginningOfLine"                         },
+    { VK_HOME,     ShiftKey,            "MoveToBeginningOfLineAndModifySelection"       },
+    { VK_LEFT,     MetaKey,             "MoveToBeginningOfLine"                         },
+    { VK_LEFT,     MetaKey | ShiftKey,  "MoveToBeginningOfLineAndModifySelection"       },
+    { VK_UP,       MetaKey,             "MoveToBeginningOfDocument"                     },
+    { VK_UP,       MetaKey | ShiftKey,  "MoveToBeginningOfDocumentAndModifySelection"   },
+
+    { VK_END,      0,                   "MoveToEndOfLine"                               },
+    { VK_END,      ShiftKey,            "MoveToEndOfLineAndModifySelection"             },
+    { VK_DOWN,     MetaKey,             "MoveToEndOfDocument"                           },
+    { VK_DOWN,     MetaKey | ShiftKey,  "MoveToEndOfDocumentAndModifySelection"         },
+    { VK_RIGHT,    MetaKey,             "MoveToEndOfLine"                               },
+    { VK_RIGHT,    MetaKey | ShiftKey,  "MoveToEndOfLineAndModifySelection"             },
+
+    { VK_BACK,     0,                   "DeleteBackward"                                },
+    { VK_BACK,     ShiftKey,            "DeleteBackward"                                },
+    { VK_DELETE,   0,                   "DeleteForward"                                 },
+    { VK_BACK,     AltKey,              "DeleteWordBackward"                            },
+    { VK_DELETE,   AltKey,              "DeleteWordForward"                             },
 
     { 'B',         CtrlKey,             "ToggleBold"                                    },
     { 'I',         CtrlKey,             "ToggleItalic"                                  },
 
-    { VKEY_ESCAPE, 0,                   "Cancel"                                        },
-    { VKEY_OEM_PERIOD, CtrlKey,         "Cancel"                                        },
-    { VKEY_TAB,    0,                   "InsertTab"                                     },
-    { VKEY_TAB,    ShiftKey,            "InsertBacktab"                                 },
-    { VKEY_RETURN, 0,                   "InsertNewline"                                 },
-    { VKEY_RETURN, CtrlKey,             "InsertNewline"                                 },
-    { VKEY_RETURN, AltKey,              "InsertNewline"                                 },
-    { VKEY_RETURN, AltKey | ShiftKey,   "InsertNewline"                                 },
-    { VKEY_RETURN, ShiftKey,            "InsertLineBreak"                               },
+    { VK_ESCAPE,   0,                   "Cancel"                                        },
+    { VK_OEM_PERIOD, CtrlKey,           "Cancel"                                        },
+    { VK_TAB,      0,                   "InsertTab"                                     },
+    { VK_TAB,      ShiftKey,            "InsertBacktab"                                 },
+    { VK_RETURN,   0,                   "InsertNewline"                                 },
+    { VK_RETURN,   CtrlKey,             "InsertNewline"                                 },
+    { VK_RETURN,   AltKey,              "InsertNewline"                                 },
+    { VK_RETURN,   AltKey | ShiftKey,   "InsertNewline"                                 },
+    { VK_RETURN,   ShiftKey,            "InsertLineBreak"                               },
 
     { 'C',         MetaKey,             "Copy"                                          },
     { 'V',         MetaKey,             "Paste"                                         },
     { 'X',         MetaKey,             "Cut"                                           },
     { 'A',         MetaKey,             "SelectAll"                                     },
-    { VKEY_INSERT, CtrlKey,             "Copy"                                          },
-    { VKEY_INSERT, ShiftKey,            "Paste"                                         },
-    { VKEY_DELETE, ShiftKey,            "Cut"                                           },
+    { VK_INSERT,   CtrlKey,             "Copy"                                          },
+    { VK_INSERT,   ShiftKey,            "Paste"                                         },
+    { VK_DELETE,   ShiftKey,            "Cut"                                           },
     { 'Z',         MetaKey,             "Undo"                                          },
     { 'Z',         MetaKey | ShiftKey,  "Redo"                                          },
 };