This source file includes following definitions.
- IsKeyEvent
- IsKeyEvent
- IsKeyEvent
- IsPossibleAcceleratorNotForMenu
#include "ash/accelerators/accelerator_dispatcher.h"
#if defined(USE_X11)
#include <X11/Xlib.h>
#endif
#include "ash/accelerators/accelerator_controller.h"
#include "ash/shell.h"
#include "ui/aura/env.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_utils.h"
#include "ui/views/controls/menu/menu_controller.h"
namespace ash {
namespace {
const int kModifierMask = (ui::EF_SHIFT_DOWN |
ui::EF_CONTROL_DOWN |
ui::EF_ALT_DOWN);
#if defined(OS_WIN)
bool IsKeyEvent(const MSG& msg) {
return
msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN ||
msg.message == WM_KEYUP || msg.message == WM_SYSKEYUP;
}
#elif defined(USE_X11)
bool IsKeyEvent(const XEvent* xev) {
return xev->type == KeyPress || xev->type == KeyRelease;
}
#elif defined(USE_OZONE)
bool IsKeyEvent(const base::NativeEvent& native_event) {
const ui::KeyEvent* event = static_cast<const ui::KeyEvent*>(native_event);
return event->IsKeyEvent();
}
#endif
bool IsPossibleAcceleratorNotForMenu(const ui::KeyEvent& key_event) {
if (key_event.type() == ui::ET_KEY_PRESSED &&
(key_event.flags() & (ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN))) {
const ui::KeyboardCode key_code = key_event.key_code();
if ((key_code >= ui::VKEY_A && key_code <= ui::VKEY_Z) ||
(key_code >= ui::VKEY_0 && key_code <= ui::VKEY_9) ||
(key_code == ui::VKEY_TAB)) {
return true;
}
}
return false;
}
}
AcceleratorDispatcher::AcceleratorDispatcher(
base::MessagePumpDispatcher* nested_dispatcher)
: nested_dispatcher_(nested_dispatcher) {
}
AcceleratorDispatcher::~AcceleratorDispatcher() {
}
uint32_t AcceleratorDispatcher::Dispatch(const base::NativeEvent& event) {
if (IsKeyEvent(event)) {
ui::KeyEvent key_event(event, false);
if (IsPossibleAcceleratorNotForMenu(key_event)) {
if (views::MenuController* menu_controller =
views::MenuController::GetActiveInstance()) {
menu_controller->CancelAll();
#if defined(USE_X11)
XPutBackEvent(event->xany.display, event);
#else
NOTIMPLEMENTED() << " Repost NativeEvent here.";
#endif
return POST_DISPATCH_QUIT_LOOP;
}
}
ash::AcceleratorController* accelerator_controller =
ash::Shell::GetInstance()->accelerator_controller();
if (accelerator_controller) {
ui::Accelerator accelerator(key_event.key_code(),
key_event.flags() & kModifierMask);
if (key_event.type() == ui::ET_KEY_RELEASED)
accelerator.set_type(ui::ET_KEY_RELEASED);
Shell::GetInstance()->accelerator_controller()->context()->
UpdateContext(accelerator);
if (accelerator_controller->Process(accelerator))
return POST_DISPATCH_NONE;
}
return nested_dispatcher_
? nested_dispatcher_->Dispatch(key_event.native_event())
: POST_DISPATCH_PERFORM_DEFAULT;
}
return nested_dispatcher_ ? nested_dispatcher_->Dispatch(event)
: POST_DISPATCH_PERFORM_DEFAULT;
}
}