OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/paint/TextPainter.h" | 6 #include "core/paint/TextPainter.h" |
7 | 7 |
8 #include "core/CSSPropertyNames.h" | 8 #include "core/CSSPropertyNames.h" |
9 #include "core/CSSValueKeywords.h" | 9 #include "core/CSSValueKeywords.h" |
10 #include "core/css/CSSPrimitiveValue.h" | 10 #include "core/css/CSSPrimitiveValue.h" |
11 #include "core/frame/Settings.h" | 11 #include "core/frame/Settings.h" |
12 #include "core/layout/LayoutTestHelper.h" | 12 #include "core/layout/LayoutTestHelper.h" |
13 #include "core/layout/LayoutText.h" | 13 #include "core/layout/LayoutText.h" |
14 #include "core/style/ShadowData.h" | 14 #include "core/style/ShadowData.h" |
15 #include "core/style/ShadowList.h" | 15 #include "core/style/ShadowList.h" |
16 #include <gtest/gtest.h> | 16 #include <gtest/gtest.h> |
17 | 17 |
18 namespace blink { | 18 namespace blink { |
19 namespace { | 19 namespace { |
20 | 20 |
21 class TextPainterTest : public RenderingTest { | 21 class TextPainterTest : public RenderingTest { |
22 public: | 22 public: |
23 TextPainterTest() : m_renderText(nullptr) { } | 23 TextPainterTest() : m_renderText(nullptr) { } |
24 | 24 |
25 protected: | 25 protected: |
26 LayoutText* renderText() { return m_renderText; } | 26 LayoutText* layoutText() { return m_renderText; } |
27 | 27 |
28 private: | 28 private: |
29 virtual void SetUp() override | 29 virtual void SetUp() override |
30 { | 30 { |
31 RenderingTest::SetUp(); | 31 RenderingTest::SetUp(); |
32 setBodyInnerHTML("Hello world"); | 32 setBodyInnerHTML("Hello world"); |
33 m_renderText = toLayoutText(document().body()->firstChild()->layoutObjec
t()); | 33 m_renderText = toLayoutText(document().body()->firstChild()->layoutObjec
t()); |
34 ASSERT_TRUE(m_renderText); | 34 ASSERT_TRUE(m_renderText); |
35 ASSERT_EQ("Hello world", m_renderText->text()); | 35 ASSERT_EQ("Hello world", m_renderText->text()); |
36 } | 36 } |
37 | 37 |
38 LayoutText* m_renderText; | 38 LayoutText* m_renderText; |
39 }; | 39 }; |
40 | 40 |
41 TEST_F(TextPainterTest, TextPaintingStyle_Simple) | 41 TEST_F(TextPainterTest, TextPaintingStyle_Simple) |
42 { | 42 { |
43 document().body()->setInlineStyleProperty(CSSPropertyColor, CSSValueBlue); | 43 document().body()->setInlineStyleProperty(CSSPropertyColor, CSSValueBlue); |
44 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 44 document().view()->updateLayoutAndStyleIfNeededRecursive(); |
45 | 45 |
46 TextPainter::Style textStyle = TextPainter::textPaintingStyle( | 46 TextPainter::Style textStyle = TextPainter::textPaintingStyle( |
47 *renderText(), renderText()->styleRef(), false /* forceBlackText */, fal
se /* isPrinting */); | 47 *layoutText(), layoutText()->styleRef(), false /* forceBlackText */, fal
se /* isPrinting */); |
48 EXPECT_EQ(Color(0, 0, 255), textStyle.fillColor); | 48 EXPECT_EQ(Color(0, 0, 255), textStyle.fillColor); |
49 EXPECT_EQ(Color(0, 0, 255), textStyle.strokeColor); | 49 EXPECT_EQ(Color(0, 0, 255), textStyle.strokeColor); |
50 EXPECT_EQ(Color(0, 0, 255), textStyle.emphasisMarkColor); | 50 EXPECT_EQ(Color(0, 0, 255), textStyle.emphasisMarkColor); |
51 EXPECT_EQ(0, textStyle.strokeWidth); | 51 EXPECT_EQ(0, textStyle.strokeWidth); |
52 EXPECT_EQ(nullptr, textStyle.shadow); | 52 EXPECT_EQ(nullptr, textStyle.shadow); |
53 } | 53 } |
54 | 54 |
55 TEST_F(TextPainterTest, TextPaintingStyle_AllProperties) | 55 TEST_F(TextPainterTest, TextPaintingStyle_AllProperties) |
56 { | 56 { |
57 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextFillColor, CS
SValueRed); | 57 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextFillColor, CS
SValueRed); |
58 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeColor,
CSSValueLime); | 58 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeColor,
CSSValueLime); |
59 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextEmphasisColor
, CSSValueBlue); | 59 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextEmphasisColor
, CSSValueBlue); |
60 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeWidth,
4, CSSPrimitiveValue::CSS_PX); | 60 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeWidth,
4, CSSPrimitiveValue::CSS_PX); |
61 document().body()->setInlineStyleProperty(CSSPropertyTextShadow, "1px 2px 3p
x yellow"); | 61 document().body()->setInlineStyleProperty(CSSPropertyTextShadow, "1px 2px 3p
x yellow"); |
62 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 62 document().view()->updateLayoutAndStyleIfNeededRecursive(); |
63 | 63 |
64 TextPainter::Style textStyle = TextPainter::textPaintingStyle( | 64 TextPainter::Style textStyle = TextPainter::textPaintingStyle( |
65 *renderText(), renderText()->styleRef(), false /* forceBlackText */, fal
se /* isPrinting */); | 65 *layoutText(), layoutText()->styleRef(), false /* forceBlackText */, fal
se /* isPrinting */); |
66 EXPECT_EQ(Color(255, 0, 0), textStyle.fillColor); | 66 EXPECT_EQ(Color(255, 0, 0), textStyle.fillColor); |
67 EXPECT_EQ(Color(0, 255, 0), textStyle.strokeColor); | 67 EXPECT_EQ(Color(0, 255, 0), textStyle.strokeColor); |
68 EXPECT_EQ(Color(0, 0, 255), textStyle.emphasisMarkColor); | 68 EXPECT_EQ(Color(0, 0, 255), textStyle.emphasisMarkColor); |
69 EXPECT_EQ(4, textStyle.strokeWidth); | 69 EXPECT_EQ(4, textStyle.strokeWidth); |
70 ASSERT_NE(nullptr, textStyle.shadow); | 70 ASSERT_NE(nullptr, textStyle.shadow); |
71 EXPECT_EQ(1u, textStyle.shadow->shadows().size()); | 71 EXPECT_EQ(1u, textStyle.shadow->shadows().size()); |
72 EXPECT_EQ(1, textStyle.shadow->shadows()[0].x()); | 72 EXPECT_EQ(1, textStyle.shadow->shadows()[0].x()); |
73 EXPECT_EQ(2, textStyle.shadow->shadows()[0].y()); | 73 EXPECT_EQ(2, textStyle.shadow->shadows()[0].y()); |
74 EXPECT_EQ(3, textStyle.shadow->shadows()[0].blur()); | 74 EXPECT_EQ(3, textStyle.shadow->shadows()[0].blur()); |
75 EXPECT_EQ(Color(255, 255, 0), textStyle.shadow->shadows()[0].color()); | 75 EXPECT_EQ(Color(255, 255, 0), textStyle.shadow->shadows()[0].color()); |
76 } | 76 } |
77 | 77 |
78 TEST_F(TextPainterTest, TextPaintingStyle_ForceBlackText) | 78 TEST_F(TextPainterTest, TextPaintingStyle_ForceBlackText) |
79 { | 79 { |
80 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextFillColor, CS
SValueRed); | 80 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextFillColor, CS
SValueRed); |
81 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeColor,
CSSValueLime); | 81 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeColor,
CSSValueLime); |
82 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextEmphasisColor
, CSSValueBlue); | 82 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextEmphasisColor
, CSSValueBlue); |
83 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeWidth,
4, CSSPrimitiveValue::CSS_PX); | 83 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeWidth,
4, CSSPrimitiveValue::CSS_PX); |
84 document().body()->setInlineStyleProperty(CSSPropertyTextShadow, "1px 2px 3p
x yellow"); | 84 document().body()->setInlineStyleProperty(CSSPropertyTextShadow, "1px 2px 3p
x yellow"); |
85 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 85 document().view()->updateLayoutAndStyleIfNeededRecursive(); |
86 | 86 |
87 TextPainter::Style textStyle = TextPainter::textPaintingStyle( | 87 TextPainter::Style textStyle = TextPainter::textPaintingStyle( |
88 *renderText(), renderText()->styleRef(), true /* forceBlackText */, fals
e /* isPrinting */); | 88 *layoutText(), layoutText()->styleRef(), true /* forceBlackText */, fals
e /* isPrinting */); |
89 EXPECT_EQ(Color::black, textStyle.fillColor); | 89 EXPECT_EQ(Color::black, textStyle.fillColor); |
90 EXPECT_EQ(Color::black, textStyle.strokeColor); | 90 EXPECT_EQ(Color::black, textStyle.strokeColor); |
91 EXPECT_EQ(Color::black, textStyle.emphasisMarkColor); | 91 EXPECT_EQ(Color::black, textStyle.emphasisMarkColor); |
92 EXPECT_EQ(4, textStyle.strokeWidth); | 92 EXPECT_EQ(4, textStyle.strokeWidth); |
93 EXPECT_EQ(nullptr, textStyle.shadow); | 93 EXPECT_EQ(nullptr, textStyle.shadow); |
94 } | 94 } |
95 | 95 |
96 TEST_F(TextPainterTest, TextPaintingStyle_ForceBackgroundToWhite_NoAdjustmentNee
ded) | 96 TEST_F(TextPainterTest, TextPaintingStyle_ForceBackgroundToWhite_NoAdjustmentNee
ded) |
97 { | 97 { |
98 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextFillColor, CS
SValueRed); | 98 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextFillColor, CS
SValueRed); |
99 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeColor,
CSSValueLime); | 99 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeColor,
CSSValueLime); |
100 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextEmphasisColor
, CSSValueBlue); | 100 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextEmphasisColor
, CSSValueBlue); |
101 document().body()->setInlineStyleProperty(CSSPropertyWebkitPrintColorAdjust,
CSSValueEconomy); | 101 document().body()->setInlineStyleProperty(CSSPropertyWebkitPrintColorAdjust,
CSSValueEconomy); |
102 document().settings()->setShouldPrintBackgrounds(false); | 102 document().settings()->setShouldPrintBackgrounds(false); |
103 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 103 document().view()->updateLayoutAndStyleIfNeededRecursive(); |
104 | 104 |
105 TextPainter::Style textStyle = TextPainter::textPaintingStyle( | 105 TextPainter::Style textStyle = TextPainter::textPaintingStyle( |
106 *renderText(), renderText()->styleRef(), false /* forceBlackText */, tru
e /* isPrinting */); | 106 *layoutText(), layoutText()->styleRef(), false /* forceBlackText */, tru
e /* isPrinting */); |
107 EXPECT_EQ(Color(255, 0, 0), textStyle.fillColor); | 107 EXPECT_EQ(Color(255, 0, 0), textStyle.fillColor); |
108 EXPECT_EQ(Color(0, 255, 0), textStyle.strokeColor); | 108 EXPECT_EQ(Color(0, 255, 0), textStyle.strokeColor); |
109 EXPECT_EQ(Color(0, 0, 255), textStyle.emphasisMarkColor); | 109 EXPECT_EQ(Color(0, 0, 255), textStyle.emphasisMarkColor); |
110 } | 110 } |
111 | 111 |
112 TEST_F(TextPainterTest, TextPaintingStyle_ForceBackgroundToWhite_Darkened) | 112 TEST_F(TextPainterTest, TextPaintingStyle_ForceBackgroundToWhite_Darkened) |
113 { | 113 { |
114 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextFillColor, "r
gb(255, 220, 220)"); | 114 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextFillColor, "r
gb(255, 220, 220)"); |
115 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeColor,
"rgb(220, 255, 220)"); | 115 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextStrokeColor,
"rgb(220, 255, 220)"); |
116 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextEmphasisColor
, "rgb(220, 220, 255)"); | 116 document().body()->setInlineStyleProperty(CSSPropertyWebkitTextEmphasisColor
, "rgb(220, 220, 255)"); |
117 document().body()->setInlineStyleProperty(CSSPropertyWebkitPrintColorAdjust,
CSSValueEconomy); | 117 document().body()->setInlineStyleProperty(CSSPropertyWebkitPrintColorAdjust,
CSSValueEconomy); |
118 document().settings()->setShouldPrintBackgrounds(false); | 118 document().settings()->setShouldPrintBackgrounds(false); |
119 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 119 document().view()->updateLayoutAndStyleIfNeededRecursive(); |
120 | 120 |
121 TextPainter::Style textStyle = TextPainter::textPaintingStyle( | 121 TextPainter::Style textStyle = TextPainter::textPaintingStyle( |
122 *renderText(), renderText()->styleRef(), false /* forceBlackText */, tru
e /* isPrinting */); | 122 *layoutText(), layoutText()->styleRef(), false /* forceBlackText */, tru
e /* isPrinting */); |
123 EXPECT_EQ(Color(255, 220, 220).dark(), textStyle.fillColor); | 123 EXPECT_EQ(Color(255, 220, 220).dark(), textStyle.fillColor); |
124 EXPECT_EQ(Color(220, 255, 220).dark(), textStyle.strokeColor); | 124 EXPECT_EQ(Color(220, 255, 220).dark(), textStyle.strokeColor); |
125 EXPECT_EQ(Color(220, 220, 255).dark(), textStyle.emphasisMarkColor); | 125 EXPECT_EQ(Color(220, 220, 255).dark(), textStyle.emphasisMarkColor); |
126 } | 126 } |
127 | 127 |
128 } // namespace | 128 } // namespace |
129 } // namespace blink | 129 } // namespace blink |
OLD | NEW |