| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_height_metrics.h" | 5 #include "core/layout/ng/inline/ng_line_height_metrics.h" |
| 6 | 6 |
| 7 #include "core/style/ComputedStyle.h" | 7 #include "core/style/ComputedStyle.h" |
| 8 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 | 10 |
| 11 NGLineHeightMetrics::NGLineHeightMetrics(const ComputedStyle& style, | 11 NGLineHeightMetrics::NGLineHeightMetrics(const ComputedStyle& style, |
| 12 FontBaseline baseline_type) { | 12 FontBaseline baseline_type) { |
| 13 const SimpleFontData* font_data = style.GetFont().PrimaryFont(); | 13 const SimpleFontData* font_data = style.GetFont().PrimaryFont(); |
| 14 DCHECK(font_data); | 14 DCHECK(font_data); |
| 15 Initialize(font_data->GetFontMetrics(), baseline_type); | 15 Initialize(font_data->GetFontMetrics(), baseline_type); |
| 16 } | 16 } |
| 17 | 17 |
| 18 NGLineHeightMetrics::NGLineHeightMetrics(const FontMetrics& font_metrics, | 18 NGLineHeightMetrics::NGLineHeightMetrics(const FontMetrics& font_metrics, |
| 19 FontBaseline baseline_type) { | 19 FontBaseline baseline_type) { |
| 20 Initialize(font_metrics, baseline_type); | 20 Initialize(font_metrics, baseline_type); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void NGLineHeightMetrics::Initialize(const FontMetrics& font_metrics, | 23 void NGLineHeightMetrics::Initialize(const FontMetrics& font_metrics, |
| 24 FontBaseline baseline_type) { | 24 FontBaseline baseline_type) { |
| 25 ascent = font_metrics.FixedAscent(baseline_type); | 25 ascent = font_metrics.FixedAscent(baseline_type); |
| 26 descent = font_metrics.FixedDescent(baseline_type); | 26 descent = font_metrics.FixedDescent(baseline_type); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void NGLineHeightMetrics::AddLeading(LayoutUnit line_height) { | 29 void NGLineHeightMetrics::AddLeading(LayoutUnit line_height) { |
| 30 DCHECK(!IsEmpty()); |
| 30 LayoutUnit half_leading = (line_height - (ascent + descent)) / 2; | 31 LayoutUnit half_leading = (line_height - (ascent + descent)) / 2; |
| 31 // TODO(kojii): floor() is to make text dump compatible with legacy test | 32 // TODO(kojii): floor() is to make text dump compatible with legacy test |
| 32 // results. Revisit when we paint. | 33 // results. Revisit when we paint. |
| 33 ascent += half_leading.Floor(); | 34 ascent += half_leading.Floor(); |
| 34 descent = line_height - ascent; | 35 descent = line_height - ascent; |
| 35 } | 36 } |
| 36 | 37 |
| 38 void NGLineHeightMetrics::Move(LayoutUnit delta) { |
| 39 DCHECK(!IsEmpty()); |
| 40 ascent -= delta; |
| 41 descent += delta; |
| 42 } |
| 43 |
| 37 void NGLineHeightMetrics::Unite(const NGLineHeightMetrics& other) { | 44 void NGLineHeightMetrics::Unite(const NGLineHeightMetrics& other) { |
| 38 ascent = std::max(ascent, other.ascent); | 45 ascent = std::max(ascent, other.ascent); |
| 39 descent = std::max(descent, other.descent); | 46 descent = std::max(descent, other.descent); |
| 40 } | 47 } |
| 41 | 48 |
| 42 } // namespace blink | 49 } // namespace blink |
| OLD | NEW |