| OLD | NEW |
| (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/layout/line/InlineTextBox.h" | |
| 6 | |
| 7 #include "core/layout/LayoutTestHelper.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 namespace blink { | |
| 11 | |
| 12 class InlineTextBoxTest : public RenderingTest {}; | |
| 13 | |
| 14 class TestInlineTextBox : public InlineTextBox { | |
| 15 public: | |
| 16 TestInlineTextBox(LineLayoutItem item) : InlineTextBox(item, 0, 0) { | |
| 17 setHasVirtualLogicalHeight(); | |
| 18 } | |
| 19 | |
| 20 static TestInlineTextBox* create(Document& document, const String& string) { | |
| 21 Text* node = document.createTextNode(string); | |
| 22 LayoutText* text = new LayoutText(node, string.impl()); | |
| 23 text->setStyle(ComputedStyle::create()); | |
| 24 return new TestInlineTextBox(LineLayoutItem(text)); | |
| 25 } | |
| 26 | |
| 27 LayoutUnit virtualLogicalHeight() const override { return m_logicalHeight; } | |
| 28 | |
| 29 void setLogicalFrameRect(const LayoutRect& rect) { | |
| 30 setX(rect.x()); | |
| 31 setY(rect.y()); | |
| 32 setLogicalWidth(rect.width()); | |
| 33 m_logicalHeight = rect.height(); | |
| 34 } | |
| 35 | |
| 36 private: | |
| 37 LayoutUnit m_logicalHeight; | |
| 38 }; | |
| 39 | |
| 40 static void moveAndTest(InlineTextBox* box, | |
| 41 const LayoutSize& move, | |
| 42 LayoutRect& frame, | |
| 43 LayoutRect& overflow) { | |
| 44 box->move(move); | |
| 45 frame.move(move); | |
| 46 overflow.move(move); | |
| 47 ASSERT_EQ(frame, box->logicalFrameRect()); | |
| 48 ASSERT_EQ(overflow, box->logicalOverflowRect()); | |
| 49 } | |
| 50 | |
| 51 TEST_F(InlineTextBoxTest, LogicalOverflowRect) { | |
| 52 // Setup a TestInlineTextBox. | |
| 53 TestInlineTextBox* box = TestInlineTextBox::create(document(), ""); | |
| 54 | |
| 55 // Initially, logicalOverflowRect() should be the same as logicalFrameRect(). | |
| 56 LayoutRect frame(5, 20, 100, 200); | |
| 57 LayoutRect overflow = frame; | |
| 58 box->setLogicalFrameRect(frame); | |
| 59 ASSERT_EQ(frame, box->logicalFrameRect()); | |
| 60 ASSERT_EQ(overflow, box->logicalOverflowRect()); | |
| 61 | |
| 62 // Ensure it's movable and the rects are correct. | |
| 63 LayoutSize move(10, 10); | |
| 64 moveAndTest(box, move, frame, overflow); | |
| 65 | |
| 66 // Ensure clearKnownToHaveNoOverflow() doesn't change either rects. | |
| 67 box->clearKnownToHaveNoOverflow(); | |
| 68 ASSERT_EQ(frame, box->logicalFrameRect()); | |
| 69 ASSERT_EQ(overflow, box->logicalOverflowRect()); | |
| 70 | |
| 71 // Ensure it's still movable correctly when !knownToHaveNoOverflow(). | |
| 72 moveAndTest(box, move, frame, overflow); | |
| 73 | |
| 74 // Let it have different logicalOverflowRect() than logicalFrameRect(). | |
| 75 overflow.expand(LayoutSize(10, 10)); | |
| 76 box->setLogicalOverflowRect(overflow); | |
| 77 ASSERT_EQ(frame, box->logicalFrameRect()); | |
| 78 ASSERT_EQ(overflow, box->logicalOverflowRect()); | |
| 79 | |
| 80 // Ensure it's still movable correctly. | |
| 81 moveAndTest(box, move, frame, overflow); | |
| 82 } | |
| 83 | |
| 84 } // namespace blink | |
| OLD | NEW |