| 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_line_breaker.h" | 5 #include "core/layout/ng/inline/ng_line_breaker.h" |
| 6 | 6 |
| 7 #include "core/layout/ng/inline/ng_inline_break_token.h" | 7 #include "core/layout/ng/inline/ng_inline_break_token.h" |
| 8 #include "core/layout/ng/inline/ng_inline_layout_algorithm.h" | 8 #include "core/layout/ng/inline/ng_inline_layout_algorithm.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_text_fragment.h" | 10 #include "core/layout/ng/inline/ng_text_fragment.h" |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 const ComputedStyle& float_style = node.Style(); | 410 const ComputedStyle& float_style = node.Style(); |
| 411 NGBoxStrut margins = ComputeMargins(*constraint_space_, float_style, | 411 NGBoxStrut margins = ComputeMargins(*constraint_space_, float_style, |
| 412 constraint_space_->WritingMode(), | 412 constraint_space_->WritingMode(), |
| 413 constraint_space_->Direction()); | 413 constraint_space_->Direction()); |
| 414 | 414 |
| 415 // TODO(ikilpatrick): Add support for float break tokens inside an inline | 415 // TODO(ikilpatrick): Add support for float break tokens inside an inline |
| 416 // layout context. | 416 // layout context. |
| 417 RefPtr<NGUnpositionedFloat> unpositioned_float = NGUnpositionedFloat::Create( | 417 RefPtr<NGUnpositionedFloat> unpositioned_float = NGUnpositionedFloat::Create( |
| 418 constraint_space_->AvailableSize(), | 418 constraint_space_->AvailableSize(), |
| 419 constraint_space_->PercentageResolutionSize(), | 419 constraint_space_->PercentageResolutionSize(), |
| 420 constraint_space_->BfcOffset(), constraint_space_->BfcOffset(), margins, | 420 constraint_space_->BfcOffset().inline_offset, |
| 421 node, /* break_token */ nullptr); | 421 constraint_space_->BfcOffset().inline_offset, margins, node, |
| 422 /* break_token */ nullptr); |
| 422 | 423 |
| 423 LayoutUnit inline_size = ComputeInlineSizeForUnpositionedFloat( | 424 LayoutUnit inline_size = ComputeInlineSizeForUnpositionedFloat( |
| 424 constraint_space_, unpositioned_float.Get()); | 425 constraint_space_, unpositioned_float.Get()); |
| 425 | 426 |
| 426 // We can only determine if our float will fit if we have an available_width | 427 // We can only determine if our float will fit if we have an available_width |
| 427 // I.e. we may not have come across any text yet, in order to be able to | 428 // I.e. we may not have come across any text yet, in order to be able to |
| 428 // resolve the BFC position. | 429 // resolve the BFC position. |
| 429 bool float_does_not_fit = | 430 bool float_does_not_fit = |
| 430 !HasAvailableWidth() || | 431 !HasAvailableWidth() || |
| 431 position_ + inline_size + margins.InlineSum() > AvailableWidth(); | 432 position_ + inline_size + margins.InlineSum() > AvailableWidth(); |
| 432 | 433 |
| 433 // Check if we already have a pending float. That's because a float cannot be | 434 // Check if we already have a pending float. That's because a float cannot be |
| 434 // higher than any block or floated box generated before. | 435 // higher than any block or floated box generated before. |
| 435 if (!container_builder_->UnpositionedFloats().IsEmpty() || | 436 if (!container_builder_->UnpositionedFloats().IsEmpty() || |
| 436 float_does_not_fit) { | 437 float_does_not_fit) { |
| 437 container_builder_->AddUnpositionedFloat(unpositioned_float); | 438 container_builder_->AddUnpositionedFloat(unpositioned_float); |
| 438 } else { | 439 } else { |
| 439 NGLogicalOffset container_bfc_offset = | 440 NGLogicalOffset container_bfc_offset = |
| 440 container_builder_->BfcOffset().value(); | 441 container_builder_->BfcOffset().value(); |
| 441 unpositioned_float->origin_offset = container_bfc_offset + content_offset_; | 442 LayoutUnit origin_block_offset = |
| 442 unpositioned_float->from_offset.block_offset = | 443 container_bfc_offset.block_offset + content_offset_.block_offset; |
| 443 container_bfc_offset.block_offset; | |
| 444 unpositioned_float->parent_bfc_block_offset = | |
| 445 container_bfc_offset.block_offset; | |
| 446 | 444 |
| 447 container_builder_->AddPositionedFloat( | 445 container_builder_->AddPositionedFloat( |
| 448 PositionFloat(unpositioned_float.Get(), constraint_space_)); | 446 PositionFloat(origin_block_offset, container_bfc_offset.block_offset, |
| 447 unpositioned_float.Get(), constraint_space_)); |
| 449 | 448 |
| 450 // We need to recalculate the available_width as the float probably | 449 // We need to recalculate the available_width as the float probably |
| 451 // consumed space on the line. | 450 // consumed space on the line. |
| 452 UpdateAvailableWidth(); | 451 UpdateAvailableWidth(); |
| 453 } | 452 } |
| 454 | 453 |
| 455 // Floats are already positioned in the container_builder. | 454 // Floats are already positioned in the container_builder. |
| 456 item_results->pop_back(); | 455 item_results->pop_back(); |
| 457 MoveToNextOf(item); | 456 MoveToNextOf(item); |
| 458 } | 457 } |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 } | 684 } |
| 686 | 685 |
| 687 RefPtr<NGInlineBreakToken> NGLineBreaker::CreateBreakToken() const { | 686 RefPtr<NGInlineBreakToken> NGLineBreaker::CreateBreakToken() const { |
| 688 const Vector<NGInlineItem>& items = node_.Items(); | 687 const Vector<NGInlineItem>& items = node_.Items(); |
| 689 if (item_index_ >= items.size()) | 688 if (item_index_ >= items.size()) |
| 690 return nullptr; | 689 return nullptr; |
| 691 return NGInlineBreakToken::Create(node_, item_index_, offset_); | 690 return NGInlineBreakToken::Create(node_, item_index_, offset_); |
| 692 } | 691 } |
| 693 | 692 |
| 694 } // namespace blink | 693 } // namespace blink |
| OLD | NEW |