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

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: 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 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_view_host.h"
10 #include "content/public/browser/render_widget_host_view.h" 11 #include "content/public/browser/render_widget_host_view.h"
11 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/web_contents_view.h" 13 #include "content/public/browser/web_contents_view.h"
13 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
14 #include "ui/base/accelerators/accelerator.h" 15 #include "ui/base/accelerators/accelerator.h"
16 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/events/keycodes/keyboard_codes.h" 17 #include "ui/events/keycodes/keyboard_codes.h"
16 #include "ui/gfx/point.h" 18 #include "ui/gfx/point.h"
17 #include "ui/views/controls/menu/menu_item_view.h" 19 #include "ui/views/controls/menu/menu_item_view.h"
18 #include "ui/views/controls/menu/menu_runner.h" 20 #include "ui/views/controls/menu/menu_runner.h"
19 21
22
20 using content::WebContents; 23 using content::WebContents;
21 24
22 //////////////////////////////////////////////////////////////////////////////// 25 ////////////////////////////////////////////////////////////////////////////////
23 // RenderViewContextMenuViews, public: 26 // RenderViewContextMenuViews, public:
24 27
25 RenderViewContextMenuViews::RenderViewContextMenuViews( 28 RenderViewContextMenuViews::RenderViewContextMenuViews(
26 WebContents* web_contents, 29 WebContents* web_contents,
27 const content::ContextMenuParams& params) 30 const content::ContextMenuParams& params)
28 : RenderViewContextMenu(web_contents, params) { 31 : RenderViewContextMenu(web_contents, params),
32 bidi_submenu_model_(this) {
29 } 33 }
30 34
31 RenderViewContextMenuViews::~RenderViewContextMenuViews() { 35 RenderViewContextMenuViews::~RenderViewContextMenuViews() {
32 } 36 }
33 37
34 #if !defined(OS_WIN) 38 #if !defined(OS_WIN)
35 // static 39 // static
36 RenderViewContextMenuViews* RenderViewContextMenuViews::Create( 40 RenderViewContextMenuViews* RenderViewContextMenuViews::Create(
37 content::WebContents* web_contents, 41 content::WebContents* web_contents,
38 const content::ContextMenuParams& params) { 42 const content::ContextMenuParams& params) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 106
103 case IDC_CONTENT_CONTEXT_SELECTALL: 107 case IDC_CONTENT_CONTEXT_SELECTALL:
104 *accel = ui::Accelerator(ui::VKEY_A, ui::EF_CONTROL_DOWN); 108 *accel = ui::Accelerator(ui::VKEY_A, ui::EF_CONTROL_DOWN);
105 return true; 109 return true;
106 110
107 default: 111 default:
108 return false; 112 return false;
109 } 113 }
110 } 114 }
111 115
116 void RenderViewContextMenuViews::ExecuteCommand(int command_id,
117 int event_flags) {
118 switch (command_id) {
119 case IDC_WRITING_DIRECTION_DEFAULT:
120 // WebKit's current behavior is for this menu item to always be disabled.
121 NOTREACHED();
122 break;
123
124 case IDC_WRITING_DIRECTION_RTL:
125 case IDC_WRITING_DIRECTION_LTR: {
126 content::RenderViewHost* view_host = GetRenderViewHost();
127 view_host->UpdateTextDirection((command_id == IDC_WRITING_DIRECTION_RTL) ?
128 blink::WebTextDirectionRightToLeft :
129 blink::WebTextDirectionLeftToRight);
130 view_host->NotifyTextDirection();
131 break;
132 }
133
134 default:
135 RenderViewContextMenu::ExecuteCommand(command_id, event_flags);
136 break;
137 }
138 }
139
140 bool RenderViewContextMenuViews::IsCommandIdChecked(int command_id) const {
141 switch (command_id) {
142 case IDC_WRITING_DIRECTION_DEFAULT:
143 return (params_.writing_direction_default &
144 blink::WebContextMenuData::CheckableMenuItemChecked) != 0;
145 case IDC_WRITING_DIRECTION_RTL:
146 return (params_.writing_direction_right_to_left &
147 blink::WebContextMenuData::CheckableMenuItemChecked) != 0;
148 case IDC_WRITING_DIRECTION_LTR:
149 return (params_.writing_direction_left_to_right &
150 blink::WebContextMenuData::CheckableMenuItemChecked) != 0;
151
152 default:
153 return RenderViewContextMenu::IsCommandIdChecked(command_id);
154 }
155 }
156
157 bool RenderViewContextMenuViews::IsCommandIdEnabled(int command_id) const {
158 switch (command_id) {
159 case IDC_WRITING_DIRECTION_MENU:
160 return true;
161 case IDC_WRITING_DIRECTION_DEFAULT: // Provided to match OS defaults.
162 return params_.writing_direction_default &
163 blink::WebContextMenuData::CheckableMenuItemEnabled;
164 case IDC_WRITING_DIRECTION_RTL:
165 return params_.writing_direction_right_to_left &
166 blink::WebContextMenuData::CheckableMenuItemEnabled;
167 case IDC_WRITING_DIRECTION_LTR:
168 return params_.writing_direction_left_to_right &
169 blink::WebContextMenuData::CheckableMenuItemEnabled;
170
171 default:
172 return RenderViewContextMenu::IsCommandIdEnabled(command_id);
173 }
174 }
175
176 void RenderViewContextMenuViews::AppendPlatformEditableItems() {
177 bidi_submenu_model_.AddCheckItem(
178 IDC_WRITING_DIRECTION_DEFAULT,
179 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT));
180 bidi_submenu_model_.AddCheckItem(
181 IDC_WRITING_DIRECTION_LTR,
182 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR));
183 bidi_submenu_model_.AddCheckItem(
184 IDC_WRITING_DIRECTION_RTL,
185 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL));
186
187 menu_model_.AddSubMenu(
188 IDC_WRITING_DIRECTION_MENU,
189 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_MENU),
190 &bidi_submenu_model_);
191 }
192
112 void RenderViewContextMenuViews::UpdateMenuItem(int command_id, 193 void RenderViewContextMenuViews::UpdateMenuItem(int command_id,
113 bool enabled, 194 bool enabled,
114 bool hidden, 195 bool hidden,
115 const string16& title) { 196 const string16& title) {
116 views::MenuItemView* item = 197 views::MenuItemView* item =
117 menu_runner_->GetMenu()->GetMenuItemByID(command_id); 198 menu_runner_->GetMenu()->GetMenuItemByID(command_id);
118 if (!item) 199 if (!item)
119 return; 200 return;
120 201
121 item->SetEnabled(enabled); 202 item->SetEnabled(enabled);
122 item->SetTitle(title); 203 item->SetTitle(title);
123 item->SetVisible(!hidden); 204 item->SetVisible(!hidden);
124 205
125 views::MenuItemView* parent = item->GetParentMenuItem(); 206 views::MenuItemView* parent = item->GetParentMenuItem();
126 if (!parent) 207 if (!parent)
127 return; 208 return;
128 209
129 parent->ChildrenChanged(); 210 parent->ChildrenChanged();
130 } 211 }
OLDNEW
« 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