OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 5 #include <algorithm> |
6 #include <set> | 6 #include <set> |
7 | 7 |
8 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 8 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 | 186 |
187 RenderViewContextMenu::RenderViewContextMenu( | 187 RenderViewContextMenu::RenderViewContextMenu( |
188 TabContents* tab_contents, | 188 TabContents* tab_contents, |
189 const ContextMenuParams& params) | 189 const ContextMenuParams& params) |
190 : params_(params), | 190 : params_(params), |
191 source_tab_contents_(tab_contents), | 191 source_tab_contents_(tab_contents), |
192 profile_(tab_contents->profile()), | 192 profile_(tab_contents->profile()), |
193 ALLOW_THIS_IN_INITIALIZER_LIST(menu_model_(this)), | 193 ALLOW_THIS_IN_INITIALIZER_LIST(menu_model_(this)), |
194 external_(false), | 194 external_(false), |
195 ALLOW_THIS_IN_INITIALIZER_LIST(spellcheck_submenu_model_(this)), | 195 ALLOW_THIS_IN_INITIALIZER_LIST(spellcheck_submenu_model_(this)), |
196 ALLOW_THIS_IN_INITIALIZER_LIST(speech_input_submenu_model_(this)), | |
196 ALLOW_THIS_IN_INITIALIZER_LIST(bidi_submenu_model_(this)), | 197 ALLOW_THIS_IN_INITIALIZER_LIST(bidi_submenu_model_(this)), |
197 ALLOW_THIS_IN_INITIALIZER_LIST(protocol_handler_submenu_model_(this)), | 198 ALLOW_THIS_IN_INITIALIZER_LIST(protocol_handler_submenu_model_(this)), |
198 protocol_handler_registry_( | 199 protocol_handler_registry_( |
199 tab_contents->profile()->GetProtocolHandlerRegistry()) { | 200 tab_contents->profile()->GetProtocolHandlerRegistry()) { |
200 } | 201 } |
201 | 202 |
202 RenderViewContextMenu::~RenderViewContextMenu() { | 203 RenderViewContextMenu::~RenderViewContextMenu() { |
203 } | 204 } |
204 | 205 |
205 // Menu construction functions ------------------------------------------------- | 206 // Menu construction functions ------------------------------------------------- |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
786 IDS_CONTENT_CONTEXT_DELETE); | 787 IDS_CONTENT_CONTEXT_DELETE); |
787 menu_model_.AddSeparator(); | 788 menu_model_.AddSeparator(); |
788 | 789 |
789 if (!params_.keyword_url.is_empty()) { | 790 if (!params_.keyword_url.is_empty()) { |
790 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ADDSEARCHENGINE, | 791 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ADDSEARCHENGINE, |
791 IDS_CONTENT_CONTEXT_ADDSEARCHENGINE); | 792 IDS_CONTENT_CONTEXT_ADDSEARCHENGINE); |
792 menu_model_.AddSeparator(); | 793 menu_model_.AddSeparator(); |
793 } | 794 } |
794 | 795 |
795 AppendSpellcheckOptionsSubMenu(); | 796 AppendSpellcheckOptionsSubMenu(); |
797 AppendSpeechInputOptionsSubMenu(); | |
796 | 798 |
797 #if defined(OS_MACOSX) | 799 #if defined(OS_MACOSX) |
798 // OS X provides a contextual menu to set writing direction for BiDi | 800 // OS X provides a contextual menu to set writing direction for BiDi |
799 // languages. | 801 // languages. |
800 // This functionality is exposed as a keyboard shortcut on Windows & Linux. | 802 // This functionality is exposed as a keyboard shortcut on Windows & Linux. |
801 AppendBidiSubMenu(); | 803 AppendBidiSubMenu(); |
802 #endif // OS_MACOSX | 804 #endif // OS_MACOSX |
803 | 805 |
804 menu_model_.AddSeparator(); | 806 menu_model_.AddSeparator(); |
805 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SELECTALL, | 807 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SELECTALL, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
846 IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL : | 848 IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL : |
847 IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL)); | 849 IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL)); |
848 } | 850 } |
849 | 851 |
850 menu_model_.AddSubMenu( | 852 menu_model_.AddSubMenu( |
851 IDC_SPELLCHECK_MENU, | 853 IDC_SPELLCHECK_MENU, |
852 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU), | 854 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU), |
853 &spellcheck_submenu_model_); | 855 &spellcheck_submenu_model_); |
854 } | 856 } |
855 | 857 |
858 void RenderViewContextMenu::AppendSpeechInputOptionsSubMenu() { | |
859 if (params_.speech_input_enabled) { | |
860 // Add 'Block offensive words' item in the sub menu. | |
Satish
2011/07/19 08:22:39
suggest removing this and the next comment as the
gshires
2011/07/19 22:56:31
Done.
| |
861 speech_input_submenu_model_.AddCheckItem( | |
862 IDC_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS, | |
863 l10n_util::GetStringUTF16( | |
864 IDS_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS)); | |
865 | |
866 // Add 'About voice recognition' item in the sub menu. | |
867 speech_input_submenu_model_.AddItemWithStringId( | |
868 IDC_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT, | |
869 IDS_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT); | |
870 | |
871 menu_model_.AddSubMenu( | |
872 IDC_SPEECH_INPUT_MENU, | |
873 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPEECH_INPUT_MENU), | |
874 &speech_input_submenu_model_); | |
875 } | |
876 } | |
877 | |
856 #if defined(OS_MACOSX) | 878 #if defined(OS_MACOSX) |
857 void RenderViewContextMenu::AppendBidiSubMenu() { | 879 void RenderViewContextMenu::AppendBidiSubMenu() { |
858 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_DEFAULT, | 880 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_DEFAULT, |
859 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT)); | 881 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT)); |
860 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_LTR, | 882 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_LTR, |
861 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR)); | 883 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR)); |
862 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_RTL, | 884 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_RTL, |
863 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL)); | 885 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL)); |
864 | 886 |
865 menu_model_.AddSubMenu( | 887 menu_model_.AddSubMenu( |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1183 case IDC_INPUT_METHODS_MENU: | 1205 case IDC_INPUT_METHODS_MENU: |
1184 return true; | 1206 return true; |
1185 #endif | 1207 #endif |
1186 | 1208 |
1187 case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE: | 1209 case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE: |
1188 return !params_.keyword_url.is_empty(); | 1210 return !params_.keyword_url.is_empty(); |
1189 | 1211 |
1190 case IDC_SPELLCHECK_MENU: | 1212 case IDC_SPELLCHECK_MENU: |
1191 return true; | 1213 return true; |
1192 | 1214 |
1215 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS: | |
1216 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT: | |
1217 case IDC_SPEECH_INPUT_MENU: | |
1218 return true; | |
1219 | |
1193 case IDC_CONTENT_CONTEXT_OPENLINKWITH: | 1220 case IDC_CONTENT_CONTEXT_OPENLINKWITH: |
1194 return true; | 1221 return true; |
1195 | 1222 |
1196 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS: | 1223 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS: |
1197 return true; | 1224 return true; |
1198 | 1225 |
1199 default: | 1226 default: |
1200 NOTREACHED(); | 1227 NOTREACHED(); |
1201 return false; | 1228 return false; |
1202 } | 1229 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1243 if (id == IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY) | 1270 if (id == IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY) |
1244 return false; | 1271 return false; |
1245 #endif // OS_MACOSX | 1272 #endif // OS_MACOSX |
1246 | 1273 |
1247 // Check box for 'Check the Spelling of this field'. | 1274 // Check box for 'Check the Spelling of this field'. |
1248 if (id == IDC_CHECK_SPELLING_OF_THIS_FIELD) { | 1275 if (id == IDC_CHECK_SPELLING_OF_THIS_FIELD) { |
1249 return (params_.spellcheck_enabled && | 1276 return (params_.spellcheck_enabled && |
1250 profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)); | 1277 profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)); |
1251 } | 1278 } |
1252 | 1279 |
1280 // Check box for menu item 'Block offensive words'. | |
1281 if (id == IDC_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS) { | |
1282 return (profile_->GetPrefs()->GetBoolean( | |
Satish
2011/07/19 08:22:39
remove brackets around the return value
gshires
2011/07/19 22:56:31
Done.
| |
1283 prefs::kSpeechInputCensorResults)); | |
1284 } | |
1285 | |
1253 // Don't bother getting the display language vector if this isn't a spellcheck | 1286 // Don't bother getting the display language vector if this isn't a spellcheck |
1254 // language. | 1287 // language. |
1255 if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) || | 1288 if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) || |
1256 (id >= IDC_SPELLCHECK_LANGUAGES_LAST)) | 1289 (id >= IDC_SPELLCHECK_LANGUAGES_LAST)) |
1257 return false; | 1290 return false; |
1258 | 1291 |
1259 std::vector<std::string> languages; | 1292 std::vector<std::string> languages; |
1260 return SpellCheckHost::GetSpellCheckLanguages(profile_, &languages) == | 1293 return SpellCheckHost::GetSpellCheckLanguages(profile_, &languages) == |
1261 (id - IDC_SPELLCHECK_LANGUAGES_FIRST); | 1294 (id - IDC_SPELLCHECK_LANGUAGES_FIRST); |
1262 } | 1295 } |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1655 if (tab_contents_wrapper && | 1688 if (tab_contents_wrapper && |
1656 tab_contents_wrapper->search_engine_tab_helper() && | 1689 tab_contents_wrapper->search_engine_tab_helper() && |
1657 tab_contents_wrapper->search_engine_tab_helper()->delegate()) { | 1690 tab_contents_wrapper->search_engine_tab_helper()->delegate()) { |
1658 // Takes ownership of |template_url|. | 1691 // Takes ownership of |template_url|. |
1659 tab_contents_wrapper->search_engine_tab_helper()->delegate()-> | 1692 tab_contents_wrapper->search_engine_tab_helper()->delegate()-> |
1660 ConfirmAddSearchProvider(template_url.release(), profile_); | 1693 ConfirmAddSearchProvider(template_url.release(), profile_); |
1661 } | 1694 } |
1662 break; | 1695 break; |
1663 } | 1696 } |
1664 | 1697 |
1698 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS: { | |
1699 PrefService* prefs = profile_->GetPrefs(); | |
1700 const bool censor = | |
1701 !prefs->GetBoolean(prefs::kSpeechInputCensorResults); | |
1702 prefs->SetBoolean(prefs::kSpeechInputCensorResults, censor); | |
1703 break; | |
1704 } | |
1705 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT: { | |
Satish
2011/07/19 08:22:39
add a newline above?
gshires
2011/07/19 22:56:31
Done.
| |
1706 rvh->SpeechInputAbout(); | |
1707 break; | |
1708 } | |
1709 | |
1665 default: | 1710 default: |
1666 NOTREACHED(); | 1711 NOTREACHED(); |
1667 break; | 1712 break; |
1668 } | 1713 } |
1669 } | 1714 } |
1670 | 1715 |
1671 ProtocolHandlerRegistry::ProtocolHandlerList | 1716 ProtocolHandlerRegistry::ProtocolHandlerList |
1672 RenderViewContextMenu::GetHandlersForLinkUrl() { | 1717 RenderViewContextMenu::GetHandlersForLinkUrl() { |
1673 ProtocolHandlerRegistry::ProtocolHandlerList handlers = | 1718 ProtocolHandlerRegistry::ProtocolHandlerList handlers = |
1674 protocol_handler_registry_->GetHandlersFor(params_.link_url.scheme()); | 1719 protocol_handler_registry_->GetHandlersFor(params_.link_url.scheme()); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1753 g_browser_process->clipboard()); | 1798 g_browser_process->clipboard()); |
1754 } | 1799 } |
1755 | 1800 |
1756 void RenderViewContextMenu::MediaPlayerActionAt( | 1801 void RenderViewContextMenu::MediaPlayerActionAt( |
1757 const gfx::Point& location, | 1802 const gfx::Point& location, |
1758 const WebMediaPlayerAction& action) { | 1803 const WebMediaPlayerAction& action) { |
1759 RenderViewHost* rvh = source_tab_contents_->render_view_host(); | 1804 RenderViewHost* rvh = source_tab_contents_->render_view_host(); |
1760 rvh->Send(new ViewMsg_MediaPlayerActionAt( | 1805 rvh->Send(new ViewMsg_MediaPlayerActionAt( |
1761 rvh->routing_id(), location, action)); | 1806 rvh->routing_id(), location, action)); |
1762 } | 1807 } |
OLD | NEW |