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

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

Issue 18836002: Implement 'mouseenter' and 'mouseleave' from DOM Level 3 Events. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Attribute tests. Created 7 years, 5 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/dom/Document.idl » ('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 4282042f7853697cb2c5e9395eff38e1263c3fa7..699eb28d7ac78bf0d1e56c9dda795afee1b3b4df 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -2790,7 +2790,7 @@ MouseEventWithHitTestResults Document::prepareMouseEvent(const HitTestRequest& r
renderView()->hitTest(request, result);
if (!request.readOnly())
- updateHoverActiveState(request, result.innerElement());
+ updateHoverActiveState(request, result.innerElement(), &event);
return MouseEventWithHitTestResults(event, result);
}
@@ -4847,13 +4847,13 @@ static RenderObject* nearestCommonHoverAncestor(RenderObject* obj1, RenderObject
return 0;
}
-void Document::updateHoverActiveState(const HitTestRequest& request, Element* innerElement)
+void Document::updateHoverActiveState(const HitTestRequest& request, Element* innerElement, const PlatformMouseEvent* event)
{
ASSERT(!request.readOnly());
Element* innerElementInDocument = innerElement;
while (innerElementInDocument && innerElementInDocument->document() != this) {
- innerElementInDocument->document()->updateHoverActiveState(request, innerElementInDocument);
+ innerElementInDocument->document()->updateHoverActiveState(request, innerElementInDocument, event);
innerElementInDocument = innerElementInDocument->document()->ownerElement();
}
@@ -4941,9 +4941,38 @@ 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(eventNames().mouseleaveEvent)) {
+ ancestorHasCapturingMouseleaveListener = true;
+ break;
+ }
+ }
+ }
+
size_t removeCount = nodesToRemoveFromChain.size();
- for (size_t i = 0; i < removeCount; ++i)
+ for (size_t i = 0; i < removeCount; ++i) {
nodesToRemoveFromChain[i]->setHovered(false);
+ if (event && (ancestorHasCapturingMouseleaveListener || nodesToRemoveFromChain[i]->hasEventListeners(eventNames().mouseleaveEvent)))
+ nodesToRemoveFromChain[i]->dispatchMouseEvent(*event, eventNames().mouseleaveEvent, 0, newHoverNode);
+ }
+
+ bool ancestorHasCapturingMouseenterListener = false;
+ if (event && newHoverNode != oldHoverNode.get()) {
+ for (Node* node = newHoverNode; node; node = node->parentOrShadowHostNode()) {
+ if (node->hasCapturingEventListeners(eventNames().mouseenterEvent)) {
+ ancestorHasCapturingMouseenterListener = true;
+ break;
+ }
+ }
+ }
bool sawCommonAncestor = false;
size_t addCount = nodesToAddToChain.size();
@@ -4953,8 +4982,11 @@ void Document::updateHoverActiveState(const HitTestRequest& request, Element* in
sawCommonAncestor = true;
if (allowActiveChanges)
nodesToAddToChain[i]->setActive(true);
- if (!sawCommonAncestor)
+ if (!sawCommonAncestor) {
nodesToAddToChain[i]->setHovered(true);
+ if (event && (ancestorHasCapturingMouseenterListener || nodesToAddToChain[i]->hasEventListeners(eventNames().mouseenterEvent)))
+ nodesToAddToChain[i]->dispatchMouseEvent(*event, eventNames().mouseenterEvent, 0, oldHoverNode.get());
+ }
}
updateStyleIfNeeded();
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/dom/Document.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698