Chromium Code Reviews| 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 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1075 //////////////////////////////////////////////////////////////////////////////// | 1075 //////////////////////////////////////////////////////////////////////////////// |
| 1076 // Textfield, WordLookupClient overrides: | 1076 // Textfield, WordLookupClient overrides: |
| 1077 | 1077 |
| 1078 bool Textfield::GetDecoratedWordAtPoint(const gfx::Point& point, | 1078 bool Textfield::GetDecoratedWordAtPoint(const gfx::Point& point, |
| 1079 gfx::DecoratedText* decorated_word, | 1079 gfx::DecoratedText* decorated_word, |
| 1080 gfx::Point* baseline_point) { | 1080 gfx::Point* baseline_point) { |
| 1081 return GetRenderText()->GetDecoratedWordAtPoint(point, decorated_word, | 1081 return GetRenderText()->GetDecoratedWordAtPoint(point, decorated_word, |
| 1082 baseline_point); | 1082 baseline_point); |
| 1083 } | 1083 } |
| 1084 | 1084 |
| 1085 bool Textfield::GetDecoratedTextFromSelection( | |
| 1086 gfx::DecoratedText* decorated_text, | |
| 1087 gfx::Point* baseline_point) { | |
| 1088 return GetRenderText()->GetDecoratedTextForRange( | |
| 1089 GetRenderText()->selection(), decorated_text, baseline_point); | |
| 1090 } | |
| 1091 | |
| 1085 //////////////////////////////////////////////////////////////////////////////// | 1092 //////////////////////////////////////////////////////////////////////////////// |
| 1086 // Textfield, SelectionControllerDelegate overrides: | 1093 // Textfield, SelectionControllerDelegate overrides: |
| 1087 | 1094 |
| 1088 bool Textfield::HasTextBeingDragged() const { | 1095 bool Textfield::HasTextBeingDragged() const { |
| 1089 return initiating_drag_; | 1096 return initiating_drag_; |
| 1090 } | 1097 } |
| 1091 | 1098 |
| 1092 //////////////////////////////////////////////////////////////////////////////// | 1099 //////////////////////////////////////////////////////////////////////////////// |
| 1093 // Textfield, ui::TouchEditable overrides: | 1100 // Textfield, ui::TouchEditable overrides: |
| 1094 | 1101 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1169 } | 1176 } |
| 1170 | 1177 |
| 1171 void Textfield::DestroyTouchSelection() { | 1178 void Textfield::DestroyTouchSelection() { |
| 1172 touch_selection_controller_.reset(); | 1179 touch_selection_controller_.reset(); |
| 1173 } | 1180 } |
| 1174 | 1181 |
| 1175 //////////////////////////////////////////////////////////////////////////////// | 1182 //////////////////////////////////////////////////////////////////////////////// |
| 1176 // Textfield, ui::SimpleMenuModel::Delegate overrides: | 1183 // Textfield, ui::SimpleMenuModel::Delegate overrides: |
| 1177 | 1184 |
| 1178 bool Textfield::IsCommandIdChecked(int command_id) const { | 1185 bool Textfield::IsCommandIdChecked(int command_id) const { |
| 1186 if (text_services_context_menu_->IsTextServicesCommandId(command_id)) | |
|
tapted
2016/12/13 05:11:24
same here - I think only LOOK_UP should get here.
spqchan
2016/12/15 23:29:01
Acknowledged.
| |
| 1187 return text_services_context_menu_->IsCommandIdChecked(command_id); | |
| 1188 | |
| 1179 return true; | 1189 return true; |
| 1180 } | 1190 } |
| 1181 | 1191 |
| 1182 bool Textfield::IsCommandIdEnabled(int command_id) const { | 1192 bool Textfield::IsCommandIdEnabled(int command_id) const { |
| 1193 if (text_services_context_menu_->IsTextServicesCommandId(command_id)) | |
|
tapted
2016/12/13 05:11:24
text_services_context_menu_ can be null currently,
spqchan
2016/12/15 23:29:01
Done.
| |
| 1194 return text_services_context_menu_->IsCommandIdEnabled(command_id); | |
| 1195 | |
| 1183 return Textfield::IsTextEditCommandEnabled( | 1196 return Textfield::IsTextEditCommandEnabled( |
| 1184 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); | 1197 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); |
| 1185 } | 1198 } |
| 1186 | 1199 |
| 1187 bool Textfield::GetAcceleratorForCommandId(int command_id, | 1200 bool Textfield::GetAcceleratorForCommandId(int command_id, |
| 1188 ui::Accelerator* accelerator) const { | 1201 ui::Accelerator* accelerator) const { |
| 1189 switch (command_id) { | 1202 switch (command_id) { |
| 1190 case IDS_APP_UNDO: | 1203 case IDS_APP_UNDO: |
| 1191 *accelerator = ui::Accelerator(ui::VKEY_Z, kPlatformModifier); | 1204 *accelerator = ui::Accelerator(ui::VKEY_Z, kPlatformModifier); |
| 1192 return true; | 1205 return true; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1206 case IDS_APP_SELECT_ALL: | 1219 case IDS_APP_SELECT_ALL: |
| 1207 *accelerator = ui::Accelerator(ui::VKEY_A, kPlatformModifier); | 1220 *accelerator = ui::Accelerator(ui::VKEY_A, kPlatformModifier); |
| 1208 return true; | 1221 return true; |
| 1209 | 1222 |
| 1210 default: | 1223 default: |
| 1211 return false; | 1224 return false; |
| 1212 } | 1225 } |
| 1213 } | 1226 } |
| 1214 | 1227 |
| 1215 void Textfield::ExecuteCommand(int command_id, int event_flags) { | 1228 void Textfield::ExecuteCommand(int command_id, int event_flags) { |
| 1229 if (text_services_context_menu_->IsTextServicesCommandId(command_id)) { | |
| 1230 text_services_context_menu_->ExecuteCommand(command_id, event_flags); | |
| 1231 return; | |
| 1232 } | |
| 1233 | |
| 1216 Textfield::ExecuteTextEditCommand( | 1234 Textfield::ExecuteTextEditCommand( |
| 1217 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); | 1235 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); |
| 1218 } | 1236 } |
| 1219 | 1237 |
| 1220 //////////////////////////////////////////////////////////////////////////////// | 1238 //////////////////////////////////////////////////////////////////////////////// |
| 1221 // Textfield, ui::TextInputClient overrides: | 1239 // Textfield, ui::TextInputClient overrides: |
| 1222 | 1240 |
| 1223 void Textfield::SetCompositionText(const ui::CompositionText& composition) { | 1241 void Textfield::SetCompositionText(const ui::CompositionText& composition) { |
| 1224 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) | 1242 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) |
| 1225 return; | 1243 return; |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1969 bool Textfield::Paste() { | 1987 bool Textfield::Paste() { |
| 1970 if (!read_only() && model_->Paste()) { | 1988 if (!read_only() && model_->Paste()) { |
| 1971 if (controller_) | 1989 if (controller_) |
| 1972 controller_->OnAfterPaste(); | 1990 controller_->OnAfterPaste(); |
| 1973 return true; | 1991 return true; |
| 1974 } | 1992 } |
| 1975 return false; | 1993 return false; |
| 1976 } | 1994 } |
| 1977 | 1995 |
| 1978 void Textfield::UpdateContextMenu() { | 1996 void Textfield::UpdateContextMenu() { |
| 1979 if (!context_menu_contents_.get()) { | 1997 if (!context_menu_contents_.get() || |
| 1998 (text_services_context_menu_ && | |
| 1999 text_services_context_menu_->ShouldUpdateMenu())) { | |
| 1980 context_menu_contents_.reset(new ui::SimpleMenuModel(this)); | 2000 context_menu_contents_.reset(new ui::SimpleMenuModel(this)); |
| 1981 context_menu_contents_->AddItemWithStringId(IDS_APP_UNDO, IDS_APP_UNDO); | 2001 context_menu_contents_->AddItemWithStringId(IDS_APP_UNDO, IDS_APP_UNDO); |
| 1982 context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR); | 2002 context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR); |
| 1983 context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT); | 2003 context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT); |
| 1984 context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); | 2004 context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); |
| 1985 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); | 2005 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); |
| 1986 context_menu_contents_->AddItemWithStringId(IDS_APP_DELETE, IDS_APP_DELETE); | 2006 context_menu_contents_->AddItemWithStringId(IDS_APP_DELETE, IDS_APP_DELETE); |
| 1987 context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR); | 2007 context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR); |
| 1988 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL, | 2008 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL, |
| 1989 IDS_APP_SELECT_ALL); | 2009 IDS_APP_SELECT_ALL); |
| 1990 | 2010 |
| 1991 // If the controller adds menu commands, also override ExecuteCommand() and | 2011 // If the controller adds menu commands, also override ExecuteCommand() and |
| 1992 // IsCommandIdEnabled() as appropriate, for the commands added. | 2012 // IsCommandIdEnabled() as appropriate, for the commands added. |
| 1993 if (controller_) | 2013 if (controller_) |
| 1994 controller_->UpdateContextMenu(context_menu_contents_.get()); | 2014 controller_->UpdateContextMenu(context_menu_contents_.get()); |
| 2015 | |
| 2016 ViewsTextServicesContextMenu* text_services_menu = | |
| 2017 ViewsTextServicesContextMenu::Create( | |
| 2018 this, this, context_menu_contents_.get(), this); | |
| 2019 if (text_services_menu) | |
| 2020 text_services_context_menu_.reset(text_services_menu); | |
|
tapted
2016/12/13 05:11:24
we should be able to assign directly, so long as `
spqchan
2016/12/15 23:29:01
Done.
| |
| 2021 else | |
| 2022 text_services_context_menu_.reset(); | |
| 2023 | |
| 2024 context_menu_runner_.reset(new MenuRunner(context_menu_contents_.get(), | |
|
tapted
2016/12/13 05:11:24
this should be outside the `if` I think ? (i.e. be
spqchan
2016/12/15 23:29:01
Done.
| |
| 2025 MenuRunner::HAS_MNEMONICS | | |
| 2026 MenuRunner::CONTEXT_MENU | | |
| 2027 MenuRunner::ASYNC)); | |
| 1995 } | 2028 } |
| 1996 context_menu_runner_.reset(new MenuRunner(context_menu_contents_.get(), | |
| 1997 MenuRunner::HAS_MNEMONICS | | |
| 1998 MenuRunner::CONTEXT_MENU | | |
| 1999 MenuRunner::ASYNC)); | |
| 2000 } | 2029 } |
| 2001 | 2030 |
| 2002 bool Textfield::ImeEditingAllowed() const { | 2031 bool Textfield::ImeEditingAllowed() const { |
| 2003 // Disallow input method editing of password fields. | 2032 // Disallow input method editing of password fields. |
| 2004 ui::TextInputType t = GetTextInputType(); | 2033 ui::TextInputType t = GetTextInputType(); |
| 2005 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD); | 2034 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD); |
| 2006 } | 2035 } |
| 2007 | 2036 |
| 2008 void Textfield::RevealPasswordChar(int index) { | 2037 void Textfield::RevealPasswordChar(int index) { |
| 2009 GetRenderText()->SetObscuredRevealIndex(index); | 2038 GetRenderText()->SetObscuredRevealIndex(index); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2053 } | 2082 } |
| 2054 | 2083 |
| 2055 void Textfield::OnCursorBlinkTimerFired() { | 2084 void Textfield::OnCursorBlinkTimerFired() { |
| 2056 DCHECK(ShouldBlinkCursor()); | 2085 DCHECK(ShouldBlinkCursor()); |
| 2057 gfx::RenderText* render_text = GetRenderText(); | 2086 gfx::RenderText* render_text = GetRenderText(); |
| 2058 render_text->set_cursor_visible(!render_text->cursor_visible()); | 2087 render_text->set_cursor_visible(!render_text->cursor_visible()); |
| 2059 RepaintCursor(); | 2088 RepaintCursor(); |
| 2060 } | 2089 } |
| 2061 | 2090 |
| 2062 } // namespace views | 2091 } // namespace views |
| OLD | NEW |