| Index: ui/gfx/render_text.cc
|
| diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
|
| index 498bb3b42a3ad552208fee366dc42ec7de434b44..d3f567342257308048c13fbd77752705e85ce77c 100644
|
| --- a/ui/gfx/render_text.cc
|
| +++ b/ui/gfx/render_text.cc
|
| @@ -175,6 +175,11 @@ void RenderText::SetSelectionModel(const SelectionModel& sel) {
|
| cached_bounds_and_offset_valid_ = false;
|
| }
|
|
|
| +void RenderText::ToggleInsertMode() {
|
| + insert_mode_ = !insert_mode_;
|
| + cached_bounds_and_offset_valid_ = false;
|
| +}
|
| +
|
| void RenderText::SetDisplayRect(const Rect& r) {
|
| display_rect_ = r;
|
| cached_bounds_and_offset_valid_ = false;
|
| @@ -184,13 +189,8 @@ size_t RenderText::GetCursorPosition() const {
|
| 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) {
|
| @@ -251,6 +251,8 @@ bool RenderText::MoveCursorTo(const Point& point, bool select) {
|
| }
|
|
|
| bool RenderText::IsPointInSelection(const Point& point) {
|
| + if (EmptySelection())
|
| + return false;
|
| // TODO(xji): should this check whether the point is inside the visual
|
| // selection bounds? In case of "abcFED", if "ED" is selected, |point| points
|
| // to the right half of 'c', is the point in selection?
|
| @@ -308,12 +310,8 @@ void RenderText::SelectWord() {
|
| break;
|
| }
|
|
|
| - SelectionModel sel(selection_model());
|
| - sel.set_selection_start(selection_start);
|
| - sel.set_selection_end(cursor_position);
|
| - sel.set_caret_pos(GetIndexOfPreviousGrapheme(cursor_position));
|
| - sel.set_caret_placement(SelectionModel::TRAILING);
|
| - SetSelectionModel(sel);
|
| + MoveCursorTo(selection_start, false);
|
| + MoveCursorTo(cursor_position, true);
|
| }
|
|
|
| const ui::Range& RenderText::GetCompositionRange() const {
|
| @@ -576,6 +574,15 @@ void RenderText::ApplyCompositionAndSelectionStyles(
|
| }
|
| }
|
|
|
| +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]));
|
| @@ -589,7 +596,6 @@ void RenderText::UpdateCachedBoundsAndOffset() {
|
| // function will set |cursor_bounds_| and |display_offset_| to correct values.
|
| cached_bounds_and_offset_valid_ = true;
|
| cursor_bounds_ = GetCursorBounds(selection_model_, insert_mode_);
|
| - cursor_bounds_.set_width(std::max(cursor_bounds_.width(), 1));
|
| // Update |display_offset_| to ensure the current cursor is visible.
|
| int display_width = display_rect_.width();
|
| int string_width = GetStringWidth();
|
|
|