Index: ui/gfx/render_text.cc |
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc |
index fb7364b66f2b538f5733867b11afc11330755c6d..29e25b387bb3faf74f077439f9ff14affbde3520 100644 |
--- a/ui/gfx/render_text.cc |
+++ b/ui/gfx/render_text.cc |
@@ -892,7 +892,7 @@ void RenderText::SetDisplayOffset(int horizontal_offset) { |
max_offset = extra_content; |
break; |
case ALIGN_CENTER: |
- min_offset = -extra_content / 2; |
+ min_offset = -(extra_content + 1) / 2; |
max_offset = extra_content / 2; |
break; |
default: |
@@ -1309,48 +1309,29 @@ void RenderText::UpdateCachedBoundsAndOffset() { |
// TODO(ckocagil): Add support for scrolling multiline text. |
- // First, set the valid flag true to calculate the current cursor bounds using |
- // the stale |display_offset_|. Applying |delta_offset| at the end of this |
- // function will set |cursor_bounds_| and |display_offset_| to correct values. |
- cached_bounds_and_offset_valid_ = true; |
- if (cursor_enabled()) |
- cursor_bounds_ = GetCursorBounds(selection_model_, insert_mode_); |
+ int delta_x = 0; |
- // Update |display_offset_| to ensure the current cursor is visible. |
- const int display_width = display_rect_.width(); |
- const int content_width = GetContentWidth(); |
+ if (cursor_enabled()) { |
+ // When cursor is enabled, ensure it is visible. For this, set the valid |
+ // flag true and calculate the current cursor bounds using the stale |
+ // |display_offset_|. Then calculate the change in offset needed to move the |
+ // cursor into the visible area. |
+ cached_bounds_and_offset_valid_ = true; |
+ cursor_bounds_ = GetCursorBounds(selection_model_, insert_mode_); |
- int delta_x = 0; |
- if (content_width <= display_width || !cursor_enabled()) { |
- // Don't pan if the text fits in the display width or when the cursor is |
- // disabled. |
- delta_x = -display_offset_.x(); |
- } else if (cursor_bounds_.right() > display_rect_.right()) { |
- // TODO(xji): when the character overflow is a RTL character, currently, if |
- // we pan cursor at the rightmost position, the entered RTL character is not |
- // displayed. Should pan cursor to show the last logical characters. |
- // |
- // Pan to show the cursor when it overflows to the right. |
- delta_x = display_rect_.right() - cursor_bounds_.right(); |
- } else if (cursor_bounds_.x() < display_rect_.x()) { |
- // TODO(xji): have similar problem as above when overflow character is a |
- // LTR character. |
- // |
- // Pan to show the cursor when it overflows to the left. |
- delta_x = display_rect_.x() - cursor_bounds_.x(); |
- } else if (display_offset_.x() != 0) { |
- // Reduce the pan offset to show additional overflow text when the display |
- // width increases. |
- const int negate_rtl = horizontal_alignment_ == ALIGN_RIGHT ? -1 : 1; |
- const int offset = negate_rtl * display_offset_.x(); |
- if (display_width > (content_width + offset)) { |
- delta_x = negate_rtl * (display_width - (content_width + offset)); |
- } |
+ // TODO(bidi): In left-aligned text, when overflow character is an RTL |
msw
2014/07/16 21:55:54
nit: use this one-liner: "// TODO(bidi): Show RTL
mohsen
2014/07/16 23:36:21
Done.
|
+ // character, panning cursor at the rightmost position would not show the |
+ // entered character. The same happens in right-aligned text, when the |
+ // overflow character is an LTR character, if we pan cursor at the leftmost |
+ // position. Ideally, we should pan cursor to show the last logical |
+ // characters. |
+ if (cursor_bounds_.right() > display_rect_.right()) |
+ delta_x = display_rect_.right() - cursor_bounds_.right(); |
+ else if (cursor_bounds_.x() < display_rect_.x()) |
+ delta_x = display_rect_.x() - cursor_bounds_.x(); |
} |
- Vector2d delta_offset(delta_x, 0); |
- display_offset_ += delta_offset; |
- cursor_bounds_ += delta_offset; |
+ SetDisplayOffset(display_offset_.x() + delta_x); |
} |
void RenderText::DrawSelection(Canvas* canvas) { |