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

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

Issue 2970803002: Fix underline/overline flipping (Closed)
Patch Set: Created 3 years, 5 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/fast/css3-text/css3-text-decoration/line-through-vertical-expected.html ('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/Editor.h" 7 #include "core/editing/Editor.h"
8 #include "core/editing/markers/CompositionMarker.h" 8 #include "core/editing/markers/CompositionMarker.h"
9 #include "core/editing/markers/DocumentMarkerController.h" 9 #include "core/editing/markers/DocumentMarkerController.h"
10 #include "core/editing/markers/TextMatchMarker.h" 10 #include "core/editing/markers/TextMatchMarker.h"
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 ResolvedUnderlinePosition underline_position = 212 ResolvedUnderlinePosition underline_position =
213 decoration_info.underline_position; 213 decoration_info.underline_position;
214 bool flip_underline_and_overline = false; 214 bool flip_underline_and_overline = false;
215 if (underline_position == ResolvedUnderlinePosition::kOver) { 215 if (underline_position == ResolvedUnderlinePosition::kOver) {
216 flip_underline_and_overline = true; 216 flip_underline_and_overline = true;
217 underline_position = ResolvedUnderlinePosition::kUnder; 217 underline_position = ResolvedUnderlinePosition::kUnder;
218 } 218 }
219 219
220 for (const AppliedTextDecoration& decoration : decorations) { 220 for (const AppliedTextDecoration& decoration : decorations) {
221 TextDecoration lines = decoration.Lines(); 221 TextDecoration lines = decoration.Lines();
222 bool has_underline = EnumHasFlags(lines, TextDecoration::kUnderline);
223 bool has_overline = EnumHasFlags(lines, TextDecoration::kOverline);
222 if (flip_underline_and_overline) { 224 if (flip_underline_and_overline) {
223 lines ^= (TextDecoration::kUnderline | TextDecoration::kOverline); 225 std::swap(has_underline, has_overline);
224 } 226 }
225 if (EnumHasFlags(lines, TextDecoration::kUnderline) && 227 if (has_underline && decoration_info.font_data) {
226 decoration_info.font_data) {
227 const int underline_offset = ComputeUnderlineOffset( 228 const int underline_offset = ComputeUnderlineOffset(
228 underline_position, *decoration_info.style, 229 underline_position, *decoration_info.style,
229 decoration_info.font_data->GetFontMetrics(), &box, decorating_box, 230 decoration_info.font_data->GetFontMetrics(), &box, decorating_box,
230 decoration_info.thickness); 231 decoration_info.thickness);
231 text_painter.PaintDecorationUnderOrOverLine( 232 text_painter.PaintDecorationUnderOrOverLine(
232 context, decoration_info, decoration, underline_offset, 233 context, decoration_info, decoration, underline_offset,
233 decoration_info.double_offset); 234 decoration_info.double_offset);
234 } 235 }
235 if (EnumHasFlags(lines, TextDecoration::kOverline)) { 236 if (has_overline) {
236 const int overline_offset = ComputeUnderlineOffsetForUnder( 237 const int overline_offset = ComputeUnderlineOffsetForUnder(
237 *decoration_info.style, &box, decorating_box, 238 *decoration_info.style, &box, decorating_box,
238 decoration_info.thickness, 239 decoration_info.thickness,
239 flip_underline_and_overline ? LineVerticalPositionType::TopOfEmHeight 240 flip_underline_and_overline ? LineVerticalPositionType::TopOfEmHeight
240 : LineVerticalPositionType::TextTop); 241 : LineVerticalPositionType::TextTop);
241 text_painter.PaintDecorationUnderOrOverLine( 242 text_painter.PaintDecorationUnderOrOverLine(
242 context, decoration_info, decoration, overline_offset, 243 context, decoration_info, decoration, overline_offset,
243 -decoration_info.double_offset); 244 -decoration_info.double_offset);
244 } 245 }
245 // We could instead build a vector of the TextDecoration instances needing 246 // We could instead build a vector of the TextDecoration instances needing
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 1179
1179 LayoutRect box_rect(box_origin, LayoutSize(inline_text_box_.LogicalWidth(), 1180 LayoutRect box_rect(box_origin, LayoutSize(inline_text_box_.LogicalWidth(),
1180 inline_text_box_.LogicalHeight())); 1181 inline_text_box_.LogicalHeight()));
1181 context.Clip(FloatRect(box_rect)); 1182 context.Clip(FloatRect(box_rect));
1182 context.DrawHighlightForText(font, run, FloatPoint(box_origin), 1183 context.DrawHighlightForText(font, run, FloatPoint(box_origin),
1183 box_rect.Height().ToInt(), color, 1184 box_rect.Height().ToInt(), color,
1184 paint_offsets.first, paint_offsets.second); 1185 paint_offsets.first, paint_offsets.second);
1185 } 1186 }
1186 1187
1187 } // namespace blink 1188 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/css3-text/css3-text-decoration/line-through-vertical-expected.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698