OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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/ng/ng_base_layout_algorithm_test.h" |
| 6 |
| 7 #include "core/dom/TagCollection.h" |
| 8 #include "core/layout/line/InlineTextBox.h" |
| 9 #include "core/layout/ng/ng_inline_node.h" |
| 10 #include "core/layout/ng/ng_physical_text_fragment.h" |
| 11 #include "platform/geometry/LayoutPoint.h" |
| 12 #include "platform/geometry/LayoutRect.h" |
| 13 |
| 14 namespace blink { |
| 15 namespace { |
| 16 |
| 17 class NGTextLayoutAlgorithmTest : public NGBaseLayoutAlgorithmTest {}; |
| 18 |
| 19 // Verifies that text can flow correctly around floats that were positioned |
| 20 // before the inline block. |
| 21 TEST_F(NGTextLayoutAlgorithmTest, TextFloatsAroundFloatsBefore) { |
| 22 setBodyInnerHTML(R"HTML( |
| 23 <!DOCTYPE html> |
| 24 <style> |
| 25 * { |
| 26 font-family: "Arial", sans-serif; |
| 27 font-size: 19px; |
| 28 } |
| 29 #container { |
| 30 height: 200px; width: 200px; outline: solid blue; |
| 31 } |
| 32 #left-float1 { |
| 33 float: left; width: 30px; height: 30px; background-color: blue; |
| 34 } |
| 35 #left-float2 { |
| 36 float: left; width: 10px; height: 10px; |
| 37 background-color: purple; |
| 38 } |
| 39 #right-float { |
| 40 float: right; width: 40px; height: 40px; background-color: yellow; |
| 41 } |
| 42 </style> |
| 43 <div id="container"> |
| 44 <div id="left-float1"></div> |
| 45 <div id="left-float2"></div> |
| 46 <div id="right-float"></div> |
| 47 <span id="text">The quick brown fox jumps over the lazy dog</span> |
| 48 </div> |
| 49 )HTML"); |
| 50 // ** Run LayoutNG algorithm ** |
| 51 RefPtr<NGConstraintSpace> space; |
| 52 RefPtr<NGPhysicalBoxFragment> html_fragment; |
| 53 std::tie(html_fragment, space) = RunBlockLayoutAlgorithmForElement( |
| 54 document().getElementsByTagName("html")->item(0)); |
| 55 auto* body_fragment = |
| 56 toNGPhysicalBoxFragment(html_fragment->Children()[0].get()); |
| 57 auto* container_fragment = |
| 58 toNGPhysicalBoxFragment(body_fragment->Children()[0].get()); |
| 59 auto* text_fragments_wrapper = |
| 60 toNGPhysicalBoxFragment(container_fragment->Children()[0].get()); |
| 61 |
| 62 LayoutText* layout_text = |
| 63 toLayoutText(getLayoutObjectByElementId("text")->slowFirstChild()); |
| 64 ASSERT(layout_text->hasTextBoxes()); |
| 65 |
| 66 // TODO(glebl): Should have only 3 text fragments. For some reason we have a |
| 67 // left over fragment with text == "dog". |
| 68 ASSERT_EQ(4UL, text_fragments_wrapper->Children().size()); |
| 69 |
| 70 auto* text_fragment1 = |
| 71 toNGPhysicalTextFragment(text_fragments_wrapper->Children()[0].get()); |
| 72 auto* text_node = text_fragment1->Node(); |
| 73 // 40 = #left-float1' width 30 + #left-float2 10 |
| 74 EXPECT_EQ(LayoutUnit(40), text_fragment1->LeftOffset()); |
| 75 EXPECT_EQ("The quick ", text_node->Text(text_fragment1->StartOffset(), |
| 76 text_fragment1->EndOffset())); |
| 77 InlineTextBox* inline_text_box1 = layout_text->firstTextBox(); |
| 78 EXPECT_EQ(LayoutPoint(40, 0), inline_text_box1->frameRect().location()); |
| 79 |
| 80 auto* text_fragment2 = |
| 81 toNGPhysicalTextFragment(text_fragments_wrapper->Children()[1].get()); |
| 82 // 40 = #left-float1' width 30 |
| 83 EXPECT_EQ(LayoutUnit(30), text_fragment2->LeftOffset()); |
| 84 EXPECT_EQ("brown fox jumps over", |
| 85 text_node->Text(text_fragment2->StartOffset(), |
| 86 text_fragment2->EndOffset())); |
| 87 InlineTextBox* inline_text_box2 = inline_text_box1->nextTextBox(); |
| 88 EXPECT_EQ(LayoutPoint(30, 22), inline_text_box2->frameRect().location()); |
| 89 |
| 90 auto* text_fragment3 = |
| 91 toNGPhysicalTextFragment(text_fragments_wrapper->Children()[2].get()); |
| 92 EXPECT_EQ(LayoutUnit(), text_fragment3->LeftOffset()); |
| 93 EXPECT_EQ("jumps over the lazy dog", |
| 94 text_node->Text(text_fragment3->StartOffset(), |
| 95 text_fragment3->EndOffset())); |
| 96 InlineTextBox* inline_text_box3 = inline_text_box2->nextTextBox(); |
| 97 EXPECT_EQ(LayoutPoint(0, 44), inline_text_box3->frameRect().location()); |
| 98 } |
| 99 |
| 100 } // namespace |
| 101 } // namespace blink |
OLD | NEW |