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

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

Issue 2151203002: Revert of Calculate correct cull rect for SVG inline text boxes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/layout/svg/LayoutSVGInlineText.h"
14 #include "core/layout/svg/LayoutSVGText.h"
15 #include "core/paint/PaintLayer.h"
16 #include "platform/graphics/GraphicsLayer.h"
17 #include "platform/graphics/paint/DisplayItemList.h"
18 #include "platform/graphics/paint/DrawingDisplayItem.h"
19 #include "platform/graphics/paint/PaintController.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 namespace blink {
23 namespace {
24
25 class SVGInlineTextBoxPainterTest : public RenderingTest {
26 public:
27 const DrawingDisplayItem* getDrawingForSVGTextById(const char* elementName)
28 {
29 // Look up the inline text box that serves as the display item client fo r the painted text.
30 LayoutSVGText* targetSVGText = toLayoutSVGText(
31 document().getElementById(AtomicString(elementName))->layoutObject() );
32 LayoutSVGInlineText* targetInlineText = targetSVGText->descendantTextNod es()[0];
33 const DisplayItemClient* targetClient = static_cast<const DisplayItemCli ent*>(targetInlineText->firstTextBox());
34
35 // Find the appropriate drawing in the display item list.
36 const DisplayItemList& displayItemList = rootPaintController().getDispla yItemList();
37 for (size_t i = 0; i < displayItemList.size(); i++) {
38 if (displayItemList[i].client() == *targetClient)
39 return static_cast<const DrawingDisplayItem*>(&displayItemList[i ]);
40 }
41
42 return nullptr;
43 }
44
45
46 void selectAllText()
47 {
48 Range* range = document().createRange();
49 range->selectNode(document().documentElement());
50 LocalDOMWindow* window = document().domWindow();
51 DOMSelection* selection = window->getSelection();
52 selection->removeAllRanges();
53 selection->addRange(range);
54 }
55
56 private:
57 PaintController& rootPaintController()
58 {
59 return document().view()->layoutView()->layer()->graphicsLayerBacking()- >getPaintController();
60 }
61
62 void SetUp() override
63 {
64 RenderingTest::SetUp();
65 enableCompositing();
66 }
67 };
68
69 static void assertTextDrawingEquals(const DrawingDisplayItem* drawingDisplayItem , const char* str)
70 {
71 ASSERT_EQ(str, static_cast<const InlineTextBox*>(&drawingDisplayItem->client ())->text());
72 }
73
74 static void assertCullRectEquals(const DrawingDisplayItem* drawingDisplayItem, c onst IntRect& expectedRect)
75 {
76 ASSERT_EQ(expectedRect, IntRect(drawingDisplayItem->picture()->cullRect()));
77 }
78
79 TEST_F(SVGInlineTextBoxPainterTest, TextCullRect_DefaultWritingMode)
80 {
81 setBodyInnerHTML(
82 "<svg width='400px' height='400px' font-family='Arial' font-size='30'>"
83 "<text id='target' x='50' y='30'>x</text>"
84 "</svg>");
85 document().view()->updateAllLifecyclePhases();
86
87 const DrawingDisplayItem* drawingDisplayItem = getDrawingForSVGTextById("tar get");
88 assertTextDrawingEquals(drawingDisplayItem, "x");
89 assertCullRectEquals(drawingDisplayItem, IntRect(50, 3, 15, 33));
90
91 selectAllText();
92 document().view()->updateAllLifecyclePhases();
93
94 drawingDisplayItem = getDrawingForSVGTextById("target");
95 assertTextDrawingEquals(drawingDisplayItem, "x");
96 assertCullRectEquals(drawingDisplayItem, IntRect(50, 3, 15, 33));
97 }
98
99 TEST_F(SVGInlineTextBoxPainterTest, TextCullRect_WritingModeTopToBottom)
100 {
101 setBodyInnerHTML(
102 "<svg width='400px' height='400px' font-family='Arial' font-size='30'>"
103 "<text id='target' x='50' y='30' writing-mode='tb'>x</text>"
104 "</svg>");
105 document().view()->updateAllLifecyclePhases();
106
107 const DrawingDisplayItem* drawingDisplayItem = getDrawingForSVGTextById("tar get");
108 assertTextDrawingEquals(drawingDisplayItem, "x");
109 assertCullRectEquals(drawingDisplayItem, IntRect(33, 30, 34, 15));
110
111 selectAllText();
112 document().view()->updateAllLifecyclePhases();
113
114 // The selection rect is one pixel taller due to sub-pixel difference
115 // between the text bounds and selection bounds in combination with use of
116 // enclosingIntRect() in SVGInlineTextBox::localSelectionRect().
117 drawingDisplayItem = getDrawingForSVGTextById("target");
118 assertTextDrawingEquals(drawingDisplayItem, "x");
119 assertCullRectEquals(drawingDisplayItem, IntRect(33, 30, 34, 16));
120 }
121
122 } // namespace
123 } // 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