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

Unified Diff: Source/core/page/scrolling/ScrollingCoordinator.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 side-by-side diff with in-line comments
Download patch
Index: Source/core/page/scrolling/ScrollingCoordinator.cpp
diff --git a/Source/core/page/scrolling/ScrollingCoordinator.cpp b/Source/core/page/scrolling/ScrollingCoordinator.cpp
index 6147b1228d0c4cef0c9d456665edb1c57156e3e2..feb047ea1a62f55c9f6980ac5ae6a38e7689900e 100644
--- a/Source/core/page/scrolling/ScrollingCoordinator.cpp
+++ b/Source/core/page/scrolling/ScrollingCoordinator.cpp
@@ -29,13 +29,14 @@
#include "RuntimeEnabledFeatures.h"
#include "core/dom/Document.h"
+#include "core/dom/EventHandlerRegistry.h"
#include "core/dom/FullscreenElementStack.h"
#include "core/dom/Node.h"
-#include "core/dom/WheelController.h"
-#include "core/html/HTMLElement.h"
+#include "core/frame/DOMWindow.h"
#include "core/frame/FrameView.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Settings.h"
+#include "core/html/HTMLElement.h"
#include "core/page/Page.h"
#include "core/plugins/PluginView.h"
#include "core/rendering/RenderGeometryMap.h"
@@ -631,9 +632,24 @@ void ScrollingCoordinator::setWheelEventHandlerCount(unsigned count)
scrollLayer->setHaveWheelEventHandlers(count > 0);
}
-void ScrollingCoordinator::recomputeWheelEventHandlerCountForFrameView(FrameView*)
+void ScrollingCoordinator::setScrollEventHandlerCount(unsigned count)
+{
+ if (WebLayer* scrollLayer = toWebLayer(m_page->mainFrame()->view()->layerForScrolling()))
+ scrollLayer->setHaveScrollEventHandlers(count > 0);
+}
+
+void ScrollingCoordinator::updateWheelEventHandlerCountForFrameView(FrameView*)
+{
+ LocalFrame* frame = m_page->mainFrame();
+ unsigned count = EventHandlerRegistry::from(*frame->document())->eventHandlerCount(EventHandlerRegistry::WheelEvent);
+ setWheelEventHandlerCount(count);
+}
+
+void ScrollingCoordinator::updateScrollEventHandlerCountForFrameView(FrameView*)
{
- setWheelEventHandlerCount(computeCurrentWheelEventHandlerCount());
+ LocalFrame* frame = m_page->mainFrame();
+ unsigned count = EventHandlerRegistry::from(*frame->document())->eventHandlerCount(EventHandlerRegistry::ScrollEvent);
Rick Byers 2014/03/27 16:43:31 why all this work with 'counts' when this function
Sami 2014/04/02 19:58:05 Yeah, the more I looked at this the more obvious i
+ setScrollEventHandlerCount(count);
}
void ScrollingCoordinator::setShouldUpdateScrollLayerPositionOnMainThread(MainThreadScrollingReasons reasons)
@@ -720,21 +736,21 @@ Region ScrollingCoordinator::computeShouldHandleScrollGestureOnMainThreadRegion(
return shouldHandleScrollGestureOnMainThreadRegion;
}
-static void accumulateDocumentTouchEventTargetRects(LayerHitTestRects& rects, const Document* document)
+static void accumulateDocumentTouchEventTargetRects(LayerHitTestRects& rects, Document* document)
{
ASSERT(document);
- if (!document->touchEventTargets())
+ const EventTargetSet* targets = EventHandlerRegistry::from(*document)->eventHandlerTargets(EventHandlerRegistry::TouchEvent);
+ if (!targets)
return;
- const TouchEventTargetSet* targets = document->touchEventTargets();
-
- // If there's a handler on the document, html or body element (fairly common in practice),
+ // If there's a handler on the window, document, html or body element (fairly common in practice),
// then we can quickly mark the entire document and skip looking at any other handlers.
// Note that technically a handler on the body doesn't cover the whole document, but it's
// reasonable to be conservative and report the whole document anyway.
- for (TouchEventTargetSet::const_iterator iter = targets->begin(); iter != targets->end(); ++iter) {
- Node* target = iter->key;
- if (target == document || target == document->documentElement() || target == document->body()) {
+ for (EventTargetSet::const_iterator iter = targets->begin(); iter != targets->end(); ++iter) {
+ EventTarget* target = iter->key;
+ Node* node = target->toNode();
+ if (target->toDOMWindow() || node == document || node == document->documentElement() || node == document->body()) {
if (RenderObject* renderer = document->renderer()) {
renderer->computeLayerHitTestRects(rects);
}
@@ -742,19 +758,20 @@ static void accumulateDocumentTouchEventTargetRects(LayerHitTestRects& rects, co
}
}
- for (TouchEventTargetSet::const_iterator iter = targets->begin(); iter != targets->end(); ++iter) {
- const Node* target = iter->key;
- if (!target->inDocument())
+ for (EventTargetSet::const_iterator iter = targets->begin(); iter != targets->end(); ++iter) {
+ EventTarget* target = iter->key;
+ Node* node = target->toDOMWindow() ? target->toDOMWindow()->document() : target->toNode();
Rick Byers 2014/03/27 16:43:31 Would be simpler to just combine this with the "if
Sami 2014/04/02 19:58:05 Done.
+ if (!node->inDocument())
continue;
- if (target->isDocumentNode()) {
- ASSERT(target != document);
- accumulateDocumentTouchEventTargetRects(rects, toDocument(target));
- } else if (RenderObject* renderer = target->renderer()) {
+ if (node->isDocumentNode()) {
+ ASSERT(node != document);
+ accumulateDocumentTouchEventTargetRects(rects, toDocument(node));
+ } else if (RenderObject* renderer = node->renderer()) {
// If the set also contains one of our ancestor nodes then processing
// this node would be redundant.
bool hasTouchEventTargetAncestor = false;
- for (Node* ancestor = target->parentNode(); ancestor && !hasTouchEventTargetAncestor; ancestor = ancestor->parentNode()) {
+ for (Node* ancestor = node->parentNode(); ancestor && !hasTouchEventTargetAncestor; ancestor = ancestor->parentNode()) {
if (targets->contains(ancestor))
hasTouchEventTargetAncestor = true;
}
@@ -793,24 +810,20 @@ void ScrollingCoordinator::computeTouchEventTargetRects(LayerHitTestRects& rects
accumulateDocumentTouchEventTargetRects(rects, document);
}
-unsigned ScrollingCoordinator::computeCurrentWheelEventHandlerCount()
+void ScrollingCoordinator::frameViewWheelEventHandlerCountChanged(FrameView* frameView)
{
- unsigned wheelEventHandlerCount = 0;
-
- for (LocalFrame* frame = m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
- if (frame->document())
- wheelEventHandlerCount += WheelController::from(*frame->document())->wheelEventHandlerCount();
- }
+ ASSERT(isMainThread());
+ ASSERT(m_page);
- return wheelEventHandlerCount;
+ updateWheelEventHandlerCountForFrameView(frameView);
}
-void ScrollingCoordinator::frameViewWheelEventHandlerCountChanged(FrameView* frameView)
+void ScrollingCoordinator::frameViewScrollEventHandlerCountChanged(FrameView* frameView)
{
ASSERT(isMainThread());
ASSERT(m_page);
- recomputeWheelEventHandlerCountForFrameView(frameView);
+ updateScrollEventHandlerCountForFrameView(frameView);
}
void ScrollingCoordinator::frameViewHasSlowRepaintObjectsDidChange(FrameView* frameView)
@@ -862,7 +875,8 @@ void ScrollingCoordinator::frameViewRootLayerDidChange(FrameView* frameView)
return;
notifyLayoutUpdated();
- recomputeWheelEventHandlerCountForFrameView(frameView);
+ updateWheelEventHandlerCountForFrameView(frameView);
+ updateScrollEventHandlerCountForFrameView(frameView);
}
#if OS(MACOSX)

Powered by Google App Engine
This is Rietveld 408576698