Reviewed by Darin.
authorap@webkit.org <ap@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Dec 2007 20:40:29 +0000 (20:40 +0000)
committerap@webkit.org <ap@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Dec 2007 20:40:29 +0000 (20:40 +0000)
        Turn on keyboard event processing quirks for feed views and old applications on Mac OS X.

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

13 files changed:
WebCore/ChangeLog
WebCore/WebCore.base.exp
WebCore/dom/KeyboardEvent.cpp
WebCore/page/EventHandler.cpp
WebCore/page/EventHandler.h
WebCore/page/Settings.cpp
WebCore/page/Settings.h
WebCore/page/mac/EventHandlerMac.mm
WebCore/platform/PlatformKeyboardEvent.h
WebCore/platform/mac/KeyEventMac.mm
WebKit/mac/ChangeLog
WebKit/mac/Misc/WebKitVersionChecks.h
WebKit/mac/WebView/WebView.mm

index 0ba6b389d955d35b7b76f5f37fba69451214d6c3..1bec79d6a8e01bf6f6c045311d0d7001ab0657b8 100644 (file)
@@ -1,3 +1,28 @@
+2007-12-13  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Darin.
+
+        Turn on keyboard event processing quirks for feed views and old applications on Mac OS X.
+
+        * WebCore.base.exp:
+        * dom/KeyboardEvent.cpp:
+        (WebCore::KeyboardEvent::charCode):
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::needsKeyboardEventDisambiguationQuirks):
+        (WebCore::EventHandler::keyEvent):
+        * page/EventHandler.h:
+        * page/Settings.cpp:
+        (WebCore::Settings::Settings):
+        (WebCore::Settings::setNeedsKeyboardEventDisambiguationQuirks):
+        * page/Settings.h:
+        (WebCore::Settings::needsKeyboardEventDisambiguationQuirks):
+        * page/mac/EventHandlerMac.mm:
+        (WebCore::EventHandler::needsKeyboardEventDisambiguationQuirks):
+        * platform/PlatformKeyboardEvent.h:
+        * platform/mac/KeyEventMac.mm:
+        (WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):
+        (WebCore::PlatformKeyboardEvent::disambiguateKeyDownEvent):
+
 2007-12-13  Dan Bernstein  <mitz@apple.com>
 
         - build fix
index 6a4ee8f6b1d044db2de99a4adad891a0f3817d87..3f96aedb4e8675cea7e0f114e0def37c3970f002 100644 (file)
@@ -498,6 +498,7 @@ __ZN7WebCore8Settings29setDefaultDatabaseOriginQuotaEy
 __ZN7WebCore8Settings31setShrinksStandaloneImagesToFitEb
 __ZN7WebCore8Settings32setNeedsAdobeFrameReloadingQuirkEb
 __ZN7WebCore8Settings40setJavaScriptCanOpenWindowsAutomaticallyEb
+__ZN7WebCore8Settings41setNeedsKeyboardEventDisambiguationQuirksEb
 __ZN7WebCore8Settings41setUsesDashboardBackwardCompatibilityModeEb
 __ZN7WebCore8parseURLERKNS_6StringE
 __ZN7WebCore9FloatRectC1ERK7_NSRect
index 8a90ae4b3ec086b00910f5066d0046c7f010731e..0ee8cb52898c6419d8654a99e4d297f8e8e07f71 100644 (file)
@@ -26,6 +26,8 @@
 #include "Document.h"
 #include "DOMWindow.h"
 #include "EventNames.h"
+#include "EventHandler.h"
+#include "Frame.h"
 #include "PlatformKeyboardEvent.h"
 #include "Settings.h"
 
