This source file includes following definitions.
- IsSystemKey
- CanConsumeSystemKeys
- ShouldProcessAcceleratorsNow
- OnKeyEvent
#include "ash/accelerators/accelerator_filter.h"
#include "ash/accelerators/accelerator_controller.h"
#include "ash/shell.h"
#include "ash/wm/window_state.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/accelerators/accelerator_manager.h"
#include "ui/events/event.h"
#include "ui/wm/core/window_util.h"
namespace ash {
namespace {
const int kModifierFlagMask = (ui::EF_SHIFT_DOWN |
ui::EF_CONTROL_DOWN |
ui::EF_ALT_DOWN);
bool IsSystemKey(ui::KeyboardCode key_code) {
#if defined(OS_CHROMEOS)
switch (key_code) {
case ui::VKEY_MEDIA_LAUNCH_APP2:
case ui::VKEY_MEDIA_LAUNCH_APP1:
case ui::VKEY_BRIGHTNESS_DOWN:
case ui::VKEY_BRIGHTNESS_UP:
case ui::VKEY_KBD_BRIGHTNESS_DOWN:
case ui::VKEY_KBD_BRIGHTNESS_UP:
case ui::VKEY_VOLUME_MUTE:
case ui::VKEY_VOLUME_DOWN:
case ui::VKEY_VOLUME_UP:
return true;
default:
return false;
}
#endif
return false;
}
bool CanConsumeSystemKeys(aura::Window* target) {
if (!target)
return false;
aura::Window* top_level = ::wm::GetToplevelWindow(target);
return top_level && wm::GetWindowState(top_level)->can_consume_system_keys();
}
bool ShouldProcessAcceleratorsNow(const ui::Accelerator& accelerator,
aura::Window* 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;
if (wm::GetWindowState(target)->IsFullscreen()) {
return false;
}
if (Shell::GetInstance()->GetAppListTargetVisibility())
return true;
return Shell::GetInstance()->accelerator_controller()->IsReservedAccelerator(
accelerator);
}
}
AcceleratorFilter::AcceleratorFilter() {
}
AcceleratorFilter::~AcceleratorFilter() {
}
void AcceleratorFilter::OnKeyEvent(ui::KeyEvent* event) {
const ui::EventType type = event->type();
if (type != ui::ET_KEY_PRESSED && type != ui::ET_KEY_RELEASED)
return;
if (event->is_char())
return;
ui::Accelerator accelerator(event->key_code(),
event->flags() & kModifierFlagMask);
accelerator.set_type(type);
AcceleratorController* accelerator_controller =
Shell::GetInstance()->accelerator_controller();
accelerator_controller->context()->UpdateContext(accelerator);
aura::Window* target = static_cast<aura::Window*>(event->target());
if (IsSystemKey(event->key_code()) && !CanConsumeSystemKeys(target)) {
accelerator_controller->Process(accelerator);
event->StopPropagation();
return;
}
if (!ShouldProcessAcceleratorsNow(accelerator, target))
return;
if (accelerator_controller->Process(accelerator))
event->StopPropagation();
}
}