Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: views/events/event_win.cc

Issue 6487002: Add a new constructor to KeyEvent. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "views/events/event.h" 5 #include "views/events/event.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/logging.h"
10 #include "ui/base/keycodes/keyboard_code_conversion_win.h"
11
9 namespace views { 12 namespace views {
10 13
11 KeyEvent::KeyEvent(ui::EventType type, ui::KeyboardCode key_code, 14 namespace {
12 int event_flags, int repeat_count, int message_flags, 15
13 UINT message) 16 // Returns a mask corresponding to the set of modifier keys that are currently
14 : Event(type, event_flags), 17 // pressed. Windows key messages don't come with control key state as parameters
15 key_code_(key_code), 18 // as with mouse messages, so we need to explicitly ask for these states.
16 repeat_count_(repeat_count), 19 int GetKeyStateFlags() {
17 message_flags_(message_flags), 20 int flags = 0;
18 message_(message) { 21 if (GetKeyState(VK_MENU) & 0x80)
22 flags |= ui::EF_ALT_DOWN;
23 if (GetKeyState(VK_SHIFT) & 0x80)
24 flags |= ui::EF_SHIFT_DOWN;
25 if (GetKeyState(VK_CONTROL) & 0x80)
26 flags |= ui::EF_CONTROL_DOWN;
27 return flags;
19 } 28 }
20 29
30 // Convert windows message identifiers to Event types.
31 ui::EventType EventTypeFromNative(NativeEvent native_event) {
32 switch (native_event.message) {
33 case WM_KEYDOWN:
34 case WM_SYSKEYDOWN:
35 return ui::ET_KEY_PRESSED;
36 case WM_KEYUP:
37 case WM_SYSKEYUP:
38 return ui::ET_KEY_RELEASED;
39 case WM_LBUTTONDOWN:
40 case WM_MBUTTONDOWN:
41 case WM_NCLBUTTONDOWN:
42 case WM_NCMBUTTONDOWN:
43 case WM_NCRBUTTONDOWN:
44 case WM_RBUTTONDOWN:
45 return ui::ET_MOUSE_PRESSED;
46 case WM_LBUTTONDBLCLK:
47 case WM_LBUTTONUP:
48 case WM_MBUTTONDBLCLK:
49 case WM_MBUTTONUP:
50 case WM_NCLBUTTONDBLCLK:
51 case WM_NCLBUTTONUP:
52 case WM_NCMBUTTONDBLCLK:
53 case WM_NCMBUTTONUP:
54 case WM_NCRBUTTONDBLCLK:
55 case WM_NCRBUTTONUP:
56 case WM_RBUTTONDBLCLK:
57 case WM_RBUTTONUP:
58 return ui::ET_MOUSE_RELEASED;
59 case WM_MOUSEMOVE:
60 case WM_NCMOUSEMOVE:
61 return ui::ET_MOUSE_MOVED;
62 case WM_MOUSEWHEEL:
63 return ui::ET_MOUSEWHEEL;
64 case WM_MOUSELEAVE:
65 case WM_NCMOUSELEAVE:
66 return ui::ET_MOUSE_EXITED;
67 default:
68 NOTREACHED();
69 }
70 return ui::ET_UNKNOWN;
71 }
72
73 } // namespace
74
75 ////////////////////////////////////////////////////////////////////////////////
76 // Event, public:
77
21 int Event::GetWindowsFlags() const { 78 int Event::GetWindowsFlags() const {
22 // TODO: need support for x1/x2. 79 // TODO: need support for x1/x2.
23 int result = 0; 80 int result = 0;
24 result |= (flags_ & ui::EF_SHIFT_DOWN) ? MK_SHIFT : 0; 81 result |= (flags_ & ui::EF_SHIFT_DOWN) ? MK_SHIFT : 0;
25 result |= (flags_ & ui::EF_CONTROL_DOWN) ? MK_CONTROL : 0; 82 result |= (flags_ & ui::EF_CONTROL_DOWN) ? MK_CONTROL : 0;
26 result |= (flags_ & ui::EF_LEFT_BUTTON_DOWN) ? MK_LBUTTON : 0; 83 result |= (flags_ & ui::EF_LEFT_BUTTON_DOWN) ? MK_LBUTTON : 0;
27 result |= (flags_ & ui::EF_MIDDLE_BUTTON_DOWN) ? MK_MBUTTON : 0; 84 result |= (flags_ & ui::EF_MIDDLE_BUTTON_DOWN) ? MK_MBUTTON : 0;
28 result |= (flags_ & ui::EF_RIGHT_BUTTON_DOWN) ? MK_RBUTTON : 0; 85 result |= (flags_ & ui::EF_RIGHT_BUTTON_DOWN) ? MK_RBUTTON : 0;
29 return result; 86 return result;
30 } 87 }
31 88
32 //static 89 //static
33 int Event::ConvertWindowsFlags(UINT win_flags) { 90 int Event::ConvertWindowsFlags(UINT win_flags) {
34 int r = 0; 91 int r = 0;
35 if (win_flags & MK_CONTROL) 92 if (win_flags & MK_CONTROL)
36 r |= ui::EF_CONTROL_DOWN; 93 r |= ui::EF_CONTROL_DOWN;
37 if (win_flags & MK_SHIFT) 94 if (win_flags & MK_SHIFT)
38 r |= ui::EF_SHIFT_DOWN; 95 r |= ui::EF_SHIFT_DOWN;
39 if (GetKeyState(VK_MENU) < 0) 96 if (GetKeyState(VK_MENU) < 0)
40 r |= ui::EF_ALT_DOWN; 97 r |= ui::EF_ALT_DOWN;
41 if (win_flags & MK_LBUTTON) 98 if (win_flags & MK_LBUTTON)
42 r |= ui::EF_LEFT_BUTTON_DOWN; 99 r |= ui::EF_LEFT_BUTTON_DOWN;
43 if (win_flags & MK_MBUTTON) 100 if (win_flags & MK_MBUTTON)
44 r |= ui::EF_MIDDLE_BUTTON_DOWN; 101 r |= ui::EF_MIDDLE_BUTTON_DOWN;
45 if (win_flags & MK_RBUTTON) 102 if (win_flags & MK_RBUTTON)
46 r |= ui::EF_RIGHT_BUTTON_DOWN; 103 r |= ui::EF_RIGHT_BUTTON_DOWN;
47 return r; 104 return r;
48 } 105 }
49 106
50 // static 107 ////////////////////////////////////////////////////////////////////////////////
51 int KeyEvent::GetKeyStateFlags() { 108 // Event, private:
52 // Windows Keyboard messages don't come with control key state as parameters 109
53 // like mouse messages do, so we need to explicitly probe for these key 110 void Event::Init() {
54 // states. 111 native_event_ = MSG();
55 int flags = 0; 112 native_event_2_ = NULL;
56 if (GetKeyState(VK_MENU) & 0x80)
57 flags |= ui::EF_ALT_DOWN;
58 if (GetKeyState(VK_SHIFT) & 0x80)
59 flags |= ui::EF_SHIFT_DOWN;
60 if (GetKeyState(VK_CONTROL) & 0x80)
61 flags |= ui::EF_CONTROL_DOWN;
62 return flags;
63 } 113 }
64 114
65 bool KeyEvent::IsExtendedKey() const { 115 void Event::InitWithNativeEvent(NativeEvent native_event) {
66 return (message_flags_ & KF_EXTENDED) == KF_EXTENDED; 116 native_event_ = native_event;
117 // TODO(beng): remove once we rid views of Gtk/Gdk.
118 native_event_2_ = NULL;
119 }
120
121 void Event::InitWithNativeEvent2(NativeEvent2 native_event_2) {
122 // No one should ever call this on Windows.
123 // TODO(beng): remove once we rid views of Gtk/Gdk.
124 NOTREACHED();
125 native_event_2_ = NULL;
126 }
127
128 ////////////////////////////////////////////////////////////////////////////////
129 // KeyEvent, public:
130
131 KeyEvent::KeyEvent(NativeEvent native_event)
132 : Event(native_event,
133 EventTypeFromNative(native_event),
134 GetKeyStateFlags()),
135 key_code_(ui::KeyboardCodeForWindowsKeyCode(native_event.wParam)) {
136 }
137
138 KeyEvent::KeyEvent(NativeEvent2 native_event_2)
139 : Event(native_event_2, ui::ET_UNKNOWN, 0) {
140 // No one should ever call this on Windows.
141 // TODO(beng): remove once we rid views of Gtk/Gdk.
142 NOTREACHED();
67 } 143 }
68 144
69 } // namespace views 145 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698