Index: ash/accelerators/accelerator_delegate.cc |
diff --git a/ash/accelerators/accelerator_delegate.cc b/ash/accelerators/accelerator_delegate.cc |
index dc83437aceef6f0d5863cfbd4a42a14e9081e8be..f00efe62a4d0654007d14a28644762fac54a8556 100644 |
--- a/ash/accelerators/accelerator_delegate.cc |
+++ b/ash/accelerators/accelerator_delegate.cc |
@@ -27,12 +27,31 @@ void AcceleratorDelegate::PreProcessAccelerator( |
accelerator); |
} |
+bool AcceleratorDelegate::ProcessAccelerator(const ui::KeyEvent& key_event, |
+ const ui::Accelerator& accelerator, |
+ KeyType key_type) { |
+ // 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 (key_type == SYSTEM_KEYS && !CanConsumeSystemKeys(key_event)) { |
+ // System keys are always consumed regardless of whether they trigger an |
+ // accelerator to prevent windows from seeing unexpected key up events. |
+ Shell::GetInstance()->accelerator_controller()->Process(accelerator); |
+ return true; |
+ } |
+ if (key_type == NORMAL_KEYS && |
+ !ShouldProcessAcceleratorNow(key_event, accelerator)) { |
+ return false; |
+ } |
+ return Shell::GetInstance()->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()); |
- if (!target) // Can be NULL in tests. |
- return false; |
+ DCHECK(target); |
aura::Window* top_level = ::wm::GetToplevelWindow(target); |
return top_level && wm::GetWindowState(top_level)->can_consume_system_keys(); |
} |
@@ -43,9 +62,7 @@ bool AcceleratorDelegate::ShouldProcessAcceleratorNow( |
const ui::KeyEvent& event, |
const ui::Accelerator& accelerator) { |
aura::Window* target = static_cast<aura::Window*>(event.target()); |
- if (!target) |
- return true; |
- |
+ DCHECK(target); |
aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
if (std::find(root_windows.begin(), root_windows.end(), target) != |
root_windows.end()) |
@@ -53,7 +70,9 @@ bool AcceleratorDelegate::ShouldProcessAcceleratorNow( |
// A full screen window should be able to handle all key events including the |
// reserved ones. |
- if (wm::GetWindowState(target)->IsFullscreen()) { |
+ aura::Window* top_level = ::wm::GetToplevelWindow(target); |
+ |
+ if (top_level && wm::GetWindowState(top_level)->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 |
@@ -71,9 +90,4 @@ bool AcceleratorDelegate::ShouldProcessAcceleratorNow( |
accelerator); |
} |
-bool AcceleratorDelegate::ProcessAccelerator( |
- const ui::Accelerator& accelerator) { |
- return Shell::GetInstance()->accelerator_controller()->Process(accelerator); |
-} |
- |
} // namespace ash |