Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(994)

Side by Side Diff: third_party/WebKit/Source/core/paint/SVGInlineTextBoxPainterTest.cpp

Issue 2162033003: Include any text shadow bounds in SVG text cull rect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix approximation. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/paint/SVGInlineTextBoxPainter.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "core/paint/SVGInlineTextBoxPainter.h" 5 #include "core/paint/SVGInlineTextBoxPainter.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/Range.h" 8 #include "core/dom/Range.h"
9 #include "core/editing/DOMSelection.h" 9 #include "core/editing/DOMSelection.h"
10 #include "core/frame/LocalDOMWindow.h" 10 #include "core/frame/LocalDOMWindow.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 RenderingTest::SetUp(); 64 RenderingTest::SetUp();
65 enableCompositing(); 65 enableCompositing();
66 } 66 }
67 }; 67 };
68 68
69 static void assertTextDrawingEquals(const DrawingDisplayItem* drawingDisplayItem , const char* str) 69 static void assertTextDrawingEquals(const DrawingDisplayItem* drawingDisplayItem , const char* str)
70 { 70 {
71 ASSERT_EQ(str, static_cast<const InlineTextBox*>(&drawingDisplayItem->client ())->text()); 71 ASSERT_EQ(str, static_cast<const InlineTextBox*>(&drawingDisplayItem->client ())->text());
72 } 72 }
73 73
74 const static int kAllowedPixelDelta = 8; 74 bool ApproximatelyEqual(int a, int b, int delta)
75 {
76 return abs(a - b) <= delta;
77 }
75 78
76 static void assertCullRectEquals(const DrawingDisplayItem* drawingDisplayItem, c onst IntRect& expectedRect) 79 const static int kPixelDelta = 4;
80
81 #define EXPECT_RECT_EQ(expected, actual) \
82 do { \
83 const FloatRect& actualRect = actual; \
84 EXPECT_TRUE(ApproximatelyEqual(expected.x(), actualRect.x(), kPixelDelta)) < < "actual: " << actualRect.x() << ", expected: " << expected.x(); \
85 EXPECT_TRUE(ApproximatelyEqual(expected.y(), actualRect.y(), kPixelDelta)) < < "actual: " << actualRect.y() << ", expected: " << expected.y(); \
86 EXPECT_TRUE(ApproximatelyEqual(expected.width(), actualRect.width(), kPixelD elta)) << "actual: " << actualRect.width() << ", expected: " << expected.width() ; \
87 EXPECT_TRUE(ApproximatelyEqual(expected.height(), actualRect.height(), kPixe lDelta)) << "actual: " << actualRect.height() << ", expected: " << expected.heig ht(); \
88 } while (false)
89
90 static IntRect cullRectFromDrawing(const DrawingDisplayItem& drawingDisplayItem)
77 { 91 {
78 // Text metrics can vary slightly across platforms, so we allow for a small pixel difference. 92 return IntRect(drawingDisplayItem.picture()->cullRect());
79 IntRect outerRect(expectedRect);
80 int delta = kAllowedPixelDelta / 2;
81 outerRect.expand(IntRectOutsets(delta, delta, delta, delta));
82 IntRect innerRect(expectedRect);
83 // Rect contains is inclusive of edge, so shrink by one extra pixel.
84 int contractDelta = -delta - 1;
85 innerRect.expand(IntRectOutsets(contractDelta, contractDelta, contractDelta, contractDelta));
86
87 IntRect actualRect(IntRect(drawingDisplayItem->picture()->cullRect()));
88 ASSERT_TRUE(outerRect.contains(actualRect) && !innerRect.contains(actualRect ))
89 << "Cull rect not approximately equal [expected=("
90 << expectedRect.x() << "," << expectedRect.y() << " " << expectedRect.wi dth() << "x" << expectedRect.height() << "), actual=("
91 << actualRect.x() << "," << actualRect.y() << " " << actualRect.width() << "x" << actualRect.height() << ")].";
92 } 93 }
93 94
94 TEST_F(SVGInlineTextBoxPainterTest, TextCullRect_DefaultWritingMode) 95 TEST_F(SVGInlineTextBoxPainterTest, TextCullRect_DefaultWritingMode)
95 { 96 {
96 setBodyInnerHTML( 97 setBodyInnerHTML(
97 "<svg width='400px' height='400px' font-family='Arial' font-size='30'>" 98 "<svg width='400px' height='400px' font-family='Arial' font-size='30'>"
98 "<text id='target' x='50' y='30'>x</text>" 99 "<text id='target' x='50' y='30'>x</text>"
99 "</svg>"); 100 "</svg>");
100 document().view()->updateAllLifecyclePhases(); 101 document().view()->updateAllLifecyclePhases();
101 102
102 const DrawingDisplayItem* drawingDisplayItem = getDrawingForSVGTextById("tar get"); 103 const DrawingDisplayItem* drawingDisplayItem = getDrawingForSVGTextById("tar get");
103 assertTextDrawingEquals(drawingDisplayItem, "x"); 104 assertTextDrawingEquals(drawingDisplayItem, "x");
104 assertCullRectEquals(drawingDisplayItem, IntRect(50, 3, 15, 33)); 105 EXPECT_RECT_EQ(IntRect(50, 3, 15, 33), cullRectFromDrawing(*drawingDisplayIt em));
105 106
106 selectAllText(); 107 selectAllText();
107 document().view()->updateAllLifecyclePhases(); 108 document().view()->updateAllLifecyclePhases();
108 109
109 drawingDisplayItem = getDrawingForSVGTextById("target"); 110 drawingDisplayItem = getDrawingForSVGTextById("target");
110 assertTextDrawingEquals(drawingDisplayItem, "x"); 111 assertTextDrawingEquals(drawingDisplayItem, "x");
111 assertCullRectEquals(drawingDisplayItem, IntRect(50, 3, 15, 33)); 112 EXPECT_RECT_EQ(IntRect(50, 3, 15, 33), cullRectFromDrawing(*drawingDisplayIt em));
112 } 113 }
113 114
114 TEST_F(SVGInlineTextBoxPainterTest, TextCullRect_WritingModeTopToBottom) 115 TEST_F(SVGInlineTextBoxPainterTest, TextCullRect_WritingModeTopToBottom)
115 { 116 {
116 setBodyInnerHTML( 117 setBodyInnerHTML(
117 "<svg width='400px' height='400px' font-family='Arial' font-size='30'>" 118 "<svg width='400px' height='400px' font-family='Arial' font-size='30'>"
118 "<text id='target' x='50' y='30' writing-mode='tb'>x</text>" 119 "<text id='target' x='50' y='30' writing-mode='tb'>x</text>"
119 "</svg>"); 120 "</svg>");
120 document().view()->updateAllLifecyclePhases(); 121 document().view()->updateAllLifecyclePhases();
121 122
122 const DrawingDisplayItem* drawingDisplayItem = getDrawingForSVGTextById("tar get"); 123 const DrawingDisplayItem* drawingDisplayItem = getDrawingForSVGTextById("tar get");
123 assertTextDrawingEquals(drawingDisplayItem, "x"); 124 assertTextDrawingEquals(drawingDisplayItem, "x");
124 assertCullRectEquals(drawingDisplayItem, IntRect(33, 30, 34, 15)); 125 EXPECT_RECT_EQ(IntRect(33, 30, 34, 15), cullRectFromDrawing(*drawingDisplayI tem));
125 126
126 selectAllText(); 127 selectAllText();
127 document().view()->updateAllLifecyclePhases(); 128 document().view()->updateAllLifecyclePhases();
128 129
129 // The selection rect is one pixel taller due to sub-pixel difference 130 // The selection rect is one pixel taller due to sub-pixel difference
130 // between the text bounds and selection bounds in combination with use of 131 // between the text bounds and selection bounds in combination with use of
131 // enclosingIntRect() in SVGInlineTextBox::localSelectionRect(). 132 // enclosingIntRect() in SVGInlineTextBox::localSelectionRect().
132 drawingDisplayItem = getDrawingForSVGTextById("target"); 133 drawingDisplayItem = getDrawingForSVGTextById("target");
133 assertTextDrawingEquals(drawingDisplayItem, "x"); 134 assertTextDrawingEquals(drawingDisplayItem, "x");
134 assertCullRectEquals(drawingDisplayItem, IntRect(33, 30, 34, 16)); 135 EXPECT_RECT_EQ(IntRect(33, 30, 34, 16), cullRectFromDrawing(*drawingDisplayI tem));
136 }
137
138 TEST_F(SVGInlineTextBoxPainterTest, TextCullRect_TextShadow)
139 {
140 setBodyInnerHTML(
141 "<svg width='400px' height='400px' font-family='Arial' font-size='30'>"
142 "<text id='target' x='50' y='30' style='text-shadow: 200px 200px 5px red '>x</text>"
143 "</svg>");
144 document().view()->updateAllLifecyclePhases();
145
146 const DrawingDisplayItem* drawingDisplayItem = getDrawingForSVGTextById("tar get");
147 assertTextDrawingEquals(drawingDisplayItem, "x");
148 EXPECT_RECT_EQ(IntRect(50, 3, 220, 238), cullRectFromDrawing(*drawingDisplay Item));
135 } 149 }
136 150
137 } // namespace 151 } // namespace
138 } // namespace blink 152 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/paint/SVGInlineTextBoxPainter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698