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

Side by Side Diff: Source/core/dom/Node.cpp

Issue 237963014: Track scroll event handlers in nested documents (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Discard handlers in detached docs. Moar tests. Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 24 matching lines...) Expand all
35 #include "core/dom/ChildListMutationScope.h" 35 #include "core/dom/ChildListMutationScope.h"
36 #include "core/dom/ChildNodeList.h" 36 #include "core/dom/ChildNodeList.h"
37 #include "core/dom/DOMImplementation.h" 37 #include "core/dom/DOMImplementation.h"
38 #include "core/dom/Document.h" 38 #include "core/dom/Document.h"
39 #include "core/dom/DocumentFragment.h" 39 #include "core/dom/DocumentFragment.h"
40 #include "core/dom/DocumentMarkerController.h" 40 #include "core/dom/DocumentMarkerController.h"
41 #include "core/dom/DocumentType.h" 41 #include "core/dom/DocumentType.h"
42 #include "core/dom/Element.h" 42 #include "core/dom/Element.h"
43 #include "core/dom/ElementRareData.h" 43 #include "core/dom/ElementRareData.h"
44 #include "core/dom/ElementTraversal.h" 44 #include "core/dom/ElementTraversal.h"
45 #include "core/dom/EventHandlerRegistry.h"
46 #include "core/dom/ExceptionCode.h" 45 #include "core/dom/ExceptionCode.h"
47 #include "core/dom/LiveNodeList.h" 46 #include "core/dom/LiveNodeList.h"
48 #include "core/dom/NodeRareData.h" 47 #include "core/dom/NodeRareData.h"
49 #include "core/dom/NodeRenderingTraversal.h" 48 #include "core/dom/NodeRenderingTraversal.h"
50 #include "core/dom/NodeTraversal.h" 49 #include "core/dom/NodeTraversal.h"
51 #include "core/dom/ProcessingInstruction.h" 50 #include "core/dom/ProcessingInstruction.h"
52 #include "core/dom/Range.h" 51 #include "core/dom/Range.h"
53 #include "core/dom/StaticNodeList.h" 52 #include "core/dom/StaticNodeList.h"
54 #include "core/dom/TemplateContentDocumentFragment.h" 53 #include "core/dom/TemplateContentDocumentFragment.h"
55 #include "core/dom/Text.h" 54 #include "core/dom/Text.h"
(...skipping 18 matching lines...) Expand all
74 #include "core/events/TouchEvent.h" 73 #include "core/events/TouchEvent.h"
75 #include "core/events/UIEvent.h" 74 #include "core/events/UIEvent.h"
76 #include "core/events/WheelEvent.h" 75 #include "core/events/WheelEvent.h"
77 #include "core/frame/LocalFrame.h" 76 #include "core/frame/LocalFrame.h"
78 #include "core/html/HTMLAnchorElement.h" 77 #include "core/html/HTMLAnchorElement.h"
79 #include "core/html/HTMLDialogElement.h" 78 #include "core/html/HTMLDialogElement.h"
80 #include "core/html/HTMLFrameOwnerElement.h" 79 #include "core/html/HTMLFrameOwnerElement.h"
81 #include "core/html/HTMLStyleElement.h" 80 #include "core/html/HTMLStyleElement.h"
82 #include "core/page/ContextMenuController.h" 81 #include "core/page/ContextMenuController.h"
83 #include "core/page/EventHandler.h" 82 #include "core/page/EventHandler.h"
83 #include "core/page/EventHandlerRegistry.h"
84 #include "core/page/Page.h" 84 #include "core/page/Page.h"
85 #include "core/frame/Settings.h" 85 #include "core/frame/Settings.h"
86 #include "core/rendering/FlowThreadController.h" 86 #include "core/rendering/FlowThreadController.h"
87 #include "core/rendering/RenderBox.h" 87 #include "core/rendering/RenderBox.h"
88 #include "core/svg/graphics/SVGImage.h" 88 #include "core/svg/graphics/SVGImage.h"
89 #include "platform/Partitions.h" 89 #include "platform/Partitions.h"
90 #include "platform/TraceEvent.h" 90 #include "platform/TraceEvent.h"
91 #include "platform/TracedValue.h" 91 #include "platform/TracedValue.h"
92 #include "wtf/HashSet.h" 92 #include "wtf/HashSet.h"
93 #include "wtf/PassOwnPtr.h" 93 #include "wtf/PassOwnPtr.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 void Node::willBeDeletedFromDocument() 291 void Node::willBeDeletedFromDocument()
292 { 292 {
293 if (!isTreeScopeInitialized()) 293 if (!isTreeScopeInitialized())
294 return; 294 return;
295 295
296 Document& document = this->document(); 296 Document& document = this->document();
297 297
298 if (hasEventTargetData()) { 298 if (hasEventTargetData()) {
299 clearEventTargetData(); 299 clearEventTargetData();
300 document.didClearTouchEventHandlers(this); 300 document.didClearTouchEventHandlers(this);
301 EventHandlerRegistry::from(document)->didRemoveAllEventHandlers(*this); 301 if (document.page())
302 EventHandlerRegistry::from(*document.page())->didRemoveAllEventHandl ers(*this);
302 } 303 }
303 304
304 if (AXObjectCache* cache = document.existingAXObjectCache()) 305 if (AXObjectCache* cache = document.existingAXObjectCache())
305 cache->remove(this); 306 cache->remove(this);
306 307
307 document.markers().removeMarkers(this); 308 document.markers().removeMarkers(this);
308 } 309 }
309 310
310 NodeRareData* Node::rareData() const 311 NodeRareData* Node::rareData() const
311 { 312 {
(...skipping 1635 matching lines...) Expand 10 before | Expand all | Expand 10 after
1947 oldController->didRemoveWheelEventHandler(oldDocument); 1948 oldController->didRemoveWheelEventHandler(oldDocument);
1948 newController->didAddWheelEventHandler(document()); 1949 newController->didAddWheelEventHandler(document());
1949 } 1950 }
1950 1951
1951 if (const TouchEventTargetSet* touchHandlers = oldDocument.touchEventTargets ()) { 1952 if (const TouchEventTargetSet* touchHandlers = oldDocument.touchEventTargets ()) {
1952 while (touchHandlers->contains(this)) { 1953 while (touchHandlers->contains(this)) {
1953 oldDocument.didRemoveTouchEventHandler(this); 1954 oldDocument.didRemoveTouchEventHandler(this);
1954 document().didAddTouchEventHandler(this); 1955 document().didAddTouchEventHandler(this);
1955 } 1956 }
1956 } 1957 }
1957 EventHandlerRegistry::from(document())->didMoveFromOtherDocument(*this, oldD ocument); 1958 if (oldDocument.page() != document().page()) {
1959 if (oldDocument.page())
1960 EventHandlerRegistry::from(*oldDocument.page())->didMoveOutOfPage(*t his);
1961 if (document().page())
1962 EventHandlerRegistry::from(*document().page())->didMoveIntoPage(*thi s);
1963 }
1958 1964
1959 if (WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* reg istry = mutationObserverRegistry()) { 1965 if (WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> >* reg istry = mutationObserverRegistry()) {
1960 for (size_t i = 0; i < registry->size(); ++i) { 1966 for (size_t i = 0; i < registry->size(); ++i) {
1961 document().addMutationObserverTypes(registry->at(i)->mutationTypes() ); 1967 document().addMutationObserverTypes(registry->at(i)->mutationTypes() );
1962 } 1968 }
1963 } 1969 }
1964 1970
1965 if (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >* tr ansientRegistry = transientMutationObserverRegistry()) { 1971 if (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >* tr ansientRegistry = transientMutationObserverRegistry()) {
1966 for (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >::iterator iter = transientRegistry->begin(); iter != transientRegistry->end(); ++iter) { 1972 for (WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> >::iterator iter = transientRegistry->begin(); iter != transientRegistry->end(); ++iter) {
1967 document().addMutationObserverTypes((*iter)->mutationTypes()); 1973 document().addMutationObserverTypes((*iter)->mutationTypes());
1968 } 1974 }
1969 } 1975 }
1970 } 1976 }
1971 1977
1972 static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve ntType, PassRefPtr<EventListener> listener, bool useCapture) 1978 static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve ntType, PassRefPtr<EventListener> listener, bool useCapture)
1973 { 1979 {
1974 if (!targetNode->EventTarget::addEventListener(eventType, listener, useCaptu re)) 1980 if (!targetNode->EventTarget::addEventListener(eventType, listener, useCaptu re))
1975 return false; 1981 return false;
1976 1982
1977 Document& document = targetNode->document(); 1983 Document& document = targetNode->document();
1978 document.addListenerTypeIfNeeded(eventType); 1984 document.addListenerTypeIfNeeded(eventType);
1979 if (eventType == EventTypeNames::wheel || eventType == EventTypeNames::mouse wheel) 1985 if (eventType == EventTypeNames::wheel || eventType == EventTypeNames::mouse wheel)
1980 WheelController::from(document)->didAddWheelEventHandler(document); 1986 WheelController::from(document)->didAddWheelEventHandler(document);
1981 else if (isTouchEventType(eventType)) 1987 else if (isTouchEventType(eventType))
1982 document.didAddTouchEventHandler(targetNode); 1988 document.didAddTouchEventHandler(targetNode);
1983 EventHandlerRegistry::from(document)->didAddEventHandler(*targetNode, eventT ype); 1989 if (document.page())
1990 EventHandlerRegistry::from(*document.page())->didAddEventHandler(*target Node, eventType);
1984 1991
1985 return true; 1992 return true;
1986 } 1993 }
1987 1994
1988 bool Node::addEventListener(const AtomicString& eventType, PassRefPtr<EventListe ner> listener, bool useCapture) 1995 bool Node::addEventListener(const AtomicString& eventType, PassRefPtr<EventListe ner> listener, bool useCapture)
1989 { 1996 {
1990 return tryAddEventListener(this, eventType, listener, useCapture); 1997 return tryAddEventListener(this, eventType, listener, useCapture);
1991 } 1998 }
1992 1999
1993 static inline bool tryRemoveEventListener(Node* targetNode, const AtomicString& eventType, EventListener* listener, bool useCapture) 2000 static inline bool tryRemoveEventListener(Node* targetNode, const AtomicString& eventType, EventListener* listener, bool useCapture)
1994 { 2001 {
1995 if (!targetNode->EventTarget::removeEventListener(eventType, listener, useCa pture)) 2002 if (!targetNode->EventTarget::removeEventListener(eventType, listener, useCa pture))
1996 return false; 2003 return false;
1997 2004
1998 // FIXME: Notify Document that the listener has vanished. We need to keep tr ack of a number of 2005 // FIXME: Notify Document that the listener has vanished. We need to keep tr ack of a number of
1999 // listeners for each type, not just a bool - see https://bugs.webkit.org/sh ow_bug.cgi?id=33861 2006 // listeners for each type, not just a bool - see https://bugs.webkit.org/sh ow_bug.cgi?id=33861
2000 Document& document = targetNode->document(); 2007 Document& document = targetNode->document();
2001 if (eventType == EventTypeNames::wheel || eventType == EventTypeNames::mouse wheel) 2008 if (eventType == EventTypeNames::wheel || eventType == EventTypeNames::mouse wheel)
2002 WheelController::from(document)->didRemoveWheelEventHandler(document); 2009 WheelController::from(document)->didRemoveWheelEventHandler(document);
2003 else if (isTouchEventType(eventType)) 2010 else if (isTouchEventType(eventType))
2004 document.didRemoveTouchEventHandler(targetNode); 2011 document.didRemoveTouchEventHandler(targetNode);
2005 EventHandlerRegistry::from(document)->didRemoveEventHandler(*targetNode, eve ntType); 2012 if (document.page())
2013 EventHandlerRegistry::from(*document.page())->didRemoveEventHandler(*tar getNode, eventType);
2006 2014
2007 return true; 2015 return true;
2008 } 2016 }
2009 2017
2010 bool Node::removeEventListener(const AtomicString& eventType, EventListener* lis tener, bool useCapture) 2018 bool Node::removeEventListener(const AtomicString& eventType, EventListener* lis tener, bool useCapture)
2011 { 2019 {
2012 return tryRemoveEventListener(this, eventType, listener, useCapture); 2020 return tryRemoveEventListener(this, eventType, listener, useCapture);
2013 } 2021 }
2014 2022
2015 void Node::removeAllEventListeners() 2023 void Node::removeAllEventListeners()
2016 { 2024 {
2017 if (hasEventListeners()) 2025 if (hasEventListeners() && document().page())
2018 EventHandlerRegistry::from(document())->didRemoveAllEventHandlers(*this) ; 2026 EventHandlerRegistry::from(*document().page())->didRemoveAllEventHandler s(*this);
2019 EventTarget::removeAllEventListeners(); 2027 EventTarget::removeAllEventListeners();
2020 document().didClearTouchEventHandlers(this); 2028 document().didClearTouchEventHandlers(this);
2021 } 2029 }
2022 2030
2023 void Node::removeAllEventListenersRecursively() 2031 void Node::removeAllEventListenersRecursively()
2024 { 2032 {
2025 for (Node* node = this; node; node = NodeTraversal::next(*node)) { 2033 for (Node* node = this; node; node = NodeTraversal::next(*node)) {
2026 node->removeAllEventListeners(); 2034 node->removeAllEventListeners();
2027 for (ShadowRoot* root = node->youngestShadowRoot(); root; root = root->o lderShadowRoot()) 2035 for (ShadowRoot* root = node->youngestShadowRoot(); root; root = root->o lderShadowRoot())
2028 root->removeAllEventListenersRecursively(); 2036 root->removeAllEventListenersRecursively();
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
2558 node->showTreeForThis(); 2566 node->showTreeForThis();
2559 } 2567 }
2560 2568
2561 void showNodePath(const WebCore::Node* node) 2569 void showNodePath(const WebCore::Node* node)
2562 { 2570 {
2563 if (node) 2571 if (node)
2564 node->showNodePathForThis(); 2572 node->showNodePathForThis();
2565 } 2573 }
2566 2574
2567 #endif 2575 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698