Skip to content

Instantly share code, notes, and snippets.

@iamralpht
Created December 14, 2012 23:21
Show Gist options
  • Save iamralpht/4289534 to your computer and use it in GitHub Desktop.
Save iamralpht/4289534 to your computer and use it in GitHub Desktop.
Reduce the number of rects emitted by computeAbsoluteTouchEventTargetRects
diff --git a/Source/WebCore/page/scrolling/ScrollingCoordinator.cpp b/Source/WebCore/page/scrolling/ScrollingCoordinator.cpp
index 1d8ad6a..d56bb11 100644
--- a/Source/WebCore/page/scrolling/ScrollingCoordinator.cpp
+++ b/Source/WebCore/page/scrolling/ScrollingCoordinator.cpp
@@ -149,14 +149,18 @@ static Region computeNonFastScrollableRegion(Frame* frame, const IntPoint& frame
}
#if ENABLE(TOUCH_EVENT_TRACKING)
-static void accumulateRendererTouchEventTargetRects(Vector<IntRect>& rects, const RenderObject* renderer)
+static void accumulateRendererTouchEventTargetRects(Vector<IntRect>& rects, const RenderObject* renderer, IntRect container)
{
// FIXME: This method is O(N^2) as it walks the tree to the root for every renderer. RenderGeometryMap would fix this.
- rects.append(enclosingIntRect(renderer->clippedOverflowRectForRepaint(0)));
+ IntRect r = enclosingIntRect(renderer->clippedOverflowRectForRepaint(0));
+ if (!r.isEmpty() && !container.contains(r)) {
+ rects.append(r);
+ container = r;
+ }
if (renderer->isRenderBlock()) {
const RenderBlock* block = toRenderBlock(renderer);
for (RenderObject* child = block->firstChild(); child; child = child->nextSibling())
- accumulateRendererTouchEventTargetRects(rects, child);
+ accumulateRendererTouchEventTargetRects(rects, child, container);
}
}
@@ -168,10 +172,12 @@ static void accumulateDocumentEventTargetRects(Vector<IntRect>& rects, const Doc
const TouchEventTargetSet* targets = document->touchEventTargets();
for (TouchEventTargetSet::const_iterator iter = targets->begin(); iter != targets->end(); ++iter) {
- const Node* touchTarget = iter->key;
+ const Node* touchTarget = iter->first;
if (touchTarget == document) {
- if (RenderView* view = document->renderView())
- rects.append(enclosingIntRect(view->clippedOverflowRectForRepaint(0)));
+ if (RenderView* view = document->renderView()) {
+ IntRect r = enclosingIntRect(view->clippedOverflowRectForRepaint(0));
+ if (!r.isEmpty()) rects.append(r);
+ }
return;
}
@@ -181,7 +187,7 @@ static void accumulateDocumentEventTargetRects(Vector<IntRect>& rects, const Doc
}
if (RenderObject* renderer = touchTarget->renderer())
- accumulateRendererTouchEventTargetRects(rects, renderer);
+ accumulateRendererTouchEventTargetRects(rects, renderer, IntRect());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment