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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/paint/SVGInlineTextBoxPainter.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/paint/SVGInlineTextBoxPainterTest.cpp
diff --git a/third_party/WebKit/Source/core/paint/SVGInlineTextBoxPainterTest.cpp b/third_party/WebKit/Source/core/paint/SVGInlineTextBoxPainterTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..7e2448528aef82efafe64ab26bc3b563dcf87121
--- /dev/null
+++ b/third_party/WebKit/Source/core/paint/SVGInlineTextBoxPainterTest.cpp
@@ -0,0 +1,110 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/paint/SVGInlineTextBoxPainter.h"
+
+#include "core/dom/Document.h"
+#include "core/dom/Range.h"
+#include "core/editing/DOMSelection.h"
+#include "core/frame/LocalDOMWindow.h"
+#include "core/layout/LayoutTestHelper.h"
+#include "core/layout/line/InlineTextBox.h"
+#include "core/paint/PaintLayer.h"
+#include "platform/graphics/GraphicsLayer.h"
+#include "platform/graphics/paint/DisplayItemList.h"
+#include "platform/graphics/paint/DrawingDisplayItem.h"
+#include "platform/graphics/paint/PaintController.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+namespace {
+
+class SVGInlineTextBoxPainterTest : public RenderingTest {
+public:
+ SVGInlineTextBoxPainterTest() { }
+
+ const DrawingDisplayItem* getDrawingDisplayItem(int index)
+ {
+ const DisplayItemList& displayItemList = rootPaintController().getDisplayItemList();
+ return static_cast<const DrawingDisplayItem*>(&displayItemList[index]);
+ }
+
+ void selectAllText()
+ {
+ Range* range = document().createRange();
+ range->selectNode(document().documentElement());
+ LocalDOMWindow* window = document().domWindow();
+ DOMSelection* selection = window->getSelection();
+ selection->removeAllRanges();
+ selection->addRange(range);
+ }
+
+private:
+ PaintController& rootPaintController()
+ {
+ return document().view()->layoutView()->layer()->graphicsLayerBacking()->getPaintController();
+ }
+
+ void SetUp() override
+ {
+ RenderingTest::SetUp();
+ enableCompositing();
+ }
+};
+
+static void assertTextDrawingEquals(const DrawingDisplayItem* drawingDisplayItem, const char* str)
+{
+ ASSERT_EQ(str, static_cast<const InlineTextBox*>(&drawingDisplayItem->client())->text());
+}
+
+static void assertCullRectEquals(const DrawingDisplayItem* drawingDisplayItem, const IntRect& expectedRect)
+{
+ ASSERT_EQ(expectedRect, IntRect(drawingDisplayItem->picture()->cullRect()));
+}
+
+TEST_F(SVGInlineTextBoxPainterTest, TextCullRect_DefaultWritingMode)
+{
+ setBodyInnerHTML(
+ "<svg width='400px' height='400px' font-family='Arial' font-size='30'>"
+ "<text x='50' y='30'>x</text>"
+ "</svg>");
+ document().view()->updateAllLifecyclePhases();
+
+ const DrawingDisplayItem* drawingDisplayItem = getDrawingDisplayItem(4);
+ assertTextDrawingEquals(drawingDisplayItem, "x");
+ assertCullRectEquals(drawingDisplayItem, IntRect(50, 3, 15, 33));
+
+ selectAllText();
+ document().view()->updateAllLifecyclePhases();
+
+ drawingDisplayItem = getDrawingDisplayItem(5);
+ assertTextDrawingEquals(drawingDisplayItem, "x");
+ assertCullRectEquals(drawingDisplayItem, IntRect(50, 3, 15, 33));
+}
+
+TEST_F(SVGInlineTextBoxPainterTest, TextCullRect_WritingModeTopToBottom)
+{
+ setBodyInnerHTML(
+ "<svg width='400px' height='400px' font-family='Arial' font-size='30'>"
+ "<text x='50' y='30' writing-mode='tb'>x</text>"
+ "</svg>");
+ document().view()->updateAllLifecyclePhases();
+
+ const DrawingDisplayItem* drawingDisplayItem = getDrawingDisplayItem(4);
+ assertTextDrawingEquals(drawingDisplayItem, "x");
+ assertCullRectEquals(drawingDisplayItem, IntRect(33, 30, 34, 15));
+
+ selectAllText();
+ document().view()->updateAllLifecyclePhases();
+
+ // 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
+ // between the text bounds and selection bounds in combination with use of
+ // enclosingIntRect() in SVGInlineTextBox::localSelectionRect().
+ drawingDisplayItem = getDrawingDisplayItem(5);
+ assertTextDrawingEquals(drawingDisplayItem, "x");
+ assertCullRectEquals(drawingDisplayItem, IntRect(33, 30, 34, 16));
+}
+
+} // namespace
+} // namespace blink
« 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