Delete key doesn't go Back in WebKit2
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Aug 2010 20:45:36 +0000 (20:45 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Aug 2010 20:45:36 +0000 (20:45 +0000)
<rdar://problem/8272978>
https://bugs.webkit.org/show_bug.cgi?id=43665

Reviewed by Anders Carlsson.

- Adds support for delete key going back (mac only for now)
- Adds support for command-left/command right going back/forward
- Flesh out scrolling due to arrow keys on the mac to match old webkit.
- Made performDefaultBehaviorForKeyEvent platform specific and added
  a boolean return value which will be used later to inform the UI process
  about what events have been processed.

* Shared/CoreIPCSupport/WebPageProxyMessageKinds.h:
(WebPageProxyMessage::):
* UIProcess/API/mac/WKView.mm:
(-[WKView _wantsKeyDownForEvent:]):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didReceiveSyncMessage):
* WebProcess/WebPage/WebBackForwardListProxy.cpp:
(WebKit::WebBackForwardListProxy::backItem):
(WebKit::WebBackForwardListProxy::forwardItem):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::keyEvent):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::scroll):
(WebKit::WebPage::performDefaultBehaviorForKeyEvent):
* WebProcess/WebPage/qt/WebPageQt.cpp:
(WebKit::scroll):
(WebKit::WebPage::performDefaultBehaviorForKeyEvent):
* WebProcess/WebPage/win/WebPageWin.cpp:
(WebKit::scroll):
(WebKit::WebPage::performDefaultBehaviorForKeyEvent):

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

WebKit2/ChangeLog
WebKit2/Shared/CoreIPCSupport/WebPageProxyMessageKinds.h
WebKit2/UIProcess/API/mac/WKView.mm
WebKit2/UIProcess/WebPageProxy.cpp
WebKit2/WebProcess/WebPage/WebBackForwardListProxy.cpp
WebKit2/WebProcess/WebPage/WebPage.cpp
WebKit2/WebProcess/WebPage/WebPage.h
WebKit2/WebProcess/WebPage/mac/WebPageMac.mm
WebKit2/WebProcess/WebPage/qt/WebPageQt.cpp
WebKit2/WebProcess/WebPage/win/WebPageWin.cpp

index e5a71f0..a3e81cb 100644 (file)
@@ -1,3 +1,40 @@
+2010-08-06  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Anders Carlsson.
+
+        Delete key doesn't go Back in WebKit2
+        <rdar://problem/8272978>
+        https://bugs.webkit.org/show_bug.cgi?id=43665
+
+        - Adds support for delete key going back (mac only for now)
+        - Adds support for command-left/command right going back/forward
+        - Flesh out scrolling due to arrow keys on the mac to match old webkit.
+        - Made performDefaultBehaviorForKeyEvent platform specific and added
+          a boolean return value which will be used later to inform the UI process
+          about what events have been processed.
+
+        * Shared/CoreIPCSupport/WebPageProxyMessageKinds.h:
+        (WebPageProxyMessage::):
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView _wantsKeyDownForEvent:]):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::didReceiveSyncMessage):
+        * WebProcess/WebPage/WebBackForwardListProxy.cpp:
+        (WebKit::WebBackForwardListProxy::backItem):
+        (WebKit::WebBackForwardListProxy::forwardItem):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::keyEvent):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::scroll):
+        (WebKit::WebPage::performDefaultBehaviorForKeyEvent):
+        * WebProcess/WebPage/qt/WebPageQt.cpp:
+        (WebKit::scroll):
+        (WebKit::WebPage::performDefaultBehaviorForKeyEvent):
+        * WebProcess/WebPage/win/WebPageWin.cpp:
+        (WebKit::scroll):
+        (WebKit::WebPage::performDefaultBehaviorForKeyEvent):
+
 2010-08-07  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r64904.
