Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/browser_command_controller.h" | 5 #include "chrome/browser/ui/browser_command_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 #endif | 81 #endif |
| 82 | 82 |
| 83 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 83 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 84 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" | 84 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" |
| 85 #endif | 85 #endif |
| 86 | 86 |
| 87 using content::NavigationEntry; | 87 using content::NavigationEntry; |
| 88 using content::NavigationController; | 88 using content::NavigationController; |
| 89 using content::WebContents; | 89 using content::WebContents; |
| 90 | 90 |
| 91 namespace { | |
| 92 | |
| 93 enum WindowState { | |
| 94 // Not in fullscreen mode. | |
| 95 WINDOW_STATE_NOT_FULLSCREEN, | |
| 96 | |
| 97 // Fullscreen mode, occupying the whole screen. | |
| 98 WINDOW_STATE_FULLSCREEN, | |
| 99 }; | |
| 100 | |
| 101 } // namespace | |
| 102 | |
| 103 namespace chrome { | 91 namespace chrome { |
| 104 | 92 |
| 105 /////////////////////////////////////////////////////////////////////////////// | 93 /////////////////////////////////////////////////////////////////////////////// |
| 106 // BrowserCommandController, public: | 94 // BrowserCommandController, public: |
| 107 | 95 |
| 108 BrowserCommandController::BrowserCommandController(Browser* browser) | 96 BrowserCommandController::BrowserCommandController(Browser* browser) |
| 109 : browser_(browser), | 97 : browser_(browser), |
| 110 command_updater_(this), | 98 command_updater_(this), |
| 111 block_command_execution_(false), | 99 block_command_execution_(false), |
| 112 last_blocked_command_id_(-1), | 100 last_blocked_command_id_(-1), |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 // reserve browser back/forward and refresh here. | 180 // reserve browser back/forward and refresh here. |
| 193 ui::KeyboardCode key_code = | 181 ui::KeyboardCode key_code = |
| 194 static_cast<ui::KeyboardCode>(event.windowsKeyCode); | 182 static_cast<ui::KeyboardCode>(event.windowsKeyCode); |
| 195 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) || | 183 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) || |
| 196 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) || | 184 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) || |
| 197 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) { | 185 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) { |
| 198 return true; | 186 return true; |
| 199 } | 187 } |
| 200 #endif | 188 #endif |
| 201 | 189 |
| 202 if (window()->IsFullscreen() && command_id == IDC_FULLSCREEN) | 190 if (window()->IsFullscreen()) { |
| 203 return true; | 191 // In full-screen mode, all the keys, except for ESC and F11, should be |
| 192 // delivered to the web page. This has been discussed in the document | |
| 193 // Allowing sites to intercept keyboard shortcuts at https://goo.gl/r6XmNt. | |
|
dominickn
2017/02/08 00:42:38
Change this comment to be:
In fullscreen, all key
Hzj_jie
2017/02/08 18:29:37
Done.
| |
| 194 if (command_id == IDC_FULLSCREEN) { | |
| 195 return true; | |
| 196 } else if (command_id == IDC_CLOSE_TAB || | |
| 197 command_id == IDC_CLOSE_WINDOW || | |
| 198 command_id == IDC_NEW_INCOGNITO_WINDOW || | |
| 199 command_id == IDC_NEW_TAB || | |
| 200 command_id == IDC_NEW_WINDOW || | |
| 201 command_id == IDC_RESTORE_TAB || | |
| 202 command_id == IDC_SELECT_NEXT_TAB || | |
| 203 command_id == IDC_SELECT_PREVIOUS_TAB) { | |
| 204 return false; | |
| 205 } | |
| 206 } | |
| 204 | 207 |
| 205 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 208 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 206 // If this key was registered by the user as a content editing hotkey, then | 209 // If this key was registered by the user as a content editing hotkey, then |
| 207 // it is not reserved. | 210 // it is not reserved. |
| 208 ui::TextEditKeyBindingsDelegateAuraLinux* delegate = | 211 ui::TextEditKeyBindingsDelegateAuraLinux* delegate = |
| 209 ui::GetTextEditKeyBindingsDelegate(); | 212 ui::GetTextEditKeyBindingsDelegate(); |
| 210 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL)) | 213 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL)) |
| 211 return false; | 214 return false; |
| 212 #endif | 215 #endif |
| 213 | 216 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 } | 300 } |
| 298 | 301 |
| 299 // The order of commands in this switch statement must match the function | 302 // The order of commands in this switch statement must match the function |
| 300 // declaration order in browser.h! | 303 // declaration order in browser.h! |
| 301 switch (id) { | 304 switch (id) { |
| 302 // Navigation commands | 305 // Navigation commands |
| 303 case IDC_BACKSPACE_BACK: | 306 case IDC_BACKSPACE_BACK: |
| 304 if (base::FeatureList::IsEnabled(features::kBackspaceGoesBackFeature)) | 307 if (base::FeatureList::IsEnabled(features::kBackspaceGoesBackFeature)) |
| 305 GoBack(browser_, disposition); | 308 GoBack(browser_, disposition); |
| 306 else | 309 else |
| 307 browser_->window()->MaybeShowNewBackShortcutBubble(false); | 310 window()->MaybeShowNewBackShortcutBubble(false); |
|
dominickn
2017/02/08 00:42:37
Why did you change these? It seems unrelated to me
Hzj_jie
2017/02/08 18:29:38
I have done a full document replacement to replace
dominickn
2017/02/08 23:40:21
Intents to implement are only required for web-fac
Hzj_jie
2017/02/09 02:04:51
Oh, that would be good. I will revert these change
| |
| 308 break; | 311 break; |
| 309 case IDC_BACK: | 312 case IDC_BACK: |
| 310 browser_->window()->HideNewBackShortcutBubble(); | 313 window()->HideNewBackShortcutBubble(); |
| 311 GoBack(browser_, disposition); | 314 GoBack(browser_, disposition); |
| 312 break; | 315 break; |
| 313 case IDC_BACKSPACE_FORWARD: | 316 case IDC_BACKSPACE_FORWARD: |
| 314 if (base::FeatureList::IsEnabled(features::kBackspaceGoesBackFeature)) | 317 if (base::FeatureList::IsEnabled(features::kBackspaceGoesBackFeature)) |
| 315 GoForward(browser_, disposition); | 318 GoForward(browser_, disposition); |
| 316 else | 319 else |
| 317 browser_->window()->MaybeShowNewBackShortcutBubble(true); | 320 window()->MaybeShowNewBackShortcutBubble(true); |
| 318 break; | 321 break; |
| 319 case IDC_FORWARD: | 322 case IDC_FORWARD: |
| 320 browser_->window()->HideNewBackShortcutBubble(); | 323 window()->HideNewBackShortcutBubble(); |
| 321 GoForward(browser_, disposition); | 324 GoForward(browser_, disposition); |
| 322 break; | 325 break; |
| 323 case IDC_RELOAD: | 326 case IDC_RELOAD: |
| 324 Reload(browser_, disposition); | 327 Reload(browser_, disposition); |
| 325 break; | 328 break; |
| 326 case IDC_RELOAD_CLEARING_CACHE: | 329 case IDC_RELOAD_CLEARING_CACHE: |
| 327 ClearCache(browser_); | 330 ClearCache(browser_); |
| 328 // FALL THROUGH | 331 // FALL THROUGH |
| 329 case IDC_RELOAD_BYPASSING_CACHE: | 332 case IDC_RELOAD_BYPASSING_CACHE: |
| 330 ReloadBypassingCache(browser_, disposition); | 333 ReloadBypassingCache(browser_, disposition); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 case IDC_SHOW_AS_TAB: | 397 case IDC_SHOW_AS_TAB: |
| 395 ConvertPopupToTabbedBrowser(browser_); | 398 ConvertPopupToTabbedBrowser(browser_); |
| 396 break; | 399 break; |
| 397 case IDC_FULLSCREEN: | 400 case IDC_FULLSCREEN: |
| 398 chrome::ToggleFullscreenMode(browser_); | 401 chrome::ToggleFullscreenMode(browser_); |
| 399 break; | 402 break; |
| 400 | 403 |
| 401 #if defined(OS_CHROMEOS) | 404 #if defined(OS_CHROMEOS) |
| 402 case IDC_VISIT_DESKTOP_OF_LRU_USER_2: | 405 case IDC_VISIT_DESKTOP_OF_LRU_USER_2: |
| 403 case IDC_VISIT_DESKTOP_OF_LRU_USER_3: | 406 case IDC_VISIT_DESKTOP_OF_LRU_USER_3: |
| 404 ExecuteVisitDesktopCommand(id, browser_->window()->GetNativeWindow()); | 407 ExecuteVisitDesktopCommand(id, window()->GetNativeWindow()); |
|
dominickn
2017/02/08 00:42:38
This seems unrelated
Hzj_jie
2017/02/08 18:29:38
Explained above.
| |
| 405 break; | 408 break; |
| 406 #endif | 409 #endif |
| 407 | 410 |
| 408 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 411 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 409 case IDC_USE_SYSTEM_TITLE_BAR: { | 412 case IDC_USE_SYSTEM_TITLE_BAR: { |
| 410 PrefService* prefs = browser_->profile()->GetPrefs(); | 413 PrefService* prefs = profile()->GetPrefs(); |
|
dominickn
2017/02/08 00:42:38
Unrelated?
Hzj_jie
2017/02/08 18:29:38
Ditto.
| |
| 411 prefs->SetBoolean(prefs::kUseCustomChromeFrame, | 414 prefs->SetBoolean(prefs::kUseCustomChromeFrame, |
| 412 !prefs->GetBoolean(prefs::kUseCustomChromeFrame)); | 415 !prefs->GetBoolean(prefs::kUseCustomChromeFrame)); |
| 413 break; | 416 break; |
| 414 } | 417 } |
| 415 #endif | 418 #endif |
| 416 | 419 |
| 417 #if defined(OS_MACOSX) | 420 #if defined(OS_MACOSX) |
| 418 case IDC_TOGGLE_FULLSCREEN_TOOLBAR: | 421 case IDC_TOGGLE_FULLSCREEN_TOOLBAR: |
| 419 chrome::ToggleFullscreenToolbar(browser_); | 422 chrome::ToggleFullscreenToolbar(browser_); |
| 420 break; | 423 break; |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1013 bookmarks::prefs::kShowBookmarkBar) && | 1016 bookmarks::prefs::kShowBookmarkBar) && |
| 1014 IsShowingMainUI()); | 1017 IsShowingMainUI()); |
| 1015 } | 1018 } |
| 1016 | 1019 |
| 1017 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() { | 1020 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() { |
| 1018 UpdateSaveAsState(); | 1021 UpdateSaveAsState(); |
| 1019 UpdateOpenFileState(&command_updater_); | 1022 UpdateOpenFileState(&command_updater_); |
| 1020 } | 1023 } |
| 1021 | 1024 |
| 1022 void BrowserCommandController::UpdateCommandsForFullscreenMode() { | 1025 void BrowserCommandController::UpdateCommandsForFullscreenMode() { |
| 1023 WindowState window_state = WINDOW_STATE_NOT_FULLSCREEN; | 1026 const bool is_fullscreen = (window() && window()->IsFullscreen()); |
| 1024 if (window() && window()->IsFullscreen()) { | 1027 const bool is_not_fullscreen = !is_fullscreen; |
|
dominickn
2017/02/08 00:42:38
I don't think you need bools for is_fullscreen and
Hzj_jie
2017/02/08 18:29:37
is_fullscreen is also used when calculating fullsc
dominickn
2017/02/08 23:40:21
It just feels a little wasteful to have two boolea
Hzj_jie
2017/02/09 02:04:51
No, nothing could be wrong. I would prefer to remo
| |
| 1025 window_state = WINDOW_STATE_FULLSCREEN; | 1028 const bool show_main_ui = IsShowingMainUI(); |
| 1026 } | 1029 const bool main_not_fullscreen = show_main_ui && is_not_fullscreen; |
| 1027 bool show_main_ui = IsShowingMainUI(); | |
| 1028 bool main_not_fullscreen = | |
| 1029 show_main_ui && window_state == WINDOW_STATE_NOT_FULLSCREEN; | |
| 1030 | 1030 |
| 1031 // Navigation commands | 1031 // Navigation commands |
| 1032 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui); | 1032 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui); |
| 1033 | 1033 |
| 1034 // Window management commands | 1034 // Window management commands |
| 1035 command_updater_.UpdateCommandEnabled( | 1035 command_updater_.UpdateCommandEnabled( |
| 1036 IDC_SHOW_AS_TAB, | 1036 IDC_SHOW_AS_TAB, |
| 1037 !browser_->is_type_tabbed() && | 1037 !browser_->is_type_tabbed() && is_not_fullscreen); |
| 1038 window_state == WINDOW_STATE_NOT_FULLSCREEN); | |
| 1039 | 1038 |
| 1040 // Focus various bits of UI | 1039 // Focus various bits of UI |
| 1041 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui); | 1040 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui); |
| 1042 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui); | 1041 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui); |
| 1043 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui); | 1042 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui); |
| 1044 command_updater_.UpdateCommandEnabled( | 1043 command_updater_.UpdateCommandEnabled( |
| 1045 IDC_FOCUS_MENU_BAR, main_not_fullscreen); | 1044 IDC_FOCUS_MENU_BAR, main_not_fullscreen); |
| 1046 command_updater_.UpdateCommandEnabled( | 1045 command_updater_.UpdateCommandEnabled( |
| 1047 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); | 1046 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); |
| 1048 command_updater_.UpdateCommandEnabled( | 1047 command_updater_.UpdateCommandEnabled( |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1070 options_enabled && !guest_session); | 1069 options_enabled && !guest_session); |
| 1071 | 1070 |
| 1072 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); | 1071 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
| 1073 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); | 1072 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); |
| 1074 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); | 1073 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); |
| 1075 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); | 1074 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); |
| 1076 | 1075 |
| 1077 if (base::debug::IsProfilingSupported()) | 1076 if (base::debug::IsProfilingSupported()) |
| 1078 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); | 1077 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); |
| 1079 | 1078 |
| 1080 bool fullscreen_enabled = true; | |
| 1081 #if !defined(OS_MACOSX) | 1079 #if !defined(OS_MACOSX) |
| 1082 if (window_state == WINDOW_STATE_NOT_FULLSCREEN && | 1080 // Disable toggling into fullscreen mode if disallowed by pref. |
| 1083 !profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed)) { | 1081 const bool fullscreen_enabled = is_fullscreen || |
| 1084 // Disable toggling into fullscreen mode if disallowed by pref. | 1082 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed); |
| 1085 fullscreen_enabled = false; | 1083 #else |
| 1086 } | 1084 const bool fullscreen_enabled = true; |
| 1087 #endif | 1085 #endif |
| 1088 | 1086 |
| 1089 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled); | 1087 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled); |
| 1090 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR, | 1088 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR, |
| 1091 fullscreen_enabled); | 1089 fullscreen_enabled); |
| 1092 | 1090 |
| 1091 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, is_not_fullscreen); | |
| 1092 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, is_not_fullscreen); | |
| 1093 command_updater_.UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, | |
| 1094 is_not_fullscreen); | |
| 1095 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, is_not_fullscreen); | |
| 1096 command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, is_not_fullscreen); | |
| 1097 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, is_not_fullscreen); | |
| 1098 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, is_not_fullscreen); | |
| 1099 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, | |
| 1100 is_not_fullscreen); | |
| 1101 | |
| 1093 UpdateCommandsForBookmarkBar(); | 1102 UpdateCommandsForBookmarkBar(); |
| 1094 } | 1103 } |
| 1095 | 1104 |
| 1096 void BrowserCommandController::UpdatePrintingState() { | 1105 void BrowserCommandController::UpdatePrintingState() { |
| 1097 bool print_enabled = CanPrint(browser_); | 1106 bool print_enabled = CanPrint(browser_); |
| 1098 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); | 1107 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); |
| 1099 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 1108 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 1100 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT, | 1109 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT, |
| 1101 CanBasicPrint(browser_)); | 1110 CanBasicPrint(browser_)); |
| 1102 #endif // ENABLE_BASIC_PRINTING | 1111 #endif // ENABLE_BASIC_PRINTING |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1173 | 1182 |
| 1174 BrowserWindow* BrowserCommandController::window() { | 1183 BrowserWindow* BrowserCommandController::window() { |
| 1175 return browser_->window(); | 1184 return browser_->window(); |
| 1176 } | 1185 } |
| 1177 | 1186 |
| 1178 Profile* BrowserCommandController::profile() { | 1187 Profile* BrowserCommandController::profile() { |
| 1179 return browser_->profile(); | 1188 return browser_->profile(); |
| 1180 } | 1189 } |
| 1181 | 1190 |
| 1182 } // namespace chrome | 1191 } // namespace chrome |
| OLD | NEW |