Fix for 10945, WheelEvent should support two dimensions at once, since
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Sep 2006 09:52:25 +0000 (09:52 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Sep 2006 09:52:25 +0000 (09:52 +0000)
        MacBooks allow for diagonal scrolling.  Also enhance the PlatformWheelEvent
        to allow for diagonal scrolling.

        Reviewed by Eric

        * dom/EventTargetNode.cpp:
        (WebCore::EventTargetNode::dispatchWheelEvent):
        * dom/WheelEvent.cpp:
        (WebCore::WheelEvent::WheelEvent):
        (WebCore::WheelEvent::initWheelEvent):
        * dom/WheelEvent.h:
        (WebCore::WheelEvent::wheelDelta):
        (WebCore::WheelEvent::wheelDeltaX):
        (WebCore::WheelEvent::wheelDeltaY):
        * dom/WheelEvent.idl:
        * page/FrameView.cpp:
        (WebCore::FrameView::handleWheelEvent):
        * platform/PlatformWheelEvent.h:
        (WebCore::PlatformWheelEvent::deltaX):
        (WebCore::PlatformWheelEvent::deltaY):
        (WebCore::PlatformWheelEvent::normalize):
        * platform/mac/WheelEventMac.mm:
        (WebCore::PlatformWheelEvent::PlatformWheelEvent):

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

WebCore/ChangeLog
WebCore/dom/EventTargetNode.cpp
WebCore/dom/WheelEvent.cpp
WebCore/dom/WheelEvent.h
WebCore/dom/WheelEvent.idl
WebCore/page/FrameView.cpp
WebCore/platform/PlatformWheelEvent.h
WebCore/platform/mac/WheelEventMac.mm

index 01c2942b537c7458d63ba5def74dc2927b0d4f25..d89375deff785155405621c9fb62d10cb534041d 100644 (file)
@@ -1,3 +1,30 @@
+2006-09-20  David Hyatt  <hyatt@apple.com>
+
+        Fix for 10945, WheelEvent should support two dimensions at once, since
+        MacBooks allow for diagonal scrolling.  Also enhance the PlatformWheelEvent
+        to allow for diagonal scrolling.
+
+        Reviewed by Eric
+
+        * dom/EventTargetNode.cpp:
+        (WebCore::EventTargetNode::dispatchWheelEvent):
+        * dom/WheelEvent.cpp:
+        (WebCore::WheelEvent::WheelEvent):
+        (WebCore::WheelEvent::initWheelEvent):
+        * dom/WheelEvent.h:
+        (WebCore::WheelEvent::wheelDelta):
+        (WebCore::WheelEvent::wheelDeltaX):
+        (WebCore::WheelEvent::wheelDeltaY):
+        * dom/WheelEvent.idl:
+        * page/FrameView.cpp:
+        (WebCore::FrameView::handleWheelEvent):
+        * platform/PlatformWheelEvent.h:
+        (WebCore::PlatformWheelEvent::deltaX):
+        (WebCore::PlatformWheelEvent::deltaY):
+        (WebCore::PlatformWheelEvent::normalize):
+        * platform/mac/WheelEventMac.mm:
+        (WebCore::PlatformWheelEvent::PlatformWheelEvent):
+
 2006-09-19  Eric Seidel  <eric@eseidel.com>
 
         Reviewed by hyatt.
index e091ca81f0f2f9f8de03e0f095db9f625b078fd0..4eaa0c36261848977b4f4eabb8d953c4f54d60ed 100644 (file)
@@ -446,7 +446,7 @@ bool EventTargetNode::dispatchMouseEvent(const AtomicString& eventType, int butt
 void EventTargetNode::dispatchWheelEvent(PlatformWheelEvent& e)
 {
     assert(!eventDispatchForbidden());
-    if (e.delta() == 0)
+    if (e.deltaX() == 0 && e.deltaY() == 0)
         return;
     
     FrameView* view = document()->view();
@@ -455,7 +455,7 @@ void EventTargetNode::dispatchWheelEvent(PlatformWheelEvent& e)
     
     IntPoint pos = view->viewportToContents(e.pos());
     
-    RefPtr<WheelEvent> we = new WheelEvent(e.isHorizontal(), e.delta(),
+    RefPtr<WheelEvent> we = new WheelEvent(e.deltaX(), e.deltaY(),
                                            document()->defaultView(), e.globalX(), e.globalY(), pos.x(), pos.y(),
                                            e.ctrlKey(), e.altKey(), e.shiftKey(), e.metaKey());
     ExceptionCode ec = 0;
index 6eabed46fe201a29d617590880d399d347f3579b..08bbaf7bb6ec3c5ca59d71600bf451019e4f0ed8 100644 (file)
 
 #include "EventNames.h"
 
+#include <wtf/MathExtras.h>
+
 namespace WebCore {
 
 using namespace EventNames;
 
 WheelEvent::WheelEvent()
-    : m_horizontal(false)
-    , m_wheelDelta(0)
+    : m_wheelDeltaX(0)
+    , m_wheelDeltaY(0)
 {
 }
 
-WheelEvent::WheelEvent(bool horizontal, int wheelDelta, AbstractView* view,
+WheelEvent::WheelEvent(float wheelDeltaX, float wheelDeltaY, AbstractView* view,
                        int screenX, int screenY, int pageX, int pageY,
                        bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
-    : MouseRelatedEvent(horizontal ? khtmlHorizontalmousewheelEvent : mousewheelEvent,
+    : MouseRelatedEvent(mousewheelEvent,
                         true, true, view, 0, screenX, screenY, pageX, pageY, 
                         ctrlKey, altKey, shiftKey, metaKey)
-    , m_horizontal(horizontal)
-    , m_wheelDelta(wheelDelta)
+    , m_wheelDeltaX(lrint(wheelDeltaX) * 120)
+    , m_wheelDeltaY(lrint(wheelDeltaY) * 120) // Normalize to the Windows 120 multiple
 {
 }
 
-void WheelEvent::initWheelEvent(bool horizontal, int wheelDelta, AbstractView* view,
+void WheelEvent::initWheelEvent(int wheelDeltaX, int wheelDeltaY, AbstractView* view,
                                 int screenX, int screenY, int pageX, int pageY,
                                 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
 {
     if (dispatched())
         return;
     
-    initUIEvent(horizontal ? khtmlHorizontalmousewheelEvent : mousewheelEvent, 
-                true, true, view, 0);
+    initUIEvent(mousewheelEvent, true, true, view, 0);
     
     m_screenX = screenX;
     m_screenY = screenY;
@@ -64,8 +65,8 @@ void WheelEvent::initWheelEvent(bool horizontal, int wheelDelta, AbstractView* v
     m_altKey = altKey;
     m_shiftKey = shiftKey;
     m_metaKey = metaKey;
-    m_horizontal = horizontal;
-    m_wheelDelta = wheelDelta;
+    m_wheelDeltaX = wheelDeltaX;
+    m_wheelDeltaY = wheelDeltaY;
     
     initCoordinates(pageX, pageY);
 }
index 4f2da2d690a2bee1004d29409aa98e0876f0a3e6..14352a86bcf8382837bf8987b9f6ca2ee9fbf7b4 100644 (file)
@@ -34,22 +34,23 @@ namespace WebCore {
     class WheelEvent : public MouseRelatedEvent {
     public:
         WheelEvent();
-        WheelEvent(bool horizontal, int wheelDelta, AbstractView*,
+        WheelEvent(float wheelDeltaX, float wheelDeltaY, AbstractView*,
                    int screenX, int screenY, int pageX, int pageY,
                    bool ctrlKey, bool altKey, bool shiftKey, bool metaKey);
 
-        void initWheelEvent(bool horizontal, int wheelDelta, AbstractView*,
+        void initWheelEvent(int wheelDeltaX, int wheelDeltaY, AbstractView*,
                             int screenX, int screenY, int pageX, int pageY,
                             bool ctrlKey, bool altKey, bool shiftKey, bool metaKey);
-        
-        bool isHorizontal() const { return m_horizontal; }
-        int wheelDelta() const { return m_wheelDelta; }
+
+        int wheelDelta() const { if (m_wheelDeltaY == 0) return m_wheelDeltaX; return m_wheelDeltaY; }
+        int wheelDeltaX() const { return m_wheelDeltaX; }
+        int wheelDeltaY() const { return m_wheelDeltaY; }
 
     private:
         virtual bool isWheelEvent() const;
 
-        bool m_horizontal;
-        int m_wheelDelta;
+        int m_wheelDeltaX;
+        int m_wheelDeltaY;
     };
 
 } // namespace WebCore
index 4c69a5f86dc3d8f88281ee4442e5753e2c7d8c5f..dad2331b74602a3e5fa7aaf08285882b61fc957c 100644 (file)
@@ -31,6 +31,8 @@ module events {
         readonly attribute boolean altKey;
         readonly attribute boolean metaKey;
         readonly attribute long    wheelDelta;
+        readonly attribute long    wheelDeltaX;
+        readonly attribute long    wheelDeltaY;
 
         // WebKit Extensions
         readonly attribute long    offsetX;
@@ -39,10 +41,8 @@ module events {
         readonly attribute long    y;
 
 #if !defined(LANGUAGE_JAVASCRIPT)
-        readonly attribute boolean isHorizontal;
-
-        void initWheelEvent(in boolean horizontal, 
-                            in long wheelDelta, 
+        void initWheelEvent(in long wheelDeltaX,
+                            in long wheelDeltaY, 
                             in DOMWindow view, 
                             in long screenX,
                             in long screenY,
index d544e538c36dd0f9d97cfc30e5501dc6bee75127..a6e5446d6343d54c89e151f8f03fb378d7e57949 100644 (file)
@@ -1191,26 +1191,13 @@ void FrameView::handleWheelEvent(PlatformWheelEvent& e)
                     return;
                     
                 if (node->renderer()) {
-                    ScrollDirection direction;
-                    float multiplier;
-                    float deltaX = e.isHorizontal() ? e.platformDelta() : 0;
-                    float deltaY = e.isHorizontal() ? 0 : e.platformDelta();
-                    if (deltaX < 0) {
-                        direction = ScrollRight;
-                        multiplier = -deltaX;
-                    } else if (deltaX > 0) {
-                        direction = ScrollLeft;
-                        multiplier = deltaX;
-                    } else if (deltaY < 0) {
-                        direction = ScrollDown;
-                        multiplier = -deltaY;
-                    }  else if (deltaY > 0) {
-                        direction = ScrollUp;
-                        multiplier = deltaY;
-                    } else
-                        return;
-
-                    if (node->renderer()->scroll(direction, ScrollByWheel, multiplier))
+                    // Just break up into two scrolls if we need to.  Diagonal movement on 
+                    // a MacBook pro is an example of a 2-dimensional mouse wheel event (where both deltaX and deltaY can be set).
+                    if (e.deltaX() && node->renderer()->scroll(e.deltaX() < 0 ? ScrollRight : ScrollLeft, ScrollByWheel,
+                                                               e.deltaX() < 0 ? -e.deltaX() : e.deltaX()))
+                        e.accept();
+                    if (e.deltaY() && node->renderer()->scroll(e.deltaY() < 0 ? ScrollDown : ScrollUp, ScrollByWheel,
+                                                               e.deltaY() < 0 ? -e.deltaY() : e.deltaY()))
                         e.accept();
                 }
             }
index 914ac48c3238cb49fc5af877ad7db3d9cbe5d483..357f02759f1e21e6bd6d43f17e6a5f45b85b94bb 100644 (file)
@@ -46,9 +46,9 @@ namespace WebCore {
     public:
         const IntPoint& pos() const { return m_position; }
         const IntPoint& globalPos() const { return m_globalPosition; }
-        float platformDelta() const { return m_platformDelta; } // This is the original delta amount on the native platform and can vary.
-        int delta() const { return m_delta; } // This delta is a multiple of 120 and is designed to match the Windows standard for wheel deltas.
-        bool isHorizontal() const { return m_isHorizontal; }
+        float deltaX() const { return m_deltaX; }
+        float deltaY() const { return m_deltaY; }
+
         bool isAccepted() const { return m_isAccepted; }
         bool shiftKey() const { return m_shiftKey; }
         bool ctrlKey() const { return m_ctrlKey; }
@@ -74,9 +74,8 @@ namespace WebCore {
     private:
         IntPoint m_position;
         IntPoint m_globalPosition;
-        float m_platformDelta;
-        int m_delta;
-        bool m_isHorizontal;
+        float m_deltaX;
+        float m_deltaY;
         bool m_isAccepted;
         bool m_shiftKey;
         bool m_ctrlKey;
index 3a216f7d0ce0627d014d9cd035937dbf0bb60e50..e0fa8957777fa4e3d6530a5acc48e95305708bbd 100644 (file)
@@ -52,32 +52,11 @@ static IntPoint globalPositionForEvent(NSEvent *event)
     }
 }
 
-static bool eventIsHorizontal(NSEvent *event)
-{
-    switch ([event type]) {
-        case NSScrollWheel:
-            return [event deltaX] != 0;
-        default:
-            return false;
-    }
-}
-
-static float platformDeltaForEvent(NSEvent *event)
-{
-    switch ([event type]) {
-        case NSScrollWheel:
-            return eventIsHorizontal(event) ? [event deltaX] : [event deltaY];
-        default:
-            return 0;
-    }
-}
-
 PlatformWheelEvent::PlatformWheelEvent(NSEvent* event)
     : m_position(positionForEvent(event))
     , m_globalPosition(globalPositionForEvent(event))
-    , m_platformDelta(platformDeltaForEvent(event))
-    , m_delta(lrint(m_platformDelta) * 120)
-    , m_isHorizontal(eventIsHorizontal(event))
+    , m_deltaX([event deltaX])
+    , m_deltaY([event deltaY])
     , m_isAccepted(false)
     , m_shiftKey([event modifierFlags] & NSShiftKeyMask)
     , m_ctrlKey([event modifierFlags] & NSControlKeyMask)