Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
WebCore: Add the capability to create and dispatch a WheelEvent in Ja…
…vaScript. Ensure the event's default handler is triggered in the same way as it is during a PlatformWheelEvent. Patch by Andy Estes <aestes@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@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. Canonical link: https://commits.webkit.org/46737@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@55436 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
10 changed files
with
274 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.