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/content_accelerators/accelerator_util.h"
7 #include "third_party/WebKit/public/web/WebInputEvent.h"
8 #include "ui/events/event.h"
9 #include "ui/events/event_constants.h"
15 int GetModifiersFromNativeWebKeyboardEvent(
16 const content::NativeWebKeyboardEvent
& event
) {
17 int modifiers
= ui::EF_NONE
;
18 if (event
.modifiers
& content::NativeWebKeyboardEvent::ShiftKey
)
19 modifiers
|= ui::EF_SHIFT_DOWN
;
20 if (event
.modifiers
& content::NativeWebKeyboardEvent::ControlKey
)
21 modifiers
|= ui::EF_CONTROL_DOWN
;
22 if (event
.modifiers
& content::NativeWebKeyboardEvent::AltKey
)
23 modifiers
|= ui::EF_ALT_DOWN
;
24 #if defined(OS_MACOSX) || defined(OS_CHROMEOS)
25 if (event
.modifiers
& content::NativeWebKeyboardEvent::MetaKey
)
26 modifiers
|= ui::EF_COMMAND_DOWN
;
33 ui::Accelerator
GetAcceleratorFromNativeWebKeyboardEvent(
34 const content::NativeWebKeyboardEvent
& event
) {
35 ui::Accelerator
accelerator(
36 static_cast<ui::KeyboardCode
>(event
.windowsKeyCode
),
37 GetModifiersFromNativeWebKeyboardEvent(event
));
38 if (event
.type
== blink::WebInputEvent::KeyUp
)
39 accelerator
.set_type(ui::ET_KEY_RELEASED
);
41 if (event
.os_event
&& event
.os_event
->IsRepeat())
42 accelerator
.set_is_repeat(true);