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

Unified Diff: ash/common/accelerators/accelerator_router.cc

Issue 2171983002: Move processing out of AcceleratorDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wire_up_controller
Patch Set: feedback Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/common/accelerators/accelerator_router.h ('k') | ash/common/wm_window.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/common/accelerators/accelerator_router.cc
diff --git a/ash/accelerators/accelerator_delegate.cc b/ash/common/accelerators/accelerator_router.cc
similarity index 65%
copy from ash/accelerators/accelerator_delegate.cc
copy to ash/common/accelerators/accelerator_router.cc
index db8024f1cd3ce2a5e4355acee3f660b60eda8283..51e08cbdcb12dfc55d2da1a8bf56de2ffaf5da15 100644
--- a/ash/accelerators/accelerator_delegate.cc
+++ b/ash/common/accelerators/accelerator_router.cc
@@ -2,16 +2,15 @@
// 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/common/accelerators/accelerator_router.h"
#include "ash/common/accelerators/accelerator_controller.h"
#include "ash/common/wm/window_state.h"
#include "ash/common/wm_shell.h"
-#include "ash/shell.h"
-#include "ash/wm/window_state_aura.h"
+#include "ash/common/wm_window.h"
+#include "base/stl_util.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/events/event.h"
-#include "ui/wm/core/window_util.h"
namespace ash {
@@ -41,55 +40,53 @@ bool IsSystemKey(ui::KeyboardCode key_code) {
} // namespace
-AcceleratorDelegate::AcceleratorDelegate() {}
-AcceleratorDelegate::~AcceleratorDelegate() {}
+AcceleratorRouter::AcceleratorRouter() {}
-bool AcceleratorDelegate::ProcessAccelerator(
- const ui::KeyEvent& key_event,
- const ui::Accelerator& accelerator) {
+AcceleratorRouter::~AcceleratorRouter() {}
+
+bool AcceleratorRouter::ProcessAccelerator(WmWindow* target,
+ const ui::KeyEvent& key_event,
+ const ui::Accelerator& accelerator) {
+ // Callers should never supply null.
+ DCHECK(target);
// Special hardware keys like brightness and volume are handled in
// special way. However, some windows can override this behavior
// (e.g. Chrome v1 apps by default and Chrome v2 apps with
// permission) by setting a window property.
- if (IsSystemKey(key_event.key_code()) && !CanConsumeSystemKeys(key_event)) {
+ if (IsSystemKey(key_event.key_code()) &&
+ !CanConsumeSystemKeys(target, key_event)) {
// System keys are always consumed regardless of whether they trigger an
// accelerator to prevent windows from seeing unexpected key up events.
WmShell::Get()->accelerator_controller()->Process(accelerator);
return true;
}
- if (!ShouldProcessAcceleratorNow(key_event, accelerator))
+ if (!ShouldProcessAcceleratorNow(target, key_event, accelerator))
return false;
return WmShell::Get()->accelerator_controller()->Process(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());
- DCHECK(target);
- aura::Window* top_level = ::wm::GetToplevelWindow(target);
- return top_level && wm::GetWindowState(top_level)->can_consume_system_keys();
+bool AcceleratorRouter::CanConsumeSystemKeys(WmWindow* target,
+ const ui::KeyEvent& event) {
+ // Uses the top level window so if the target is a web contents window the
+ // containing parent window will be checked for the property.
+ WmWindow* top_level = target->GetToplevelWindowForFocus();
+ return top_level && top_level->GetWindowState()->can_consume_system_keys();
}
-// Returns true if the |accelerator| should be processed now, inside Ash's env
-// event filter.
-bool AcceleratorDelegate::ShouldProcessAcceleratorNow(
+bool AcceleratorRouter::ShouldProcessAcceleratorNow(
+ WmWindow* target,
const ui::KeyEvent& event,
const ui::Accelerator& accelerator) {
+ // Callers should never supply null.
+ DCHECK(target);
// On ChromeOS, If the accelerator is Search+<key(s)> then it must never be
// intercepted by apps or windows.
if (accelerator.IsCmdDown())
return true;
- aura::Window* target = static_cast<aura::Window*>(event.target());
- DCHECK(target);
-
- aura::Window::Windows root_windows = Shell::GetAllRootWindows();
- if (std::find(root_windows.begin(), root_windows.end(), target) !=
- root_windows.end())
+ if (ContainsValue(WmShell::Get()->GetAllRootWindows(), target))
return true;
- aura::Window* top_level = ::wm::GetToplevelWindow(target);
AcceleratorController* accelerator_controller =
WmShell::Get()->accelerator_controller();
@@ -99,7 +96,8 @@ bool AcceleratorDelegate::ShouldProcessAcceleratorNow(
// A full screen window has a right to handle all key events including the
// reserved ones.
- if (top_level && wm::GetWindowState(top_level)->IsFullscreen()) {
+ WmWindow* top_level = target->GetToplevelWindowForFocus();
+ if (top_level && top_level->GetWindowState()->IsFullscreen()) {
// On ChromeOS, fullscreen windows are either browser or apps, which
// send key events to a web content first, then will process keys
// if the web content didn't consume them.
« no previous file with comments | « ash/common/accelerators/accelerator_router.h ('k') | ash/common/wm_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698