| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "ui/accessibility/ax_view_state.h" | 12 #include "ui/accessibility/ax_view_state.h" |
| 13 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 13 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 14 #include "ui/base/cursor/cursor.h" | 14 #include "ui/base/cursor/cursor.h" |
| 15 #include "ui/base/default_style.h" | 15 #include "ui/base/default_style.h" |
| 16 #include "ui/base/dragdrop/drag_drop_types.h" | 16 #include "ui/base/dragdrop/drag_drop_types.h" |
| 17 #include "ui/base/dragdrop/drag_utils.h" | 17 #include "ui/base/dragdrop/drag_utils.h" |
| 18 #include "ui/base/ime/input_method.h" | 18 #include "ui/base/ime/input_method.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/base/touch/selection_bound.h" | |
| 21 #include "ui/base/ui_base_switches_util.h" | 20 #include "ui/base/ui_base_switches_util.h" |
| 22 #include "ui/compositor/canvas_painter.h" | 21 #include "ui/compositor/canvas_painter.h" |
| 23 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 22 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 24 #include "ui/display/display.h" | 23 #include "ui/display/display.h" |
| 25 #include "ui/display/screen.h" | 24 #include "ui/display/screen.h" |
| 26 #include "ui/events/base_event_utils.h" | 25 #include "ui/events/base_event_utils.h" |
| 27 #include "ui/events/event.h" | 26 #include "ui/events/event.h" |
| 28 #include "ui/events/keycodes/keyboard_codes.h" | 27 #include "ui/events/keycodes/keyboard_codes.h" |
| 29 #include "ui/gfx/canvas.h" | 28 #include "ui/gfx/canvas.h" |
| 30 #include "ui/gfx/geometry/insets.h" | 29 #include "ui/gfx/geometry/insets.h" |
| 30 #include "ui/gfx/selection_bound.h" |
| 31 #include "ui/native_theme/native_theme.h" | 31 #include "ui/native_theme/native_theme.h" |
| 32 #include "ui/strings/grit/ui_strings.h" | 32 #include "ui/strings/grit/ui_strings.h" |
| 33 #include "ui/views/background.h" | 33 #include "ui/views/background.h" |
| 34 #include "ui/views/controls/focusable_border.h" | 34 #include "ui/views/controls/focusable_border.h" |
| 35 #include "ui/views/controls/label.h" | 35 #include "ui/views/controls/label.h" |
| 36 #include "ui/views/controls/menu/menu_runner.h" | 36 #include "ui/views/controls/menu/menu_runner.h" |
| 37 #include "ui/views/controls/native/native_view_host.h" | 37 #include "ui/views/controls/native/native_view_host.h" |
| 38 #include "ui/views/controls/textfield/textfield_controller.h" | 38 #include "ui/views/controls/textfield/textfield_controller.h" |
| 39 #include "ui/views/drag_utils.h" | 39 #include "ui/views/drag_utils.h" |
| 40 #include "ui/views/metrics.h" | 40 #include "ui/views/metrics.h" |
| (...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 | 1152 |
| 1153 OnBeforeUserAction(); | 1153 OnBeforeUserAction(); |
| 1154 SelectSelectionModel(selection); | 1154 SelectSelectionModel(selection); |
| 1155 OnAfterUserAction(); | 1155 OnAfterUserAction(); |
| 1156 } | 1156 } |
| 1157 | 1157 |
| 1158 void Textfield::MoveCaretTo(const gfx::Point& point) { | 1158 void Textfield::MoveCaretTo(const gfx::Point& point) { |
| 1159 SelectRect(point, point); | 1159 SelectRect(point, point); |
| 1160 } | 1160 } |
| 1161 | 1161 |
| 1162 void Textfield::GetSelectionEndPoints(ui::SelectionBound* anchor, | 1162 void Textfield::GetSelectionEndPoints(gfx::SelectionBound* anchor, |
| 1163 ui::SelectionBound* focus) { | 1163 gfx::SelectionBound* focus) { |
| 1164 gfx::RenderText* render_text = GetRenderText(); | 1164 gfx::RenderText* render_text = GetRenderText(); |
| 1165 const gfx::SelectionModel& sel = render_text->selection_model(); | 1165 const gfx::SelectionModel& sel = render_text->selection_model(); |
| 1166 gfx::SelectionModel start_sel = | 1166 gfx::SelectionModel start_sel = |
| 1167 render_text->GetSelectionModelForSelectionStart(); | 1167 render_text->GetSelectionModelForSelectionStart(); |
| 1168 gfx::Rect r1 = render_text->GetCursorBounds(start_sel, true); | 1168 gfx::Rect r1 = render_text->GetCursorBounds(start_sel, true); |
| 1169 gfx::Rect r2 = render_text->GetCursorBounds(sel, true); | 1169 gfx::Rect r2 = render_text->GetCursorBounds(sel, true); |
| 1170 | 1170 |
| 1171 anchor->SetEdge(gfx::PointF(r1.origin()), gfx::PointF(r1.bottom_left())); | 1171 anchor->SetEdge(gfx::PointF(r1.origin()), gfx::PointF(r1.bottom_left())); |
| 1172 focus->SetEdge(gfx::PointF(r2.origin()), gfx::PointF(r2.bottom_left())); | 1172 focus->SetEdge(gfx::PointF(r2.origin()), gfx::PointF(r2.bottom_left())); |
| 1173 | 1173 |
| 1174 // Determine the SelectionBound's type for focus and anchor. | 1174 // Determine the SelectionBound's type for focus and anchor. |
| 1175 // TODO(mfomitchev): Ideally we should have different logical directions for | 1175 // TODO(mfomitchev): Ideally we should have different logical directions for |
| 1176 // start and end to support proper handle direction for mixed LTR/RTL text. | 1176 // start and end to support proper handle direction for mixed LTR/RTL text. |
| 1177 const bool ltr = GetTextDirection() != base::i18n::RIGHT_TO_LEFT; | 1177 const bool ltr = GetTextDirection() != base::i18n::RIGHT_TO_LEFT; |
| 1178 size_t anchor_position_index = sel.selection().start(); | 1178 size_t anchor_position_index = sel.selection().start(); |
| 1179 size_t focus_position_index = sel.selection().end(); | 1179 size_t focus_position_index = sel.selection().end(); |
| 1180 | 1180 |
| 1181 if (anchor_position_index == focus_position_index) { | 1181 if (anchor_position_index == focus_position_index) { |
| 1182 anchor->set_type(ui::SelectionBound::CENTER); | 1182 anchor->set_type(gfx::SelectionBound::CENTER); |
| 1183 focus->set_type(ui::SelectionBound::CENTER); | 1183 focus->set_type(gfx::SelectionBound::CENTER); |
| 1184 } else if ((ltr && anchor_position_index < focus_position_index) || | 1184 } else if ((ltr && anchor_position_index < focus_position_index) || |
| 1185 (!ltr && anchor_position_index > focus_position_index)) { | 1185 (!ltr && anchor_position_index > focus_position_index)) { |
| 1186 anchor->set_type(ui::SelectionBound::LEFT); | 1186 anchor->set_type(gfx::SelectionBound::LEFT); |
| 1187 focus->set_type(ui::SelectionBound::RIGHT); | 1187 focus->set_type(gfx::SelectionBound::RIGHT); |
| 1188 } else { | 1188 } else { |
| 1189 anchor->set_type(ui::SelectionBound::RIGHT); | 1189 anchor->set_type(gfx::SelectionBound::RIGHT); |
| 1190 focus->set_type(ui::SelectionBound::LEFT); | 1190 focus->set_type(gfx::SelectionBound::LEFT); |
| 1191 } | 1191 } |
| 1192 } | 1192 } |
| 1193 | 1193 |
| 1194 gfx::Rect Textfield::GetBounds() { | 1194 gfx::Rect Textfield::GetBounds() { |
| 1195 return GetLocalBounds(); | 1195 return GetLocalBounds(); |
| 1196 } | 1196 } |
| 1197 | 1197 |
| 1198 gfx::NativeView Textfield::GetNativeView() const { | 1198 gfx::NativeView Textfield::GetNativeView() const { |
| 1199 return GetWidget()->GetNativeView(); | 1199 return GetWidget()->GetNativeView(); |
| 1200 } | 1200 } |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1929 RequestFocus(); | 1929 RequestFocus(); |
| 1930 model_->MoveCursorTo(mouse); | 1930 model_->MoveCursorTo(mouse); |
| 1931 if (!selection_clipboard_text.empty()) { | 1931 if (!selection_clipboard_text.empty()) { |
| 1932 model_->InsertText(selection_clipboard_text); | 1932 model_->InsertText(selection_clipboard_text); |
| 1933 UpdateAfterChange(true, true); | 1933 UpdateAfterChange(true, true); |
| 1934 } | 1934 } |
| 1935 OnAfterUserAction(); | 1935 OnAfterUserAction(); |
| 1936 } | 1936 } |
| 1937 | 1937 |
| 1938 } // namespace views | 1938 } // namespace views |
| OLD | NEW |