Commit 04283387 authored by jbroman@chromium.org's avatar jbroman@chromium.org

Simplify InlineFlowBox::paintBoxDecorations.

This change:
* simplifies the paintPhase checks in InlineFlowBox::paint
* clarifies and moves the "should paint box decorations" check above
  other work, including the roundedFrameRect computation
* makes some internal painting methods private
* fixes the name of "adjustedPaintOffset"
* resolves lint errors that arose during the above

3% reduction in record time on desktop Wikipedia.
Negligible impact on N7 key_silk_cases.

BUG=388946

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

git-svn-id: svn://svn.chromium.org/blink/trunk@177180 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 5a38d268
......@@ -1095,7 +1095,6 @@ void InlineFlowBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset,
if (!paintInfo.rect.intersects(pixelSnappedIntRect(overflowRect)))
return;
if (paintInfo.phase != PaintPhaseChildOutlines) {
if (paintInfo.phase == PaintPhaseOutline || paintInfo.phase == PaintPhaseSelfOutline) {
// Add ourselves to the paint info struct's list of inlines that need to paint their
// outlines.
......@@ -1109,9 +1108,9 @@ void InlineFlowBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset,
// after a child removal. As a result, those merged inlines do not get seperated and hence not get enclosed by
// anonymous blocks. In this case, it is better to bail out and paint it ourself.
RenderBlock* enclosingAnonymousBlock = renderer().containingBlock();
if (!enclosingAnonymousBlock->isAnonymousBlock())
if (!enclosingAnonymousBlock->isAnonymousBlock()) {
containingBlockPaintsContinuationOutline = false;
else {
} else {
cb = enclosingAnonymousBlock->containingBlock();
for (RenderBoxModelObject* box = boxModelObject(); box != cb; box = box->parent()->enclosingBoxModelObject()) {
if (box->hasSelfPaintingLayer()) {
......@@ -1133,21 +1132,15 @@ void InlineFlowBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset,
} else if (paintInfo.phase == PaintPhaseMask) {
paintMask(paintInfo, paintOffset);
return;
} else {
} else if (paintInfo.phase == PaintPhaseForeground) {
// Paint our background, border and box-shadow.
paintBoxDecorations(paintInfo, paintOffset);
}
}
if (paintInfo.phase == PaintPhaseMask)
return;
PaintPhase paintPhase = paintInfo.phase == PaintPhaseChildOutlines ? PaintPhaseOutline : paintInfo.phase;
// Paint our children.
if (paintPhase != PaintPhaseSelfOutline) {
if (paintInfo.phase != PaintPhaseSelfOutline) {
PaintInfo childInfo(paintInfo);
childInfo.phase = paintPhase;
childInfo.phase = paintInfo.phase == PaintPhaseChildOutlines ? PaintPhaseOutline : paintInfo.phase;
if (childInfo.paintingRoot && childInfo.paintingRoot->isDescendantOf(&renderer()))
childInfo.paintingRoot = 0;
......@@ -1281,32 +1274,39 @@ static LayoutRect clipRectForNinePieceImageStrip(InlineFlowBox* box, const NineP
void InlineFlowBox::paintBoxDecorations(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
if (!paintInfo.shouldPaintWithinRoot(&renderer()) || renderer().style()->visibility() != VISIBLE || paintInfo.phase != PaintPhaseForeground)
ASSERT(paintInfo.phase == PaintPhaseForeground);
if (!paintInfo.shouldPaintWithinRoot(&renderer()) || renderer().style()->visibility() != VISIBLE)
return;
// You can use p::first-line to specify a background. If so, the root line boxes for
// a line may actually have to paint a background.
RenderStyle* styleToUse = renderer().style(isFirstLineStyle());
bool shouldPaintBoxDecorations;
if (parent())
shouldPaintBoxDecorations = renderer().hasBoxDecorations();
else
shouldPaintBoxDecorations = isFirstLineStyle() && styleToUse != renderer().style();
if (!shouldPaintBoxDecorations)
return;
// Pixel snap background/border painting.
LayoutRect frameRect = roundedFrameRect();
constrainToLineTopAndBottomIfNeeded(frameRect);
// Move x/y to our coordinates.
LayoutRect localRect(frameRect);
flipForWritingMode(localRect);
LayoutPoint adjustedPaintoffset = paintOffset + localRect.location();
LayoutPoint adjustedPaintOffset = paintOffset + localRect.location();
GraphicsContext* context = paintInfo.context;
LayoutRect paintRect = LayoutRect(adjustedPaintOffset, frameRect.size());
// You can use p::first-line to specify a background. If so, the root line boxes for
// a line may actually have to paint a background.
RenderStyle* styleToUse = renderer().style(isFirstLineStyle());
if ((!parent() && isFirstLineStyle() && styleToUse != renderer().style()) || (parent() && renderer().hasBoxDecorations())) {
LayoutRect paintRect = LayoutRect(adjustedPaintoffset, frameRect.size());
// Shadow comes first and is behind the background and border.
if (!boxModelObject()->boxShadowShouldBeAppliedToBackground(BackgroundBleedNone, this))
paintBoxShadow(paintInfo, styleToUse, Normal, paintRect);
Color c = renderer().resolveColor(styleToUse, CSSPropertyBackgroundColor);
paintFillLayers(paintInfo, c, styleToUse->backgroundLayers(), paintRect);
Color backgroundColor = renderer().resolveColor(styleToUse, CSSPropertyBackgroundColor);
paintFillLayers(paintInfo, backgroundColor, styleToUse->backgroundLayers(), paintRect);
paintBoxShadow(paintInfo, styleToUse, Inset, paintRect);
// :first-line cannot be used to put borders on a line. Always paint borders with our
......@@ -1318,11 +1318,11 @@ void InlineFlowBox::paintBoxDecorations(PaintInfo& paintInfo, const LayoutPoint&
if (hasBorderImage && !borderImageSource->isLoaded())
return; // Don't paint anything while we wait for the image to load.
// The simple case is where we either have no border image or we are the only box for this object. In those
// cases only a single call to draw is required.
if (!hasBorderImage || (!prevLineBox() && !nextLineBox()))
// The simple case is where we either have no border image or we are the only box for this object.
// In those cases only a single call to draw is required.
if (!hasBorderImage || (!prevLineBox() && !nextLineBox())) {
boxModelObject()->paintBorder(paintInfo, paintRect, renderer().style(isFirstLineStyle()), BackgroundBleedNone, includeLogicalLeftEdge(), includeLogicalRightEdge());
else {
} else {
// We have a border image that spans multiple lines.
// We need to adjust tx and ty by the width of all previous lines.
// Think of border image painting on inlines as though you had one long line, a single continuous
......@@ -1337,18 +1337,17 @@ void InlineFlowBox::paintBoxDecorations(PaintInfo& paintInfo, const LayoutPoint&
LayoutUnit totalLogicalWidth = logicalOffsetOnLine;
for (InlineFlowBox* curr = this; curr; curr = curr->nextLineBox())
totalLogicalWidth += curr->logicalWidth();
LayoutUnit stripX = adjustedPaintoffset.x() - (isHorizontal() ? logicalOffsetOnLine : LayoutUnit());
LayoutUnit stripY = adjustedPaintoffset.y() - (isHorizontal() ? LayoutUnit() : logicalOffsetOnLine);
LayoutUnit stripX = adjustedPaintOffset.x() - (isHorizontal() ? logicalOffsetOnLine : LayoutUnit());
LayoutUnit stripY = adjustedPaintOffset.y() - (isHorizontal() ? LayoutUnit() : logicalOffsetOnLine);
LayoutUnit stripWidth = isHorizontal() ? totalLogicalWidth : frameRect.width();
LayoutUnit stripHeight = isHorizontal() ? frameRect.height() : totalLogicalWidth;
LayoutRect clipRect = clipRectForNinePieceImageStrip(this, borderImage, paintRect);
GraphicsContextStateSaver stateSaver(*context);
context->clip(clipRect);
GraphicsContextStateSaver stateSaver(*paintInfo.context);
paintInfo.context->clip(clipRect);
boxModelObject()->paintBorder(paintInfo, LayoutRect(stripX, stripY, stripWidth, stripHeight), renderer().style(isFirstLineStyle()));
}
}
}
}
void InlineFlowBox::paintMask(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
......
......@@ -112,11 +112,6 @@ public:
IntRect roundedFrameRect() const;
void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
void paintMask(PaintInfo&, const LayoutPoint&);
void paintFillLayers(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, CompositeOperator = CompositeSourceOver);
void paintFillLayer(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, CompositeOperator = CompositeSourceOver);
void paintBoxShadow(const PaintInfo&, RenderStyle*, ShadowStyle, const LayoutRect&);
virtual void paint(PaintInfo&, const LayoutPoint&, LayoutUnit lineTop, LayoutUnit lineBottom) OVERRIDE;
virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom) OVERRIDE;
......@@ -301,6 +296,12 @@ public:
}
private:
void paintBoxDecorations(PaintInfo&, const LayoutPoint&);
void paintMask(PaintInfo&, const LayoutPoint&);
void paintFillLayers(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, CompositeOperator = CompositeSourceOver);
void paintFillLayer(const PaintInfo&, const Color&, const FillLayer*, const LayoutRect&, CompositeOperator = CompositeSourceOver);
void paintBoxShadow(const PaintInfo&, RenderStyle*, ShadowStyle, const LayoutRect&);
void addBoxShadowVisualOverflow(LayoutRect& logicalVisualOverflow);
void addBorderOutsetVisualOverflow(LayoutRect& logicalVisualOverflow);
void addOutlineVisualOverflow(LayoutRect& logicalVisualOverflow);
......
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