| OLD | NEW |
| 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/inline/ng_inline_layout_algorithm.h" | 5 #include "core/layout/ng/inline/ng_inline_layout_algorithm.h" |
| 6 | 6 |
| 7 #include "core/layout/ng/inline/ng_bidi_paragraph.h" | 7 #include "core/layout/ng/inline/ng_bidi_paragraph.h" |
| 8 #include "core/layout/ng/inline/ng_inline_break_token.h" | 8 #include "core/layout/ng/inline/ng_inline_break_token.h" |
| 9 #include "core/layout/ng/inline/ng_inline_node.h" | 9 #include "core/layout/ng/inline/ng_inline_node.h" |
| 10 #include "core/layout/ng/inline/ng_line_box_fragment.h" | 10 #include "core/layout/ng/inline/ng_line_box_fragment.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 const ComputedStyle& style = child.Style(); | 36 const ComputedStyle& style = child.Style(); |
| 37 | 37 |
| 38 bool is_new_bfc = | 38 bool is_new_bfc = |
| 39 IsNewFormattingContextForBlockLevelChild(parent_style, child); | 39 IsNewFormattingContextForBlockLevelChild(parent_style, child); |
| 40 return space_builder->SetIsNewFormattingContext(is_new_bfc) | 40 return space_builder->SetIsNewFormattingContext(is_new_bfc) |
| 41 .SetTextDirection(style.Direction()) | 41 .SetTextDirection(style.Direction()) |
| 42 .SetIsShrinkToFit(ShouldShrinkToFit(parent_style, style)) | 42 .SetIsShrinkToFit(ShouldShrinkToFit(parent_style, style)) |
| 43 .ToConstraintSpace(FromPlatformWritingMode(style.GetWritingMode())); | 43 .ToConstraintSpace(FromPlatformWritingMode(style.GetWritingMode())); |
| 44 } | 44 } |
| 45 | 45 |
| 46 NGLogicalOffset GetOriginPointForFloats(const NGConstraintSpace& space, | 46 NGLogicalOffset GetOriginPointForFloats( |
| 47 LayoutUnit content_size) { | 47 const NGLogicalOffset& container_bfc_offset, |
| 48 NGLogicalOffset origin_point = space.BfcOffset(); | 48 LayoutUnit content_size) { |
| 49 NGLogicalOffset origin_point = container_bfc_offset; |
| 49 origin_point.block_offset += content_size; | 50 origin_point.block_offset += content_size; |
| 50 return origin_point; | 51 return origin_point; |
| 51 } | 52 } |
| 52 | 53 |
| 53 } // namespace | 54 } // namespace |
| 54 | 55 |
| 55 NGInlineLayoutAlgorithm::NGInlineLayoutAlgorithm( | 56 NGInlineLayoutAlgorithm::NGInlineLayoutAlgorithm( |
| 56 NGInlineNode* inline_node, | 57 NGInlineNode* inline_node, |
| 57 NGConstraintSpace* space, | 58 NGConstraintSpace* space, |
| 58 NGInlineBreakToken* break_token) | 59 NGInlineBreakToken* break_token) |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 start_index_++; | 289 start_index_++; |
| 289 } | 290 } |
| 290 DCHECK_GE(end_position_, last_break_opportunity_position_); | 291 DCHECK_GE(end_position_, last_break_opportunity_position_); |
| 291 end_position_ -= last_break_opportunity_position_; | 292 end_position_ -= last_break_opportunity_position_; |
| 292 last_break_opportunity_position_ = LayoutUnit(); | 293 last_break_opportunity_position_ = LayoutUnit(); |
| 293 #if DCHECK_IS_ON() | 294 #if DCHECK_IS_ON() |
| 294 is_bidi_reordered_ = false; | 295 is_bidi_reordered_ = false; |
| 295 #endif | 296 #endif |
| 296 | 297 |
| 297 NGLogicalOffset origin_point = | 298 NGLogicalOffset origin_point = |
| 298 GetOriginPointForFloats(ConstraintSpace(), content_size_); | 299 GetOriginPointForFloats(ContainerBfcOffset(), content_size_); |
| 299 PositionPendingFloats(origin_point.block_offset, &container_builder_, | 300 PositionPendingFloats(origin_point.block_offset, &container_builder_, |
| 300 MutableConstraintSpace()); | 301 MutableConstraintSpace()); |
| 301 FindNextLayoutOpportunity(); | 302 FindNextLayoutOpportunity(); |
| 302 return true; | 303 return true; |
| 303 } | 304 } |
| 304 | 305 |
| 305 void NGInlineLayoutAlgorithm::BidiReorder( | 306 void NGInlineLayoutAlgorithm::BidiReorder( |
| 306 Vector<LineItemChunk, 32>* line_item_chunks) { | 307 Vector<LineItemChunk, 32>* line_item_chunks) { |
| 307 #if DCHECK_IS_ON() | 308 #if DCHECK_IS_ON() |
| 308 DCHECK(!is_bidi_reordered_); | 309 DCHECK(!is_bidi_reordered_); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 // determine if it fits on this line, then perform layout with the correct | 369 // determine if it fits on this line, then perform layout with the correct |
| 369 // fragmentation line. | 370 // fragmentation line. |
| 370 // diff writing mode - get the inline size from performing layout. | 371 // diff writing mode - get the inline size from performing layout. |
| 371 RefPtr<NGLayoutResult> layout_result = node->Layout(float_space.Get()); | 372 RefPtr<NGLayoutResult> layout_result = node->Layout(float_space.Get()); |
| 372 | 373 |
| 373 NGBoxFragment float_fragment( | 374 NGBoxFragment float_fragment( |
| 374 float_space->WritingMode(), | 375 float_space->WritingMode(), |
| 375 ToNGPhysicalBoxFragment(layout_result->PhysicalFragment().Get())); | 376 ToNGPhysicalBoxFragment(layout_result->PhysicalFragment().Get())); |
| 376 | 377 |
| 377 NGLogicalOffset origin_offset = | 378 NGLogicalOffset origin_offset = |
| 378 GetOriginPointForFloats(ConstraintSpace(), content_size_); | 379 GetOriginPointForFloats(ContainerBfcOffset(), content_size_); |
| 379 NGLogicalOffset from_offset = ConstraintSpace().BfcOffset(); | |
| 380 const ComputedStyle& float_style = node->Style(); | 380 const ComputedStyle& float_style = node->Style(); |
| 381 NGBoxStrut margins = ComputeMargins(ConstraintSpace(), float_style, | 381 NGBoxStrut margins = ComputeMargins(ConstraintSpace(), float_style, |
| 382 ConstraintSpace().WritingMode(), | 382 ConstraintSpace().WritingMode(), |
| 383 ConstraintSpace().Direction()); | 383 ConstraintSpace().Direction()); |
| 384 RefPtr<NGFloatingObject> floating_object = NGFloatingObject::Create( | 384 RefPtr<NGFloatingObject> floating_object = NGFloatingObject::Create( |
| 385 float_style, float_space->WritingMode(), current_opportunity_.size, | 385 float_style, float_space->WritingMode(), current_opportunity_.size, |
| 386 origin_offset, from_offset, margins, | 386 origin_offset, ContainerBfcOffset(), margins, |
| 387 layout_result->PhysicalFragment().Get()); | 387 layout_result->PhysicalFragment().Get()); |
| 388 floating_object->parent_bfc_block_offset = ContainerBfcOffset().block_offset; |
| 388 | 389 |
| 389 bool float_does_not_fit = end_position + float_fragment.InlineSize() > | 390 bool float_does_not_fit = end_position + float_fragment.InlineSize() > |
| 390 current_opportunity_.InlineSize(); | 391 current_opportunity_.InlineSize(); |
| 391 // Check if we already have a pending float. That's because a float cannot be | 392 // Check if we already have a pending float. That's because a float cannot be |
| 392 // higher than any block or floated box generated before. | 393 // higher than any block or floated box generated before. |
| 393 if (!container_builder_.UnpositionedFloats().IsEmpty() || | 394 if (!container_builder_.UnpositionedFloats().IsEmpty() || |
| 394 float_does_not_fit) { | 395 float_does_not_fit) { |
| 395 container_builder_.AddUnpositionedFloat(floating_object); | 396 container_builder_.AddUnpositionedFloat(floating_object); |
| 396 } else { | 397 } else { |
| 397 container_builder_.MutablePositionedFloats().push_back( | 398 container_builder_.MutablePositionedFloats().push_back( |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 | 597 |
| 597 // max-content is the width without any line wrapping. | 598 // max-content is the width without any line wrapping. |
| 598 // TODO(kojii): Implement hard breaks (<br> etc.) to break. | 599 // TODO(kojii): Implement hard breaks (<br> etc.) to break. |
| 599 for (const auto& item : Node()->Items()) | 600 for (const auto& item : Node()->Items()) |
| 600 sizes.max_content += InlineSize(item); | 601 sizes.max_content += InlineSize(item); |
| 601 | 602 |
| 602 return sizes; | 603 return sizes; |
| 603 } | 604 } |
| 604 | 605 |
| 605 } // namespace blink | 606 } // namespace blink |
| OLD | NEW |