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/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 #include "ui/gfx/selection_bound.h" | 34 #include "ui/gfx/selection_bound.h" |
35 #include "ui/native_theme/native_theme.h" | 35 #include "ui/native_theme/native_theme.h" |
36 #include "ui/strings/grit/ui_strings.h" | 36 #include "ui/strings/grit/ui_strings.h" |
37 #include "ui/views/background.h" | 37 #include "ui/views/background.h" |
38 #include "ui/views/controls/focus_ring.h" | 38 #include "ui/views/controls/focus_ring.h" |
39 #include "ui/views/controls/focusable_border.h" | 39 #include "ui/views/controls/focusable_border.h" |
40 #include "ui/views/controls/label.h" | 40 #include "ui/views/controls/label.h" |
41 #include "ui/views/controls/menu/menu_runner.h" | 41 #include "ui/views/controls/menu/menu_runner.h" |
42 #include "ui/views/controls/native/native_view_host.h" | 42 #include "ui/views/controls/native/native_view_host.h" |
43 #include "ui/views/controls/textfield/textfield_controller.h" | 43 #include "ui/views/controls/textfield/textfield_controller.h" |
44 #include "ui/views/controls/views_text_services_context_menu.h" | |
44 #include "ui/views/drag_utils.h" | 45 #include "ui/views/drag_utils.h" |
45 #include "ui/views/native_cursor.h" | 46 #include "ui/views/native_cursor.h" |
46 #include "ui/views/painter.h" | 47 #include "ui/views/painter.h" |
47 #include "ui/views/style/platform_style.h" | 48 #include "ui/views/style/platform_style.h" |
48 #include "ui/views/views_delegate.h" | 49 #include "ui/views/views_delegate.h" |
49 #include "ui/views/widget/widget.h" | 50 #include "ui/views/widget/widget.h" |
50 | 51 |
51 #if defined(OS_WIN) | 52 #if defined(OS_WIN) |
52 #include "base/win/win_util.h" | 53 #include "base/win/win_util.h" |
53 #include "ui/base/win/osk_display_manager.h" | 54 #include "ui/base/win/osk_display_manager.h" |
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1075 //////////////////////////////////////////////////////////////////////////////// | 1076 //////////////////////////////////////////////////////////////////////////////// |
1076 // Textfield, WordLookupClient overrides: | 1077 // Textfield, WordLookupClient overrides: |
1077 | 1078 |
1078 bool Textfield::GetDecoratedWordAtPoint(const gfx::Point& point, | 1079 bool Textfield::GetDecoratedWordAtPoint(const gfx::Point& point, |
1079 gfx::DecoratedText* decorated_word, | 1080 gfx::DecoratedText* decorated_word, |
1080 gfx::Point* baseline_point) { | 1081 gfx::Point* baseline_point) { |
1081 return GetRenderText()->GetDecoratedWordAtPoint(point, decorated_word, | 1082 return GetRenderText()->GetDecoratedWordAtPoint(point, decorated_word, |
1082 baseline_point); | 1083 baseline_point); |
1083 } | 1084 } |
1084 | 1085 |
1086 bool Textfield::GetDecoratedTextFromSelection( | |
1087 gfx::DecoratedText* decorated_text, | |
1088 gfx::Point* baseline_point) { | |
1089 return GetRenderText()->GetDecoratedTextAndBaselineForRange( | |
1090 GetRenderText()->selection(), decorated_text, baseline_point); | |
1091 } | |
1092 | |
1085 //////////////////////////////////////////////////////////////////////////////// | 1093 //////////////////////////////////////////////////////////////////////////////// |
1086 // Textfield, SelectionControllerDelegate overrides: | 1094 // Textfield, SelectionControllerDelegate overrides: |
1087 | 1095 |
1088 bool Textfield::HasTextBeingDragged() const { | 1096 bool Textfield::HasTextBeingDragged() const { |
1089 return initiating_drag_; | 1097 return initiating_drag_; |
1090 } | 1098 } |
1091 | 1099 |
1092 //////////////////////////////////////////////////////////////////////////////// | 1100 //////////////////////////////////////////////////////////////////////////////// |
1093 // Textfield, ui::TouchEditable overrides: | 1101 // Textfield, ui::TouchEditable overrides: |
1094 | 1102 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1169 } | 1177 } |
1170 | 1178 |
1171 void Textfield::DestroyTouchSelection() { | 1179 void Textfield::DestroyTouchSelection() { |
1172 touch_selection_controller_.reset(); | 1180 touch_selection_controller_.reset(); |
1173 } | 1181 } |
1174 | 1182 |
1175 //////////////////////////////////////////////////////////////////////////////// | 1183 //////////////////////////////////////////////////////////////////////////////// |
1176 // Textfield, ui::SimpleMenuModel::Delegate overrides: | 1184 // Textfield, ui::SimpleMenuModel::Delegate overrides: |
1177 | 1185 |
1178 bool Textfield::IsCommandIdChecked(int command_id) const { | 1186 bool Textfield::IsCommandIdChecked(int command_id) const { |
1187 if (text_services_context_menu_ && | |
1188 text_services_context_menu_->IsTextServicesCommandId(command_id)) { | |
1189 return text_services_context_menu_->IsCommandIdChecked(command_id); | |
1190 } | |
1191 | |
1179 return true; | 1192 return true; |
1180 } | 1193 } |
1181 | 1194 |
1182 bool Textfield::IsCommandIdEnabled(int command_id) const { | 1195 bool Textfield::IsCommandIdEnabled(int command_id) const { |
1196 if (text_services_context_menu_ && | |
1197 text_services_context_menu_->IsTextServicesCommandId(command_id)) { | |
1198 return text_services_context_menu_->IsCommandIdEnabled(command_id); | |
1199 } | |
1200 | |
1183 return Textfield::IsTextEditCommandEnabled( | 1201 return Textfield::IsTextEditCommandEnabled( |
1184 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); | 1202 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); |
1185 } | 1203 } |
1186 | 1204 |
1187 bool Textfield::GetAcceleratorForCommandId(int command_id, | 1205 bool Textfield::GetAcceleratorForCommandId(int command_id, |
1188 ui::Accelerator* accelerator) const { | 1206 ui::Accelerator* accelerator) const { |
1189 switch (command_id) { | 1207 switch (command_id) { |
1190 case IDS_APP_UNDO: | 1208 case IDS_APP_UNDO: |
1191 *accelerator = ui::Accelerator(ui::VKEY_Z, kPlatformModifier); | 1209 *accelerator = ui::Accelerator(ui::VKEY_Z, kPlatformModifier); |
1192 return true; | 1210 return true; |
(...skipping 13 matching lines...) Expand all Loading... | |
1206 case IDS_APP_SELECT_ALL: | 1224 case IDS_APP_SELECT_ALL: |
1207 *accelerator = ui::Accelerator(ui::VKEY_A, kPlatformModifier); | 1225 *accelerator = ui::Accelerator(ui::VKEY_A, kPlatformModifier); |
1208 return true; | 1226 return true; |
1209 | 1227 |
1210 default: | 1228 default: |
1211 return false; | 1229 return false; |
1212 } | 1230 } |
1213 } | 1231 } |
1214 | 1232 |
1215 void Textfield::ExecuteCommand(int command_id, int event_flags) { | 1233 void Textfield::ExecuteCommand(int command_id, int event_flags) { |
1234 if (text_services_context_menu_ && | |
1235 text_services_context_menu_->IsTextServicesCommandId(command_id)) { | |
1236 text_services_context_menu_->ExecuteCommand(command_id, event_flags); | |
1237 return; | |
1238 } | |
1239 | |
1216 Textfield::ExecuteTextEditCommand( | 1240 Textfield::ExecuteTextEditCommand( |
1217 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); | 1241 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); |
1218 } | 1242 } |
1219 | 1243 |
1220 //////////////////////////////////////////////////////////////////////////////// | 1244 //////////////////////////////////////////////////////////////////////////////// |
1221 // Textfield, ui::TextInputClient overrides: | 1245 // Textfield, ui::TextInputClient overrides: |
1222 | 1246 |
1223 void Textfield::SetCompositionText(const ui::CompositionText& composition) { | 1247 void Textfield::SetCompositionText(const ui::CompositionText& composition) { |
1224 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) | 1248 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) |
1225 return; | 1249 return; |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1924 void Textfield::MoveCursorTo(const gfx::Point& point, bool select) { | 1948 void Textfield::MoveCursorTo(const gfx::Point& point, bool select) { |
1925 if (model_->MoveCursorTo(point, select)) | 1949 if (model_->MoveCursorTo(point, select)) |
1926 UpdateAfterChange(false, true); | 1950 UpdateAfterChange(false, true); |
1927 } | 1951 } |
1928 | 1952 |
1929 void Textfield::OnCaretBoundsChanged() { | 1953 void Textfield::OnCaretBoundsChanged() { |
1930 if (GetInputMethod()) | 1954 if (GetInputMethod()) |
1931 GetInputMethod()->OnCaretBoundsChanged(this); | 1955 GetInputMethod()->OnCaretBoundsChanged(this); |
1932 if (touch_selection_controller_) | 1956 if (touch_selection_controller_) |
1933 touch_selection_controller_->SelectionChanged(); | 1957 touch_selection_controller_->SelectionChanged(); |
1958 | |
1959 context_menu_contents_.reset(); | |
tapted
2016/12/16 07:01:19
this should have a comment
spqchan
2016/12/17 00:34:21
Done.
| |
1934 } | 1960 } |
1935 | 1961 |
1936 void Textfield::OnBeforeUserAction() { | 1962 void Textfield::OnBeforeUserAction() { |
1937 DCHECK(!performing_user_action_); | 1963 DCHECK(!performing_user_action_); |
1938 performing_user_action_ = true; | 1964 performing_user_action_ = true; |
1939 if (controller_) | 1965 if (controller_) |
1940 controller_->OnBeforeUserAction(this); | 1966 controller_->OnBeforeUserAction(this); |
1941 } | 1967 } |
1942 | 1968 |
1943 void Textfield::OnAfterUserAction() { | 1969 void Textfield::OnAfterUserAction() { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1985 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); | 2011 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); |
1986 context_menu_contents_->AddItemWithStringId(IDS_APP_DELETE, IDS_APP_DELETE); | 2012 context_menu_contents_->AddItemWithStringId(IDS_APP_DELETE, IDS_APP_DELETE); |
1987 context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR); | 2013 context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR); |
1988 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL, | 2014 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL, |
1989 IDS_APP_SELECT_ALL); | 2015 IDS_APP_SELECT_ALL); |
1990 | 2016 |
1991 // If the controller adds menu commands, also override ExecuteCommand() and | 2017 // If the controller adds menu commands, also override ExecuteCommand() and |
1992 // IsCommandIdEnabled() as appropriate, for the commands added. | 2018 // IsCommandIdEnabled() as appropriate, for the commands added. |
1993 if (controller_) | 2019 if (controller_) |
1994 controller_->UpdateContextMenu(context_menu_contents_.get()); | 2020 controller_->UpdateContextMenu(context_menu_contents_.get()); |
2021 | |
2022 text_services_context_menu_ = ViewsTextServicesContextMenu::Create( | |
2023 context_menu_contents_.get(), this); | |
1995 } | 2024 } |
2025 | |
1996 context_menu_runner_.reset(new MenuRunner(context_menu_contents_.get(), | 2026 context_menu_runner_.reset(new MenuRunner(context_menu_contents_.get(), |
1997 MenuRunner::HAS_MNEMONICS | | 2027 MenuRunner::HAS_MNEMONICS | |
1998 MenuRunner::CONTEXT_MENU | | 2028 MenuRunner::CONTEXT_MENU | |
1999 MenuRunner::ASYNC)); | 2029 MenuRunner::ASYNC)); |
2000 } | 2030 } |
2001 | 2031 |
2002 bool Textfield::ImeEditingAllowed() const { | 2032 bool Textfield::ImeEditingAllowed() const { |
2003 // Disallow input method editing of password fields. | 2033 // Disallow input method editing of password fields. |
2004 ui::TextInputType t = GetTextInputType(); | 2034 ui::TextInputType t = GetTextInputType(); |
2005 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD); | 2035 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2053 } | 2083 } |
2054 | 2084 |
2055 void Textfield::OnCursorBlinkTimerFired() { | 2085 void Textfield::OnCursorBlinkTimerFired() { |
2056 DCHECK(ShouldBlinkCursor()); | 2086 DCHECK(ShouldBlinkCursor()); |
2057 gfx::RenderText* render_text = GetRenderText(); | 2087 gfx::RenderText* render_text = GetRenderText(); |
2058 render_text->set_cursor_visible(!render_text->cursor_visible()); | 2088 render_text->set_cursor_visible(!render_text->cursor_visible()); |
2059 RepaintCursor(); | 2089 RepaintCursor(); |
2060 } | 2090 } |
2061 | 2091 |
2062 } // namespace views | 2092 } // namespace views |
OLD | NEW |