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

Side by Side Diff: third_party/WebKit/Source/core/paint/InlineTextBoxPainter.cpp

Issue 2643293004: Fix gap for "text-underline-position:under" (Closed)
Patch Set: Rebase Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/TestExpectations ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/paint/InlineTextBoxPainter.h" 5 #include "core/paint/InlineTextBoxPainter.h"
6 6
7 #include "core/editing/CompositionUnderline.h" 7 #include "core/editing/CompositionUnderline.h"
8 #include "core/editing/Editor.h" 8 #include "core/editing/Editor.h"
9 #include "core/editing/markers/DocumentMarkerController.h" 9 #include "core/editing/markers/DocumentMarkerController.h"
10 #include "core/frame/LocalFrame.h" 10 #include "core/frame/LocalFrame.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 LayoutUnit position = inlineTextBox->logicalTop(); 70 LayoutUnit position = inlineTextBox->logicalTop();
71 return position - 71 return position -
72 root.minLogicalTopForUnderline(decorationObject, position); 72 root.minLogicalTopForUnderline(decorationObject, position);
73 } else { 73 } else {
74 LayoutUnit position = inlineTextBox->logicalBottom(); 74 LayoutUnit position = inlineTextBox->logicalBottom();
75 return root.maxLogicalBottomForUnderline(decorationObject, position) - 75 return root.maxLogicalBottomForUnderline(decorationObject, position) -
76 position; 76 position;
77 } 77 }
78 } 78 }
79 79
80 static int computeUnderlineOffsetForRoman(const FontMetrics& fontMetrics,
81 const float textDecorationThickness) {
82 // Compute the gap between the font and the underline. Use at least one
83 // pixel gap, if underline is thick then use a bigger gap.
84 int gap = 0;
85
86 // Underline position of zero means draw underline on Baseline Position,
87 // in Blink we need at least 1-pixel gap to adding following check.
88 // Positive underline Position means underline should be drawn above baseline
89 // and negative value means drawing below baseline, negating the value as in
90 // Blink downward Y-increases.
91
92 if (fontMetrics.underlinePosition())
93 gap = -fontMetrics.underlinePosition();
94 else
95 gap = std::max<int>(1, ceilf(textDecorationThickness / 2.f));
96
97 // Position underline near the alphabetic baseline.
98 return fontMetrics.ascent() + gap;
99 }
100
80 static int computeUnderlineOffset(const TextUnderlinePosition underlinePosition, 101 static int computeUnderlineOffset(const TextUnderlinePosition underlinePosition,
81 const ComputedStyle& style, 102 const ComputedStyle& style,
82 const FontMetrics& fontMetrics, 103 const FontMetrics& fontMetrics,
83 const InlineTextBox* inlineTextBox, 104 const InlineTextBox* inlineTextBox,
84 const float textDecorationThickness) { 105 const float textDecorationThickness) {
85 // Compute the gap between the font and the underline. Use at least one
86 // pixel gap, if underline is thick then use a bigger gap.
87 int gap = 0;
88
89 // Underline position of zero means draw underline on Baseline Position,
90 // in Blink we need at least 1-pixel gap to adding following check.
91 // Positive underline Position means underline should be drawn above baselin e
92 // and negative value means drawing below baseline, negating the value as in
93 // Blink
94 // downward Y-increases.
95
96 if (fontMetrics.underlinePosition())
97 gap = -fontMetrics.underlinePosition();
98 else
99 gap = std::max<int>(1, ceilf(textDecorationThickness / 2.f));
100
101 // FIXME: We support only horizontal text for now. 106 // FIXME: We support only horizontal text for now.
102 switch (underlinePosition) { 107 switch (underlinePosition) {
108 default:
drott 2017/01/23 08:20:23 Do we parse other values than Auto and Under in CS
109 NOTREACHED();
110 // Fall through.
103 case TextUnderlinePositionAuto: 111 case TextUnderlinePositionAuto:
104 return fontMetrics.ascent() + 112 return computeUnderlineOffsetForRoman(fontMetrics,
105 gap; // Position underline near the alphabetic baseline. 113 textDecorationThickness);
106 case TextUnderlinePositionUnder: { 114 case TextUnderlinePositionUnder: {
107 // Position underline relative to the under edge of the lowest element's 115 // Position underline at the under edge of the lowest element's
108 // content box. 116 // content box.
109 LayoutUnit offset = computeUnderlineOffsetForUnder(style, inlineTextBox); 117 LayoutUnit offset = computeUnderlineOffsetForUnder(style, inlineTextBox);
110 offset = inlineTextBox->logicalHeight() + std::max(offset, LayoutUnit()); 118 offset = inlineTextBox->logicalHeight() + std::max(offset, LayoutUnit());
111 return offset.toInt() + gap; 119 return offset.toInt();
112 } 120 }
113 } 121 }
114
115 NOTREACHED();
116 return fontMetrics.ascent() + gap;
117 } 122 }
118 123
119 static bool shouldSetDecorationAntialias( 124 static bool shouldSetDecorationAntialias(
120 const Vector<AppliedTextDecoration>& decorations) { 125 const Vector<AppliedTextDecoration>& decorations) {
121 for (const AppliedTextDecoration& decoration : decorations) { 126 for (const AppliedTextDecoration& decoration : decorations) {
122 TextDecorationStyle decorationStyle = decoration.style(); 127 TextDecorationStyle decorationStyle = decoration.style();
123 if (decorationStyle == TextDecorationStyleDotted || 128 if (decorationStyle == TextDecorationStyleDotted ||
124 decorationStyle == TextDecorationStyleDashed) 129 decorationStyle == TextDecorationStyleDashed)
125 return true; 130 return true;
126 } 131 }
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 1330
1326 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), 1331 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(),
1327 m_inlineTextBox.logicalHeight())); 1332 m_inlineTextBox.logicalHeight()));
1328 context.clip(FloatRect(boxRect)); 1333 context.clip(FloatRect(boxRect));
1329 context.drawHighlightForText(font, run, FloatPoint(boxOrigin), 1334 context.drawHighlightForText(font, run, FloatPoint(boxOrigin),
1330 boxRect.height().toInt(), color, 1335 boxRect.height().toInt(), color,
1331 paintOffsets.first, paintOffsets.second); 1336 paintOffsets.first, paintOffsets.second);
1332 } 1337 }
1333 1338
1334 } // namespace blink 1339 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/TestExpectations ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698