Commit 4657fd08 authored by leviw@chromium.org's avatar leviw@chromium.org

Push selection gaps logic down to RenderBlockFlow

Part of my ultimate goal of de-coupling invalidation and painting of selection
gaps from one function so I can move the painting into BlockFlowPainter.

We don't actually paint selection gaps for non-blockFlow RenderBlocks. Make the
code actually represent that!

Review URL: https://codereview.chromium.org/720313002

git-svn-id: svn://svn.chromium.org/blink/trunk@185396 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent a47a6006
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "core/rendering/FloatingObjects.h" #include "core/rendering/FloatingObjects.h"
#include "core/rendering/PaintInfo.h" #include "core/rendering/PaintInfo.h"
#include "core/rendering/RenderBlockFlow.h" #include "core/rendering/RenderBlockFlow.h"
#include "core/rendering/RenderLayer.h"
namespace blink { namespace blink {
...@@ -44,4 +45,28 @@ void BlockFlowPainter::paintFloats(PaintInfo& paintInfo, const LayoutPoint& pain ...@@ -44,4 +45,28 @@ void BlockFlowPainter::paintFloats(PaintInfo& paintInfo, const LayoutPoint& pain
} }
} }
void BlockFlowPainter::paintSelection(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
if (m_renderBlockFlow.shouldPaintSelectionGaps() && paintInfo.phase == PaintPhaseForeground) {
LayoutUnit lastTop = 0;
LayoutUnit lastLeft = m_renderBlockFlow.logicalLeftSelectionOffset(&m_renderBlockFlow, lastTop);
LayoutUnit lastRight = m_renderBlockFlow.logicalRightSelectionOffset(&m_renderBlockFlow, lastTop);
GraphicsContextStateSaver stateSaver(*paintInfo.context);
LayoutRect gapRectsBounds = m_renderBlockFlow.selectionGaps(&m_renderBlockFlow, paintOffset, LayoutSize(), lastTop, lastLeft, lastRight, &paintInfo);
if (!gapRectsBounds.isEmpty()) {
RenderLayer* layer = m_renderBlockFlow.enclosingLayer();
gapRectsBounds.moveBy(-paintOffset);
if (!m_renderBlockFlow.hasLayer()) {
LayoutRect localBounds(gapRectsBounds);
m_renderBlockFlow.flipForWritingMode(localBounds);
gapRectsBounds = m_renderBlockFlow.localToContainerQuad(FloatRect(localBounds), layer->renderer()).enclosingBoundingBox();
if (layer->renderer()->hasOverflowClip())
gapRectsBounds.move(layer->renderBox()->scrolledContentOffset());
}
layer->addBlockSelectionGapsBounds(gapRectsBounds);
}
}
}
} // namespace blink } // namespace blink
...@@ -15,7 +15,7 @@ class BlockFlowPainter { ...@@ -15,7 +15,7 @@ class BlockFlowPainter {
public: public:
BlockFlowPainter(RenderBlockFlow& renderBlockFlow) : m_renderBlockFlow(renderBlockFlow) { } BlockFlowPainter(RenderBlockFlow& renderBlockFlow) : m_renderBlockFlow(renderBlockFlow) { }
void paintFloats(PaintInfo&, const LayoutPoint&, bool preservePhase); void paintFloats(PaintInfo&, const LayoutPoint&, bool preservePhase);
void paintSelection(PaintInfo&, const LayoutPoint&);
private: private:
RenderBlockFlow& m_renderBlockFlow; RenderBlockFlow& m_renderBlockFlow;
}; };
......
...@@ -196,7 +196,7 @@ void BlockPainter::paintObject(PaintInfo& paintInfo, const LayoutPoint& paintOff ...@@ -196,7 +196,7 @@ void BlockPainter::paintObject(PaintInfo& paintInfo, const LayoutPoint& paintOff
// FIXME: Make this work with multi column layouts. For now don't fill gaps. // FIXME: Make this work with multi column layouts. For now don't fill gaps.
bool isPrinting = m_renderBlock.document().printing(); bool isPrinting = m_renderBlock.document().printing();
if (!isPrinting && !m_renderBlock.hasColumns()) if (!isPrinting && !m_renderBlock.hasColumns())
paintSelection(paintInfo, scrolledOffset); // Fill in gaps in selection on lines and between blocks. m_renderBlock.paintSelection(paintInfo, scrolledOffset); // Fill in gaps in selection on lines and between blocks.
// 4. paint floats. // 4. paint floats.
if (paintPhase == PaintPhaseFloat || paintPhase == PaintPhaseSelection || paintPhase == PaintPhaseTextClip) { if (paintPhase == PaintPhaseFloat || paintPhase == PaintPhaseSelection || paintPhase == PaintPhaseTextClip) {
...@@ -441,30 +441,6 @@ void BlockPainter::paintContents(PaintInfo& paintInfo, const LayoutPoint& paintO ...@@ -441,30 +441,6 @@ void BlockPainter::paintContents(PaintInfo& paintInfo, const LayoutPoint& paintO
} }
} }
void BlockPainter::paintSelection(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
if (m_renderBlock.shouldPaintSelectionGaps() && paintInfo.phase == PaintPhaseForeground) {
LayoutUnit lastTop = 0;
LayoutUnit lastLeft = m_renderBlock.logicalLeftSelectionOffset(&m_renderBlock, lastTop);
LayoutUnit lastRight = m_renderBlock.logicalRightSelectionOffset(&m_renderBlock, lastTop);
GraphicsContextStateSaver stateSaver(*paintInfo.context);
LayoutRect gapRectsBounds = m_renderBlock.selectionGaps(&m_renderBlock, paintOffset, LayoutSize(), lastTop, lastLeft, lastRight, &paintInfo);
if (!gapRectsBounds.isEmpty()) {
RenderLayer* layer = m_renderBlock.enclosingLayer();
gapRectsBounds.moveBy(-paintOffset);
if (!m_renderBlock.hasLayer()) {
LayoutRect localBounds(gapRectsBounds);
m_renderBlock.flipForWritingMode(localBounds);
gapRectsBounds = m_renderBlock.localToContainerQuad(FloatRect(localBounds), layer->renderer()).enclosingBoundingBox();
if (layer->renderer()->hasOverflowClip())
gapRectsBounds.move(layer->renderBox()->scrolledContentOffset());
}
layer->addBlockSelectionGapsBounds(gapRectsBounds);
}
}
}
void BlockPainter::paintContinuationOutlines(PaintInfo& info, const LayoutPoint& paintOffset) void BlockPainter::paintContinuationOutlines(PaintInfo& info, const LayoutPoint& paintOffset)
{ {
RenderInline* inlineCont = m_renderBlock.inlineElementContinuation(); RenderInline* inlineCont = m_renderBlock.inlineElementContinuation();
......
...@@ -158,13 +158,6 @@ public: ...@@ -158,13 +158,6 @@ public:
LayoutUnit blockDirectionOffset(const LayoutSize& offsetFromBlock) const; LayoutUnit blockDirectionOffset(const LayoutSize& offsetFromBlock) const;
LayoutUnit inlineDirectionOffset(const LayoutSize& offsetFromBlock) const; LayoutUnit inlineDirectionOffset(const LayoutSize& offsetFromBlock) const;
virtual bool shouldPaintSelectionGaps() const override final;
GapRects selectionGapRectsForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer) const;
LayoutRect logicalLeftSelectionGap(const RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
const RenderObject* selObj, LayoutUnit logicalLeft, LayoutUnit logicalTop, LayoutUnit logicalHeight, const PaintInfo*) const;
LayoutRect logicalRightSelectionGap(const RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
const RenderObject* selObj, LayoutUnit logicalRight, LayoutUnit logicalTop, LayoutUnit logicalHeight, const PaintInfo*) const;
void getSelectionGapInfo(SelectionState, bool& leftGap, bool& rightGap) const;
RenderBlock* blockBeforeWithinSelectionRoot(LayoutSize& offset) const; RenderBlock* blockBeforeWithinSelectionRoot(LayoutSize& offset) const;
virtual void setSelectionState(SelectionState) override; virtual void setSelectionState(SelectionState) override;
...@@ -242,9 +235,6 @@ public: ...@@ -242,9 +235,6 @@ public:
virtual LayoutUnit logicalLeftSelectionOffset(const RenderBlock* rootBlock, LayoutUnit position) const; virtual LayoutUnit logicalLeftSelectionOffset(const RenderBlock* rootBlock, LayoutUnit position) const;
virtual LayoutUnit logicalRightSelectionOffset(const RenderBlock* rootBlock, LayoutUnit position) const; virtual LayoutUnit logicalRightSelectionOffset(const RenderBlock* rootBlock, LayoutUnit position) const;
GapRects selectionGaps(const RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const PaintInfo* = 0) const;
#if ENABLE(ASSERT) #if ENABLE(ASSERT)
void checkPositionedObjectsNeedLayout(); void checkPositionedObjectsNeedLayout();
bool paintsContinuationOutline(RenderInline* flow); bool paintsContinuationOutline(RenderInline* flow);
...@@ -256,8 +246,6 @@ public: ...@@ -256,8 +246,6 @@ public:
bool recalcChildOverflowAfterStyleChange(); bool recalcChildOverflowAfterStyleChange();
bool recalcOverflowAfterStyleChange(); bool recalcOverflowAfterStyleChange();
virtual LayoutRect selectionRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer) const override final;
protected: protected:
virtual void willBeDestroyed() override; virtual void willBeDestroyed() override;
...@@ -286,6 +274,7 @@ public: ...@@ -286,6 +274,7 @@ public:
// FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
virtual void paintFloats(PaintInfo&, const LayoutPoint&, bool) { } virtual void paintFloats(PaintInfo&, const LayoutPoint&, bool) { }
virtual void paintSelection(PaintInfo&, const LayoutPoint&) { }
protected: protected:
virtual void adjustInlineDirectionLineBounds(unsigned /* expansionOpportunityCount */, float& /* logicalLeft */, float& /* logicalWidth */) const { } virtual void adjustInlineDirectionLineBounds(unsigned /* expansionOpportunityCount */, float& /* logicalLeft */, float& /* logicalWidth */) const { }
...@@ -395,10 +384,6 @@ private: ...@@ -395,10 +384,6 @@ private:
virtual void childBecameNonInline(RenderObject* child) override final; virtual void childBecameNonInline(RenderObject* child) override final;
bool isSelectionRoot() const; bool isSelectionRoot() const;
GapRects blockSelectionGaps(const RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const PaintInfo*) const;
LayoutRect blockSelectionGap(const RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
LayoutUnit lastLogicalTop, LayoutUnit lastLogicalLeft, LayoutUnit lastLogicalRight, LayoutUnit logicalBottom, const PaintInfo*) const;
// FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
virtual void clipOutFloatingObjects(const RenderBlock*, const PaintInfo*, const LayoutPoint&, const LayoutSize&) const { }; virtual void clipOutFloatingObjects(const RenderBlock*, const PaintInfo*, const LayoutPoint&, const LayoutSize&) const { };
......
...@@ -181,8 +181,23 @@ public: ...@@ -181,8 +181,23 @@ public:
// FIXME: This should be const to avoid a const_cast, but can modify child dirty bits and RenderCombineText // FIXME: This should be const to avoid a const_cast, but can modify child dirty bits and RenderCombineText
void computeInlinePreferredLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth); void computeInlinePreferredLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth);
virtual bool shouldPaintSelectionGaps() const override final;
LayoutRect logicalLeftSelectionGap(const RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
const RenderObject* selObj, LayoutUnit logicalLeft, LayoutUnit logicalTop, LayoutUnit logicalHeight, const PaintInfo*) const;
LayoutRect logicalRightSelectionGap(const RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
const RenderObject* selObj, LayoutUnit logicalRight, LayoutUnit logicalTop, LayoutUnit logicalHeight, const PaintInfo*) const;
void getSelectionGapInfo(SelectionState, bool& leftGap, bool& rightGap) const;
virtual LayoutRect selectionRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer) const override final;
GapRects selectionGapRectsForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer) const;
GapRects selectionGaps(const RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const PaintInfo* = 0) const;
GapRects inlineSelectionGaps(const RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock, GapRects inlineSelectionGaps(const RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const PaintInfo*) const; LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const PaintInfo*) const;
GapRects blockSelectionGaps(const RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const PaintInfo*) const;
LayoutRect blockSelectionGap(const RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
LayoutUnit lastLogicalTop, LayoutUnit lastLogicalLeft, LayoutUnit lastLogicalRight, LayoutUnit logicalBottom, const PaintInfo*) const;
LayoutUnit paginationStrut() const { return m_rareData ? m_rareData->m_paginationStrut : LayoutUnit(); } LayoutUnit paginationStrut() const { return m_rareData ? m_rareData->m_paginationStrut : LayoutUnit(); }
void setPaginationStrut(LayoutUnit); void setPaginationStrut(LayoutUnit);
...@@ -267,6 +282,7 @@ private: ...@@ -267,6 +282,7 @@ private:
virtual void invalidatePaintForOverhangingFloats(bool paintAllDescendants) override final; virtual void invalidatePaintForOverhangingFloats(bool paintAllDescendants) override final;
virtual void invalidatePaintForOverflow() override final; virtual void invalidatePaintForOverflow() override final;
virtual void paintFloats(PaintInfo&, const LayoutPoint&, bool preservePhase = false) override final; virtual void paintFloats(PaintInfo&, const LayoutPoint&, bool preservePhase = false) override final;
virtual void paintSelection(PaintInfo&, const LayoutPoint&) override final;
virtual void clipOutFloatingObjects(const RenderBlock*, const PaintInfo*, const LayoutPoint&, const LayoutSize&) const override; virtual void clipOutFloatingObjects(const RenderBlock*, const PaintInfo*, const LayoutPoint&, const LayoutSize&) const override;
void clearFloats(EClear); void clearFloats(EClear);
......
...@@ -2156,11 +2156,11 @@ void RenderLayer::invalidatePaintForBlockSelectionGaps() ...@@ -2156,11 +2156,11 @@ void RenderLayer::invalidatePaintForBlockSelectionGaps()
IntRect RenderLayer::blockSelectionGapsBounds() const IntRect RenderLayer::blockSelectionGapsBounds() const
{ {
if (!renderer()->isRenderBlock()) if (!renderer()->isRenderBlockFlow())
return IntRect(); return IntRect();
RenderBlock* renderBlock = toRenderBlock(renderer()); RenderBlockFlow* renderBlockFlow = toRenderBlockFlow(renderer());
LayoutRect gapRects = renderBlock->selectionGapRectsForPaintInvalidation(renderBlock); LayoutRect gapRects = renderBlockFlow->selectionGapRectsForPaintInvalidation(renderBlockFlow);
return pixelSnappedIntRect(gapRects); return pixelSnappedIntRect(gapRects);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment