Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / ui / content_accelerators / accelerator_util.cc
blob9930cb6aa5c5c677a941140577520a9fb72db6d0
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"
11 namespace ui {
13 namespace {
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;
27 #endif
28 return modifiers;
31 } // namespace
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);
40 #if defined(USE_AURA)
41 if (event.os_event && event.os_event->IsRepeat())
42 accelerator.set_is_repeat(true);
43 #endif
44 return accelerator;
47 } // namespace ui