| 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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 break; | 569 break; |
| 570 #ifdef WEBCONTEXT_MEDIATYPEFILE_DEFINED | 570 #ifdef WEBCONTEXT_MEDIATYPEFILE_DEFINED |
| 571 case WebContextMenuData::MediaTypeFile: | 571 case WebContextMenuData::MediaTypeFile: |
| 572 break; | 572 break; |
| 573 #endif | 573 #endif |
| 574 } | 574 } |
| 575 | 575 |
| 576 if (params_.is_editable) { | 576 if (params_.is_editable) { |
| 577 // Add a menu item that shows suggestions. | 577 // Add a menu item that shows suggestions. |
| 578 if (!spelling_menu_observer_.get()) { | 578 if (!spelling_menu_observer_.get()) { |
| 579 spelling_menu_observer_.reset( | 579 spelling_menu_observer_.reset(new SpellingMenuObserver(this)); |
| 580 new SpellingMenuObserver(this)); | |
| 581 } | 580 } |
| 582 if (spelling_menu_observer_.get()) | 581 if (spelling_menu_observer_.get()) { |
| 583 observers_.AddObserver(spelling_menu_observer_.get()); | 582 observers_.AddObserver(spelling_menu_observer_.get()); |
| 583 spelling_menu_observer_->InitMenu(params_); |
| 584 } |
| 584 } | 585 } |
| 585 | 586 |
| 586 // Ask our observers to add their menu items. | |
| 587 FOR_EACH_OBSERVER(RenderViewContextMenuObserver, observers_, | |
| 588 InitMenu(params_)); | |
| 589 | |
| 590 if (params_.is_editable) | 587 if (params_.is_editable) |
| 591 AppendEditableItems(); | 588 AppendEditableItems(); |
| 592 else if (has_selection) | 589 else if (has_selection) |
| 593 AppendCopyItem(); | 590 AppendCopyItem(); |
| 594 | 591 |
| 595 if (has_selection) | 592 if (has_selection) |
| 596 AppendSearchProvider(); | 593 AppendSearchProvider(); |
| 597 | 594 |
| 598 if (!IsDevToolsURL(params_.page_url)) | 595 if (!IsDevToolsURL(params_.page_url)) |
| 599 AppendAllExtensionItems(); | 596 AppendAllExtensionItems(); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 return; | 828 return; |
| 832 menu_model_.AddItem( | 829 menu_model_.AddItem( |
| 833 IDC_CONTENT_CONTEXT_SEARCHWEBFOR, | 830 IDC_CONTENT_CONTEXT_SEARCHWEBFOR, |
| 834 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, | 831 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, |
| 835 default_provider->short_name(), | 832 default_provider->short_name(), |
| 836 printable_selection_text)); | 833 printable_selection_text)); |
| 837 } | 834 } |
| 838 } | 835 } |
| 839 | 836 |
| 840 void RenderViewContextMenu::AppendEditableItems() { | 837 void RenderViewContextMenu::AppendEditableItems() { |
| 841 // Append Dictionary spell check suggestions. | |
| 842 for (size_t i = 0; i < params_.dictionary_suggestions.size() && | |
| 843 IDC_SPELLCHECK_SUGGESTION_0 + i <= IDC_SPELLCHECK_SUGGESTION_LAST; | |
| 844 ++i) { | |
| 845 menu_model_.AddItem(IDC_SPELLCHECK_SUGGESTION_0 + static_cast<int>(i), | |
| 846 params_.dictionary_suggestions[i]); | |
| 847 } | |
| 848 if (!params_.dictionary_suggestions.empty()) { | 838 if (!params_.dictionary_suggestions.empty()) { |
| 849 menu_model_.AddSeparator(); | 839 menu_model_.AddSeparator(); |
| 850 | 840 |
| 851 // |spellcheck_host| can be null when the suggested word is | 841 // |spellcheck_host| can be null when the suggested word is |
| 852 // provided by Web SpellCheck API. | 842 // provided by Web SpellCheck API. |
| 853 SpellCheckHost* spellcheck_host = profile_->GetSpellCheckHost(); | 843 SpellCheckHost* spellcheck_host = profile_->GetSpellCheckHost(); |
| 854 if (spellcheck_host && spellcheck_host->GetMetrics()) | 844 if (spellcheck_host && spellcheck_host->GetMetrics()) |
| 855 spellcheck_host->GetMetrics()->RecordSuggestionStats(1); | 845 spellcheck_host->GetMetrics()->RecordSuggestionStats(1); |
| 856 } | 846 } |
| 857 | 847 |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1227 return false; | 1217 return false; |
| 1228 } | 1218 } |
| 1229 return params_.media_type == WebContextMenuData::MediaTypeNone || | 1219 return params_.media_type == WebContextMenuData::MediaTypeNone || |
| 1230 params_.media_flags & WebContextMenuData::MediaCanPrint; | 1220 params_.media_flags & WebContextMenuData::MediaCanPrint; |
| 1231 | 1221 |
| 1232 case IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS: | 1222 case IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS: |
| 1233 return false; | 1223 return false; |
| 1234 | 1224 |
| 1235 case IDC_CONTENT_CONTEXT_SEARCHWEBFOR: | 1225 case IDC_CONTENT_CONTEXT_SEARCHWEBFOR: |
| 1236 case IDC_CONTENT_CONTEXT_GOTOURL: | 1226 case IDC_CONTENT_CONTEXT_GOTOURL: |
| 1237 case IDC_SPELLCHECK_SUGGESTION_0: | |
| 1238 case IDC_SPELLCHECK_SUGGESTION_1: | |
| 1239 case IDC_SPELLCHECK_SUGGESTION_2: | |
| 1240 case IDC_SPELLCHECK_SUGGESTION_3: | |
| 1241 case IDC_SPELLCHECK_SUGGESTION_4: | |
| 1242 case IDC_SPELLPANEL_TOGGLE: | 1227 case IDC_SPELLPANEL_TOGGLE: |
| 1243 #if !defined(OS_MACOSX) | 1228 #if !defined(OS_MACOSX) |
| 1244 // TODO(jeremy): re-enable - http://crbug.com/34512 . | 1229 // TODO(jeremy): re-enable - http://crbug.com/34512 . |
| 1245 case IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS: | 1230 case IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS: |
| 1246 #endif | 1231 #endif |
| 1247 case IDC_CONTENT_CONTEXT_VIEWFRAMEINFO: | 1232 case IDC_CONTENT_CONTEXT_VIEWFRAMEINFO: |
| 1248 return true; | 1233 return true; |
| 1249 | 1234 |
| 1250 case IDC_CHECK_SPELLING_OF_THIS_FIELD: | 1235 case IDC_CHECK_SPELLING_OF_THIS_FIELD: |
| 1251 return profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck); | 1236 return profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1682 WindowOpenDisposition disposition = | 1667 WindowOpenDisposition disposition = |
| 1683 ForceNewTabDispositionFromEventFlags(event_flags); | 1668 ForceNewTabDispositionFromEventFlags(event_flags); |
| 1684 OpenURL(selection_navigation_url_, | 1669 OpenURL(selection_navigation_url_, |
| 1685 GURL(), | 1670 GURL(), |
| 1686 params_.frame_id, | 1671 params_.frame_id, |
| 1687 disposition, | 1672 disposition, |
| 1688 content::PAGE_TRANSITION_LINK); | 1673 content::PAGE_TRANSITION_LINK); |
| 1689 break; | 1674 break; |
| 1690 } | 1675 } |
| 1691 | 1676 |
| 1692 case IDC_SPELLCHECK_SUGGESTION_0: | |
| 1693 case IDC_SPELLCHECK_SUGGESTION_1: | |
| 1694 case IDC_SPELLCHECK_SUGGESTION_2: | |
| 1695 case IDC_SPELLCHECK_SUGGESTION_3: | |
| 1696 case IDC_SPELLCHECK_SUGGESTION_4: { | |
| 1697 rvh->Replace( | |
| 1698 params_.dictionary_suggestions[id - IDC_SPELLCHECK_SUGGESTION_0]); | |
| 1699 // GetSpellCheckHost() can return null when the suggested word is | |
| 1700 // provided by Web SpellCheck API. | |
| 1701 SpellCheckHost* spellcheck_host = profile_->GetSpellCheckHost(); | |
| 1702 if (spellcheck_host && spellcheck_host->GetMetrics()) | |
| 1703 spellcheck_host->GetMetrics()->RecordReplacedWordStats(1); | |
| 1704 break; | |
| 1705 } | |
| 1706 case IDC_SPELLCHECK_ADD_TO_DICTIONARY: { | 1677 case IDC_SPELLCHECK_ADD_TO_DICTIONARY: { |
| 1707 // GetSpellCheckHost() can return null when the suggested word is | 1678 // GetSpellCheckHost() can return null when the suggested word is |
| 1708 // provided by Web SpellCheck API. | 1679 // provided by Web SpellCheck API. |
| 1709 if (profile_->GetSpellCheckHost()) | 1680 if (profile_->GetSpellCheckHost()) |
| 1710 profile_->GetSpellCheckHost()->AddWord( | 1681 profile_->GetSpellCheckHost()->AddWord( |
| 1711 UTF16ToUTF8(params_.misspelled_word)); | 1682 UTF16ToUTF8(params_.misspelled_word)); |
| 1712 SpellCheckerPlatform::AddWord(params_.misspelled_word); | 1683 SpellCheckerPlatform::AddWord(params_.misspelled_word); |
| 1713 break; | 1684 break; |
| 1714 } | 1685 } |
| 1715 | 1686 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1897 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), | 1868 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
| 1898 g_browser_process->clipboard()); | 1869 g_browser_process->clipboard()); |
| 1899 } | 1870 } |
| 1900 | 1871 |
| 1901 void RenderViewContextMenu::MediaPlayerActionAt( | 1872 void RenderViewContextMenu::MediaPlayerActionAt( |
| 1902 const gfx::Point& location, | 1873 const gfx::Point& location, |
| 1903 const WebMediaPlayerAction& action) { | 1874 const WebMediaPlayerAction& action) { |
| 1904 source_tab_contents_->render_view_host()-> | 1875 source_tab_contents_->render_view_host()-> |
| 1905 ExecuteMediaPlayerActionAtLocation(location, action); | 1876 ExecuteMediaPlayerActionAtLocation(location, action); |
| 1906 } | 1877 } |
| OLD | NEW |