Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: ui/views/controls/textfield/textfield.cc

Issue 2164483006: [MacViews] Implemented text context menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 24 matching lines...) Expand all
35 #include "ui/gfx/selection_bound.h" 35 #include "ui/gfx/selection_bound.h"
36 #include "ui/native_theme/native_theme.h" 36 #include "ui/native_theme/native_theme.h"
37 #include "ui/strings/grit/ui_strings.h" 37 #include "ui/strings/grit/ui_strings.h"
38 #include "ui/views/background.h" 38 #include "ui/views/background.h"
39 #include "ui/views/controls/focus_ring.h" 39 #include "ui/views/controls/focus_ring.h"
40 #include "ui/views/controls/focusable_border.h" 40 #include "ui/views/controls/focusable_border.h"
41 #include "ui/views/controls/label.h" 41 #include "ui/views/controls/label.h"
42 #include "ui/views/controls/menu/menu_runner.h" 42 #include "ui/views/controls/menu/menu_runner.h"
43 #include "ui/views/controls/native/native_view_host.h" 43 #include "ui/views/controls/native/native_view_host.h"
44 #include "ui/views/controls/textfield/textfield_controller.h" 44 #include "ui/views/controls/textfield/textfield_controller.h"
45 #include "ui/views/controls/views_text_services_context_menu.h"
45 #include "ui/views/drag_utils.h" 46 #include "ui/views/drag_utils.h"
46 #include "ui/views/native_cursor.h" 47 #include "ui/views/native_cursor.h"
47 #include "ui/views/painter.h" 48 #include "ui/views/painter.h"
48 #include "ui/views/style/platform_style.h" 49 #include "ui/views/style/platform_style.h"
49 #include "ui/views/views_delegate.h" 50 #include "ui/views/views_delegate.h"
50 #include "ui/views/widget/widget.h" 51 #include "ui/views/widget/widget.h"
51 52
52 #if defined(OS_WIN) 53 #if defined(OS_WIN)
53 #include "base/win/win_util.h" 54 #include "base/win/win_util.h"
54 #include "ui/base/win/osk_display_manager.h" 55 #include "ui/base/win/osk_display_manager.h"
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 1073
1073 bool Textfield::CanStartDragForView(View* sender, 1074 bool Textfield::CanStartDragForView(View* sender,
1074 const gfx::Point& press_pt, 1075 const gfx::Point& press_pt,
1075 const gfx::Point& p) { 1076 const gfx::Point& p) {
1076 return initiating_drag_ && GetRenderText()->IsPointInSelection(press_pt); 1077 return initiating_drag_ && GetRenderText()->IsPointInSelection(press_pt);
1077 } 1078 }
1078 1079
1079 //////////////////////////////////////////////////////////////////////////////// 1080 ////////////////////////////////////////////////////////////////////////////////
1080 // Textfield, WordLookupClient overrides: 1081 // Textfield, WordLookupClient overrides:
1081 1082
1082 bool Textfield::GetDecoratedWordAtPoint(const gfx::Point& point, 1083 bool Textfield::GetDecoratedWordAndBaselineAtPoint(
1083 gfx::DecoratedText* decorated_word, 1084 const gfx::Point& point,
1084 gfx::Point* baseline_point) { 1085 gfx::DecoratedText* decorated_word,
1085 return GetRenderText()->GetDecoratedWordAtPoint(point, decorated_word, 1086 gfx::Point* baseline_point) {
1086 baseline_point); 1087 return GetRenderText()->GetDecoratedWordAndBaselineAtPoint(
1088 point, decorated_word, baseline_point);
1089 }
1090
1091 bool Textfield::GetDecoratedTextAndBaselineFromSelection(
1092 gfx::DecoratedText* decorated_text,
1093 gfx::Point* baseline_point) {
1094 return GetRenderText()->GetDecoratedTextAndBaselineForRange(
1095 GetRenderText()->selection(), decorated_text, baseline_point);
1087 } 1096 }
1088 1097
1089 //////////////////////////////////////////////////////////////////////////////// 1098 ////////////////////////////////////////////////////////////////////////////////
1090 // Textfield, SelectionControllerDelegate overrides: 1099 // Textfield, SelectionControllerDelegate overrides:
1091 1100
1092 bool Textfield::HasTextBeingDragged() const { 1101 bool Textfield::HasTextBeingDragged() const {
1093 return initiating_drag_; 1102 return initiating_drag_;
1094 } 1103 }
1095 1104
1096 //////////////////////////////////////////////////////////////////////////////// 1105 ////////////////////////////////////////////////////////////////////////////////
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 } 1182 }
1174 1183
1175 void Textfield::DestroyTouchSelection() { 1184 void Textfield::DestroyTouchSelection() {
1176 touch_selection_controller_.reset(); 1185 touch_selection_controller_.reset();
1177 } 1186 }
1178 1187
1179 //////////////////////////////////////////////////////////////////////////////// 1188 ////////////////////////////////////////////////////////////////////////////////
1180 // Textfield, ui::SimpleMenuModel::Delegate overrides: 1189 // Textfield, ui::SimpleMenuModel::Delegate overrides:
1181 1190
1182 bool Textfield::IsCommandIdChecked(int command_id) const { 1191 bool Textfield::IsCommandIdChecked(int command_id) const {
1192 if (text_services_context_menu_ &&
1193 text_services_context_menu_->HandlesCommandId(command_id)) {
1194 return text_services_context_menu_->IsCommandIdChecked(command_id);
1195 }
1196
1183 return true; 1197 return true;
1184 } 1198 }
1185 1199
1186 bool Textfield::IsCommandIdEnabled(int command_id) const { 1200 bool Textfield::IsCommandIdEnabled(int command_id) const {
1201 if (text_services_context_menu_ &&
1202 text_services_context_menu_->HandlesCommandId(command_id)) {
1203 return text_services_context_menu_->IsCommandIdEnabled(command_id);
1204 }
1205
1187 return Textfield::IsTextEditCommandEnabled( 1206 return Textfield::IsTextEditCommandEnabled(
1188 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); 1207 GetTextEditCommandFromMenuCommand(command_id, HasSelection()));
1189 } 1208 }
1190 1209
1191 bool Textfield::GetAcceleratorForCommandId(int command_id, 1210 bool Textfield::GetAcceleratorForCommandId(int command_id,
1192 ui::Accelerator* accelerator) const { 1211 ui::Accelerator* accelerator) const {
1193 switch (command_id) { 1212 switch (command_id) {
1194 case IDS_APP_UNDO: 1213 case IDS_APP_UNDO:
1195 *accelerator = ui::Accelerator(ui::VKEY_Z, kPlatformModifier); 1214 *accelerator = ui::Accelerator(ui::VKEY_Z, kPlatformModifier);
1196 return true; 1215 return true;
(...skipping 13 matching lines...) Expand all
1210 case IDS_APP_SELECT_ALL: 1229 case IDS_APP_SELECT_ALL:
1211 *accelerator = ui::Accelerator(ui::VKEY_A, kPlatformModifier); 1230 *accelerator = ui::Accelerator(ui::VKEY_A, kPlatformModifier);
1212 return true; 1231 return true;
1213 1232
1214 default: 1233 default:
1215 return false; 1234 return false;
1216 } 1235 }
1217 } 1236 }
1218 1237
1219 void Textfield::ExecuteCommand(int command_id, int event_flags) { 1238 void Textfield::ExecuteCommand(int command_id, int event_flags) {
1239 if (text_services_context_menu_ &&
1240 text_services_context_menu_->HandlesCommandId(command_id)) {
1241 text_services_context_menu_->ExecuteCommand(command_id, event_flags);
1242 return;
1243 }
1244
1220 Textfield::ExecuteTextEditCommand( 1245 Textfield::ExecuteTextEditCommand(
1221 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); 1246 GetTextEditCommandFromMenuCommand(command_id, HasSelection()));
1222 } 1247 }
1223 1248
1224 //////////////////////////////////////////////////////////////////////////////// 1249 ////////////////////////////////////////////////////////////////////////////////
1225 // Textfield, ui::TextInputClient overrides: 1250 // Textfield, ui::TextInputClient overrides:
1226 1251
1227 void Textfield::SetCompositionText(const ui::CompositionText& composition) { 1252 void Textfield::SetCompositionText(const ui::CompositionText& composition) {
1228 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) 1253 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE)
1229 return; 1254 return;
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
1928 void Textfield::MoveCursorTo(const gfx::Point& point, bool select) { 1953 void Textfield::MoveCursorTo(const gfx::Point& point, bool select) {
1929 if (model_->MoveCursorTo(point, select)) 1954 if (model_->MoveCursorTo(point, select))
1930 UpdateAfterChange(false, true); 1955 UpdateAfterChange(false, true);
1931 } 1956 }
1932 1957
1933 void Textfield::OnCaretBoundsChanged() { 1958 void Textfield::OnCaretBoundsChanged() {
1934 if (GetInputMethod()) 1959 if (GetInputMethod())
1935 GetInputMethod()->OnCaretBoundsChanged(this); 1960 GetInputMethod()->OnCaretBoundsChanged(this);
1936 if (touch_selection_controller_) 1961 if (touch_selection_controller_)
1937 touch_selection_controller_->SelectionChanged(); 1962 touch_selection_controller_->SelectionChanged();
1963
1964 // On Mac, the context menu contains a look up item which displays the
1965 // selected text. As such, the menu needs to be updated if the selection has
1966 // changed.
1967 context_menu_contents_.reset();
1938 } 1968 }
1939 1969
1940 void Textfield::OnBeforeUserAction() { 1970 void Textfield::OnBeforeUserAction() {
1941 DCHECK(!performing_user_action_); 1971 DCHECK(!performing_user_action_);
1942 performing_user_action_ = true; 1972 performing_user_action_ = true;
1943 if (controller_) 1973 if (controller_)
1944 controller_->OnBeforeUserAction(this); 1974 controller_->OnBeforeUserAction(this);
1945 } 1975 }
1946 1976
1947 void Textfield::OnAfterUserAction() { 1977 void Textfield::OnAfterUserAction() {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); 2019 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE);
1990 context_menu_contents_->AddItemWithStringId(IDS_APP_DELETE, IDS_APP_DELETE); 2020 context_menu_contents_->AddItemWithStringId(IDS_APP_DELETE, IDS_APP_DELETE);
1991 context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR); 2021 context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR);
1992 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL, 2022 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL,
1993 IDS_APP_SELECT_ALL); 2023 IDS_APP_SELECT_ALL);
1994 2024
1995 // If the controller adds menu commands, also override ExecuteCommand() and 2025 // If the controller adds menu commands, also override ExecuteCommand() and
1996 // IsCommandIdEnabled() as appropriate, for the commands added. 2026 // IsCommandIdEnabled() as appropriate, for the commands added.
1997 if (controller_) 2027 if (controller_)
1998 controller_->UpdateContextMenu(context_menu_contents_.get()); 2028 controller_->UpdateContextMenu(context_menu_contents_.get());
2029
2030 text_services_context_menu_ = ViewsTextServicesContextMenu::Create(
2031 context_menu_contents_.get(), this);
1999 } 2032 }
2033
2000 context_menu_runner_.reset(new MenuRunner(context_menu_contents_.get(), 2034 context_menu_runner_.reset(new MenuRunner(context_menu_contents_.get(),
2001 MenuRunner::HAS_MNEMONICS | 2035 MenuRunner::HAS_MNEMONICS |
2002 MenuRunner::CONTEXT_MENU | 2036 MenuRunner::CONTEXT_MENU |
2003 MenuRunner::ASYNC)); 2037 MenuRunner::ASYNC));
2004 } 2038 }
2005 2039
2006 bool Textfield::ImeEditingAllowed() const { 2040 bool Textfield::ImeEditingAllowed() const {
2007 // Disallow input method editing of password fields. 2041 // Disallow input method editing of password fields.
2008 ui::TextInputType t = GetTextInputType(); 2042 ui::TextInputType t = GetTextInputType();
2009 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD); 2043 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
2057 } 2091 }
2058 2092
2059 void Textfield::OnCursorBlinkTimerFired() { 2093 void Textfield::OnCursorBlinkTimerFired() {
2060 DCHECK(ShouldBlinkCursor()); 2094 DCHECK(ShouldBlinkCursor());
2061 gfx::RenderText* render_text = GetRenderText(); 2095 gfx::RenderText* render_text = GetRenderText();
2062 render_text->set_cursor_visible(!render_text->cursor_visible()); 2096 render_text->set_cursor_visible(!render_text->cursor_visible());
2063 RepaintCursor(); 2097 RepaintCursor();
2064 } 2098 }
2065 2099
2066 } // namespace views 2100 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.h ('k') | ui/views/controls/textfield/textfield_test_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698