Index: third_party/WebKit/Source/core/layout/ng/ng_box_fragment.cc |
diff --git a/third_party/WebKit/Source/core/layout/ng/ng_box_fragment.cc b/third_party/WebKit/Source/core/layout/ng/ng_box_fragment.cc |
index 99db6d83e1faeb286bd49a50ad8494be71a007c2..175c163491abe441ed392f7740a8f0d47e36e21f 100644 |
--- a/third_party/WebKit/Source/core/layout/ng/ng_box_fragment.cc |
+++ b/third_party/WebKit/Source/core/layout/ng/ng_box_fragment.cc |
@@ -4,7 +4,9 @@ |
#include "core/layout/ng/ng_box_fragment.h" |
+#include "core/layout/LayoutBox.h" |
#include "core/layout/ng/geometry/ng_logical_size.h" |
+#include "core/layout/ng/inline/ng_line_height_metrics.h" |
#include "core/layout/ng/ng_macros.h" |
#include "core/layout/ng/ng_physical_box_fragment.h" |
@@ -15,4 +17,40 @@ NGLogicalSize NGBoxFragment::OverflowSize() const { |
return physical_fragment->OverflowSize().ConvertToLogical(WritingMode()); |
} |
+NGLineHeightMetrics NGBoxFragment::BaselineMetrics( |
+ const NGBaselineRequest& request) const { |
+ LayoutBox* layout_box = ToLayoutBox(physical_fragment_->GetLayoutObject()); |
+ |
+ // Find the baseline from the computed results. |
+ const NGPhysicalBoxFragment* physical_fragment = |
+ ToNGPhysicalBoxFragment(physical_fragment_); |
+ if (const NGBaseline* baseline = physical_fragment->Baseline(request)) { |
+ LayoutUnit ascent = baseline->offset; |
+ LayoutUnit descent = BlockSize() - ascent; |
+ |
+ // 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 |
+ if (layout_box->IsAtomicInlineLevel()) { |
+ ascent += layout_box->MarginOver(); |
+ descent += layout_box->MarginUnder(); |
+ } |
+ |
+ return NGLineHeightMetrics(ascent, descent); |
+ } |
+ |
+ // The baseline type was not found. This is either this box should synthesize |
+ // box-baseline without propagating from children, or caller forgot to add |
+ // baseline requests to constraint space when it called Layout(). |
+ LayoutUnit block_size = BlockSize(); |
+ |
+ // If atomic inline, use the margin box. See above. |
+ if (layout_box->IsAtomicInlineLevel()) |
+ block_size += layout_box->MarginLogicalHeight(); |
+ |
+ if (request.baseline_type == kAlphabeticBaseline) |
+ return NGLineHeightMetrics(block_size, LayoutUnit()); |
+ return NGLineHeightMetrics(block_size - block_size / 2, block_size / 2); |
+} |
+ |
} // namespace blink |