Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 WebVector<WebRect> webRects(rects.size()); | 103 WebVector<WebRect> webRects(rects.size()); |
| 99 for (size_t i = 0; i < rects.size(); ++i) | 104 for (size_t i = 0; i < rects.size(); ++i) |
| 100 webRects[i] = rects[i]; | 105 webRects[i] = rects[i]; |
| 101 scrollLayer->setNonFastScrollableRegion(webRects); | 106 scrollLayer->setNonFastScrollableRegion(webRects); |
| 102 } | 107 } |
| 103 } | 108 } |
| 104 | 109 |
| 105 void ScrollingCoordinator::frameViewLayoutUpdated(FrameView* frameView) | 110 void ScrollingCoordinator::frameViewLayoutUpdated(FrameView* frameView) |
| 106 { | 111 { |
| 107 ASSERT(m_page); | 112 ASSERT(m_page); |
| 113 if (!RuntimeEnabledFeatures::touchEnabled()) | |
| 114 return; | |
| 115 | |
| 116 TRACE_EVENT0("input", "ScrollingCoordinator::frameViewLayoutUpdated"); | |
| 108 | 117 |
| 109 // Compute the region of the page that we can't handle scroll gestures on im pl thread: | 118 // Compute the region of the page that we can't handle scroll gestures on im pl thread: |
| 110 // This currently includes: | 119 // This currently includes: |
| 111 // 1. All scrollable areas, such as subframes, overflow divs and list boxes, whose composited | 120 // 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 | 121 // 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. | 122 // 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 | 123 // 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. | 124 // CSS property "resize" is enabled. |
| 116 // 3. Plugin areas. | 125 // 3. Plugin areas. |
| 117 Region shouldHandleScrollGestureOnMainThreadRegion = computeShouldHandleScro llGestureOnMainThreadRegion(m_page->mainFrame(), IntPoint()); | 126 Region shouldHandleScrollGestureOnMainThreadRegion = computeShouldHandleScro llGestureOnMainThreadRegion(m_page->mainFrame(), IntPoint()); |
| 118 setShouldHandleScrollGestureOnMainThreadRegion(shouldHandleScrollGestureOnMa inThreadRegion); | 127 setShouldHandleScrollGestureOnMainThreadRegion(shouldHandleScrollGestureOnMa inThreadRegion); |
| 119 Vector<IntRect> touchEventTargetRects; | 128 LayerHitTestRects touchEventTargetRects; |
| 120 computeAbsoluteTouchEventTargetRects(m_page->mainFrame()->document(), touchE ventTargetRects); | 129 computeTouchEventTargetRects(touchEventTargetRects); |
| 121 setTouchEventTargetRects(touchEventTargetRects); | 130 setTouchEventTargetRects(touchEventTargetRects); |
| 122 if (WebLayer* scrollLayer = scrollingWebLayerForScrollableArea(frameView)) | 131 if (WebLayer* scrollLayer = scrollingWebLayerForScrollableArea(frameView)) |
| 123 scrollLayer->setBounds(frameView->contentsSize()); | 132 scrollLayer->setBounds(frameView->contentsSize()); |
| 124 } | 133 } |
| 125 | 134 |
| 126 void ScrollingCoordinator::setLayerIsContainerForFixedPositionLayers(GraphicsLay er* layer, bool enable) | 135 void ScrollingCoordinator::setLayerIsContainerForFixedPositionLayers(GraphicsLay er* layer, bool enable) |
| 127 { | 136 { |
| 128 if (WebLayer* scrollableLayer = scrollingWebLayerForGraphicsLayer(layer)) | 137 if (WebLayer* scrollableLayer = scrollingWebLayerForGraphicsLayer(layer)) |
| 129 scrollableLayer->setIsContainerForFixedPositionLayers(enable); | 138 scrollableLayer->setIsContainerForFixedPositionLayers(enable); |
| 130 } | 139 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 } | 298 } |
| 290 if (WebScrollbarLayer* scrollbarLayer = getWebScrollbarLayer(scrollableArea, VerticalScrollbar)) { | 299 if (WebScrollbarLayer* scrollbarLayer = getWebScrollbarLayer(scrollableArea, VerticalScrollbar)) { |
| 291 GraphicsLayer* verticalScrollbarLayer = verticalScrollbarLayerForScrolla bleArea(scrollableArea); | 300 GraphicsLayer* verticalScrollbarLayer = verticalScrollbarLayerForScrolla bleArea(scrollableArea); |
| 292 if (verticalScrollbarLayer) | 301 if (verticalScrollbarLayer) |
| 293 setupScrollbarLayer(verticalScrollbarLayer, scrollbarLayer, webLayer ); | 302 setupScrollbarLayer(verticalScrollbarLayer, scrollbarLayer, webLayer ); |
| 294 } | 303 } |
| 295 | 304 |
| 296 return !!webLayer; | 305 return !!webLayer; |
| 297 } | 306 } |
| 298 | 307 |
| 299 void ScrollingCoordinator::setTouchEventTargetRects(const Vector<IntRect>& absol uteHitTestRects) | 308 static void convertLayerRectsToEnclosingCompositedLayer(const LayerHitTestRects& layerRects, LayerHitTestRects& compositorRects) |
| 300 { | 309 { |
| 301 if (WebLayer* scrollLayer = scrollingWebLayerForScrollableArea(m_page->mainF rame()->view())) { | 310 // 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()); | 311 // enclosing composited layer. |
| 303 for (size_t i = 0; i < absoluteHitTestRects.size(); ++i) | 312 for (LayerHitTestRects::const_iterator layerIter = layerRects.begin(); layer Iter != layerRects.end(); ++layerIter) { |
| 304 webRects[i] = absoluteHitTestRects[i]; | 313 // Find the enclosing composited layer when it's in another document (fo r non-composited iframes). |
| 305 scrollLayer->setTouchEventHandlerRegion(webRects); | 314 RenderLayer* compositedLayer = 0; |
| 315 for (const RenderLayer* layer = layerIter->key; !compositedLayer;) { | |
| 316 compositedLayer = layer->enclosingCompositingLayerForRepaint(); | |
| 317 if (!compositedLayer) { | |
| 318 RenderObject* owner = layer->renderer()->frame()->ownerRenderer( ); | |
| 319 if (!owner) | |
| 320 break; | |
| 321 layer = owner->enclosingLayer(); | |
| 322 } | |
| 323 } | |
| 324 // This page may not have compositing enabled at all. | |
|
leviw_travelin_and_unemployed
2013/07/18 20:23:03
So I get that, but then we should return, not cont
| |
| 325 if (!compositedLayer) | |
| 326 continue; | |
| 327 | |
| 328 LayerHitTestRects::iterator compIter = compositorRects.find(compositedLa yer); | |
| 329 if (compIter == compositorRects.end()) | |
| 330 compIter = compositorRects.add(compositedLayer, Vector<IntRect>()).i terator; | |
| 331 | |
| 332 // Transform each rect to the co-ordinate space of it's enclosing compos ited layer. | |
| 333 // Ideally we'd compute a transformation matrix once and re-use it for e ach rect, but | |
| 334 // there doesn't appear to be any easy way to do it (mapLocalToContainer will flatten | |
| 335 // the TransformState, so we can't use setQuad/mappedQuad over and over again). Perhaps | |
| 336 // RenderGeometryMap? | |
| 337 for (size_t i = 0; i < layerIter->value.size(); ++i) { | |
| 338 FloatQuad localQuad(layerIter->value[i]); | |
| 339 TransformState transformState(TransformState::ApplyTransformDirectio n, localQuad); | |
| 340 MapCoordinatesFlags flags = ApplyContainerFlip | UseTransforms | Tra verseDocumentBoundaries; | |
| 341 layerIter->key->renderer()->mapLocalToContainer(compositedLayer->ren derer(), transformState, flags); | |
| 342 transformState.flatten(); | |
| 343 IntRect compositorRect = enclosingIntRect(transformState.lastPlanarQ uad().boundingBox()); | |
| 344 compIter->value.append(compositorRect); | |
| 345 } | |
| 346 } | |
| 347 } | |
| 348 | |
| 349 void ScrollingCoordinator::setTouchEventTargetRects(const LayerHitTestRects& lay erRects) | |
| 350 { | |
| 351 TRACE_EVENT0("input", "ScrollingCoordinator::setTouchEventTargetRects"); | |
| 352 | |
| 353 LayerHitTestRects compositorRects; | |
| 354 convertLayerRectsToEnclosingCompositedLayer(layerRects, compositorRects); | |
| 355 | |
| 356 // Inform any observers (i.e. for testing) of these new rects. | |
| 357 HashSet<TouchEventTargetRectsObserver*>::iterator stop = m_touchEventTargetR ectsObservers.end(); | |
| 358 for (HashSet<TouchEventTargetRectsObserver*>::iterator it = m_touchEventTarg etRectsObservers.begin(); it != stop; ++it) | |
| 359 (*it)->touchEventTargetRectsChanged(compositorRects); | |
| 360 | |
| 361 // Note that ideally we'd clear the touch event handler region on all layers first, | |
| 362 // in case there are others that no longer have any handlers. But it's unlik ely to | |
| 363 // matter much in practice (just makes us more conservative). | |
| 364 for (LayerHitTestRects::const_iterator iter = compositorRects.begin(); iter != compositorRects.end(); ++iter) { | |
| 365 WebVector<WebRect> webRects(iter->value.size()); | |
| 366 for (size_t i = 0; i < iter->value.size(); ++i) | |
| 367 webRects[i] = iter->value[i]; | |
| 368 RenderLayerBacking* backing = iter->key->backing(); | |
| 369 // If the layer is using composited scrolling, then it's the contents th at these | |
| 370 // rects apply to. | |
| 371 GraphicsLayer* graphicsLayer = backing->scrollingContentsLayer(); | |
| 372 if (!graphicsLayer) | |
| 373 graphicsLayer = backing->graphicsLayer(); | |
| 374 graphicsLayer->platformLayer()->setTouchEventHandlerRegion(webRects); | |
| 306 } | 375 } |
| 307 } | 376 } |
| 308 | 377 |
| 309 void ScrollingCoordinator::touchEventTargetRectsDidChange(const Document*) | 378 void ScrollingCoordinator::touchEventTargetRectsDidChange(const Document*) |
| 310 { | 379 { |
| 311 // The rects are always evaluated and used in the main frame coordinates. | 380 if (!RuntimeEnabledFeatures::touchEnabled()) |
| 312 FrameView* frameView = m_page->mainFrame()->view(); | 381 return; |
| 313 Document* document = m_page->mainFrame()->document(); | |
| 314 | 382 |
| 315 // Wait until after layout to update. | 383 // Wait until after layout to update. |
| 316 if (frameView->needsLayout() || !document) | 384 if (m_page->mainFrame()->view()->needsLayout()) |
| 317 return; | 385 return; |
| 318 | 386 |
| 319 Vector<IntRect> touchEventTargetRects; | 387 TRACE_EVENT0("input", "ScrollingCoordinator::touchEventTargetRectsDidChange" ); |
| 320 computeAbsoluteTouchEventTargetRects(document, touchEventTargetRects); | 388 |
| 389 LayerHitTestRects touchEventTargetRects; | |
| 390 computeTouchEventTargetRects(touchEventTargetRects); | |
| 321 setTouchEventTargetRects(touchEventTargetRects); | 391 setTouchEventTargetRects(touchEventTargetRects); |
| 322 } | 392 } |
| 323 | 393 |
| 324 void ScrollingCoordinator::setWheelEventHandlerCount(unsigned count) | 394 void ScrollingCoordinator::setWheelEventHandlerCount(unsigned count) |
| 325 { | 395 { |
| 326 if (WebLayer* scrollLayer = scrollingWebLayerForScrollableArea(m_page->mainF rame()->view())) | 396 if (WebLayer* scrollLayer = scrollingWebLayerForScrollableArea(m_page->mainF rame()->view())) |
| 327 scrollLayer->setHaveWheelEventHandlers(count > 0); | 397 scrollLayer->setHaveWheelEventHandlers(count > 0); |
| 328 } | 398 } |
| 329 | 399 |
| 330 void ScrollingCoordinator::recomputeWheelEventHandlerCountForFrameView(FrameView * frameView) | 400 void ScrollingCoordinator::recomputeWheelEventHandlerCountForFrameView(FrameView * frameView) |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 356 | 426 |
| 357 // We currently only support composited mode. | 427 // We currently only support composited mode. |
| 358 RenderView* renderView = m_page->mainFrame()->contentRenderer(); | 428 RenderView* renderView = m_page->mainFrame()->contentRenderer(); |
| 359 if (!renderView) | 429 if (!renderView) |
| 360 return false; | 430 return false; |
| 361 return renderView->usesCompositing(); | 431 return renderView->usesCompositing(); |
| 362 } | 432 } |
| 363 | 433 |
| 364 Region ScrollingCoordinator::computeShouldHandleScrollGestureOnMainThreadRegion( const Frame* frame, const IntPoint& frameLocation) const | 434 Region ScrollingCoordinator::computeShouldHandleScrollGestureOnMainThreadRegion( const Frame* frame, const IntPoint& frameLocation) const |
| 365 { | 435 { |
| 436 TRACE_EVENT0("input", "ScrollingCoordinator::computeShouldHandleScrollGestur eOnMainThreadRegion"); | |
| 366 Region shouldHandleScrollGestureOnMainThreadRegion; | 437 Region shouldHandleScrollGestureOnMainThreadRegion; |
| 367 FrameView* frameView = frame->view(); | 438 FrameView* frameView = frame->view(); |
| 368 if (!frameView) | 439 if (!frameView) |
| 369 return shouldHandleScrollGestureOnMainThreadRegion; | 440 return shouldHandleScrollGestureOnMainThreadRegion; |
| 370 | 441 |
| 371 IntPoint offset = frameLocation; | 442 IntPoint offset = frameLocation; |
| 372 offset.moveBy(frameView->frameRect().location()); | 443 offset.moveBy(frameView->frameRect().location()); |
| 373 | 444 |
| 374 if (const FrameView::ScrollableAreaSet* scrollableAreas = frameView->scrolla bleAreas()) { | 445 if (const FrameView::ScrollableAreaSet* scrollableAreas = frameView->scrolla bleAreas()) { |
| 375 for (FrameView::ScrollableAreaSet::const_iterator it = scrollableAreas-> begin(), end = scrollableAreas->end(); it != end; ++it) { | 446 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 Loading... | |
| 408 } | 479 } |
| 409 } | 480 } |
| 410 | 481 |
| 411 FrameTree* tree = frame->tree(); | 482 FrameTree* tree = frame->tree(); |
| 412 for (Frame* subFrame = tree->firstChild(); subFrame; subFrame = subFrame->tr ee()->nextSibling()) | 483 for (Frame* subFrame = tree->firstChild(); subFrame; subFrame = subFrame->tr ee()->nextSibling()) |
| 413 shouldHandleScrollGestureOnMainThreadRegion.unite(computeShouldHandleScr ollGestureOnMainThreadRegion(subFrame, offset)); | 484 shouldHandleScrollGestureOnMainThreadRegion.unite(computeShouldHandleScr ollGestureOnMainThreadRegion(subFrame, offset)); |
| 414 | 485 |
| 415 return shouldHandleScrollGestureOnMainThreadRegion; | 486 return shouldHandleScrollGestureOnMainThreadRegion; |
| 416 } | 487 } |
| 417 | 488 |
| 418 static void accumulateRendererTouchEventTargetRects(Vector<IntRect>& rects, cons t RenderObject* renderer, const IntRect& parentRect = IntRect()) | 489 void ScrollingCoordinator::addTouchEventTargetRectsObserver(TouchEventTargetRect sObserver* observer) |
| 419 { | 490 { |
| 420 IntRect adjustedParentRect = parentRect; | 491 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 } | 492 } |
| 439 | 493 |
| 440 static void accumulateDocumentEventTargetRects(Vector<IntRect>& rects, const Doc ument* document) | 494 void ScrollingCoordinator::removeTouchEventTargetRectsObserver(TouchEventTargetR ectsObserver* observer) |
| 495 { | |
| 496 m_touchEventTargetRectsObservers.remove(observer); | |
| 497 } | |
| 498 | |
| 499 static void accumulateDocumentTouchEventTargetRects(LayerHitTestRects& rects, co nst Document* document) | |
| 441 { | 500 { |
| 442 ASSERT(document); | 501 ASSERT(document); |
| 443 if (!document->touchEventTargets()) | 502 if (!document->touchEventTargets()) |
| 444 return; | 503 return; |
| 445 | 504 |
| 446 const TouchEventTargetSet* targets = document->touchEventTargets(); | 505 const TouchEventTargetSet* targets = document->touchEventTargets(); |
| 506 | |
| 507 // If there's a handler on the document, html or body element (fairly common in practice), | |
| 508 // then we can quickly mark the entire document and skip looking at any othe r handlers. | |
| 509 // Note that technically a handler on the body doesn't cover the whole docum ent, but it's | |
| 510 // reasonable to be conservative and report the whole document anyway. | |
| 447 for (TouchEventTargetSet::const_iterator iter = targets->begin(); iter != ta rgets->end(); ++iter) { | 511 for (TouchEventTargetSet::const_iterator iter = targets->begin(); iter != ta rgets->end(); ++iter) { |
| 448 const Node* touchTarget = iter->key; | 512 Node* target = iter->key; |
| 449 if (!touchTarget->inDocument()) | 513 if (target == document || target == document->documentElement() || targe t == document->body()) { |
| 450 continue; | 514 if (RenderObject* renderer = document->renderer()) { |
| 451 | 515 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 } | 516 } |
| 466 return; | 517 return; |
| 467 } | 518 } |
| 519 } | |
| 468 | 520 |
| 469 if (touchTarget->isDocumentNode() && touchTarget != document) { | 521 for (TouchEventTargetSet::const_iterator iter = targets->begin(); iter != ta rgets->end(); ++iter) { |
| 470 accumulateDocumentEventTargetRects(rects, toDocument(touchTarget)); | 522 const Node* target = iter->key; |
| 523 if (!target->inDocument()) | |
| 471 continue; | 524 continue; |
| 525 | |
| 526 if (target->isDocumentNode()) { | |
| 527 ASSERT(target != document); | |
| 528 accumulateDocumentTouchEventTargetRects(rects, toDocument(target)); | |
| 529 } else if (RenderObject* renderer = target->renderer()) { | |
| 530 renderer->computeLayerHitTestRects(rects); | |
| 472 } | 531 } |
| 532 } | |
| 473 | 533 |
| 474 if (RenderObject* renderer = touchTarget->renderer()) | |
| 475 accumulateRendererTouchEventTargetRects(rects, renderer); | |
| 476 } | |
| 477 } | 534 } |
| 478 | 535 |
| 479 void ScrollingCoordinator::computeAbsoluteTouchEventTargetRects(const Document* document, Vector<IntRect>& rects) | 536 void ScrollingCoordinator::computeTouchEventTargetRects(LayerHitTestRects& rects ) |
| 480 { | 537 { |
| 481 ASSERT(document); | 538 TRACE_EVENT0("input", "ScrollingCoordinator::computeTouchEventTargetRects"); |
| 482 if (!document->view()) | 539 |
| 540 Document* document = m_page->mainFrame()->document(); | |
| 541 if (!document || !document->view()) | |
| 483 return; | 542 return; |
| 484 | 543 |
| 485 // FIXME: These rects won't be properly updated if the renderers are in a su b-tree that scrolls. | 544 accumulateDocumentTouchEventTargetRects(rects, document); |
| 486 accumulateDocumentEventTargetRects(rects, document); | |
| 487 } | 545 } |
| 488 | 546 |
| 489 unsigned ScrollingCoordinator::computeCurrentWheelEventHandlerCount() | 547 unsigned ScrollingCoordinator::computeCurrentWheelEventHandlerCount() |
| 490 { | 548 { |
| 491 unsigned wheelEventHandlerCount = 0; | 549 unsigned wheelEventHandlerCount = 0; |
| 492 | 550 |
| 493 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->trave rseNext()) { | 551 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->trave rseNext()) { |
| 494 if (frame->document()) | 552 if (frame->document()) |
| 495 wheelEventHandlerCount += frame->document()->wheelEventHandlerCount( ); | 553 wheelEventHandlerCount += frame->document()->wheelEventHandlerCount( ); |
| 496 } | 554 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 648 stringBuilder.resize(stringBuilder.length() - 2); | 706 stringBuilder.resize(stringBuilder.length() - 2); |
| 649 return stringBuilder.toString(); | 707 return stringBuilder.toString(); |
| 650 } | 708 } |
| 651 | 709 |
| 652 String ScrollingCoordinator::mainThreadScrollingReasonsAsText() const | 710 String ScrollingCoordinator::mainThreadScrollingReasonsAsText() const |
| 653 { | 711 { |
| 654 return mainThreadScrollingReasonsAsText(mainThreadScrollingReasons()); | 712 return mainThreadScrollingReasonsAsText(mainThreadScrollingReasons()); |
| 655 } | 713 } |
| 656 | 714 |
| 657 } // namespace WebCore | 715 } // namespace WebCore |
| OLD | NEW |