Chromium Code Reviews| Index: Source/core/page/scrolling/ScrollingCoordinator.cpp |
| diff --git a/Source/core/page/scrolling/ScrollingCoordinator.cpp b/Source/core/page/scrolling/ScrollingCoordinator.cpp |
| index ba8cca0f7d5d8ef99e1b655de4918b0e15d4b823..b9c87c2c646c74e6ceb091b3ba359199a7dce4e7 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" |
| @@ -630,15 +631,22 @@ void ScrollingCoordinator::willDestroyRenderLayer(RenderLayer* layer) |
| m_layersWithTouchRects.remove(layer); |
| } |
| -void ScrollingCoordinator::setWheelEventHandlerCount(unsigned count) |
| +void ScrollingCoordinator::updateHaveWheelEventHandlers() |
| { |
| - if (WebLayer* scrollLayer = toWebLayer(m_page->mainFrame()->view()->layerForScrolling())) |
| - scrollLayer->setHaveWheelEventHandlers(count > 0); |
| + if (WebLayer* scrollLayer = toWebLayer(m_page->mainFrame()->view()->layerForScrolling())) { |
| + LocalFrame* frame = m_page->mainFrame(); |
| + bool haveHandlers = EventHandlerRegistry::from(*frame->document())->hasEventHandlers(EventHandlerRegistry::WheelEvent); |
| + scrollLayer->setHaveWheelEventHandlers(haveHandlers); |
| + } |
| } |
| -void ScrollingCoordinator::recomputeWheelEventHandlerCountForFrameView(FrameView*) |
| +void ScrollingCoordinator::updateHaveScrollEventHandlers() |
| { |
| - setWheelEventHandlerCount(computeCurrentWheelEventHandlerCount()); |
| + if (WebLayer* scrollLayer = toWebLayer(m_page->mainFrame()->view()->layerForScrolling())) { |
| + LocalFrame* frame = m_page->mainFrame(); |
| + bool haveHandlers = EventHandlerRegistry::from(*frame->document())->hasEventHandlers(EventHandlerRegistry::ScrollEvent); |
| + scrollLayer->setHaveScrollEventHandlers(haveHandlers); |
| + } |
| } |
| void ScrollingCoordinator::setShouldUpdateScrollLayerPositionOnMainThread(MainThreadScrollingReasons reasons) |
| @@ -725,21 +733,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); |
| } |
| @@ -747,19 +755,24 @@ 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; |
| + if (DOMWindow* window = target->toDOMWindow()) { |
|
Rick Byers
2014/04/03 15:33:19
Sorry I should have pointed out earlier - this can
|
| + accumulateDocumentTouchEventTargetRects(rects, window->document()); |
| + continue; |
| + } |
| + Node* node = target->toNode(); |
| + 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; |
| } |
| @@ -798,24 +811,20 @@ void ScrollingCoordinator::computeTouchEventTargetRects(LayerHitTestRects& rects |
| accumulateDocumentTouchEventTargetRects(rects, document); |
| } |
| -unsigned ScrollingCoordinator::computeCurrentWheelEventHandlerCount() |
| +void ScrollingCoordinator::haveWheelEventHandlersChangedForPage() |
| { |
| - 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; |
| + updateHaveWheelEventHandlers(); |
| } |
| -void ScrollingCoordinator::frameViewWheelEventHandlerCountChanged(FrameView* frameView) |
| +void ScrollingCoordinator::haveScrollEventHandlersChangedForPage() |
| { |
| ASSERT(isMainThread()); |
| ASSERT(m_page); |
| - recomputeWheelEventHandlerCountForFrameView(frameView); |
| + updateHaveScrollEventHandlers(); |
| } |
| void ScrollingCoordinator::frameViewHasSlowRepaintObjectsDidChange(FrameView* frameView) |
| @@ -867,7 +876,8 @@ void ScrollingCoordinator::frameViewRootLayerDidChange(FrameView* frameView) |
| return; |
| notifyLayoutUpdated(); |
| - recomputeWheelEventHandlerCountForFrameView(frameView); |
| + updateHaveWheelEventHandlers(); |
| + updateHaveScrollEventHandlers(); |
| } |
| #if OS(MACOSX) |