| Index: third_party/WebKit/Source/core/layout/ng/inline/ng_inline_layout_algorithm.cc
|
| diff --git a/third_party/WebKit/Source/core/layout/ng/inline/ng_inline_layout_algorithm.cc b/third_party/WebKit/Source/core/layout/ng/inline/ng_inline_layout_algorithm.cc
|
| index c1792201e175ec5e1339ef780b5eb4ef3216216a..330a8b93e2986640ca975447bd3a409431e3296d 100644
|
| --- a/third_party/WebKit/Source/core/layout/ng/inline/ng_inline_layout_algorithm.cc
|
| +++ b/third_party/WebKit/Source/core/layout/ng/inline/ng_inline_layout_algorithm.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "core/layout/ng/inline/ng_inline_layout_algorithm.h"
|
|
|
| +#include "core/layout/ng/inline/ng_baseline.h"
|
| #include "core/layout/ng/inline/ng_bidi_paragraph.h"
|
| #include "core/layout/ng/inline/ng_inline_break_token.h"
|
| #include "core/layout/ng/inline/ng_inline_node.h"
|
| @@ -287,25 +288,15 @@ NGInlineBoxState* NGInlineLayoutAlgorithm::PlaceAtomicInline(
|
| NGInlineBoxState* box =
|
| box_states_.OnOpenTag(item, *item_result, line_box, position);
|
|
|
| - // For replaced elements, inline-block elements, and inline-table elements,
|
| - // the height is the height of their margin box.
|
| - // https://drafts.csswg.org/css2/visudet.html#line-height
|
| NGBoxFragment fragment(
|
| ConstraintSpace().WritingMode(),
|
| ToNGPhysicalBoxFragment(
|
| item_result->layout_result->PhysicalFragment().Get()));
|
| - LayoutUnit block_size =
|
| - fragment.BlockSize() + item_result->margins.BlockSum();
|
| -
|
| - // TODO(kojii): Add baseline position to NGPhysicalFragment.
|
| - LayoutBox* layout_box = ToLayoutBox(item.GetLayoutObject());
|
| - LineDirectionMode line_direction_mode =
|
| - IsHorizontalWritingMode() ? LineDirectionMode::kHorizontalLine
|
| - : LineDirectionMode::kVerticalLine;
|
| - LayoutUnit baseline_offset(layout_box->BaselinePosition(
|
| - baseline_type_, line_info.UseFirstLineStyle(), line_direction_mode));
|
| -
|
| - NGLineHeightMetrics metrics(baseline_offset, block_size - baseline_offset);
|
| + NGLineHeightMetrics metrics = fragment.BaselineMetrics(
|
| + {line_info.UseFirstLineStyle()
|
| + ? NGBaselineAlgorithmType::kAtomicInlineForFirstLine
|
| + : NGBaselineAlgorithmType::kAtomicInline,
|
| + baseline_type_});
|
| box->metrics.Unite(metrics);
|
|
|
| // TODO(kojii): Figure out what to do with OOF in NGLayoutResult.
|
| @@ -315,7 +306,7 @@ NGInlineBoxState* NGInlineLayoutAlgorithm::PlaceAtomicInline(
|
| // |fragment| directly. Currently |CopyFragmentDataToLayoutBlockFlow|
|
| // requires a text fragment.
|
| text_builder->SetDirection(style.Direction());
|
| - text_builder->SetSize({fragment.InlineSize(), block_size});
|
| + text_builder->SetSize({fragment.InlineSize(), metrics.LineHeight()});
|
| LayoutUnit line_top = item_result->margins.block_start - metrics.ascent;
|
| RefPtr<NGPhysicalTextFragment> text_fragment = text_builder->ToTextFragment(
|
| item_result->item_index, item_result->start_offset,
|
| @@ -406,6 +397,50 @@ LayoutUnit NGInlineLayoutAlgorithm::ComputeContentSize(
|
| return content_size;
|
| }
|
|
|
| +// Add a baseline from a child line box.
|
| +// @return false if the specified child is not a line box.
|
| +bool NGInlineLayoutAlgorithm::AddBaseline(const NGBaselineRequest& request,
|
| + unsigned child_index) {
|
| + const NGPhysicalFragment* child =
|
| + container_builder_.Children()[child_index].Get();
|
| + if (!child->IsLineBox())
|
| + return false;
|
| +
|
| + const NGPhysicalLineBoxFragment* line_box =
|
| + ToNGPhysicalLineBoxFragment(child);
|
| + LayoutUnit offset = line_box->BaselinePosition(request.baseline_type);
|
| + container_builder_.AddBaseline(
|
| + request.algorithm_type, request.baseline_type,
|
| + offset + container_builder_.Offsets()[child_index].block_offset);
|
| + return true;
|
| +}
|
| +
|
| +// Compute requested baselines from child line boxes.
|
| +void NGInlineLayoutAlgorithm::PropagateBaselinesFromChildren() {
|
| + const Vector<NGBaselineRequest>& requests =
|
| + ConstraintSpace().BaselineRequests();
|
| + if (requests.IsEmpty())
|
| + return;
|
| +
|
| + for (const auto& request : requests) {
|
| + switch (request.algorithm_type) {
|
| + case NGBaselineAlgorithmType::kAtomicInline:
|
| + case NGBaselineAlgorithmType::kAtomicInlineForFirstLine:
|
| + for (unsigned i = container_builder_.Children().size(); i--;) {
|
| + if (AddBaseline(request, i))
|
| + break;
|
| + }
|
| + break;
|
| + case NGBaselineAlgorithmType::kFirstLine:
|
| + for (unsigned i = 0; i < container_builder_.Children().size(); i++) {
|
| + if (AddBaseline(request, i))
|
| + break;
|
| + }
|
| + break;
|
| + }
|
| + }
|
| +}
|
| +
|
| RefPtr<NGLayoutResult> NGInlineLayoutAlgorithm::Layout() {
|
| // Line boxes should start at (0,0).
|
| // The parent NGBlockLayoutAlgorithm places the anonymous wrapper using the
|
| @@ -429,6 +464,8 @@ RefPtr<NGLayoutResult> NGInlineLayoutAlgorithm::Layout() {
|
| container_builder_.SetEndMarginStrut(ConstraintSpace().MarginStrut());
|
| }
|
|
|
| + PropagateBaselinesFromChildren();
|
| +
|
| return container_builder_.ToBoxFragment();
|
| }
|
|
|
|
|