[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.22-985-g3c00f00
mrowe at apple.com
mrowe at apple.com
Wed Mar 17 18:10:49 UTC 2010
The following commit has been merged in the webkit-1.1 branch:
commit 7916fd4c6fad971839bc0e5a68360799e5252ea9
Author: mrowe at apple.com <mrowe at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Mar 2 23:33:38 2010 +0000
WebCore: Add the capability to create and dispatch a WheelEvent in JavaScript.
Ensure the event's default handler is triggered in the same way as it is
during a PlatformWheelEvent.
Patch by Andy Estes <aestes at apple.com> on 2010-03-02
Reviewed by Maciej Stachowiak.
https://bugs.webkit.org/show_bug.cgi?id=35566
Test: fast/events/wheelevent-in-scrolling-div.html
* dom/Node.cpp: Ensure that the default behavior (scrolling) occurs for
wheel events originating both from the platform and from
JavaScript/ObjC.
(WebCore::Node::dispatchWheelEvent): Instantiate new WheelEvent with
the graunularity of the PlatformWheelEvent.
(WebCore::Node::defaultEventHandler): Add support for mousewheel events.
* dom/WheelEvent.cpp: Add three new member variables: m_deltaX, m_deltaY
and m_granularity. m_deltaX and m_deltaY differ from m_wheelDeltaX and
m_wheelDeltaY, which are the number of wheel ticks multiplied by 120 for
IE compatibility.
(WebCore::WheelEvent::WheelEvent): Initialize new member variables.
(WebCore::WheelEvent::initWheelEvent): Same.
(WebCore::WheelEvent::initWebKitWheelEvent): Same.
* dom/WheelEvent.h: See WheelEvent.cpp.
(WebCore::WheelEvent::): Add Granularity enum (Pixel, Line, Page).
(WebCore::WheelEvent::create): Add new arguments.
(WebCore::WheelEvent::deltaX): Amount of scroll in x direction.
(WebCore::WheelEvent::deltaY): Amount of scroll in y direction.
(WebCore::WheelEvent::granularity): Units of deltaX and deltaY.
* dom/WheelEvent.idl: Add initWebKitWheelEvent() to JavaScript. This is
the same as the initWheelEvent ObjC method. As the DOM Level 3 Events
specification is still a working draft and subject to change, prefix
'WebKit' to the method signature to indicate experimental support.
* page/EventHandler.cpp: Move the scroll handling from
handleWheelEvent() to defaultWheelEventHandler(), which is executed on
both PlatformWheelEvents and JavaScript WheelEvents.
(WebCore::scrollNode): Renamed from scrollAndAcceptEvent(). Remove
the PlatformWheelEvent from the argument list and instead return a
boolean indicating if the scroll event was accepted.
(WebCore::EventHandler::handleWheelEvent): Move scrolling code from here
(WebCore::EventHandler::defaultWheelEventHandler): ...to here.
* page/EventHandler.h: Add function signature.
LayoutTests: Add a test for the patch to https://bugs.webkit.org/show_bug.cgi?id=35566.
These can be run manually or from DRT.
Patch by Andy Estes <aestes at apple.com> on 2010-03-02
Reviewed by Maciej Stachowiak.
* fast/events/wheelevent-in-scrolling-div-expected.txt: Added.
* fast/events/wheelevent-in-scrolling-div.html: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@55436 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 4c80092..62b68cf 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,13 @@
+2010-03-02 Andy Estes <aestes at apple.com>
+
+ Reviewed by Maciej Stachowiak.
+
+ Add a test for the patch to https://bugs.webkit.org/show_bug.cgi?id=35566.
+ These can be run manually or from DRT.
+
+ * fast/events/wheelevent-in-scrolling-div-expected.txt: Added.
+ * fast/events/wheelevent-in-scrolling-div.html: Added.
+
2010-03-02 Mark Rowe <mrowe at apple.com>
Reviewed by Darin Adler.
diff --git a/LayoutTests/fast/events/wheelevent-in-scrolling-div-expected.txt b/LayoutTests/fast/events/wheelevent-in-scrolling-div-expected.txt
new file mode 100644
index 0000000..e2471ef
--- /dev/null
+++ b/LayoutTests/fast/events/wheelevent-in-scrolling-div-expected.txt
@@ -0,0 +1,6 @@
+scrollTop=200 (should be 200): PASS
+scrollLeft=100 (should be 100): PASS
+wheelDeltaY=-24000 (should be -24000): PASS
+wheelDeltaX=-12000 (should be -12000): PASS
+wheelDelta=-24000 (should be -24000): PASS
+
diff --git a/LayoutTests/fast/events/wheelevent-in-scrolling-div.html b/LayoutTests/fast/events/wheelevent-in-scrolling-div.html
new file mode 100644
index 0000000..03dae4b
--- /dev/null
+++ b/LayoutTests/fast/events/wheelevent-in-scrolling-div.html
@@ -0,0 +1,84 @@
+<head>
+ <script>
+ var expectedScrollTop = 200;
+ var expectedScrollLeft = 100;
+
+ if (window.layoutTestController) {
+ layoutTestController.dumpAsText();
+ layoutTestController.waitUntilDone();
+ }
+
+ function dispatchWheelEvent()
+ {
+ var overflowElement = document.getElementById("overflow");
+ if (overflowElement) {
+ overflowElement.addEventListener("mousewheel", mousewheelHandler, false);
+ var wheelEvent = document.createEvent("WheelEvent");
+ if (wheelEvent) {
+ wheelEvent.initWebKitWheelEvent(-window.expectedScrollLeft, -window.expectedScrollTop, window, 0, 0, 0, 0, false, false, false, false);
+ overflowElement.dispatchEvent(wheelEvent);
+ }
+ }
+
+ setTimeout('printScrollOffsets();', 100);
+ }
+
+ function passFailString(p)
+ {
+ var color = p?"green":"red";
+ var text = p?"PASS":"FAIL";
+ return "<span style='color:"+color+"'>"+text+"</span>";
+ }
+
+ function printScrollOffsets()
+ {
+ var consoleDiv = document.getElementById("offsetConsole");
+ var overflowDiv = document.getElementById("overflow");
+ if (consoleDiv && overflowDiv) {
+ consoleDiv.innerHTML = "";
+
+ consoleDiv.innerHTML += "scrollTop=" + overflowDiv.scrollTop + " (should be " + window.expectedScrollTop + "): ";
+ consoleDiv.innerHTML += passFailString(overflowDiv.scrollTop == window.expectedScrollTop);
+ consoleDiv.innerHTML += "<br>"
+
+ consoleDiv.innerHTML += "scrollLeft=" + overflowDiv.scrollLeft + " (should be " + window.expectedScrollLeft + "): ";
+ consoleDiv.innerHTML += passFailString(overflowDiv.scrollLeft == window.expectedScrollLeft);
+ consoleDiv.innerHTML += "<br>"
+ }
+
+ if (window.layoutTestController)
+ window.layoutTestController.notifyDone();
+ }
+
+ function mousewheelHandler(e)
+ {
+ var consoleDiv = document.getElementById("mousewheelConsole");
+ if (consoleDiv) {
+ consoleDiv.innerHTML = "";
+
+ consoleDiv.innerHTML += "wheelDeltaY=" + e.wheelDeltaY + " (should be " + window.expectedScrollTop*-120 + "): ";
+ consoleDiv.innerHTML += passFailString(e.wheelDeltaY == window.expectedScrollTop*-120);
+ consoleDiv.innerHTML += "<br>"
+
+ consoleDiv.innerHTML += "wheelDeltaX=" + e.wheelDeltaX + " (should be " + window.expectedScrollLeft*-120 + "): ";
+ consoleDiv.innerHTML += passFailString(e.wheelDeltaX == window.expectedScrollLeft*-120);
+ consoleDiv.innerHTML += "<br>"
+
+ var expectedScroll = e.wheelDeltaY?window.expectedScrollTop:window.expectedScrollLeft;
+ consoleDiv.innerHTML += "wheelDelta=" + e.wheelDelta + " (should be " + expectedScroll*-120 + "): ";
+ consoleDiv.innerHTML += passFailString(e.wheelDelta == expectedScroll*-120);
+ consoleDiv.innerHTML += "<br>"
+ }
+ }
+ </script>
+</head>
+
+<body style="margin:0" onload="setTimeout('dispatchWheelEvent();', 100)">
+ <div id="overflow" style="border:2px solid black;overflow:auto;height:200px;width:200px;">
+ <div style="background-color:red;height:200px;width:400px;"></div>
+ <div style="background-color:green;height:200px;width:400px;"></div>
+ <div style="background-color:red;height:200px;width:400px;"></div>
+ </div>
+ <div id="offsetConsole"><span style="color:red">FAIL</span></div>
+ <div id="mousewheelConsole"><span style="color:red">FAIL</span></div>
+</body>
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 44a4131..45e5e43 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,48 @@
+2010-03-02 Andy Estes <aestes at apple.com>
+
+ Reviewed by Maciej Stachowiak.
+
+ Add the capability to create and dispatch a WheelEvent in JavaScript.
+ Ensure the event's default handler is triggered in the same way as it is
+ during a PlatformWheelEvent.
+
+ https://bugs.webkit.org/show_bug.cgi?id=35566
+
+ Test: fast/events/wheelevent-in-scrolling-div.html
+
+ * dom/Node.cpp: Ensure that the default behavior (scrolling) occurs for
+ wheel events originating both from the platform and from
+ JavaScript/ObjC.
+ (WebCore::Node::dispatchWheelEvent): Instantiate new WheelEvent with
+ the graunularity of the PlatformWheelEvent.
+ (WebCore::Node::defaultEventHandler): Add support for mousewheel events.
+ * dom/WheelEvent.cpp: Add three new member variables: m_deltaX, m_deltaY
+ and m_granularity. m_deltaX and m_deltaY differ from m_wheelDeltaX and
+ m_wheelDeltaY, which are the number of wheel ticks multiplied by 120 for
+ IE compatibility.
+ (WebCore::WheelEvent::WheelEvent): Initialize new member variables.
+ (WebCore::WheelEvent::initWheelEvent): Same.
+ (WebCore::WheelEvent::initWebKitWheelEvent): Same.
+ * dom/WheelEvent.h: See WheelEvent.cpp.
+ (WebCore::WheelEvent::): Add Granularity enum (Pixel, Line, Page).
+ (WebCore::WheelEvent::create): Add new arguments.
+ (WebCore::WheelEvent::deltaX): Amount of scroll in x direction.
+ (WebCore::WheelEvent::deltaY): Amount of scroll in y direction.
+ (WebCore::WheelEvent::granularity): Units of deltaX and deltaY.
+ * dom/WheelEvent.idl: Add initWebKitWheelEvent() to JavaScript. This is
+ the same as the initWheelEvent ObjC method. As the DOM Level 3 Events
+ specification is still a working draft and subject to change, prefix
+ 'WebKit' to the method signature to indicate experimental support.
+ * page/EventHandler.cpp: Move the scroll handling from
+ handleWheelEvent() to defaultWheelEventHandler(), which is executed on
+ both PlatformWheelEvents and JavaScript WheelEvents.
+ (WebCore::scrollNode): Renamed from scrollAndAcceptEvent(). Remove
+ the PlatformWheelEvent from the argument list and instead return a
+ boolean indicating if the scroll event was accepted.
+ (WebCore::EventHandler::handleWheelEvent): Move scrolling code from here
+ (WebCore::EventHandler::defaultWheelEventHandler): ...to here.
+ * page/EventHandler.h: Add function signature.
+
2010-03-02 Mark Rowe <mrowe at apple.com>
Reviewed by Darin Adler.
diff --git a/WebCore/dom/Node.cpp b/WebCore/dom/Node.cpp
index b897177..59cdddc 100644
--- a/WebCore/dom/Node.cpp
+++ b/WebCore/dom/Node.cpp
@@ -2,7 +2,7 @@
* Copyright (C) 1999 Lars Knoll (knoll at kde.org)
* (C) 1999 Antti Koivisto (koivisto at kde.org)
* (C) 2001 Dirk Mueller (mueller at kde.org)
- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
* Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
* Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
*
@@ -2902,14 +2902,27 @@ void Node::dispatchWheelEvent(PlatformWheelEvent& e)
}
}
- RefPtr<WheelEvent> we = WheelEvent::create(e.wheelTicksX(), e.wheelTicksY(),
+ WheelEvent::Granularity granularity;
+ switch (e.granularity()) {
+ case ScrollByPageWheelEvent:
+ granularity = WheelEvent::Page;
+ break;
+ case ScrollByPixelWheelEvent:
+ default:
+ granularity = WheelEvent::Pixel;
+ break;
+ }
+
+ RefPtr<WheelEvent> we = WheelEvent::create(e.wheelTicksX(), e.wheelTicksY(), e.deltaX(), e.deltaY(), granularity,
document()->defaultView(), e.globalX(), e.globalY(), adjustedPageX, adjustedPageY,
e.ctrlKey(), e.altKey(), e.shiftKey(), e.metaKey());
we->setAbsoluteLocation(IntPoint(pos.x(), pos.y()));
- if (!dispatchEvent(we.release()))
+ if (!dispatchEvent(we) || we->defaultHandled())
e.accept();
+
+ we.release();
}
void Node::dispatchFocusEvent()
@@ -2966,6 +2979,18 @@ void Node::defaultEventHandler(Event* event)
}
}
#endif
+ } else if (eventType == eventNames().mousewheelEvent && event->isWheelEvent()) {
+ WheelEvent* wheelEvent = static_cast<WheelEvent*>(event);
+
+ // If we don't have a renderer, send the wheel event to the first node we find with a renderer.
+ // This is needed for <option> and <optgroup> elements so that <select>s get a wheel scroll.
+ Node* startNode = this;
+ while (startNode && !startNode->renderer())
+ startNode = startNode->parent();
+
+ if (startNode && startNode->renderer())
+ if (Frame* frame = document()->frame())
+ frame->eventHandler()->defaultWheelEventHandler(startNode, wheelEvent);
}
}
diff --git a/WebCore/dom/WheelEvent.cpp b/WebCore/dom/WheelEvent.cpp
index 2039541..0981a57 100644
--- a/WebCore/dom/WheelEvent.cpp
+++ b/WebCore/dom/WheelEvent.cpp
@@ -2,7 +2,7 @@
* Copyright (C) 2001 Peter Kelly (pmk at post.com)
* Copyright (C) 2001 Tobias Anton (anton at stud.fbi.fh-darmstadt.de)
* Copyright (C) 2006 Samuel Weinig (sam.weinig at gmail.com)
- * Copyright (C) 2003, 2005, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2003, 2005, 2006, 2008, 2010 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -31,21 +31,28 @@ namespace WebCore {
WheelEvent::WheelEvent()
: m_wheelDeltaX(0)
, m_wheelDeltaY(0)
+ , m_rawDeltaX(0)
+ , m_rawDeltaY(0)
+ , m_granularity(Pixel)
{
}
-WheelEvent::WheelEvent(float wheelTicksX, float wheelTicksY, PassRefPtr<AbstractView> view,
+WheelEvent::WheelEvent(float wheelTicksX, float wheelTicksY, float rawDeltaX, float rawDeltaY,
+ Granularity granularity, PassRefPtr<AbstractView> view,
int screenX, int screenY, int pageX, int pageY,
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
: MouseRelatedEvent(eventNames().mousewheelEvent,
- true, true, view, 0, screenX, screenY, pageX, pageY,
+ true, true, view, 0, screenX, screenY, pageX, pageY,
ctrlKey, altKey, shiftKey, metaKey)
, m_wheelDeltaX(lroundf(wheelTicksX * 120))
, m_wheelDeltaY(lroundf(wheelTicksY * 120)) // Normalize to the Windows 120 multiple
+ , m_rawDeltaX(rawDeltaX)
+ , m_rawDeltaY(rawDeltaY)
+ , m_granularity(granularity)
{
}
-void WheelEvent::initWheelEvent(int wheelDeltaX, int wheelDeltaY, PassRefPtr<AbstractView> view,
+void WheelEvent::initWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtr<AbstractView> view,
int screenX, int screenY, int pageX, int pageY,
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
{
@@ -60,12 +67,25 @@ void WheelEvent::initWheelEvent(int wheelDeltaX, int wheelDeltaY, PassRefPtr<Abs
m_altKey = altKey;
m_shiftKey = shiftKey;
m_metaKey = metaKey;
- m_wheelDeltaX = wheelDeltaX;
- m_wheelDeltaY = wheelDeltaY;
+
+ // Normalize to the Windows 120 multiple
+ m_wheelDeltaX = rawDeltaX * 120;
+ m_wheelDeltaY = rawDeltaY * 120;
+
+ m_rawDeltaX = rawDeltaX;
+ m_rawDeltaY = rawDeltaY;
+ m_granularity = Pixel;
initCoordinates(pageX, pageY);
}
+void WheelEvent::initWebKitWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtr<AbstractView> view,
+ int screenX, int screenY, int pageX, int pageY,
+ bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
+{
+ initWheelEvent(rawDeltaX, rawDeltaY, view, screenX, screenY, pageX, pageY,
+ ctrlKey, altKey, shiftKey, metaKey);
+}
bool WheelEvent::isWheelEvent() const
{
diff --git a/WebCore/dom/WheelEvent.h b/WebCore/dom/WheelEvent.h
index 04d5421..b085e86 100644
--- a/WebCore/dom/WheelEvent.h
+++ b/WebCore/dom/WheelEvent.h
@@ -2,7 +2,7 @@
* Copyright (C) 2001 Peter Kelly (pmk at post.com)
* Copyright (C) 2001 Tobias Anton (anton at stud.fbi.fh-darmstadt.de)
* Copyright (C) 2006 Samuel Weinig (sam.weinig at gmail.com)
- * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2010 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -31,39 +31,55 @@ namespace WebCore {
// extension: mouse wheel event
class WheelEvent : public MouseRelatedEvent {
public:
+ enum Granularity { Pixel, Line, Page };
+
static PassRefPtr<WheelEvent> create()
{
return adoptRef(new WheelEvent);
}
- static PassRefPtr<WheelEvent> create(float wheelTicksX, float wheelTicksY, PassRefPtr<AbstractView> view,
+ static PassRefPtr<WheelEvent> create(float wheelTicksX, float wheelTicksY,
+ float rawDeltaX, float rawDeltaY, Granularity granularity, PassRefPtr<AbstractView> view,
int screenX, int screenY, int pageX, int pageY,
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
{
- return adoptRef(new WheelEvent(wheelTicksX, wheelTicksY, view, screenX, screenY, pageX, pageY,
+ return adoptRef(new WheelEvent(wheelTicksX, wheelTicksY, rawDeltaX, rawDeltaY,
+ granularity, view, screenX, screenY, pageX, pageY,
ctrlKey, altKey, shiftKey, metaKey));
}
- void initWheelEvent(int wheelDeltaX, int wheelDeltaY, PassRefPtr<AbstractView>,
+ void initWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtr<AbstractView>,
int screenX, int screenY, int pageX, int pageY,
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey);
+ void initWebKitWheelEvent(int rawDeltaX, int rawDeltaY, PassRefPtr<AbstractView>,
+ int screenX, int screenY, int pageX, int pageY,
+ bool ctrlKey, bool altKey, bool shiftKey, bool metaKey);
+
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; }
+ int rawDeltaX() const { return m_rawDeltaX; }
+ int rawDeltaY() const { return m_rawDeltaY; }
+ Granularity granularity() const { return m_granularity; }
// Needed for Objective-C legacy support
bool isHorizontal() const { return m_wheelDeltaX; }
private:
WheelEvent();
- WheelEvent(float wheelTicksX, float wheelTicksY, PassRefPtr<AbstractView>,
+ WheelEvent(float wheelTicksX, float wheelTicksY, float rawDeltaX, float rawDeltaY,
+ Granularity granularity, PassRefPtr<AbstractView>,
int screenX, int screenY, int pageX, int pageY,
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey);
virtual bool isWheelEvent() const;
-
+
int m_wheelDeltaX;
int m_wheelDeltaY;
+
+ int m_rawDeltaX;
+ int m_rawDeltaY;
+ Granularity m_granularity;
};
} // namespace WebCore
diff --git a/WebCore/dom/WheelEvent.idl b/WebCore/dom/WheelEvent.idl
index a8481a0..4c709ce 100644
--- a/WebCore/dom/WheelEvent.idl
+++ b/WebCore/dom/WheelEvent.idl
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2010 Apple Inc. All rights reserved.
* Copyright (C) 2006 Samuel Weinig <sam.weinig at gmail.com>
*
* This library is free software; you can redistribute it and/or
@@ -57,6 +57,19 @@ module events {
in boolean shiftKey,
in boolean metaKey);
#endif /* !defined(LANGUAGE_JAVASCRIPT) */
- };
+#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
+ void initWebKitWheelEvent(in long wheelDeltaX,
+ in long wheelDeltaY,
+ in DOMWindow view,
+ in long screenX,
+ in long screenY,
+ in long clientX,
+ in long clientY,
+ in boolean ctrlKey,
+ in boolean altKey,
+ in boolean shiftKey,
+ in boolean metaKey);
+#endif /* defined(LANGUAGE_JAVASCRIPT) */
+ };
}
diff --git a/WebCore/page/EventHandler.cpp b/WebCore/page/EventHandler.cpp
index 93fc5bd..d8208a5 100644
--- a/WebCore/page/EventHandler.cpp
+++ b/WebCore/page/EventHandler.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
* Copyright (C) 2006 Alexey Proskuryakov (ap at webkit.org)
*
* Redistribution and use in source and binary forms, with or without
@@ -65,6 +65,7 @@
#include "SelectionController.h"
#include "Settings.h"
#include "TextEvent.h"
+#include "WheelEvent.h"
#include "htmlediting.h" // for comparePositions()
#include <wtf/StdLibExtras.h>
@@ -107,23 +108,26 @@ const double autoscrollInterval = 0.05;
static Frame* subframeForHitTestResult(const MouseEventWithHitTestResults&);
-static inline void scrollAndAcceptEvent(float delta, ScrollDirection positiveDirection, ScrollDirection negativeDirection, PlatformWheelEvent& e, Node* node, Node** stopNode)
+static inline bool scrollNode(float delta, WheelEvent::Granularity granularity, ScrollDirection positiveDirection, ScrollDirection negativeDirection, Node* node, Node** stopNode)
{
if (!delta)
- return;
-
+ return false;
+
// Find the nearest enclosing box.
RenderBox* enclosingBox = node->renderer()->enclosingBox();
- if (e.granularity() == ScrollByPageWheelEvent) {
- if (enclosingBox->scroll(delta < 0 ? negativeDirection : positiveDirection, ScrollByPage, 1, stopNode))
- e.accept();
- return;
- }
+ float absDelta = delta > 0 ? delta : -delta;
+
+ if (granularity == WheelEvent::Page)
+ return enclosingBox->scroll(delta < 0 ? negativeDirection : positiveDirection, ScrollByPage, absDelta, stopNode);
+
+ if (granularity == WheelEvent::Line)
+ return enclosingBox->scroll(delta < 0 ? negativeDirection : positiveDirection, ScrollByLine, absDelta, stopNode);
- float pixelsToScroll = delta > 0 ? delta : -delta;
- if (enclosingBox->scroll(delta < 0 ? negativeDirection : positiveDirection, ScrollByPixel, pixelsToScroll, stopNode))
- e.accept();
+ if (granularity == WheelEvent::Pixel)
+ return enclosingBox->scroll(delta < 0 ? negativeDirection : positiveDirection, ScrollByPixel, absDelta, stopNode);
+
+ return false;
}
#if !PLATFORM(MAC) || ENABLE(EXPERIMENTAL_SINGLE_VIEW_MODE)
@@ -1865,21 +1869,6 @@ bool EventHandler::handleWheelEvent(PlatformWheelEvent& e)
node->dispatchWheelEvent(e);
if (e.isAccepted())
return true;
-
- // If we don't have a renderer, send the wheel event to the first node we find with a renderer.
- // This is needed for <option> and <optgroup> elements so that <select>s get a wheel scroll.
- while (node && !node->renderer())
- node = node->parent();
-
- if (node && node->renderer()) {
- // 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).
- Node* stopNode = m_previousWheelScrolledNode.get();
- scrollAndAcceptEvent(e.deltaX(), ScrollLeft, ScrollRight, e, node, &stopNode);
- scrollAndAcceptEvent(e.deltaY(), ScrollUp, ScrollDown, e, node, &stopNode);
- if (!m_useLatchedWheelEventNode)
- m_previousWheelScrolledNode = stopNode;
- }
}
if (e.isAccepted())
@@ -1892,6 +1881,25 @@ bool EventHandler::handleWheelEvent(PlatformWheelEvent& e)
view->wheelEvent(e);
return e.isAccepted();
}
+
+void EventHandler::defaultWheelEventHandler(Node* startNode, WheelEvent* wheelEvent)
+{
+ if (!startNode || !wheelEvent)
+ return;
+
+ Node* stopNode = m_previousWheelScrolledNode.get();
+
+ // 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 (scrollNode(wheelEvent->rawDeltaX(), wheelEvent->granularity(), ScrollLeft, ScrollRight, startNode, &stopNode))
+ wheelEvent->setDefaultHandled();
+
+ if (scrollNode(wheelEvent->rawDeltaY(), wheelEvent->granularity(), ScrollUp, ScrollDown, startNode, &stopNode))
+ wheelEvent->setDefaultHandled();
+
+ if (!m_useLatchedWheelEventNode)
+ m_previousWheelScrolledNode = stopNode;
+}
#if ENABLE(CONTEXT_MENUS)
bool EventHandler::sendContextMenuEvent(const PlatformMouseEvent& event)
diff --git a/WebCore/page/EventHandler.h b/WebCore/page/EventHandler.h
index a268adb..2a29a17 100644
--- a/WebCore/page/EventHandler.h
+++ b/WebCore/page/EventHandler.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2009, 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -67,6 +67,7 @@ class String;
class SVGElementInstance;
class TextEvent;
class TouchEvent;
+class WheelEvent;
class Widget;
#if ENABLE(DRAG_SUPPORT)
@@ -146,6 +147,7 @@ public:
bool handleMouseMoveEvent(const PlatformMouseEvent&, HitTestResult* hoveredNode = 0);
bool handleMouseReleaseEvent(const PlatformMouseEvent&);
bool handleWheelEvent(PlatformWheelEvent&);
+ void defaultWheelEventHandler(Node*, WheelEvent*);
#if ENABLE(CONTEXT_MENUS)
bool sendContextMenuEvent(const PlatformMouseEvent&);
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list