Index: ui/gfx/render_text.cc |
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc |
index c3a4f00e0fd14524e3ad0247c4efb3085a34ee1d..6aa490e4c076a770529b0576b8095e4b1dcb8052 100644 |
--- a/ui/gfx/render_text.cc |
+++ b/ui/gfx/render_text.cc |
@@ -484,6 +484,14 @@ void RenderText::SetHorizontalAlignment(HorizontalAlignment alignment) { |
} |
} |
+void RenderText::SetVerticalAlignment(VerticalAlignment alignment) { |
+ if (vertical_alignment_ != alignment) { |
+ vertical_alignment_ = alignment; |
+ display_offset_ = Vector2d(); |
+ cached_bounds_and_offset_valid_ = false; |
+ } |
+} |
+ |
void RenderText::SetFontList(const FontList& font_list) { |
font_list_ = font_list; |
const int font_style = font_list.GetFontStyle(); |
@@ -955,6 +963,7 @@ Vector2d RenderText::GetLineOffset(size_t line_number) { |
RenderText::RenderText() |
: horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), |
+ vertical_alignment_(VALIGN_MIDDLE), |
directionality_mode_(DIRECTIONALITY_FROM_TEXT), |
text_direction_(base::i18n::UNKNOWN_DIRECTION), |
cursor_enabled_(true), |
@@ -1155,15 +1164,28 @@ Vector2d RenderText::GetAlignmentOffset(size_t line_number) { |
offset.set_x((offset.x() + 1) / 2); |
} |
- // Vertically center the text. |
+ // Vertically align the text. |
if (multiline_) { |
- const int text_height = lines_.back().preceding_heights + |
- lines_.back().size.height(); |
- offset.set_y((display_rect_.height() - text_height) / 2); |
+ const int text_height = |
+ lines_.back().preceding_heights + lines_.back().size.height(); |
+ if (vertical_alignment_ == VALIGN_TOP) { |
+ offset.set_y(lines_.back().preceding_heights); |
msw
2015/03/26 22:55:44
I don't think this is correct... Shouldn't it just
dschuyler
2015/03/27 21:20:34
I'm not sure. If it's a single line or if it's do
msw
2015/03/30 19:19:12
This should probably be 0 (as in your latest patch
dschuyler
2015/03/31 18:38:14
Done.
|
+ } else if (vertical_alignment_ == VALIGN_BOTTOM) { |
+ offset.set_y(display_rect_.height() - text_height); |
+ } else { |
+ // Vertically center the text. |
msw
2015/03/26 22:55:44
nit: change this comment to DCHECK_EQ(VALIGN_MIDDL
dschuyler
2015/03/27 21:20:34
Done.
|
+ offset.set_y((display_rect_.height() - text_height) / 2); |
+ } |
} else { |
- offset.set_y(GetBaseline() - GetDisplayTextBaseline()); |
+ if (vertical_alignment_ == VALIGN_TOP) { |
+ offset.set_y(0); |
+ } else if (vertical_alignment_ == VALIGN_BOTTOM) { |
+ offset.set_y(display_rect_.height() - font_list_.GetHeight()); |
+ } else { |
+ // Vertically center the text. |
msw
2015/03/26 22:55:45
ditto nit: change this comment to DCHECK_EQ(VALIGN
dschuyler
2015/03/27 21:20:34
Done.
|
+ offset.set_y(GetBaseline() - GetDisplayTextBaseline()); |
+ } |
} |
- |
return offset; |
} |