Changeset 64091 in webkit


Ignore:
Timestamp:
Jul 26, 2010 5:00:51 PM (14 years ago)
Author:
weinig@apple.com
Message:

Part 2 of https://bugs.webkit.org/show_bug.cgi?id=43013
<rdar://problem/8152434>
Add support for scrolling using the keyboard in WebKit2

Reviewed by Anders Carlsson.

Add support for scrolling with the space bar and ensure that we don't scroll
if WebCore is handling the event in another way.

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::keyEvent):
(WebKit::getScrollMapping):
(WebKit::WebPage::performDefaultBehaviorForKeyEvent):

  • WebProcess/WebPage/WebPage.h:
Location:
trunk/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit2/ChangeLog

    r64086 r64091  
     12010-07-26  Sam Weinig  <sam@webkit.org>
     2
     3        Reviewed by Anders Carlsson.
     4
     5        Part 2 of https://bugs.webkit.org/show_bug.cgi?id=43013
     6        <rdar://problem/8152434>
     7        Add support for scrolling using the keyboard in WebKit2
     8
     9        Add support for scrolling with the space bar and ensure that we don't scroll
     10        if WebCore is handling the event in another way.
     11
     12        * WebProcess/WebPage/WebPage.cpp:
     13        (WebKit::WebPage::keyEvent):
     14        (WebKit::getScrollMapping):
     15        (WebKit::WebPage::performDefaultBehaviorForKeyEvent):
     16        * WebProcess/WebPage/WebPage.h:
     17
    1182010-07-26  Sam Weinig  <sam@webkit.org>
    219
  • trunk/WebKit2/WebProcess/WebPage/WebPage.cpp

    r64086 r64091  
    345345}
    346346
    347 static bool getScrollMapping(const WebKeyboardEvent& event, ScrollDirection& direction, ScrollGranularity& granularity)
    348 {
    349     if (event.type() != WebEvent::KeyDown && event.type() != WebEvent::RawKeyDown)
    350         return false;
    351 
    352     switch (event.windowsVirtualKeyCode()) {
    353     case VK_LEFT:
    354         granularity = ScrollByLine;
    355         direction = ScrollLeft;
    356         break;
    357     case VK_RIGHT:
    358         granularity = ScrollByLine;
    359         direction = ScrollRight;
    360         break;
    361     case VK_UP:
    362         granularity = ScrollByLine;
    363         direction = ScrollUp;
    364         break;
    365     case VK_DOWN:
    366         granularity = ScrollByLine;
    367         direction = ScrollDown;
    368         break;
    369     case VK_HOME:
    370         granularity = ScrollByDocument;
    371         direction = ScrollUp;
    372         break;
    373     case VK_END:
    374         granularity = ScrollByDocument;
    375         direction = ScrollDown;
    376         break;
    377     case VK_PRIOR:
    378         granularity = ScrollByPage;
    379         direction = ScrollUp;
    380         break;
    381     case VK_NEXT:
    382         granularity = ScrollByPage;
    383         direction = ScrollDown;
    384         break;
    385     default:
    386         return false;
    387     }
    388 
    389     return true;
    390 }
    391347
    392348void WebPage::keyEvent(const WebKeyboardEvent& keyboardEvent)
     
    400356
    401357    PlatformKeyboardEvent platformKeyboardEvent = platform(keyboardEvent);
    402 
    403     Frame* frame = m_page->focusController()->focusedOrMainFrame();
    404     frame->eventHandler()->keyEvent(platformKeyboardEvent);
    405 
    406     ScrollDirection direction;
    407     ScrollGranularity granularity;
    408     if (getScrollMapping(keyboardEvent, direction, granularity))
    409         frame->eventHandler()->scrollRecursively(direction, granularity);
     358    if (m_page->focusController()->focusedOrMainFrame()->eventHandler()->keyEvent(platformKeyboardEvent))
     359        return;
     360
     361    performDefaultBehaviorForKeyEvent(keyboardEvent);
    410362}
    411363
     
    499451}
    500452
     453static bool getScrollMapping(const WebKeyboardEvent& event, ScrollDirection& direction, ScrollGranularity& granularity)
     454{
     455    if (event.type() != WebEvent::KeyDown && event.type() != WebEvent::RawKeyDown)
     456        return false;
     457
     458    switch (event.windowsVirtualKeyCode()) {
     459    case VK_SPACE:
     460        granularity = ScrollByPage;
     461        direction = event.shiftKey() ? ScrollUp : ScrollDown;
     462        break;
     463    case VK_LEFT:
     464        granularity = ScrollByLine;
     465        direction = ScrollLeft;
     466        break;
     467    case VK_RIGHT:
     468        granularity = ScrollByLine;
     469        direction = ScrollRight;
     470        break;
     471    case VK_UP:
     472        granularity = ScrollByLine;
     473        direction = ScrollUp;
     474        break;
     475    case VK_DOWN:
     476        granularity = ScrollByLine;
     477        direction = ScrollDown;
     478        break;
     479    case VK_HOME:
     480        granularity = ScrollByDocument;
     481        direction = ScrollUp;
     482        break;
     483    case VK_END:
     484        granularity = ScrollByDocument;
     485        direction = ScrollDown;
     486        break;
     487    case VK_PRIOR:
     488        granularity = ScrollByPage;
     489        direction = ScrollUp;
     490        break;
     491    case VK_NEXT:
     492        granularity = ScrollByPage;
     493        direction = ScrollDown;
     494        break;
     495    default:
     496        return false;
     497    }
     498
     499    return true;
     500}
     501
     502void WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboardEvent)
     503{
     504    ScrollDirection direction;
     505    ScrollGranularity granularity;
     506    if (getScrollMapping(keyboardEvent, direction, granularity))
     507        m_page->focusController()->focusedOrMainFrame()->eventHandler()->scrollRecursively(direction, granularity);
     508}
     509
    501510void WebPage::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder& arguments)
    502511{
  • trunk/WebKit2/WebProcess/WebPage/WebPage.h

    r64063 r64091  
    118118    void platformInitialize();
    119119    static const char* interpretKeyEvent(const WebCore::KeyboardEvent*);
     120    void performDefaultBehaviorForKeyEvent(const WebKeyboardEvent&);
    120121
    121122    // Actions
Note: See TracChangeset for help on using the changeset viewer.