@@ -130,13 +132,12 @@ int KeyboardEvent::charCode() const
 {
     // IE: not supported
     // Firefox: 0 for keydown/keyup events, character code for keypress
-    // We match Firefox, unless in Dashboard compatibility mode, where we always return the character code.
-    bool dashboardCompatibilityMode = false;
+    // We match Firefox, unless in backward compatibility mode, where we always return the character code.
+    bool backwardCompatibilityMode = false;
     if (view())
-        if (Settings* settings = view()->document()->settings())
-            dashboardCompatibilityMode = settings->usesDashboardBackwardCompatibilityMode();
+        backwardCompatibilityMode = view()->frame()->eventHandler()->needsKeyboardEventDisambiguationQuirks();
 
-    if (!m_keyEvent || (type() != keypressEvent && !dashboardCompatibilityMode))
+    if (!m_keyEvent || (type() != keypressEvent && !backwardCompatibilityMode))
         return 0;
     String text = m_keyEvent->text();
     return static_cast<int>(text.characterStartingAt(0));
index 98613eb93b53954f78acc7c5651a962c89f14a51..cc77e1b4d0a6bf55475a6b7e46c5f0f3bf969d5c 100644 (file)
@@ -1483,6 +1483,13 @@ static bool handleAccessKey(Document* document, const PlatformKeyboardEvent& evt
     return false;
 }
 
+#if !PLATFORM(MAC)
+bool EventHandler::needsKeyboardEventDisambiguationQuirks() const
+{
+    return false;
+}
+#endif
+
 bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
 {
     // Check for cases where we are too early for events -- possible unmatched key up
@@ -1509,14 +1516,12 @@ bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
     if (initialKeyEvent.type() == PlatformKeyboardEvent::KeyUp || initialKeyEvent.type() == PlatformKeyboardEvent::Char)
         return !node->dispatchKeyEvent(initialKeyEvent);
 
-    bool dashboardCompatibilityMode = false;
-    if (Settings* settings = node->document()->settings())
-        dashboardCompatibilityMode = settings->usesDashboardBackwardCompatibilityMode();
+    bool backwardCompatibilityMode = needsKeyboardEventDisambiguationQuirks();
 
     ExceptionCode ec;
     PlatformKeyboardEvent keyDownEvent = initialKeyEvent;    
     if (keyDownEvent.type() != PlatformKeyboardEvent::RawKeyDown)
-        keyDownEvent.disambiguateKeyDownEvent(PlatformKeyboardEvent::RawKeyDown, dashboardCompatibilityMode);
+        keyDownEvent.disambiguateKeyDownEvent(PlatformKeyboardEvent::RawKeyDown, backwardCompatibilityMode);
     RefPtr<KeyboardEvent> keydown = new KeyboardEvent(keyDownEvent, m_frame->document()->defaultView());
     if (matchedAnAccessKey)
         keydown->setDefaultPrevented(true);
@@ -1545,11 +1550,11 @@ bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
 
     node->dispatchEvent(keydown, ec, true);
     bool keydownResult = keydown->defaultHandled() || keydown->defaultPrevented();
-    if (handledByInputMethod || (keydownResult && !dashboardCompatibilityMode) || initialKeyEvent.text().isEmpty())
+    if (handledByInputMethod || (keydownResult && !backwardCompatibilityMode) || initialKeyEvent.text().isEmpty())
         return keydownResult;
     
     // Focus may have changed during keydown handling, so refetch node.
-    // But if we are dispatching a fake Dashboard compatibility keypress, then we pretend that the keypress happened on the original node.
+    // But if we are dispatching a fake backward compatibility keypress, then we pretend that the keypress happened on the original node.
     if (!keydownResult) {
         node = eventTargetNodeForDocument(m_frame->document());
         if (!node)
@@ -1557,7 +1562,7 @@ bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
     }
 
     PlatformKeyboardEvent keyPressEvent = initialKeyEvent;
-    keyPressEvent.disambiguateKeyDownEvent(PlatformKeyboardEvent::Char, dashboardCompatibilityMode);
+    keyPressEvent.disambiguateKeyDownEvent(PlatformKeyboardEvent::Char, backwardCompatibilityMode);
     RefPtr<KeyboardEvent> keypress = new KeyboardEvent(keyPressEvent, m_frame->document()->defaultView());
     keypress->setTarget(node);
     if (keydownResult)
index 3e2e2318c08288f2f50fb3b124055bfb599fb1fa..919c3c41751ae621c35569235287529c5719e47a 100644 (file)
@@ -132,6 +132,8 @@ public:
 
     void setMouseDownMayStartAutoscroll() { m_mouseDownMayStartAutoscroll = true; }
 
+    bool needsKeyboardEventDisambiguationQuirks() const;
+
     bool keyEvent(const PlatformKeyboardEvent&);
     void defaultKeyboardEventHandler(KeyboardEvent*);
 
index 9719dea1c0d335c8d124ce37b86782e70f98d289..ee84b6057c254ed9842df1da10801e192e6016ab 100644 (file)
@@ -58,6 +58,7 @@ Settings::Settings(Page* page)
     , m_textAreasAreResizable(false)
     , m_usesDashboardBackwardCompatibilityMode(false)
     , m_needsAdobeFrameReloadingQuirk(false)
+    , m_needsKeyboardEventDisambiguationQuirks(false)
     , m_isDOMPasteAllowed(false)
     , m_shrinksStandaloneImagesToFit(true)
     , m_usesPageCache(false)
@@ -236,6 +237,14 @@ void Settings::setNeedsAdobeFrameReloadingQuirk(bool shouldNotReloadIFramesForUn
     m_needsAdobeFrameReloadingQuirk = shouldNotReloadIFramesForUnchangedSRC;
 }
 
+// This is a quirk we are pro-actively applying to old applications. It changes keyboard event dispatching,
+// making keyIdentifier available on keypress events, making charCode available on keydown/keyup events,
+// and getting keypress dispatched in more cases.
+void Settings::setNeedsKeyboardEventDisambiguationQuirks(bool needsQuirks)
+{
+    m_needsKeyboardEventDisambiguationQuirks = needsQuirks;
+}
+
 void Settings::setDOMPasteAllowed(bool DOMPasteAllowed)
 {
     m_isDOMPasteAllowed = DOMPasteAllowed;
index 569deac61575f44cc2dadb87c349d279b91e9465..6029a097e2ba3a286d8d20e0c53856587b6b5c53 100644 (file)
@@ -115,7 +115,10 @@ namespace WebCore {
         
         void setNeedsAdobeFrameReloadingQuirk(bool);
         bool needsAcrobatFrameReloadingQuirk() const { return m_needsAdobeFrameReloadingQuirk; }
-        
+
+        void setNeedsKeyboardEventDisambiguationQuirks(bool);
+        bool needsKeyboardEventDisambiguationQuirks() const { return m_needsKeyboardEventDisambiguationQuirks; }
+
         void setDOMPasteAllowed(bool);
         bool isDOMPasteAllowed() const { return m_isDOMPasteAllowed; }
         
@@ -170,6 +173,7 @@ namespace WebCore {
         bool m_textAreasAreResizable : 1;
         bool m_usesDashboardBackwardCompatibilityMode : 1;
         bool m_needsAdobeFrameReloadingQuirk : 1;
+        bool m_needsKeyboardEventDisambiguationQuirks : 1;
         bool m_isDOMPasteAllowed : 1;
         bool m_shrinksStandaloneImagesToFit : 1;
         bool m_usesPageCache: 1;
index 28eec966584b6acffe4da1247a27bd993dae841c..f8f8054b7a893e4e537983fc24aa37bb98db79fe 100644 (file)
@@ -50,6 +50,7 @@
 #include "PlatformScrollBar.h"
 #include "PlatformWheelEvent.h"
 #include "RenderWidget.h"
+#include "Settings.h"
 #include "WebCoreFrameBridge.h"
 
 namespace WebCore {
@@ -132,6 +133,29 @@ bool EventHandler::tabsToAllControls(KeyboardEvent* event) const
     return handlingOptionTab;
 }
 
+bool EventHandler::needsKeyboardEventDisambiguationQuirks() const
+{
+    static BOOL checkedSafari = NO;
+    static BOOL isSafari = NO;
+
+    if (!checkedSafari) {
+        isSafari = [[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.Safari"];
+        checkedSafari = YES;
+    }
+    
+    Document* document = m_frame->document();
+    if (!document)
+        return false;
+
+    // RSS view needs arrow key keypress events.
+    if (isSafari && document->url().startsWith("feed:", false) || document->url().startsWith("feeds:", false))
+        return true;
+    Settings* settings = m_frame->settings();
+    if (!settings)
+        return false;
+    return settings->usesDashboardBackwardCompatibilityMode() || settings->needsKeyboardEventDisambiguationQuirks();
+}
+
 bool EventHandler::keyEvent(NSEvent *event)
 {
     bool result;
index 368bfe907d1231383efe2eb5a4f20e327bf29315..3d4268a3f4c7bd88bff6107613d42de8af99f31f 100644 (file)
@@ -75,7 +75,7 @@ namespace WebCore {
         };
 
         Type type() const { return m_type; }
-        void disambiguateKeyDownEvent(Type, bool dashboardCompatibilityMode = false); // Only used on platforms that need it, i.e. those that generate KeyDown events.
+        void disambiguateKeyDownEvent(Type, bool backwardCompatibilityMode = false); // Only used on platforms that need it, i.e. those that generate KeyDown events.
 
         // Text as as generated by processing a virtual key code with a keyboard layout
         // (in most cases, just a character code, but the layout can emit several
index c44c4d748142b511b7998f3474c6d56019fb6207..50d05464989c0f50cf8a2a461966b86d6cdc6023 100644 (file)
@@ -828,7 +828,7 @@ PlatformKeyboardEvent::PlatformKeyboardEvent(NSEvent *event)
         m_unmodifiedText = "\r";
     }
 
-    // The adjustments below are only needed in Dashboard compatibility mode, but we cannot tell what mode we are in from here.
+    // The adjustments below are only needed in backward compatibility mode, but we cannot tell what mode we are in from here.
 
     // Turn 0x7F into 8, because backspace needs to always be 8.
     if (m_text == "\x7F")
@@ -842,13 +842,13 @@ PlatformKeyboardEvent::PlatformKeyboardEvent(NSEvent *event)
     }
 }
 
-void PlatformKeyboardEvent::disambiguateKeyDownEvent(Type type, bool dashboardCompatibilityMode)
+void PlatformKeyboardEvent::disambiguateKeyDownEvent(Type type, bool backwardCompatibilityMode)
 {
     // Can only change type from KeyDown to RawKeyDown or Char, as we lack information for other conversions.
     ASSERT(m_type == KeyDown);
     ASSERT(type == RawKeyDown || type == Char);
     m_type = type;
-    if (dashboardCompatibilityMode)
+    if (backwardCompatibilityMode)
         return;
 
     if (type == RawKeyDown) {
index d4dde7252e9f29fd1b6db305cb9593aca60e998d..c88cea108e14e5d9a657f72e2951a5bfbaf87fc9 100644 (file)
@@ -1,3 +1,14 @@
+2007-12-13  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Darin.
+
+        Turn on keyboard event processing quirks for feed views and old applications on Mac OS X.
+
+        * Misc/WebKitVersionChecks.h:
+        * WebView/WebView.mm:
+        (-[WebView _needsKeyboardEventHandlingQuirks]):
+        (-[WebView _preferencesChangedNotification:]):
+
 2007-12-12  Brady Eidson  <beidson@apple.com>
 
         Reviewed by Sam Weinig
index 5b4bd621efb9c105a3741657ed8ee8fc986018e9..793dc7374b2f4ac42fbcdf2ad150e9a657fba175 100644 (file)
@@ -43,6 +43,7 @@
 #define WEBKIT_FIRST_VERSION_WITH_INSPECT_ELEMENT_MENU_TAG 0x020A0C00 // 522.12.0
 #define WEBKIT_FIRST_VERSION_WITH_CACHE_MODEL_API 0x020B0500 // 523.5.0
 #define WEBKIT_FIRST_VERSION_WITHOUT_JAVASCRIPT_RETURN_QUIRK 0x020D0100 // 525.1.0
+#define WEBKIT_FIRST_VERSION_WITH_IE_COMPATIBLE_KEYBOARD_EVENT_DISPATCH 0x020D0100 // 525.1.0
 
 #ifdef __cplusplus
 extern "C" {
index 9cc118fcadccd3ab4904c18e30700dd749788400..68499b6e9b12919594a4c89852ae37fdc24a69ed 100644 (file)
@@ -892,10 +892,26 @@ static bool debugWidget = true;
         || WKAppVersionCheckLessThan(@"com.adobe.InCopy", -1, 5.1)
         || WKAppVersionCheckLessThan(@"com.adobe.InDesign", -1, 5.1)
         || WKAppVersionCheckLessThan(@"com.adobe.Soundbooth", -1, 2);
+    checked = YES;
 
     return needsQuirk;
 }
 
+- (BOOL)_needsKeyboardEventDisambiguationQuirks
+{
+    static BOOL checked = NO;
+    static BOOL needsQuirks = NO;
+
+    if (checked)
+        return needsQuirks;
+
+    needsQuirks = !WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_IE_COMPATIBLE_KEYBOARD_EVENT_DISPATCH)
+               && ![[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.Safari"];
+    checked = YES;
+
+    return needsQuirks;
+}
+
 - (void)_preferencesChangedNotification:(NSNotification *)notification
 {
     WebPreferences *preferences = (WebPreferences *)[notification object];
@@ -947,6 +963,7 @@ static bool debugWidget = true;
     } else
         settings->setUserStyleSheetLocation([NSURL URLWithString:@""]);
     settings->setNeedsAdobeFrameReloadingQuirk([self _needsAdobeFrameReloadingQuirk]);
+    settings->setNeedsKeyboardEventDisambiguationQuirks([self _needsKeyboardEventDisambiguationQuirks]);
     settings->setDefaultDatabaseOriginQuota([preferences defaultDatabaseQuota]); 
 }