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

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_inline_node_test.cc

Issue 2706403008: [LayoutNG] Implement ComputeMinAndMaxContentSizes for inline (Closed)
Patch Set: cbiesinger review Created 3 years, 9 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 unified diff | Download patch
OLDNEW
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/layout/ng/ng_inline_node.h" 5 #include "core/layout/ng/ng_inline_node.h"
6 6
7 #include "core/layout/LayoutTestHelper.h"
7 #include "core/layout/ng/ng_constraint_space.h" 8 #include "core/layout/ng/ng_constraint_space.h"
8 #include "core/layout/ng/ng_constraint_space_builder.h" 9 #include "core/layout/ng/ng_constraint_space_builder.h"
9 #include "core/layout/ng/ng_fragment_builder.h" 10 #include "core/layout/ng/ng_fragment_builder.h"
10 #include "core/layout/ng/ng_line_builder.h" 11 #include "core/layout/ng/ng_line_builder.h"
11 #include "core/layout/ng/ng_physical_box_fragment.h" 12 #include "core/layout/ng/ng_physical_box_fragment.h"
12 #include "core/layout/ng/ng_physical_text_fragment.h" 13 #include "core/layout/ng/ng_physical_text_fragment.h"
13 #include "core/layout/ng/ng_text_fragment.h" 14 #include "core/layout/ng/ng_text_fragment.h"
14 #include "core/layout/ng/ng_text_layout_algorithm.h" 15 #include "core/layout/ng/ng_text_layout_algorithm.h"
15 #include "core/style/ComputedStyle.h" 16 #include "core/style/ComputedStyle.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 30 matching lines...) Expand all
47 48
48 void ClearText() { 49 void ClearText() {
49 text_content_ = String(); 50 text_content_ = String();
50 items_.clear(); 51 items_.clear();
51 } 52 }
52 53
53 void SegmentText() { 54 void SegmentText() {
54 is_bidi_enabled_ = true; 55 is_bidi_enabled_ = true;
55 NGInlineNode::SegmentText(); 56 NGInlineNode::SegmentText();
56 } 57 }
58
59 using NGInlineNode::ShapeText;
57 }; 60 };
58 61
59 class NGInlineNodeTest : public ::testing::Test { 62 class NGInlineNodeTest : public RenderingTest {
60 protected: 63 protected:
61 void SetUp() override { 64 void SetUp() override {
65 RenderingTest::SetUp();
62 style_ = ComputedStyle::create(); 66 style_ = ComputedStyle::create();
63 style_->font().update(nullptr); 67 style_->font().update(nullptr);
64 } 68 }
65 69
70 void setAhemToStyle() {
71 // Get Ahem from document. Loading "Ahem.woff" using |createTestFont| fails
72 // on linux_chromium_asan_rel_ng.
73 loadAhem();
74 setBodyInnerHTML("<div id=t style='font:10px Ahem'></div>");
75 LayoutObject* layout_object = getLayoutObjectByElementId("t");
76 style_->setFont(layout_object->style()->font());
77 }
78
66 void CreateLine(NGInlineNode* node, 79 void CreateLine(NGInlineNode* node,
67 Vector<RefPtr<const NGPhysicalTextFragment>>* fragments_out) { 80 Vector<RefPtr<const NGPhysicalTextFragment>>* fragments_out) {
68 NGConstraintSpace* constraint_space = 81 NGConstraintSpace* constraint_space =
69 NGConstraintSpaceBuilder(kHorizontalTopBottom) 82 NGConstraintSpaceBuilder(kHorizontalTopBottom)
70 .ToConstraintSpace(kHorizontalTopBottom); 83 .ToConstraintSpace(kHorizontalTopBottom);
71 NGLineBuilder line_builder(node, constraint_space); 84 NGLineBuilder line_builder(node, constraint_space);
72 85
73 NGTextLayoutAlgorithm algorithm(node, constraint_space); 86 NGTextLayoutAlgorithm algorithm(node, constraint_space);
74 algorithm.LayoutInline(&line_builder); 87 algorithm.LayoutInline(&line_builder);
75 88
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 dir) \ 197 dir) \
185 EXPECT_EQ(node, fragment->Node()); \ 198 EXPECT_EQ(node, fragment->Node()); \
186 EXPECT_EQ(index, fragment->ItemIndex()); \ 199 EXPECT_EQ(index, fragment->ItemIndex()); \
187 EXPECT_EQ(start_offset, fragment->StartOffset()); \ 200 EXPECT_EQ(start_offset, fragment->StartOffset()); \
188 EXPECT_EQ(end_offset, fragment->EndOffset()); \ 201 EXPECT_EQ(end_offset, fragment->EndOffset()); \
189 EXPECT_EQ(dir, node->Items()[fragment->ItemIndex()].Direction()) 202 EXPECT_EQ(dir, node->Items()[fragment->ItemIndex()].Direction())
190 203
191 TEST_F(NGInlineNodeTest, CreateLineBidiIsolate) { 204 TEST_F(NGInlineNodeTest, CreateLineBidiIsolate) {
192 RefPtr<ComputedStyle> style = ComputedStyle::create(); 205 RefPtr<ComputedStyle> style = ComputedStyle::create();
193 style->setLineHeight(Length(1, Fixed)); 206 style->setLineHeight(Length(1, Fixed));
207 style->font().update(nullptr);
194 NGInlineNodeForTest* node = CreateBidiIsolateNode(style.get()); 208 NGInlineNodeForTest* node = CreateBidiIsolateNode(style.get());
195 Vector<RefPtr<const NGPhysicalTextFragment>> fragments; 209 Vector<RefPtr<const NGPhysicalTextFragment>> fragments;
196 CreateLine(node, &fragments); 210 CreateLine(node, &fragments);
197 ASSERT_EQ(5u, fragments.size()); 211 ASSERT_EQ(5u, fragments.size());
198 TEST_TEXT_FRAGMENT(fragments[0], node, 0u, 0u, 6u, TextDirection::kLtr); 212 TEST_TEXT_FRAGMENT(fragments[0], node, 0u, 0u, 6u, TextDirection::kLtr);
199 TEST_TEXT_FRAGMENT(fragments[1], node, 6u, 16u, 21u, TextDirection::kRtl); 213 TEST_TEXT_FRAGMENT(fragments[1], node, 6u, 16u, 21u, TextDirection::kRtl);
200 TEST_TEXT_FRAGMENT(fragments[2], node, 4u, 14u, 15u, TextDirection::kLtr); 214 TEST_TEXT_FRAGMENT(fragments[2], node, 4u, 14u, 15u, TextDirection::kLtr);
201 TEST_TEXT_FRAGMENT(fragments[3], node, 2u, 7u, 13u, TextDirection::kRtl); 215 TEST_TEXT_FRAGMENT(fragments[3], node, 2u, 7u, 13u, TextDirection::kRtl);
202 TEST_TEXT_FRAGMENT(fragments[4], node, 8u, 22u, 28u, TextDirection::kLtr); 216 TEST_TEXT_FRAGMENT(fragments[4], node, 8u, 22u, 28u, TextDirection::kLtr);
203 } 217 }
204 218
219 TEST_F(NGInlineNodeTest, MinAndMaxContentSizes) {
220 setAhemToStyle();
221 NGInlineNodeForTest* node = new NGInlineNodeForTest(style_.get());
222 node->Append("AB CDE", style_.get());
223 node->ShapeText();
224 MinAndMaxContentSizes sizes = node->ComputeMinAndMaxContentSizes();
225 // TODO(kojii): min_content should be 20, but is 30 until NGLineBuilder
226 // implements trailing spaces correctly.
227 EXPECT_EQ(30, sizes.min_content);
228 EXPECT_EQ(60, sizes.max_content);
229 }
230
231 TEST_F(NGInlineNodeTest, MinAndMaxContentSizesElementBoundary) {
232 setAhemToStyle();
233 NGInlineNodeForTest* node = new NGInlineNodeForTest(style_.get());
234 node->Append("A B", style_.get());
235 node->Append("C D", style_.get());
236 node->ShapeText();
237 MinAndMaxContentSizes sizes = node->ComputeMinAndMaxContentSizes();
238 // |min_content| should be the width of "BC" because there is an element
239 // boundary between "B" and "C" but no break opportunities.
240 // TODO(kojii): min_content should be 20, but is 30 until NGLineBuilder
241 // implements trailing spaces correctly.
242 EXPECT_EQ(30, sizes.min_content);
243 EXPECT_EQ(60, sizes.max_content);
244 }
245
205 } // namespace blink 246 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_inline_node.cc ('k') | third_party/WebKit/Source/core/layout/ng/ng_line_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698