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

Side by Side Diff: ui/gfx/render_text.cc

Issue 2948033003: Vertically center the cap height of multi-line text.
Patch Set: Created 3 years, 6 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 | « no previous file | 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/gfx/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <climits> 10 #include <climits>
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 (cursor_enabled_ ? 1 : 0) : 1196 (cursor_enabled_ ? 1 : 0) :
1197 GetContentWidth(); 1197 GetContentWidth();
1198 offset.set_x(display_rect().width() - width); 1198 offset.set_x(display_rect().width() - width);
1199 // Put any extra margin pixel on the left to match legacy behavior. 1199 // Put any extra margin pixel on the left to match legacy behavior.
1200 if (horizontal_alignment == ALIGN_CENTER) 1200 if (horizontal_alignment == ALIGN_CENTER)
1201 offset.set_x((offset.x() + 1) / 2); 1201 offset.set_x((offset.x() + 1) / 2);
1202 } 1202 }
1203 1203
1204 // Vertically center the text. 1204 // Vertically center the text.
1205 if (multiline_) { 1205 if (multiline_) {
1206 const int text_height = lines_.back().preceding_heights + 1206 const int line_height = lines_.back().size.height();
1207 lines_.back().size.height(); 1207 const int text_height = lines_.back().preceding_heights + line_height;
1208 offset.set_y((display_rect_.height() - text_height) / 2); 1208 const int extra_space = display_rect_.height() - text_height;
1209 const int centering_baseline =
1210 DetermineBaselineCenteringText(line_height + extra_space, font_list());
1211 offset.set_y(centering_baseline - GetDisplayTextBaseline());
1209 } else { 1212 } else {
1210 offset.set_y(GetBaseline() - GetDisplayTextBaseline()); 1213 offset.set_y(GetBaseline() - GetDisplayTextBaseline());
1211 } 1214 }
1212 1215
1213 return offset; 1216 return offset;
1214 } 1217 }
1215 1218
1216 void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) { 1219 void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) {
1217 const int width = display_rect().width(); 1220 const int width = display_rect().width();
1218 if (multiline() || elide_behavior_ != FADE_TAIL || GetContentWidth() <= width) 1221 if (multiline() || elide_behavior_ != FADE_TAIL || GetContentWidth() <= width)
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1639 1642
1640 for (; range_max < length; ++range_max) 1643 for (; range_max < length; ++range_max)
1641 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max)) 1644 if (iter.IsEndOfWord(range_max) || iter.IsStartOfWord(range_max))
1642 break; 1645 break;
1643 1646
1644 return range.is_reversed() ? Range(range_max, range_min) 1647 return range.is_reversed() ? Range(range_max, range_min)
1645 : Range(range_min, range_max); 1648 : Range(range_min, range_max);
1646 } 1649 }
1647 1650
1648 } // namespace gfx 1651 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698