index 64b47a4..8869ca7 100644 (file)
@@ -67,7 +67,9 @@ enum Kind {
     
     BackForwardAddItem,
     BackForwardGoToItem,
+    BackForwardBackItem,
     BackForwardCurrentItem,
+    BackForwardForwardItem,
     BackForwardItemAtIndex,
     BackForwardBackListCount,
     BackForwardForwardListCount,
index b00b96d..c799686 100644 (file)
@@ -148,6 +148,13 @@ using namespace WebCore;
 
 // Events
 
+// Override this so that AppKit will send us arrow keys as key down events so we can
+// support them via the key bindings mechanism.
+- (BOOL)_wantsKeyDownForEvent:(NSEvent *)event
+{
+    return YES;
+}
+
 - (void)mouseDown:(NSEvent *)theEvent
 {
     WebMouseEvent mouseEvent = WebEventFactory::createWebMouseEvent(theEvent, self);
index 51aa970..8e7cd53 100644 (file)
@@ -644,12 +644,25 @@ void WebPageProxy::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIP
             reply->encode(CoreIPC::In(result));
             break;
         }
+
+        case WebPageProxyMessage::BackForwardBackItem: {
+            WebBackForwardListItem* backItem = m_backForwardList->backItem();
+            uint64_t backItemID = backItem ? backItem->itemID() : 0;
+            reply->encode(CoreIPC::In(backItemID));
+            break;
+        }
         case WebPageProxyMessage::BackForwardCurrentItem: {
             WebBackForwardListItem* currentItem = m_backForwardList->currentItem();
             uint64_t currentItemID = currentItem ? currentItem->itemID() : 0;
             reply->encode(CoreIPC::In(currentItemID));
             break;
         }
+        case WebPageProxyMessage::BackForwardForwardItem: {
+            WebBackForwardListItem* forwardItem = m_backForwardList->forwardItem();
+            uint64_t forwardItemID = forwardItem ? forwardItem->itemID() : 0;
+            reply->encode(CoreIPC::In(forwardItemID));
+            break;
+        }
         case WebPageProxyMessage::BackForwardItemAtIndex: {
             int itemIndex;
             if (!arguments->decode(CoreIPC::Out(itemIndex)))
index e61ad87..40d81b9 100644 (file)
@@ -140,7 +140,19 @@ void WebBackForwardListProxy::goToItem(HistoryItem* item)
 
 HistoryItem* WebBackForwardListProxy::backItem()
 {
-    return 0;
+    uint64_t backItemID = 0;
+    if (!WebProcess::shared().connection()->sendSync(WebPageProxyMessage::BackForwardBackItem,
+                                                     m_page->pageID(), CoreIPC::In(),
+                                                     CoreIPC::Out(backItemID),
+                                                     CoreIPC::Connection::NoTimeout)) {
+        return 0;
+    }
+
+    if (!backItemID)
+        return 0;
+
+    RefPtr<HistoryItem> item = idToHistoryItemMap().get(backItemID);
+    return item.get();
 }
 
 HistoryItem* WebBackForwardListProxy::currentItem()
@@ -162,7 +174,19 @@ HistoryItem* WebBackForwardListProxy::currentItem()
 
 HistoryItem* WebBackForwardListProxy::forwardItem()
 {
-    return 0;
+    uint64_t forwardItemID = 0;
+    if (!WebProcess::shared().connection()->sendSync(WebPageProxyMessage::BackForwardForwardItem,
+                                                     m_page->pageID(), CoreIPC::In(),
+                                                     CoreIPC::Out(forwardItemID),
+                                                     CoreIPC::Connection::NoTimeout)) {
+        return 0;
+    }
+
+    if (!forwardItemID)
+        return 0;
+
+    RefPtr<HistoryItem> item = idToHistoryItemMap().get(forwardItemID);
+    return item.get();
 }
 
 HistoryItem* WebBackForwardListProxy::itemAtIndex(int itemIndex)
index 6f7c17c..f2dfa6f 100644 (file)
@@ -44,7 +44,6 @@
 #include "WebPageProxyMessageKinds.h"
 #include "WebPreferencesStore.h"
 #include "WebProcess.h"
-#include <WebCore/BackForwardList.h>
 #include <WebCore/EventHandler.h>
 #include <WebCore/FocusController.h>
 #include <WebCore/Frame.h>
@@ -57,7 +56,6 @@
 #include <WebCore/RenderTreeAsText.h>
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/Settings.h>
-#include <WebCore/WindowsKeyboardCodes.h>
 #include <runtime/JSLock.h>
 #include <runtime/JSValue.h>
 
@@ -393,7 +391,9 @@ void WebPage::keyEvent(const WebKeyboardEvent& keyboardEvent)
     if (m_page->focusController()->focusedOrMainFrame()->eventHandler()->keyEvent(platformKeyboardEvent))
         return;
 
-    performDefaultBehaviorForKeyEvent(keyboardEvent);
+    bool handled = performDefaultBehaviorForKeyEvent(keyboardEvent);
+    // FIXME: Communicate back to the UI process that the event was handled.
+    (void)handled;
 }
 
 void WebPage::setActive(bool isActive)
@@ -487,63 +487,6 @@ bool WebPage::handleEditingKeyboardEvent(KeyboardEvent* evt)
     return frame->editor()->insertText(evt->keyEvent()->text(), evt);
 }
 
