| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/clipboard.h" | 8 #include "base/clipboard.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 77 } |
| 78 | 78 |
| 79 void RenderViewContextMenu::AppendLinkItems() { | 79 void RenderViewContextMenu::AppendLinkItems() { |
| 80 AppendMenuItem(IDS_CONTENT_CONTEXT_OPENLINKNEWTAB); | 80 AppendMenuItem(IDS_CONTENT_CONTEXT_OPENLINKNEWTAB); |
| 81 AppendMenuItem(IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW); | 81 AppendMenuItem(IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW); |
| 82 AppendMenuItem(IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD); | 82 AppendMenuItem(IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD); |
| 83 AppendMenuItem(IDS_CONTENT_CONTEXT_SAVELINKAS); | 83 AppendMenuItem(IDS_CONTENT_CONTEXT_SAVELINKAS); |
| 84 | 84 |
| 85 if (params_.link_url.SchemeIs(chrome::kMailToScheme)) { | 85 if (params_.link_url.SchemeIs(chrome::kMailToScheme)) { |
| 86 AppendMenuItem(IDS_CONTENT_CONTEXT_COPYLINKLOCATION, | 86 AppendMenuItem(IDS_CONTENT_CONTEXT_COPYLINKLOCATION, |
| 87 l10n_util::GetString(IDS_CONTENT_CONTEXT_COPYEMAILADDRESS)); | 87 l10n_util::GetStringUTF16( |
| 88 IDS_CONTENT_CONTEXT_COPYEMAILADDRESS)); |
| 88 } else { | 89 } else { |
| 89 AppendMenuItem(IDS_CONTENT_CONTEXT_COPYLINKLOCATION); | 90 AppendMenuItem(IDS_CONTENT_CONTEXT_COPYLINKLOCATION); |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 | 93 |
| 93 void RenderViewContextMenu::AppendImageItems() { | 94 void RenderViewContextMenu::AppendImageItems() { |
| 94 AppendMenuItem(IDS_CONTENT_CONTEXT_SAVEIMAGEAS); | 95 AppendMenuItem(IDS_CONTENT_CONTEXT_SAVEIMAGEAS); |
| 95 AppendMenuItem(IDS_CONTENT_CONTEXT_COPYIMAGELOCATION); | 96 AppendMenuItem(IDS_CONTENT_CONTEXT_COPYIMAGELOCATION); |
| 96 AppendMenuItem(IDS_CONTENT_CONTEXT_COPYIMAGE); | 97 AppendMenuItem(IDS_CONTENT_CONTEXT_COPYIMAGE); |
| 97 AppendMenuItem(IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB); | 98 AppendMenuItem(IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 130 } |
| 130 | 131 |
| 131 void RenderViewContextMenu::AppendSearchProvider() { | 132 void RenderViewContextMenu::AppendSearchProvider() { |
| 132 DCHECK(profile_); | 133 DCHECK(profile_); |
| 133 const TemplateURL* const default_provider = | 134 const TemplateURL* const default_provider = |
| 134 profile_->GetTemplateURLModel()->GetDefaultSearchProvider(); | 135 profile_->GetTemplateURLModel()->GetDefaultSearchProvider(); |
| 135 if (default_provider != NULL) { | 136 if (default_provider != NULL) { |
| 136 std::wstring selection_text = | 137 std::wstring selection_text = |
| 137 l10n_util::TruncateString(params_.selection_text, 50); | 138 l10n_util::TruncateString(params_.selection_text, 50); |
| 138 if (!selection_text.empty()) { | 139 if (!selection_text.empty()) { |
| 139 std::wstring label(l10n_util::GetStringF(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, | 140 string16 label(WideToUTF16( |
| 140 default_provider->short_name(), | 141 l10n_util::GetStringF(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, |
| 141 selection_text)); | 142 default_provider->short_name(), |
| 143 selection_text))); |
| 142 AppendMenuItem(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, label); | 144 AppendMenuItem(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, label); |
| 143 } | 145 } |
| 144 } | 146 } |
| 145 } | 147 } |
| 146 | 148 |
| 147 void RenderViewContextMenu::AppendEditableItems() { | 149 void RenderViewContextMenu::AppendEditableItems() { |
| 148 // Append Dictionary spell check suggestions. | 150 // Append Dictionary spell check suggestions. |
| 149 for (size_t i = 0; i < params_.dictionary_suggestions.size() && | 151 for (size_t i = 0; i < params_.dictionary_suggestions.size() && |
| 150 IDC_SPELLCHECK_SUGGESTION_0 + i <= IDC_SPELLCHECK_SUGGESTION_LAST; | 152 IDC_SPELLCHECK_SUGGESTION_0 + i <= IDC_SPELLCHECK_SUGGESTION_LAST; |
| 151 ++i) { | 153 ++i) { |
| 152 AppendMenuItem(IDC_SPELLCHECK_SUGGESTION_0 + static_cast<int>(i), | 154 AppendMenuItem(IDC_SPELLCHECK_SUGGESTION_0 + static_cast<int>(i), |
| 153 params_.dictionary_suggestions[i]); | 155 WideToUTF16(params_.dictionary_suggestions[i])); |
| 154 } | 156 } |
| 155 if (params_.dictionary_suggestions.size() > 0) | 157 if (params_.dictionary_suggestions.size() > 0) |
| 156 AppendSeparator(); | 158 AppendSeparator(); |
| 157 | 159 |
| 158 // If word is misspelled, give option for "Add to dictionary" | 160 // If word is misspelled, give option for "Add to dictionary" |
| 159 if (!params_.misspelled_word.empty()) { | 161 if (!params_.misspelled_word.empty()) { |
| 160 if (params_.dictionary_suggestions.size() == 0) { | 162 if (params_.dictionary_suggestions.size() == 0) { |
| 161 AppendMenuItem(0, | 163 AppendMenuItem(0, |
| 162 l10n_util::GetString(IDS_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS)); | 164 l10n_util::GetStringUTF16( |
| 165 IDS_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS)); |
| 163 } | 166 } |
| 164 AppendMenuItem(IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY); | 167 AppendMenuItem(IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY); |
| 165 AppendSeparator(); | 168 AppendSeparator(); |
| 166 } | 169 } |
| 167 | 170 |
| 168 AppendMenuItem(IDS_CONTENT_CONTEXT_UNDO); | 171 AppendMenuItem(IDS_CONTENT_CONTEXT_UNDO); |
| 169 AppendMenuItem(IDS_CONTENT_CONTEXT_REDO); | 172 AppendMenuItem(IDS_CONTENT_CONTEXT_REDO); |
| 170 AppendSeparator(); | 173 AppendSeparator(); |
| 171 AppendMenuItem(IDS_CONTENT_CONTEXT_CUT); | 174 AppendMenuItem(IDS_CONTENT_CONTEXT_CUT); |
| 172 AppendMenuItem(IDS_CONTENT_CONTEXT_COPY); | 175 AppendMenuItem(IDS_CONTENT_CONTEXT_COPY); |
| 173 AppendMenuItem(IDS_CONTENT_CONTEXT_PASTE); | 176 AppendMenuItem(IDS_CONTENT_CONTEXT_PASTE); |
| 174 AppendMenuItem(IDS_CONTENT_CONTEXT_DELETE); | 177 AppendMenuItem(IDS_CONTENT_CONTEXT_DELETE); |
| 175 AppendSeparator(); | 178 AppendSeparator(); |
| 176 | 179 |
| 177 // Add Spell Check options sub menu. | 180 // Add Spell Check options sub menu. |
| 178 StartSubMenu(IDC_SPELLCHECK_MENU, | 181 StartSubMenu(IDC_SPELLCHECK_MENU, |
| 179 l10n_util::GetString(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU)); | 182 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU)); |
| 180 | 183 |
| 181 // Add Spell Check languages to sub menu. | 184 // Add Spell Check languages to sub menu. |
| 182 SpellChecker::Languages display_languages; | 185 SpellChecker::Languages spellcheck_languages; |
| 183 SpellChecker::GetSpellCheckLanguages(profile_, | 186 SpellChecker::GetSpellCheckLanguages(profile_, |
| 184 &display_languages); | 187 &spellcheck_languages); |
| 185 DCHECK(display_languages.size() < | 188 DCHECK(spellcheck_languages.size() < |
| 186 IDC_SPELLCHECK_LANGUAGES_LAST - IDC_SPELLCHECK_LANGUAGES_FIRST); | 189 IDC_SPELLCHECK_LANGUAGES_LAST - IDC_SPELLCHECK_LANGUAGES_FIRST); |
| 187 const std::wstring app_locale = g_browser_process->GetApplicationLocale(); | 190 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
| 188 for (size_t i = 0; i < display_languages.size(); ++i) { | 191 for (size_t i = 0; i < spellcheck_languages.size(); ++i) { |
| 189 std::wstring local_language(l10n_util::GetLocalName( | 192 string16 display_name(l10n_util::GetDisplayNameForLocale( |
| 190 display_languages[i], app_locale, true)); | 193 spellcheck_languages[i], app_locale, true)); |
| 191 AppendRadioMenuItem(IDC_SPELLCHECK_LANGUAGES_FIRST + i, local_language); | 194 AppendRadioMenuItem(IDC_SPELLCHECK_LANGUAGES_FIRST + i, display_name); |
| 192 } | 195 } |
| 193 | 196 |
| 194 // Add item in the sub menu to pop up the fonts and languages options menu. | 197 // Add item in the sub menu to pop up the fonts and languages options menu. |
| 195 AppendSeparator(); | 198 AppendSeparator(); |
| 196 AppendMenuItem(IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS); | 199 AppendMenuItem(IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS); |
| 197 | 200 |
| 198 // Add 'Check the spelling of this field' item in the sub menu. | 201 // Add 'Check the spelling of this field' item in the sub menu. |
| 199 AppendCheckboxMenuItem( | 202 AppendCheckboxMenuItem( |
| 200 IDC_CHECK_SPELLING_OF_THIS_FIELD, | 203 IDC_CHECK_SPELLING_OF_THIS_FIELD, |
| 201 l10n_util::GetString(IDS_CONTENT_CONTEXT_CHECK_SPELLING_OF_THIS_FIELD)); | 204 l10n_util::GetStringUTF16( |
| 205 IDS_CONTENT_CONTEXT_CHECK_SPELLING_OF_THIS_FIELD)); |
| 202 | 206 |
| 203 FinishSubMenu(); | 207 FinishSubMenu(); |
| 204 | 208 |
| 205 AppendSeparator(); | 209 AppendSeparator(); |
| 206 AppendMenuItem(IDS_CONTENT_CONTEXT_SELECTALL); | 210 AppendMenuItem(IDS_CONTENT_CONTEXT_SELECTALL); |
| 207 } | 211 } |
| 208 | 212 |
| 209 // Menu delegate functions ----------------------------------------------------- | 213 // Menu delegate functions ----------------------------------------------------- |
| 210 | 214 |
| 211 bool RenderViewContextMenu::IsItemCommandEnabled(int id) const { | 215 bool RenderViewContextMenu::IsItemCommandEnabled(int id) const { |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 // applications may not enocode non-ASCII characters in UTF-8. | 650 // applications may not enocode non-ASCII characters in UTF-8. |
| 647 // So the 4th parameter of net::FormatUrl() should be false. | 651 // So the 4th parameter of net::FormatUrl() should be false. |
| 648 // See crbug.com/2820. | 652 // See crbug.com/2820. |
| 649 WideToUTF8(net::FormatUrl( | 653 WideToUTF8(net::FormatUrl( |
| 650 url, profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), | 654 url, profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
| 651 false, UnescapeRule::NONE, NULL, NULL)); | 655 false, UnescapeRule::NONE, NULL, NULL)); |
| 652 | 656 |
| 653 WriteTextToClipboard(UTF8ToUTF16(utf8_text)); | 657 WriteTextToClipboard(UTF8ToUTF16(utf8_text)); |
| 654 DidWriteURLToClipboard(utf8_text); | 658 DidWriteURLToClipboard(utf8_text); |
| 655 } | 659 } |
| OLD | NEW |