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 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 | 1103 |
1104 void Textfield::GetSelectionEndPoints(ui::SelectionBound* anchor, | 1104 void Textfield::GetSelectionEndPoints(ui::SelectionBound* anchor, |
1105 ui::SelectionBound* focus) { | 1105 ui::SelectionBound* focus) { |
1106 gfx::RenderText* render_text = GetRenderText(); | 1106 gfx::RenderText* render_text = GetRenderText(); |
1107 const gfx::SelectionModel& sel = render_text->selection_model(); | 1107 const gfx::SelectionModel& sel = render_text->selection_model(); |
1108 gfx::SelectionModel start_sel = | 1108 gfx::SelectionModel start_sel = |
1109 render_text->GetSelectionModelForSelectionStart(); | 1109 render_text->GetSelectionModelForSelectionStart(); |
1110 gfx::Rect r1 = render_text->GetCursorBounds(start_sel, true); | 1110 gfx::Rect r1 = render_text->GetCursorBounds(start_sel, true); |
1111 gfx::Rect r2 = render_text->GetCursorBounds(sel, true); | 1111 gfx::Rect r2 = render_text->GetCursorBounds(sel, true); |
1112 | 1112 |
1113 anchor->edge_top = r1.origin(); | 1113 anchor->SetEdgeTop(r1.origin()); |
1114 anchor->edge_bottom = r1.bottom_left(); | 1114 anchor->SetEdgeBottom(r1.bottom_left()); |
1115 focus->edge_top = r2.origin(); | 1115 focus->SetEdgeTop(r2.origin()); |
1116 focus->edge_bottom = r2.bottom_left(); | 1116 focus->SetEdgeBottom(r2.bottom_left()); |
1117 | 1117 |
1118 // Determine the SelectionBound's type for focus and anchor. | 1118 // Determine the SelectionBound's type for focus and anchor. |
1119 // TODO(mfomitchev): Ideally we should have different logical directions for | 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. | 1120 // start and end to support proper handle direction for mixed LTR/RTL text. |
1121 const bool ltr = GetTextDirection() != base::i18n::RIGHT_TO_LEFT; | 1121 const bool ltr = GetTextDirection() != base::i18n::RIGHT_TO_LEFT; |
1122 size_t anchor_position_index = sel.selection().start(); | 1122 size_t anchor_position_index = sel.selection().start(); |
1123 size_t focus_position_index = sel.selection().end(); | 1123 size_t focus_position_index = sel.selection().end(); |
1124 | 1124 |
1125 if (anchor_position_index == focus_position_index) { | 1125 if (anchor_position_index == focus_position_index) { |
1126 anchor->type = focus->type = ui::SelectionBound::CENTER; | 1126 anchor->set_type(ui::SelectionBound::CENTER); |
| 1127 focus->set_type(ui::SelectionBound::CENTER); |
1127 } else if ((ltr && anchor_position_index < focus_position_index) || | 1128 } else if ((ltr && anchor_position_index < focus_position_index) || |
1128 (!ltr && anchor_position_index > focus_position_index)) { | 1129 (!ltr && anchor_position_index > focus_position_index)) { |
1129 anchor->type = ui::SelectionBound::LEFT; | 1130 anchor->set_type(ui::SelectionBound::LEFT); |
1130 focus->type = ui::SelectionBound::RIGHT; | 1131 focus->set_type(ui::SelectionBound::RIGHT); |
1131 } else { | 1132 } else { |
1132 anchor->type = ui::SelectionBound::RIGHT; | 1133 anchor->set_type(ui::SelectionBound::RIGHT); |
1133 focus->type = ui::SelectionBound::LEFT; | 1134 focus->set_type(ui::SelectionBound::LEFT); |
1134 } | 1135 } |
1135 } | 1136 } |
1136 | 1137 |
1137 gfx::Rect Textfield::GetBounds() { | 1138 gfx::Rect Textfield::GetBounds() { |
1138 return GetLocalBounds(); | 1139 return GetLocalBounds(); |
1139 } | 1140 } |
1140 | 1141 |
1141 gfx::NativeView Textfield::GetNativeView() const { | 1142 gfx::NativeView Textfield::GetNativeView() const { |
1142 return GetWidget()->GetNativeView(); | 1143 return GetWidget()->GetNativeView(); |
1143 } | 1144 } |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1865 const size_t length = selection_clipboard_text.length(); | 1866 const size_t length = selection_clipboard_text.length(); |
1866 range = gfx::Range(range.start() + length, range.end() + length); | 1867 range = gfx::Range(range.start() + length, range.end() + length); |
1867 } | 1868 } |
1868 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); | 1869 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); |
1869 UpdateAfterChange(true, true); | 1870 UpdateAfterChange(true, true); |
1870 OnAfterUserAction(); | 1871 OnAfterUserAction(); |
1871 } | 1872 } |
1872 } | 1873 } |
1873 | 1874 |
1874 } // namespace views | 1875 } // namespace views |
OLD | NEW |