-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_SPACE:
-        granularity = ScrollByPage;
-        direction = event.shiftKey() ? ScrollUp : ScrollDown;
-        break;
-    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::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboardEvent)
-{
-    ScrollDirection direction;
-    ScrollGranularity granularity;
-    if (getScrollMapping(keyboardEvent, direction, granularity))
-        m_page->focusController()->focusedOrMainFrame()->eventHandler()->scrollRecursively(direction, granularity);
-}
-
 void WebPage::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
 {
     if (messageID.is<CoreIPC::MessageClassDrawingArea>()) {
index 23f32c2..acc0da1 100644 (file)
@@ -129,7 +129,7 @@ private:
 
     void platformInitialize();
     static const char* interpretKeyEvent(const WebCore::KeyboardEvent*);
-    void performDefaultBehaviorForKeyEvent(const WebKeyboardEvent&);
+    bool performDefaultBehaviorForKeyEvent(const WebKeyboardEvent&);
 
     // Actions
     void tryClose();
index 6093664..c3f0165 100644 (file)
@@ -25,6 +25,9 @@
 
 #include "WebPage.h"
 
+#include "WebEvent.h"
+#include <WebCore/FocusController.h>
+#include <WebCore/Frame.h>
 #include <WebCore/KeyboardEvent.h>
 #include <WebCore/Page.h>
 #include <WebCore/PlatformKeyboardEvent.h>
@@ -39,6 +42,10 @@ void WebPage::platformInitialize()
     m_page->addSchedulePair(SchedulePair::create([NSRunLoop currentRunLoop], kCFRunLoopCommonModes));
 }
 
+void WebPage::platformPreferencesDidChange(const WebPreferencesStore&)
+{
+}
+
 // FIXME: Editor commands should not be hard coded and instead should come from AppKit.  
 
 static const unsigned CtrlKey   = 1 << 0;
@@ -174,8 +181,96 @@ const char* WebPage::interpretKeyEvent(const KeyboardEvent* evt)
     return mapKey ? keyPressCommandsMap->get(mapKey) : 0;
 }
 
-void WebPage::platformPreferencesDidChange(const WebPreferencesStore&)
+static inline void scroll(Page* page, ScrollDirection direction, ScrollGranularity granularity)
+{
+    page->focusController()->focusedOrMainFrame()->eventHandler()->scrollRecursively(direction, granularity);
+}
+
+bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboardEvent)
 {
+    if (keyboardEvent.type() != WebEvent::KeyDown)
+        return false;
+
+    // FIXME: This should be in WebCore.
+
+    switch (keyboardEvent.windowsVirtualKeyCode()) {
+    case VK_BACK:
+        if (keyboardEvent.shiftKey())
+            m_page->goForward();
+        else
+            m_page->goBack();
+        break;
+    case VK_SPACE:
+        if (keyboardEvent.shiftKey())
+            scroll(m_page, ScrollUp, ScrollByPage);
+        else
+            scroll(m_page, ScrollDown, ScrollByPage);
+        break;
+    case VK_PRIOR:
+        scroll(m_page, ScrollUp, ScrollByPage);
+        break;
+    case VK_NEXT:
+        scroll(m_page, ScrollDown, ScrollByPage);
+        break;
+    case VK_HOME:
+        scroll(m_page, ScrollUp, ScrollByDocument);
+        scroll(m_page, ScrollLeft, ScrollByDocument);
+        break;
+    case VK_END:
+        scroll(m_page, ScrollDown, ScrollByDocument);
+        scroll(m_page, ScrollLeft, ScrollByDocument);
+        break;
+    case VK_UP:
+        if (keyboardEvent.shiftKey())
+            return false;
+        if (keyboardEvent.metaKey()) {
+            scroll(m_page, ScrollUp, ScrollByDocument);
+            scroll(m_page, ScrollLeft, ScrollByDocument);
+        } else if (keyboardEvent.altKey() || keyboardEvent.controlKey())
+            scroll(m_page, ScrollUp, ScrollByPage);
+        else
+            scroll(m_page, ScrollUp, ScrollByLine);
+        break;
+    case VK_DOWN:
+        if (keyboardEvent.shiftKey())
+            return false;
+        if (keyboardEvent.metaKey()) {
+            scroll(m_page, ScrollDown, ScrollByDocument);
+            scroll(m_page, ScrollLeft, ScrollByDocument);
+        } else if (keyboardEvent.altKey() || keyboardEvent.controlKey())
+            scroll(m_page, ScrollDown, ScrollByPage);
+        else
+            scroll(m_page, ScrollDown, ScrollByLine);
+        break;
+    case VK_LEFT:
+        if (keyboardEvent.shiftKey())
+            return false;
+        if (keyboardEvent.metaKey())
+            m_page->goBack();
+        else {
+            if (keyboardEvent.altKey()  | keyboardEvent.controlKey())
+                scroll(m_page, ScrollLeft, ScrollByPage);
+            else
+                scroll(m_page, ScrollLeft, ScrollByLine);
+        }
+        break;
+    case VK_RIGHT:
+        if (keyboardEvent.shiftKey())
+            return false;
+        if (keyboardEvent.metaKey())
+            m_page->goForward();
+        else {
+            if (keyboardEvent.altKey() || keyboardEvent.controlKey())
+                scroll(m_page, ScrollRight, ScrollByPage);
+            else
+                scroll(m_page, ScrollRight, ScrollByLine);
+        }
+        break;
+    default:
+        return false;
+    }
+
+    return true;
 }
 
 } // namespace WebKit
