Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: chrome/browser/ui/browser_command_controller.cc

Issue 2698013004: Revert 3c7af99, but keep only IsReservedCommandOrKey change (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/browser_command_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 {
msw 2017/02/16 00:48:53 I appreciated the removal of this enum; feel free
Hzj_jie 2017/02/16 01:56:53 Done.
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
91 namespace chrome { 103 namespace chrome {
92 104
93 /////////////////////////////////////////////////////////////////////////////// 105 ///////////////////////////////////////////////////////////////////////////////
94 // BrowserCommandController, public: 106 // BrowserCommandController, public:
95 107
96 BrowserCommandController::BrowserCommandController(Browser* browser) 108 BrowserCommandController::BrowserCommandController(Browser* browser)
97 : browser_(browser), 109 : browser_(browser),
98 command_updater_(this), 110 command_updater_(this),
99 block_command_execution_(false), 111 block_command_execution_(false),
100 last_blocked_command_id_(-1), 112 last_blocked_command_id_(-1),
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // reserve browser back/forward and refresh here. 192 // reserve browser back/forward and refresh here.
181 ui::KeyboardCode key_code = 193 ui::KeyboardCode key_code =
182 static_cast<ui::KeyboardCode>(event.windowsKeyCode); 194 static_cast<ui::KeyboardCode>(event.windowsKeyCode);
183 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) || 195 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) ||
184 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) || 196 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) ||
185 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) { 197 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) {
186 return true; 198 return true;
187 } 199 }
188 #endif 200 #endif
189 201
190 const bool is_tab_or_window_command =
191 command_id == IDC_CLOSE_TAB ||
192 command_id == IDC_CLOSE_WINDOW ||
193 command_id == IDC_NEW_INCOGNITO_WINDOW ||
194 command_id == IDC_NEW_TAB ||
195 command_id == IDC_NEW_WINDOW ||
196 command_id == IDC_RESTORE_TAB ||
197 command_id == IDC_SELECT_NEXT_TAB ||
198 command_id == IDC_SELECT_PREVIOUS_TAB;
199 if (window()->IsFullscreen()) { 202 if (window()->IsFullscreen()) {
200 // In fullscreen, all commands except for IDC_FULLSCREEN and IDC_EXIT should 203 // In fullscreen, all commands except for IDC_FULLSCREEN and IDC_EXIT should
201 // be delivered to the web page. See https://goo.gl/4tJ32G. 204 // be delivered to the web page. See, intent to implement,
202 if (command_id == IDC_FULLSCREEN) 205 // https://goo.gl/4tJ32G.
203 return true; 206 return command_id == IDC_EXIT || command_id == IDC_FULLSCREEN;
204 if (is_tab_or_window_command)
205 return false;
206 } 207 }
207 208
208 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 209 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
209 // If this key was registered by the user as a content editing hotkey, then 210 // If this key was registered by the user as a content editing hotkey, then
210 // it is not reserved. 211 // it is not reserved.
211 ui::TextEditKeyBindingsDelegateAuraLinux* delegate = 212 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
212 ui::GetTextEditKeyBindingsDelegate(); 213 ui::GetTextEditKeyBindingsDelegate();
213 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL)) 214 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
214 return false; 215 return false;
215 #endif 216 #endif
216 217
217 return is_tab_or_window_command || command_id == IDC_EXIT; 218 return command_id == IDC_CLOSE_TAB ||
219 command_id == IDC_CLOSE_WINDOW ||
220 command_id == IDC_NEW_INCOGNITO_WINDOW ||
221 command_id == IDC_NEW_TAB ||
222 command_id == IDC_NEW_WINDOW ||
223 command_id == IDC_RESTORE_TAB ||
224 command_id == IDC_SELECT_NEXT_TAB ||
225 command_id == IDC_SELECT_PREVIOUS_TAB ||
226 command_id == IDC_EXIT;
218 } 227 }
219 228
220 void BrowserCommandController::SetBlockCommandExecution(bool block) { 229 void BrowserCommandController::SetBlockCommandExecution(bool block) {
221 block_command_execution_ = block; 230 block_command_execution_ = block;
222 if (block) { 231 if (block) {
223 last_blocked_command_id_ = -1; 232 last_blocked_command_id_ = -1;
224 last_blocked_command_disposition_ = WindowOpenDisposition::CURRENT_TAB; 233 last_blocked_command_disposition_ = WindowOpenDisposition::CURRENT_TAB;
225 } 234 }
226 } 235 }
227 236
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 bookmarks::prefs::kShowBookmarkBar) && 1017 bookmarks::prefs::kShowBookmarkBar) &&
1009 IsShowingMainUI()); 1018 IsShowingMainUI());
1010 } 1019 }
1011 1020
1012 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() { 1021 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
1013 UpdateSaveAsState(); 1022 UpdateSaveAsState();
1014 UpdateOpenFileState(&command_updater_); 1023 UpdateOpenFileState(&command_updater_);
1015 } 1024 }
1016 1025
1017 void BrowserCommandController::UpdateCommandsForFullscreenMode() { 1026 void BrowserCommandController::UpdateCommandsForFullscreenMode() {
1018 const bool is_fullscreen = window() && window()->IsFullscreen(); 1027 WindowState window_state = WINDOW_STATE_NOT_FULLSCREEN;
1019 const bool show_main_ui = IsShowingMainUI(); 1028 if (window() && window()->IsFullscreen()) {
1020 const bool main_not_fullscreen = show_main_ui && !is_fullscreen; 1029 window_state = WINDOW_STATE_FULLSCREEN;
1030 }
1031 bool show_main_ui = IsShowingMainUI();
1032 bool main_not_fullscreen =
1033 show_main_ui && window_state == WINDOW_STATE_NOT_FULLSCREEN;
1021 1034
1022 // Navigation commands 1035 // Navigation commands
1023 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui); 1036 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1024 1037
1025 // Window management commands 1038 // Window management commands
1026 command_updater_.UpdateCommandEnabled( 1039 command_updater_.UpdateCommandEnabled(
1027 IDC_SHOW_AS_TAB, 1040 IDC_SHOW_AS_TAB,
1028 !browser_->is_type_tabbed() && !is_fullscreen); 1041 !browser_->is_type_tabbed() &&
1042 window_state == WINDOW_STATE_NOT_FULLSCREEN);
1029 1043
1030 // Focus various bits of UI 1044 // Focus various bits of UI
1031 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui); 1045 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
1032 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui); 1046 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui);
1033 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui); 1047 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
1034 command_updater_.UpdateCommandEnabled( 1048 command_updater_.UpdateCommandEnabled(
1035 IDC_FOCUS_MENU_BAR, main_not_fullscreen); 1049 IDC_FOCUS_MENU_BAR, main_not_fullscreen);
1036 command_updater_.UpdateCommandEnabled( 1050 command_updater_.UpdateCommandEnabled(
1037 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); 1051 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
1038 command_updater_.UpdateCommandEnabled( 1052 command_updater_.UpdateCommandEnabled(
(...skipping 21 matching lines...) Expand all
1060 options_enabled && !guest_session); 1074 options_enabled && !guest_session);
1061 1075
1062 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); 1076 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1063 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); 1077 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1064 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); 1078 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1065 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); 1079 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
1066 1080
1067 if (base::debug::IsProfilingSupported()) 1081 if (base::debug::IsProfilingSupported())
1068 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); 1082 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
1069 1083
1084 bool fullscreen_enabled = true;
1070 #if !defined(OS_MACOSX) 1085 #if !defined(OS_MACOSX)
1071 // Disable toggling into fullscreen mode if disallowed by pref. 1086 if (window_state == WINDOW_STATE_NOT_FULLSCREEN &&
1072 const bool fullscreen_enabled = is_fullscreen || 1087 !profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed)) {
1073 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed); 1088 // Disable toggling into fullscreen mode if disallowed by pref.
1074 #else 1089 fullscreen_enabled = false;
1075 const bool fullscreen_enabled = true; 1090 }
1076 #endif 1091 #endif
1077 1092
1078 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled); 1093 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
1079 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR, 1094 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1080 fullscreen_enabled); 1095 fullscreen_enabled);
1081 1096
1082 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, !is_fullscreen);
1083 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, !is_fullscreen);
1084 command_updater_.UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW,
1085 !is_fullscreen);
1086 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, !is_fullscreen);
1087 command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, !is_fullscreen);
1088 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, !is_fullscreen);
1089 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, !is_fullscreen);
1090 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
1091 !is_fullscreen);
1092
1093 UpdateCommandsForBookmarkBar(); 1097 UpdateCommandsForBookmarkBar();
1094 } 1098 }
1095 1099
1096 void BrowserCommandController::UpdatePrintingState() { 1100 void BrowserCommandController::UpdatePrintingState() {
1097 bool print_enabled = CanPrint(browser_); 1101 bool print_enabled = CanPrint(browser_);
1098 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); 1102 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
1099 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 1103 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
1100 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT, 1104 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1101 CanBasicPrint(browser_)); 1105 CanBasicPrint(browser_));
1102 #endif // ENABLE_BASIC_PRINTING 1106 #endif // ENABLE_BASIC_PRINTING
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 1177
1174 BrowserWindow* BrowserCommandController::window() { 1178 BrowserWindow* BrowserCommandController::window() {
1175 return browser_->window(); 1179 return browser_->window();
1176 } 1180 }
1177 1181
1178 Profile* BrowserCommandController::profile() { 1182 Profile* BrowserCommandController::profile() {
1179 return browser_->profile(); 1183 return browser_->profile();
1180 } 1184 }
1181 1185
1182 } // namespace chrome 1186 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/browser_command_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698