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

Unified Diff: third_party/WebKit/Source/core/layout/line/InlineTextBox.cpp

Issue 2643413002: Fix 'text-underline-position: under' to use em height ascent/descent (Closed)
Patch Set: eae review Created 3 years, 8 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/line/InlineTextBox.cpp
diff --git a/third_party/WebKit/Source/core/layout/line/InlineTextBox.cpp b/third_party/WebKit/Source/core/layout/line/InlineTextBox.cpp
index f4ad8822e1d20cfe3e60c1130cc1615992f50555..e4d74e82c235958022d425020c91596b0d0241fc 100644
--- a/third_party/WebKit/Source/core/layout/line/InlineTextBox.cpp
+++ b/third_party/WebKit/Source/core/layout/line/InlineTextBox.cpp
@@ -125,6 +125,44 @@ LayoutUnit InlineTextBox::LineHeight() const {
kPositionOnContainingLine);
}
+LayoutUnit InlineTextBox::OffsetTo(LineVerticalPositionType position_type,
+ FontBaseline baseline_type) const {
+ if (IsText() &&
+ (position_type == LineVerticalPositionType::TopOfEmHeight ||
+ position_type == LineVerticalPositionType::BottomOfEmHeight)) {
+ const Font& font = GetLineLayoutItem().Style(IsFirstLineStyle())->GetFont();
+ if (const SimpleFontData* font_data = font.PrimaryFont()) {
+ const FontMetrics& metrics = font_data->GetFontMetrics();
+ if (position_type == LineVerticalPositionType::TopOfEmHeight) {
+ // Use Ascent, not FixedAscent, to match to how InlineTextBoxPainter
+ // computes the baseline position.
+ return metrics.Ascent(baseline_type) -
+ font_data->EmHeightAscent(baseline_type);
+ }
+ if (position_type == LineVerticalPositionType::BottomOfEmHeight) {
+ return metrics.Ascent(baseline_type) +
+ font_data->EmHeightDescent(baseline_type);
+ }
+ }
+ }
+ switch (position_type) {
+ case LineVerticalPositionType::TextTop:
+ case LineVerticalPositionType::TopOfEmHeight:
+ return LayoutUnit();
+ case LineVerticalPositionType::TextBottom:
+ case LineVerticalPositionType::BottomOfEmHeight:
+ return LogicalHeight();
+ }
+ NOTREACHED();
+ return LayoutUnit();
+}
+
+LayoutUnit InlineTextBox::VerticalPosition(
+ LineVerticalPositionType position_type,
+ FontBaseline baseline_type) const {
+ return LogicalTop() + OffsetTo(position_type, baseline_type);
+}
+
bool InlineTextBox::IsSelected(int start_pos, int end_pos) const {
int s_pos = std::max(start_pos - start_, 0);
// The position after a hard line break is considered to be past its end.

Powered by Google App Engine
This is Rietveld 408576698