index 2aac565..7408b2a 100644 (file)
@@ -26,6 +26,9 @@
 
 #include "WebPage.h"
 
+#include "WebEvent.h"
+#include <WebCore/FocusController.h>
+#include <WebCore/Frame.h>
 #include <WebCore/KeyboardEvent.h>
 #include <WebCore/Page.h>
 #include <WebCore/PlatformKeyboardEvent.h>
@@ -81,6 +84,10 @@ void WebPage::platformInitialize()
 {
 }
 
+void WebPage::platformPreferencesDidChange(const WebPreferencesStore&)
+{
+}
+
 static const unsigned CtrlKey = 1 << 0;
 static const unsigned AltKey = 1 << 1;
 static const unsigned ShiftKey = 1 << 2;
@@ -201,8 +208,58 @@ const char* WebPage::interpretKeyEvent(const KeyboardEvent* evt)
     return mapKey ? keyPressCommandsMap->get(mapKey) : 0;
 }
 
-void WebPage::platformPreferencesDidChange(const WebPreferencesStore&)
+static inline void scroll(Page* page, ScrollDirection direction, ScrollGranularity granularity)
 {
+    page->focusController()->focusedOrMainFrame()->eventHandler()->scrollRecursively(direction, granularity);
+}
+
+bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboardEvent)
+{
+    if (keyboardEvent.type() != WebEvent::KeyDown && keyboardEvent.type() != WebEvent::RawKeyDown)
+        return false;
+
+    switch (keyboardEvent.windowsVirtualKeyCode()) {
+    case VK_BACK:
+        if (keyboardEvent.shiftKey())
+            m_page->goForward();
+        else
+            m_page->goBack();
+        break;
+    case VK_SPACE:
+        if (keyboardEvent.shiftKey())
+            scroll(m_page, ScrollUp, ScrollByPage);
+        else
+            scroll(m_page, ScrollDown, ScrollByPage);
+        break;
+    case VK_LEFT:
+        scroll(m_page, ScrollLeft, ScrollByLine);
+        break;
+    case VK_RIGHT:
+        scroll(m_page, ScrollRight, ScrollByLine);
+        break;
+    case VK_UP:
+        scroll(m_page, ScrollUp, ScrollByLine);
+        break;
+    case VK_DOWN:
+        scroll(m_page, ScrollDown, ScrollByLine);
+        break;
+    case VK_HOME:
+        scroll(m_page, ScrollUp, ScrollByDocument);
+        break;
+    case VK_END:
+        scroll(m_page, ScrollDown, ScrollByDocument);
+        break;
+    case VK_PRIOR:
+        scroll(m_page, ScrollUp, ScrollByPage);
+        break;
+    case VK_NEXT:
+        scroll(m_page, ScrollDown, ScrollByPage);
+        break;
+    default:
+        return false;
+    }
+
+    return true;
 }
 
 } // namespace WebKit
