Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(695)

Unified Diff: Source/core/dom/Document.cpp

Issue 1047733002: Fixed mouseenter/mouseleave event firing order. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/page/EventHandler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Document.cpp
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp
index e6dbf1221c14dccf4e0dac19dfa61dbe4d9a3762..f3d75410595b1ce579cdc0d36d027979b93a194f 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -3118,7 +3118,7 @@ MouseEventWithHitTestResults Document::prepareMouseEvent(const HitTestRequest& r
layoutView()->hitTest(request, result);
if (!request.readOnly())
- updateHoverActiveState(request, result.innerElement(), &event);
+ updateHoverActiveState(request, result.innerElement());
return MouseEventWithHitTestResults(event, result);
}
@@ -5239,7 +5239,7 @@ static LayoutObject* nearestCommonHoverAncestor(LayoutObject* obj1, LayoutObject
return 0;
}
-void Document::updateHoverActiveState(const HitTestRequest& request, Element* innerElement, const PlatformMouseEvent* event)
+void Document::updateHoverActiveState(const HitTestRequest& request, Element* innerElement)
{
ASSERT(!request.readOnly());
@@ -5248,7 +5248,7 @@ void Document::updateHoverActiveState(const HitTestRequest& request, Element* in
Element* innerElementInDocument = innerElement;
while (innerElementInDocument && innerElementInDocument->document() != this) {
- innerElementInDocument->document().updateHoverActiveState(request, innerElementInDocument, event);
+ innerElementInDocument->document().updateHoverActiveState(request, innerElementInDocument);
innerElementInDocument = innerElementInDocument->document().ownerElement();
}
@@ -5322,6 +5322,8 @@ void Document::updateHoverActiveState(const HitTestRequest& request, Element* in
if (curr->node() && !curr->isText() && (!mustBeInActiveChain || curr->node()->inActiveChain()))
nodesToRemoveFromChain.append(curr->node());
}
+
+ // TODO(mustaq): The two loops above may push a single node twice into nodesToRemoveFromChain. There must be a better way.
}
// Now set the hover state for our new object up to the root.
@@ -5330,37 +5332,9 @@ void Document::updateHoverActiveState(const HitTestRequest& request, Element* in
nodesToAddToChain.append(curr->node());
}
- // mouseenter and mouseleave events do not bubble, so they are dispatched iff there is a capturing
- // event handler on an ancestor or a normal event handler on the element itself. This special
- // handling is necessary to avoid O(n^2) capturing event handler checks. We'll check the previously
- // hovered node's ancestor tree for 'mouseleave' handlers here, then check the newly hovered node's
- // ancestor tree for 'mouseenter' handlers after dispatching the 'mouseleave' events (as the handler
- // for 'mouseleave' might set a capturing 'mouseenter' handler, odd as that might be).
- bool ancestorHasCapturingMouseleaveListener = false;
- if (event && newHoverNode != oldHoverNode.get()) {
- for (Node* node = oldHoverNode.get(); node; node = node->parentOrShadowHostNode()) {
- if (node->hasCapturingEventListeners(EventTypeNames::mouseleave)) {
- ancestorHasCapturingMouseleaveListener = true;
- break;
- }
- }
- }
-
size_t removeCount = nodesToRemoveFromChain.size();
for (size_t i = 0; i < removeCount; ++i) {
nodesToRemoveFromChain[i]->setHovered(false);
- if (event && (ancestorHasCapturingMouseleaveListener || nodesToRemoveFromChain[i]->hasEventListeners(EventTypeNames::mouseleave)))
- nodesToRemoveFromChain[i]->dispatchMouseEvent(*event, EventTypeNames::mouseleave, 0, newHoverNode);
- }
-
- bool ancestorHasCapturingMouseenterListener = false;
- if (event && newHoverNode != oldHoverNode.get()) {
- for (Node* node = newHoverNode; node; node = node->parentOrShadowHostNode()) {
- if (node->hasCapturingEventListeners(EventTypeNames::mouseenter)) {
- ancestorHasCapturingMouseenterListener = true;
- break;
- }
- }
}
bool sawCommonAncestor = false;
@@ -5373,8 +5347,6 @@ void Document::updateHoverActiveState(const HitTestRequest& request, Element* in
nodesToAddToChain[i]->setActive(true);
if (!sawCommonAncestor) {
nodesToAddToChain[i]->setHovered(true);
- if (event && (ancestorHasCapturingMouseenterListener || nodesToAddToChain[i]->hasEventListeners(EventTypeNames::mouseenter)))
- nodesToAddToChain[i]->dispatchMouseEvent(*event, EventTypeNames::mouseenter, 0, oldHoverNode.get());
}
}
}
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/page/EventHandler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698