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

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 const bool is_tab_or_window_command =
203 return true; 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()) {
msw 2017/02/10 02:03:39 Can we replace this block with: if (window()->Is
Hzj_jie 2017/02/10 19:18:08 It looks like your solution changes the behavior o
msw 2017/02/10 23:56:14 Can you elaborate? It looks like the Linux block o
200 // In fullscreen, all commands except for IDC_FULLSCREEN and IDC_EXIT should
201 // be delivered to the web page. See https://goo.gl/4tJ32G.
202 if (command_id == IDC_FULLSCREEN) {
msw 2017/02/10 02:03:39 nit: curlies not needed
Hzj_jie 2017/02/10 19:18:08 Done.
203 return true;
204 }
205 if (is_tab_or_window_command) {
msw 2017/02/10 02:03:39 nit: curlies not needed
Hzj_jie 2017/02/10 19:18:08 Done.
206 return false;
207 }
208 }
204 209
205 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 210 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
206 // If this key was registered by the user as a content editing hotkey, then 211 // If this key was registered by the user as a content editing hotkey, then
207 // it is not reserved. 212 // it is not reserved.
208 ui::TextEditKeyBindingsDelegateAuraLinux* delegate = 213 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
209 ui::GetTextEditKeyBindingsDelegate(); 214 ui::GetTextEditKeyBindingsDelegate();
210 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL)) 215 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
211 return false; 216 return false;
212 #endif 217 #endif
213 218
214 return command_id == IDC_CLOSE_TAB || 219 return is_tab_or_window_command || command_id == IDC_EXIT;
215 command_id == IDC_CLOSE_WINDOW ||
216 command_id == IDC_NEW_INCOGNITO_WINDOW ||
217 command_id == IDC_NEW_TAB ||
218 command_id == IDC_NEW_WINDOW ||
219 command_id == IDC_RESTORE_TAB ||
220 command_id == IDC_SELECT_NEXT_TAB ||
221 command_id == IDC_SELECT_PREVIOUS_TAB ||
222 command_id == IDC_EXIT;
223 } 220 }
224 221
225 void BrowserCommandController::SetBlockCommandExecution(bool block) { 222 void BrowserCommandController::SetBlockCommandExecution(bool block) {
226 block_command_execution_ = block; 223 block_command_execution_ = block;
227 if (block) { 224 if (block) {
228 last_blocked_command_id_ = -1; 225 last_blocked_command_id_ = -1;
229 last_blocked_command_disposition_ = WindowOpenDisposition::CURRENT_TAB; 226 last_blocked_command_disposition_ = WindowOpenDisposition::CURRENT_TAB;
230 } 227 }
231 } 228 }
232 229
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 bookmarks::prefs::kShowBookmarkBar) && 1010 bookmarks::prefs::kShowBookmarkBar) &&
1014 IsShowingMainUI()); 1011 IsShowingMainUI());
1015 } 1012 }
1016 1013
1017 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() { 1014 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
1018 UpdateSaveAsState(); 1015 UpdateSaveAsState();
1019 UpdateOpenFileState(&command_updater_); 1016 UpdateOpenFileState(&command_updater_);
1020 } 1017 }
1021 1018
1022 void BrowserCommandController::UpdateCommandsForFullscreenMode() { 1019 void BrowserCommandController::UpdateCommandsForFullscreenMode() {
1023 WindowState window_state = WINDOW_STATE_NOT_FULLSCREEN; 1020 const bool is_fullscreen = window() && window()->IsFullscreen();
1024 if (window() && window()->IsFullscreen()) { 1021 const bool show_main_ui = IsShowingMainUI();
1025 window_state = WINDOW_STATE_FULLSCREEN; 1022 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 1023
1031 // Navigation commands 1024 // Navigation commands
1032 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui); 1025 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1033 1026
1034 // Window management commands 1027 // Window management commands
1035 command_updater_.UpdateCommandEnabled( 1028 command_updater_.UpdateCommandEnabled(
1036 IDC_SHOW_AS_TAB, 1029 IDC_SHOW_AS_TAB,
1037 !browser_->is_type_tabbed() && 1030 !browser_->is_type_tabbed() && !is_fullscreen);
1038 window_state == WINDOW_STATE_NOT_FULLSCREEN);
1039 1031
1040 // Focus various bits of UI 1032 // Focus various bits of UI
1041 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui); 1033 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
1042 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui); 1034 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui);
1043 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui); 1035 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
1044 command_updater_.UpdateCommandEnabled( 1036 command_updater_.UpdateCommandEnabled(
1045 IDC_FOCUS_MENU_BAR, main_not_fullscreen); 1037 IDC_FOCUS_MENU_BAR, main_not_fullscreen);
1046 command_updater_.UpdateCommandEnabled( 1038 command_updater_.UpdateCommandEnabled(
1047 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); 1039 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
1048 command_updater_.UpdateCommandEnabled( 1040 command_updater_.UpdateCommandEnabled(
(...skipping 21 matching lines...) Expand all
1070 options_enabled && !guest_session); 1062 options_enabled && !guest_session);
1071 1063
1072 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); 1064 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1073 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); 1065 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1074 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); 1066 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1075 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); 1067 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
1076 1068
1077 if (base::debug::IsProfilingSupported()) 1069 if (base::debug::IsProfilingSupported())
1078 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); 1070 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
1079 1071
1080 bool fullscreen_enabled = true;
1081 #if !defined(OS_MACOSX) 1072 #if !defined(OS_MACOSX)
1082 if (window_state == WINDOW_STATE_NOT_FULLSCREEN && 1073 // Disable toggling into fullscreen mode if disallowed by pref.
1083 !profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed)) { 1074 const bool fullscreen_enabled = is_fullscreen ||
1084 // Disable toggling into fullscreen mode if disallowed by pref. 1075 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1085 fullscreen_enabled = false; 1076 #else
1086 } 1077 const bool fullscreen_enabled = true;
1087 #endif 1078 #endif
1088 1079
1089 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled); 1080 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
1090 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR, 1081 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1091 fullscreen_enabled); 1082 fullscreen_enabled);
1092 1083
1084 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, !is_fullscreen);
1085 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, !is_fullscreen);
1086 command_updater_.UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW,
1087 !is_fullscreen);
1088 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, !is_fullscreen);
1089 command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, !is_fullscreen);
1090 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, !is_fullscreen);
1091 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, !is_fullscreen);
1092 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
1093 !is_fullscreen);
1094
1093 UpdateCommandsForBookmarkBar(); 1095 UpdateCommandsForBookmarkBar();
1094 } 1096 }
1095 1097
1096 void BrowserCommandController::UpdatePrintingState() { 1098 void BrowserCommandController::UpdatePrintingState() {
1097 bool print_enabled = CanPrint(browser_); 1099 bool print_enabled = CanPrint(browser_);
1098 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); 1100 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
1099 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 1101 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
1100 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT, 1102 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1101 CanBasicPrint(browser_)); 1103 CanBasicPrint(browser_));
1102 #endif // ENABLE_BASIC_PRINTING 1104 #endif // ENABLE_BASIC_PRINTING
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 1175
1174 BrowserWindow* BrowserCommandController::window() { 1176 BrowserWindow* BrowserCommandController::window() {
1175 return browser_->window(); 1177 return browser_->window();
1176 } 1178 }
1177 1179
1178 Profile* BrowserCommandController::profile() { 1180 Profile* BrowserCommandController::profile() {
1179 return browser_->profile(); 1181 return browser_->profile();
1180 } 1182 }
1181 1183
1182 } // namespace chrome 1184 } // 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