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

Unified Diff: chrome/browser/ui/views/tab_contents/render_view_context_menu_views.cc

Issue 83163002: [Aura] Adding Writing direction to the context menu for Aura. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed compilation on Win Created 7 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: chrome/browser/ui/views/tab_contents/render_view_context_menu_views.cc
diff --git a/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.cc b/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.cc
index 19294bacc477e2bc632e3947051c3a1a2cacb11b..2762b73a7ce0b3bdee035b2c488643bd54aff433 100644
--- a/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.cc
+++ b/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.cc
@@ -7,16 +7,19 @@
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
+#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "grit/generated_resources.h"
#include "ui/base/accelerators/accelerator.h"
+#include "ui/base/l10n/l10n_util.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/point.h"
#include "ui/views/controls/menu/menu_item_view.h"
#include "ui/views/controls/menu/menu_runner.h"
+
using content::WebContents;
////////////////////////////////////////////////////////////////////////////////
@@ -25,7 +28,8 @@ using content::WebContents;
RenderViewContextMenuViews::RenderViewContextMenuViews(
WebContents* web_contents,
const content::ContextMenuParams& params)
- : RenderViewContextMenu(web_contents, params) {
+ : RenderViewContextMenu(web_contents, params),
+ bidi_submenu_model_(this) {
}
RenderViewContextMenuViews::~RenderViewContextMenuViews() {
@@ -109,6 +113,83 @@ bool RenderViewContextMenuViews::GetAcceleratorForCommandId(
}
}
+void RenderViewContextMenuViews::ExecuteCommand(int command_id,
+ int event_flags) {
+ switch (command_id) {
+ case IDC_WRITING_DIRECTION_DEFAULT:
+ // WebKit's current behavior is for this menu item to always be disabled.
+ NOTREACHED();
+ break;
+
+ case IDC_WRITING_DIRECTION_RTL:
+ case IDC_WRITING_DIRECTION_LTR: {
+ content::RenderViewHost* view_host = GetRenderViewHost();
+ view_host->UpdateTextDirection((command_id == IDC_WRITING_DIRECTION_RTL) ?
+ blink::WebTextDirectionRightToLeft :
+ blink::WebTextDirectionLeftToRight);
+ view_host->NotifyTextDirection();
+ break;
+ }
+
+ default:
+ RenderViewContextMenu::ExecuteCommand(command_id, event_flags);
+ break;
+ }
+}
+
+bool RenderViewContextMenuViews::IsCommandIdChecked(int command_id) const {
+ switch (command_id) {
+ case IDC_WRITING_DIRECTION_DEFAULT:
+ return (params_.writing_direction_default &
+ blink::WebContextMenuData::CheckableMenuItemChecked) != 0;
+ case IDC_WRITING_DIRECTION_RTL:
+ return (params_.writing_direction_right_to_left &
+ blink::WebContextMenuData::CheckableMenuItemChecked) != 0;
+ case IDC_WRITING_DIRECTION_LTR:
+ return (params_.writing_direction_left_to_right &
+ blink::WebContextMenuData::CheckableMenuItemChecked) != 0;
+
+ default:
+ return RenderViewContextMenu::IsCommandIdChecked(command_id);
+ }
+}
+
+bool RenderViewContextMenuViews::IsCommandIdEnabled(int command_id) const {
+ switch (command_id) {
+ case IDC_WRITING_DIRECTION_MENU:
+ return true;
+ case IDC_WRITING_DIRECTION_DEFAULT: // Provided to match OS defaults.
+ return params_.writing_direction_default &
+ blink::WebContextMenuData::CheckableMenuItemEnabled;
+ case IDC_WRITING_DIRECTION_RTL:
+ return params_.writing_direction_right_to_left &
+ blink::WebContextMenuData::CheckableMenuItemEnabled;
+ case IDC_WRITING_DIRECTION_LTR:
+ return params_.writing_direction_left_to_right &
+ blink::WebContextMenuData::CheckableMenuItemEnabled;
+
+ default:
+ return RenderViewContextMenu::IsCommandIdEnabled(command_id);
+ }
+}
+
+void RenderViewContextMenuViews::AppendPlatformEditableItems() {
+ bidi_submenu_model_.AddCheckItem(
+ IDC_WRITING_DIRECTION_DEFAULT,
+ l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT));
+ bidi_submenu_model_.AddCheckItem(
+ IDC_WRITING_DIRECTION_LTR,
+ l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR));
+ bidi_submenu_model_.AddCheckItem(
+ IDC_WRITING_DIRECTION_RTL,
+ l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL));
+
+ menu_model_.AddSubMenu(
+ IDC_WRITING_DIRECTION_MENU,
+ l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_MENU),
+ &bidi_submenu_model_);
+}
+
void RenderViewContextMenuViews::UpdateMenuItem(int command_id,
bool enabled,
bool hidden,
« no previous file with comments | « chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h ('k') | content/common/view_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698