Changeset 119736 in webkit
- Timestamp:
- Jun 7, 2012, 10:57:00 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r119733 r119736 1 2012-06-07 Simon Fraser <simon.fraser@apple.com> 2 3 Optimize FrameView::scrollXForFixedPosition() / scrollYForFixedPosition() 4 https://bugs.webkit.org/show_bug.cgi?id=88475 5 6 Reviewed by Sam Weinig. 7 8 FrameView's scrollXForFixedPosition() and scrollYForFixedPosition() 9 methods were often called together, but they do duplicate work, 10 including calling into platform widget code which might be slow. 11 12 Fix by converting scrollOffsetForFixedPosition() from being a wrapper 13 that just calls scrollXForFixedPosition() and scrollYForFixedPosition() 14 to the method that does all the work, calling just once into platform 15 widget code. 16 17 Changed callers to use scrollOffsetForFixedPosition() rather than make 18 two separate method calls. 19 20 Added ScrollView::layoutSize() and visibleSize() methods for 21 convenience. 22 23 Removed FrameView::scrollXForFixedPosition and FrameView::scrollYForFixedPosition 24 to avoid inefficient callers in future. 25 26 No new tests; refactoring only. 27 28 * page/FrameView.cpp: 29 (WebCore::fixedPositionScrollOffset): 30 (WebCore::FrameView::scrollOffsetForFixedPosition): 31 * page/FrameView.h: Removed scrollXForFixedPosition and scrollYForFixedPosition. 32 * platform/ScrollView.cpp: 33 (WebCore::ScrollView::layoutSize): 34 * platform/ScrollView.h: 35 (WebCore::ScrollView::visibleSize): 36 * rendering/RenderLayer.cpp: 37 (WebCore::RenderLayer::backgroundClipRect): 38 * rendering/RenderLayer.h: 39 (WebCore::ClipRect::move): 40 * rendering/RenderLayerCompositor.cpp: 41 (WebCore::RenderLayerCompositor::requiresCompositingForPosition): 42 * rendering/RenderView.cpp: 43 (WebCore::RenderView::computeRectForRepaint): 44 1 45 2012-06-07 Raymes Khoury <raymes@chromium.org> 2 46 -
trunk/Source/WebCore/page/FrameView.cpp
r119378 r119736 1373 1373 } 1374 1374 1375 int FrameView::scrollXForFixedPosition() const 1376 { 1377 int visibleContentWidth = visibleContentRect().width(); 1378 int maxX = contentsWidth() - visibleContentWidth; 1379 1380 if (maxX == 0) 1375 static int fixedPositionScrollOffset(int scrollPosition, int maxValue, int scrollOrigin, float dragFactor) 1376 { 1377 if (!maxValue) 1381 1378 return 0; 1382 1379 1383 int x = scrollX(); 1384 1385 if (!scrollOrigin().x()) { 1386 if (x < 0) 1387 x = 0; 1388 else if (x > maxX) 1389 x = maxX; 1380 if (!scrollOrigin) { 1381 if (scrollPosition < 0) 1382 scrollPosition = 0; 1383 else if (scrollPosition > maxValue) 1384 scrollPosition = maxValue; 1390 1385 } else { 1391 if (x > 0) 1392 x = 0; 1393 else if (x < -maxX) 1394 x = -maxX; 1395 } 1396 1397 if (!m_frame) 1398 return x; 1399 1400 float frameScaleFactor = m_frame->frameScaleFactor(); 1401 1402 // When the page is scaled, the scaled "viewport" with respect to which fixed object are positioned 1403 // doesn't move as fast as the content view, so that when the content is scrolled all the way to the 1404 // end, the bottom of the scaled "viewport" touches the bottom of the real viewport. 1405 float dragFactor = fixedElementsLayoutRelativeToFrame() ? 1 : (contentsWidth() - visibleContentWidth * frameScaleFactor) / maxX; 1406 1407 return x * dragFactor / frameScaleFactor; 1408 } 1409 1410 int FrameView::scrollYForFixedPosition() const 1411 { 1412 int visibleContentHeight = visibleContentRect().height(); 1413 1414 int maxY = contentsHeight() - visibleContentHeight; 1415 if (maxY == 0) 1416 return 0; 1417 1418 int y = scrollY(); 1419 1420 if (!scrollOrigin().y()) { 1421 if (y < 0) 1422 y = 0; 1423 else if (y > maxY) 1424 y = maxY; 1425 } else { 1426 if (y > 0) 1427 y = 0; 1428 else if (y < -maxY) 1429 y = -maxY; 1430 } 1431 1432 if (!m_frame) 1433 return y; 1434 1435 float frameScaleFactor = m_frame->frameScaleFactor(); 1436 float dragFactor = fixedElementsLayoutRelativeToFrame() ? 1 : (contentsHeight() - visibleContentHeight * frameScaleFactor) / maxY; 1437 return y * dragFactor / frameScaleFactor; 1386 if (scrollPosition > 0) 1387 scrollPosition = 0; 1388 else if (scrollPosition < -maxValue) 1389 scrollPosition = -maxValue; 1390 } 1391 1392 return scrollPosition * dragFactor; 1438 1393 } 1439 1394 1440 1395 IntSize FrameView::scrollOffsetForFixedPosition() const 1441 1396 { 1442 return IntSize(scrollXForFixedPosition(), scrollYForFixedPosition()); 1397 IntRect visibleContentRect = this->visibleContentRect(); 1398 IntSize contentsSize = this->contentsSize(); 1399 IntPoint scrollPosition = this->scrollPosition(); 1400 IntPoint scrollOrigin = this->scrollOrigin(); 1401 1402 IntSize maxOffset(contentsSize.width() - visibleContentRect.width(), contentsSize.height() - visibleContentRect.height()); 1403 1404 float frameScaleFactor = m_frame ? m_frame->frameScaleFactor() : 1; 1405 1406 FloatSize dragFactor = fixedElementsLayoutRelativeToFrame() ? FloatSize(1, 1) : FloatSize( 1407 (contentsSize.width() - visibleContentRect.width() * frameScaleFactor) / maxOffset.width(), 1408 (contentsSize.height() - visibleContentRect.height() * frameScaleFactor) / maxOffset.height()); 1409 1410 int x = fixedPositionScrollOffset(scrollPosition.x(), maxOffset.width(), scrollOrigin.x(), dragFactor.width() / frameScaleFactor); 1411 int y = fixedPositionScrollOffset(scrollPosition.y(), maxOffset.height(), scrollOrigin.y(), dragFactor.height() / frameScaleFactor); 1412 1413 return IntSize(x, y); 1443 1414 } 1444 1415 -
trunk/Source/WebCore/page/FrameView.h
r116799 r119736 201 201 // Functions for querying the current scrolled position, negating the effects of overhang 202 202 // and adjusting for page scale. 203 int scrollXForFixedPosition() const;204 int scrollYForFixedPosition() const;205 203 IntSize scrollOffsetForFixedPosition() const; 206 204 -
trunk/Source/WebCore/platform/ScrollView.cpp
r117069 r119736 253 253 #endif 254 254 255 IntSize ScrollView::layoutSize() const 256 { 257 return m_fixedLayoutSize.isEmpty() || !m_useFixedLayout ? visibleSize() : m_fixedLayoutSize; 258 } 259 255 260 int ScrollView::layoutWidth() const 256 261 { -
trunk/Source/WebCore/platform/ScrollView.h
r117069 r119736 147 147 virtual void setFixedVisibleContentRect(const IntRect& visibleContentRect) { m_fixedVisibleContentRect = visibleContentRect; } 148 148 IntRect fixedVisibleContentRect() const { return m_fixedVisibleContentRect; } 149 IntSize visibleSize() const { return visibleContentRect().size(); } 149 150 int visibleWidth() const { return visibleContentRect().width(); } 150 151 int visibleHeight() const { return visibleContentRect().height(); } … … 152 153 // Functions for getting/setting the size webkit should use to layout the contents. By default this is the same as the visible 153 154 // content size. Explicitly setting a layout size value will cause webkit to layout the contents using this size instead. 155 IntSize layoutSize() const; 154 156 int layoutWidth() const; 155 157 int layoutHeight() const; -
trunk/Source/WebCore/rendering/RenderLayer.cpp
r119676 r119736 3903 3903 // Note: infinite clipRects should not be scrolled here, otherwise they will accidentally no longer be considered infinite. 3904 3904 if (parentRects.fixed() && rootLayer->renderer() == view && backgroundClipRect != PaintInfo::infiniteRect()) 3905 backgroundClipRect.move(view->frameView()->scroll XForFixedPosition(), view->frameView()->scrollYForFixedPosition());3905 backgroundClipRect.move(view->frameView()->scrollOffsetForFixedPosition()); 3906 3906 3907 3907 return backgroundClipRect; -
trunk/Source/WebCore/rendering/RenderLayer.h
r119676 r119736 112 112 } 113 113 void move(LayoutUnit x, LayoutUnit y) { m_rect.move(x, y); } 114 void move(const LayoutSize& size) { m_rect.move(size); } 114 115 115 116 bool isEmpty() const { return m_rect.isEmpty(); } -
trunk/Source/WebCore/rendering/RenderLayerCompositor.cpp
r119529 r119736 1805 1805 // Fixed position elements that are invisible in the current view don't get their own layer. 1806 1806 FrameView* frameView = m_renderView->frameView(); 1807 if (frameView && !layer->absoluteBoundingBox().intersects(IntRect( frameView->scrollXForFixedPosition(), frameView->scrollYForFixedPosition(), frameView->layoutWidth(), frameView->layoutHeight())))1807 if (frameView && !layer->absoluteBoundingBox().intersects(IntRect(IntPoint(frameView->scrollOffsetForFixedPosition()), frameView->layoutSize()))) 1808 1808 return false; 1809 1809 -
trunk/Source/WebCore/rendering/RenderView.cpp
r119548 r119736 391 391 392 392 if (fixed && m_frameView) 393 rect.move(m_frameView->scroll XForFixedPosition(), m_frameView->scrollYForFixedPosition());393 rect.move(m_frameView->scrollOffsetForFixedPosition()); 394 394 395 395 // Apply our transform if we have one (because of full page zooming).
Note:
See TracChangeset
for help on using the changeset viewer.