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

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: Fix for tapted 3 Created 3 years, 12 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/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 23 matching lines...) Expand all
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 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 1069
1069 bool Textfield::CanStartDragForView(View* sender, 1070 bool Textfield::CanStartDragForView(View* sender,
1070 const gfx::Point& press_pt, 1071 const gfx::Point& press_pt,
1071 const gfx::Point& p) { 1072 const gfx::Point& p) {
1072 return initiating_drag_ && GetRenderText()->IsPointInSelection(press_pt); 1073 return initiating_drag_ && GetRenderText()->IsPointInSelection(press_pt);
1073 } 1074 }
1074 1075
1075 //////////////////////////////////////////////////////////////////////////////// 1076 ////////////////////////////////////////////////////////////////////////////////
1076 // Textfield, WordLookupClient overrides: 1077 // Textfield, WordLookupClient overrides:
1077 1078
1078 bool Textfield::GetDecoratedWordAtPoint(const gfx::Point& point, 1079 bool Textfield::GetDecoratedWordAndBaselineAtPoint(
1079 gfx::DecoratedText* decorated_word, 1080 const gfx::Point& point,
1080 gfx::Point* baseline_point) { 1081 gfx::DecoratedText* decorated_word,
1081 return GetRenderText()->GetDecoratedWordAtPoint(point, decorated_word, 1082 gfx::Point* baseline_point) {
1082 baseline_point); 1083 return GetRenderText()->GetDecoratedWordAndBaselineAtPoint(
1084 point, decorated_word, baseline_point);
1085 }
1086
1087 bool Textfield::GetDecoratedTextAndBaselineFromSelection(
1088 gfx::DecoratedText* decorated_text,
1089 gfx::Point* baseline_point) {
1090 return GetRenderText()->GetDecoratedTextAndBaselineForRange(
1091 GetRenderText()->selection(), decorated_text, baseline_point);
1083 } 1092 }
1084 1093
1085 //////////////////////////////////////////////////////////////////////////////// 1094 ////////////////////////////////////////////////////////////////////////////////
1086 // Textfield, SelectionControllerDelegate overrides: 1095 // Textfield, SelectionControllerDelegate overrides:
1087 1096
1088 bool Textfield::HasTextBeingDragged() const { 1097 bool Textfield::HasTextBeingDragged() const {
1089 return initiating_drag_; 1098 return initiating_drag_;
1090 } 1099 }
1091 1100
1092 //////////////////////////////////////////////////////////////////////////////// 1101 ////////////////////////////////////////////////////////////////////////////////
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 } 1178 }
1170 1179
1171 void Textfield::DestroyTouchSelection() { 1180 void Textfield::DestroyTouchSelection() {
1172 touch_selection_controller_.reset(); 1181 touch_selection_controller_.reset();
1173 } 1182 }
1174 1183
1175 //////////////////////////////////////////////////////////////////////////////// 1184 ////////////////////////////////////////////////////////////////////////////////
1176 // Textfield, ui::SimpleMenuModel::Delegate overrides: 1185 // Textfield, ui::SimpleMenuModel::Delegate overrides:
1177 1186
1178 bool Textfield::IsCommandIdChecked(int command_id) const { 1187 bool Textfield::IsCommandIdChecked(int command_id) const {
1188 if (text_services_context_menu_ &&
tapted 2016/12/21 11:20:27 These changes might no longer be needed
spqchan 2016/12/21 22:00:13 This is needed since ViewsTextServicesContextMenu
1189 text_services_context_menu_->HandlesCommandId(command_id)) {
1190 return text_services_context_menu_->IsCommandIdChecked(command_id);
1191 }
1192
1179 return true; 1193 return true;
1180 } 1194 }
1181 1195
1182 bool Textfield::IsCommandIdEnabled(int command_id) const { 1196 bool Textfield::IsCommandIdEnabled(int command_id) const {
1197 if (text_services_context_menu_ &&
1198 text_services_context_menu_->HandlesCommandId(command_id)) {
1199 return text_services_context_menu_->IsCommandIdEnabled(command_id);
1200 }
1201
1183 return Textfield::IsTextEditCommandEnabled( 1202 return Textfield::IsTextEditCommandEnabled(
1184 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); 1203 GetTextEditCommandFromMenuCommand(command_id, HasSelection()));
1185 } 1204 }
1186 1205
1187 bool Textfield::GetAcceleratorForCommandId(int command_id, 1206 bool Textfield::GetAcceleratorForCommandId(int command_id,
1188 ui::Accelerator* accelerator) const { 1207 ui::Accelerator* accelerator) const {
1189 switch (command_id) { 1208 switch (command_id) {
1190 case IDS_APP_UNDO: 1209 case IDS_APP_UNDO:
1191 *accelerator = ui::Accelerator(ui::VKEY_Z, kPlatformModifier); 1210 *accelerator = ui::Accelerator(ui::VKEY_Z, kPlatformModifier);
1192 return true; 1211 return true;
(...skipping 13 matching lines...) Expand all
1206 case IDS_APP_SELECT_ALL: 1225 case IDS_APP_SELECT_ALL:
1207 *accelerator = ui::Accelerator(ui::VKEY_A, kPlatformModifier); 1226 *accelerator = ui::Accelerator(ui::VKEY_A, kPlatformModifier);
1208 return true; 1227 return true;
1209 1228
1210 default: 1229 default:
1211 return false; 1230 return false;
1212 } 1231 }
1213 } 1232 }
1214 1233
1215 void Textfield::ExecuteCommand(int command_id, int event_flags) { 1234 void Textfield::ExecuteCommand(int command_id, int event_flags) {
1235 if (text_services_context_menu_ &&
1236 text_services_context_menu_->HandlesCommandId(command_id)) {
1237 text_services_context_menu_->ExecuteCommand(command_id, event_flags);
1238 return;
1239 }
1240
1216 Textfield::ExecuteTextEditCommand( 1241 Textfield::ExecuteTextEditCommand(
1217 GetTextEditCommandFromMenuCommand(command_id, HasSelection())); 1242 GetTextEditCommandFromMenuCommand(command_id, HasSelection()));
1218 } 1243 }
1219 1244
1220 //////////////////////////////////////////////////////////////////////////////// 1245 ////////////////////////////////////////////////////////////////////////////////
1221 // Textfield, ui::TextInputClient overrides: 1246 // Textfield, ui::TextInputClient overrides:
1222 1247
1223 void Textfield::SetCompositionText(const ui::CompositionText& composition) { 1248 void Textfield::SetCompositionText(const ui::CompositionText& composition) {
1224 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) 1249 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE)
1225 return; 1250 return;
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 void Textfield::MoveCursorTo(const gfx::Point& point, bool select) { 1949 void Textfield::MoveCursorTo(const gfx::Point& point, bool select) {
1925 if (model_->MoveCursorTo(point, select)) 1950 if (model_->MoveCursorTo(point, select))
1926 UpdateAfterChange(false, true); 1951 UpdateAfterChange(false, true);
1927 } 1952 }
1928 1953
1929 void Textfield::OnCaretBoundsChanged() { 1954 void Textfield::OnCaretBoundsChanged() {
1930 if (GetInputMethod()) 1955 if (GetInputMethod())
1931 GetInputMethod()->OnCaretBoundsChanged(this); 1956 GetInputMethod()->OnCaretBoundsChanged(this);
1932 if (touch_selection_controller_) 1957 if (touch_selection_controller_)
1933 touch_selection_controller_->SelectionChanged(); 1958 touch_selection_controller_->SelectionChanged();
1959
1960 // On Mac, the context menu contains a look up item which displays the
1961 // selected text. As such, the menu needs to be updated if the selection has
1962 // changed.
1963 context_menu_contents_.reset();
1934 } 1964 }
1935 1965
1936 void Textfield::OnBeforeUserAction() { 1966 void Textfield::OnBeforeUserAction() {
1937 DCHECK(!performing_user_action_); 1967 DCHECK(!performing_user_action_);
1938 performing_user_action_ = true; 1968 performing_user_action_ = true;
1939 if (controller_) 1969 if (controller_)
1940 controller_->OnBeforeUserAction(this); 1970 controller_->OnBeforeUserAction(this);
1941 } 1971 }
1942 1972
1943 void Textfield::OnAfterUserAction() { 1973 void Textfield::OnAfterUserAction() {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1985 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); 2015 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE);
1986 context_menu_contents_->AddItemWithStringId(IDS_APP_DELETE, IDS_APP_DELETE); 2016 context_menu_contents_->AddItemWithStringId(IDS_APP_DELETE, IDS_APP_DELETE);
1987 context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR); 2017 context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR);
1988 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL, 2018 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL,
1989 IDS_APP_SELECT_ALL); 2019 IDS_APP_SELECT_ALL);
1990 2020
1991 // If the controller adds menu commands, also override ExecuteCommand() and 2021 // If the controller adds menu commands, also override ExecuteCommand() and
1992 // IsCommandIdEnabled() as appropriate, for the commands added. 2022 // IsCommandIdEnabled() as appropriate, for the commands added.
1993 if (controller_) 2023 if (controller_)
1994 controller_->UpdateContextMenu(context_menu_contents_.get()); 2024 controller_->UpdateContextMenu(context_menu_contents_.get());
2025
2026 text_services_context_menu_ = ViewsTextServicesContextMenu::Create(
2027 context_menu_contents_.get(), this);
1995 } 2028 }
2029
1996 context_menu_runner_.reset(new MenuRunner(context_menu_contents_.get(), 2030 context_menu_runner_.reset(new MenuRunner(context_menu_contents_.get(),
1997 MenuRunner::HAS_MNEMONICS | 2031 MenuRunner::HAS_MNEMONICS |
1998 MenuRunner::CONTEXT_MENU | 2032 MenuRunner::CONTEXT_MENU |
1999 MenuRunner::ASYNC)); 2033 MenuRunner::ASYNC));
2000 } 2034 }
2001 2035
2002 bool Textfield::ImeEditingAllowed() const { 2036 bool Textfield::ImeEditingAllowed() const {
2003 // Disallow input method editing of password fields. 2037 // Disallow input method editing of password fields.
2004 ui::TextInputType t = GetTextInputType(); 2038 ui::TextInputType t = GetTextInputType();
2005 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD); 2039 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
2053 } 2087 }
2054 2088
2055 void Textfield::OnCursorBlinkTimerFired() { 2089 void Textfield::OnCursorBlinkTimerFired() {
2056 DCHECK(ShouldBlinkCursor()); 2090 DCHECK(ShouldBlinkCursor());
2057 gfx::RenderText* render_text = GetRenderText(); 2091 gfx::RenderText* render_text = GetRenderText();
2058 render_text->set_cursor_visible(!render_text->cursor_visible()); 2092 render_text->set_cursor_visible(!render_text->cursor_visible());
2059 RepaintCursor(); 2093 RepaintCursor();
2060 } 2094 }
2061 2095
2062 } // namespace views 2096 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698