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

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

Issue 7942004: Consolidate/cleanup event cracking code; single out GdkEvents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge removal of compact nav. Created 9 years, 2 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
« no previous file with comments | « ui/views/events/event.cc ('k') | ui/views/native_types.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/views/events/event.h"
6
7 #include <windowsx.h>
8
9 #include "base/logging.h"
10 #include "ui/base/keycodes/keyboard_code_conversion_win.h"
11
12 namespace ui {
13
14 namespace {
15
16 // Returns a mask corresponding to the set of modifier keys that are currently
17 // pressed. Windows key messages don't come with control key state as parameters
18 // as with mouse messages, so we need to explicitly ask for these states.
19 int GetKeyStateFlags() {
20 int flags = 0;
21 flags |= (GetKeyState(VK_MENU) & 0x80)? ui::EF_ALT_DOWN : 0;
22 flags |= (GetKeyState(VK_SHIFT) & 0x80)? ui::EF_SHIFT_DOWN : 0;
23 flags |= (GetKeyState(VK_CONTROL) & 0x80)? ui::EF_CONTROL_DOWN : 0;
24 return flags;
25 }
26
27 // Convert windows message identifiers to Event types.
28 ui::Event::EventType EventTypeFromNative(NativeEvent native_event) {
29 switch (native_event.message) {
30 case WM_KEYDOWN:
31 case WM_SYSKEYDOWN:
32 case WM_CHAR:
33 return ui::Event::ET_KEY_PRESSED;
34 case WM_KEYUP:
35 case WM_SYSKEYUP:
36 return ui::Event::ET_KEY_RELEASED;
37 case WM_LBUTTONDOWN:
38 case WM_MBUTTONDOWN:
39 case WM_NCLBUTTONDOWN:
40 case WM_NCMBUTTONDOWN:
41 case WM_NCRBUTTONDOWN:
42 case WM_RBUTTONDOWN:
43 return ui::Event::ET_MOUSE_PRESSED;
44 case WM_LBUTTONDBLCLK:
45 case WM_LBUTTONUP:
46 case WM_MBUTTONDBLCLK:
47 case WM_MBUTTONUP:
48 case WM_NCLBUTTONDBLCLK:
49 case WM_NCLBUTTONUP:
50 case WM_NCMBUTTONDBLCLK:
51 case WM_NCMBUTTONUP:
52 case WM_NCRBUTTONDBLCLK:
53 case WM_NCRBUTTONUP:
54 case WM_RBUTTONDBLCLK:
55 case WM_RBUTTONUP:
56 return ui::Event::ET_MOUSE_RELEASED;
57 case WM_MOUSEMOVE:
58 case WM_NCMOUSEMOVE:
59 return ui::Event::ET_MOUSE_MOVED;
60 case WM_MOUSEWHEEL:
61 return ui::Event::ET_MOUSEWHEEL;
62 case WM_MOUSELEAVE:
63 case WM_NCMOUSELEAVE:
64 return ui::Event::ET_MOUSE_EXITED;
65 default:
66 NOTREACHED();
67 }
68 return ui::Event::ET_UNKNOWN;
69 }
70
71 bool IsClientMouseEvent(NativeEvent native_event) {
72 return native_event.message == WM_MOUSELEAVE ||
73 native_event.message == WM_MOUSEHOVER ||
74 (native_event.message >= WM_MOUSEFIRST &&
75 native_event.message <= WM_MOUSELAST);
76 }
77
78 bool IsNonClientMouseEvent(NativeEvent native_event) {
79 return native_event.message == WM_NCMOUSELEAVE ||
80 native_event.message == WM_NCMOUSEHOVER ||
81 (native_event.message >= WM_NCMOUSEMOVE &&
82 native_event.message <= WM_NCXBUTTONDBLCLK);
83 }
84
85 gfx::Point MousePositionFromNative(NativeEvent native_event) {
86 // Client message. The position is contained in the LPARAM.
87 if (IsClientMouseEvent(native_event))
88 return gfx::Point(native_event.lParam);
89 DCHECK(IsNonClientMouseEvent(native_event));
90 // Non-client message. The position is contained in a POINTS structure in
91 // LPARAM, and is in screen coordinates so we have to convert to client.
92 POINT native_point = { GET_X_LPARAM(native_event.lParam),
93 GET_Y_LPARAM(native_event.lParam) };
94 ScreenToClient(native_event.hwnd, &native_point);
95 return gfx::Point(native_point);
96 }
97
98 int MouseEventFlagsFromNative(NativeEvent native_event) {
99 int flags = 0;
100
101 // Check if the event occurred in the non-client area.
102 if (IsNonClientMouseEvent(native_event))
103 flags |= ui::MouseEvent::EF_IS_NON_CLIENT;
104
105 // Check for double click events.
106 switch (native_event.message) {
107 case WM_NCLBUTTONDBLCLK:
108 case WM_NCMBUTTONDBLCLK:
109 case WM_NCRBUTTONDBLCLK:
110 case WM_LBUTTONDBLCLK:
111 case WM_MBUTTONDBLCLK:
112 case WM_RBUTTONDBLCLK:
113 flags |= ui::MouseEvent::EF_IS_DOUBLE_CLICK;
114 break;
115 }
116
117 // Check for pressed buttons.
118 if (IsClientMouseEvent(native_event)) {
119 if (native_event.wParam & MK_LBUTTON)
120 flags |= ui::MouseEvent::EF_LEFT_BUTTON_DOWN;
121 if (native_event.wParam & MK_MBUTTON)
122 flags |= ui::MouseEvent::EF_MIDDLE_BUTTON_DOWN;
123 if (native_event.wParam & MK_RBUTTON)
124 flags |= ui::MouseEvent::EF_RIGHT_BUTTON_DOWN;
125 } else if (IsNonClientMouseEvent(native_event)) {
126 switch (native_event.message) {
127 case WM_NCLBUTTONDOWN:
128 flags |= ui::MouseEvent::EF_LEFT_BUTTON_DOWN;
129 break;
130 case WM_NCMBUTTONDOWN:
131 flags |= ui::MouseEvent::EF_MIDDLE_BUTTON_DOWN;
132 break;
133 case WM_NCRBUTTONDOWN:
134 flags |= ui::MouseEvent::EF_RIGHT_BUTTON_DOWN;
135 break;
136 }
137 }
138
139 // Finally make sure the key state flags are included.
140 return flags | GetKeyStateFlags();
141 }
142
143 int MouseWheelEventFlagsFromNative(NativeEvent native_event) {
144 int win_flags = GET_KEYSTATE_WPARAM(native_event.wParam);
145 int flags = 0;
146 flags |= (win_flags & MK_CONTROL) ? ui::MouseEvent::EF_CONTROL_DOWN : 0;
147 flags |= (win_flags & MK_SHIFT) ? ui::MouseEvent::EF_SHIFT_DOWN : 0;
148 flags |= (GetKeyState(VK_MENU) < 0) ? ui::MouseEvent::EF_ALT_DOWN : 0;
149 flags |= (win_flags & MK_LBUTTON) ? ui::MouseEvent::EF_LEFT_BUTTON_DOWN : 0;
150 flags |= (win_flags & MK_MBUTTON) ? ui::MouseEvent::EF_MIDDLE_BUTTON_DOWN : 0;
151 flags |= (win_flags & MK_RBUTTON) ? ui::MouseEvent::EF_RIGHT_BUTTON_DOWN : 0;
152 return flags;
153 }
154
155 } // namespace
156
157 ////////////////////////////////////////////////////////////////////////////////
158 // KeyEvent, public:
159
160 KeyEvent::KeyEvent(NativeEvent native_event)
161 : Event(EventTypeFromNative(native_event), GetKeyStateFlags()),
162 key_code_(KeyboardCodeForWindowsKeyCode(native_event.wParam)),
163 repeat_count_(native_event.lParam & 0xFFFF),
164 message_flags_((native_event.lParam & 0xFFFF0000) >> 16) {
165 }
166
167 ////////////////////////////////////////////////////////////////////////////////
168 // MouseEvent, public:
169
170 MouseEvent::MouseEvent(NativeEvent native_event)
171 : LocatedEvent(EventTypeFromNative(native_event),
172 MousePositionFromNative(native_event),
173 MouseEventFlagsFromNative(native_event)) {
174 }
175
176 ////////////////////////////////////////////////////////////////////////////////
177 // MouseWheelEvent, public:
178
179 MouseWheelEvent::MouseWheelEvent(NativeEvent native_event)
180 : LocatedEvent(ET_MOUSEWHEEL,
181 MousePositionFromNative(native_event),
182 MouseWheelEventFlagsFromNative(native_event)),
183 offset_(GET_WHEEL_DELTA_WPARAM(native_event.wParam)) {
184 }
185
186 } // namespace ui
187
OLDNEW
« no previous file with comments | « ui/views/events/event.cc ('k') | ui/views/native_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698