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

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

Issue 206603002: Add EventHandlerRegistry (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Just the registry. Created 6 years, 8 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
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"
45 #include "core/dom/ExceptionCode.h" 46 #include "core/dom/ExceptionCode.h"
46 #include "core/dom/LiveNodeList.h" 47 #include "core/dom/LiveNodeList.h"
47 #include "core/dom/NodeRareData.h" 48 #include "core/dom/NodeRareData.h"
48 #include "core/dom/NodeRenderingTraversal.h" 49 #include "core/dom/NodeRenderingTraversal.h"
49 #include "core/dom/NodeTraversal.h" 50 #include "core/dom/NodeTraversal.h"
50 #include "core/dom/ProcessingInstruction.h" 51 #include "core/dom/ProcessingInstruction.h"
51 #include "core/dom/Range.h" 52 #include "core/dom/Range.h"
52 #include "core/dom/StaticNodeList.h" 53 #include "core/dom/StaticNodeList.h"
53 #include "core/dom/TemplateContentDocumentFragment.h" 54 #include "core/dom/TemplateContentDocumentFragment.h"
54 #include "core/dom/Text.h" 55 #include "core/dom/Text.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 void Node::willBeDeletedFromDocument() 285 void Node::willBeDeletedFromDocument()
285 { 286 {
286 if (!isTreeScopeInitialized()) 287 if (!isTreeScopeInitialized())
287 return; 288 return;
288 289
289 Document& document = this->document(); 290 Document& document = this->document();
290 291
291 if (hasEventTargetData()) { 292 if (hasEventTargetData()) {
292 clearEventTargetData(); 293 clearEventTargetData();
293 document.didClearTouchEventHandlers(this); 294 document.didClearTouchEventHandlers(this);
295 EventHandlerRegistry::from(document)->didRemoveAllEventHandlers(*this);
294 } 296 }
295 297
296 if (AXObjectCache* cache = document.existingAXObjectCache()) 298 if (AXObjectCache* cache = document.existingAXObjectCache())
297 cache->remove(this); 299 cache->remove(this);
298 300
299 document.markers().removeMarkers(this); 301 document.markers().removeMarkers(this);
300 } 302 }
301 303
302 NodeRareData* Node::rareData() const 304 NodeRareData* Node::rareData() const
303 { 305 {
(...skipping 1628 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 oldController->didRemoveWheelEventHandler(oldDocument); 1934 oldController->didRemoveWheelEventHandler(oldDocument);
1933 newController->didAddWheelEventHandler(document()); 1935 newController->didAddWheelEventHandler(document());
1934 } 1936 }
1935 1937
1936 if (const TouchEventTargetSet* touchHandlers = oldDocument.touchEventTargets ()) { 1938 if (const TouchEventTargetSet* touchHandlers = oldDocument.touchEventTargets ()) {
1937 while (touchHandlers->contains(this)) { 1939 while (touchHandlers->contains(this)) {
1938 oldDocument.didRemoveTouchEventHandler(this); 1940 oldDocument.didRemoveTouchEventHandler(this);
1939 document().didAddTouchEventHandler(this); 1941 document().didAddTouchEventHandler(this);
1940 } 1942 }
1941 } 1943 }
1944 EventHandlerRegistry::from(document())->didMoveFromOtherDocument(*this, oldD ocument);
1942 1945
1943 if (Vector<OwnPtr<MutationObserverRegistration> >* registry = mutationObserv erRegistry()) { 1946 if (Vector<OwnPtr<MutationObserverRegistration> >* registry = mutationObserv erRegistry()) {
1944 for (size_t i = 0; i < registry->size(); ++i) { 1947 for (size_t i = 0; i < registry->size(); ++i) {
1945 document().addMutationObserverTypes(registry->at(i)->mutationTypes() ); 1948 document().addMutationObserverTypes(registry->at(i)->mutationTypes() );
1946 } 1949 }
1947 } 1950 }
1948 1951
1949 if (HashSet<MutationObserverRegistration*>* transientRegistry = transientMut ationObserverRegistry()) { 1952 if (HashSet<MutationObserverRegistration*>* transientRegistry = transientMut ationObserverRegistry()) {
1950 for (HashSet<MutationObserverRegistration*>::iterator iter = transientRe gistry->begin(); iter != transientRegistry->end(); ++iter) { 1953 for (HashSet<MutationObserverRegistration*>::iterator iter = transientRe gistry->begin(); iter != transientRegistry->end(); ++iter) {
1951 document().addMutationObserverTypes((*iter)->mutationTypes()); 1954 document().addMutationObserverTypes((*iter)->mutationTypes());
1952 } 1955 }
1953 } 1956 }
1954 } 1957 }
1955 1958
1956 static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve ntType, PassRefPtr<EventListener> listener, bool useCapture) 1959 static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve ntType, PassRefPtr<EventListener> listener, bool useCapture)
1957 { 1960 {
1958 if (!targetNode->EventTarget::addEventListener(eventType, listener, useCaptu re)) 1961 if (!targetNode->EventTarget::addEventListener(eventType, listener, useCaptu re))
1959 return false; 1962 return false;
1960 1963
1961 Document& document = targetNode->document(); 1964 Document& document = targetNode->document();
1962 document.addListenerTypeIfNeeded(eventType); 1965 document.addListenerTypeIfNeeded(eventType);
1963 if (eventType == EventTypeNames::wheel || eventType == EventTypeNames::mouse wheel) 1966 if (eventType == EventTypeNames::wheel || eventType == EventTypeNames::mouse wheel)
1964 WheelController::from(document)->didAddWheelEventHandler(document); 1967 WheelController::from(document)->didAddWheelEventHandler(document);
1965 else if (isTouchEventType(eventType)) 1968 else if (isTouchEventType(eventType))
1966 document.didAddTouchEventHandler(targetNode); 1969 document.didAddTouchEventHandler(targetNode);
1970 EventHandlerRegistry::from(document)->didAddEventHandler(*targetNode, eventT ype);
1967 1971
1968 return true; 1972 return true;
1969 } 1973 }
1970 1974
1971 bool Node::addEventListener(const AtomicString& eventType, PassRefPtr<EventListe ner> listener, bool useCapture) 1975 bool Node::addEventListener(const AtomicString& eventType, PassRefPtr<EventListe ner> listener, bool useCapture)
1972 { 1976 {
1973 return tryAddEventListener(this, eventType, listener, useCapture); 1977 return tryAddEventListener(this, eventType, listener, useCapture);
1974 } 1978 }
1975 1979
1976 static inline bool tryRemoveEventListener(Node* targetNode, const AtomicString& eventType, EventListener* listener, bool useCapture) 1980 static inline bool tryRemoveEventListener(Node* targetNode, const AtomicString& eventType, EventListener* listener, bool useCapture)
1977 { 1981 {
1978 if (!targetNode->EventTarget::removeEventListener(eventType, listener, useCa pture)) 1982 if (!targetNode->EventTarget::removeEventListener(eventType, listener, useCa pture))
1979 return false; 1983 return false;
1980 1984
1981 // FIXME: Notify Document that the listener has vanished. We need to keep tr ack of a number of 1985 // FIXME: Notify Document that the listener has vanished. We need to keep tr ack of a number of
1982 // listeners for each type, not just a bool - see https://bugs.webkit.org/sh ow_bug.cgi?id=33861 1986 // listeners for each type, not just a bool - see https://bugs.webkit.org/sh ow_bug.cgi?id=33861
1983 Document& document = targetNode->document(); 1987 Document& document = targetNode->document();
1984 if (eventType == EventTypeNames::wheel || eventType == EventTypeNames::mouse wheel) 1988 if (eventType == EventTypeNames::wheel || eventType == EventTypeNames::mouse wheel)
1985 WheelController::from(document)->didRemoveWheelEventHandler(document); 1989 WheelController::from(document)->didRemoveWheelEventHandler(document);
1986 else if (isTouchEventType(eventType)) 1990 else if (isTouchEventType(eventType))
1987 document.didRemoveTouchEventHandler(targetNode); 1991 document.didRemoveTouchEventHandler(targetNode);
1992 EventHandlerRegistry::from(document)->didRemoveEventHandler(*targetNode, eve ntType);
1988 1993
1989 return true; 1994 return true;
1990 } 1995 }
1991 1996
1992 bool Node::removeEventListener(const AtomicString& eventType, EventListener* lis tener, bool useCapture) 1997 bool Node::removeEventListener(const AtomicString& eventType, EventListener* lis tener, bool useCapture)
1993 { 1998 {
1994 return tryRemoveEventListener(this, eventType, listener, useCapture); 1999 return tryRemoveEventListener(this, eventType, listener, useCapture);
1995 } 2000 }
1996 2001
1997 void Node::removeAllEventListeners() 2002 void Node::removeAllEventListeners()
1998 { 2003 {
1999 EventTarget::removeAllEventListeners(); 2004 EventTarget::removeAllEventListeners();
2000 document().didClearTouchEventHandlers(this); 2005 document().didClearTouchEventHandlers(this);
2006 EventHandlerRegistry::from(document())->didRemoveAllEventHandlers(*this);
2001 } 2007 }
2002 2008
2003 void Node::removeAllEventListenersRecursively() 2009 void Node::removeAllEventListenersRecursively()
2004 { 2010 {
2005 for (Node* node = this; node; node = NodeTraversal::next(*node)) { 2011 for (Node* node = this; node; node = NodeTraversal::next(*node)) {
2006 node->removeAllEventListeners(); 2012 node->removeAllEventListeners();
2007 for (ShadowRoot* root = node->youngestShadowRoot(); root; root = root->o lderShadowRoot()) 2013 for (ShadowRoot* root = node->youngestShadowRoot(); root; root = root->o lderShadowRoot())
2008 root->removeAllEventListenersRecursively(); 2014 root->removeAllEventListenersRecursively();
2009 } 2015 }
2010 } 2016 }
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
2538 node->showTreeForThis(); 2544 node->showTreeForThis();
2539 } 2545 }
2540 2546
2541 void showNodePath(const WebCore::Node* node) 2547 void showNodePath(const WebCore::Node* node)
2542 { 2548 {
2543 if (node) 2549 if (node)
2544 node->showNodePathForThis(); 2550 node->showNodePathForThis();
2545 } 2551 }
2546 2552
2547 #endif 2553 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698