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

Side by Side 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: Created 7 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h" 5 #include "chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "content/public/browser/render_widget_host_view.h" 10 #include "content/public/browser/render_widget_host_view.h"
11 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/web_contents_view.h" 12 #include "content/public/browser/web_contents_view.h"
13 #include "grit/generated_resources.h" 13 #include "grit/generated_resources.h"
14 #include "ui/base/accelerators/accelerator.h" 14 #include "ui/base/accelerators/accelerator.h"
15 #include "ui/events/keycodes/keyboard_codes.h" 15 #include "ui/events/keycodes/keyboard_codes.h"
16 #include "ui/gfx/point.h" 16 #include "ui/gfx/point.h"
17 #include "ui/views/controls/menu/menu_item_view.h" 17 #include "ui/views/controls/menu/menu_item_view.h"
18 #include "ui/views/controls/menu/menu_runner.h" 18 #include "ui/views/controls/menu/menu_runner.h"
19 19
20 #if !defined(OS_WIN)
21 #include "content/public/browser/render_view_host.h"
22 #include "ui/base/l10n/l10n_util.h"
23 #endif // !OS_WIN
24
20 using content::WebContents; 25 using content::WebContents;
21 26
22 //////////////////////////////////////////////////////////////////////////////// 27 ////////////////////////////////////////////////////////////////////////////////
23 // RenderViewContextMenuViews, public: 28 // RenderViewContextMenuViews, public:
24 29
25 RenderViewContextMenuViews::RenderViewContextMenuViews( 30 RenderViewContextMenuViews::RenderViewContextMenuViews(
26 WebContents* web_contents, 31 WebContents* web_contents,
27 const content::ContextMenuParams& params) 32 const content::ContextMenuParams& params)
28 : RenderViewContextMenu(web_contents, params) { 33 : RenderViewContextMenu(web_contents, params)
34 #if !defined(OS_WIN)
35 , bidi_submenu_model_(this)
36 #endif // !OS_WIN
37 {
29 } 38 }
30 39
31 RenderViewContextMenuViews::~RenderViewContextMenuViews() { 40 RenderViewContextMenuViews::~RenderViewContextMenuViews() {
32 } 41 }
33 42
34 #if !defined(OS_WIN) 43 #if !defined(OS_WIN)
35 // static 44 // static
36 RenderViewContextMenuViews* RenderViewContextMenuViews::Create( 45 RenderViewContextMenuViews* RenderViewContextMenuViews::Create(
37 content::WebContents* web_contents, 46 content::WebContents* web_contents,
38 const content::ContextMenuParams& params) { 47 const content::ContextMenuParams& params) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 111
103 case IDC_CONTENT_CONTEXT_SELECTALL: 112 case IDC_CONTENT_CONTEXT_SELECTALL:
104 *accel = ui::Accelerator(ui::VKEY_A, ui::EF_CONTROL_DOWN); 113 *accel = ui::Accelerator(ui::VKEY_A, ui::EF_CONTROL_DOWN);
105 return true; 114 return true;
106 115
107 default: 116 default:
108 return false; 117 return false;
109 } 118 }
110 } 119 }
111 120
121 #if !defined(OS_WIN)
122 void RenderViewContextMenuViews::ExecuteCommand(
123 int command_id, int event_flags) {
Peter Kasting 2013/11/22 21:53:03 Nit: One arg per line; try to put the first arg on
pals 2013/11/25 06:28:13 Done.
124 switch (command_id) {
125 case IDC_WRITING_DIRECTION_DEFAULT:
126 // WebKit's current behavior is for this menu item to always be disabled.
127 NOTREACHED();
128 break;
129
130 case IDC_WRITING_DIRECTION_RTL:
131 case IDC_WRITING_DIRECTION_LTR: {
132 content::RenderViewHost* view_host = GetRenderViewHost();
133 blink::WebTextDirection dir = blink::WebTextDirectionLeftToRight;
134 if (command_id == IDC_WRITING_DIRECTION_RTL)
135 dir = blink::WebTextDirectionRightToLeft;
136 view_host->UpdateTextDirection(dir);
Peter Kasting 2013/11/22 21:53:03 Nit: Shorter and simpler: view_host->Update
pals 2013/11/25 06:28:13 Done. looks better.
137 view_host->NotifyTextDirection();
138 break;
139 }
140
141 default:
142 RenderViewContextMenu::ExecuteCommand(command_id, event_flags);
143 break;
144 }
145 }
146
147 bool RenderViewContextMenuViews::IsCommandIdChecked(int command_id) const {
148 switch (command_id) {
149 case IDC_WRITING_DIRECTION_DEFAULT:
150 return params_.writing_direction_default &
151 blink::WebContextMenuData::CheckableMenuItemChecked;
152 case IDC_WRITING_DIRECTION_RTL:
153 return params_.writing_direction_right_to_left &
154 blink::WebContextMenuData::CheckableMenuItemChecked;
155 case IDC_WRITING_DIRECTION_LTR:
156 return params_.writing_direction_left_to_right &
157 blink::WebContextMenuData::CheckableMenuItemChecked;
158
159 default:
160 return RenderViewContextMenu::IsCommandIdChecked(command_id);
161 }
162 }
163
164 bool RenderViewContextMenuViews::IsCommandIdEnabled(int command_id) const {
165 switch (command_id) {
166 case IDC_WRITING_DIRECTION_MENU:
167 return true;
168 case IDC_WRITING_DIRECTION_DEFAULT: // Provided to match OS defaults.
169 return params_.writing_direction_default &
170 blink::WebContextMenuData::CheckableMenuItemEnabled;
171 case IDC_WRITING_DIRECTION_RTL:
172 return params_.writing_direction_right_to_left &
173 blink::WebContextMenuData::CheckableMenuItemEnabled;
174 case IDC_WRITING_DIRECTION_LTR:
175 return params_.writing_direction_left_to_right &
176 blink::WebContextMenuData::CheckableMenuItemEnabled;
177
178 default:
179 return RenderViewContextMenu::IsCommandIdEnabled(command_id);
180 }
181 }
182
183 void RenderViewContextMenuViews::AppendPlatformEditableItems() {
184 // OS X and Linux provide a contextual menu to set writing direction for BiDi
185 // languages.
186 // This functionality is exposed as a keyboard shortcut on Windows.
Peter Kasting 2013/11/22 21:53:03 We need to have a keyboard shortcut on all platfor
pals 2013/11/25 06:28:13 As per the comment #31 http://code.google.com/p/ch
Peter Kasting 2013/11/26 02:18:31 I'm not necessarily opposed to having a context me
187 AppendBidiSubMenu();
188 }
189
190 void RenderViewContextMenuViews::AppendBidiSubMenu() {
191 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_DEFAULT,
192 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT));
193 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_LTR,
194 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR));
195 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_RTL,
196 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL));
197
198 menu_model_.AddSubMenu(
199 IDC_WRITING_DIRECTION_MENU,
200 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_MENU),
201 &bidi_submenu_model_);
202 }
203 #endif // !OS_WIN
204
112 void RenderViewContextMenuViews::UpdateMenuItem(int command_id, 205 void RenderViewContextMenuViews::UpdateMenuItem(int command_id,
113 bool enabled, 206 bool enabled,
114 bool hidden, 207 bool hidden,
115 const string16& title) { 208 const string16& title) {
116 views::MenuItemView* item = 209 views::MenuItemView* item =
117 menu_runner_->GetMenu()->GetMenuItemByID(command_id); 210 menu_runner_->GetMenu()->GetMenuItemByID(command_id);
118 if (!item) 211 if (!item)
119 return; 212 return;
120 213
121 item->SetEnabled(enabled); 214 item->SetEnabled(enabled);
122 item->SetTitle(title); 215 item->SetTitle(title);
123 item->SetVisible(!hidden); 216 item->SetVisible(!hidden);
124 217
125 views::MenuItemView* parent = item->GetParentMenuItem(); 218 views::MenuItemView* parent = item->GetParentMenuItem();
126 if (!parent) 219 if (!parent)
127 return; 220 return;
128 221
129 parent->ChildrenChanged(); 222 parent->ChildrenChanged();
130 } 223 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698