| OLD | NEW |
| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 EXPECT_TRUE(ApproximatelyEqual(expected.Width(), actual_rect.Width(), \ | 92 EXPECT_TRUE(ApproximatelyEqual(expected.Width(), actual_rect.Width(), \ |
| 93 kPixelDelta)) \ | 93 kPixelDelta)) \ |
| 94 << "actual: " << actual_rect.Width() \ | 94 << "actual: " << actual_rect.Width() \ |
| 95 << ", expected: " << expected.Width(); \ | 95 << ", expected: " << expected.Width(); \ |
| 96 EXPECT_TRUE(ApproximatelyEqual(expected.Height(), actual_rect.Height(), \ | 96 EXPECT_TRUE(ApproximatelyEqual(expected.Height(), actual_rect.Height(), \ |
| 97 kPixelDelta)) \ | 97 kPixelDelta)) \ |
| 98 << "actual: " << actual_rect.Height() \ | 98 << "actual: " << actual_rect.Height() \ |
| 99 << ", expected: " << expected.Height(); \ | 99 << ", expected: " << expected.Height(); \ |
| 100 } while (false) | 100 } while (false) |
| 101 | 101 |
| 102 static IntRect CullRectFromDrawing( |
| 103 const DrawingDisplayItem& drawing_display_item) { |
| 104 return IntRect(drawing_display_item.GetPaintRecord()->cullRect()); |
| 105 } |
| 106 |
| 102 TEST_F(SVGInlineTextBoxPainterTest, TextCullRect_DefaultWritingMode) { | 107 TEST_F(SVGInlineTextBoxPainterTest, TextCullRect_DefaultWritingMode) { |
| 103 SetBodyInnerHTML( | 108 SetBodyInnerHTML( |
| 104 "<svg width='400px' height='400px' font-family='Arial' font-size='30'>" | 109 "<svg width='400px' height='400px' font-family='Arial' font-size='30'>" |
| 105 "<text id='target' x='50' y='30'>x</text>" | 110 "<text id='target' x='50' y='30'>x</text>" |
| 106 "</svg>"); | 111 "</svg>"); |
| 107 GetDocument().View()->UpdateAllLifecyclePhases(); | 112 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 108 | 113 |
| 109 const DrawingDisplayItem* drawing_display_item = | 114 const DrawingDisplayItem* drawing_display_item = |
| 110 GetDrawingForSVGTextById("target"); | 115 GetDrawingForSVGTextById("target"); |
| 111 AssertTextDrawingEquals(drawing_display_item, "x"); | 116 AssertTextDrawingEquals(drawing_display_item, "x"); |
| 112 EXPECT_RECT_EQ(IntRect(50, 3, 15, 33), | 117 EXPECT_RECT_EQ(IntRect(50, 3, 15, 33), |
| 113 drawing_display_item->GetPaintRecordBounds()); | 118 CullRectFromDrawing(*drawing_display_item)); |
| 114 | 119 |
| 115 SelectAllText(); | 120 SelectAllText(); |
| 116 GetDocument().View()->UpdateAllLifecyclePhases(); | 121 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 117 | 122 |
| 118 drawing_display_item = GetDrawingForSVGTextById("target"); | 123 drawing_display_item = GetDrawingForSVGTextById("target"); |
| 119 AssertTextDrawingEquals(drawing_display_item, "x"); | 124 AssertTextDrawingEquals(drawing_display_item, "x"); |
| 120 EXPECT_RECT_EQ(IntRect(50, 3, 15, 33), | 125 EXPECT_RECT_EQ(IntRect(50, 3, 15, 33), |
| 121 drawing_display_item->GetPaintRecordBounds()); | 126 CullRectFromDrawing(*drawing_display_item)); |
| 122 } | 127 } |
| 123 | 128 |
| 124 TEST_F(SVGInlineTextBoxPainterTest, TextCullRect_WritingModeTopToBottom) { | 129 TEST_F(SVGInlineTextBoxPainterTest, TextCullRect_WritingModeTopToBottom) { |
| 125 SetBodyInnerHTML( | 130 SetBodyInnerHTML( |
| 126 "<svg width='400px' height='400px' font-family='Arial' font-size='30'>" | 131 "<svg width='400px' height='400px' font-family='Arial' font-size='30'>" |
| 127 "<text id='target' x='50' y='30' writing-mode='tb'>x</text>" | 132 "<text id='target' x='50' y='30' writing-mode='tb'>x</text>" |
| 128 "</svg>"); | 133 "</svg>"); |
| 129 GetDocument().View()->UpdateAllLifecyclePhases(); | 134 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 130 | 135 |
| 131 const DrawingDisplayItem* drawing_display_item = | 136 const DrawingDisplayItem* drawing_display_item = |
| 132 GetDrawingForSVGTextById("target"); | 137 GetDrawingForSVGTextById("target"); |
| 133 AssertTextDrawingEquals(drawing_display_item, "x"); | 138 AssertTextDrawingEquals(drawing_display_item, "x"); |
| 134 EXPECT_RECT_EQ(IntRect(33, 30, 34, 15), | 139 EXPECT_RECT_EQ(IntRect(33, 30, 34, 15), |
| 135 drawing_display_item->GetPaintRecordBounds()); | 140 CullRectFromDrawing(*drawing_display_item)); |
| 136 | 141 |
| 137 SelectAllText(); | 142 SelectAllText(); |
| 138 GetDocument().View()->UpdateAllLifecyclePhases(); | 143 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 139 | 144 |
| 140 // The selection rect is one pixel taller due to sub-pixel difference | 145 // The selection rect is one pixel taller due to sub-pixel difference |
| 141 // between the text bounds and selection bounds in combination with use of | 146 // between the text bounds and selection bounds in combination with use of |
| 142 // enclosingIntRect() in SVGInlineTextBox::localSelectionRect(). | 147 // enclosingIntRect() in SVGInlineTextBox::localSelectionRect(). |
| 143 drawing_display_item = GetDrawingForSVGTextById("target"); | 148 drawing_display_item = GetDrawingForSVGTextById("target"); |
| 144 AssertTextDrawingEquals(drawing_display_item, "x"); | 149 AssertTextDrawingEquals(drawing_display_item, "x"); |
| 145 EXPECT_RECT_EQ(IntRect(33, 30, 34, 16), | 150 EXPECT_RECT_EQ(IntRect(33, 30, 34, 16), |
| 146 drawing_display_item->GetPaintRecordBounds()); | 151 CullRectFromDrawing(*drawing_display_item)); |
| 147 } | 152 } |
| 148 | 153 |
| 149 TEST_F(SVGInlineTextBoxPainterTest, TextCullRect_TextShadow) { | 154 TEST_F(SVGInlineTextBoxPainterTest, TextCullRect_TextShadow) { |
| 150 SetBodyInnerHTML( | 155 SetBodyInnerHTML( |
| 151 "<svg width='400px' height='400px' font-family='Arial' font-size='30'>" | 156 "<svg width='400px' height='400px' font-family='Arial' font-size='30'>" |
| 152 "<text id='target' x='50' y='30' style='text-shadow: 200px 200px 5px " | 157 "<text id='target' x='50' y='30' style='text-shadow: 200px 200px 5px " |
| 153 "red'>x</text>" | 158 "red'>x</text>" |
| 154 "</svg>"); | 159 "</svg>"); |
| 155 GetDocument().View()->UpdateAllLifecyclePhases(); | 160 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 156 | 161 |
| 157 const DrawingDisplayItem* drawing_display_item = | 162 const DrawingDisplayItem* drawing_display_item = |
| 158 GetDrawingForSVGTextById("target"); | 163 GetDrawingForSVGTextById("target"); |
| 159 AssertTextDrawingEquals(drawing_display_item, "x"); | 164 AssertTextDrawingEquals(drawing_display_item, "x"); |
| 160 EXPECT_RECT_EQ(IntRect(50, 3, 220, 238), | 165 EXPECT_RECT_EQ(IntRect(50, 3, 220, 238), |
| 161 drawing_display_item->GetPaintRecordBounds()); | 166 CullRectFromDrawing(*drawing_display_item)); |
| 162 } | 167 } |
| 163 | 168 |
| 164 } // namespace | 169 } // namespace |
| 165 } // namespace blink | 170 } // namespace blink |
| OLD | NEW |