Commit 727bd37e authored by pilgrim's avatar pilgrim Committed by Commit bot

[Line Layout API] Add LineLayoutItem::resolveColor()

This addition to the line layout API has cascading effects (all good):

  1. Allows us to convert several methods in TextPainter to take a
     LineLayoutItem instead of LayoutText
  2. Removes several instances of using the LineLayoutAPIShim just to call
     the resolveColor method
  3. Converts a (required) reference of InlineBox::layoutObject() to
     lineLayoutItem()
  4. Lets us convert TextPainterTest entirely to the line layout API

There are no functional changes.

BUG=499321

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

Cr-Commit-Position: refs/heads/master@{#371932}
parent 8067d716
...@@ -324,6 +324,11 @@ public: ...@@ -324,6 +324,11 @@ public:
return m_layoutObject->selectionBackgroundColor(); return m_layoutObject->selectionBackgroundColor();
} }
Color resolveColor(const ComputedStyle& styleToUse, int colorProperty)
{
return m_layoutObject->resolveColor(styleToUse, colorProperty);
}
bool isInFlowPositioned() const bool isInFlowPositioned() const
{ {
return m_layoutObject->isInFlowPositioned(); return m_layoutObject->isInFlowPositioned();
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "core/paint/EllipsisBoxPainter.h" #include "core/paint/EllipsisBoxPainter.h"
#include "core/layout/TextRunConstructor.h" #include "core/layout/TextRunConstructor.h"
#include "core/layout/api/LineLayoutAPIShim.h" #include "core/layout/api/LineLayoutItem.h"
#include "core/layout/api/SelectionState.h" #include "core/layout/api/SelectionState.h"
#include "core/layout/line/EllipsisBox.h" #include "core/layout/line/EllipsisBox.h"
#include "core/layout/line/RootInlineBox.h" #include "core/layout/line/RootInlineBox.h"
...@@ -54,9 +54,9 @@ void EllipsisBoxPainter::paintEllipsis(const PaintInfo& paintInfo, const LayoutP ...@@ -54,9 +54,9 @@ void EllipsisBoxPainter::paintEllipsis(const PaintInfo& paintInfo, const LayoutP
else if (paintInfo.phase == PaintPhaseSelection) else if (paintInfo.phase == PaintPhaseSelection)
return; return;
TextPainter::Style textStyle = TextPainter::textPaintingStyle(m_ellipsisBox.layoutObject(), style, paintInfo); TextPainter::Style textStyle = TextPainter::textPaintingStyle(m_ellipsisBox.lineLayoutItem(), style, paintInfo);
if (haveSelection) if (haveSelection)
textStyle = TextPainter::selectionPaintingStyle(m_ellipsisBox.layoutObject(), true, paintInfo, textStyle); textStyle = TextPainter::selectionPaintingStyle(m_ellipsisBox.lineLayoutItem(), true, paintInfo, textStyle);
TextRun textRun = constructTextRun(font, m_ellipsisBox.ellipsisStr(), style, TextRun::AllowTrailingExpansion); TextRun textRun = constructTextRun(font, m_ellipsisBox.ellipsisStr(), style, TextRun::AllowTrailingExpansion);
LayoutPoint textOrigin(boxOrigin.x(), boxOrigin.y() + font.fontMetrics().ascent()); LayoutPoint textOrigin(boxOrigin.x(), boxOrigin.y() + font.fontMetrics().ascent());
...@@ -66,7 +66,7 @@ void EllipsisBoxPainter::paintEllipsis(const PaintInfo& paintInfo, const LayoutP ...@@ -66,7 +66,7 @@ void EllipsisBoxPainter::paintEllipsis(const PaintInfo& paintInfo, const LayoutP
void EllipsisBoxPainter::paintSelection(GraphicsContext& context, const LayoutPoint& boxOrigin, const ComputedStyle& style, const Font& font) void EllipsisBoxPainter::paintSelection(GraphicsContext& context, const LayoutPoint& boxOrigin, const ComputedStyle& style, const Font& font)
{ {
Color textColor = LineLayoutAPIShim::layoutObjectFrom(m_ellipsisBox.lineLayoutItem())->resolveColor(style, CSSPropertyColor); Color textColor = m_ellipsisBox.lineLayoutItem().resolveColor(style, CSSPropertyColor);
Color c = m_ellipsisBox.lineLayoutItem().selectionBackgroundColor(); Color c = m_ellipsisBox.lineLayoutItem().selectionBackgroundColor();
if (!c.alpha()) if (!c.alpha())
return; return;
......
...@@ -141,9 +141,8 @@ void InlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& ...@@ -141,9 +141,8 @@ void InlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoint&
} }
// Determine text colors. // Determine text colors.
const LayoutObject& textBoxLayoutObject = *LineLayoutAPIShim::layoutObjectFrom(m_inlineTextBox.lineLayoutItem()); TextPainter::Style textStyle = TextPainter::textPaintingStyle(m_inlineTextBox.lineLayoutItem(), styleToUse, paintInfo);
TextPainter::Style textStyle = TextPainter::textPaintingStyle(textBoxLayoutObject, styleToUse, paintInfo); TextPainter::Style selectionStyle = TextPainter::selectionPaintingStyle(m_inlineTextBox.lineLayoutItem(), haveSelection, paintInfo, textStyle);
TextPainter::Style selectionStyle = TextPainter::selectionPaintingStyle(textBoxLayoutObject, haveSelection, paintInfo, textStyle);
bool paintSelectedTextOnly = (paintInfo.phase == PaintPhaseSelection); bool paintSelectedTextOnly = (paintInfo.phase == PaintPhaseSelection);
bool paintSelectedTextSeparately = !paintSelectedTextOnly && textStyle != selectionStyle; bool paintSelectedTextSeparately = !paintSelectedTextOnly && textStyle != selectionStyle;
...@@ -157,6 +156,7 @@ void InlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& ...@@ -157,6 +156,7 @@ void InlineTextBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoint&
if (paintInfo.phase != PaintPhaseSelection && paintInfo.phase != PaintPhaseTextClip && !isPrinting) { if (paintInfo.phase != PaintPhaseSelection && paintInfo.phase != PaintPhaseTextClip && !isPrinting) {
paintDocumentMarkers(paintInfo, boxOrigin, styleToUse, font, DocumentMarkerPaintPhase::Background); paintDocumentMarkers(paintInfo, boxOrigin, styleToUse, font, DocumentMarkerPaintPhase::Background);
const LayoutObject& textBoxLayoutObject = *LineLayoutAPIShim::layoutObjectFrom(m_inlineTextBox.lineLayoutItem());
if (haveSelection && !paintsCompositionMarkers(textBoxLayoutObject)) { if (haveSelection && !paintsCompositionMarkers(textBoxLayoutObject)) {
if (combinedText) if (combinedText)
paintSelection<InlineTextBoxPainter::PaintOptions::CombinedText>(context, boxRect, styleToUse, font, selectionStyle.fillColor, combinedText); paintSelection<InlineTextBoxPainter::PaintOptions::CombinedText>(context, boxRect, styleToUse, font, selectionStyle.fillColor, combinedText);
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "core/frame/Settings.h" #include "core/frame/Settings.h"
#include "core/layout/LayoutObject.h" #include "core/layout/LayoutObject.h"
#include "core/layout/LayoutTextCombine.h" #include "core/layout/LayoutTextCombine.h"
#include "core/layout/api/LineLayoutAPIShim.h"
#include "core/layout/api/LineLayoutItem.h"
#include "core/layout/line/InlineTextBox.h" #include "core/layout/line/InlineTextBox.h"
#include "core/paint/BoxPainter.h" #include "core/paint/BoxPainter.h"
#include "core/paint/PaintInfo.h" #include "core/paint/PaintInfo.h"
...@@ -115,7 +117,7 @@ static Color textColorForWhiteBackground(Color textColor) ...@@ -115,7 +117,7 @@ static Color textColorForWhiteBackground(Color textColor)
} }
// static // static
TextPainter::Style TextPainter::textPaintingStyle(const LayoutObject& layoutObject, const ComputedStyle& style, const PaintInfo& paintInfo) TextPainter::Style TextPainter::textPaintingStyle(LineLayoutItem lineLayoutItem, const ComputedStyle& style, const PaintInfo& paintInfo)
{ {
TextPainter::Style textStyle; TextPainter::Style textStyle;
bool isPrinting = paintInfo.isPrinting(); bool isPrinting = paintInfo.isPrinting();
...@@ -130,15 +132,15 @@ TextPainter::Style TextPainter::textPaintingStyle(const LayoutObject& layoutObje ...@@ -130,15 +132,15 @@ TextPainter::Style TextPainter::textPaintingStyle(const LayoutObject& layoutObje
textStyle.shadow = 0; textStyle.shadow = 0;
} else { } else {
textStyle.currentColor = style.visitedDependentColor(CSSPropertyColor); textStyle.currentColor = style.visitedDependentColor(CSSPropertyColor);
textStyle.fillColor = layoutObject.resolveColor(style, CSSPropertyWebkitTextFillColor); textStyle.fillColor = lineLayoutItem.resolveColor(style, CSSPropertyWebkitTextFillColor);
textStyle.strokeColor = layoutObject.resolveColor(style, CSSPropertyWebkitTextStrokeColor); textStyle.strokeColor = lineLayoutItem.resolveColor(style, CSSPropertyWebkitTextStrokeColor);
textStyle.emphasisMarkColor = layoutObject.resolveColor(style, CSSPropertyWebkitTextEmphasisColor); textStyle.emphasisMarkColor = lineLayoutItem.resolveColor(style, CSSPropertyWebkitTextEmphasisColor);
textStyle.strokeWidth = style.textStrokeWidth(); textStyle.strokeWidth = style.textStrokeWidth();
textStyle.shadow = style.textShadow(); textStyle.shadow = style.textShadow();
// Adjust text color when printing with a white background. // Adjust text color when printing with a white background.
ASSERT(layoutObject.document().printing() == isPrinting); ASSERT(lineLayoutItem.document().printing() == isPrinting);
bool forceBackgroundToWhite = BoxPainter::shouldForceWhiteBackgroundForPrintEconomy(style, layoutObject.document()); bool forceBackgroundToWhite = BoxPainter::shouldForceWhiteBackgroundForPrintEconomy(style, lineLayoutItem.document());
if (forceBackgroundToWhite) { if (forceBackgroundToWhite) {
textStyle.fillColor = textColorForWhiteBackground(textStyle.fillColor); textStyle.fillColor = textColorForWhiteBackground(textStyle.fillColor);
textStyle.strokeColor = textColorForWhiteBackground(textStyle.strokeColor); textStyle.strokeColor = textColorForWhiteBackground(textStyle.strokeColor);
...@@ -153,8 +155,9 @@ TextPainter::Style TextPainter::textPaintingStyle(const LayoutObject& layoutObje ...@@ -153,8 +155,9 @@ TextPainter::Style TextPainter::textPaintingStyle(const LayoutObject& layoutObje
return textStyle; return textStyle;
} }
TextPainter::Style TextPainter::selectionPaintingStyle(const LayoutObject& layoutObject, bool haveSelection, const PaintInfo& paintInfo, const TextPainter::Style& textStyle) TextPainter::Style TextPainter::selectionPaintingStyle(LineLayoutItem lineLayoutItem, bool haveSelection, const PaintInfo& paintInfo, const TextPainter::Style& textStyle)
{ {
const LayoutObject& layoutObject = *LineLayoutAPIShim::constLayoutObjectFrom(lineLayoutItem);
TextPainter::Style selectionStyle = textStyle; TextPainter::Style selectionStyle = textStyle;
bool usesTextAsClip = paintInfo.phase == PaintPhaseTextClip; bool usesTextAsClip = paintInfo.phase == PaintPhaseTextClip;
bool isPrinting = paintInfo.isPrinting(); bool isPrinting = paintInfo.isPrinting();
......
...@@ -24,6 +24,7 @@ class GraphicsContext; ...@@ -24,6 +24,7 @@ class GraphicsContext;
class GraphicsContextStateSaver; class GraphicsContextStateSaver;
class LayoutTextCombine; class LayoutTextCombine;
class LayoutObject; class LayoutObject;
class LineLayoutItem;
struct PaintInfo; struct PaintInfo;
class ShadowList; class ShadowList;
class TextRun; class TextRun;
...@@ -64,8 +65,8 @@ public: ...@@ -64,8 +65,8 @@ public:
} }
bool operator!=(const Style& other) { return !(*this == other); } bool operator!=(const Style& other) { return !(*this == other); }
}; };
static Style textPaintingStyle(const LayoutObject&, const ComputedStyle&, const PaintInfo&); static Style textPaintingStyle(LineLayoutItem, const ComputedStyle&, const PaintInfo&);
static Style selectionPaintingStyle(const LayoutObject&, bool haveSelection, const PaintInfo&, const Style& textStyle); static Style selectionPaintingStyle(LineLayoutItem, bool haveSelection, const PaintInfo&, const Style& textStyle);
enum RotationDirection { Counterclockwise, Clockwise }; enum RotationDirection { Counterclockwise, Clockwise };
static AffineTransform rotation(const LayoutRect& boxRect, RotationDirection); static AffineTransform rotation(const LayoutRect& boxRect, RotationDirection);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "core/css/CSSPrimitiveValue.h" #include "core/css/CSSPrimitiveValue.h"
#include "core/frame/Settings.h" #include "core/frame/Settings.h"
#include "core/layout/LayoutTestHelper.h" #include "core/layout/LayoutTestHelper.h"
#include "core/layout/LayoutText.h" #include "core/layout/api/LineLayoutText.h"
#include "core/paint/PaintInfo.h" #include "core/paint/PaintInfo.h"
#include "core/style/ShadowData.h" #include "core/style/ShadowData.h"
#include "core/style/ShadowList.h" #include "core/style/ShadowList.h"
...@@ -28,7 +28,7 @@ public: ...@@ -28,7 +28,7 @@ public:
{ } { }
protected: protected:
LayoutText* layoutText() { return m_layoutText; } LineLayoutText lineLayoutText() { return LineLayoutText(m_layoutText); }
PaintInfo createPaintInfo(bool usesTextAsClip, bool isPrinting) PaintInfo createPaintInfo(bool usesTextAsClip, bool isPrinting)
{ {
...@@ -56,7 +56,7 @@ TEST_F(TextPainterTest, TextPaintingStyle_Simple) ...@@ -56,7 +56,7 @@ TEST_F(TextPainterTest, TextPaintingStyle_Simple)
document().view()->updateAllLifecyclePhases(); document().view()->updateAllLifecyclePhases();
TextPainter::Style textStyle = TextPainter::textPaintingStyle( TextPainter::Style textStyle = TextPainter::textPaintingStyle(
*layoutText(), layoutText()->styleRef(), createPaintInfo(false /* usesTextAsClip */, false /* isPrinting */)); lineLayoutText(), lineLayoutText().styleRef(), createPaintInfo(false /* usesTextAsClip */, false /* isPrinting */));
EXPECT_EQ(Color(0, 0, 255), textStyle.fillColor); EXPECT_EQ(Color(0, 0, 255), textStyle.fillColor);
EXPECT_EQ(Color(0, 0, 255), textStyle.strokeColor); EXPECT_EQ(Color(0, 0, 255), textStyle.strokeColor);
EXPECT_EQ(Color(0, 0, 255), textStyle.emphasisMarkColor); EXPECT_EQ(Color(0, 0, 255), textStyle.emphasisMarkColor);
...@@ -74,7 +74,7 @@ TEST_F(TextPainterTest, TextPaintingStyle_AllProperties) ...@@ -74,7 +74,7 @@ TEST_F(TextPainterTest, TextPaintingStyle_AllProperties)
document().view()->updateAllLifecyclePhases(); document().view()->updateAllLifecyclePhases();
TextPainter::Style textStyle = TextPainter::textPaintingStyle( TextPainter::Style textStyle = TextPainter::textPaintingStyle(
*layoutText(), layoutText()->styleRef(), createPaintInfo(false /* usesTextAsClip */, false /* isPrinting */)); lineLayoutText(), lineLayoutText().styleRef(), createPaintInfo(false /* usesTextAsClip */, false /* isPrinting */));
EXPECT_EQ(Color(255, 0, 0), textStyle.fillColor); EXPECT_EQ(Color(255, 0, 0), textStyle.fillColor);
EXPECT_EQ(Color(0, 255, 0), textStyle.strokeColor); EXPECT_EQ(Color(0, 255, 0), textStyle.strokeColor);
EXPECT_EQ(Color(0, 0, 255), textStyle.emphasisMarkColor); EXPECT_EQ(Color(0, 0, 255), textStyle.emphasisMarkColor);
...@@ -97,7 +97,7 @@ TEST_F(TextPainterTest, TextPaintingStyle_UsesTextAsClip) ...@@ -97,7 +97,7 @@ TEST_F(TextPainterTest, TextPaintingStyle_UsesTextAsClip)
document().view()->updateAllLifecyclePhases(); document().view()->updateAllLifecyclePhases();
TextPainter::Style textStyle = TextPainter::textPaintingStyle( TextPainter::Style textStyle = TextPainter::textPaintingStyle(
*layoutText(), layoutText()->styleRef(), createPaintInfo(true /* usesTextAsClip */, false /* isPrinting */)); lineLayoutText(), lineLayoutText().styleRef(), createPaintInfo(true /* usesTextAsClip */, false /* isPrinting */));
EXPECT_EQ(Color::black, textStyle.fillColor); EXPECT_EQ(Color::black, textStyle.fillColor);
EXPECT_EQ(Color::black, textStyle.strokeColor); EXPECT_EQ(Color::black, textStyle.strokeColor);
EXPECT_EQ(Color::black, textStyle.emphasisMarkColor); EXPECT_EQ(Color::black, textStyle.emphasisMarkColor);
...@@ -116,7 +116,7 @@ TEST_F(TextPainterTest, TextPaintingStyle_ForceBackgroundToWhite_NoAdjustmentNee ...@@ -116,7 +116,7 @@ TEST_F(TextPainterTest, TextPaintingStyle_ForceBackgroundToWhite_NoAdjustmentNee
document().view()->updateAllLifecyclePhases(); document().view()->updateAllLifecyclePhases();
TextPainter::Style textStyle = TextPainter::textPaintingStyle( TextPainter::Style textStyle = TextPainter::textPaintingStyle(
*layoutText(), layoutText()->styleRef(), createPaintInfo(false /* usesTextAsClip */, true /* isPrinting */)); lineLayoutText(), lineLayoutText().styleRef(), createPaintInfo(false /* usesTextAsClip */, true /* isPrinting */));
EXPECT_EQ(Color(255, 0, 0), textStyle.fillColor); EXPECT_EQ(Color(255, 0, 0), textStyle.fillColor);
EXPECT_EQ(Color(0, 255, 0), textStyle.strokeColor); EXPECT_EQ(Color(0, 255, 0), textStyle.strokeColor);
EXPECT_EQ(Color(0, 0, 255), textStyle.emphasisMarkColor); EXPECT_EQ(Color(0, 0, 255), textStyle.emphasisMarkColor);
...@@ -133,7 +133,7 @@ TEST_F(TextPainterTest, TextPaintingStyle_ForceBackgroundToWhite_Darkened) ...@@ -133,7 +133,7 @@ TEST_F(TextPainterTest, TextPaintingStyle_ForceBackgroundToWhite_Darkened)
document().view()->updateAllLifecyclePhases(); document().view()->updateAllLifecyclePhases();
TextPainter::Style textStyle = TextPainter::textPaintingStyle( TextPainter::Style textStyle = TextPainter::textPaintingStyle(
*layoutText(), layoutText()->styleRef(), createPaintInfo(false /* usesTextAsClip */, true /* isPrinting */)); lineLayoutText(), lineLayoutText().styleRef(), createPaintInfo(false /* usesTextAsClip */, true /* isPrinting */));
EXPECT_EQ(Color(255, 220, 220).dark(), textStyle.fillColor); EXPECT_EQ(Color(255, 220, 220).dark(), textStyle.fillColor);
EXPECT_EQ(Color(220, 255, 220).dark(), textStyle.strokeColor); EXPECT_EQ(Color(220, 255, 220).dark(), textStyle.strokeColor);
EXPECT_EQ(Color(220, 220, 255).dark(), textStyle.emphasisMarkColor); EXPECT_EQ(Color(220, 220, 255).dark(), textStyle.emphasisMarkColor);
......
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