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

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

Issue 206603002: Add EventHandlerRegistry (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Tests now seem to pass. 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 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 #include "core/dom/ContextFeatures.h" 64 #include "core/dom/ContextFeatures.h"
65 #include "core/dom/DOMImplementation.h" 65 #include "core/dom/DOMImplementation.h"
66 #include "core/dom/DocumentFragment.h" 66 #include "core/dom/DocumentFragment.h"
67 #include "core/dom/DocumentLifecycleNotifier.h" 67 #include "core/dom/DocumentLifecycleNotifier.h"
68 #include "core/dom/DocumentLifecycleObserver.h" 68 #include "core/dom/DocumentLifecycleObserver.h"
69 #include "core/dom/DocumentMarkerController.h" 69 #include "core/dom/DocumentMarkerController.h"
70 #include "core/dom/DocumentType.h" 70 #include "core/dom/DocumentType.h"
71 #include "core/dom/Element.h" 71 #include "core/dom/Element.h"
72 #include "core/dom/ElementDataCache.h" 72 #include "core/dom/ElementDataCache.h"
73 #include "core/dom/ElementTraversal.h" 73 #include "core/dom/ElementTraversal.h"
74 #include "core/dom/EventHandlerRegistry.h"
74 #include "core/dom/ExceptionCode.h" 75 #include "core/dom/ExceptionCode.h"
75 #include "core/dom/ExecutionContextTask.h" 76 #include "core/dom/ExecutionContextTask.h"
76 #include "core/dom/MainThreadTaskRunner.h" 77 #include "core/dom/MainThreadTaskRunner.h"
77 #include "core/dom/MutationObserver.h" 78 #include "core/dom/MutationObserver.h"
78 #include "core/dom/NodeChildRemovalTracker.h" 79 #include "core/dom/NodeChildRemovalTracker.h"
79 #include "core/dom/NodeFilter.h" 80 #include "core/dom/NodeFilter.h"
80 #include "core/dom/NodeIterator.h" 81 #include "core/dom/NodeIterator.h"
81 #include "core/dom/NodeRareData.h" 82 #include "core/dom/NodeRareData.h"
82 #include "core/dom/NodeRenderStyle.h" 83 #include "core/dom/NodeRenderStyle.h"
83 #include "core/dom/NodeRenderingTraversal.h" 84 #include "core/dom/NodeRenderingTraversal.h"
(...skipping 1953 matching lines...) Expand 10 before | Expand all | Expand 10 after
2037 m_renderView = new RenderView(this); 2038 m_renderView = new RenderView(this);
2038 setRenderer(m_renderView); 2039 setRenderer(m_renderView);
2039 2040
2040 m_renderView->setIsInWindow(true); 2041 m_renderView->setIsInWindow(true);
2041 m_renderView->setStyle(StyleResolver::styleForDocument(*this)); 2042 m_renderView->setStyle(StyleResolver::styleForDocument(*this));
2042 view()->updateCompositingLayersAfterStyleChange(); 2043 view()->updateCompositingLayersAfterStyleChange();
2043 2044
2044 ContainerNode::attach(context); 2045 ContainerNode::attach(context);
2045 2046
2046 m_lifecycle.advanceTo(DocumentLifecycle::StyleClean); 2047 m_lifecycle.advanceTo(DocumentLifecycle::StyleClean);
2048 lifecycleNotifier().notifyDocumentWasAttached();
2047 } 2049 }
2048 2050
2049 void Document::detach(const AttachContext& context) 2051 void Document::detach(const AttachContext& context)
2050 { 2052 {
2051 ASSERT(isActive()); 2053 ASSERT(isActive());
2052 m_lifecycle.advanceTo(DocumentLifecycle::Stopping); 2054 m_lifecycle.advanceTo(DocumentLifecycle::Stopping);
2055 lifecycleNotifier().notifyWillDetachDocument();
2053 2056
2054 if (page()) 2057 if (page())
2055 page()->documentDetached(this); 2058 page()->documentDetached(this);
2056 InspectorInstrumentation::documentDetached(this); 2059 InspectorInstrumentation::documentDetached(this);
2057 2060
2058 if (m_frame->loader().client()->sharedWorkerRepositoryClient()) 2061 if (m_frame->loader().client()->sharedWorkerRepositoryClient())
2059 m_frame->loader().client()->sharedWorkerRepositoryClient()->documentDeta ched(this); 2062 m_frame->loader().client()->sharedWorkerRepositoryClient()->documentDeta ched(this);
2060 2063
2061 if (this == topDocument()) 2064 if (this == topDocument())
2062 clearAXObjectCache(); 2065 clearAXObjectCache();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2096 m_activeHoverElement = nullptr; 2099 m_activeHoverElement = nullptr;
2097 m_autofocusElement = nullptr; 2100 m_autofocusElement = nullptr;
2098 2101
2099 ContainerNode::detach(context); 2102 ContainerNode::detach(context);
2100 2103
2101 m_styleEngine->didDetach(); 2104 m_styleEngine->didDetach();
2102 2105
2103 if (renderView) 2106 if (renderView)
2104 renderView->destroy(); 2107 renderView->destroy();
2105 2108
2106 if (Document* parentDoc = parentDocument())
2107 parentDoc->didClearTouchEventHandlers(this);
2108
2109 // This is required, as our LocalFrame might delete itself as soon as it det aches 2109 // This is required, as our LocalFrame might delete itself as soon as it det aches
2110 // us. However, this violates Node::detach() semantics, as it's never 2110 // us. However, this violates Node::detach() semantics, as it's never
2111 // possible to re-attach. Eventually Document::detach() should be renamed, 2111 // possible to re-attach. Eventually Document::detach() should be renamed,
2112 // or this setting of the frame to 0 could be made explicit in each of the 2112 // or this setting of the frame to 0 could be made explicit in each of the
2113 // callers of Document::detach(). 2113 // callers of Document::detach().
2114 m_frame = 0; 2114 m_frame = 0;
2115 2115
2116 if (m_mediaQueryMatcher) 2116 if (m_mediaQueryMatcher)
2117 m_mediaQueryMatcher->documentDestroyed(); 2117 m_mediaQueryMatcher->documentDestroyed();
2118 2118
(...skipping 2838 matching lines...) Expand 10 before | Expand all | Expand 10 after
4957 // and implement them here. See https://bugs.webkit.org/show_bug.cgi?id=4781 9 4957 // and implement them here. See https://bugs.webkit.org/show_bug.cgi?id=4781 9
4958 LocalFrame* frame = window ? window->frame() : this->frame(); 4958 LocalFrame* frame = window ? window->frame() : this->frame();
4959 return Touch::create(frame, target, identifier, screenX, screenY, pageX, pag eY, radiusX, radiusY, rotationAngle, force); 4959 return Touch::create(frame, target, identifier, screenX, screenY, pageX, pag eY, radiusX, radiusY, rotationAngle, force);
4960 } 4960 }
4961 4961
4962 PassRefPtrWillBeRawPtr<TouchList> Document::createTouchList(WillBeHeapVector<Ref PtrWillBeMember<Touch> >& touches) const 4962 PassRefPtrWillBeRawPtr<TouchList> Document::createTouchList(WillBeHeapVector<Ref PtrWillBeMember<Touch> >& touches) const
4963 { 4963 {
4964 return TouchList::create(touches); 4964 return TouchList::create(touches);
4965 } 4965 }
4966 4966
4967 void Document::didAddTouchEventHandler(Node* handler)
4968 {
4969 // The node should either be in this document, or be the Document node of a child
4970 // of this document.
4971 ASSERT(&handler->document() == this
4972 || (handler->isDocumentNode() && toDocument(handler)->parentDocument() = = this));
4973 if (!m_touchEventTargets.get())
4974 m_touchEventTargets = adoptPtr(new TouchEventTargetSet);
4975 bool isFirstHandler = m_touchEventTargets->isEmpty();
4976
4977 if (!m_touchEventTargets->add(handler).isNewEntry) {
4978 // Just incremented refcount, no real change.
4979 // If this is a child document node, then the count should never go abov e 1.
4980 ASSERT(!handler->isDocumentNode() || &handler->document() == this);
4981 return;
4982 }
4983
4984 if (isFirstHandler) {
4985 if (Document* parent = parentDocument()) {
4986 parent->didAddTouchEventHandler(this);
4987 } else {
4988 // This is the first touch handler on the whole page.
4989 if (FrameHost* frameHost = this->frameHost())
4990 frameHost->chrome().client().needTouchEvents(true);
4991 }
4992 }
4993
4994 // When we're all done with all frames, ensure touch hit rects are marked as dirty.
4995 if (!handler->isDocumentNode() || handler == this) {
4996 if (Page* page = this->page()) {
4997 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoor dinator())
4998 scrollingCoordinator->touchEventTargetRectsDidChange();
4999 }
5000 }
5001 }
5002
5003 void Document::didRemoveTouchEventHandler(Node* handler, bool clearAll)
5004 {
5005 // Note that we can't assert that |handler| is in this document because it m ight be in
5006 // the process of moving out of it.
5007 ASSERT(clearAll || m_touchEventTargets->contains(handler));
5008 if (!m_touchEventTargets.get())
5009 return;
5010
5011 if (clearAll) {
5012 if (!m_touchEventTargets->contains(handler))
5013 return;
5014 m_touchEventTargets->removeAll(handler);
5015 } else {
5016 if (!m_touchEventTargets->remove(handler))
5017 // Just decremented refcount, no real update.
5018 return;
5019 }
5020
5021 if (m_touchEventTargets->isEmpty()) {
5022 if (Document* parent = parentDocument()) {
5023 // This was the last handler in this document, update the parent doc ument too.
5024 parent->didRemoveTouchEventHandler(this, clearAll);
5025 } else {
5026 // We just removed the last touch handler on the whole page.
5027 if (FrameHost* frameHost = this->frameHost())
5028 frameHost->chrome().client().needTouchEvents(false);
5029 }
5030 }
5031
5032 // When we're all done with all frames, ensure touch hit rects are marked as dirty.
5033 if (!handler->isDocumentNode() || handler == this) {
5034 if (Page* page = this->page()) {
5035 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoor dinator())
5036 scrollingCoordinator->touchEventTargetRectsDidChange();
5037 }
5038 }
5039 }
5040
5041 void Document::resetLastHandledUserGestureTimestamp() 4967 void Document::resetLastHandledUserGestureTimestamp()
5042 { 4968 {
5043 m_lastHandledUserGestureTimestamp = currentTime(); 4969 m_lastHandledUserGestureTimestamp = currentTime();
5044 } 4970 }
5045 4971
5046 DocumentLoader* Document::loader() const 4972 DocumentLoader* Document::loader() const
5047 { 4973 {
5048 if (!m_frame) 4974 if (!m_frame)
5049 return 0; 4975 return 0;
5050 4976
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
5465 } 5391 }
5466 5392
5467 void Document::invalidateNodeListCaches(const QualifiedName* attrName) 5393 void Document::invalidateNodeListCaches(const QualifiedName* attrName)
5468 { 5394 {
5469 HashSet<LiveNodeListBase*>::iterator end = m_listsInvalidatedAtDocument.end( ); 5395 HashSet<LiveNodeListBase*>::iterator end = m_listsInvalidatedAtDocument.end( );
5470 for (HashSet<LiveNodeListBase*>::iterator it = m_listsInvalidatedAtDocument. begin(); it != end; ++it) 5396 for (HashSet<LiveNodeListBase*>::iterator it = m_listsInvalidatedAtDocument. begin(); it != end; ++it)
5471 (*it)->invalidateCache(attrName); 5397 (*it)->invalidateCache(attrName);
5472 } 5398 }
5473 5399
5474 } // namespace WebCore 5400 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698