summaryrefslogtreecommitdiffstats
path: root/ui/content_accelerators/accelerator_util.cc
blob: 9930cb6aa5c5c677a941140577520a9fb72db6d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/content_accelerators/accelerator_util.h"

#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"

namespace ui {

namespace {

int GetModifiersFromNativeWebKeyboardEvent(
    const content::NativeWebKeyboardEvent& event) {
  int modifiers = ui::EF_NONE;
  if (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey)
    modifiers |= ui::EF_SHIFT_DOWN;
  if (event.modifiers & content::NativeWebKeyboardEvent::ControlKey)
    modifiers |= ui::EF_CONTROL_DOWN;
  if (event.modifiers & content::NativeWebKeyboardEvent::AltKey)
    modifiers |= ui::EF_ALT_DOWN;
#if defined(OS_MACOSX) || defined(OS_CHROMEOS)
  if (event.modifiers & content::NativeWebKeyboardEvent::MetaKey)
    modifiers |= ui::EF_COMMAND_DOWN;
#endif
  return modifiers;
}

}  // namespace

ui::Accelerator GetAcceleratorFromNativeWebKeyboardEvent(
    const content::NativeWebKeyboardEvent& event) {
  ui::Accelerator accelerator(
      static_cast<ui::KeyboardCode>(event.windowsKeyCode),
      GetModifiersFromNativeWebKeyboardEvent(event));
  if (event.type == blink::WebInputEvent::KeyUp)
    accelerator.set_type(ui::ET_KEY_RELEASED);
#if defined(USE_AURA)
  if (event.os_event && event.os_event->IsRepeat())
    accelerator.set_is_repeat(true);
#endif
  return accelerator;
}

}  // namespace ui