OLD | NEW |
---|---|
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) | |
Peter Kasting
2013/12/03 22:52:35
These #includes should not be ifdefed.
pals
2013/12/04 12:54:50
Done.
| |
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 bidi_submenu_model_(this) { | |
29 } | 35 } |
30 | 36 |
31 RenderViewContextMenuViews::~RenderViewContextMenuViews() { | 37 RenderViewContextMenuViews::~RenderViewContextMenuViews() { |
32 } | 38 } |
33 | 39 |
34 #if !defined(OS_WIN) | 40 #if !defined(OS_WIN) |
35 // static | 41 // static |
36 RenderViewContextMenuViews* RenderViewContextMenuViews::Create( | 42 RenderViewContextMenuViews* RenderViewContextMenuViews::Create( |
37 content::WebContents* web_contents, | 43 content::WebContents* web_contents, |
38 const content::ContextMenuParams& params) { | 44 const content::ContextMenuParams& params) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 | 108 |
103 case IDC_CONTENT_CONTEXT_SELECTALL: | 109 case IDC_CONTENT_CONTEXT_SELECTALL: |
104 *accel = ui::Accelerator(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 110 *accel = ui::Accelerator(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
105 return true; | 111 return true; |
106 | 112 |
107 default: | 113 default: |
108 return false; | 114 return false; |
109 } | 115 } |
110 } | 116 } |
111 | 117 |
118 void RenderViewContextMenuViews::ExecuteCommand(int command_id, | |
119 int event_flags) { | |
Peter Kasting
2013/12/03 22:52:35
Nit: Indent even
pals
2013/12/04 12:54:50
Done.
| |
120 switch (command_id) { | |
121 case IDC_WRITING_DIRECTION_DEFAULT: | |
122 // WebKit's current behavior is for this menu item to always be disabled. | |
Peter Kasting
2013/12/03 22:52:35
Then why are we displaying it in the menu? Or wil
pals
2013/12/04 12:54:50
I think default is for dir="auto". see crbug.com/3
Peter Kasting
2013/12/04 19:46:31
Right, I'd also think it corresponds to dir=auto.
pals
2013/12/05 14:25:49
I found original implementaion on OSX (webkit side
jeremy
2013/12/05 14:33:18
If I had to guess, I'd think this is a "match-the-
| |
123 NOTREACHED(); | |
124 break; | |
125 | |
126 case IDC_WRITING_DIRECTION_RTL: | |
127 case IDC_WRITING_DIRECTION_LTR: { | |
128 content::RenderViewHost* view_host = GetRenderViewHost(); | |
129 view_host->UpdateTextDirection((command_id == IDC_WRITING_DIRECTION_RTL) ? | |
130 blink::WebTextDirectionRightToLeft : | |
131 blink::WebTextDirectionLeftToRight); | |
132 view_host->NotifyTextDirection(); | |
133 break; | |
134 } | |
135 | |
136 default: | |
137 RenderViewContextMenu::ExecuteCommand(command_id, event_flags); | |
138 break; | |
139 } | |
140 } | |
141 | |
142 bool RenderViewContextMenuViews::IsCommandIdChecked(int command_id) const { | |
143 switch (command_id) { | |
144 case IDC_WRITING_DIRECTION_DEFAULT: | |
145 return params_.writing_direction_default & | |
146 blink::WebContextMenuData::CheckableMenuItemChecked; | |
147 case IDC_WRITING_DIRECTION_RTL: | |
148 return params_.writing_direction_right_to_left & | |
149 blink::WebContextMenuData::CheckableMenuItemChecked; | |
150 case IDC_WRITING_DIRECTION_LTR: | |
151 return params_.writing_direction_left_to_right & | |
152 blink::WebContextMenuData::CheckableMenuItemChecked; | |
153 | |
154 default: | |
155 return RenderViewContextMenu::IsCommandIdChecked(command_id); | |
156 } | |
157 } | |
158 | |
159 bool RenderViewContextMenuViews::IsCommandIdEnabled(int command_id) const { | |
160 switch (command_id) { | |
161 case IDC_WRITING_DIRECTION_MENU: | |
162 return true; | |
163 case IDC_WRITING_DIRECTION_DEFAULT: // Provided to match OS defaults. | |
164 return params_.writing_direction_default & | |
165 blink::WebContextMenuData::CheckableMenuItemEnabled; | |
166 case IDC_WRITING_DIRECTION_RTL: | |
167 return params_.writing_direction_right_to_left & | |
168 blink::WebContextMenuData::CheckableMenuItemEnabled; | |
169 case IDC_WRITING_DIRECTION_LTR: | |
170 return params_.writing_direction_left_to_right & | |
171 blink::WebContextMenuData::CheckableMenuItemEnabled; | |
172 | |
173 default: | |
174 return RenderViewContextMenu::IsCommandIdEnabled(command_id); | |
175 } | |
176 } | |
177 | |
178 void RenderViewContextMenuViews::AppendPlatformEditableItems() { | |
179 // OS X and Linux provide a contextual menu to set writing direction for BiDi | |
180 // languages. | |
181 // This functionality is exposed as a keyboard shortcut on Windows. | |
Peter Kasting
2013/12/03 22:52:35
This comment seems out of date.
pals
2013/12/04 12:54:50
Done.
| |
182 AppendBidiSubMenu(); | |
Peter Kasting
2013/12/03 22:52:35
Why a separate function for this instead of just d
pals
2013/12/04 12:54:50
Done.
| |
183 } | |
184 | |
185 void RenderViewContextMenuViews::AppendBidiSubMenu() { | |
186 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_DEFAULT, | |
Peter Kasting
2013/12/03 22:52:35
Nit: Wrap after '(' so all lines of args are align
pals
2013/12/04 12:54:50
Done.
| |
187 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT)); | |
188 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_LTR, | |
189 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR)); | |
190 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_RTL, | |
191 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL)); | |
192 | |
193 menu_model_.AddSubMenu( | |
194 IDC_WRITING_DIRECTION_MENU, | |
195 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_MENU), | |
196 &bidi_submenu_model_); | |
197 } | |
198 | |
112 void RenderViewContextMenuViews::UpdateMenuItem(int command_id, | 199 void RenderViewContextMenuViews::UpdateMenuItem(int command_id, |
113 bool enabled, | 200 bool enabled, |
114 bool hidden, | 201 bool hidden, |
115 const string16& title) { | 202 const string16& title) { |
116 views::MenuItemView* item = | 203 views::MenuItemView* item = |
117 menu_runner_->GetMenu()->GetMenuItemByID(command_id); | 204 menu_runner_->GetMenu()->GetMenuItemByID(command_id); |
118 if (!item) | 205 if (!item) |
119 return; | 206 return; |
120 | 207 |
121 item->SetEnabled(enabled); | 208 item->SetEnabled(enabled); |
122 item->SetTitle(title); | 209 item->SetTitle(title); |
123 item->SetVisible(!hidden); | 210 item->SetVisible(!hidden); |
124 | 211 |
125 views::MenuItemView* parent = item->GetParentMenuItem(); | 212 views::MenuItemView* parent = item->GetParentMenuItem(); |
126 if (!parent) | 213 if (!parent) |
127 return; | 214 return; |
128 | 215 |
129 parent->ChildrenChanged(); | 216 parent->ChildrenChanged(); |
130 } | 217 } |
OLD | NEW |