summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsanjoy.pal@samsung.com <sanjoy.pal@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-21 13:10:11 +0000
committersanjoy.pal@samsung.com <sanjoy.pal@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-21 13:10:11 +0000
commit40c2c91e0ae053925e2018465516fd24d259c990 (patch)
tree32589195e9d00e5d39ed090d98488f45362e4f1d
parent3f43f4dfdf6232235863feb5c70bab10304dbb86 (diff)
downloadchromium_src-40c2c91e0ae053925e2018465516fd24d259c990.zip
chromium_src-40c2c91e0ae053925e2018465516fd24d259c990.tar.gz
chromium_src-40c2c91e0ae053925e2018465516fd24d259c990.tar.bz2
Adding Writing direction to the context menu for linux gtk.
Blink side change is here https://codereview.chromium.org/66313007/ This CL takes care of the context menu on Linux Gtk. Most of the changes are copied from Writing direction context menu entry implementation on MacOSX. There seems to be no way to change writing direction on Aura. I would like create a separate CL to implement the same on Aura. BUG=91178 TBR=cpu@chromium.org Review URL: https://codereview.chromium.org/73963004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236515 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/chrome_command_ids.h8
-rw-r--r--chrome/app/generated_resources.grd2
-rw-r--r--chrome/browser/ui/gtk/tab_contents/render_view_context_menu_gtk.cc85
-rw-r--r--chrome/browser/ui/gtk/tab_contents/render_view_context_menu_gtk.h12
-rw-r--r--content/common/view_messages.h4
-rw-r--r--content/public/common/context_menu_params.cc4
-rw-r--r--content/public/common/context_menu_params.h6
-rw-r--r--content/renderer/context_menu_params_builder.cc4
8 files changed, 110 insertions, 15 deletions
diff --git a/chrome/app/chrome_command_ids.h b/chrome/app/chrome_command_ids.h
index 1e93ca5b..eaf70f2 100644
--- a/chrome/app/chrome_command_ids.h
+++ b/chrome/app/chrome_command_ids.h
@@ -228,10 +228,10 @@
#define IDC_SPELLCHECK_ADD_TO_DICTIONARY 41110
// Writing direction
-#define IDC_WRITING_DIRECTION_MENU 41120 // OSX only
-#define IDC_WRITING_DIRECTION_DEFAULT 41121 // OSX only
-#define IDC_WRITING_DIRECTION_LTR 41122 // OSX only
-#define IDC_WRITING_DIRECTION_RTL 41123 // OSX only
+#define IDC_WRITING_DIRECTION_MENU 41120 // OSX and Linux Gtk only
+#define IDC_WRITING_DIRECTION_DEFAULT 41121 // OSX and Linux Gtk only
+#define IDC_WRITING_DIRECTION_LTR 41122 // OSX and Linux Gtk only
+#define IDC_WRITING_DIRECTION_RTL 41123 // OSX and Linux Gtk only
// Translate
#define IDC_TRANSLATE_OPTIONS_ALWAYS 42000
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index fb5fad5..c9c7a73 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -592,7 +592,7 @@ Psst! Incognito mode <ph name="SHORTCUT_KEY">$1<ex>(Ctrl+Shift+N)</ex></ph> may
</message>
<!-- content area context menus -->
- <if expr="is_macosx">
+ <if expr="is_macosx or is_linux">
<message name="IDS_CONTENT_CONTEXT_WRITING_DIRECTION_MENU" desc="The name of the Writing Direction submenu in the content area context menu. To translate, launch /Applications/TextEdit.app in an appropriately localized version of OS X, right-click on the text entry area and use the translation from there.">
Writing Direction
</message>
diff --git a/chrome/browser/ui/gtk/tab_contents/render_view_context_menu_gtk.cc b/chrome/browser/ui/gtk/tab_contents/render_view_context_menu_gtk.cc
index ebe7585..d7744b2 100644
--- a/chrome/browser/ui/gtk/tab_contents/render_view_context_menu_gtk.cc
+++ b/chrome/browser/ui/gtk/tab_contents/render_view_context_menu_gtk.cc
@@ -10,6 +10,7 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/ui/gtk/gtk_util.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/common/context_menu_params.h"
@@ -77,7 +78,8 @@ RenderViewContextMenuGtk::RenderViewContextMenuGtk(
WebContents* web_contents,
const content::ContextMenuParams& params,
content::RenderWidgetHostView* view)
- : RenderViewContextMenu(web_contents, params) {
+ : RenderViewContextMenu(web_contents, params),
+ bidi_submenu_model_(this) {
GdkEventButton* event = view->GetLastMouseDown();
triggering_event_time_ = event ? event->time : GDK_CURRENT_TIME;
}
@@ -139,6 +141,87 @@ bool RenderViewContextMenuGtk::AlwaysShowIconForCmd(int command_id) const {
command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST;
}
+void RenderViewContextMenuGtk::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();
+ blink::WebTextDirection dir = blink::WebTextDirectionLeftToRight;
+ if (command_id == IDC_WRITING_DIRECTION_RTL)
+ dir = blink::WebTextDirectionRightToLeft;
+ view_host->UpdateTextDirection(dir);
+ view_host->NotifyTextDirection();
+ break;
+ }
+
+ default:
+ RenderViewContextMenu::ExecuteCommand(command_id, event_flags);
+ break;
+ }
+}
+
+bool RenderViewContextMenuGtk::IsCommandIdChecked(int command_id) const {
+ switch (command_id) {
+ case IDC_WRITING_DIRECTION_DEFAULT:
+ return params_.writing_direction_default &
+ blink::WebContextMenuData::CheckableMenuItemChecked;
+ case IDC_WRITING_DIRECTION_RTL:
+ return params_.writing_direction_right_to_left &
+ blink::WebContextMenuData::CheckableMenuItemChecked;
+ case IDC_WRITING_DIRECTION_LTR:
+ return params_.writing_direction_left_to_right &
+ blink::WebContextMenuData::CheckableMenuItemChecked;
+
+ default:
+ return RenderViewContextMenu::IsCommandIdChecked(command_id);
+ }
+}
+
+bool RenderViewContextMenuGtk::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 RenderViewContextMenuGtk::AppendPlatformEditableItems() {
+ // OS X and Linux provide a contextual menu to set writing direction for BiDi
+ // languages.
+ // This functionality is exposed as a keyboard shortcut on Windows.
+ AppendBidiSubMenu();
+}
+
+void RenderViewContextMenuGtk::AppendBidiSubMenu() {
+ 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 RenderViewContextMenuGtk::UpdateMenuItem(int command_id,
bool enabled,
bool hidden,
diff --git a/chrome/browser/ui/gtk/tab_contents/render_view_context_menu_gtk.h b/chrome/browser/ui/gtk/tab_contents/render_view_context_menu_gtk.h
index aeb8689..22f065b 100644
--- a/chrome/browser/ui/gtk/tab_contents/render_view_context_menu_gtk.h
+++ b/chrome/browser/ui/gtk/tab_contents/render_view_context_menu_gtk.h
@@ -31,6 +31,11 @@ class RenderViewContextMenuGtk : public RenderViewContextMenu,
// Menu::Delegate implementation ---------------------------------------------
virtual bool AlwaysShowIconForCmd(int command_id) const OVERRIDE;
+ // SimpleMenuModel::Delegate implementation.
+ virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
+ virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
+ virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
+
// RenderViewContextMenuDelegate implementation ------------------------------
virtual void UpdateMenuItem(int command_id,
bool enabled,
@@ -45,8 +50,15 @@ class RenderViewContextMenuGtk : public RenderViewContextMenu,
virtual bool GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) OVERRIDE;
+ virtual void AppendPlatformEditableItems() OVERRIDE;
private:
+ // Adds writing direction submenu.
+ void AppendBidiSubMenu();
+
+ // Model for the BiDi input submenu.
+ ui::SimpleMenuModel bidi_submenu_model_;
+
scoped_ptr<MenuGtk> menu_gtk_;
uint32_t triggering_event_time_;
};
diff --git a/content/common/view_messages.h b/content/common/view_messages.h
index df630d3..e85ae75 100644
--- a/content/common/view_messages.h
+++ b/content/common/view_messages.h
@@ -180,11 +180,11 @@ IPC_STRUCT_TRAITS_BEGIN(content::ContextMenuParams)
IPC_STRUCT_TRAITS_MEMBER(speech_input_enabled)
IPC_STRUCT_TRAITS_MEMBER(spellcheck_enabled)
IPC_STRUCT_TRAITS_MEMBER(is_editable)
-#if defined(OS_MACOSX)
+#if defined(OS_MACOSX) || defined(TOOLKIT_GTK)
IPC_STRUCT_TRAITS_MEMBER(writing_direction_default)
IPC_STRUCT_TRAITS_MEMBER(writing_direction_left_to_right)
IPC_STRUCT_TRAITS_MEMBER(writing_direction_right_to_left)
-#endif // OS_MACOSX
+#endif // OS_MACOSX || defined(TOOLKIT_GTK)
IPC_STRUCT_TRAITS_MEMBER(edit_flags)
IPC_STRUCT_TRAITS_MEMBER(security_info)
IPC_STRUCT_TRAITS_MEMBER(frame_charset)
diff --git a/content/public/common/context_menu_params.cc b/content/public/common/context_menu_params.cc
index 4a5f485..a267fb2 100644
--- a/content/public/common/context_menu_params.cc
+++ b/content/public/common/context_menu_params.cc
@@ -25,14 +25,14 @@ ContextMenuParams::ContextMenuParams()
speech_input_enabled(false),
spellcheck_enabled(false),
is_editable(false),
-#if defined(OS_MACOSX)
+#if defined(OS_MACOSX) || defined(TOOLKIT_GTK)
writing_direction_default(
blink::WebContextMenuData::CheckableMenuItemDisabled),
writing_direction_left_to_right(
blink::WebContextMenuData::CheckableMenuItemEnabled),
writing_direction_right_to_left(
blink::WebContextMenuData::CheckableMenuItemEnabled),
-#endif // OS_MACOSX
+#endif // OS_MACOSX || defined(TOOLKIT_GTK)
edit_flags(0),
referrer_policy(blink::WebReferrerPolicyDefault) {
}
diff --git a/content/public/common/context_menu_params.h b/content/public/common/context_menu_params.h
index a64dd95..49bd74f 100644
--- a/content/public/common/context_menu_params.h
+++ b/content/public/common/context_menu_params.h
@@ -124,13 +124,13 @@ struct CONTENT_EXPORT ContextMenuParams {
// Whether context is editable.
bool is_editable;
-#if defined(OS_MACOSX)
+#if defined(OS_MACOSX) || defined(TOOLKIT_GTK)
// Writing direction menu items.
- // Currently only used on OS X.
+ // Currently only used on OS X and Linux.
int writing_direction_default;
int writing_direction_left_to_right;
int writing_direction_right_to_left;
-#endif // OS_MACOSX
+#endif // OS_MACOSX || defined(TOOLKIT_GTK)
// These flags indicate to the browser whether the renderer believes it is
// able to perform the corresponding action.
diff --git a/content/renderer/context_menu_params_builder.cc b/content/renderer/context_menu_params_builder.cc
index f864459..a7783d0 100644
--- a/content/renderer/context_menu_params_builder.cc
+++ b/content/renderer/context_menu_params_builder.cc
@@ -35,11 +35,11 @@ ContextMenuParams ContextMenuParamsBuilder::Build(
params.speech_input_enabled = data.isSpeechInputEnabled;
params.spellcheck_enabled = data.isSpellCheckingEnabled;
params.is_editable = data.isEditable;
-#if defined(OS_MACOSX)
+#if defined(OS_MACOSX) || defined(TOOLKIT_GTK)
params.writing_direction_default = data.writingDirectionDefault;
params.writing_direction_left_to_right = data.writingDirectionLeftToRight;
params.writing_direction_right_to_left = data.writingDirectionRightToLeft;
-#endif // OS_MACOSX
+#endif // OS_MACOSX || defined(TOOLKIT_GTK)
params.edit_flags = data.editFlags;
params.frame_charset = data.frameEncoding.utf8();
params.referrer_policy = data.referrerPolicy;