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

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

Issue 2643293004: Fix gap for "text-underline-position:under" (Closed)
Patch Set: Resolved merge conflict 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 ComputedStyle& style, 101 static int computeUnderlineOffset(const ComputedStyle& style,
81 const FontMetrics& fontMetrics, 102 const FontMetrics& fontMetrics,
82 const InlineTextBox* inlineTextBox, 103 const InlineTextBox* inlineTextBox,
83 const float textDecorationThickness) { 104 const float textDecorationThickness) {
84 // Compute the gap between the font and the underline. Use at least one
85 // pixel gap, if underline is thick then use a bigger gap.
86 int gap = 0;
87
88 // Underline position of zero means draw underline on Baseline Position,
89 // in Blink we need at least 1-pixel gap to adding following check.
90 // Positive underline Position means underline should be drawn above baselin e
91 // and negative value means drawing below baseline, negating the value as in
92 // Blink
93 // downward Y-increases.
94
95 if (fontMetrics.underlinePosition())
96 gap = -fontMetrics.underlinePosition();
97 else
98 gap = std::max<int>(1, ceilf(textDecorationThickness / 2.f));
99
100 // FIXME: We support only horizontal text for now. 105 // FIXME: We support only horizontal text for now.
101 switch (style.getTextUnderlinePosition()) { 106 switch (style.getTextUnderlinePosition()) {
107 default:
108 NOTREACHED();
109 // Fall through.
102 case TextUnderlinePositionAuto: 110 case TextUnderlinePositionAuto:
103 return fontMetrics.ascent() + 111 return computeUnderlineOffsetForRoman(fontMetrics,
104 gap; // Position underline near the alphabetic baseline. 112 textDecorationThickness);
105 case TextUnderlinePositionUnder: { 113 case TextUnderlinePositionUnder: {
106 // Position underline relative to the under edge of the lowest element's 114 // Position underline at the under edge of the lowest element's
107 // content box. 115 // content box.
108 LayoutUnit offset = computeUnderlineOffsetForUnder(style, inlineTextBox); 116 LayoutUnit offset = computeUnderlineOffsetForUnder(style, inlineTextBox);
109 offset = inlineTextBox->logicalHeight() + std::max(offset, LayoutUnit()); 117 offset = inlineTextBox->logicalHeight() + std::max(offset, LayoutUnit());
110 return offset.toInt() + gap; 118 return offset.toInt();
111 } 119 }
112 } 120 }
113
114 NOTREACHED();
115 return fontMetrics.ascent() + gap;
116 } 121 }
117 122
118 static bool shouldSetDecorationAntialias( 123 static bool shouldSetDecorationAntialias(
119 const Vector<AppliedTextDecoration>& decorations) { 124 const Vector<AppliedTextDecoration>& decorations) {
120 for (const AppliedTextDecoration& decoration : decorations) { 125 for (const AppliedTextDecoration& decoration : decorations) {
121 TextDecorationStyle decorationStyle = decoration.style(); 126 TextDecorationStyle decorationStyle = decoration.style();
122 if (decorationStyle == TextDecorationStyleDotted || 127 if (decorationStyle == TextDecorationStyleDotted ||
123 decorationStyle == TextDecorationStyleDashed) 128 decorationStyle == TextDecorationStyleDashed)
124 return true; 129 return true;
125 } 130 }
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 1328
1324 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), 1329 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(),
1325 m_inlineTextBox.logicalHeight())); 1330 m_inlineTextBox.logicalHeight()));
1326 context.clip(FloatRect(boxRect)); 1331 context.clip(FloatRect(boxRect));
1327 context.drawHighlightForText(font, run, FloatPoint(boxOrigin), 1332 context.drawHighlightForText(font, run, FloatPoint(boxOrigin),
1328 boxRect.height().toInt(), color, 1333 boxRect.height().toInt(), color,
1329 paintOffsets.first, paintOffsets.second); 1334 paintOffsets.first, paintOffsets.second);
1330 } 1335 }
1331 1336
1332 } // namespace blink 1337 } // 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