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..b145c87bf440a35ce8a688989eb1ce30fdf79bc8 100644 |
| --- a/chrome/browser/ui/exclusive_access/exclusive_access_manager.cc |
| +++ b/chrome/browser/ui/exclusive_access/exclusive_access_manager.cc |
| @@ -19,11 +19,21 @@ |
| using content::WebContents; |
| +namespace { |
| + |
| +// Time in milliseconds to hold the Esc key in order to exit full screen. |
| +// TODO(dominickn) refactor the way timings/input handling works so this |
| +// constant doesn't have to be in this file. |
| +const int kHoldEscapeTimeMs = 1500; |
| + |
| +} |
| + |
| 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_() { |
|
msw
2016/03/23 17:07:32
nit: this explicit call to the default ctor should
dominickn
2016/03/23 23:36:22
Done.
|
| } |
| ExclusiveAccessManager::~ExclusiveAccessManager() { |
| @@ -58,6 +68,8 @@ ExclusiveAccessManager::GetExclusiveAccessExitBubbleType() const { |
| if (fullscreen_controller_.IsUserAcceptedFullscreen()) { |
| if (fullscreen_controller_.IsPrivilegedFullscreenForTab()) |
| return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; |
| + if (IsExperimentalKeyboardLockUIEnabled()) |
| + return EXCLUSIVE_ACCESS_BUBBLE_TYPE_KEYBOARD_LOCK_EXIT_INSTRUCTION; |
| if (mouse_lock_controller_.IsMouseLocked()) |
| return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION; |
| if (mouse_lock_controller_.IsMouseLockRequested()) |
| @@ -91,6 +103,11 @@ GURL ExclusiveAccessManager::GetExclusiveAccessBubbleURL() const { |
| } |
| // static |
| +bool ExclusiveAccessManager::IsExperimentalKeyboardLockUIEnabled() { |
| + return base::FeatureList::IsEnabled(features::kExperimentalKeyboardLockUI); |
| +} |
| + |
| +// static |
| bool ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() { |
| return base::FeatureList::IsEnabled(features::kSimplifiedFullscreenUI); |
| } |
| @@ -117,6 +134,27 @@ bool ExclusiveAccessManager::HandleUserKeyPress( |
| return false; |
| } |
| + if (IsExperimentalKeyboardLockUIEnabled()) { |
| + 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::FromMilliseconds(kHoldEscapeTimeMs), |
| + base::Bind(&ExclusiveAccessManager::HandleUserHeldEscape, |
| + base::Unretained(this))); |
| + } |
| + // We never handle the keyboard event. |
| + return false; |
| + } |
| + |
| bool handled = false; |
| handled = fullscreen_controller_.HandleUserPressedEscape(); |
| handled |= mouse_lock_controller_.HandleUserPressedEscape(); |
| @@ -159,6 +197,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_KEYBOARD_LOCK_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 +220,8 @@ void ExclusiveAccessManager::RecordBubbleReshownUMA( |
| if (mouselock) |
| mouse_lock_controller_.RecordBubbleReshownUMA(); |
| } |
| + |
| +void ExclusiveAccessManager::HandleUserHeldEscape() { |
| + fullscreen_controller_.HandleUserPressedEscape(); |
| + mouse_lock_controller_.HandleUserPressedEscape(); |
| +} |