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

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

Issue 2636013002: Disable browser key reservation in fullscreen mode (Closed)
Patch Set: Resolve review comments 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 {
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
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 fullscreen, all keys except Esc and F11 should be delivered to the web
msw 2017/02/09 18:01:13 nit: maybe describe this in terms of commands, not
Hzj_jie 2017/02/10 01:14:23 Done.
192 // page. See https://goo.gl/4tJ32G.
193 if (command_id == IDC_FULLSCREEN) {
msw 2017/02/09 18:01:13 If the comment above is correct; why can't we just
Hzj_jie 2017/02/10 01:14:23 I have updated the comment. IDC_EXIT should also b
194 return true;
195 } else if (command_id == IDC_CLOSE_TAB ||
msw 2017/02/09 18:01:13 nit: no else after return
Hzj_jie 2017/02/10 01:14:23 Done.
196 command_id == IDC_CLOSE_WINDOW ||
msw 2017/02/09 18:01:13 nit: since most of this block is duplicated below,
Hzj_jie 2017/02/10 01:14:23 Done.
197 command_id == IDC_NEW_INCOGNITO_WINDOW ||
198 command_id == IDC_NEW_TAB ||
199 command_id == IDC_NEW_WINDOW ||
200 command_id == IDC_RESTORE_TAB ||
201 command_id == IDC_SELECT_NEXT_TAB ||
202 command_id == IDC_SELECT_PREVIOUS_TAB) {
203 return false;
204 }
205 }
204 206
205 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 207 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
206 // If this key was registered by the user as a content editing hotkey, then 208 // If this key was registered by the user as a content editing hotkey, then
207 // it is not reserved. 209 // it is not reserved.
208 ui::TextEditKeyBindingsDelegateAuraLinux* delegate = 210 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
209 ui::GetTextEditKeyBindingsDelegate(); 211 ui::GetTextEditKeyBindingsDelegate();
210 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL)) 212 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
211 return false; 213 return false;
212 #endif 214 #endif
213 215
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 bookmarks::prefs::kShowBookmarkBar) && 1015 bookmarks::prefs::kShowBookmarkBar) &&
1014 IsShowingMainUI()); 1016 IsShowingMainUI());
1015 } 1017 }
1016 1018
1017 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() { 1019 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
1018 UpdateSaveAsState(); 1020 UpdateSaveAsState();
1019 UpdateOpenFileState(&command_updater_); 1021 UpdateOpenFileState(&command_updater_);
1020 } 1022 }
1021 1023
1022 void BrowserCommandController::UpdateCommandsForFullscreenMode() { 1024 void BrowserCommandController::UpdateCommandsForFullscreenMode() {
1023 WindowState window_state = WINDOW_STATE_NOT_FULLSCREEN; 1025 const bool is_fullscreen = (window() && window()->IsFullscreen());
msw 2017/02/09 18:01:13 nit: parens not needed
Hzj_jie 2017/02/10 01:14:23 Done.
1024 if (window() && window()->IsFullscreen()) { 1026 const bool show_main_ui = IsShowingMainUI();
1025 window_state = WINDOW_STATE_FULLSCREEN; 1027 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
1026 }
1027 bool show_main_ui = IsShowingMainUI();
1028 bool main_not_fullscreen =
1029 show_main_ui && window_state == WINDOW_STATE_NOT_FULLSCREEN;
1030 1028
1031 // Navigation commands 1029 // Navigation commands
1032 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui); 1030 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1033 1031
1034 // Window management commands 1032 // Window management commands
1035 command_updater_.UpdateCommandEnabled( 1033 command_updater_.UpdateCommandEnabled(
1036 IDC_SHOW_AS_TAB, 1034 IDC_SHOW_AS_TAB,
1037 !browser_->is_type_tabbed() && 1035 !browser_->is_type_tabbed() && !is_fullscreen);
1038 window_state == WINDOW_STATE_NOT_FULLSCREEN);
1039 1036
1040 // Focus various bits of UI 1037 // Focus various bits of UI
1041 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui); 1038 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
1042 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui); 1039 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui);
1043 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui); 1040 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
1044 command_updater_.UpdateCommandEnabled( 1041 command_updater_.UpdateCommandEnabled(
1045 IDC_FOCUS_MENU_BAR, main_not_fullscreen); 1042 IDC_FOCUS_MENU_BAR, main_not_fullscreen);
1046 command_updater_.UpdateCommandEnabled( 1043 command_updater_.UpdateCommandEnabled(
1047 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); 1044 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
1048 command_updater_.UpdateCommandEnabled( 1045 command_updater_.UpdateCommandEnabled(
(...skipping 21 matching lines...) Expand all
1070 options_enabled && !guest_session); 1067 options_enabled && !guest_session);
1071 1068
1072 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); 1069 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1073 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); 1070 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1074 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); 1071 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1075 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); 1072 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
1076 1073
1077 if (base::debug::IsProfilingSupported()) 1074 if (base::debug::IsProfilingSupported())
1078 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); 1075 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
1079 1076
1080 bool fullscreen_enabled = true;
1081 #if !defined(OS_MACOSX) 1077 #if !defined(OS_MACOSX)
1082 if (window_state == WINDOW_STATE_NOT_FULLSCREEN && 1078 // Disable toggling into fullscreen mode if disallowed by pref.
1083 !profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed)) { 1079 const bool fullscreen_enabled = is_fullscreen ||
1084 // Disable toggling into fullscreen mode if disallowed by pref. 1080 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1085 fullscreen_enabled = false; 1081 #else
1086 } 1082 const bool fullscreen_enabled = true;
1087 #endif 1083 #endif
1088 1084
1089 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled); 1085 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
1090 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR, 1086 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1091 fullscreen_enabled); 1087 fullscreen_enabled);
1092 1088
1089 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, !is_fullscreen);
msw 2017/02/09 18:01:13 Does this CL need security/UX review beyond the 'i
Hzj_jie 2017/02/10 01:14:23 Dominick has reviewed this already, though I canno
1090 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, !is_fullscreen);
1091 command_updater_.UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW,
1092 !is_fullscreen);
1093 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, !is_fullscreen);
1094 command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, !is_fullscreen);
1095 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, !is_fullscreen);
1096 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, !is_fullscreen);
1097 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
1098 !is_fullscreen);
1099
1093 UpdateCommandsForBookmarkBar(); 1100 UpdateCommandsForBookmarkBar();
1094 } 1101 }
1095 1102
1096 void BrowserCommandController::UpdatePrintingState() { 1103 void BrowserCommandController::UpdatePrintingState() {
1097 bool print_enabled = CanPrint(browser_); 1104 bool print_enabled = CanPrint(browser_);
1098 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); 1105 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
1099 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 1106 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
1100 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT, 1107 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1101 CanBasicPrint(browser_)); 1108 CanBasicPrint(browser_));
1102 #endif // ENABLE_BASIC_PRINTING 1109 #endif // ENABLE_BASIC_PRINTING
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 1180
1174 BrowserWindow* BrowserCommandController::window() { 1181 BrowserWindow* BrowserCommandController::window() {
1175 return browser_->window(); 1182 return browser_->window();
1176 } 1183 }
1177 1184
1178 Profile* BrowserCommandController::profile() { 1185 Profile* BrowserCommandController::profile() {
1179 return browser_->profile(); 1186 return browser_->profile();
1180 } 1187 }
1181 1188
1182 } // namespace chrome 1189 } // 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