Chromium Code Reviews| Index: ui/views/controls/textfield/textfield.cc |
| diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc |
| index 2bb3e822ca82468a0d386dc9980f1f4b756353e6..b1d4ad1acc4aeafc6a659185a5778a8067337c16 100644 |
| --- a/ui/views/controls/textfield/textfield.cc |
| +++ b/ui/views/controls/textfield/textfield.cc |
| @@ -41,6 +41,7 @@ |
| #include "ui/views/controls/menu/menu_runner.h" |
| #include "ui/views/controls/native/native_view_host.h" |
| #include "ui/views/controls/textfield/textfield_controller.h" |
| +#include "ui/views/controls/views_text_services_context_menu.h" |
| #include "ui/views/drag_utils.h" |
| #include "ui/views/native_cursor.h" |
| #include "ui/views/painter.h" |
| @@ -1075,11 +1076,19 @@ bool Textfield::CanStartDragForView(View* sender, |
| //////////////////////////////////////////////////////////////////////////////// |
| // Textfield, WordLookupClient overrides: |
| -bool Textfield::GetDecoratedWordAtPoint(const gfx::Point& point, |
| - gfx::DecoratedText* decorated_word, |
| - gfx::Point* baseline_point) { |
| - return GetRenderText()->GetDecoratedWordAtPoint(point, decorated_word, |
| - baseline_point); |
| +bool Textfield::GetDecoratedWordAndBaselineAtPoint( |
| + const gfx::Point& point, |
| + gfx::DecoratedText* decorated_word, |
| + gfx::Point* baseline_point) { |
| + return GetRenderText()->GetDecoratedWordAndBaselineAtPoint( |
| + point, decorated_word, baseline_point); |
| +} |
| + |
| +bool Textfield::GetDecoratedTextAndBaselineFromSelection( |
| + gfx::DecoratedText* decorated_text, |
| + gfx::Point* baseline_point) { |
| + return GetRenderText()->GetDecoratedTextAndBaselineForRange( |
| + GetRenderText()->selection(), decorated_text, baseline_point); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -1176,10 +1185,20 @@ void Textfield::DestroyTouchSelection() { |
| // Textfield, ui::SimpleMenuModel::Delegate overrides: |
| bool Textfield::IsCommandIdChecked(int command_id) const { |
| + 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
|
| + text_services_context_menu_->HandlesCommandId(command_id)) { |
| + return text_services_context_menu_->IsCommandIdChecked(command_id); |
| + } |
| + |
| return true; |
| } |
| bool Textfield::IsCommandIdEnabled(int command_id) const { |
| + if (text_services_context_menu_ && |
| + text_services_context_menu_->HandlesCommandId(command_id)) { |
| + return text_services_context_menu_->IsCommandIdEnabled(command_id); |
| + } |
| + |
| return Textfield::IsTextEditCommandEnabled( |
| GetTextEditCommandFromMenuCommand(command_id, HasSelection())); |
| } |
| @@ -1213,6 +1232,12 @@ bool Textfield::GetAcceleratorForCommandId(int command_id, |
| } |
| void Textfield::ExecuteCommand(int command_id, int event_flags) { |
| + if (text_services_context_menu_ && |
| + text_services_context_menu_->HandlesCommandId(command_id)) { |
| + text_services_context_menu_->ExecuteCommand(command_id, event_flags); |
| + return; |
| + } |
| + |
| Textfield::ExecuteTextEditCommand( |
| GetTextEditCommandFromMenuCommand(command_id, HasSelection())); |
| } |
| @@ -1931,6 +1956,11 @@ void Textfield::OnCaretBoundsChanged() { |
| GetInputMethod()->OnCaretBoundsChanged(this); |
| if (touch_selection_controller_) |
| touch_selection_controller_->SelectionChanged(); |
| + |
| + // On Mac, the context menu contains a look up item which displays the |
| + // selected text. As such, the menu needs to be updated if the selection has |
| + // changed. |
| + context_menu_contents_.reset(); |
| } |
| void Textfield::OnBeforeUserAction() { |
| @@ -1992,7 +2022,11 @@ void Textfield::UpdateContextMenu() { |
| // IsCommandIdEnabled() as appropriate, for the commands added. |
| if (controller_) |
| controller_->UpdateContextMenu(context_menu_contents_.get()); |
| + |
| + text_services_context_menu_ = ViewsTextServicesContextMenu::Create( |
| + context_menu_contents_.get(), this); |
| } |
| + |
| context_menu_runner_.reset(new MenuRunner(context_menu_contents_.get(), |
| MenuRunner::HAS_MNEMONICS | |
| MenuRunner::CONTEXT_MENU | |