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

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

Issue 2137753002: Calculate correct cull rect for SVG inline text boxes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Exploring a test. 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "core/paint/SVGInlineTextBoxPainter.h"
6
7 #include "core/dom/Document.h"
8 #include "core/dom/Range.h"
9 #include "core/editing/DOMSelection.h"
10 #include "core/frame/LocalDOMWindow.h"
11 #include "core/layout/LayoutTestHelper.h"
12 #include "core/layout/line/InlineTextBox.h"
13 #include "core/paint/PaintLayer.h"
14 #include "platform/graphics/GraphicsLayer.h"
15 #include "platform/graphics/paint/DisplayItemList.h"
16 #include "platform/graphics/paint/DrawingDisplayItem.h"
17 #include "platform/graphics/paint/PaintController.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 namespace blink {
21 namespace {
22
23 class SVGInlineTextBoxPainterTest : public RenderingTest {
24 public:
25 SVGInlineTextBoxPainterTest() { }
26
27 const DrawingDisplayItem* getDrawingDisplayItem(int index)
28 {
29 const DisplayItemList& displayItemList = rootPaintController().getDispla yItemList();
30 return static_cast<const DrawingDisplayItem*>(&displayItemList[index]);
31 }
32
33 void selectAllText()
34 {
35 Range* range = document().createRange();
36 range->selectNode(document().documentElement());
37 LocalDOMWindow* window = document().domWindow();
38 DOMSelection* selection = window->getSelection();
39 selection->removeAllRanges();
40 selection->addRange(range);
41 }
42
43 private:
44 PaintController& rootPaintController()
45 {
46 return document().view()->layoutView()->layer()->graphicsLayerBacking()- >getPaintController();
47 }
48
49 void SetUp() override
50 {
51 RenderingTest::SetUp();
52 enableCompositing();
53 }
54 };
55
56 static void assertTextDrawingEquals(const DrawingDisplayItem* drawingDisplayItem , const char* str)
57 {
58 ASSERT_EQ(str, static_cast<const InlineTextBox*>(&drawingDisplayItem->client ())->text());
59 }
60
61 static void assertCullRectEquals(const DrawingDisplayItem* drawingDisplayItem, c onst IntRect& expectedRect)
62 {
63 ASSERT_EQ(expectedRect, IntRect(drawingDisplayItem->picture()->cullRect()));
64 }
65
66 TEST_F(SVGInlineTextBoxPainterTest, TextCullRect_DefaultWritingMode)
67 {
68 setBodyInnerHTML(
69 "<svg width='400px' height='400px' font-family='Arial' font-size='30'>"
70 "<text x='50' y='30'>x</text>"
71 "</svg>");
72 document().view()->updateAllLifecyclePhases();
73
74 const DrawingDisplayItem* drawingDisplayItem = getDrawingDisplayItem(4);
75 assertTextDrawingEquals(drawingDisplayItem, "x");
76 assertCullRectEquals(drawingDisplayItem, IntRect(50, 3, 15, 33));
77
78 selectAllText();
79 document().view()->updateAllLifecyclePhases();
80
81 drawingDisplayItem = getDrawingDisplayItem(5);
82 assertTextDrawingEquals(drawingDisplayItem, "x");
83 assertCullRectEquals(drawingDisplayItem, IntRect(50, 3, 15, 33));
84 }
85
86 TEST_F(SVGInlineTextBoxPainterTest, TextCullRect_WritingModeTopToBottom)
87 {
88 setBodyInnerHTML(
89 "<svg width='400px' height='400px' font-family='Arial' font-size='30'>"
90 "<text x='50' y='30' writing-mode='tb'>x</text>"
91 "</svg>");
92 document().view()->updateAllLifecyclePhases();
93
94 const DrawingDisplayItem* drawingDisplayItem = getDrawingDisplayItem(4);
95 assertTextDrawingEquals(drawingDisplayItem, "x");
96 assertCullRectEquals(drawingDisplayItem, IntRect(33, 30, 34, 15));
97
98 selectAllText();
99 document().view()->updateAllLifecyclePhases();
100
101 // The selection rect is one pixel taller due to sub-pixel difference
pdr. 2016/07/12 22:51:41 This may be a bug.
wkorman 2016/07/12 23:33:20 Yeah, let's discuss in person soon separately. I t
102 // between the text bounds and selection bounds in combination with use of
103 // enclosingIntRect() in SVGInlineTextBox::localSelectionRect().
104 drawingDisplayItem = getDrawingDisplayItem(5);
105 assertTextDrawingEquals(drawingDisplayItem, "x");
106 assertCullRectEquals(drawingDisplayItem, IntRect(33, 30, 34, 16));
107 }
108
109 } // namespace
110 } // 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