Chromium Code Reviews| Index: chrome/browser/ui/exclusive_access/exclusive_access_manager.cc |
| diff --git a/chrome/browser/ui/exclusive_access/exclusive_access_manager.cc b/chrome/browser/ui/exclusive_access/exclusive_access_manager.cc |
| index 666d11e6970660990014e60c2a88d65f567d018b..29ecf1687cf6c3cf49ff552fbdecc003fa655d4a 100644 |
| --- a/chrome/browser/ui/exclusive_access/exclusive_access_manager.cc |
| +++ b/chrome/browser/ui/exclusive_access/exclusive_access_manager.cc |
| @@ -19,11 +19,19 @@ |
| using content::WebContents; |
| +namespace { |
| + |
| +// Time in seconds required to hold the Esc key in order to exit full screen. |
| +const double kDurationToHoldEscapeToExitFullscreen = 1.5; |
|
Matt Giuca
2016/03/21 00:36:07
I think this should be in c/b/u/exclusive_access/e
dominickn
2016/03/21 21:58:04
That means a) pulling in exclusive_access_bubble.h
msw
2016/03/23 07:20:54
nit: add a todo if you think it should be moved
|
| + |
| +} |
| + |
| ExclusiveAccessManager::ExclusiveAccessManager( |
| ExclusiveAccessContext* exclusive_access_context) |
| : exclusive_access_context_(exclusive_access_context), |
| fullscreen_controller_(this), |
| - mouse_lock_controller_(this) { |
| + mouse_lock_controller_(this), |
| + hold_timer_(true, false) { |
| } |
| ExclusiveAccessManager::~ExclusiveAccessManager() { |
| @@ -58,6 +66,9 @@ ExclusiveAccessManager::GetExclusiveAccessExitBubbleType() const { |
| if (fullscreen_controller_.IsUserAcceptedFullscreen()) { |
| if (fullscreen_controller_.IsPrivilegedFullscreenForTab()) |
| return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; |
| + if (IsExperimentalFullscreenUIEnabled()) |
| + return |
| + EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXPERIMENTAL_FULLSCREEN_EXIT_INSTRUCTION; |
| if (mouse_lock_controller_.IsMouseLocked()) |
| return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION; |
| if (mouse_lock_controller_.IsMouseLockRequested()) |
| @@ -91,6 +102,11 @@ GURL ExclusiveAccessManager::GetExclusiveAccessBubbleURL() const { |
| } |
| // static |
| +bool ExclusiveAccessManager::IsExperimentalFullscreenUIEnabled() { |
| + return base::FeatureList::IsEnabled(features::kExperimentalFullscreenUI); |
| +} |
| + |
| +// static |
| bool ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() { |
| return base::FeatureList::IsEnabled(features::kSimplifiedFullscreenUI); |
| } |
| @@ -112,15 +128,39 @@ void ExclusiveAccessManager::OnTabClosing(WebContents* web_contents) { |
| bool ExclusiveAccessManager::HandleUserKeyPress( |
| const content::NativeWebKeyboardEvent& event) { |
| - if (event.windowsKeyCode != ui::VKEY_ESCAPE) { |
| - OnUserInput(); |
| + if (IsExperimentalFullscreenUIEnabled()) { |
| + if (event.windowsKeyCode != ui::VKEY_ESCAPE) { |
|
Matt Giuca
2016/03/21 00:36:07
This block got duplicated. It's the same for both
dominickn
2016/03/21 21:58:04
Good point, thanks
|
| + OnUserInput(); |
| + } else if (event.type == content::NativeWebKeyboardEvent::KeyUp && |
| + hold_timer_.IsRunning()) { |
| + // Seeing a key up event on Esc with the hold timer running cancels the |
| + // timer and doesn't exit. This means the user pressed Esc, but not long |
| + // enough to trigger an exit |
| + hold_timer_.Stop(); |
| + } else if (event.type == content::NativeWebKeyboardEvent::RawKeyDown && |
| + !hold_timer_.IsRunning()) { |
| + // Seeing a key down event on Esc when the hold timer is stopped starts |
| + // the timer. When the timer reaches 0, the callback will trigger an exit |
| + // from fullscreen/mouselock. |
| + hold_timer_.Start( |
| + FROM_HERE, |
| + base::TimeDelta::FromSeconds(kDurationToHoldEscapeToExitFullscreen), |
|
Matt Giuca
2016/03/21 00:36:07
FromSeconds takes an int, so this will round down
dominickn
2016/03/21 21:58:04
FromMillseeconds, done
|
| + base::Bind(&ExclusiveAccessManager::HandleUserHeldEscape, |
| + base::Unretained(this))); |
| + } |
| + // We never handle the keyboard event. |
| return false; |
| + } else { |
| + if (event.windowsKeyCode != ui::VKEY_ESCAPE) { |
| + OnUserInput(); |
| + return false; |
| + } |
| + |
| + bool handled = false; |
| + handled = fullscreen_controller_.HandleUserPressedEscape(); |
| + handled |= mouse_lock_controller_.HandleUserPressedEscape(); |
| + return handled; |
| } |
| - |
| - bool handled = false; |
| - handled = fullscreen_controller_.HandleUserPressedEscape(); |
| - handled |= mouse_lock_controller_.HandleUserPressedEscape(); |
| - return handled; |
| } |
| void ExclusiveAccessManager::OnUserInput() { |
| @@ -159,6 +199,7 @@ void ExclusiveAccessManager::RecordBubbleReshownUMA( |
| break; |
| case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS: |
| case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION: |
| + case EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXPERIMENTAL_FULLSCREEN_EXIT_INSTRUCTION: |
| case EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION: |
| case EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION: |
| // Only fullscreen in effect. |
| @@ -181,3 +222,8 @@ void ExclusiveAccessManager::RecordBubbleReshownUMA( |
| if (mouselock) |
| mouse_lock_controller_.RecordBubbleReshownUMA(); |
| } |
| + |
| +void ExclusiveAccessManager::HandleUserHeldEscape() { |
| + fullscreen_controller_.HandleUserPressedEscape(); |
| + mouse_lock_controller_.HandleUserPressedEscape(); |
| +} |