Skip to content
Permalink
Browse files
WheelEvent should not target text nodes.
https://bugs.webkit.org/show_bug.cgi?id=109939

Reviewed by Darin Adler.

Source/WebCore:

WheelEvent, like other mouse events, should not target text nodes.
EventHandler correctly handles other mouse events by retargeting
events to text nodes' parents; this patch adds that logic to the
WheelEvent handler.

This should allow jQuery to stop working around WebKit's behavior[1].

[1]: jquery/jquery@c611504

Test: fast/events/wheelevent-in-text-node.html

* page/EventHandler.cpp:
(WebCore::EventHandler::handleWheelEvent):
    If a WheelEvent's hit test lands on a text node, retarget the
    event to the text node's parent. Do this before latching the node.

LayoutTests:

* fast/events/wheelevent-in-text-node-expected.txt: Added.
* fast/events/wheelevent-in-text-node.html: Added.


Canonical link: https://commits.webkit.org/128349@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@143148 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
mikewest committed Feb 18, 2013
1 parent c5e2e19 commit 886b44fa3aa343dd0982c3305d395634b72c686a
Showing 5 changed files with 90 additions and 7 deletions.
@@ -1,3 +1,13 @@
2013-02-17 Mike West <mkwst@chromium.org>

WheelEvent should not target text nodes.
https://bugs.webkit.org/show_bug.cgi?id=109939

Reviewed by Darin Adler.

* fast/events/wheelevent-in-text-node-expected.txt: Added.
* fast/events/wheelevent-in-text-node.html: Added.

2013-02-17 Philip Rogers <pdr@google.com>

Fix non-root SVG viewport under zoom
@@ -0,0 +1,6 @@
'Real' MouseWheel events should not be dispatched on the text node, but instead on its parent.
PASS theEvent.target.nodeName is "DIV"
PASS successfullyParsed is true

TEST COMPLETE
This is a div containing text. Wheel events originating on the text node should target the div.
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<script src="../js/resources/js-test-pre.js"></script>
<script>
window.jsTestIsAsync = true;

function test() {
var div = document.querySelector('div');
if (window.eventSender) {
eventSender.mouseMoveTo(div.offsetLeft + 5, div.offsetTop + 5);
eventSender.mouseScrollBy(0,120);
} else {
debug("FAIL: This test requires window.eventSender.");
finishJSTest();
}
}

function wheelHandler(e) {
window.theEvent = e;

debug("'Real' MouseWheel events should not be dispatched on the text node, but instead on its parent.");
shouldBeEqualToString('theEvent.target.nodeName', 'DIV');
finishJSTest();
}

window.onload = function () {
var div = document.querySelector('div');
div.addEventListener('mousewheel', wheelHandler);
test();
};
</script>
<script src="../js/resources/js-test-post.js"></script>
</head>
<body>
<div>This is a div containing text. Wheel events originating on the text
node should target the div.</div>
</body>
</html>
@@ -1,3 +1,26 @@
2013-02-17 Mike West <mkwst@chromium.org>

WheelEvent should not target text nodes.
https://bugs.webkit.org/show_bug.cgi?id=109939

Reviewed by Darin Adler.

WheelEvent, like other mouse events, should not target text nodes.
EventHandler correctly handles other mouse events by retargeting
events to text nodes' parents; this patch adds that logic to the
WheelEvent handler.

This should allow jQuery to stop working around WebKit's behavior[1].

[1]: https://github.com/jquery/jquery/commit/c61150427fc8ccc8e884df8f221a6c9bb5477929

Test: fast/events/wheelevent-in-text-node.html

* page/EventHandler.cpp:
(WebCore::EventHandler::handleWheelEvent):
If a WheelEvent's hit test lands on a text node, retarget the
event to the text node's parent. Do this before latching the node.

2013-02-17 Filip Pizlo <fpizlo@apple.com>

Move all Structure out-of-line inline methods to StructureInlines.h
@@ -2323,30 +2323,35 @@ bool EventHandler::handleWheelEvent(const PlatformWheelEvent& e)
setFrameWasScrolledByUser();
LayoutPoint vPoint = view->windowToContents(e.position());

Node* node;
bool isOverWidget;

HitTestRequest request(HitTestRequest::ReadOnly);
HitTestResult result(vPoint);
doc->renderView()->hitTest(request, result);

bool useLatchedWheelEventNode = e.useLatchedEventNode();

Node* node = result.innerNode();
// Wheel events should not dispatch to text nodes.
if (node && node->isTextNode()) {
AncestorChainWalker walker(node);
walker.parent();
node = walker.get();
}

bool isOverWidget;
if (useLatchedWheelEventNode) {
if (!m_latchedWheelEventNode) {
m_latchedWheelEventNode = result.innerNode();
m_latchedWheelEventNode = node;
m_widgetIsLatched = result.isOverWidget();
}
} else
node = m_latchedWheelEventNode.get();

node = m_latchedWheelEventNode.get();
isOverWidget = m_widgetIsLatched;
} else {
if (m_latchedWheelEventNode)
m_latchedWheelEventNode = 0;
if (m_previousWheelScrolledNode)
m_previousWheelScrolledNode = 0;

node = result.innerNode();
isOverWidget = result.isOverWidget();
}

0 comments on commit 886b44f

Please sign in to comment.