1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/views/focus/accelerator_handler.h"
7 #include "ui/events/event.h"
8 #include "ui/events/keycodes/keyboard_code_conversion_win.h"
9 #include "ui/events/keycodes/keyboard_codes.h"
10 #include "ui/views/focus/focus_manager.h"
11 #include "ui/views/widget/widget.h"
15 AcceleratorHandler::AcceleratorHandler() {
18 bool AcceleratorHandler::Dispatch(const base::NativeEvent
& msg
) {
19 if (msg
.message
>= WM_KEYFIRST
&& msg
.message
<= WM_KEYLAST
) {
20 Widget
* widget
= Widget::GetTopLevelWidgetForNativeView(msg
.hwnd
);
21 FocusManager
* focus_manager
= widget
? widget
->GetFocusManager() : NULL
;
23 switch (msg
.message
) {
26 ui::KeyEvent
event(msg
, false);
27 if (!focus_manager
->OnKeyEvent(event
)) {
28 // Record that this key is pressed so we can remember not to
29 // translate and dispatch the associated WM_KEYUP.
30 pressed_keys_
.insert(msg
.wParam
);
37 std::set
<WPARAM
>::iterator iter
= pressed_keys_
.find(msg
.wParam
);
38 if (iter
!= pressed_keys_
.end()) {
39 // Don't translate/dispatch the KEYUP since we have eaten the
40 // associated KEYDOWN.
41 pressed_keys_
.erase(iter
);
50 TranslateMessage(&msg
);
51 DispatchMessage(&msg
);