summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-05 11:51:27 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-05 11:51:27 +0000
commit6c8493c5bf17929c6cd6815e8dc80c5038cbbd29 (patch)
treead69c84e7332b9b51fa72cf8a53bcfea4795924a
parentdee5464259bc255197d56b250f66ee80b380c2c5 (diff)
downloadchromium_src-6c8493c5bf17929c6cd6815e8dc80c5038cbbd29.zip
chromium_src-6c8493c5bf17929c6cd6815e8dc80c5038cbbd29.tar.gz
chromium_src-6c8493c5bf17929c6cd6815e8dc80c5038cbbd29.tar.bz2
WebKit side is in https://bugs.webkit.org/show_bug.cgi?id=34524
BUG=NONE TEST=Right clicking on a text input field in Web content on OS X should now show a Writing Direction submenu. Clicking on "Left To Right" should align the input to the left, and "Right To Left" should do the opposit. The "Default" menu item should always be disabled. Review URL: http://codereview.chromium.org/566031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38204 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/chrome_dll_resource.h6
-rw-r--r--chrome/app/generated_resources.grd14
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc63
-rw-r--r--chrome/common/render_messages.h10
-rw-r--r--webkit/glue/context_menu.h13
5 files changed, 105 insertions, 1 deletions
diff --git a/chrome/app/chrome_dll_resource.h b/chrome/app/chrome_dll_resource.h
index 423c053..c73243c 100644
--- a/chrome/app/chrome_dll_resource.h
+++ b/chrome/app/chrome_dll_resource.h
@@ -230,6 +230,12 @@
#define IDC_SYNC_BOOKMARKS 41108
#define IDC_SPELLPANEL_TOGGLE 41109
+// 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
+
// Translate
#define IDC_TRANSLATE_OPTIONS_ALWAYS 42000
#define IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG 42001
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index dc37001..79922a5 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -320,6 +320,20 @@ each locale. -->
</message>
<!-- content area context menus -->
+ <if expr="os == 'darwin'">
+ <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>
+ <message name="IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT" desc="The name of the 'default' item from 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.">
+ Default
+ </message>
+ <message name="IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR" desc="The name of the 'Left to Right' item from 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.">
+ Left to Right
+ </message>
+ <message name="IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL" desc="The name of the 'Right to Left' item from 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.">
+ Right to Left
+ </message>
+ </if>
<if expr="not pp_ifdef('use_titlecase')">
<message name="IDS_CONTENT_CONTEXT_BACK" desc="The name of the Back command in the content area context menu">
&amp;Back
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index 039b245..a9cc073 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -34,8 +34,9 @@
#include "net/base/escape.h"
#include "net/url_request/url_request.h"
#include "webkit/glue/webmenuitem.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayerAction.h"
#include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayerAction.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h"
using WebKit::WebContextMenuData;
using WebKit::WebMediaPlayerAction;
@@ -337,6 +338,25 @@ void RenderViewContextMenu::AppendEditableItems() {
}
FinishSubMenu();
+#if defined(OS_MACOSX)
+ // OS X provides a contextual menu to set writing direction for BiDi
+ // languages.
+ // This functionality is exposed as a keyboard shortcut on Windows & Linux.
+
+ // Add writing direction sub menu.
+ StartSubMenu(IDC_WRITING_DIRECTION_MENU,
+ l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_MENU));
+
+ AppendCheckboxMenuItem(IDC_WRITING_DIRECTION_DEFAULT,
+ l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT));
+ AppendCheckboxMenuItem(IDC_WRITING_DIRECTION_LTR,
+ l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR));
+ AppendCheckboxMenuItem(IDC_WRITING_DIRECTION_RTL,
+ l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL));
+
+ FinishSubMenu();
+#endif // OS_MACOSX
+
AppendSeparator();
AppendMenuItem(IDS_CONTENT_CONTEXT_SELECTALL);
}
@@ -512,6 +532,18 @@ bool RenderViewContextMenu::IsItemCommandEnabled(int id) const {
case IDC_CHECK_SPELLING_OF_THIS_FIELD:
return profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck);
+#if defined(OS_MACOSX)
+ case IDC_WRITING_DIRECTION_DEFAULT: // Provided to match OS defaults.
+ return params_.writing_direction_default &
+ WebContextMenuData::CheckableMenuItemEnabled;
+ case IDC_WRITING_DIRECTION_RTL:
+ return params_.writing_direction_right_to_left &
+ WebContextMenuData::CheckableMenuItemEnabled;
+ case IDC_WRITING_DIRECTION_LTR:
+ return params_.writing_direction_left_to_right &
+ WebContextMenuData::CheckableMenuItemEnabled;
+#endif // OS_MACOSX
+
#if defined(OS_LINUX)
// Enable the input methods context menu if the content is editable.
// TODO(suzhe): It should not be enabled in password boxes. Anyway,
@@ -535,6 +567,18 @@ bool RenderViewContextMenu::ItemIsChecked(int id) const {
WebContextMenuData::MediaLoop) != 0;
}
+#if defined(OS_MACOSX)
+ if (id == IDC_WRITING_DIRECTION_DEFAULT)
+ return params_.writing_direction_default &
+ WebContextMenuData::CheckableMenuItemChecked;
+ if (id == IDC_WRITING_DIRECTION_RTL)
+ return params_.writing_direction_right_to_left &
+ WebContextMenuData::CheckableMenuItemChecked;
+ if (id == IDC_WRITING_DIRECTION_LTR)
+ return params_.writing_direction_left_to_right &
+ WebContextMenuData::CheckableMenuItemChecked;
+#endif // OS_MACOSX
+
// Check box for 'Check the Spelling of this field'.
if (id == IDC_CHECK_SPELLING_OF_THIS_FIELD) {
return (params_.spellcheck_enabled &&
@@ -816,6 +860,23 @@ void RenderViewContextMenu::ExecuteItemCommand(int id) {
source_tab_contents_->render_view_host()->ToggleSpellPanel(
SpellCheckerPlatform::SpellingPanelVisible());
break;
+
+#if defined(OS_MACOSX)
+ 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: {
+ WebKit::WebTextDirection dir = WebKit::WebTextDirectionLeftToRight;
+ if (id == IDC_WRITING_DIRECTION_RTL)
+ dir = WebKit::WebTextDirectionRightToLeft;
+ source_tab_contents_->render_view_host()->UpdateTextDirection(dir);
+ source_tab_contents_->render_view_host()->NotifyTextDirection();
+ break;
+ }
+#endif // OS_MACOSX
+
case IDS_CONTENT_CONTEXT_ADDSEARCHENGINE: // Not implemented.
default:
break;
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index 21bb359..d985d2d 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -1034,6 +1034,11 @@ struct ParamTraits<ContextMenuParams> {
WriteParam(m, p.dictionary_suggestions);
WriteParam(m, p.spellcheck_enabled);
WriteParam(m, p.is_editable);
+#if defined(OS_MACOSX)
+ WriteParam(m, p.writing_direction_default);
+ WriteParam(m, p.writing_direction_left_to_right);
+ WriteParam(m, p.writing_direction_right_to_left);
+#endif // OS_MACOSX
WriteParam(m, p.edit_flags);
WriteParam(m, p.security_info);
WriteParam(m, p.frame_charset);
@@ -1055,6 +1060,11 @@ struct ParamTraits<ContextMenuParams> {
ReadParam(m, iter, &p->dictionary_suggestions) &&
ReadParam(m, iter, &p->spellcheck_enabled) &&
ReadParam(m, iter, &p->is_editable) &&
+#if defined(OS_MACOSX)
+ ReadParam(m, iter, &p->writing_direction_default) &&
+ ReadParam(m, iter, &p->writing_direction_left_to_right) &&
+ ReadParam(m, iter, &p->writing_direction_right_to_left) &&
+#endif // OS_MACOSX
ReadParam(m, iter, &p->edit_flags) &&
ReadParam(m, iter, &p->security_info) &&
ReadParam(m, iter, &p->frame_charset) &&
diff --git a/webkit/glue/context_menu.h b/webkit/glue/context_menu.h
index b1744df..beced3f 100644
--- a/webkit/glue/context_menu.h
+++ b/webkit/glue/context_menu.h
@@ -73,6 +73,14 @@ struct ContextMenuParams {
// Whether context is editable.
bool is_editable;
+#if defined(OS_MACOSX)
+ // Writing direction menu items.
+ // Currently only used on OS X.
+ int writing_direction_default;
+ int writing_direction_left_to_right;
+ int writing_direction_right_to_left;
+#endif // OS_MACOSX
+
// These flags indicate to the browser whether the renderer believes it is
// able to perform the corresponding action.
int edit_flags;
@@ -101,6 +109,11 @@ struct ContextMenuParams {
misspelled_word(data.misspelledWord),
spellcheck_enabled(data.isSpellCheckingEnabled),
is_editable(data.isEditable),
+#if defined(OS_MACOSX)
+ writing_direction_default(data.writingDirectionDefault),
+ writing_direction_left_to_right(data.writingDirectionLeftToRight),
+ writing_direction_right_to_left(data.writingDirectionRightToLeft),
+#endif // OS_MACOSX
edit_flags(data.editFlags),
security_info(data.securityInfo),
frame_charset(data.frameEncoding.utf8()) {