From 850e0e2db6c93528cee37127f9a0315010bfd155 Mon Sep 17 00:00:00 2001 From: "jchaffraix@webkit.org" Date: Tue, 21 Feb 2012 19:59:42 +0000 Subject: [PATCH] Move RenderLayer::scrolledContentOffset calls to a common function https://bugs.webkit.org/show_bug.cgi?id=76971 Reviewed by David Hyatt. Refactoring without any change in behavior. This change adds a RenderBox::scrolledContentOffset function to handle all the calls that goes through the layer(). This indirection will enable us to add layer() checks without patching a lot of call sites as part of bug 75568. We also moved down the concept of scroll offset down to RenderBox where it belongs! * rendering/RenderLayer.h: (RenderLayer): (WebCore::RenderLayer::scrolledContentOffset): Moved scrolledContent to the private section of the class to prevent misuse. * rendering/RenderBox.cpp: (WebCore::RenderBox::scrolledContentOffset): New function to add an indirection with RenderLayer. * editing/visible_units.cpp: (WebCore::absoluteLineDirectionPointToLocalPointInBlock): * rendering/LayoutState.cpp: (WebCore::LayoutState::LayoutState): * rendering/RenderBlock.cpp: (WebCore::RenderBlock::layoutBlock): (WebCore::RenderBlock::paintObject): (WebCore::RenderBlock::selectionGapRectsForRepaint): (WebCore::RenderBlock::paintSelection): (WebCore::RenderBlock::nodeAtPoint): (WebCore::RenderBlock::offsetForContents): * rendering/RenderBox.cpp: (WebCore::RenderBox::offsetFromContainer): (WebCore::RenderBox::computeRectForRepaint): * rendering/RenderBox.h: (RenderBox): * rendering/RenderBoxModelObject.cpp: (WebCore::RenderBoxModelObject::paintFillLayerExtended): * rendering/RenderInline.cpp: (WebCore::RenderInline::clippedOverflowRectForRepaint): (WebCore::RenderInline::computeRectForRepaint): (WebCore::RenderInline::offsetFromContainer): * rendering/RenderObject.cpp: (WebCore::RenderObject::computeRectForRepaint): (WebCore::RenderObject::mapLocalToContainer): (WebCore::RenderObject::mapAbsoluteToLocalPoint): (WebCore::RenderObject::offsetFromContainer): * rendering/RenderTextControlSingleLine.cpp: (WebCore::RenderTextControlInnerBlock::positionForPoint): Patched all those call sites to use the new function. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@108382 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebCore/ChangeLog | 55 ++++++++++++++++++++++ Source/WebCore/editing/visible_units.cpp | 2 +- Source/WebCore/rendering/LayoutState.cpp | 7 +-- Source/WebCore/rendering/RenderBlock.cpp | 16 +++---- Source/WebCore/rendering/RenderBox.cpp | 11 ++++- Source/WebCore/rendering/RenderBox.h | 2 + Source/WebCore/rendering/RenderBoxModelObject.cpp | 5 +- Source/WebCore/rendering/RenderInline.cpp | 6 +-- Source/WebCore/rendering/RenderLayer.h | 5 +- Source/WebCore/rendering/RenderObject.cpp | 8 ++-- .../rendering/RenderTextControlSingleLine.cpp | 2 +- 11 files changed, 93 insertions(+), 26 deletions(-) diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 8a61ab1..5b5c043 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,58 @@ +2012-02-21 Julien Chaffraix + + Move RenderLayer::scrolledContentOffset calls to a common function + https://bugs.webkit.org/show_bug.cgi?id=76971 + + Reviewed by David Hyatt. + + Refactoring without any change in behavior. + + This change adds a RenderBox::scrolledContentOffset function to handle all + the calls that goes through the layer(). This indirection will enable us to + add layer() checks without patching a lot of call sites as part of bug 75568. + + We also moved down the concept of scroll offset down to RenderBox where it belongs! + + * rendering/RenderLayer.h: + (RenderLayer): + (WebCore::RenderLayer::scrolledContentOffset): + Moved scrolledContent to the private section of the class to prevent misuse. + + * rendering/RenderBox.cpp: + (WebCore::RenderBox::scrolledContentOffset): + New function to add an indirection with RenderLayer. + + * editing/visible_units.cpp: + (WebCore::absoluteLineDirectionPointToLocalPointInBlock): + * rendering/LayoutState.cpp: + (WebCore::LayoutState::LayoutState): + * rendering/RenderBlock.cpp: + (WebCore::RenderBlock::layoutBlock): + (WebCore::RenderBlock::paintObject): + (WebCore::RenderBlock::selectionGapRectsForRepaint): + (WebCore::RenderBlock::paintSelection): + (WebCore::RenderBlock::nodeAtPoint): + (WebCore::RenderBlock::offsetForContents): + * rendering/RenderBox.cpp: + (WebCore::RenderBox::offsetFromContainer): + (WebCore::RenderBox::computeRectForRepaint): + * rendering/RenderBox.h: + (RenderBox): + * rendering/RenderBoxModelObject.cpp: + (WebCore::RenderBoxModelObject::paintFillLayerExtended): + * rendering/RenderInline.cpp: + (WebCore::RenderInline::clippedOverflowRectForRepaint): + (WebCore::RenderInline::computeRectForRepaint): + (WebCore::RenderInline::offsetFromContainer): + * rendering/RenderObject.cpp: + (WebCore::RenderObject::computeRectForRepaint): + (WebCore::RenderObject::mapLocalToContainer): + (WebCore::RenderObject::mapAbsoluteToLocalPoint): + (WebCore::RenderObject::offsetFromContainer): + * rendering/RenderTextControlSingleLine.cpp: + (WebCore::RenderTextControlInnerBlock::positionForPoint): + Patched all those call sites to use the new function. + 2012-02-21 Emil A Eklund Remove obsolete float comparison FIXMEs diff --git a/Source/WebCore/editing/visible_units.cpp b/Source/WebCore/editing/visible_units.cpp index a078e18..db89259 100644 --- a/Source/WebCore/editing/visible_units.cpp +++ b/Source/WebCore/editing/visible_units.cpp @@ -545,7 +545,7 @@ static inline IntPoint absoluteLineDirectionPointToLocalPointInBlock(RootInlineB RenderBlock* containingBlock = root->block(); FloatPoint absoluteBlockPoint = containingBlock->localToAbsolute(FloatPoint()); if (containingBlock->hasOverflowClip()) - absoluteBlockPoint -= containingBlock->layer()->scrolledContentOffset(); + absoluteBlockPoint -= containingBlock->scrolledContentOffset(); if (root->block()->isHorizontalWritingMode()) return IntPoint(lineDirectionPoint - absoluteBlockPoint.x(), root->blockDirectionPointInLine()); diff --git a/Source/WebCore/rendering/LayoutState.cpp b/Source/WebCore/rendering/LayoutState.cpp index c9018c5..e89dcc5 100644 --- a/Source/WebCore/rendering/LayoutState.cpp +++ b/Source/WebCore/rendering/LayoutState.cpp @@ -79,7 +79,7 @@ LayoutState::LayoutState(LayoutState* prev, RenderBox* renderer, const LayoutSiz m_clipped = true; } - m_paintOffset -= layer->scrolledContentOffset(); + m_paintOffset -= renderer->scrolledContentOffset(); } // If we establish a new page height, then cache the offset to the top of the first page. @@ -156,10 +156,11 @@ LayoutState::LayoutState(RenderObject* root) m_paintOffset = LayoutSize(absContentPoint.x(), absContentPoint.y()); if (container->hasOverflowClip()) { - RenderLayer* layer = toRenderBoxModelObject(container)->layer(); + RenderBox* containerBox = toRenderBox(container); + RenderLayer* layer = containerBox->layer(); m_clipped = true; m_clipRect = LayoutRect(toPoint(m_paintOffset), layer->size()); - m_paintOffset -= layer->scrolledContentOffset(); + m_paintOffset -= containerBox->scrolledContentOffset(); } } diff --git a/Source/WebCore/rendering/RenderBlock.cpp b/Source/WebCore/rendering/RenderBlock.cpp index 0af7e3a..11f5a1d 100755 --- a/Source/WebCore/rendering/RenderBlock.cpp +++ b/Source/WebCore/rendering/RenderBlock.cpp @@ -1509,7 +1509,7 @@ void RenderBlock::layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeigh if (hasOverflowClip()) { // Adjust repaint rect for scroll offset - repaintRect.move(-layer()->scrolledContentOffset()); + repaintRect.move(-scrolledContentOffset()); // Don't allow this rect to spill out of our overflow box. repaintRect.intersect(LayoutRect(LayoutPoint(), size())); @@ -2771,7 +2771,7 @@ void RenderBlock::paintObject(PaintInfo& paintInfo, const LayoutPoint& paintOffs // Adjust our painting position if we're inside a scrolled layer (e.g., an overflow:auto div). LayoutPoint scrolledOffset = paintOffset; if (hasOverflowClip()) - scrolledOffset.move(-layer()->scrolledContentOffset()); + scrolledOffset.move(-scrolledContentOffset()); // 2. paint contents if (paintPhase != PaintPhaseSelfOutline) { @@ -3019,7 +3019,7 @@ GapRects RenderBlock::selectionGapRectsForRepaint(RenderBoxModelObject* repaintC LayoutPoint offsetFromRepaintContainer = roundedLayoutPoint(transformState.mappedPoint()); if (hasOverflowClip()) - offsetFromRepaintContainer -= layer()->scrolledContentOffset(); + offsetFromRepaintContainer -= scrolledContentOffset(); LayoutUnit lastTop = 0; LayoutUnit lastLeft = logicalLeftSelectionOffset(this, lastTop); @@ -3044,7 +3044,8 @@ void RenderBlock::paintSelection(PaintInfo& paintInfo, const LayoutPoint& paintO LayoutRect localBounds(gapRectsBounds); flipForWritingMode(localBounds); gapRectsBounds = localToContainerQuad(FloatRect(localBounds), layer->renderer()).enclosingBoundingBox(); - gapRectsBounds.move(layer->scrolledContentOffset()); + if (layer->renderer()->hasOverflowClip()) + gapRectsBounds.move(layer->renderBox()->scrolledContentOffset()); } layer->addBlockSelectionGapsBounds(gapRectsBounds); } @@ -4332,9 +4333,8 @@ bool RenderBlock::nodeAtPoint(const HitTestRequest& request, HitTestResult& resu if (checkChildren) { // Hit test descendants first. LayoutSize scrolledOffset(localOffset); - if (hasOverflowClip()) { - scrolledOffset -= layer()->scrolledContentOffset(); - } + if (hasOverflowClip()) + scrolledOffset -= scrolledContentOffset(); // Hit test contents if we don't have columns. if (!hasColumns()) { @@ -4681,7 +4681,7 @@ VisiblePosition RenderBlock::positionForPoint(const LayoutPoint& point) void RenderBlock::offsetForContents(LayoutPoint& offset) const { if (hasOverflowClip()) - offset += layer()->scrolledContentOffset(); + offset += scrolledContentOffset(); if (hasColumns()) adjustPointToColumnContents(offset); diff --git a/Source/WebCore/rendering/RenderBox.cpp b/Source/WebCore/rendering/RenderBox.cpp index 24ace51..d21c240 100644 --- a/Source/WebCore/rendering/RenderBox.cpp +++ b/Source/WebCore/rendering/RenderBox.cpp @@ -746,6 +746,13 @@ bool RenderBox::needsPreferredWidthsRecalculation() const return style()->paddingStart().isPercent() || style()->paddingEnd().isPercent(); } +IntSize RenderBox::scrolledContentOffset() const +{ + ASSERT(hasOverflowClip()); + ASSERT(hasLayer()); + return layer()->scrolledContentOffset(); +} + LayoutUnit RenderBox::minPreferredLogicalWidth() const { if (preferredLogicalWidthsDirty()) @@ -1433,7 +1440,7 @@ LayoutSize RenderBox::offsetFromContainer(RenderObject* o, const LayoutPoint& po } if (o->hasOverflowClip()) - offset -= toRenderBox(o)->layer()->scrolledContentOffset(); + offset -= toRenderBox(o)->scrolledContentOffset(); if (style()->position() == AbsolutePosition && o->isRelPositioned() && o->isRenderInline()) offset += toRenderInline(o)->relativePositionedInlineOffset(this); @@ -1632,7 +1639,7 @@ void RenderBox::computeRectForRepaint(RenderBoxModelObject* repaintContainer, La // o->height() is inaccurate if we're in the middle of a layout of |o|, so use the // layer's size instead. Even if the layer's size is wrong, the layer itself will repaint // anyway if its size does change. - topLeft -= containerBox->layer()->scrolledContentOffset(); // For overflow:auto/scroll/hidden. + topLeft -= containerBox->scrolledContentOffset(); // For overflow:auto/scroll/hidden. LayoutRect repaintRect(topLeft, rect.size()); LayoutRect boxRect(LayoutPoint(), containerBox->layer()->size()); diff --git a/Source/WebCore/rendering/RenderBox.h b/Source/WebCore/rendering/RenderBox.h index 8725424..31ec39a 100644 --- a/Source/WebCore/rendering/RenderBox.h +++ b/Source/WebCore/rendering/RenderBox.h @@ -447,6 +447,8 @@ public: virtual bool needsPreferredWidthsRecalculation() const; virtual void computeIntrinsicRatioInformation(FloatSize& /* intrinsicSize */, double& /* intrinsicRatio */, bool& /* isPercentageIntrinsicSize */) const { } + IntSize scrolledContentOffset() const; + protected: virtual void willBeDestroyed(); diff --git a/Source/WebCore/rendering/RenderBoxModelObject.cpp b/Source/WebCore/rendering/RenderBoxModelObject.cpp index f73387e..c66710e 100644 --- a/Source/WebCore/rendering/RenderBoxModelObject.cpp +++ b/Source/WebCore/rendering/RenderBoxModelObject.cpp @@ -727,10 +727,11 @@ void RenderBoxModelObject::paintFillLayerExtended(const PaintInfo& paintInfo, co LayoutRect scrolledPaintRect = rect; if (clippedWithLocalScrolling) { // Clip to the overflow area. - context->clip(toRenderBox(this)->overflowClipRect(rect.location(), paintInfo.renderRegion)); + RenderBox* thisBox = toRenderBox(this); + context->clip(thisBox->overflowClipRect(rect.location(), paintInfo.renderRegion)); // Adjust the paint rect to reflect a scrolled content box with borders at the ends. - LayoutSize offset = layer()->scrolledContentOffset(); + IntSize offset = thisBox->scrolledContentOffset(); scrolledPaintRect.move(-offset); scrolledPaintRect.setWidth(bLeft + layer()->scrollWidth() + bRight); scrolledPaintRect.setHeight(borderTop() + layer()->scrollHeight() + borderBottom()); diff --git a/Source/WebCore/rendering/RenderInline.cpp b/Source/WebCore/rendering/RenderInline.cpp index f09681a..e16310f 100644 --- a/Source/WebCore/rendering/RenderInline.cpp +++ b/Source/WebCore/rendering/RenderInline.cpp @@ -1031,7 +1031,7 @@ LayoutRect RenderInline::clippedOverflowRectForRepaint(RenderBoxModelObject* rep // layer's size instead. Even if the layer's size is wrong, the layer itself will repaint // anyway if its size does change. LayoutRect repaintRect(r); - repaintRect.move(-cb->layer()->scrolledContentOffset()); // For overflow:auto/scroll/hidden. + repaintRect.move(-cb->scrolledContentOffset()); // For overflow:auto/scroll/hidden. LayoutRect boxRect(LayoutPoint(), cb->layer()->size()); r = intersection(repaintRect, boxRect); @@ -1132,7 +1132,7 @@ void RenderInline::computeRectForRepaint(RenderBoxModelObject* repaintContainer, // o->height() is inaccurate if we're in the middle of a layout of |o|, so use the // layer's size instead. Even if the layer's size is wrong, the layer itself will repaint // anyway if its size does change. - topLeft -= containerBox->layer()->scrolledContentOffset(); // For overflow:auto/scroll/hidden. + topLeft -= containerBox->scrolledContentOffset(); // For overflow:auto/scroll/hidden. LayoutRect repaintRect(topLeft, rect.size()); LayoutRect boxRect(LayoutPoint(), containerBox->layer()->size()); @@ -1163,7 +1163,7 @@ LayoutSize RenderInline::offsetFromContainer(RenderObject* container, const Layo container->adjustForColumns(offset, point); if (container->hasOverflowClip()) - offset -= toRenderBox(container)->layer()->scrolledContentOffset(); + offset -= toRenderBox(container)->scrolledContentOffset(); return offset; } diff --git a/Source/WebCore/rendering/RenderLayer.h b/Source/WebCore/rendering/RenderLayer.h index 4d8b5bb..4c5be0c 100644 --- a/Source/WebCore/rendering/RenderLayer.h +++ b/Source/WebCore/rendering/RenderLayer.h @@ -295,8 +295,6 @@ public: // Scrolling methods for layers that can scroll their overflow. void scrollByRecursively(LayoutUnit xDelta, LayoutUnit yDelta, ScrollOffsetClamping = ScrollOffsetUnclamped); - IntSize scrolledContentOffset() const { return scrollOffset() + roundedIntSize(m_scrollOverflow); } - int scrollXOffset() const { return m_scrollOffset.width() + scrollOrigin().x(); } int scrollYOffset() const { return m_scrollOffset.height() + scrollOrigin().y(); } IntSize scrollOffset() const { return IntSize(scrollXOffset(), scrollYOffset()); } @@ -579,6 +577,9 @@ private: bool shouldRepaintAfterLayout() const; + friend IntSize RenderBox::scrolledContentOffset() const; + IntSize scrolledContentOffset() const { return scrollOffset() + m_scrollOverflow; } + // The normal operator new is disallowed on all render objects. void* operator new(size_t) throw(); diff --git a/Source/WebCore/rendering/RenderObject.cpp b/Source/WebCore/rendering/RenderObject.cpp index 7ff4343..4813db8 100755 --- a/Source/WebCore/rendering/RenderObject.cpp +++ b/Source/WebCore/rendering/RenderObject.cpp @@ -1506,7 +1506,7 @@ void RenderObject::computeRectForRepaint(RenderBoxModelObject* repaintContainer, RenderBox* boxParent = toRenderBox(o); LayoutRect repaintRect(rect); - repaintRect.move(-boxParent->layer()->scrolledContentOffset()); // For overflow:auto/scroll/hidden. + repaintRect.move(-boxParent->scrolledContentOffset()); // For overflow:auto/scroll/hidden. LayoutRect boxRect(LayoutPoint(), boxParent->layer()->size()); rect = intersection(repaintRect, boxRect); @@ -2018,7 +2018,7 @@ void RenderObject::mapLocalToContainer(RenderBoxModelObject* repaintContainer, b transformState.move(columnOffset); if (o->hasOverflowClip()) - transformState.move(-toRenderBox(o)->layer()->scrolledContentOffset()); + transformState.move(-toRenderBox(o)->scrolledContentOffset()); o->mapLocalToContainer(repaintContainer, fixed, useTransforms, transformState, wasFixed); } @@ -2029,7 +2029,7 @@ void RenderObject::mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, Trans if (o) { o->mapAbsoluteToLocalPoint(fixed, useTransforms, transformState); if (o->hasOverflowClip()) - transformState.move(toRenderBox(o)->layer()->scrolledContentOffset()); + transformState.move(toRenderBox(o)->scrolledContentOffset()); } } @@ -2091,7 +2091,7 @@ LayoutSize RenderObject::offsetFromContainer(RenderObject* o, const LayoutPoint& o->adjustForColumns(offset, point); if (o->hasOverflowClip()) - offset -= toRenderBox(o)->layer()->scrolledContentOffset(); + offset -= toRenderBox(o)->scrolledContentOffset(); return offset; } diff --git a/Source/WebCore/rendering/RenderTextControlSingleLine.cpp b/Source/WebCore/rendering/RenderTextControlSingleLine.cpp index 7891a3f..a44e288 100644 --- a/Source/WebCore/rendering/RenderTextControlSingleLine.cpp +++ b/Source/WebCore/rendering/RenderTextControlSingleLine.cpp @@ -60,7 +60,7 @@ VisiblePosition RenderTextControlInnerBlock::positionForPoint(const LayoutPoint& if (m_multiLine) { RenderTextControl* renderer = toRenderTextControl(node()->shadowAncestorNode()->renderer()); if (renderer->hasOverflowClip()) - contentsPoint += renderer->layer()->scrolledContentOffset(); + contentsPoint += renderer->scrolledContentOffset(); } return RenderBlock::positionForPoint(contentsPoint); -- 2.7.4