Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Unified Diff: third_party/WebKit/Source/core/layout/ng/ng_line_height_metrics.cc

Issue 2764753007: [LayoutNG] Add NGLineBoxFragment (Closed)
Patch Set: Rebase again as other CLs landed faster Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/ng/ng_line_height_metrics.cc
diff --git a/third_party/WebKit/Source/core/layout/ng/ng_line_height_metrics.cc b/third_party/WebKit/Source/core/layout/ng/ng_line_height_metrics.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b47c9892c1c71b423a6b06592ae73e81ae25f619
--- /dev/null
+++ b/third_party/WebKit/Source/core/layout/ng/ng_line_height_metrics.cc
@@ -0,0 +1,46 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/layout/ng/ng_line_height_metrics.h"
+
+#include "core/style/ComputedStyle.h"
+
+namespace blink {
+
+NGLineHeightMetrics::NGLineHeightMetrics(const ComputedStyle& style,
+ FontBaseline baseline_type) {
+ const SimpleFontData* font_data = style.font().primaryFont();
+ DCHECK(font_data);
+ Initialize(font_data->getFontMetrics(), baseline_type,
+ style.computedLineHeightInFloat());
+}
+
+NGLineHeightMetrics::NGLineHeightMetrics(const FontMetrics& font_metrics,
+ FontBaseline baseline_type) {
+ Initialize(font_metrics, baseline_type, font_metrics.floatLineSpacing());
+}
+
+void NGLineHeightMetrics::Initialize(const FontMetrics& font_metrics,
+ FontBaseline baseline_type,
+ float line_height) {
+ ascent = font_metrics.floatAscent(baseline_type);
+ descent = font_metrics.floatDescent(baseline_type);
+ float half_leading = (line_height - (ascent + descent)) / 2;
+ // Ensure the top and the baseline is snapped to CSS pixel.
+ // TODO(kojii): How to handle fractional ascent isn't determined yet. Should
+ // we snap top or baseline? If baseline, top needs fractional. If top,
+ // baseline may not align across fonts.
+ ascent_and_leading = ascent + floor(half_leading);
+ descent_and_leading = line_height - ascent_and_leading;
+}
+
+void NGLineHeightMetrics::Unite(const NGLineHeightMetrics& other) {
+ ascent = std::max(ascent, other.ascent);
+ descent = std::max(descent, other.descent);
+ ascent_and_leading = std::max(ascent_and_leading, other.ascent_and_leading);
+ descent_and_leading =
+ std::max(descent_and_leading, other.descent_and_leading);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698