summaryrefslogtreecommitdiffstats
path: root/chrome/browser/render_view_context_menu_controller.cc
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-10 22:28:58 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-10 22:28:58 +0000
commit4b4d1adc53b7e016b7966a38c48a31ec9e0aeda2 (patch)
treee4dbd1104b38920b387b0a94436a83ecfc7736e3 /chrome/browser/render_view_context_menu_controller.cc
parent0b847e38433afef0b207c85ae593d39501696aad (diff)
downloadchromium_src-4b4d1adc53b7e016b7966a38c48a31ec9e0aeda2.zip
chromium_src-4b4d1adc53b7e016b7966a38c48a31ec9e0aeda2.tar.gz
chromium_src-4b4d1adc53b7e016b7966a38c48a31ec9e0aeda2.tar.bz2
Cleanup part 6.
Lots of small things (mostly in spellcheck code), e.g.: * L"" -> std::wstring() * type *var; -> type* var; * Fix parameter line-wrapping to comply with style guide * Remove unnecessary classname scoping inside class delcaration * Remove empty declaration * Add/remove blank lines in hopes of increasing readability * Add block ("{", "}") around local use of a temporary that is later redefined * Fold temps into other statements where obvious * Use std::find() instead of hand-rolling the same functionality * Combine distinct cases in switch statements when they all do the same thing * Range-check to avoid some algorithmic work when it's not needed * at() -> [] ...and various others. Pretty much every change stands on its own. Do not hesitate to complain about changes you think are unhelpful to the code, this change is something of a dumping ground. (I did try to avoid the sort of gratuitous "const"-adding that has gotten me in trouble before :). ) Review URL: http://codereview.chromium.org/13688 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6745 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/render_view_context_menu_controller.cc')
-rw-r--r--chrome/browser/render_view_context_menu_controller.cc45
1 files changed, 25 insertions, 20 deletions
diff --git a/chrome/browser/render_view_context_menu_controller.cc b/chrome/browser/render_view_context_menu_controller.cc
index bedad0e..cbcef59 100644
--- a/chrome/browser/render_view_context_menu_controller.cc
+++ b/chrome/browser/render_view_context_menu_controller.cc
@@ -115,12 +115,12 @@ bool RenderViewContextMenuController::IsCommandEnabled(int id) const {
case IDS_CONTENT_CONTEXT_FORWARD:
return source_web_contents_->controller()->CanGoForward();
- case IDS_CONTENT_CONTEXT_RELOAD:
- return true;
+
case IDS_CONTENT_CONTEXT_VIEWPAGESOURCE:
case IDS_CONTENT_CONTEXT_VIEWFRAMESOURCE:
case IDS_CONTENT_CONTEXT_INSPECTELEMENT:
return IsDevCommandEnabled(id);
+
case IDS_CONTENT_CONTEXT_OPENLINKNEWTAB:
case IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW:
case IDS_CONTENT_CONTEXT_COPYLINKLOCATION:
@@ -137,8 +137,10 @@ bool RenderViewContextMenuController::IsCommandEnabled(int id) const {
case IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB:
case IDS_CONTENT_CONTEXT_COPYIMAGELOCATION:
return params_.image_url.is_valid();
+
case IDS_CONTENT_CONTEXT_SAVEPAGEAS:
return SavePackage::IsSavableURL(source_web_contents_->GetURL());
+
case IDS_CONTENT_CONTEXT_OPENFRAMENEWTAB:
case IDS_CONTENT_CONTEXT_OPENFRAMENEWWINDOW:
return params_.frame_url.is_valid();
@@ -172,6 +174,13 @@ bool RenderViewContextMenuController::IsCommandEnabled(int id) const {
return !source_web_contents_->profile()->IsOffTheRecord() &&
params_.frame_url.is_valid();
+ case IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY:
+ return !params_.misspelled_word.empty();
+
+ case IDS_CONTENT_CONTEXT_VIEWPAGEINFO:
+ return (source_web_contents_->controller()->GetActiveEntry() != NULL);
+
+ case IDS_CONTENT_CONTEXT_RELOAD:
case IDS_CONTENT_CONTEXT_COPYIMAGE:
case IDS_CONTENT_CONTEXT_PRINT:
case IDS_CONTENT_CONTEXT_SEARCHWEBFOR:
@@ -180,17 +189,11 @@ bool RenderViewContextMenuController::IsCommandEnabled(int id) const {
case IDC_SPELLCHECK_SUGGESTION_2:
case IDC_SPELLCHECK_SUGGESTION_3:
case IDC_SPELLCHECK_SUGGESTION_4:
- return true;
case IDC_SPELLCHECK_MENU:
- return true;
- case IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY:
- return !params_.misspelled_word.empty();
case IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS:
- return true;
- case IDS_CONTENT_CONTEXT_VIEWPAGEINFO:
- return (source_web_contents_->controller()->GetActiveEntry() != NULL);
case IDS_CONTENT_CONTEXT_VIEWFRAMEINFO:
return true;
+
case IDS_CONTENT_CONTEXT_SAVEFRAMEAS:
case IDS_CONTENT_CONTEXT_PRINTFRAME:
case IDS_CONTENT_CONTEXT_ADDSEARCHENGINE: // Not implemented.
@@ -200,14 +203,16 @@ bool RenderViewContextMenuController::IsCommandEnabled(int id) const {
}
bool RenderViewContextMenuController::IsItemChecked(int id) const {
- std::vector<std::wstring> display_language_vector;
- int spellcheck_language_index = SpellChecker::
- GetSpellCheckLanguagesToDisplayInContextMenu(
- source_web_contents_->profile(), &display_language_vector);
- if (id - IDC_SPELLCHECK_LANGUAGES_FIRST == spellcheck_language_index)
- return true;
+ // Don't bother getting the display language vector if this isn't a spellcheck
+ // language.
+ if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) ||
+ (id >= IDC_SPELLCHECK_LANGUAGES_LAST))
+ return false;
- return false;
+ std::vector<std::wstring> display_language_vector;
+ return SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu(
+ source_web_contents_->profile(), &display_language_vector) ==
+ (id - IDC_SPELLCHECK_LANGUAGES_FIRST);
}
bool RenderViewContextMenuController::GetAcceleratorInfo(
@@ -248,20 +253,20 @@ void RenderViewContextMenuController::ExecuteCommand(int id) {
// Check to see if one of the spell check language ids have been clicked.
if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
id < IDC_SPELLCHECK_LANGUAGES_LAST) {
+ const size_t language_number = id - IDC_SPELLCHECK_LANGUAGES_FIRST;
std::vector<std::wstring> display_language_vector;
SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu(
source_web_contents_->profile(), &display_language_vector);
- if (id - IDC_SPELLCHECK_LANGUAGES_FIRST <
- static_cast<int>(display_language_vector.size())) {
+ if (language_number < display_language_vector.size()) {
StringPrefMember dictionary_language;
dictionary_language.Init(prefs::kSpellCheckDictionary,
source_web_contents_->profile()->GetPrefs(), NULL);
- dictionary_language.SetValue(display_language_vector.at(
- id - IDC_SPELLCHECK_LANGUAGES_FIRST));
+ dictionary_language.SetValue(display_language_vector[language_number]);
}
return;
}
+
switch (id) {
case IDS_CONTENT_CONTEXT_OPENLINKNEWTAB:
OpenURL(params_.link_url, NEW_BACKGROUND_TAB, PageTransition::LINK);