Chromium Code Reviews| Index: ui/gfx/render_text.cc |
| =================================================================== |
| --- ui/gfx/render_text.cc (revision 97029) |
| +++ ui/gfx/render_text.cc (working copy) |
| @@ -184,13 +184,8 @@ |
| return selection_model_.selection_end(); |
| } |
| -void RenderText::SetCursorPosition(const size_t position) { |
| - SelectionModel sel(selection_model()); |
| - sel.set_selection_start(position); |
| - sel.set_selection_end(position); |
| - sel.set_caret_pos(GetIndexOfPreviousGrapheme(position)); |
| - sel.set_caret_placement(SelectionModel::TRAILING); |
| - SetSelectionModel(sel); |
| +void RenderText::SetCursorPosition(size_t position) { |
| + MoveCursorTo(position, false); |
| } |
| void RenderText::MoveCursorLeft(BreakType break_type, bool select) { |
| @@ -199,8 +194,7 @@ |
| // Cancelling a selection moves to the edge of the selection. |
| if (break_type != LINE_BREAK && !EmptySelection() && !select) { |
| // Use the selection start if it is left of the selection end. |
| - SelectionModel selection_start(GetSelectionStart(), GetSelectionStart(), |
| - SelectionModel::LEADING); |
| + SelectionModel selection_start = GetSelectionModelForSelectionStart(); |
|
msw
2011/08/23 08:01:01
Remove the extra space after '='.
xji
2011/08/23 23:52:52
Done.
|
| if (GetCursorBounds(selection_start, false).x() < |
| GetCursorBounds(position, false).x()) |
| position = selection_start; |
| @@ -221,8 +215,7 @@ |
| // Cancelling a selection moves to the edge of the selection. |
| if (break_type != LINE_BREAK && !EmptySelection() && !select) { |
| // Use the selection start if it is right of the selection end. |
| - SelectionModel selection_start(GetSelectionStart(), GetSelectionStart(), |
| - SelectionModel::LEADING); |
| + SelectionModel selection_start = GetSelectionModelForSelectionStart(); |
| if (GetCursorBounds(selection_start, false).x() > |
| GetCursorBounds(position, false).x()) |
| position = selection_start; |
| @@ -349,9 +342,11 @@ |
| cached_bounds_and_offset_valid_ = false; |
| } |
| -base::i18n::TextDirection RenderText::GetTextDirection() const { |
| +base::i18n::TextDirection RenderText::GetTextDirection() { |
| // TODO(msw): Bidi implementation, intended to replace the functionality added |
| // in crrev.com/91881 (discussed in codereview.chromium.org/7324011). |
| + if (base::i18n::IsRTL()) |
| + return base::i18n::RIGHT_TO_LEFT; |
| return base::i18n::LEFT_TO_RIGHT; |
| } |
| @@ -576,6 +571,31 @@ |
| } |
| } |
| +Point RenderText::ToTextPoint(const Point& point) { |
| + Point p(point.Subtract(display_rect_.origin())); |
| + p = p.Subtract(GetUpdatedDisplayOffset()); |
| + if (base::i18n::IsRTL()) |
| + p.Offset(GetStringWidth() - display_rect_.width() + 1, 0); |
| + return p; |
| +} |
| + |
| +Point RenderText::ToViewPoint(const Point& point) { |
| + Point p(point.Add(display_rect_.origin())); |
| + p = p.Add(GetUpdatedDisplayOffset()); |
| + if (base::i18n::IsRTL()) |
| + p.Offset(display_rect_.width() - GetStringWidth() - 1, 0); |
| + return p; |
| +} |
| + |
| +void RenderText::MoveCursorTo(size_t position, bool select) { |
| + size_t caret_pos = GetIndexOfPreviousGrapheme(position); |
| + SelectionModel::CaretPlacement placement = (caret_pos == position) ? |
| + SelectionModel::LEADING : SelectionModel::TRAILING; |
| + size_t selection_start = select ? GetSelectionStart() : position; |
| + SelectionModel sel(selection_start, position, caret_pos, placement); |
| + SetSelectionModel(sel); |
| +} |
| + |
| bool RenderText::IsPositionAtWordSelectionBoundary(size_t pos) { |
| return pos == 0 || (u_isalnum(text()[pos - 1]) && !u_isalnum(text()[pos])) || |
| (!u_isalnum(text()[pos - 1]) && u_isalnum(text()[pos])); |
| @@ -598,9 +618,17 @@ |
| // Show all text whenever the text fits to the size. |
| delta_offset = -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. |
| + // BTW, Firefox has the same issue. |
|
msw
2011/08/23 08:01:01
No need to call out Firefox here, we can alert the
xji
2011/08/23 23:52:52
Ah, you absolutely right. removed.
|
| + // |
| // Pan to show the cursor when it overflows to the right, |
| delta_offset = 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_offset = display_rect_.x() - cursor_bounds_.x(); |
| } |
| @@ -608,4 +636,14 @@ |
| cursor_bounds_.Offset(delta_offset, 0); |
| } |
| +SelectionModel RenderText::GetSelectionModelForSelectionStart() { |
| + if (GetSelectionStart() < GetCursorPosition()) |
| + return SelectionModel(GetSelectionStart(), |
| + GetSelectionStart(), |
| + SelectionModel::LEADING); |
| + return SelectionModel(GetSelectionStart(), |
| + GetIndexOfPreviousGrapheme(GetSelectionStart()), |
|
msw
2011/08/23 08:01:01
What if the selection start is 0 and there is not
xji
2011/08/23 23:52:52
this is called when selection is not empty and sel
|
| + SelectionModel::TRAILING); |
| +} |
| + |
| } // namespace gfx |