OLD | NEW |
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/views/controls/textfield/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "ui/accessibility/ax_view_state.h" | 10 #include "ui/accessibility/ax_view_state.h" |
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 | 1094 |
1095 OnBeforeUserAction(); | 1095 OnBeforeUserAction(); |
1096 SelectSelectionModel(selection); | 1096 SelectSelectionModel(selection); |
1097 OnAfterUserAction(); | 1097 OnAfterUserAction(); |
1098 } | 1098 } |
1099 | 1099 |
1100 void Textfield::MoveCaretTo(const gfx::Point& point) { | 1100 void Textfield::MoveCaretTo(const gfx::Point& point) { |
1101 SelectRect(point, point); | 1101 SelectRect(point, point); |
1102 } | 1102 } |
1103 | 1103 |
1104 void Textfield::GetSelectionEndPoints(gfx::Rect* p1, gfx::Rect* p2) { | 1104 void Textfield::GetSelectionEndPoints(ui::SelectionBound* anchor, |
| 1105 ui::SelectionBound* focus) { |
1105 gfx::RenderText* render_text = GetRenderText(); | 1106 gfx::RenderText* render_text = GetRenderText(); |
1106 const gfx::SelectionModel& sel = render_text->selection_model(); | 1107 const gfx::SelectionModel& sel = render_text->selection_model(); |
1107 gfx::SelectionModel start_sel = | 1108 gfx::SelectionModel start_sel = |
1108 render_text->GetSelectionModelForSelectionStart(); | 1109 render_text->GetSelectionModelForSelectionStart(); |
1109 *p1 = render_text->GetCursorBounds(start_sel, true); | 1110 gfx::Rect r1 = render_text->GetCursorBounds(start_sel, true); |
1110 *p2 = render_text->GetCursorBounds(sel, true); | 1111 gfx::Rect r2 = render_text->GetCursorBounds(sel, true); |
| 1112 |
| 1113 anchor->edge_top = r1.origin(); |
| 1114 anchor->edge_bottom = r1.bottom_left(); |
| 1115 focus->edge_top = r2.origin(); |
| 1116 focus->edge_bottom = r2.bottom_left(); |
| 1117 |
| 1118 // Determine the SelectionBound's type for focus and anchor. |
| 1119 // TODO(mfomitchev): Ideally we should have different logical directions for |
| 1120 // start and end to support proper handle direction for mixed LTR/RTL text. |
| 1121 const bool ltr = GetTextDirection() != base::i18n::RIGHT_TO_LEFT; |
| 1122 size_t anchor_position_index = sel.selection().start(); |
| 1123 size_t focus_position_index = sel.selection().end(); |
| 1124 |
| 1125 if (anchor_position_index == focus_position_index) { |
| 1126 anchor->type = focus->type = ui::SelectionBound::CENTER; |
| 1127 } else if ((ltr && anchor_position_index < focus_position_index) || |
| 1128 (!ltr && anchor_position_index > focus_position_index)) { |
| 1129 anchor->type = ui::SelectionBound::LEFT; |
| 1130 focus->type = ui::SelectionBound::RIGHT; |
| 1131 } else { |
| 1132 anchor->type = ui::SelectionBound::RIGHT; |
| 1133 focus->type = ui::SelectionBound::LEFT; |
| 1134 } |
1111 } | 1135 } |
1112 | 1136 |
1113 gfx::Rect Textfield::GetBounds() { | 1137 gfx::Rect Textfield::GetBounds() { |
1114 return GetLocalBounds(); | 1138 return GetLocalBounds(); |
1115 } | 1139 } |
1116 | 1140 |
1117 gfx::NativeView Textfield::GetNativeView() const { | 1141 gfx::NativeView Textfield::GetNativeView() const { |
1118 return GetWidget()->GetNativeView(); | 1142 return GetWidget()->GetNativeView(); |
1119 } | 1143 } |
1120 | 1144 |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1818 const size_t length = selection_clipboard_text.length(); | 1842 const size_t length = selection_clipboard_text.length(); |
1819 range = gfx::Range(range.start() + length, range.end() + length); | 1843 range = gfx::Range(range.start() + length, range.end() + length); |
1820 } | 1844 } |
1821 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); | 1845 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); |
1822 UpdateAfterChange(true, true); | 1846 UpdateAfterChange(true, true); |
1823 OnAfterUserAction(); | 1847 OnAfterUserAction(); |
1824 } | 1848 } |
1825 } | 1849 } |
1826 | 1850 |
1827 } // namespace views | 1851 } // namespace views |
OLD | NEW |