index 960e9bd..e4b28b2 100644 (file)
 #include "WebPage.h"
 
 #include "FontSmoothingLevel.h"
+#include "WebEvent.h"
 #include "WebPreferencesStore.h"
+#include <WebCore/FocusController.h>
 #include <WebCore/FontRenderingMode.h>
+#include <WebCore/Frame.h>
 #include <WebCore/KeyboardEvent.h>
 #include <WebCore/Page.h>
 #include <WebCore/PlatformKeyboardEvent.h>
@@ -44,6 +47,18 @@ void WebPage::platformInitialize()
     m_page->settings()->setFontRenderingMode(AlternateRenderingMode);
 }
 
+void WebPage::platformPreferencesDidChange(const WebPreferencesStore& store)
+{
+#if PLATFORM(CG)
+    FontSmoothingLevel adjustedLevel = static_cast<FontSmoothingLevel>(store.fontSmoothingLevel);
+    if (adjustedLevel == FontSmoothingLevelWindows)
+        adjustedLevel = FontSmoothingLevelMedium;
+    wkSetFontSmoothingLevel(adjustedLevel);
+#endif
+
+    m_page->settings()->setFontRenderingMode(store.fontSmoothingLevel == FontSmoothingLevelWindows ? AlternateRenderingMode : NormalRenderingMode);
+}
+
 static const unsigned CtrlKey = 1 << 0;
 static const unsigned AltKey = 1 << 1;
 static const unsigned ShiftKey = 1 << 2;
@@ -164,16 +179,58 @@ const char* WebPage::interpretKeyEvent(const KeyboardEvent* evt)
     return mapKey ? keyPressCommandsMap->get(mapKey) : 0;
 }
 
-void WebPage::platformPreferencesDidChange(const WebPreferencesStore& store)
+static inline void scroll(Page* page, ScrollDirection direction, ScrollGranularity granularity)
 {
-#if PLATFORM(CG)
-    FontSmoothingLevel adjustedLevel = static_cast<FontSmoothingLevel>(store.fontSmoothingLevel);
-    if (adjustedLevel == FontSmoothingLevelWindows)
-        adjustedLevel = FontSmoothingLevelMedium;
-    wkSetFontSmoothingLevel(adjustedLevel);
-#endif
+    page->focusController()->focusedOrMainFrame()->eventHandler()->scrollRecursively(direction, granularity);
+}
 
-    m_page->settings()->setFontRenderingMode(store.fontSmoothingLevel == FontSmoothingLevelWindows ? AlternateRenderingMode : NormalRenderingMode);
+bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboardEvent)
+{
+    if (keyboardEvent.type() != WebEvent::KeyDown && keyboardEvent.type() != WebEvent::RawKeyDown)
+        return false;
+
+    switch (keyboardEvent.windowsVirtualKeyCode()) {
+    case VK_BACK:
+        if (keyboardEvent.shiftKey())
+            m_page->goForward();
+        else
+            m_page->goBack();
+        break;
+    case VK_SPACE:
+        if (keyboardEvent.shiftKey())
+            scroll(m_page, ScrollUp, ScrollByPage);
+        else
+            scroll(m_page, ScrollDown, ScrollByPage);
+        break;
+    case VK_LEFT:
+        scroll(m_page, ScrollLeft, ScrollByLine);
+        break;
+    case VK_RIGHT:
+        scroll(m_page, ScrollRight, ScrollByLine);
+        break;
+    case VK_UP:
+        scroll(m_page, ScrollUp, ScrollByLine);
+        break;
+    case VK_DOWN:
+        scroll(m_page, ScrollDown, ScrollByLine);
+        break;
+    case VK_HOME:
+        scroll(m_page, ScrollUp, ScrollByDocument);
+        break;
+    case VK_END:
+        scroll(m_page, ScrollDown, ScrollByDocument);
+        break;
+    case VK_PRIOR:
+        scroll(m_page, ScrollUp, ScrollByPage);
+        break;
+    case VK_NEXT:
+        scroll(m_page, ScrollDown, ScrollByPage);
+        break;
+    default:
+        return false;
+    }
+
+    return true;
 }
 
 } // namespace WebKit