[email protected] | fdc9272655 | 2009-03-23 20:26:56 | [diff] [blame] | 1 | // 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] | 2362e4f | 2009-05-08 00:34:05 | [diff] [blame] | 5 | #include "views/event.h" |
[email protected] | fdc9272655 | 2009-03-23 20:26:56 | [diff] [blame] | 6 | |
[email protected] | a1a02aef | 2009-03-23 20:37:19 | [diff] [blame] | 7 | #include <windows.h> |
| 8 | |
[email protected] | fdc9272655 | 2009-03-23 20:26:56 | [diff] [blame] | 9 | namespace views { |
| 10 | |
| 11 | int 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 |
| 23 | int 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] | 0e0e6d75 | 2009-10-08 16:28:44 | [diff] [blame] | 40 | // static |
| 41 | int KeyEvent::GetKeyStateFlags() { |
[email protected] | fdc9272655 | 2009-03-23 20:26:56 | [diff] [blame] | 42 | // 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 | |
| 55 | bool KeyEvent::IsExtendedKey() const { |
| 56 | return (message_flags_ & KF_EXTENDED) == KF_EXTENDED; |
| 57 | } |
| 58 | |
| 59 | } // namespace views |