diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-30 13:07:02 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-30 13:07:02 +0000 |
commit | 60d677dd4521ddde2d8b4e16eee0020e38a21a2f (patch) | |
tree | b7ce93d078e3bb15052fc04fd0c966dceb247e10 /ash/accelerators/accelerator_delegate.cc | |
parent | 85e57d4d0241a31881536262ead36f0aff90b4fc (diff) | |
download | chromium_src-60d677dd4521ddde2d8b4e16eee0020e38a21a2f.zip chromium_src-60d677dd4521ddde2d8b4e16eee0020e38a21a2f.tar.gz chromium_src-60d677dd4521ddde2d8b4e16eee0020e38a21a2f.tar.bz2 |
Move common accelerator code from ash to ui/wm/core
accelerator_filter_unittest stays in ash because it requires ash.
BUG=375534
Review URL: https://codereview.chromium.org/307533007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273811 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/accelerators/accelerator_delegate.cc')
-rw-r--r-- | ash/accelerators/accelerator_delegate.cc | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/ash/accelerators/accelerator_delegate.cc b/ash/accelerators/accelerator_delegate.cc new file mode 100644 index 0000000..dc83437 --- /dev/null +++ b/ash/accelerators/accelerator_delegate.cc @@ -0,0 +1,79 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/accelerators/accelerator_delegate.h" + +#include "ash/accelerators/accelerator_controller.h" +#include "ash/shell.h" +#include "ash/wm/window_state.h" +#include "ui/base/accelerators/accelerator.h" +#include "ui/events/event.h" +#include "ui/wm/core/window_util.h" + +namespace ash { +namespace {} // namespace + +AcceleratorDelegate::AcceleratorDelegate() { +} +AcceleratorDelegate::~AcceleratorDelegate() { +} + +void AcceleratorDelegate::PreProcessAccelerator( + const ui::Accelerator& accelerator) { + // Fill out context object so AcceleratorController will know what + // was the previous accelerator or if the current accelerator is repeated. + Shell::GetInstance()->accelerator_controller()->context()->UpdateContext( + accelerator); +} + +// Uses the top level window so if the target is a web contents window the +// containing parent window will be checked for the property. +bool AcceleratorDelegate::CanConsumeSystemKeys(const ui::KeyEvent& event) { + aura::Window* target = static_cast<aura::Window*>(event.target()); + if (!target) // Can be NULL in tests. + return false; + aura::Window* top_level = ::wm::GetToplevelWindow(target); + return top_level && wm::GetWindowState(top_level)->can_consume_system_keys(); +} + +// Returns true if the |accelerator| should be processed now, inside Ash's env +// event filter. +bool AcceleratorDelegate::ShouldProcessAcceleratorNow( + const ui::KeyEvent& event, + const ui::Accelerator& accelerator) { + aura::Window* target = static_cast<aura::Window*>(event.target()); + if (!target) + return true; + + aura::Window::Windows root_windows = Shell::GetAllRootWindows(); + if (std::find(root_windows.begin(), root_windows.end(), target) != + root_windows.end()) + return true; + + // A full screen window should be able to handle all key events including the + // reserved ones. + if (wm::GetWindowState(target)->IsFullscreen()) { + // TODO(yusukes): On Chrome OS, only browser and flash windows can be full + // screen. Launching an app in "open full-screen" mode is not supported yet. + // That makes the IsWindowFullscreen() check above almost meaningless + // because a browser and flash window do handle Ash accelerators anyway + // before they're passed to a page or flash content. + return false; + } + + if (Shell::GetInstance()->GetAppListTargetVisibility()) + return true; + + // Unless |target| is in the full screen state, handle reserved accelerators + // such as Alt+Tab now. + return Shell::GetInstance()->accelerator_controller()->IsReservedAccelerator( + accelerator); +} + +bool AcceleratorDelegate::ProcessAccelerator( + const ui::Accelerator& accelerator) { + return Shell::GetInstance()->accelerator_controller()->Process(accelerator); +} + +} // namespace ash |