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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/textfield/textfield.cc
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc
index 3a417b19029a1274367a2506e6d39bf139e9d010..529da588a21ad237992b8613527ce17c4e8406cb 100644
--- a/ui/views/controls/textfield/textfield.cc
+++ b/ui/views/controls/textfield/textfield.cc
@@ -42,6 +42,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"
@@ -1079,11 +1080,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);
}
////////////////////////////////////////////////////////////////////////////////
@@ -1180,10 +1189,20 @@ void Textfield::DestroyTouchSelection() {
// Textfield, ui::SimpleMenuModel::Delegate overrides:
bool Textfield::IsCommandIdChecked(int command_id) const {
+ if (text_services_context_menu_ &&
+ 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()));
}
@@ -1217,6 +1236,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()));
}
@@ -1935,6 +1960,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() {
@@ -1996,7 +2026,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 |
« 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