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

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: Addressed tapted's comments and made things work Created 4 years 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
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..164ae266dff6b35e04e8f8dc05b40563cdb39939 100644
--- a/ui/views/controls/textfield/textfield.cc
+++ b/ui/views/controls/textfield/textfield.cc
@@ -1082,6 +1082,13 @@ bool Textfield::GetDecoratedWordAtPoint(const gfx::Point& point,
baseline_point);
}
+bool Textfield::GetDecoratedTextFromSelection(
+ gfx::DecoratedText* decorated_text,
+ gfx::Point* baseline_point) {
+ return GetRenderText()->GetDecoratedTextForRange(
+ GetRenderText()->selection(), decorated_text, baseline_point);
+}
+
////////////////////////////////////////////////////////////////////////////////
// Textfield, SelectionControllerDelegate overrides:
@@ -1176,10 +1183,16 @@ void Textfield::DestroyTouchSelection() {
// Textfield, ui::SimpleMenuModel::Delegate overrides:
bool Textfield::IsCommandIdChecked(int command_id) const {
+ 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.
+ return text_services_context_menu_->IsCommandIdChecked(command_id);
+
return true;
}
bool Textfield::IsCommandIdEnabled(int command_id) const {
+ 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.
+ return text_services_context_menu_->IsCommandIdEnabled(command_id);
+
return Textfield::IsTextEditCommandEnabled(
GetTextEditCommandFromMenuCommand(command_id, HasSelection()));
}
@@ -1213,6 +1226,11 @@ bool Textfield::GetAcceleratorForCommandId(int command_id,
}
void Textfield::ExecuteCommand(int command_id, int event_flags) {
+ if (text_services_context_menu_->IsTextServicesCommandId(command_id)) {
+ text_services_context_menu_->ExecuteCommand(command_id, event_flags);
+ return;
+ }
+
Textfield::ExecuteTextEditCommand(
GetTextEditCommandFromMenuCommand(command_id, HasSelection()));
}
@@ -1976,7 +1994,9 @@ bool Textfield::Paste() {
}
void Textfield::UpdateContextMenu() {
- if (!context_menu_contents_.get()) {
+ if (!context_menu_contents_.get() ||
+ (text_services_context_menu_ &&
+ text_services_context_menu_->ShouldUpdateMenu())) {
context_menu_contents_.reset(new ui::SimpleMenuModel(this));
context_menu_contents_->AddItemWithStringId(IDS_APP_UNDO, IDS_APP_UNDO);
context_menu_contents_->AddSeparator(ui::NORMAL_SEPARATOR);
@@ -1992,11 +2012,20 @@ void Textfield::UpdateContextMenu() {
// IsCommandIdEnabled() as appropriate, for the commands added.
if (controller_)
controller_->UpdateContextMenu(context_menu_contents_.get());
+
+ ViewsTextServicesContextMenu* text_services_menu =
+ ViewsTextServicesContextMenu::Create(
+ this, this, context_menu_contents_.get(), this);
+ if (text_services_menu)
+ 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.
+ else
+ text_services_context_menu_.reset();
+
+ 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.
+ MenuRunner::HAS_MNEMONICS |
+ MenuRunner::CONTEXT_MENU |
+ MenuRunner::ASYNC));
}
- context_menu_runner_.reset(new MenuRunner(context_menu_contents_.get(),
- MenuRunner::HAS_MNEMONICS |
- MenuRunner::CONTEXT_MENU |
- MenuRunner::ASYNC));
}
bool Textfield::ImeEditingAllowed() const {

Powered by Google App Engine
This is Rietveld 408576698