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

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

Issue 2790283003: Reset constraint space's BFC offset if block creates a new FC (Closed)
Patch Set: git rebase-update Created 3 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_floats_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_layout_algorithm.h" 5 #include "core/layout/ng/ng_inline_layout_algorithm.h"
6 6
7 #include "core/layout/BidiRun.h" 7 #include "core/layout/BidiRun.h"
8 #include "core/layout/LayoutBlockFlow.h" 8 #include "core/layout/LayoutBlockFlow.h"
9 #include "core/layout/line/LineInfo.h" 9 #include "core/layout/line/LineInfo.h"
10 #include "core/layout/line/RootInlineBox.h" 10 #include "core/layout/line/RootInlineBox.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 .SetIsShrinkToFit(ShouldShrinkToFit(parent_style, style)) 46 .SetIsShrinkToFit(ShouldShrinkToFit(parent_style, style))
47 .ToConstraintSpace(FromPlatformWritingMode(style.getWritingMode())); 47 .ToConstraintSpace(FromPlatformWritingMode(style.getWritingMode()));
48 } 48 }
49 49
50 NGLogicalOffset GetOriginPointForFloats(const NGConstraintSpace& space, 50 NGLogicalOffset GetOriginPointForFloats(const NGConstraintSpace& space,
51 LayoutUnit content_size) { 51 LayoutUnit content_size) {
52 NGLogicalOffset origin_point = space.BfcOffset(); 52 NGLogicalOffset origin_point = space.BfcOffset();
53 origin_point.block_offset += content_size; 53 origin_point.block_offset += content_size;
54 return origin_point; 54 return origin_point;
55 } 55 }
56
57 void PositionPendingFloats(const NGLogicalOffset& origin_point,
58 NGConstraintSpace* space,
59 NGFragmentBuilder* builder) {
60 DCHECK(builder) << "Builder cannot be null here";
61
62 for (auto& floating_object : builder->UnpositionedFloats()) {
63 NGLogicalOffset offset = PositionFloat(origin_point, space->BfcOffset(),
64 floating_object.get(), space);
65 builder->AddFloatingObject(floating_object, offset);
66 }
67 builder->MutableUnpositionedFloats().clear();
68 }
69
70 } // namespace 56 } // namespace
71 57
72 NGInlineLayoutAlgorithm::NGInlineLayoutAlgorithm( 58 NGInlineLayoutAlgorithm::NGInlineLayoutAlgorithm(
73 NGInlineNode* inline_node, 59 NGInlineNode* inline_node,
74 NGConstraintSpace* space, 60 NGConstraintSpace* space,
75 NGInlineBreakToken* break_token) 61 NGInlineBreakToken* break_token)
76 : NGLayoutAlgorithm(inline_node, space, break_token), 62 : NGLayoutAlgorithm(inline_node, space, break_token),
77 container_builder_(NGPhysicalFragment::kFragmentBox, inline_node), 63 container_builder_(NGPhysicalFragment::kFragmentBox, inline_node),
78 is_horizontal_writing_mode_( 64 is_horizontal_writing_mode_(
79 blink::IsHorizontalWritingMode(space->WritingMode())), 65 blink::IsHorizontalWritingMode(space->WritingMode())),
80 space_builder_(space) 66 space_builder_(space)
81 #if DCHECK_IS_ON() 67 #if DCHECK_IS_ON()
82 , 68 ,
83 is_bidi_reordered_(false) 69 is_bidi_reordered_(false)
84 #endif 70 #endif
85 { 71 {
86 if (!is_horizontal_writing_mode_) 72 if (!is_horizontal_writing_mode_)
87 baseline_type_ = FontBaseline::IdeographicBaseline; 73 baseline_type_ = FontBaseline::IdeographicBaseline;
88 if (break_token) 74 if (break_token)
89 Initialize(break_token->ItemIndex(), break_token->TextOffset()); 75 Initialize(break_token->ItemIndex(), break_token->TextOffset());
90 else 76 else
91 Initialize(0, 0); 77 Initialize(0, 0);
78
79 // BFC offset is known for inline fragments.
80 container_builder_.SetBfcOffset(space->BfcOffset());
92 } 81 }
93 82
94 bool NGInlineLayoutAlgorithm::CanFitOnLine() const { 83 bool NGInlineLayoutAlgorithm::CanFitOnLine() const {
95 LayoutUnit available_size = current_opportunity_.InlineSize(); 84 LayoutUnit available_size = current_opportunity_.InlineSize();
96 if (available_size == NGSizeIndefinite) 85 if (available_size == NGSizeIndefinite)
97 return true; 86 return true;
98 return end_position_ <= available_size; 87 return end_position_ <= available_size;
99 } 88 }
100 89
101 bool NGInlineLayoutAlgorithm::HasItems() const { 90 bool NGInlineLayoutAlgorithm::HasItems() const {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 start_offset_ = last_break_opportunity_offset_; 261 start_offset_ = last_break_opportunity_offset_;
273 DCHECK_GE(end_position_, last_break_opportunity_position_); 262 DCHECK_GE(end_position_, last_break_opportunity_position_);
274 end_position_ -= last_break_opportunity_position_; 263 end_position_ -= last_break_opportunity_position_;
275 last_break_opportunity_position_ = LayoutUnit(); 264 last_break_opportunity_position_ = LayoutUnit();
276 #if DCHECK_IS_ON() 265 #if DCHECK_IS_ON()
277 is_bidi_reordered_ = false; 266 is_bidi_reordered_ = false;
278 #endif 267 #endif
279 268
280 NGLogicalOffset origin_point = 269 NGLogicalOffset origin_point =
281 GetOriginPointForFloats(ConstraintSpace(), content_size_); 270 GetOriginPointForFloats(ConstraintSpace(), content_size_);
282 PositionPendingFloats(origin_point, MutableConstraintSpace(), 271 PositionPendingFloats(origin_point.block_offset, MutableConstraintSpace(),
283 &container_builder_); 272 &container_builder_);
284 FindNextLayoutOpportunity(); 273 FindNextLayoutOpportunity();
285 return true; 274 return true;
286 } 275 }
287 276
288 void NGInlineLayoutAlgorithm::BidiReorder( 277 void NGInlineLayoutAlgorithm::BidiReorder(
289 Vector<LineItemChunk, 32>* line_item_chunks) { 278 Vector<LineItemChunk, 32>* line_item_chunks) {
290 #if DCHECK_IS_ON() 279 #if DCHECK_IS_ON()
291 DCHECK(!is_bidi_reordered_); 280 DCHECK(!is_bidi_reordered_);
292 is_bidi_reordered_ = true; 281 is_bidi_reordered_ = true;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 // same writing mode - get the inline size ComputeInlineSizeForFragment to 321 // same writing mode - get the inline size ComputeInlineSizeForFragment to
333 // determine if it fits on this line, then perform layout with the correct 322 // determine if it fits on this line, then perform layout with the correct
334 // fragmentation line. 323 // fragmentation line.
335 // diff writing mode - get the inline size from performing layout. 324 // diff writing mode - get the inline size from performing layout.
336 RefPtr<NGLayoutResult> layout_result = node->Layout(float_space.get()); 325 RefPtr<NGLayoutResult> layout_result = node->Layout(float_space.get());
337 326
338 NGBoxFragment float_fragment( 327 NGBoxFragment float_fragment(
339 float_space->WritingMode(), 328 float_space->WritingMode(),
340 toNGPhysicalBoxFragment(layout_result->PhysicalFragment().get())); 329 toNGPhysicalBoxFragment(layout_result->PhysicalFragment().get()));
341 330
331 NGLogicalOffset origin_offset =
332 GetOriginPointForFloats(ConstraintSpace(), content_size_);
333 NGLogicalOffset from_offset = ConstraintSpace().BfcOffset();
334 // TODO(glebl): add margins calculation.
335 NGBoxStrut margins;
342 RefPtr<NGFloatingObject> floating_object = NGFloatingObject::Create( 336 RefPtr<NGFloatingObject> floating_object = NGFloatingObject::Create(
343 float_space.get(), MutableConstraintSpace(), node->Style(), NGBoxStrut(), 337 node->Style(), float_space->WritingMode(), current_opportunity_.size,
344 current_opportunity_.size, layout_result->PhysicalFragment().get()); 338 origin_offset, from_offset, margins,
339 layout_result->PhysicalFragment().get());
345 340
346 bool float_does_not_fit = end_position + float_fragment.InlineSize() > 341 bool float_does_not_fit = end_position + float_fragment.InlineSize() >
347 current_opportunity_.InlineSize(); 342 current_opportunity_.InlineSize();
348 // Check if we already have a pending float. That's because a float cannot be 343 // Check if we already have a pending float. That's because a float cannot be
349 // higher than any block or floated box generated before. 344 // higher than any block or floated box generated before.
350 if (!container_builder_.UnpositionedFloats().isEmpty() || 345 if (!container_builder_.UnpositionedFloats().isEmpty() ||
351 float_does_not_fit) { 346 float_does_not_fit) {
352 container_builder_.AddUnpositionedFloat(floating_object); 347 container_builder_.AddUnpositionedFloat(floating_object);
353 } else { 348 } else {
354 NGLogicalOffset origin_point =
355 GetOriginPointForFloats(ConstraintSpace(), content_size_);
356 NGLogicalOffset offset = 349 NGLogicalOffset offset =
357 PositionFloat(origin_point, ConstraintSpace().BfcOffset(), 350 PositionFloat(floating_object.get(), MutableConstraintSpace());
358 floating_object.get(), MutableConstraintSpace());
359 container_builder_.AddFloatingObject(floating_object, offset); 351 container_builder_.AddFloatingObject(floating_object, offset);
360 FindNextLayoutOpportunity(); 352 FindNextLayoutOpportunity();
361 } 353 }
362 } 354 }
363 355
364 bool NGInlineLayoutAlgorithm::PlaceItems( 356 bool NGInlineLayoutAlgorithm::PlaceItems(
365 const Vector<LineItemChunk, 32>& line_item_chunks) { 357 const Vector<LineItemChunk, 32>& line_item_chunks) {
366 const Vector<NGLayoutInlineItem>& items = Node()->Items(); 358 const Vector<NGLayoutInlineItem>& items = Node()->Items();
367 359
368 NGLineBoxFragmentBuilder line_box(Node()); 360 NGLineBoxFragmentBuilder line_box(Node());
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 LayoutUnit baseline = line_top_with_leading + metrics.ascent_and_leading; 635 LayoutUnit baseline = line_top_with_leading + metrics.ascent_and_leading;
644 root_line_box->setLineTopBottomPositions( 636 root_line_box->setLineTopBottomPositions(
645 baseline - metrics.ascent, baseline + metrics.descent, 637 baseline - metrics.ascent, baseline + metrics.descent,
646 line_top_with_leading, baseline + metrics.descent_and_leading); 638 line_top_with_leading, baseline + metrics.descent_and_leading);
647 639
648 bidi_runs.deleteRuns(); 640 bidi_runs.deleteRuns();
649 fragments_for_bidi_runs.clear(); 641 fragments_for_bidi_runs.clear();
650 } 642 }
651 } 643 }
652 } // namespace blink 644 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_floats_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698