OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/cocoa/renderer_context_menu/render_view_context_menu
_mac.h" | 5 #include "chrome/browser/ui/cocoa/renderer_context_menu/render_view_context_menu
_mac.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 }; | 176 }; |
177 | 177 |
178 // Obj-C bridge class that is the target of all items in the context menu. | 178 // Obj-C bridge class that is the target of all items in the context menu. |
179 // Relies on the tag being set to the command id. | 179 // Relies on the tag being set to the command id. |
180 | 180 |
181 RenderViewContextMenuMac::RenderViewContextMenuMac( | 181 RenderViewContextMenuMac::RenderViewContextMenuMac( |
182 content::RenderFrameHost* render_frame_host, | 182 content::RenderFrameHost* render_frame_host, |
183 const content::ContextMenuParams& params, | 183 const content::ContextMenuParams& params, |
184 NSView* parent_view) | 184 NSView* parent_view) |
185 : RenderViewContextMenu(render_frame_host, params), | 185 : RenderViewContextMenu(render_frame_host, params), |
186 speech_submenu_model_(this), | |
187 bidi_submenu_model_(this), | 186 bidi_submenu_model_(this), |
188 parent_view_(parent_view) { | 187 parent_view_(parent_view), |
| 188 text_context_menu_(new TextContextMenu(this)) { |
189 std::unique_ptr<ToolkitDelegate> delegate(new ToolkitDelegateMac(this)); | 189 std::unique_ptr<ToolkitDelegate> delegate(new ToolkitDelegateMac(this)); |
190 set_toolkit_delegate(std::move(delegate)); | 190 set_toolkit_delegate(std::move(delegate)); |
191 } | 191 } |
192 | 192 |
193 RenderViewContextMenuMac::~RenderViewContextMenuMac() { | 193 RenderViewContextMenuMac::~RenderViewContextMenuMac() { |
194 } | 194 } |
195 | 195 |
196 void RenderViewContextMenuMac::Show() { | 196 void RenderViewContextMenuMac::Show() { |
197 menu_controller_.reset( | 197 menu_controller_.reset( |
198 [[MenuController alloc] initWithModel:&menu_model_ | 198 [[MenuController alloc] initWithModel:&menu_model_ |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 stopwatch.Stop(); | 243 stopwatch.Stop(); |
244 } | 244 } |
245 } | 245 } |
246 | 246 |
247 void RenderViewContextMenuMac::ExecuteCommand(int command_id, int event_flags) { | 247 void RenderViewContextMenuMac::ExecuteCommand(int command_id, int event_flags) { |
248 switch (command_id) { | 248 switch (command_id) { |
249 case IDC_CONTENT_CONTEXT_LOOK_UP: | 249 case IDC_CONTENT_CONTEXT_LOOK_UP: |
250 LookUpInDictionary(); | 250 LookUpInDictionary(); |
251 break; | 251 break; |
252 | 252 |
253 case IDC_CONTENT_CONTEXT_SPEECH_START_SPEAKING: | |
254 StartSpeaking(); | |
255 break; | |
256 | |
257 case IDC_CONTENT_CONTEXT_SPEECH_STOP_SPEAKING: | |
258 StopSpeaking(); | |
259 break; | |
260 | |
261 case IDC_WRITING_DIRECTION_DEFAULT: | 253 case IDC_WRITING_DIRECTION_DEFAULT: |
262 // WebKit's current behavior is for this menu item to always be disabled. | 254 // WebKit's current behavior is for this menu item to always be disabled. |
263 NOTREACHED(); | 255 NOTREACHED(); |
264 break; | 256 break; |
265 | 257 |
266 case IDC_WRITING_DIRECTION_RTL: | 258 case IDC_WRITING_DIRECTION_RTL: |
267 case IDC_WRITING_DIRECTION_LTR: { | 259 case IDC_WRITING_DIRECTION_LTR: { |
268 content::RenderViewHost* view_host = GetRenderViewHost(); | 260 content::RenderViewHost* view_host = GetRenderViewHost(); |
269 blink::WebTextDirection dir = blink::WebTextDirectionLeftToRight; | 261 blink::WebTextDirection dir = blink::WebTextDirectionLeftToRight; |
270 if (command_id == IDC_WRITING_DIRECTION_RTL) | 262 if (command_id == IDC_WRITING_DIRECTION_RTL) |
(...skipping 27 matching lines...) Expand all Loading... |
298 } | 290 } |
299 } | 291 } |
300 | 292 |
301 bool RenderViewContextMenuMac::IsCommandIdEnabled(int command_id) const { | 293 bool RenderViewContextMenuMac::IsCommandIdEnabled(int command_id) const { |
302 switch (command_id) { | 294 switch (command_id) { |
303 case IDC_CONTENT_CONTEXT_LOOK_UP: | 295 case IDC_CONTENT_CONTEXT_LOOK_UP: |
304 // This is OK because the menu is not shown when it isn't | 296 // This is OK because the menu is not shown when it isn't |
305 // appropriate. | 297 // appropriate. |
306 return true; | 298 return true; |
307 | 299 |
308 case IDC_CONTENT_CONTEXT_SPEECH_START_SPEAKING: | |
309 // This is OK because the menu is not shown when it isn't | |
310 // appropriate. | |
311 return true; | |
312 | |
313 case IDC_CONTENT_CONTEXT_SPEECH_STOP_SPEAKING: { | |
314 content::RenderWidgetHostView* view = | |
315 GetRenderViewHost()->GetWidget()->GetView(); | |
316 return view && view->IsSpeaking(); | |
317 } | |
318 | |
319 case IDC_WRITING_DIRECTION_DEFAULT: // Provided to match OS defaults. | 300 case IDC_WRITING_DIRECTION_DEFAULT: // Provided to match OS defaults. |
320 return params_.writing_direction_default & | 301 return params_.writing_direction_default & |
321 blink::WebContextMenuData::CheckableMenuItemEnabled; | 302 blink::WebContextMenuData::CheckableMenuItemEnabled; |
322 case IDC_WRITING_DIRECTION_RTL: | 303 case IDC_WRITING_DIRECTION_RTL: |
323 return params_.writing_direction_right_to_left & | 304 return params_.writing_direction_right_to_left & |
324 blink::WebContextMenuData::CheckableMenuItemEnabled; | 305 blink::WebContextMenuData::CheckableMenuItemEnabled; |
325 case IDC_WRITING_DIRECTION_LTR: | 306 case IDC_WRITING_DIRECTION_LTR: |
326 return params_.writing_direction_left_to_right & | 307 return params_.writing_direction_left_to_right & |
327 blink::WebContextMenuData::CheckableMenuItemEnabled; | 308 blink::WebContextMenuData::CheckableMenuItemEnabled; |
328 | 309 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 base::string16 printable_selection_text = PrintableSelectionText(); | 347 base::string16 printable_selection_text = PrintableSelectionText(); |
367 EscapeAmpersands(&printable_selection_text); | 348 EscapeAmpersands(&printable_selection_text); |
368 menu_model_.InsertItemAt( | 349 menu_model_.InsertItemAt( |
369 index++, | 350 index++, |
370 IDC_CONTENT_CONTEXT_LOOK_UP, | 351 IDC_CONTENT_CONTEXT_LOOK_UP, |
371 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_LOOK_UP, | 352 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_LOOK_UP, |
372 printable_selection_text)); | 353 printable_selection_text)); |
373 menu_model_.InsertSeparatorAt(index++, ui::NORMAL_SEPARATOR); | 354 menu_model_.InsertSeparatorAt(index++, ui::NORMAL_SEPARATOR); |
374 } | 355 } |
375 | 356 |
376 content::RenderWidgetHostView* view = | 357 text_context_menu_->AppendToContextMenu(&menu_model_); |
377 GetRenderViewHost()->GetWidget()->GetView(); | |
378 if (view && view->SupportsSpeech()) { | |
379 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | |
380 speech_submenu_model_.AddItemWithStringId( | |
381 IDC_CONTENT_CONTEXT_SPEECH_START_SPEAKING, | |
382 IDS_SPEECH_START_SPEAKING_MAC); | |
383 speech_submenu_model_.AddItemWithStringId( | |
384 IDC_CONTENT_CONTEXT_SPEECH_STOP_SPEAKING, | |
385 IDS_SPEECH_STOP_SPEAKING_MAC); | |
386 menu_model_.AddSubMenu( | |
387 IDC_CONTENT_CONTEXT_SPEECH_MENU, | |
388 l10n_util::GetStringUTF16(IDS_SPEECH_MAC), | |
389 &speech_submenu_model_); | |
390 } | |
391 } | 358 } |
392 | 359 |
393 void RenderViewContextMenuMac::CancelToolkitMenu() { | 360 void RenderViewContextMenuMac::CancelToolkitMenu() { |
394 [menu_controller_ cancel]; | 361 [menu_controller_ cancel]; |
395 } | 362 } |
396 | 363 |
397 void RenderViewContextMenuMac::UpdateToolkitMenuItem( | 364 void RenderViewContextMenuMac::UpdateToolkitMenuItem( |
398 int command_id, | 365 int command_id, |
399 bool enabled, | 366 bool enabled, |
400 bool hidden, | 367 bool hidden, |
(...skipping 30 matching lines...) Expand all Loading... |
431 if (view) | 398 if (view) |
432 view->ShowDefinitionForSelection(); | 399 view->ShowDefinitionForSelection(); |
433 } | 400 } |
434 | 401 |
435 void RenderViewContextMenuMac::StartSpeaking() { | 402 void RenderViewContextMenuMac::StartSpeaking() { |
436 content::RenderWidgetHostView* view = | 403 content::RenderWidgetHostView* view = |
437 GetRenderViewHost()->GetWidget()->GetView(); | 404 GetRenderViewHost()->GetWidget()->GetView(); |
438 if (view) | 405 if (view) |
439 view->SpeakSelection(); | 406 view->SpeakSelection(); |
440 } | 407 } |
441 | |
442 void RenderViewContextMenuMac::StopSpeaking() { | |
443 content::RenderWidgetHostView* view = | |
444 GetRenderViewHost()->GetWidget()->GetView(); | |
445 if (view) | |
446 view->StopSpeaking(); | |
447 } | |
OLD | NEW |