Index: third_party/WebKit/Source/core/layout/ng/inline/ng_inline_box_state.cc |
diff --git a/third_party/WebKit/Source/core/layout/ng/inline/ng_inline_box_state.cc b/third_party/WebKit/Source/core/layout/ng/inline/ng_inline_box_state.cc |
index ffe3456984ef16cca82af74c8772c733dc84cf8b..084904c04f75700cd849e00925645a96a8d6dd33 100644 |
--- a/third_party/WebKit/Source/core/layout/ng/inline/ng_inline_box_state.cc |
+++ b/third_party/WebKit/Source/core/layout/ng/inline/ng_inline_box_state.cc |
@@ -11,9 +11,8 @@ |
namespace blink { |
-void NGInlineBoxState::ComputeTextMetrics(const NGInlineItem& item, |
+void NGInlineBoxState::ComputeTextMetrics(const ComputedStyle& style, |
FontBaseline baseline_type) { |
- const ComputedStyle& style = *item.Style(); |
text_metrics = NGLineHeightMetrics(style, baseline_type); |
text_top = -text_metrics.ascent; |
text_metrics.AddLeading(style.ComputedLineHeightAsFixed()); |
@@ -22,23 +21,47 @@ void NGInlineBoxState::ComputeTextMetrics(const NGInlineItem& item, |
include_used_fonts = style.LineHeight().IsNegative(); |
} |
+void NGInlineBoxState::AccumulateUsedFonts(const NGInlineItem& item, |
+ unsigned start, |
+ unsigned end, |
+ FontBaseline baseline_type) { |
+ HashSet<const SimpleFontData*> fallback_fonts; |
+ item.GetFallbackFonts(&fallback_fonts, start, end); |
+ for (const auto& fallback_font : fallback_fonts) { |
+ NGLineHeightMetrics fallback_metrics(fallback_font->GetFontMetrics(), |
+ baseline_type); |
+ fallback_metrics.AddLeading( |
+ fallback_font->GetFontMetrics().FixedLineSpacing()); |
+ metrics.Unite(fallback_metrics); |
+ } |
+} |
+ |
NGInlineBoxState* NGInlineLayoutStateStack::OnBeginPlaceItems( |
- const ComputedStyle* line_style) { |
+ const ComputedStyle* line_style, |
+ FontBaseline baseline_type) { |
if (stack_.IsEmpty()) { |
// For the first line, push a box state for the line itself. |
stack_.Resize(1); |
NGInlineBoxState* box = &stack_.back(); |
box->fragment_start = 0; |
- box->style = line_style; |
- return box; |
+ } else { |
+ // For the following lines, clear states that are not shared across lines. |
+ for (auto& box : stack_) { |
+ box.fragment_start = 0; |
+ box.metrics = NGLineHeightMetrics(); |
+ DCHECK(box.pending_descendants.IsEmpty()); |
+ } |
} |
- // For the following lines, clear states that are not shared across lines. |
- for (auto& box : stack_) { |
- box.fragment_start = 0; |
- box.metrics = NGLineHeightMetrics(); |
- DCHECK(box.pending_descendants.IsEmpty()); |
- } |
+ // Initialize the box state for the line box. |
+ NGInlineBoxState& line_box = LineBoxState(); |
+ line_box.style = line_style; |
+ |
+ // Use a "strut" (a zero-width inline box with the element's font and |
+ // line height properties) as the initial metrics for the line box. |
+ // https://drafts.csswg.org/css2/visudet.html#strut |
+ line_box.ComputeTextMetrics(*line_style, baseline_type); |
+ |
return &stack_.back(); |
} |
@@ -72,7 +95,9 @@ void NGInlineLayoutStateStack::OnEndPlaceItems( |
NGInlineBoxState* box = &(*it); |
EndBoxState(box, line_box); |
} |
- line_box->UniteMetrics(stack_.front().metrics); |
+ |
+ DCHECK(!LineBoxState().metrics.IsEmpty()); |
+ line_box->SetMetrics(LineBoxState().metrics); |
} |
void NGInlineLayoutStateStack::EndBoxState(NGInlineBoxState* box, |