diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-10 18:49:10 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-10 18:49:10 +0000 |
commit | 84214989a9be01a95c0f6f58cb22fbf2ab621952 (patch) | |
tree | 2c3bf1c8782c7f6dc9a3c73b98b59e0bfa490085 | |
parent | 89565f4825199719a6414ed7616832eab7dde006 (diff) | |
download | chromium_src-84214989a9be01a95c0f6f58cb22fbf2ab621952.zip chromium_src-84214989a9be01a95c0f6f58cb22fbf2ab621952.tar.gz chromium_src-84214989a9be01a95c0f6f58cb22fbf2ab621952.tar.bz2 |
Cleanup part 5.
Reorder identifiers, functions, initalization statements, etc. to all match. This preserves the original groups Ben created but makes a couple of changes:
* Within each group, the order is now "by GUI order" instead of random. This can be subjective, but when I tried doing alphabetical order, it resulted in related functionality being separated pretty arbitrarily.
* I moved the "window management" functions next to (but above) the "page-related" functions (this seemed a little more logical, but maybe not)
I also renamed UpdateNavigationCommands() to try and reflect that it updates a lot more than navigation commands, and moved some unconditionally-initialized commands (profile stuff) in there over to InitCommandState() where they belong.
Review URL: http://codereview.chromium.org/13681
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6721 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/chrome_dll.rc | 24 | ||||
-rw-r--r-- | chrome/app/chrome_dll_resource.h | 303 | ||||
-rw-r--r-- | chrome/browser/browser.cc | 647 | ||||
-rw-r--r-- | chrome/browser/browser.h | 75 |
4 files changed, 551 insertions, 498 deletions
diff --git a/chrome/app/chrome_dll.rc b/chrome/app/chrome_dll.rc index 6887ca0..f8005ad 100644 --- a/chrome/app/chrome_dll.rc +++ b/chrome/app/chrome_dll.rc @@ -38,7 +38,6 @@ BEGIN "W", IDC_CLOSE_TAB, VIRTKEY, CONTROL "W", IDC_CLOSE_POPUPS, VIRTKEY, SHIFT, ALT VK_OEM_3, IDC_DEBUGGER, VIRTKEY, ALT - "J", IDC_JS_CONSOLE, VIRTKEY, CONTROL, SHIFT "F", IDC_FIND, VIRTKEY, CONTROL "G", IDC_FIND_NEXT, VIRTKEY, CONTROL VK_F3, IDC_FIND_NEXT, VIRTKEY @@ -53,13 +52,14 @@ BEGIN VK_RIGHT, IDC_FORWARD, VIRTKEY, ALT VK_BACK, IDC_FORWARD, VIRTKEY, SHIFT VK_F1, IDC_HELP_PAGE, VIRTKEY + "J", IDC_JS_CONSOLE, VIRTKEY, CONTROL, SHIFT + "N", IDC_NEW_INCOGNITO_WINDOW, VIRTKEY, CONTROL, SHIFT "T", IDC_NEW_TAB, VIRTKEY, CONTROL "N", IDC_NEW_WINDOW, VIRTKEY, CONTROL - // CTRL + M is used for opening the dialog to let the user select - // a profile to open a new window. - // CTRL + SHIFT + N (N = 1 to 9) is used to let the user open a new - // window in profile 1 to profile 9 directly. - "M", IDC_SELECT_PROFILE, VIRTKEY, CONTROL + // NOTE: IDC_NEW_WINDOW_PROFILE_N is bound to the key ctrl-shift-(N+1), and + // opens a new window using profile number N. For example, + // IDC_NEW_WINDOW_PROFILE_0 is bound to ctrl-shift-1, and opens a window in + // profile 0. "1", IDC_NEW_WINDOW_PROFILE_0, VIRTKEY, CONTROL, SHIFT VK_NUMPAD1, IDC_NEW_WINDOW_PROFILE_0, VIRTKEY, CONTROL, SHIFT "2", IDC_NEW_WINDOW_PROFILE_1, VIRTKEY, CONTROL, SHIFT @@ -78,7 +78,6 @@ BEGIN VK_NUMPAD8, IDC_NEW_WINDOW_PROFILE_7, VIRTKEY, CONTROL, SHIFT "9", IDC_NEW_WINDOW_PROFILE_8, VIRTKEY, CONTROL, SHIFT VK_NUMPAD9, IDC_NEW_WINDOW_PROFILE_8, VIRTKEY, CONTROL, SHIFT - "N", IDC_NEW_INCOGNITO_WINDOW, VIRTKEY, CONTROL, SHIFT "O", IDC_OPEN_FILE, VIRTKEY, CONTROL "P", IDC_PRINT, VIRTKEY, CONTROL "R", IDC_RELOAD, VIRTKEY, CONTROL @@ -94,9 +93,10 @@ BEGIN VK_NEXT, IDC_SELECT_NEXT_TAB, VIRTKEY, CONTROL VK_TAB, IDC_SELECT_PREVIOUS_TAB, VIRTKEY, CONTROL, SHIFT VK_PRIOR, IDC_SELECT_PREVIOUS_TAB, VIRTKEY, CONTROL -// NOTE: IDC_SELECT_TAB_N is bound to the key N+1, and selects the tab at -// index N. For example, IDC_SELECT_TAB_0 is bound to control 1, and selects -// the tab at index 0. + "M", IDC_SELECT_PROFILE, VIRTKEY, CONTROL + // NOTE: IDC_SELECT_TAB_N is bound to the key ctrl-(N+1), and selects the + // tab at index N. For example, IDC_SELECT_TAB_0 is bound to ctrl-1, and + // selects the tab at index 0. "1", IDC_SELECT_TAB_0, VIRTKEY, CONTROL VK_NUMPAD1, IDC_SELECT_TAB_0, VIRTKEY, CONTROL "2", IDC_SELECT_TAB_1, VIRTKEY, CONTROL @@ -124,11 +124,11 @@ BEGIN VK_OEM_MINUS, IDC_ZOOM_MINUS, VIRTKEY, CONTROL VK_OEM_MINUS, IDC_ZOOM_MINUS, VIRTKEY, CONTROL, SHIFT VK_SUBTRACT, IDC_ZOOM_MINUS, VIRTKEY, CONTROL + "0", IDC_ZOOM_NORMAL, VIRTKEY, CONTROL + VK_NUMPAD0, IDC_ZOOM_NORMAL, VIRTKEY, CONTROL VK_OEM_PLUS, IDC_ZOOM_PLUS, VIRTKEY, CONTROL VK_OEM_PLUS, IDC_ZOOM_PLUS, VIRTKEY, CONTROL, SHIFT VK_ADD, IDC_ZOOM_PLUS, VIRTKEY, CONTROL - "0", IDC_ZOOM_NORMAL, VIRTKEY, CONTROL - VK_NUMPAD0, IDC_ZOOM_NORMAL, VIRTKEY, CONTROL END diff --git a/chrome/app/chrome_dll_resource.h b/chrome/app/chrome_dll_resource.h index edc7539..a1f6df5 100644 --- a/chrome/app/chrome_dll_resource.h +++ b/chrome/app/chrome_dll_resource.h @@ -2,14 +2,21 @@ // Microsoft Visual C++ generated include file. // Used by chrome_dll.rc // + #define IDR_MAINFRAME 101 + // Values around 200 are used by browser/browser_resources.h // Values around 300 are used by common/common_resources.h // Values around 400 are used by common/net/net_resources.h // Values around 500 are used by renderer/renderer_resources.h + +#define IDR_SAD_PLUGIN 1000 + // Values around 1600 are used by installer/setup/build/ // Values around 2000 are used by webkit/glue/webkit_resources.h + #define IDD_IPC_SETTINGS 3000 + #define IDC_View 4000 #define IDC_ViewHost 4001 #define IDC_Plugin 4002 @@ -27,151 +34,157 @@ #define IDC_NPObjectNone 4014 #define IDC_PluginHostAll 4015 #define IDC_PluginHostNone 4016 -#define IDC_BACK 32768 -#define IDC_FORWARD 32769 -#define IDC_STOP 32770 -#define IDC_RELOAD 32771 -#define IDC_GO 32772 -#define IDC_NEW_TAB 32773 -#define IDC_CLOSE_TAB 32774 -#define IDC_NEW_WINDOW 32775 -#define IDC_CLOSE_WINDOW 32776 -#define IDC_FOCUS_LOCATION 32777 -#define IDC_FOCUS_SEARCH 32778 -#define IDC_STAR 32779 -#define IDC_OPEN_CURRENT_URL 32780 -#define IDC_FIND 32781 -#define IDC_FIND_NEXT 32782 -#define IDC_FIND_PREVIOUS 32783 -#define IDC_CUT 32784 -#define IDC_COPY 32785 -#define IDC_PASTE 32786 -#define IDC_SAVE_PAGE 32787 -#define IDC_PRINT 32788 -#define IDC_VIEW_SOURCE 32789 -#define IDC_SELECT_NEXT_TAB 32790 -#define IDC_SELECT_PREVIOUS_TAB 32791 -#define IDC_SELECT_TAB_0 32792 -#define IDC_SELECT_TAB_1 32793 -#define IDC_SELECT_TAB_2 32794 -#define IDC_SELECT_TAB_3 32795 -#define IDC_SELECT_TAB_4 32796 -#define IDC_SELECT_TAB_5 32797 -#define IDC_SELECT_TAB_6 32798 -#define IDC_SELECT_TAB_7 32799 -#define IDC_SELECT_LAST_TAB 32800 -#define IDC_CREATE_SHORTCUTS 32801 -// Free space 32802 - 32804 -#define IDC_EDIT_SEARCH_ENGINES 32805 -#define IDC_ZOOM_PLUS 32806 -#define IDC_ZOOM_MINUS 32807 -#define IDC_ZOOM_NORMAL 32808 -#define IDC_OPEN_FILE 32809 -#define IDC_ZOOM_MENU 32810 -#define IDC_TASK_MANAGER 32812 -#define IDC_CLOSE_POPUPS 32813 -#define IDC_ALWAYS_ON_TOP 32814 -#define IDC_COPY_URL 32815 -#define IDC_JS_CONSOLE 32816 -#define IDC_DUPLICATE_TAB 32817 -#define IDC_NEW_INCOGNITO_WINDOW 32818 -#define IDC_VIEW_PASSWORDS 32819 -// Free space 32820 -#define IDC_SHOW_DOWNLOADS 32821 -#define IDC_HOME 32822 -#define IDC_SHOW_HISTORY 32823 -#define IDC_FOCUS_TOOLBAR 32825 -#define IDC_CLEAR_BROWSING_DATA 32826 -// Free space 32827 -#define IDC_APPMENU 32828 -#define IDC_ABOUT 32829 -#define IDC_IMPORT_SETTINGS 32830 -#define IDC_OPTIONS 32831 -#define IDC_REPORT_BUG 32832 -// Free space 32833 - 32890 -#define IDC_ENCODING_MENU 32891 -#define IDC_ENCODING_AUTO_DETECT 32892 -#define IDC_ENCODING_UTF8 32893 -#define IDC_ENCODING_UTF16LE 32894 -#define IDC_ENCODING_ISO88591 32895 -#define IDC_ENCODING_WINDOWS1252 32896 -#define IDC_ENCODING_GB2312 32897 -#define IDC_ENCODING_GB18030 32898 -#define IDC_ENCODING_BIG5 32899 -#define IDC_ENCODING_BIG5HKSCS 32900 -#define IDC_ENCODING_KOREAN 32901 -#define IDC_ENCODING_SHIFTJIS 32902 -#define IDC_ENCODING_ISO2022JP 32903 -#define IDC_ENCODING_EUCJP 32904 -#define IDC_ENCODING_THAI 32905 -#define IDC_ENCODING_ISO885915 32906 -#define IDC_ENCODING_MACINTOSH 32907 -#define IDC_ENCODING_ISO88592 32908 -#define IDC_ENCODING_WINDOWS1250 32909 -#define IDC_ENCODING_ISO88595 32910 -#define IDC_ENCODING_WINDOWS1251 32911 -#define IDC_ENCODING_KOI8R 32912 -#define IDC_ENCODING_KOI8U 32913 -#define IDC_ENCODING_ISO88597 32914 -#define IDC_ENCODING_WINDOWS1253 32915 -#define IDC_ENCODING_ISO88594 32916 -#define IDC_ENCODING_ISO885913 32917 -#define IDC_ENCODING_WINDOWS1257 32918 -#define IDC_ENCODING_ISO88593 32919 -#define IDC_ENCODING_ISO885910 32920 -#define IDC_ENCODING_ISO885914 32921 -#define IDC_ENCODING_ISO885916 32922 -#define IDC_ENCODING_WINDOWS1254 32923 -#define IDC_ENCODING_ISO88596 32924 -#define IDC_ENCODING_WINDOWS1256 32925 -#define IDC_ENCODING_ISO88598 32926 -#define IDC_ENCODING_WINDOWS1255 32927 -#define IDC_ENCODING_WINDOWS1258 32928 -// Free space 32929 -// Spell-check suggestions. -// If more suggestions have to be inserted, insert them before the _LAST -// These have to be consecutive. -#define IDC_SPELLCHECK_SUGGESTION_0 32930 -#define IDC_SPELLCHECK_SUGGESTION_1 32931 -#define IDC_SPELLCHECK_SUGGESTION_2 32932 -#define IDC_SPELLCHECK_SUGGESTION_3 32933 -#define IDC_SPELLCHECK_SUGGESTION_4 32934 -// We leave some empty room here (35-39) in case we need to grow. -#define IDC_SPELLCHECK_SUGGESTION_LAST IDC_SPELLCHECK_SUGGESTION_4 -#define IDC_RESTORE_TAB 32940 -#define IDC_SHOW_AS_TAB 32941 -#define IDC_EXIT 32942 -#define IDC_DEBUGGER 32943 -#define IDC_DEVELOPER_MENU 32944 -#define IDC_HELP_PAGE 32945 -#define IDC_SHOW_BOOKMARK_BAR 32946 -// Free space 32947 - 32950 -#define IDR_SAD_PLUGIN 32951 -#define IDC_SHOW_BOOKMARK_MANAGER 32952 -#define IDC_SPELLCHECK_MENU 32953 -// Reserve space for 100 Spell Check languages - currently we have 30. -#define IDC_SPELLCHECK_LANGUAGES_FIRST 32954 -#define IDC_SPELLCHECK_LANGUAGES_LAST 33054 -// We have a menu item for opening a new window in a specific profile, and it -// has dynamic number of sub menu items. The number of sub menu items depends on -// the number of existing profiles. But we only show menu items for nine -// different profiles, plus a menu item for other than the nine profiles (if -// there are more than nine profiles), plus a menu item for new profile. -#define IDC_PROFILE_MENU 33055 -#define IDC_SELECT_PROFILE 33056 -#define IDC_NEW_PROFILE 33057 -// Define menu IDs for nine profiles to provide accelarators like CTRL + -// SHIFT + 1, CTRL + SHIFT + 2, etc. for them. -#define IDC_NEW_WINDOW_PROFILE_0 33058 -#define IDC_NEW_WINDOW_PROFILE_1 33059 -#define IDC_NEW_WINDOW_PROFILE_2 33060 -#define IDC_NEW_WINDOW_PROFILE_3 33061 -#define IDC_NEW_WINDOW_PROFILE_4 33062 -#define IDC_NEW_WINDOW_PROFILE_5 33063 -#define IDC_NEW_WINDOW_PROFILE_6 33064 -#define IDC_NEW_WINDOW_PROFILE_7 33065 -#define IDC_NEW_WINDOW_PROFILE_8 33066 + +// NOTE: Within each of the following sections, the IDs are ordered roughly by +// how they appear in the GUI/menus (left to right, top to bottom, etc.). + +// Navigation commands +#define IDC_BACK 33000 +#define IDC_FORWARD 33001 +#define IDC_RELOAD 33002 +#define IDC_HOME 33003 +#define IDC_OPEN_CURRENT_URL 33004 +#define IDC_GO 33005 +#define IDC_STOP 33006 + +// Window management commands +#define IDC_NEW_WINDOW 34000 +#define IDC_NEW_INCOGNITO_WINDOW 34001 +#define IDC_PROFILE_MENU 34002 +// Insert any additional profile values before _LAST; these have to be +// consecutive. +#define IDC_NEW_WINDOW_PROFILE_0 34003 +#define IDC_NEW_WINDOW_PROFILE_1 34004 +#define IDC_NEW_WINDOW_PROFILE_2 34005 +#define IDC_NEW_WINDOW_PROFILE_3 34006 +#define IDC_NEW_WINDOW_PROFILE_4 34007 +#define IDC_NEW_WINDOW_PROFILE_5 34008 +#define IDC_NEW_WINDOW_PROFILE_6 34009 +#define IDC_NEW_WINDOW_PROFILE_7 34010 +#define IDC_NEW_WINDOW_PROFILE_8 34011 #define IDC_NEW_WINDOW_PROFILE_LAST IDC_NEW_WINDOW_PROFILE_8 +#define IDC_CLOSE_WINDOW 34012 +#define IDC_ALWAYS_ON_TOP 34013 +#define IDC_NEW_TAB 34014 +#define IDC_CLOSE_TAB 34015 +#define IDC_SELECT_NEXT_TAB 34016 +#define IDC_SELECT_PREVIOUS_TAB 34017 +#define IDC_SELECT_TAB_0 34018 +#define IDC_SELECT_TAB_1 34019 +#define IDC_SELECT_TAB_2 34020 +#define IDC_SELECT_TAB_3 34021 +#define IDC_SELECT_TAB_4 34022 +#define IDC_SELECT_TAB_5 34023 +#define IDC_SELECT_TAB_6 34024 +#define IDC_SELECT_TAB_7 34025 +#define IDC_SELECT_LAST_TAB 34026 +#define IDC_DUPLICATE_TAB 34027 +#define IDC_RESTORE_TAB 34028 +#define IDC_SHOW_AS_TAB 34029 +#define IDC_EXIT 34030 + +// Page-related commands +#define IDC_STAR 35000 +#define IDC_VIEW_SOURCE 35001 +#define IDC_CLOSE_POPUPS 35002 +#define IDC_PRINT 35003 +#define IDC_SAVE_PAGE 35004 +#define IDC_ENCODING_MENU 35005 +#define IDC_ENCODING_AUTO_DETECT 35006 +#define IDC_ENCODING_UTF8 35007 +#define IDC_ENCODING_UTF16LE 35008 +#define IDC_ENCODING_ISO88591 35009 +#define IDC_ENCODING_WINDOWS1252 35010 +#define IDC_ENCODING_GB2312 35011 +#define IDC_ENCODING_GB18030 35012 +#define IDC_ENCODING_BIG5 35013 +#define IDC_ENCODING_BIG5HKSCS 35014 +#define IDC_ENCODING_KOREAN 35015 +#define IDC_ENCODING_SHIFTJIS 35016 +#define IDC_ENCODING_ISO2022JP 35017 +#define IDC_ENCODING_EUCJP 35018 +#define IDC_ENCODING_THAI 35019 +#define IDC_ENCODING_ISO885915 35020 +#define IDC_ENCODING_MACINTOSH 35021 +#define IDC_ENCODING_ISO88592 35022 +#define IDC_ENCODING_WINDOWS1250 35023 +#define IDC_ENCODING_ISO88595 35024 +#define IDC_ENCODING_WINDOWS1251 35025 +#define IDC_ENCODING_KOI8R 35026 +#define IDC_ENCODING_KOI8U 35027 +#define IDC_ENCODING_ISO88597 35028 +#define IDC_ENCODING_WINDOWS1253 35029 +#define IDC_ENCODING_ISO88594 35030 +#define IDC_ENCODING_ISO885913 35031 +#define IDC_ENCODING_WINDOWS1257 35032 +#define IDC_ENCODING_ISO88593 35033 +#define IDC_ENCODING_ISO885910 35034 +#define IDC_ENCODING_ISO885914 35035 +#define IDC_ENCODING_ISO885916 35036 +#define IDC_ENCODING_WINDOWS1254 35037 +#define IDC_ENCODING_ISO88596 35038 +#define IDC_ENCODING_WINDOWS1256 35039 +#define IDC_ENCODING_ISO88598 35040 +#define IDC_ENCODING_WINDOWS1255 35041 +#define IDC_ENCODING_WINDOWS1258 35042 + +// Clipboard commands +#define IDC_CUT 36000 +#define IDC_COPY 36001 +#define IDC_COPY_URL 36002 +#define IDC_PASTE 36003 + +// Find-in-page +#define IDC_FIND 37000 +#define IDC_FIND_NEXT 37001 +#define IDC_FIND_PREVIOUS 37002 + +// Zoom +#define IDC_ZOOM_MENU 38000 +#define IDC_ZOOM_PLUS 38001 +#define IDC_ZOOM_NORMAL 38002 +#define IDC_ZOOM_MINUS 38003 + +// Focus various bits of UI +#define IDC_FOCUS_TOOLBAR 39000 +#define IDC_FOCUS_LOCATION 39001 +#define IDC_FOCUS_SEARCH 39002 + +// Show various bits of UI +#define IDC_OPEN_FILE 40000 +#define IDC_CREATE_SHORTCUTS 40001 +#define IDC_DEVELOPER_MENU 40002 +#define IDC_DEBUGGER 40003 +#define IDC_JS_CONSOLE 40004 +#define IDC_TASK_MANAGER 40005 +#define IDC_SELECT_PROFILE 40006 +#define IDC_NEW_PROFILE 40007 +#define IDC_REPORT_BUG 40008 +#define IDC_SHOW_BOOKMARK_BAR 40009 +#define IDC_SHOW_HISTORY 40010 +#define IDC_SHOW_BOOKMARK_MANAGER 40011 +#define IDC_SHOW_DOWNLOADS 40012 +#define IDC_CLEAR_BROWSING_DATA 40013 +#define IDC_IMPORT_SETTINGS 40014 +#define IDC_OPTIONS 40015 +#define IDC_EDIT_SEARCH_ENGINES 40016 +#define IDC_VIEW_PASSWORDS 40017 +#define IDC_ABOUT 40018 +#define IDC_HELP_PAGE 40019 + +// Spell-check +// Insert any additional suggestions before _LAST; these have to be consecutive. +#define IDC_SPELLCHECK_SUGGESTION_0 41000 +#define IDC_SPELLCHECK_SUGGESTION_1 41001 +#define IDC_SPELLCHECK_SUGGESTION_2 41002 +#define IDC_SPELLCHECK_SUGGESTION_3 41003 +#define IDC_SPELLCHECK_SUGGESTION_4 41004 +#define IDC_SPELLCHECK_SUGGESTION_LAST IDC_SPELLCHECK_SUGGESTION_4 +#define IDC_SPELLCHECK_MENU 41005 +// Language entries are inserted using autogenerated values between +// [_FIRST, _LAST). +#define IDC_SPELLCHECK_LANGUAGES_FIRST 41006 +#define IDC_SPELLCHECK_LANGUAGES_LAST 41106 // Next default values for new objects // @@ -179,7 +192,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC 1 #define _APS_NEXT_RESOURCE_VALUE 3001 -#define _APS_NEXT_COMMAND_VALUE 33067 +#define _APS_NEXT_COMMAND_VALUE 42000 #define _APS_NEXT_CONTROL_VALUE 4017 #define _APS_NEXT_SYMED_VALUE 1001 #endif diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 41d59a9..a483241 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -607,11 +607,6 @@ void Browser::Reload() { } } -void Browser::Stop() { - UserMetrics::RecordAction(L"Stop", profile_); - GetSelectedTabContents()->AsWebContents()->Stop(); -} - void Browser::Home() { UserMetrics::RecordAction(L"Home", profile_); GURL homepage_url = GetHomePage(); @@ -619,13 +614,6 @@ void Browser::Home() { homepage_url, GURL(), PageTransition::AUTO_BOOKMARK); } -void Browser::Go() { - UserMetrics::RecordAction(L"Go", profile_); - LocationBarView* lbv = GetLocationBarView(); - if (lbv) - lbv->location_entry()->model()->AcceptInput(CURRENT_TAB, false); -} - void Browser::OpenCurrentURL() { UserMetrics::RecordAction(L"LoadURL", profile_); LocationBarView* lbv = GetLocationBarView(); @@ -635,20 +623,16 @@ void Browser::OpenCurrentURL() { } } -void Browser::NewTab() { - UserMetrics::RecordAction(L"NewTab", profile_); - if (type() == TYPE_NORMAL) { - AddBlankTab(true); - } else { - Browser* b = GetOrCreateTabbedBrowser(); - b->AddBlankTab(true); - b->window()->Show(); - } +void Browser::Go() { + UserMetrics::RecordAction(L"Go", profile_); + LocationBarView* lbv = GetLocationBarView(); + if (lbv) + lbv->location_entry()->model()->AcceptInput(CURRENT_TAB, false); } -void Browser::CloseTab() { - UserMetrics::RecordAction(L"CloseTab_Accelerator", profile_); - tabstrip_model_.CloseTabContentsAt(tabstrip_model_.selected_index()); +void Browser::Stop() { + UserMetrics::RecordAction(L"Stop", profile_); + GetSelectedTabContents()->AsWebContents()->Stop(); } void Browser::NewWindow() { @@ -656,14 +640,9 @@ void Browser::NewWindow() { Browser::OpenEmptyWindow(profile_->GetOriginalProfile()); } -void Browser::OpenSelectProfileDialog() { - UserMetrics::RecordAction(L"SelectProfile", profile_); - SelectProfileDialog::RunDialog(); -} - -void Browser::OpenNewProfileDialog() { - UserMetrics::RecordAction(L"CreateProfile", profile_); - NewProfileDialog::RunDialog(); +void Browser::NewIncognitoWindow() { + UserMetrics::RecordAction(L"NewIncognitoWindow", profile_); + Browser::OpenEmptyWindow(profile_->GetOffTheRecordProfile()); } void Browser::NewProfileWindowByIndex(int index) { @@ -671,16 +650,27 @@ void Browser::NewProfileWindowByIndex(int index) { UserDataManager::Get()->LaunchChromeForProfile(index); } -void Browser::NewIncognitoWindow() { - UserMetrics::RecordAction(L"NewIncognitoWindow", profile_); - Browser::OpenEmptyWindow(profile_->GetOffTheRecordProfile()); -} - void Browser::CloseWindow() { UserMetrics::RecordAction(L"CloseWindow", profile_); window_->Close(); } +void Browser::NewTab() { + UserMetrics::RecordAction(L"NewTab", profile_); + if (type() == TYPE_NORMAL) { + AddBlankTab(true); + } else { + Browser* b = GetOrCreateTabbedBrowser(); + b->AddBlankTab(true); + b->window()->Show(); + } +} + +void Browser::CloseTab() { + UserMetrics::RecordAction(L"CloseTab_Accelerator", profile_); + tabstrip_model_.CloseTabContentsAt(tabstrip_model_.selected_index()); +} + void Browser::SelectNextTab() { UserMetrics::RecordAction(L"SelectNextTab", profile_); tabstrip_model_.SelectNextTab(); @@ -737,6 +727,96 @@ void Browser::Exit() { BrowserList::CloseAllBrowsers(true); } +void Browser::BookmarkCurrentPage() { + UserMetrics::RecordAction(L"Star", profile_); + + TabContents* tab = GetSelectedTabContents(); + if (!tab->AsWebContents()) + return; + + WebContents* rvh = tab->AsWebContents(); + BookmarkModel* model = tab->profile()->GetBookmarkModel(); + if (!model || !model->IsLoaded()) + return; // Ignore requests until bookmarks are loaded. + + NavigationEntry* entry = rvh->controller()->GetActiveEntry(); + if (!entry) + return; // Can't star if there is no URL. + const GURL& url = entry->display_url(); + if (url.is_empty() || !url.is_valid()) + return; + + if (window_->GetStarButton()) { + if (!window_->GetStarButton()->is_bubble_showing()) { + const bool newly_bookmarked = !model->IsBookmarked(url); + if (newly_bookmarked) { + model->SetURLStarred(url, entry->title(), true); + if (!model->IsBookmarked(url)) { + // Starring failed. This shouldn't happen. + NOTREACHED(); + return; + } + } + window_->GetStarButton()->ShowStarBubble(url, newly_bookmarked); + } + } else if (model->IsBookmarked(url)) { + // If we can't find the star button and the user wanted to unstar it, + // go ahead and unstar it without showing the bubble. + model->SetURLStarred(url, std::wstring(), false); + } +} + +void Browser::ViewSource() { + UserMetrics::RecordAction(L"ViewSource", profile_); + + TabContents* current_tab = GetSelectedTabContents(); + NavigationEntry* entry = current_tab->controller()->GetLastCommittedEntry(); + if (entry) { + GURL url("view-source:" + entry->url().spec()); + AddTabWithURL(url, GURL(), PageTransition::LINK, true, NULL); + } +} + +void Browser::ClosePopups() { + UserMetrics::RecordAction(L"CloseAllSuppressedPopups", profile_); + GetSelectedTabContents()->CloseAllSuppressedPopups(); +} + +void Browser::Print() { + UserMetrics::RecordAction(L"PrintPreview", profile_); + GetSelectedTabContents()->AsWebContents()->PrintPreview(); +} + +void Browser::SavePage() { + UserMetrics::RecordAction(L"SavePage", profile_); + GetSelectedTabContents()->AsWebContents()->OnSavePage(); +} + +void Browser::ToggleEncodingAutoDetect() { + UserMetrics::RecordAction(L"AutoDetectChange", profile_); + encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue()); + // Reload the page so we can try to auto-detect the charset. + Reload(); +} + +void Browser::OverrideEncoding(int encoding_id) { + UserMetrics::RecordAction(L"OverrideEncoding", profile_); + const std::wstring selected_encoding = + CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id); + TabContents* current_tab = GetSelectedTabContents(); + if (!selected_encoding.empty() && current_tab->AsWebContents()) + current_tab->AsWebContents()->override_encoding(selected_encoding); + // Update the list of recently selected encodings. + std::wstring new_selected_encoding_list; + if (CharacterEncoding::UpdateRecentlySelectdEncoding( + profile_->GetPrefs()->GetString(prefs::kRecentlySelectedEncoding), + encoding_id, + &new_selected_encoding_list)) { + profile_->GetPrefs()->SetString(prefs::kRecentlySelectedEncoding, + new_selected_encoding_list); + } +} + // TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always // enabled in the page menu regardless of whether the command will do // anything. When someone selects the menu item, we just act as if they hit @@ -806,16 +886,21 @@ void Browser::ZoomIn() { PageZoom::LARGER); } +void Browser::ZoomReset() { + UserMetrics::RecordAction(L"ZoomNormal", profile_); + GetSelectedTabContents()->AsWebContents()->render_view_host()->Zoom( + PageZoom::STANDARD); +} + void Browser::ZoomOut() { UserMetrics::RecordAction(L"ZoomMinus", profile_); GetSelectedTabContents()->AsWebContents()->render_view_host()->Zoom( PageZoom::SMALLER); } -void Browser::ZoomReset() { - UserMetrics::RecordAction(L"ZoomNormal", profile_); - GetSelectedTabContents()->AsWebContents()->render_view_host()->Zoom( - PageZoom::STANDARD); +void Browser::FocusToolbar() { + UserMetrics::RecordAction(L"FocusToolbar", profile_); + window_->FocusToolbar(); } void Browser::FocusLocationBar() { @@ -839,119 +924,22 @@ void Browser::FocusSearch() { } } -void Browser::FocusToolbar() { - UserMetrics::RecordAction(L"FocusToolbar", profile_); - window_->FocusToolbar(); -} - -void Browser::BookmarkCurrentPage() { - UserMetrics::RecordAction(L"Star", profile_); - - TabContents* tab = GetSelectedTabContents(); - if (!tab->AsWebContents()) - return; - - WebContents* rvh = tab->AsWebContents(); - BookmarkModel* model = tab->profile()->GetBookmarkModel(); - if (!model || !model->IsLoaded()) - return; // Ignore requests until bookmarks are loaded. - - NavigationEntry* entry = rvh->controller()->GetActiveEntry(); - if (!entry) - return; // Can't star if there is no URL. - const GURL& url = entry->display_url(); - if (url.is_empty() || !url.is_valid()) - return; - - if (window_->GetStarButton()) { - if (!window_->GetStarButton()->is_bubble_showing()) { - const bool newly_bookmarked = !model->IsBookmarked(url); - if (newly_bookmarked) { - model->SetURLStarred(url, entry->title(), true); - if (!model->IsBookmarked(url)) { - // Starring failed. This shouldn't happen. - NOTREACHED(); - return; - } - } - window_->GetStarButton()->ShowStarBubble(url, newly_bookmarked); - } - } else if (model->IsBookmarked(url)) { - // If we can't find the star button and the user wanted to unstar it, - // go ahead and unstar it without showing the bubble. - model->SetURLStarred(url, std::wstring(), false); - } -} - -void Browser::ViewSource() { - UserMetrics::RecordAction(L"ViewSource", profile_); - - TabContents* current_tab = GetSelectedTabContents(); - NavigationEntry* entry = current_tab->controller()->GetLastCommittedEntry(); - if (entry) { - GURL url("view-source:" + entry->url().spec()); - AddTabWithURL(url, GURL(), PageTransition::LINK, true, NULL); - } -} - -void Browser::ClosePopups() { - UserMetrics::RecordAction(L"CloseAllSuppressedPopups", profile_); - GetSelectedTabContents()->CloseAllSuppressedPopups(); -} - -void Browser::Print() { - UserMetrics::RecordAction(L"PrintPreview", profile_); - GetSelectedTabContents()->AsWebContents()->PrintPreview(); -} - -void Browser::SavePage() { - UserMetrics::RecordAction(L"SavePage", profile_); - GetSelectedTabContents()->AsWebContents()->OnSavePage(); -} - -void Browser::ToggleEncodingAutoDetect() { - UserMetrics::RecordAction(L"AutoDetectChange", profile_); - encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue()); - // Reload the page so we can try to auto-detect the charset. - Reload(); -} - -void Browser::OverrideEncoding(int encoding_id) { - UserMetrics::RecordAction(L"OverrideEncoding", profile_); - const std::wstring selected_encoding = - CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id); - TabContents* current_tab = GetSelectedTabContents(); - if (!selected_encoding.empty() && current_tab->AsWebContents()) - current_tab->AsWebContents()->override_encoding(selected_encoding); - // Update the list of recently selected encodings. - std::wstring new_selected_encoding_list; - if (CharacterEncoding::UpdateRecentlySelectdEncoding( - profile_->GetPrefs()->GetString(prefs::kRecentlySelectedEncoding), - encoding_id, - &new_selected_encoding_list)) { - profile_->GetPrefs()->SetString(prefs::kRecentlySelectedEncoding, - new_selected_encoding_list); - } -} - -void Browser::OpenKeywordEditor() { - UserMetrics::RecordAction(L"EditSearchEngines", profile_); - window_->ShowSearchEnginesDialog(); -} - -void Browser::OpenClearBrowsingDataDialog() { - UserMetrics::RecordAction(L"ClearBrowsingData_ShowDlg", profile_); - window_->ShowClearBrowsingDataDialog(); -} +void Browser::OpenFile() { + UserMetrics::RecordAction(L"OpenFile", profile_); + if (!select_file_dialog_.get()) + select_file_dialog_ = SelectFileDialog::Create(this); -void Browser::OpenImportSettingsDialog() { - UserMetrics::RecordAction(L"Import_ShowDlg", profile_); - window_->ShowImportDialog(); + // TODO(beng): figure out how to juggle this. + HWND parent_hwnd = reinterpret_cast<HWND>(window_->GetNativeHandle()); + select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, + std::wstring(), std::wstring(), + std::wstring(), std::wstring(), + parent_hwnd, NULL); } -void Browser::OpenBugReportDialog() { - UserMetrics::RecordAction(L"ReportBug", profile_); - window_->ShowReportBugDialog(); +void Browser::OpenCreateShortcutsDialog() { + UserMetrics::RecordAction(L"CreateShortcut", profile_); + GetSelectedTabContents()->AsWebContents()->CreateShortcut(); } void Browser::OpenDebuggerWindow() { @@ -976,47 +964,29 @@ void Browser::OpenJavaScriptConsole() { ShowJavaScriptConsole(); } -void Browser::OpenCreateShortcutsDialog() { - UserMetrics::RecordAction(L"CreateShortcut", profile_); - GetSelectedTabContents()->AsWebContents()->CreateShortcut(); -} - -void Browser::OpenPasswordManager() { - window_->ShowPasswordManager(); -} - -void Browser::OpenAboutChromeDialog() { - UserMetrics::RecordAction(L"AboutChrome", profile_); - window_->ShowAboutChromeDialog(); +void Browser::OpenTaskManager() { + UserMetrics::RecordAction(L"TaskManager", profile_); + TaskManager::Open(); } -void Browser::OpenFile() { - UserMetrics::RecordAction(L"OpenFile", profile_); - if (!select_file_dialog_.get()) - select_file_dialog_ = SelectFileDialog::Create(this); - - // TODO(beng): figure out how to juggle this. - HWND parent_hwnd = reinterpret_cast<HWND>(window_->GetNativeHandle()); - select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, - std::wstring(), std::wstring(), - std::wstring(), std::wstring(), - parent_hwnd, NULL); +void Browser::OpenSelectProfileDialog() { + UserMetrics::RecordAction(L"SelectProfile", profile_); + SelectProfileDialog::RunDialog(); } -void Browser::OpenTaskManager() { - UserMetrics::RecordAction(L"TaskManager", profile_); - TaskManager::Open(); +void Browser::OpenNewProfileDialog() { + UserMetrics::RecordAction(L"CreateProfile", profile_); + NewProfileDialog::RunDialog(); } -void Browser::OpenOptionsDialog() { - UserMetrics::RecordAction(L"ShowOptions", profile_); - ShowOptionsWindow(OPTIONS_PAGE_DEFAULT, OPTIONS_GROUP_NONE, profile_); +void Browser::OpenBugReportDialog() { + UserMetrics::RecordAction(L"ReportBug", profile_); + window_->ShowReportBugDialog(); } -void Browser::OpenHelpTab() { - GURL help_url(l10n_util::GetString(IDS_HELP_CONTENT_URL)); - AddTabWithURL(help_url, GURL(), PageTransition::AUTO_BOOKMARK, true, - NULL); +void Browser::ToggleBookmarkBar() { + UserMetrics::RecordAction(L"ShowBookmarksBar", profile_); + window_->ToggleBookmarkBar(); } void Browser::ShowHistoryTab() { @@ -1024,19 +994,49 @@ void Browser::ShowHistoryTab() { ShowNativeUITab(HistoryTabUI::GetURL()); } +void Browser::OpenBookmarkManager() { + UserMetrics::RecordAction(L"ShowBookmarkManager", profile_); + window_->ShowBookmarkManager(); +} + void Browser::ShowDownloadsTab() { UserMetrics::RecordAction(L"ShowDownloads", profile_); ShowNativeUITab(DownloadTabUI::GetURL()); } -void Browser::OpenBookmarkManager() { - UserMetrics::RecordAction(L"ShowBookmarkManager", profile_); - window_->ShowBookmarkManager(); +void Browser::OpenClearBrowsingDataDialog() { + UserMetrics::RecordAction(L"ClearBrowsingData_ShowDlg", profile_); + window_->ShowClearBrowsingDataDialog(); } -void Browser::ToggleBookmarkBar() { - UserMetrics::RecordAction(L"ShowBookmarksBar", profile_); - window_->ToggleBookmarkBar(); +void Browser::OpenImportSettingsDialog() { + UserMetrics::RecordAction(L"Import_ShowDlg", profile_); + window_->ShowImportDialog(); +} + +void Browser::OpenOptionsDialog() { + UserMetrics::RecordAction(L"ShowOptions", profile_); + ShowOptionsWindow(OPTIONS_PAGE_DEFAULT, OPTIONS_GROUP_NONE, profile_); +} + +void Browser::OpenKeywordEditor() { + UserMetrics::RecordAction(L"EditSearchEngines", profile_); + window_->ShowSearchEnginesDialog(); +} + +void Browser::OpenPasswordManager() { + window_->ShowPasswordManager(); +} + +void Browser::OpenAboutChromeDialog() { + UserMetrics::RecordAction(L"AboutChrome", profile_); + window_->ShowAboutChromeDialog(); +} + +void Browser::OpenHelpTab() { + GURL help_url(l10n_util::GetString(IDS_HELP_CONTENT_URL)); + AddTabWithURL(help_url, GURL(), PageTransition::AUTO_BOOKMARK, true, + NULL); } /////////////////////////////////////////////////////////////////////////////// @@ -1092,19 +1092,31 @@ void Browser::ExecuteCommand(int id) { // The order of commands in this switch statement must match the function // declaration order in browser.h! switch (id) { + // Navigation commands case IDC_BACK: GoBack(); break; case IDC_FORWARD: GoForward(); break; case IDC_RELOAD: Reload(); break; - case IDC_STOP: Stop(); break; case IDC_HOME: Home(); break; - case IDC_GO: Go(); break; case IDC_OPEN_CURRENT_URL: OpenCurrentURL(); break; + case IDC_GO: Go(); break; + case IDC_STOP: Stop(); break; - case IDC_NEW_TAB: NewTab(); break; - case IDC_CLOSE_TAB: CloseTab(); break; + // Window management commands case IDC_NEW_WINDOW: NewWindow(); break; case IDC_NEW_INCOGNITO_WINDOW: NewIncognitoWindow(); break; + case IDC_NEW_WINDOW_PROFILE_0: + case IDC_NEW_WINDOW_PROFILE_1: + case IDC_NEW_WINDOW_PROFILE_2: + case IDC_NEW_WINDOW_PROFILE_3: + case IDC_NEW_WINDOW_PROFILE_4: + case IDC_NEW_WINDOW_PROFILE_5: + case IDC_NEW_WINDOW_PROFILE_6: + case IDC_NEW_WINDOW_PROFILE_7: + case IDC_NEW_WINDOW_PROFILE_8: + NewProfileWindowByIndex(id - IDC_NEW_WINDOW_PROFILE_0); break; case IDC_CLOSE_WINDOW: CloseWindow(); break; + case IDC_NEW_TAB: NewTab(); break; + case IDC_CLOSE_TAB: CloseTab(); break; case IDC_SELECT_NEXT_TAB: SelectNextTab(); break; case IDC_SELECT_PREVIOUS_TAB: SelectPreviousTab(); break; case IDC_SELECT_TAB_0: @@ -1122,23 +1134,7 @@ void Browser::ExecuteCommand(int id) { case IDC_SHOW_AS_TAB: ConvertPopupToTabbedBrowser(); break; case IDC_EXIT: Exit(); break; - case IDC_CUT: Cut(); break; - case IDC_COPY: Copy(); break; - case IDC_COPY_URL: CopyCurrentPageURL(); break; - case IDC_PASTE: Paste(); break; - - case IDC_FIND: Find(); break; - case IDC_FIND_NEXT: FindNext(); break; - case IDC_FIND_PREVIOUS: FindPrevious(); break; - - case IDC_ZOOM_PLUS: ZoomIn(); break; - case IDC_ZOOM_MINUS: ZoomOut(); break; - case IDC_ZOOM_NORMAL: ZoomReset(); break; - - case IDC_FOCUS_LOCATION: FocusLocationBar(); break; - case IDC_FOCUS_SEARCH: FocusSearch(); break; - case IDC_FOCUS_TOOLBAR: FocusToolbar(); break; - + // Page-related commands case IDC_STAR: BookmarkCurrentPage(); break; case IDC_VIEW_SOURCE: ViewSource(); break; case IDC_CLOSE_POPUPS: ClosePopups(); break; @@ -1182,35 +1178,50 @@ void Browser::ExecuteCommand(int id) { case IDC_ENCODING_WINDOWS1255: case IDC_ENCODING_WINDOWS1258: OverrideEncoding(id); break; - case IDC_EDIT_SEARCH_ENGINES: OpenKeywordEditor(); break; - case IDC_CLEAR_BROWSING_DATA: OpenClearBrowsingDataDialog(); break; - case IDC_IMPORT_SETTINGS: OpenImportSettingsDialog(); break; - case IDC_REPORT_BUG: OpenBugReportDialog(); break; + // Clipboard commands + case IDC_CUT: Cut(); break; + case IDC_COPY: Copy(); break; + case IDC_COPY_URL: CopyCurrentPageURL(); break; + case IDC_PASTE: Paste(); break; + + // Find-in-page + case IDC_FIND: Find(); break; + case IDC_FIND_NEXT: FindNext(); break; + case IDC_FIND_PREVIOUS: FindPrevious(); break; + + // Zoom + case IDC_ZOOM_PLUS: ZoomIn(); break; + case IDC_ZOOM_NORMAL: ZoomReset(); break; + case IDC_ZOOM_MINUS: ZoomOut(); break; + + // Focus various bits of UI + case IDC_FOCUS_TOOLBAR: FocusToolbar(); break; + case IDC_FOCUS_LOCATION: FocusLocationBar(); break; + case IDC_FOCUS_SEARCH: FocusSearch(); break; + + // Show various bits of UI + case IDC_OPEN_FILE: OpenFile(); break; + case IDC_CREATE_SHORTCUTS: OpenCreateShortcutsDialog(); break; case IDC_DEBUGGER: OpenDebuggerWindow(); break; case IDC_JS_CONSOLE: OpenJavaScriptConsole(); break; - case IDC_CREATE_SHORTCUTS: OpenCreateShortcutsDialog(); break; - case IDC_VIEW_PASSWORDS: OpenPasswordManager(); break; - case IDC_ABOUT: OpenAboutChromeDialog(); break; - case IDC_OPEN_FILE: OpenFile(); break; case IDC_TASK_MANAGER: OpenTaskManager(); break; - case IDC_OPTIONS: OpenOptionsDialog(); break; - case IDC_HELP_PAGE: OpenHelpTab(); break; - case IDC_SHOW_HISTORY: ShowHistoryTab(); break; - case IDC_SHOW_DOWNLOADS: ShowDownloadsTab(); break; - case IDC_SHOW_BOOKMARK_MANAGER: OpenBookmarkManager(); break; - case IDC_SHOW_BOOKMARK_BAR: ToggleBookmarkBar(); break; case IDC_SELECT_PROFILE: OpenSelectProfileDialog(); break; case IDC_NEW_PROFILE: OpenNewProfileDialog(); break; + case IDC_REPORT_BUG: OpenBugReportDialog(); break; + case IDC_SHOW_BOOKMARK_BAR: ToggleBookmarkBar(); break; + case IDC_SHOW_HISTORY: ShowHistoryTab(); break; + case IDC_SHOW_BOOKMARK_MANAGER: OpenBookmarkManager(); break; + case IDC_SHOW_DOWNLOADS: ShowDownloadsTab(); break; + case IDC_CLEAR_BROWSING_DATA: OpenClearBrowsingDataDialog(); break; + case IDC_IMPORT_SETTINGS: OpenImportSettingsDialog(); break; + case IDC_OPTIONS: OpenOptionsDialog(); break; + case IDC_EDIT_SEARCH_ENGINES: OpenKeywordEditor(); break; + case IDC_VIEW_PASSWORDS: OpenPasswordManager(); break; + case IDC_ABOUT: OpenAboutChromeDialog(); break; + case IDC_HELP_PAGE: OpenHelpTab(); break; default: - // Handle the user action for creating a new window in a specific profile. - if (id >= IDC_NEW_WINDOW_PROFILE_0 && - id <= IDC_NEW_WINDOW_PROFILE_LAST) { - int index = id - IDC_NEW_WINDOW_PROFILE_0; - NewProfileWindowByIndex(index); - } else { - LOG(WARNING) << "Received Unimplemented Command: " << id; - } + LOG(WARNING) << "Received Unimplemented Command: " << id; break; } } @@ -1415,8 +1426,8 @@ void Browser::TabSelectedAt(TabContents* old_contents, (new_contents->AsWebContents() && new_contents->is_loading()) ? GoButton::MODE_STOP : GoButton::MODE_GO); - // Update other parts of the toolbar. - UpdateNavigationCommands(); + // Update commands to reflect current state. + UpdateCommandsForTabState(); // Reset the status bubble. GetStatusBubble()->Hide(); @@ -1583,10 +1594,10 @@ void Browser::NavigationStateChanged(const TabContents* source, if (changed_flags) ScheduleUIUpdate(source, changed_flags); - // We don't schedule updates to the navigation commands since they will only - // change once per navigation, so we don't have to worry about flickering. + // We don't schedule updates to commands since they will only change once per + // navigation, so we don't have to worry about flickering. if (changed_flags & TabContents::INVALIDATE_URL) - UpdateNavigationCommands(); + UpdateCommandsForTabState(); } void Browser::ReplaceContents(TabContents* source, TabContents* new_contents) { @@ -1863,21 +1874,30 @@ void Browser::InitCommandState() { // (like Back & Forward with initial page load) must have their state // initialized here, otherwise they will be forever disabled. + // Navigation commands controller_.UpdateCommandEnabled(IDC_RELOAD, true); controller_.UpdateCommandEnabled(IDC_HOME, type() == TYPE_NORMAL); + controller_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, true); controller_.UpdateCommandEnabled(IDC_GO, true); - controller_.UpdateCommandEnabled(IDC_NEW_TAB, true); - controller_.UpdateCommandEnabled(IDC_CLOSE_TAB, true); + + // Window management commands controller_.UpdateCommandEnabled(IDC_NEW_WINDOW, true); + controller_.UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, true); + controller_.UpdateCommandEnabled(IDC_PROFILE_MENU, true); + // TODO(pkasting): Perhaps the code that populates this submenu should do + // this? + controller_.UpdateCommandEnabled(IDC_NEW_WINDOW_PROFILE_0, true); + controller_.UpdateCommandEnabled(IDC_NEW_WINDOW_PROFILE_1, true); + controller_.UpdateCommandEnabled(IDC_NEW_WINDOW_PROFILE_2, true); + controller_.UpdateCommandEnabled(IDC_NEW_WINDOW_PROFILE_3, true); + controller_.UpdateCommandEnabled(IDC_NEW_WINDOW_PROFILE_4, true); + controller_.UpdateCommandEnabled(IDC_NEW_WINDOW_PROFILE_5, true); + controller_.UpdateCommandEnabled(IDC_NEW_WINDOW_PROFILE_6, true); + controller_.UpdateCommandEnabled(IDC_NEW_WINDOW_PROFILE_7, true); + controller_.UpdateCommandEnabled(IDC_NEW_WINDOW_PROFILE_8, true); controller_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true); - controller_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, true); - controller_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, true); - controller_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, true); - controller_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, true); - controller_.UpdateCommandEnabled(IDC_CUT, true); - controller_.UpdateCommandEnabled(IDC_COPY, true); - controller_.UpdateCommandEnabled(IDC_PASTE, true); - controller_.UpdateCommandEnabled(IDC_REPORT_BUG, true); + controller_.UpdateCommandEnabled(IDC_NEW_TAB, true); + controller_.UpdateCommandEnabled(IDC_CLOSE_TAB, true); controller_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, true); controller_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, true); controller_.UpdateCommandEnabled(IDC_SELECT_TAB_0, true); @@ -1889,22 +1909,14 @@ void Browser::InitCommandState() { controller_.UpdateCommandEnabled(IDC_SELECT_TAB_6, true); controller_.UpdateCommandEnabled(IDC_SELECT_TAB_7, true); controller_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, true); - controller_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false); - controller_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, true); - controller_.UpdateCommandEnabled(IDC_OPEN_FILE, true); - controller_.UpdateCommandEnabled(IDC_TASK_MANAGER, true); - controller_.UpdateCommandEnabled(IDC_CLOSE_POPUPS, true); - controller_.UpdateCommandEnabled(IDC_COPY_URL, true); controller_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true); - controller_.UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, true); - controller_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, true); - controller_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, true); - controller_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, true); - controller_.UpdateCommandEnabled(IDC_ABOUT, true); - controller_.UpdateCommandEnabled(IDC_SHOW_HISTORY, true); - controller_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, true); - controller_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_MANAGER, true); - controller_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); + controller_.UpdateCommandEnabled(IDC_RESTORE_TAB, + (!profile_->IsOffTheRecord() && type() == TYPE_NORMAL)); + controller_.UpdateCommandEnabled(IDC_SHOW_AS_TAB, type() == TYPE_POPUP); + controller_.UpdateCommandEnabled(IDC_EXIT, true); + + // Page-related commands + controller_.UpdateCommandEnabled(IDC_CLOSE_POPUPS, true); controller_.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT, true); controller_.UpdateCommandEnabled(IDC_ENCODING_UTF8, true); controller_.UpdateCommandEnabled(IDC_ENCODING_UTF16LE, true); @@ -1942,90 +1954,115 @@ void Browser::InitCommandState() { controller_.UpdateCommandEnabled(IDC_ENCODING_ISO88598, true); controller_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true); controller_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true); - controller_.UpdateCommandEnabled(IDC_OPTIONS, true); - controller_.UpdateCommandEnabled(IDC_SHOW_AS_TAB, type() == TYPE_POPUP); - controller_.UpdateCommandEnabled( - IDC_RESTORE_TAB, (!profile_->IsOffTheRecord() && - type() == TYPE_NORMAL)); - controller_.UpdateCommandEnabled(IDC_EXIT, true); - // the debugger doesn't work in single process mode + + // Clipboard commands + controller_.UpdateCommandEnabled(IDC_CUT, true); + controller_.UpdateCommandEnabled(IDC_COPY, true); + controller_.UpdateCommandEnabled(IDC_COPY_URL, true); + controller_.UpdateCommandEnabled(IDC_PASTE, true); + + // Focus various bits of UI + controller_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, true); + controller_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, true); + controller_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, true); + + // Show various bits of UI + controller_.UpdateCommandEnabled(IDC_OPEN_FILE, true); + controller_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false); + controller_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, true); + // The debugger doesn't work in single process mode. controller_.UpdateCommandEnabled(IDC_DEBUGGER, !RenderProcessHost::run_renderer_in_process()); - controller_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, true); + controller_.UpdateCommandEnabled(IDC_TASK_MANAGER, true); + controller_.UpdateCommandEnabled(IDC_SELECT_PROFILE, true); + controller_.UpdateCommandEnabled(IDC_NEW_PROFILE, true); + controller_.UpdateCommandEnabled(IDC_REPORT_BUG, true); + controller_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, true); + controller_.UpdateCommandEnabled(IDC_SHOW_HISTORY, true); + controller_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_MANAGER, true); + controller_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); + controller_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, true); + controller_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, true); + controller_.UpdateCommandEnabled(IDC_OPTIONS, true); + controller_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, true); + controller_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, true); + controller_.UpdateCommandEnabled(IDC_ABOUT, true); controller_.UpdateCommandEnabled(IDC_HELP_PAGE, true); } -void Browser::UpdateNavigationCommands() { +void Browser::UpdateCommandsForTabState() { TabContents* current_tab = GetSelectedTabContents(); if (!current_tab) { // It's possible for this to be null during tab restore. return; } + // Navigation commands NavigationController* nc = current_tab->controller(); controller_.UpdateCommandEnabled(IDC_BACK, nc->CanGoBack()); controller_.UpdateCommandEnabled(IDC_FORWARD, nc->CanGoForward()); + // Window management commands + controller_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, + CanDuplicateContentsAt(selected_index())); + + // Show various bits of UI + controller_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, + current_tab->type() == TAB_CONTENTS_WEB && + !current_tab->GetFavIcon().isNull()); + WebContents* web_contents = current_tab->AsWebContents(); if (web_contents) { + // Page-related commands controller_.UpdateCommandEnabled(IDC_STAR, true); SetStarredButtonToggled(web_contents->is_starred()); - // View-source should not be enabled if already in view-source mode. controller_.UpdateCommandEnabled(IDC_VIEW_SOURCE, current_tab->type() != TAB_CONTENTS_VIEW_SOURCE && current_tab->controller()->GetActiveEntry()); - - controller_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); - bool enable_encoding = - SavePackage::IsSavableContents(web_contents->contents_mime_type()) && - SavePackage::IsSavableURL(current_tab->GetURL()); - controller_.UpdateCommandEnabled(IDC_ENCODING_MENU, enable_encoding); - + controller_.UpdateCommandEnabled(IDC_PRINT, true); controller_.UpdateCommandEnabled(IDC_SAVE_PAGE, SavePackage::IsSavableURL(current_tab->GetURL())); - controller_.UpdateCommandEnabled(IDC_JS_CONSOLE, true); + controller_.UpdateCommandEnabled(IDC_ENCODING_MENU, + SavePackage::IsSavableContents(web_contents->contents_mime_type()) && + SavePackage::IsSavableURL(current_tab->GetURL())); + + // Find-in-page controller_.UpdateCommandEnabled(IDC_FIND, true); controller_.UpdateCommandEnabled(IDC_FIND_NEXT, true); controller_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, true); + + // Zoom + controller_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); controller_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true); - controller_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true); controller_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, true); - controller_.UpdateCommandEnabled(IDC_PRINT, true); - } else { - controller_.UpdateCommandEnabled(IDC_VIEW_SOURCE, false); - controller_.UpdateCommandEnabled(IDC_JS_CONSOLE, false); + controller_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true); + // Show various bits of UI + controller_.UpdateCommandEnabled(IDC_JS_CONSOLE, true); + } else { + // Page-related commands // Both disable the starring button and ensure it doesn't show a star. controller_.UpdateCommandEnabled(IDC_STAR, false); SetStarredButtonToggled(false); - controller_.UpdateCommandEnabled(IDC_ZOOM_MENU, false); + controller_.UpdateCommandEnabled(IDC_VIEW_SOURCE, false); + controller_.UpdateCommandEnabled(IDC_PRINT, false); + controller_.UpdateCommandEnabled(IDC_SAVE_PAGE, false); controller_.UpdateCommandEnabled(IDC_ENCODING_MENU, false); - controller_.UpdateCommandEnabled(IDC_SAVE_PAGE, false); + // Find-in-page controller_.UpdateCommandEnabled(IDC_FIND, false); controller_.UpdateCommandEnabled(IDC_FIND_NEXT, false); controller_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, false); + + // Zoom + controller_.UpdateCommandEnabled(IDC_ZOOM_MENU, false); controller_.UpdateCommandEnabled(IDC_ZOOM_PLUS, false); - controller_.UpdateCommandEnabled(IDC_ZOOM_MINUS, false); controller_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false); - controller_.UpdateCommandEnabled(IDC_PRINT, false); - } - - controller_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, - current_tab->type() == TAB_CONTENTS_WEB && - !current_tab->GetFavIcon().isNull()); - controller_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, - CanDuplicateContentsAt(selected_index())); + controller_.UpdateCommandEnabled(IDC_ZOOM_MINUS, false); - // Enable various IDC_NEWPROFILEWINDOW* commands. - controller_.UpdateCommandEnabled(IDC_PROFILE_MENU, true); - controller_.UpdateCommandEnabled(IDC_SELECT_PROFILE, true); - controller_.UpdateCommandEnabled(IDC_NEW_PROFILE, true); - for (int i = IDC_NEW_WINDOW_PROFILE_0; - i <= IDC_NEW_WINDOW_PROFILE_LAST; - ++i) { - controller_.UpdateCommandEnabled(i, true); + // Show various bits of UI + controller_.UpdateCommandEnabled(IDC_JS_CONSOLE, false); } } diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 97ccd16..9876014 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -215,22 +215,25 @@ class Browser : public TabStripModelDelegate, // Assorted browser commands //////////////////////////////////////////////// + // NOTE: Within each of the following sections, the IDs are ordered roughly by + // how they appear in the GUI/menus (left to right, top to bottom, etc.). + // Navigation commands void GoBack(); void GoForward(); void Reload(); - void Stop(); void Home(); - void Go(); void OpenCurrentURL(); + void Go(); + void Stop(); // Window management commands - void NewTab(); - void CloseTab(); void NewWindow(); - void NewProfileWindowByIndex(int index); void NewIncognitoWindow(); + void NewProfileWindowByIndex(int index); void CloseWindow(); + void NewTab(); + void CloseTab(); void SelectNextTab(); void SelectPreviousTab(); void SelectNumberedTab(int index); @@ -240,56 +243,56 @@ class Browser : public TabStripModelDelegate, void ConvertPopupToTabbedBrowser(); void Exit(); + // Page-related commands + void BookmarkCurrentPage(); + void ViewSource(); + void ClosePopups(); + void Print(); + void SavePage(); + void ToggleEncodingAutoDetect(); + void OverrideEncoding(int encoding_id); + // Clipboard commands void Cut(); void Copy(); void CopyCurrentPageURL(); void Paste(); - // Opens the FindInPage window for the currently open tab. + // Find-in-page void Find(); void FindNext(); void FindPrevious(); // Zoom void ZoomIn(); - void ZoomOut(); void ZoomReset(); + void ZoomOut(); - // Sets focus to various bits of UI. + // Focus various bits of UI + void FocusToolbar(); void FocusLocationBar(); void FocusSearch(); - void FocusToolbar(); - // Page-related commands. - void BookmarkCurrentPage(); - void ViewSource(); - void ClosePopups(); - void Print(); - void SavePage(); - void ToggleEncodingAutoDetect(); - void OverrideEncoding(int encoding_id); - - // Show various bits of UI. - void OpenKeywordEditor(); - void OpenClearBrowsingDataDialog(); - void OpenImportSettingsDialog(); - void OpenBugReportDialog(); + // Show various bits of UI + void OpenFile(); + void OpenCreateShortcutsDialog(); void OpenDebuggerWindow(); void OpenJavaScriptConsole(); - void OpenCreateShortcutsDialog(); - void OpenPasswordManager(); - void OpenAboutChromeDialog(); - void OpenFile(); void OpenTaskManager(); - void OpenOptionsDialog(); - void OpenHelpTab(); - void ShowHistoryTab(); - void ShowDownloadsTab(); - void OpenBookmarkManager(); - void ToggleBookmarkBar(); void OpenSelectProfileDialog(); void OpenNewProfileDialog(); + void OpenBugReportDialog(); + void ToggleBookmarkBar(); + void ShowHistoryTab(); + void OpenBookmarkManager(); + void ShowDownloadsTab(); + void OpenClearBrowsingDataDialog(); + void OpenImportSettingsDialog(); + void OpenOptionsDialog(); + void OpenKeywordEditor(); + void OpenPasswordManager(); + void OpenAboutChromeDialog(); + void OpenHelpTab(); ///////////////////////////////////////////////////////////////////////////// @@ -395,9 +398,9 @@ class Browser : public TabStripModelDelegate, // Initialize state for all browser commands. void InitCommandState(); - // Update commands that drive the NavigationController to reflect changes in - // the NavigationController's state (Back, Forward, etc). - void UpdateNavigationCommands(); + // Update commands which may be enabled or disabled depending on the tab's + // state. + void UpdateCommandsForTabState(); // Change the "starred" button display to starred/unstarred. // TODO(evanm): migrate this to the commands framework. |