OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/tab_contents/render_view_context_menu.h" | 5 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
6 | 6 |
7 #include "app/clipboard/clipboard.h" | 7 #include "app/clipboard/clipboard.h" |
8 #include "app/clipboard/scoped_clipboard_writer.h" | 8 #include "app/clipboard/scoped_clipboard_writer.h" |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "chrome/browser/tab_contents/tab_contents.h" | 27 #include "chrome/browser/tab_contents/tab_contents.h" |
28 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/platform_util.h" | 29 #include "chrome/common/platform_util.h" |
30 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
31 #include "chrome/common/pref_service.h" | 31 #include "chrome/common/pref_service.h" |
32 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
33 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
34 #include "net/base/escape.h" | 34 #include "net/base/escape.h" |
35 #include "net/url_request/url_request.h" | 35 #include "net/url_request/url_request.h" |
36 #include "webkit/glue/webmenuitem.h" | 36 #include "webkit/glue/webmenuitem.h" |
| 37 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" |
37 #include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayerAction.h" | 38 #include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayerAction.h" |
38 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" | 39 #include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h" |
39 | 40 |
40 using WebKit::WebContextMenuData; | 41 using WebKit::WebContextMenuData; |
41 using WebKit::WebMediaPlayerAction; | 42 using WebKit::WebMediaPlayerAction; |
42 | 43 |
43 // static | 44 // static |
44 bool RenderViewContextMenu::IsDevToolsURL(const GURL& url) { | 45 bool RenderViewContextMenu::IsDevToolsURL(const GURL& url) { |
45 return url.SchemeIs(chrome::kChromeUIScheme) && | 46 return url.SchemeIs(chrome::kChromeUIScheme) && |
46 url.host() == chrome::kChromeUIDevToolsHost; | 47 url.host() == chrome::kChromeUIDevToolsHost; |
47 } | 48 } |
48 | 49 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 // supports it. | 331 // supports it. |
331 if (SpellCheckerPlatform::SpellCheckerAvailable() && | 332 if (SpellCheckerPlatform::SpellCheckerAvailable() && |
332 SpellCheckerPlatform::SpellCheckerProvidesPanel()) { | 333 SpellCheckerPlatform::SpellCheckerProvidesPanel()) { |
333 AppendCheckboxMenuItem(IDC_SPELLPANEL_TOGGLE, l10n_util::GetStringUTF16( | 334 AppendCheckboxMenuItem(IDC_SPELLPANEL_TOGGLE, l10n_util::GetStringUTF16( |
334 SpellCheckerPlatform::SpellingPanelVisible() ? | 335 SpellCheckerPlatform::SpellingPanelVisible() ? |
335 IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL : | 336 IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL : |
336 IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL)); | 337 IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL)); |
337 } | 338 } |
338 FinishSubMenu(); | 339 FinishSubMenu(); |
339 | 340 |
| 341 #if defined(OS_MACOSX) |
| 342 // OS X provides a contextual menu to set writing direction for BiDi |
| 343 // languages. |
| 344 // This functionality is exposed as a keyboard shortcut on Windows & Linux. |
| 345 |
| 346 // Add writing direction sub menu. |
| 347 StartSubMenu(IDC_WRITING_DIRECTION_MENU, |
| 348 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_MENU)); |
| 349 |
| 350 AppendCheckboxMenuItem(IDC_WRITING_DIRECTION_DEFAULT, |
| 351 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT)); |
| 352 AppendCheckboxMenuItem(IDC_WRITING_DIRECTION_LTR, |
| 353 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR)); |
| 354 AppendCheckboxMenuItem(IDC_WRITING_DIRECTION_RTL, |
| 355 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL)); |
| 356 |
| 357 FinishSubMenu(); |
| 358 #endif // OS_MACOSX |
| 359 |
340 AppendSeparator(); | 360 AppendSeparator(); |
341 AppendMenuItem(IDS_CONTENT_CONTEXT_SELECTALL); | 361 AppendMenuItem(IDS_CONTENT_CONTEXT_SELECTALL); |
342 } | 362 } |
343 | 363 |
344 // Menu delegate functions ----------------------------------------------------- | 364 // Menu delegate functions ----------------------------------------------------- |
345 | 365 |
346 bool RenderViewContextMenu::IsItemCommandEnabled(int id) const { | 366 bool RenderViewContextMenu::IsItemCommandEnabled(int id) const { |
347 // Allow Spell Check language items on sub menu for text area context menu. | 367 // Allow Spell Check language items on sub menu for text area context menu. |
348 if ((id >= IDC_SPELLCHECK_LANGUAGES_FIRST) && | 368 if ((id >= IDC_SPELLCHECK_LANGUAGES_FIRST) && |
349 (id < IDC_SPELLCHECK_LANGUAGES_LAST)) { | 369 (id < IDC_SPELLCHECK_LANGUAGES_LAST)) { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 case IDC_SPELLCHECK_SUGGESTION_4: | 525 case IDC_SPELLCHECK_SUGGESTION_4: |
506 case IDC_SPELLCHECK_MENU: | 526 case IDC_SPELLCHECK_MENU: |
507 case IDC_SPELLPANEL_TOGGLE: | 527 case IDC_SPELLPANEL_TOGGLE: |
508 case IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS: | 528 case IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS: |
509 case IDS_CONTENT_CONTEXT_VIEWFRAMEINFO: | 529 case IDS_CONTENT_CONTEXT_VIEWFRAMEINFO: |
510 return true; | 530 return true; |
511 | 531 |
512 case IDC_CHECK_SPELLING_OF_THIS_FIELD: | 532 case IDC_CHECK_SPELLING_OF_THIS_FIELD: |
513 return profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck); | 533 return profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck); |
514 | 534 |
| 535 #if defined(OS_MACOSX) |
| 536 case IDC_WRITING_DIRECTION_DEFAULT: // Provided to match OS defaults. |
| 537 return params_.writing_direction_default & |
| 538 WebContextMenuData::CheckableMenuItemEnabled; |
| 539 case IDC_WRITING_DIRECTION_RTL: |
| 540 return params_.writing_direction_right_to_left & |
| 541 WebContextMenuData::CheckableMenuItemEnabled; |
| 542 case IDC_WRITING_DIRECTION_LTR: |
| 543 return params_.writing_direction_left_to_right & |
| 544 WebContextMenuData::CheckableMenuItemEnabled; |
| 545 #endif // OS_MACOSX |
| 546 |
515 #if defined(OS_LINUX) | 547 #if defined(OS_LINUX) |
516 // Enable the input methods context menu if the content is editable. | 548 // Enable the input methods context menu if the content is editable. |
517 // TODO(suzhe): It should not be enabled in password boxes. Anyway, | 549 // TODO(suzhe): It should not be enabled in password boxes. Anyway, |
518 // it's not a big issue. | 550 // it's not a big issue. |
519 case IDC_INPUT_METHODS_MENU: | 551 case IDC_INPUT_METHODS_MENU: |
520 return params_.is_editable; | 552 return params_.is_editable; |
521 #endif | 553 #endif |
522 | 554 |
523 case IDS_CONTENT_CONTEXT_SAVEFRAMEAS: | 555 case IDS_CONTENT_CONTEXT_SAVEFRAMEAS: |
524 case IDS_CONTENT_CONTEXT_PRINTFRAME: | 556 case IDS_CONTENT_CONTEXT_PRINTFRAME: |
525 case IDS_CONTENT_CONTEXT_ADDSEARCHENGINE: // Not implemented. | 557 case IDS_CONTENT_CONTEXT_ADDSEARCHENGINE: // Not implemented. |
526 default: | 558 default: |
527 return false; | 559 return false; |
528 } | 560 } |
529 } | 561 } |
530 | 562 |
531 bool RenderViewContextMenu::ItemIsChecked(int id) const { | 563 bool RenderViewContextMenu::ItemIsChecked(int id) const { |
532 // See if the video is set to looping. | 564 // See if the video is set to looping. |
533 if (id == IDS_CONTENT_CONTEXT_LOOP) { | 565 if (id == IDS_CONTENT_CONTEXT_LOOP) { |
534 return (params_.media_flags & | 566 return (params_.media_flags & |
535 WebContextMenuData::MediaLoop) != 0; | 567 WebContextMenuData::MediaLoop) != 0; |
536 } | 568 } |
537 | 569 |
| 570 #if defined(OS_MACOSX) |
| 571 if (id == IDC_WRITING_DIRECTION_DEFAULT) |
| 572 return params_.writing_direction_default & |
| 573 WebContextMenuData::CheckableMenuItemChecked; |
| 574 if (id == IDC_WRITING_DIRECTION_RTL) |
| 575 return params_.writing_direction_right_to_left & |
| 576 WebContextMenuData::CheckableMenuItemChecked; |
| 577 if (id == IDC_WRITING_DIRECTION_LTR) |
| 578 return params_.writing_direction_left_to_right & |
| 579 WebContextMenuData::CheckableMenuItemChecked; |
| 580 #endif // OS_MACOSX |
| 581 |
538 // Check box for 'Check the Spelling of this field'. | 582 // Check box for 'Check the Spelling of this field'. |
539 if (id == IDC_CHECK_SPELLING_OF_THIS_FIELD) { | 583 if (id == IDC_CHECK_SPELLING_OF_THIS_FIELD) { |
540 return (params_.spellcheck_enabled && | 584 return (params_.spellcheck_enabled && |
541 profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)); | 585 profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)); |
542 } | 586 } |
543 | 587 |
544 // Don't bother getting the display language vector if this isn't a spellcheck | 588 // Don't bother getting the display language vector if this isn't a spellcheck |
545 // language. | 589 // language. |
546 if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) || | 590 if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) || |
547 (id >= IDC_SPELLCHECK_LANGUAGES_LAST)) | 591 (id >= IDC_SPELLCHECK_LANGUAGES_LAST)) |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 ShowFontsLanguagesWindow( | 853 ShowFontsLanguagesWindow( |
810 platform_util::GetTopLevel( | 854 platform_util::GetTopLevel( |
811 source_tab_contents_->GetContentNativeView()), | 855 source_tab_contents_->GetContentNativeView()), |
812 LANGUAGES_PAGE, profile_); | 856 LANGUAGES_PAGE, profile_); |
813 break; | 857 break; |
814 | 858 |
815 case IDC_SPELLPANEL_TOGGLE: | 859 case IDC_SPELLPANEL_TOGGLE: |
816 source_tab_contents_->render_view_host()->ToggleSpellPanel( | 860 source_tab_contents_->render_view_host()->ToggleSpellPanel( |
817 SpellCheckerPlatform::SpellingPanelVisible()); | 861 SpellCheckerPlatform::SpellingPanelVisible()); |
818 break; | 862 break; |
| 863 |
| 864 #if defined(OS_MACOSX) |
| 865 case IDC_WRITING_DIRECTION_DEFAULT: |
| 866 // WebKit's current behavior is for this menu item to always be disabled. |
| 867 NOTREACHED(); |
| 868 break; |
| 869 case IDC_WRITING_DIRECTION_RTL: |
| 870 case IDC_WRITING_DIRECTION_LTR: { |
| 871 WebKit::WebTextDirection dir = WebKit::WebTextDirectionLeftToRight; |
| 872 if (id == IDC_WRITING_DIRECTION_RTL) |
| 873 dir = WebKit::WebTextDirectionRightToLeft; |
| 874 source_tab_contents_->render_view_host()->UpdateTextDirection(dir); |
| 875 source_tab_contents_->render_view_host()->NotifyTextDirection(); |
| 876 break; |
| 877 } |
| 878 #endif // OS_MACOSX |
| 879 |
819 case IDS_CONTENT_CONTEXT_ADDSEARCHENGINE: // Not implemented. | 880 case IDS_CONTENT_CONTEXT_ADDSEARCHENGINE: // Not implemented. |
820 default: | 881 default: |
821 break; | 882 break; |
822 } | 883 } |
823 } | 884 } |
824 | 885 |
825 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const { | 886 bool RenderViewContextMenu::IsDevCommandEnabled(int id) const { |
826 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 887 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
827 if (command_line.HasSwitch(switches::kAlwaysEnableDevTools)) | 888 if (command_line.HasSwitch(switches::kAlwaysEnableDevTools)) |
828 return true; | 889 return true; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), | 958 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
898 g_browser_process->clipboard()); | 959 g_browser_process->clipboard()); |
899 } | 960 } |
900 | 961 |
901 void RenderViewContextMenu::MediaPlayerActionAt( | 962 void RenderViewContextMenu::MediaPlayerActionAt( |
902 const gfx::Point& location, | 963 const gfx::Point& location, |
903 const WebMediaPlayerAction& action) { | 964 const WebMediaPlayerAction& action) { |
904 source_tab_contents_->render_view_host()->MediaPlayerActionAt( | 965 source_tab_contents_->render_view_host()->MediaPlayerActionAt( |
905 location, action); | 966 location, action); |
906 } | 967 } |
OLD | NEW |