blob: 5542f597f06280cfb3eaaca9a1f08778ace106f4 [file] [log] [blame]
[email protected]fdc92726552009-03-23 20:26:561// Copyright (c) 2009 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.
4
[email protected]2362e4f2009-05-08 00:34:055#include "views/event.h"
[email protected]fdc92726552009-03-23 20:26:566
[email protected]a1a02aef2009-03-23 20:37:197#include <windows.h>
8
[email protected]fdc92726552009-03-23 20:26:569namespace views {
10
11int Event::GetWindowsFlags() const {
12 // TODO: need support for x1/x2.
13 int result = 0;
14 result |= (flags_ & EF_SHIFT_DOWN) ? MK_SHIFT : 0;
15 result |= (flags_ & EF_CONTROL_DOWN) ? MK_CONTROL : 0;
16 result |= (flags_ & EF_LEFT_BUTTON_DOWN) ? MK_LBUTTON : 0;
17 result |= (flags_ & EF_MIDDLE_BUTTON_DOWN) ? MK_MBUTTON : 0;
18 result |= (flags_ & EF_RIGHT_BUTTON_DOWN) ? MK_RBUTTON : 0;
19 return result;
20}
21
22//static
23int Event::ConvertWindowsFlags(UINT win_flags) {
24 int r = 0;
25 if (win_flags & MK_CONTROL)
26 r |= EF_CONTROL_DOWN;
27 if (win_flags & MK_SHIFT)
28 r |= EF_SHIFT_DOWN;
29 if (GetKeyState(VK_MENU) < 0)
30 r |= EF_ALT_DOWN;
31 if (win_flags & MK_LBUTTON)
32 r |= EF_LEFT_BUTTON_DOWN;
33 if (win_flags & MK_MBUTTON)
34 r |= EF_MIDDLE_BUTTON_DOWN;
35 if (win_flags & MK_RBUTTON)
36 r |= EF_RIGHT_BUTTON_DOWN;
37 return r;
38}
39
[email protected]0e0e6d752009-10-08 16:28:4440// static
41int KeyEvent::GetKeyStateFlags() {
[email protected]fdc92726552009-03-23 20:26:5642 // Windows Keyboard messages don't come with control key state as parameters
43 // like mouse messages do, so we need to explicitly probe for these key
44 // states.
45 int flags = 0;
46 if (GetKeyState(VK_MENU) & 0x80)
47 flags |= Event::EF_ALT_DOWN;
48 if (GetKeyState(VK_SHIFT) & 0x80)
49 flags |= Event::EF_SHIFT_DOWN;
50 if (GetKeyState(VK_CONTROL) & 0x80)
51 flags |= Event::EF_CONTROL_DOWN;
52 return flags;
53}
54
55bool KeyEvent::IsExtendedKey() const {
56 return (message_flags_ & KF_EXTENDED) == KF_EXTENDED;
57}
58
59} // namespace views