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

Side by Side Diff: Source/core/page/scrolling/ScrollingCoordinator.cpp

Issue 17471008: Rework compositor touch hit testing (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: CR feedback - accumulate LayoutRects instead of IntRects, disable when page isn't composited. Also… Created 7 years, 5 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
« no previous file with comments | « Source/core/page/scrolling/ScrollingCoordinator.h ('k') | Source/core/rendering/RenderBlock.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE. 23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 27
28 #include "core/page/scrolling/ScrollingCoordinator.h" 28 #include "core/page/scrolling/ScrollingCoordinator.h"
29 29
30 #include "RuntimeEnabledFeatures.h"
30 #include "core/dom/Document.h" 31 #include "core/dom/Document.h"
32 #include "core/dom/Node.h"
33 #include "core/html/HTMLElement.h"
31 #include "core/page/Frame.h" 34 #include "core/page/Frame.h"
32 #include "core/page/FrameView.h" 35 #include "core/page/FrameView.h"
33 #include "core/page/Page.h" 36 #include "core/page/Page.h"
34 #include "core/platform/PlatformWheelEvent.h" 37 #include "core/platform/PlatformWheelEvent.h"
35 #include "core/platform/ScrollAnimator.h" 38 #include "core/platform/ScrollAnimator.h"
36 #include "core/platform/ScrollbarThemeComposite.h" 39 #include "core/platform/ScrollbarThemeComposite.h"
40 #include "core/platform/chromium/TraceEvent.h"
37 #include "core/platform/chromium/support/WebScrollbarImpl.h" 41 #include "core/platform/chromium/support/WebScrollbarImpl.h"
38 #include "core/platform/chromium/support/WebScrollbarThemeGeometryNative.h" 42 #include "core/platform/chromium/support/WebScrollbarThemeGeometryNative.h"
39 #include "core/platform/graphics/GraphicsLayer.h" 43 #include "core/platform/graphics/GraphicsLayer.h"
40 #include "core/platform/graphics/IntRect.h" 44 #include "core/platform/graphics/IntRect.h"
41 #include "core/platform/graphics/Region.h" 45 #include "core/platform/graphics/Region.h"
46 #include "core/platform/graphics/transforms/TransformState.h"
42 #include "core/plugins/PluginView.h" 47 #include "core/plugins/PluginView.h"
43 #include "core/rendering/RenderLayerBacking.h" 48 #include "core/rendering/RenderLayerBacking.h"
44 #include "core/rendering/RenderLayerCompositor.h" 49 #include "core/rendering/RenderLayerCompositor.h"
45 #include "core/rendering/RenderView.h" 50 #include "core/rendering/RenderView.h"
46 #include "public/platform/Platform.h" 51 #include "public/platform/Platform.h"
47 #include "public/platform/WebCompositorSupport.h" 52 #include "public/platform/WebCompositorSupport.h"
48 #include "public/platform/WebLayerPositionConstraint.h" 53 #include "public/platform/WebLayerPositionConstraint.h"
49 #include "public/platform/WebScrollbarLayer.h" 54 #include "public/platform/WebScrollbarLayer.h"
50 #include "public/platform/WebScrollbarThemeGeometry.h" 55 #include "public/platform/WebScrollbarThemeGeometry.h"
51 #include "public/platform/WebScrollbarThemePainter.h" 56 #include "public/platform/WebScrollbarThemePainter.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 ScrollingCoordinator::~ScrollingCoordinator() 89 ScrollingCoordinator::~ScrollingCoordinator()
85 { 90 {
86 ASSERT(!m_page); 91 ASSERT(!m_page);
87 for (ScrollbarMap::iterator it = m_horizontalScrollbars.begin(); it != m_hor izontalScrollbars.end(); ++it) 92 for (ScrollbarMap::iterator it = m_horizontalScrollbars.begin(); it != m_hor izontalScrollbars.end(); ++it)
88 GraphicsLayer::unregisterContentsLayer(it->value->layer()); 93 GraphicsLayer::unregisterContentsLayer(it->value->layer());
89 for (ScrollbarMap::iterator it = m_verticalScrollbars.begin(); it != m_verti calScrollbars.end(); ++it) 94 for (ScrollbarMap::iterator it = m_verticalScrollbars.begin(); it != m_verti calScrollbars.end(); ++it)
90 GraphicsLayer::unregisterContentsLayer(it->value->layer()); 95 GraphicsLayer::unregisterContentsLayer(it->value->layer());
91 96
92 } 97 }
93 98
99 bool ScrollingCoordinator::touchHitTestingEnabled() const
100 {
101 RenderView* contentRenderer = m_page->mainFrame()->contentRenderer();
102 return RuntimeEnabledFeatures::touchEnabled() && contentRenderer && contentR enderer->usesCompositing();
103 }
104
94 void ScrollingCoordinator::setShouldHandleScrollGestureOnMainThreadRegion(const Region& region) 105 void ScrollingCoordinator::setShouldHandleScrollGestureOnMainThreadRegion(const Region& region)
95 { 106 {
96 if (WebLayer* scrollLayer = scrollingWebLayerForScrollableArea(m_page->mainF rame()->view())) { 107 if (WebLayer* scrollLayer = scrollingWebLayerForScrollableArea(m_page->mainF rame()->view())) {
97 Vector<IntRect> rects = region.rects(); 108 Vector<IntRect> rects = region.rects();
98 WebVector<WebRect> webRects(rects.size()); 109 WebVector<WebRect> webRects(rects.size());
99 for (size_t i = 0; i < rects.size(); ++i) 110 for (size_t i = 0; i < rects.size(); ++i)
100 webRects[i] = rects[i]; 111 webRects[i] = rects[i];
101 scrollLayer->setNonFastScrollableRegion(webRects); 112 scrollLayer->setNonFastScrollableRegion(webRects);
102 } 113 }
103 } 114 }
104 115
105 void ScrollingCoordinator::frameViewLayoutUpdated(FrameView* frameView) 116 void ScrollingCoordinator::frameViewLayoutUpdated(FrameView* frameView)
106 { 117 {
107 ASSERT(m_page); 118 if (!touchHitTestingEnabled())
119 return;
120
121 TRACE_EVENT0("input", "ScrollingCoordinator::frameViewLayoutUpdated");
108 122
109 // Compute the region of the page that we can't handle scroll gestures on im pl thread: 123 // Compute the region of the page that we can't handle scroll gestures on im pl thread:
110 // This currently includes: 124 // This currently includes:
111 // 1. All scrollable areas, such as subframes, overflow divs and list boxes, whose composited 125 // 1. All scrollable areas, such as subframes, overflow divs and list boxes, whose composited
112 // scrolling are not enabled. We need to do this even if the frame view whos e layout was updated 126 // scrolling are not enabled. We need to do this even if the frame view whos e layout was updated
113 // is not the main frame. 127 // is not the main frame.
114 // 2. Resize control areas, e.g. the small rect at the right bottom of div/t extarea/iframe when 128 // 2. Resize control areas, e.g. the small rect at the right bottom of div/t extarea/iframe when
115 // CSS property "resize" is enabled. 129 // CSS property "resize" is enabled.
116 // 3. Plugin areas. 130 // 3. Plugin areas.
117 Region shouldHandleScrollGestureOnMainThreadRegion = computeShouldHandleScro llGestureOnMainThreadRegion(m_page->mainFrame(), IntPoint()); 131 Region shouldHandleScrollGestureOnMainThreadRegion = computeShouldHandleScro llGestureOnMainThreadRegion(m_page->mainFrame(), IntPoint());
118 setShouldHandleScrollGestureOnMainThreadRegion(shouldHandleScrollGestureOnMa inThreadRegion); 132 setShouldHandleScrollGestureOnMainThreadRegion(shouldHandleScrollGestureOnMa inThreadRegion);
119 Vector<IntRect> touchEventTargetRects; 133 LayerHitTestRects touchEventTargetRects;
120 computeAbsoluteTouchEventTargetRects(m_page->mainFrame()->document(), touchE ventTargetRects); 134 computeTouchEventTargetRects(touchEventTargetRects);
121 setTouchEventTargetRects(touchEventTargetRects); 135 setTouchEventTargetRects(touchEventTargetRects);
122 if (WebLayer* scrollLayer = scrollingWebLayerForScrollableArea(frameView)) 136 if (WebLayer* scrollLayer = scrollingWebLayerForScrollableArea(frameView))
123 scrollLayer->setBounds(frameView->contentsSize()); 137 scrollLayer->setBounds(frameView->contentsSize());
124 } 138 }
125 139
126 void ScrollingCoordinator::setLayerIsContainerForFixedPositionLayers(GraphicsLay er* layer, bool enable) 140 void ScrollingCoordinator::setLayerIsContainerForFixedPositionLayers(GraphicsLay er* layer, bool enable)
127 { 141 {
128 if (WebLayer* scrollableLayer = scrollingWebLayerForGraphicsLayer(layer)) 142 if (WebLayer* scrollableLayer = scrollingWebLayerForGraphicsLayer(layer))
129 scrollableLayer->setIsContainerForFixedPositionLayers(enable); 143 scrollableLayer->setIsContainerForFixedPositionLayers(enable);
130 } 144 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 } 303 }
290 if (WebScrollbarLayer* scrollbarLayer = getWebScrollbarLayer(scrollableArea, VerticalScrollbar)) { 304 if (WebScrollbarLayer* scrollbarLayer = getWebScrollbarLayer(scrollableArea, VerticalScrollbar)) {
291 GraphicsLayer* verticalScrollbarLayer = verticalScrollbarLayerForScrolla bleArea(scrollableArea); 305 GraphicsLayer* verticalScrollbarLayer = verticalScrollbarLayerForScrolla bleArea(scrollableArea);
292 if (verticalScrollbarLayer) 306 if (verticalScrollbarLayer)
293 setupScrollbarLayer(verticalScrollbarLayer, scrollbarLayer, webLayer ); 307 setupScrollbarLayer(verticalScrollbarLayer, scrollbarLayer, webLayer );
294 } 308 }
295 309
296 return !!webLayer; 310 return !!webLayer;
297 } 311 }
298 312
299 void ScrollingCoordinator::setTouchEventTargetRects(const Vector<IntRect>& absol uteHitTestRects) 313 static void convertLayerRectsToEnclosingCompositedLayer(const LayerHitTestRects& layerRects, LayerHitTestRects& compositorRects)
300 { 314 {
301 if (WebLayer* scrollLayer = scrollingWebLayerForScrollableArea(m_page->mainF rame()->view())) { 315 // We have a set of rects per RenderLayer, we need to map them to their boun ding boxes in their
302 WebVector<WebRect> webRects(absoluteHitTestRects.size()); 316 // enclosing composited layer.
303 for (size_t i = 0; i < absoluteHitTestRects.size(); ++i) 317 for (LayerHitTestRects::const_iterator layerIter = layerRects.begin(); layer Iter != layerRects.end(); ++layerIter) {
304 webRects[i] = absoluteHitTestRects[i]; 318 // Find the enclosing composited layer when it's in another document (fo r non-composited iframes).
305 scrollLayer->setTouchEventHandlerRegion(webRects); 319 RenderLayer* compositedLayer = 0;
320 for (const RenderLayer* layer = layerIter->key; !compositedLayer;) {
321 compositedLayer = layer->enclosingCompositingLayerForRepaint();
322 if (!compositedLayer) {
323 RenderObject* owner = layer->renderer()->frame()->ownerRenderer( );
324 if (!owner)
325 break;
326 layer = owner->enclosingLayer();
327 }
328 }
329 if (!compositedLayer) {
330 // Since this machinery is used only when accelerated compositing is enabled, we expect
331 // that every layer should have an enclosing composited layer.
332 ASSERT_NOT_REACHED();
333 continue;
334 }
335
336 LayerHitTestRects::iterator compIter = compositorRects.find(compositedLa yer);
337 if (compIter == compositorRects.end())
338 compIter = compositorRects.add(compositedLayer, Vector<LayoutRect>() ).iterator;
339
340 // Transform each rect to the co-ordinate space of it's enclosing compos ited layer.
341 // Ideally we'd compute a transformation matrix once and re-use it for e ach rect, but
342 // there doesn't appear to be any easy way to do it (mapLocalToContainer will flatten
343 // the TransformState, so we can't use setQuad/mappedQuad over and over again). Perhaps
344 // RenderGeometryMap?
345 for (size_t i = 0; i < layerIter->value.size(); ++i) {
346 FloatQuad localQuad(layerIter->value[i]);
347 TransformState transformState(TransformState::ApplyTransformDirectio n, localQuad);
348 MapCoordinatesFlags flags = ApplyContainerFlip | UseTransforms | Tra verseDocumentBoundaries;
349 layerIter->key->renderer()->mapLocalToContainer(compositedLayer->ren derer(), transformState, flags);
350 transformState.flatten();
351 LayoutRect compositorRect = LayoutRect(transformState.lastPlanarQuad ().boundingBox());
352 compIter->value.append(compositorRect);
353 }
354 }
355 }
356
357 void ScrollingCoordinator::setTouchEventTargetRects(const LayerHitTestRects& lay erRects)
358 {
359 TRACE_EVENT0("input", "ScrollingCoordinator::setTouchEventTargetRects");
360
361 LayerHitTestRects compositorRects;
362 convertLayerRectsToEnclosingCompositedLayer(layerRects, compositorRects);
363
364 // Inform any observers (i.e. for testing) of these new rects.
365 HashSet<TouchEventTargetRectsObserver*>::iterator stop = m_touchEventTargetR ectsObservers.end();
366 for (HashSet<TouchEventTargetRectsObserver*>::iterator it = m_touchEventTarg etRectsObservers.begin(); it != stop; ++it)
367 (*it)->touchEventTargetRectsChanged(compositorRects);
368
369 // Note that ideally we'd clear the touch event handler region on all layers first,
370 // in case there are others that no longer have any handlers. But it's unlik ely to
371 // matter much in practice (just makes us more conservative).
372 for (LayerHitTestRects::const_iterator iter = compositorRects.begin(); iter != compositorRects.end(); ++iter) {
373 WebVector<WebRect> webRects(iter->value.size());
374 for (size_t i = 0; i < iter->value.size(); ++i)
375 webRects[i] = enclosingIntRect(iter->value[i]);
376 RenderLayerBacking* backing = iter->key->backing();
377 // If the layer is using composited scrolling, then it's the contents th at these
378 // rects apply to.
379 GraphicsLayer* graphicsLayer = backing->scrollingContentsLayer();
380 if (!graphicsLayer)
381 graphicsLayer = backing->graphicsLayer();
382 graphicsLayer->platformLayer()->setTouchEventHandlerRegion(webRects);
306 } 383 }
307 } 384 }
308 385
309 void ScrollingCoordinator::touchEventTargetRectsDidChange(const Document*) 386 void ScrollingCoordinator::touchEventTargetRectsDidChange(const Document*)
310 { 387 {
311 // The rects are always evaluated and used in the main frame coordinates. 388 if (!touchHitTestingEnabled())
312 FrameView* frameView = m_page->mainFrame()->view(); 389 return;
313 Document* document = m_page->mainFrame()->document();
314 390
315 // Wait until after layout to update. 391 // Wait until after layout to update.
316 if (frameView->needsLayout() || !document) 392 if (m_page->mainFrame()->view()->needsLayout())
317 return; 393 return;
318 394
319 Vector<IntRect> touchEventTargetRects; 395 TRACE_EVENT0("input", "ScrollingCoordinator::touchEventTargetRectsDidChange" );
320 computeAbsoluteTouchEventTargetRects(document, touchEventTargetRects); 396
397 LayerHitTestRects touchEventTargetRects;
398 computeTouchEventTargetRects(touchEventTargetRects);
321 setTouchEventTargetRects(touchEventTargetRects); 399 setTouchEventTargetRects(touchEventTargetRects);
322 } 400 }
323 401
324 void ScrollingCoordinator::setWheelEventHandlerCount(unsigned count) 402 void ScrollingCoordinator::setWheelEventHandlerCount(unsigned count)
325 { 403 {
326 if (WebLayer* scrollLayer = scrollingWebLayerForScrollableArea(m_page->mainF rame()->view())) 404 if (WebLayer* scrollLayer = scrollingWebLayerForScrollableArea(m_page->mainF rame()->view()))
327 scrollLayer->setHaveWheelEventHandlers(count > 0); 405 scrollLayer->setHaveWheelEventHandlers(count > 0);
328 } 406 }
329 407
330 void ScrollingCoordinator::recomputeWheelEventHandlerCountForFrameView(FrameView * frameView) 408 void ScrollingCoordinator::recomputeWheelEventHandlerCountForFrameView(FrameView * frameView)
(...skipping 25 matching lines...) Expand all
356 434
357 // We currently only support composited mode. 435 // We currently only support composited mode.
358 RenderView* renderView = m_page->mainFrame()->contentRenderer(); 436 RenderView* renderView = m_page->mainFrame()->contentRenderer();
359 if (!renderView) 437 if (!renderView)
360 return false; 438 return false;
361 return renderView->usesCompositing(); 439 return renderView->usesCompositing();
362 } 440 }
363 441
364 Region ScrollingCoordinator::computeShouldHandleScrollGestureOnMainThreadRegion( const Frame* frame, const IntPoint& frameLocation) const 442 Region ScrollingCoordinator::computeShouldHandleScrollGestureOnMainThreadRegion( const Frame* frame, const IntPoint& frameLocation) const
365 { 443 {
444 TRACE_EVENT0("input", "ScrollingCoordinator::computeShouldHandleScrollGestur eOnMainThreadRegion");
366 Region shouldHandleScrollGestureOnMainThreadRegion; 445 Region shouldHandleScrollGestureOnMainThreadRegion;
367 FrameView* frameView = frame->view(); 446 FrameView* frameView = frame->view();
368 if (!frameView) 447 if (!frameView)
369 return shouldHandleScrollGestureOnMainThreadRegion; 448 return shouldHandleScrollGestureOnMainThreadRegion;
370 449
371 IntPoint offset = frameLocation; 450 IntPoint offset = frameLocation;
372 offset.moveBy(frameView->frameRect().location()); 451 offset.moveBy(frameView->frameRect().location());
373 452
374 if (const FrameView::ScrollableAreaSet* scrollableAreas = frameView->scrolla bleAreas()) { 453 if (const FrameView::ScrollableAreaSet* scrollableAreas = frameView->scrolla bleAreas()) {
375 for (FrameView::ScrollableAreaSet::const_iterator it = scrollableAreas-> begin(), end = scrollableAreas->end(); it != end; ++it) { 454 for (FrameView::ScrollableAreaSet::const_iterator it = scrollableAreas-> begin(), end = scrollableAreas->end(); it != end; ++it) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 } 487 }
409 } 488 }
410 489
411 FrameTree* tree = frame->tree(); 490 FrameTree* tree = frame->tree();
412 for (Frame* subFrame = tree->firstChild(); subFrame; subFrame = subFrame->tr ee()->nextSibling()) 491 for (Frame* subFrame = tree->firstChild(); subFrame; subFrame = subFrame->tr ee()->nextSibling())
413 shouldHandleScrollGestureOnMainThreadRegion.unite(computeShouldHandleScr ollGestureOnMainThreadRegion(subFrame, offset)); 492 shouldHandleScrollGestureOnMainThreadRegion.unite(computeShouldHandleScr ollGestureOnMainThreadRegion(subFrame, offset));
414 493
415 return shouldHandleScrollGestureOnMainThreadRegion; 494 return shouldHandleScrollGestureOnMainThreadRegion;
416 } 495 }
417 496
418 static void accumulateRendererTouchEventTargetRects(Vector<IntRect>& rects, cons t RenderObject* renderer, const IntRect& parentRect = IntRect()) 497 void ScrollingCoordinator::addTouchEventTargetRectsObserver(TouchEventTargetRect sObserver* observer)
419 { 498 {
420 IntRect adjustedParentRect = parentRect; 499 m_touchEventTargetRectsObservers.add(observer);
421 if (parentRect.isEmpty() || renderer->isFloating() || renderer->isPositioned () || renderer->hasTransform()) {
422 // FIXME: This method is O(N^2) as it walks the tree to the root for eve ry renderer. RenderGeometryMap would fix this.
423 IntRect r = enclosingIntRect(renderer->clippedOverflowRectForRepaint(0)) ;
424 if (!r.isEmpty()) {
425 // Convert to the top-level view's coordinates.
426 ASSERT(renderer->document()->view());
427 r = renderer->document()->view()->convertToRootView(r);
428
429 if (!parentRect.contains(r)) {
430 rects.append(r);
431 adjustedParentRect = r;
432 }
433 }
434 }
435
436 for (RenderObject* child = renderer->firstChild(); child; child = child->nex tSibling())
437 accumulateRendererTouchEventTargetRects(rects, child, adjustedParentRect );
438 } 500 }
439 501
440 static void accumulateDocumentEventTargetRects(Vector<IntRect>& rects, const Doc ument* document) 502 void ScrollingCoordinator::removeTouchEventTargetRectsObserver(TouchEventTargetR ectsObserver* observer)
503 {
504 m_touchEventTargetRectsObservers.remove(observer);
505 }
506
507 static void accumulateDocumentTouchEventTargetRects(LayerHitTestRects& rects, co nst Document* document)
441 { 508 {
442 ASSERT(document); 509 ASSERT(document);
443 if (!document->touchEventTargets()) 510 if (!document->touchEventTargets())
444 return; 511 return;
445 512
446 const TouchEventTargetSet* targets = document->touchEventTargets(); 513 const TouchEventTargetSet* targets = document->touchEventTargets();
514
515 // If there's a handler on the document, html or body element (fairly common in practice),
516 // then we can quickly mark the entire document and skip looking at any othe r handlers.
517 // Note that technically a handler on the body doesn't cover the whole docum ent, but it's
518 // reasonable to be conservative and report the whole document anyway.
447 for (TouchEventTargetSet::const_iterator iter = targets->begin(); iter != ta rgets->end(); ++iter) { 519 for (TouchEventTargetSet::const_iterator iter = targets->begin(); iter != ta rgets->end(); ++iter) {
448 const Node* touchTarget = iter->key; 520 Node* target = iter->key;
449 if (!touchTarget->inDocument()) 521 if (target == document || target == document->documentElement() || targe t == document->body()) {
450 continue; 522 if (RenderObject* renderer = document->renderer()) {
451 523 renderer->computeLayerHitTestRects(rects);
452 if (touchTarget == document) {
453 if (RenderView* view = document->renderView()) {
454 IntRect r;
455 if (touchTarget == document->topDocument())
456 r = view->documentRect();
457 else
458 r = enclosingIntRect(view->clippedOverflowRectForRepaint(0)) ;
459
460 if (!r.isEmpty()) {
461 ASSERT(view->document()->view());
462 r = view->document()->view()->convertToRootView(r);
463 rects.append(r);
464 }
465 } 524 }
466 return; 525 return;
467 } 526 }
527 }
468 528
469 if (touchTarget->isDocumentNode() && touchTarget != document) { 529 for (TouchEventTargetSet::const_iterator iter = targets->begin(); iter != ta rgets->end(); ++iter) {
470 accumulateDocumentEventTargetRects(rects, toDocument(touchTarget)); 530 const Node* target = iter->key;
531 if (!target->inDocument())
471 continue; 532 continue;
533
534 if (target->isDocumentNode()) {
535 ASSERT(target != document);
536 accumulateDocumentTouchEventTargetRects(rects, toDocument(target));
537 } else if (RenderObject* renderer = target->renderer()) {
538 renderer->computeLayerHitTestRects(rects);
472 } 539 }
540 }
473 541
474 if (RenderObject* renderer = touchTarget->renderer())
475 accumulateRendererTouchEventTargetRects(rects, renderer);
476 }
477 } 542 }
478 543
479 void ScrollingCoordinator::computeAbsoluteTouchEventTargetRects(const Document* document, Vector<IntRect>& rects) 544 void ScrollingCoordinator::computeTouchEventTargetRects(LayerHitTestRects& rects )
480 { 545 {
481 ASSERT(document); 546 TRACE_EVENT0("input", "ScrollingCoordinator::computeTouchEventTargetRects");
482 if (!document->view()) 547 ASSERT(touchHitTestingEnabled());
548
549 Document* document = m_page->mainFrame()->document();
550 if (!document || !document->view())
483 return; 551 return;
484 552
485 // FIXME: These rects won't be properly updated if the renderers are in a su b-tree that scrolls. 553 accumulateDocumentTouchEventTargetRects(rects, document);
486 accumulateDocumentEventTargetRects(rects, document);
487 } 554 }
488 555
489 unsigned ScrollingCoordinator::computeCurrentWheelEventHandlerCount() 556 unsigned ScrollingCoordinator::computeCurrentWheelEventHandlerCount()
490 { 557 {
491 unsigned wheelEventHandlerCount = 0; 558 unsigned wheelEventHandlerCount = 0;
492 559
493 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->trave rseNext()) { 560 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->trave rseNext()) {
494 if (frame->document()) 561 if (frame->document())
495 wheelEventHandlerCount += frame->document()->wheelEventHandlerCount( ); 562 wheelEventHandlerCount += frame->document()->wheelEventHandlerCount( );
496 } 563 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 stringBuilder.resize(stringBuilder.length() - 2); 715 stringBuilder.resize(stringBuilder.length() - 2);
649 return stringBuilder.toString(); 716 return stringBuilder.toString();
650 } 717 }
651 718
652 String ScrollingCoordinator::mainThreadScrollingReasonsAsText() const 719 String ScrollingCoordinator::mainThreadScrollingReasonsAsText() const
653 { 720 {
654 return mainThreadScrollingReasonsAsText(mainThreadScrollingReasons()); 721 return mainThreadScrollingReasonsAsText(mainThreadScrollingReasons());
655 } 722 }
656 723
657 } // namespace WebCore 724 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/page/scrolling/ScrollingCoordinator.h ('k') | Source/core/rendering/RenderBlock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698