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