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

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: Refactoring WIP. Created 6 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 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"
55 #include "core/dom/TreeScopeAdopter.h" 56 #include "core/dom/TreeScopeAdopter.h"
56 #include "core/dom/UserActionElementSet.h" 57 #include "core/dom/UserActionElementSet.h"
57 #include "core/dom/WheelController.h"
58 #include "core/dom/shadow/ElementShadow.h" 58 #include "core/dom/shadow/ElementShadow.h"
59 #include "core/dom/shadow/InsertionPoint.h" 59 #include "core/dom/shadow/InsertionPoint.h"
60 #include "core/dom/shadow/ShadowRoot.h" 60 #include "core/dom/shadow/ShadowRoot.h"
61 #include "core/editing/htmlediting.h" 61 #include "core/editing/htmlediting.h"
62 #include "core/events/BeforeLoadEvent.h" 62 #include "core/events/BeforeLoadEvent.h"
63 #include "core/events/Event.h" 63 #include "core/events/Event.h"
64 #include "core/events/EventDispatchMediator.h" 64 #include "core/events/EventDispatchMediator.h"
65 #include "core/events/EventDispatcher.h" 65 #include "core/events/EventDispatcher.h"
66 #include "core/events/EventListener.h" 66 #include "core/events/EventListener.h"
67 #include "core/events/GestureEvent.h" 67 #include "core/events/GestureEvent.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 282
283 void Node::willBeDeletedFromDocument() 283 void Node::willBeDeletedFromDocument()
284 { 284 {
285 if (!isTreeScopeInitialized()) 285 if (!isTreeScopeInitialized())
286 return; 286 return;
287 287
288 Document& document = this->document(); 288 Document& document = this->document();
289 289
290 if (hasEventTargetData()) { 290 if (hasEventTargetData()) {
291 clearEventTargetData(); 291 clearEventTargetData();
292 EventHandlerRegistry::didRemoveAllEventHandlers(*this);
292 document.didClearTouchEventHandlers(this); 293 document.didClearTouchEventHandlers(this);
293 } 294 }
294 295
295 if (AXObjectCache* cache = document.existingAXObjectCache()) 296 if (AXObjectCache* cache = document.existingAXObjectCache())
296 cache->remove(this); 297 cache->remove(this);
297 298
298 document.markers().removeMarkers(this); 299 document.markers().removeMarkers(this);
299 } 300 }
300 301
301 NodeRareData* Node::rareData() const 302 NodeRareData* Node::rareData() const
(...skipping 1609 matching lines...) Expand 10 before | Expand all | Expand 10 after
1911 for (unsigned i = 0; i < types.size(); ++i) 1912 for (unsigned i = 0; i < types.size(); ++i)
1912 document().addListenerTypeIfNeeded(types[i]); 1913 document().addListenerTypeIfNeeded(types[i]);
1913 } 1914 }
1914 } 1915 }
1915 1916
1916 if (AXObjectCache::accessibilityEnabled()) { 1917 if (AXObjectCache::accessibilityEnabled()) {
1917 if (AXObjectCache* cache = oldDocument.existingAXObjectCache()) 1918 if (AXObjectCache* cache = oldDocument.existingAXObjectCache())
1918 cache->remove(this); 1919 cache->remove(this);
1919 } 1920 }
1920 1921
1921 const EventListenerVector& mousewheelListeners = getEventListeners(EventType Names::mousewheel); 1922 EventHandlerRegistry::didMoveNodeToNewDocument(*this, oldDocument);
1922 WheelController* oldController = WheelController::from(oldDocument);
1923 WheelController* newController = WheelController::from(document());
1924 for (size_t i = 0; i < mousewheelListeners.size(); ++i) {
1925 oldController->didRemoveWheelEventHandler(oldDocument);
1926 newController->didAddWheelEventHandler(document());
1927 }
1928
1929 const EventListenerVector& wheelListeners = getEventListeners(EventTypeNames ::wheel);
1930 for (size_t i = 0; i < wheelListeners.size(); ++i) {
1931 oldController->didRemoveWheelEventHandler(oldDocument);
1932 newController->didAddWheelEventHandler(document());
1933 }
1934 1923
1935 if (const TouchEventTargetSet* touchHandlers = oldDocument.touchEventTargets ()) { 1924 if (const TouchEventTargetSet* touchHandlers = oldDocument.touchEventTargets ()) {
1936 while (touchHandlers->contains(this)) { 1925 while (touchHandlers->contains(this)) {
1937 oldDocument.didRemoveTouchEventHandler(this); 1926 oldDocument.didRemoveTouchEventHandler(this);
1938 document().didAddTouchEventHandler(this); 1927 document().didAddTouchEventHandler(this);
1939 } 1928 }
1940 } 1929 }
1941 1930
1942 if (Vector<OwnPtr<MutationObserverRegistration> >* registry = mutationObserv erRegistry()) { 1931 if (Vector<OwnPtr<MutationObserverRegistration> >* registry = mutationObserv erRegistry()) {
1943 for (size_t i = 0; i < registry->size(); ++i) { 1932 for (size_t i = 0; i < registry->size(); ++i) {
1944 document().addMutationObserverTypes(registry->at(i)->mutationTypes() ); 1933 document().addMutationObserverTypes(registry->at(i)->mutationTypes() );
1945 } 1934 }
1946 } 1935 }
1947 1936
1948 if (HashSet<MutationObserverRegistration*>* transientRegistry = transientMut ationObserverRegistry()) { 1937 if (HashSet<MutationObserverRegistration*>* transientRegistry = transientMut ationObserverRegistry()) {
1949 for (HashSet<MutationObserverRegistration*>::iterator iter = transientRe gistry->begin(); iter != transientRegistry->end(); ++iter) { 1938 for (HashSet<MutationObserverRegistration*>::iterator iter = transientRe gistry->begin(); iter != transientRegistry->end(); ++iter) {
1950 document().addMutationObserverTypes((*iter)->mutationTypes()); 1939 document().addMutationObserverTypes((*iter)->mutationTypes());
1951 } 1940 }
1952 } 1941 }
1953 } 1942 }
1954 1943
1955 static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve ntType, PassRefPtr<EventListener> listener, bool useCapture) 1944 static inline bool tryAddEventListener(Node* targetNode, const AtomicString& eve ntType, PassRefPtr<EventListener> listener, bool useCapture)
1956 { 1945 {
1957 if (!targetNode->EventTarget::addEventListener(eventType, listener, useCaptu re)) 1946 if (!targetNode->EventTarget::addEventListener(eventType, listener, useCaptu re))
1958 return false; 1947 return false;
1959 1948
1960 Document& document = targetNode->document(); 1949 Document& document = targetNode->document();
1961 document.addListenerTypeIfNeeded(eventType); 1950 document.addListenerTypeIfNeeded(eventType);
1962 if (eventType == EventTypeNames::wheel || eventType == EventTypeNames::mouse wheel) 1951 EventHandlerRegistry::from(document)->didAddEventHandler(document, eventType , targetNode);
1963 WheelController::from(document)->didAddWheelEventHandler(document); 1952 if (isTouchEventType(eventType))
1964 else if (isTouchEventType(eventType))
1965 document.didAddTouchEventHandler(targetNode); 1953 document.didAddTouchEventHandler(targetNode);
1966 1954
1967 return true; 1955 return true;
1968 } 1956 }
1969 1957
1970 bool Node::addEventListener(const AtomicString& eventType, PassRefPtr<EventListe ner> listener, bool useCapture) 1958 bool Node::addEventListener(const AtomicString& eventType, PassRefPtr<EventListe ner> listener, bool useCapture)
1971 { 1959 {
1972 return tryAddEventListener(this, eventType, listener, useCapture); 1960 return tryAddEventListener(this, eventType, listener, useCapture);
1973 } 1961 }
1974 1962
1975 static inline bool tryRemoveEventListener(Node* targetNode, const AtomicString& eventType, EventListener* listener, bool useCapture) 1963 static inline bool tryRemoveEventListener(Node* targetNode, const AtomicString& eventType, EventListener* listener, bool useCapture)
1976 { 1964 {
1977 if (!targetNode->EventTarget::removeEventListener(eventType, listener, useCa pture)) 1965 if (!targetNode->EventTarget::removeEventListener(eventType, listener, useCa pture))
1978 return false; 1966 return false;
1979 1967
1980 // FIXME: Notify Document that the listener has vanished. We need to keep tr ack of a number of 1968 // FIXME: Notify Document that the listener has vanished. We need to keep tr ack of a number of
1981 // listeners for each type, not just a bool - see https://bugs.webkit.org/sh ow_bug.cgi?id=33861 1969 // listeners for each type, not just a bool - see https://bugs.webkit.org/sh ow_bug.cgi?id=33861
1982 Document& document = targetNode->document(); 1970 Document& document = targetNode->document();
1983 if (eventType == EventTypeNames::wheel || eventType == EventTypeNames::mouse wheel) 1971 EventHandlerRegistry::from(document)->didRemoveEventHandler(document, eventT ype, targetNode);
1984 WheelController::from(document)->didRemoveWheelEventHandler(document); 1972 if (isTouchEventType(eventType))
1985 else if (isTouchEventType(eventType))
1986 document.didRemoveTouchEventHandler(targetNode); 1973 document.didRemoveTouchEventHandler(targetNode);
1987 1974
1988 return true; 1975 return true;
1989 } 1976 }
1990 1977
1991 bool Node::removeEventListener(const AtomicString& eventType, EventListener* lis tener, bool useCapture) 1978 bool Node::removeEventListener(const AtomicString& eventType, EventListener* lis tener, bool useCapture)
1992 { 1979 {
1993 return tryRemoveEventListener(this, eventType, listener, useCapture); 1980 return tryRemoveEventListener(this, eventType, listener, useCapture);
1994 } 1981 }
1995 1982
1996 void Node::removeAllEventListeners() 1983 void Node::removeAllEventListeners()
1997 { 1984 {
1985 EventHandlerRegistry::didRemoveAllEventHandlers(*this);
1998 EventTarget::removeAllEventListeners(); 1986 EventTarget::removeAllEventListeners();
1999 document().didClearTouchEventHandlers(this); 1987 document().didClearTouchEventHandlers(this);
2000 } 1988 }
2001 1989
2002 typedef HashMap<Node*, OwnPtr<EventTargetData> > EventTargetDataMap; 1990 typedef HashMap<Node*, OwnPtr<EventTargetData> > EventTargetDataMap;
2003 1991
2004 static EventTargetDataMap& eventTargetDataMap() 1992 static EventTargetDataMap& eventTargetDataMap()
2005 { 1993 {
2006 DEFINE_STATIC_LOCAL(EventTargetDataMap, map, ()); 1994 DEFINE_STATIC_LOCAL(EventTargetDataMap, map, ());
2007 return map; 1995 return map;
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
2535 node->showTreeForThis(); 2523 node->showTreeForThis();
2536 } 2524 }
2537 2525
2538 void showNodePath(const WebCore::Node* node) 2526 void showNodePath(const WebCore::Node* node)
2539 { 2527 {
2540 if (node) 2528 if (node)
2541 node->showNodePathForThis(); 2529 node->showNodePathForThis();
2542 } 2530 }
2543 2531
2544 #endif 2532 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698