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

Side by Side Diff: ui/events/blink/web_input_event_builders_win.cc

Issue 2234023002: Refactor WebInputEventAura to ui/events/blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/browser/renderer_host/input/web_input_event_builders_win.h" 5 #include "ui/events/blink/web_input_event_builders_win.h"
6 6
7 #include "base/logging.h"
8 #include "content/browser/renderer_host/input/web_input_event_util.h"
9 #include "ui/display/win/screen_win.h" 7 #include "ui/display/win/screen_win.h"
10 #include "ui/events/blink/blink_event_util.h" 8 #include "ui/events/blink/blink_event_util.h"
11 #include "ui/events/event_utils.h" 9 #include "ui/events/event_utils.h"
12 10
13 using blink::WebInputEvent; 11 using blink::WebInputEvent;
14 using blink::WebKeyboardEvent; 12 using blink::WebKeyboardEvent;
15 using blink::WebMouseEvent; 13 using blink::WebMouseEvent;
16 using blink::WebMouseWheelEvent; 14 using blink::WebMouseWheelEvent;
17 15
18 namespace content { 16 namespace ui {
19 17
20 static const unsigned long kDefaultScrollLinesPerWheelDelta = 3; 18 static const unsigned long kDefaultScrollLinesPerWheelDelta = 3;
21 static const unsigned long kDefaultScrollCharsPerWheelDelta = 1; 19 static const unsigned long kDefaultScrollCharsPerWheelDelta = 1;
22 20
23 WebKeyboardEvent WebKeyboardEventBuilder::Build(HWND hwnd, 21 WebKeyboardEvent WebKeyboardEventBuilder::Build(HWND hwnd,
24 UINT message, 22 UINT message,
25 WPARAM wparam, 23 WPARAM wparam,
26 LPARAM lparam, 24 LPARAM lparam,
27 double time_stamp) { 25 double time_stamp) {
28 WebKeyboardEvent result; 26 WebKeyboardEvent result;
29 27
30 result.timeStampSeconds = time_stamp; 28 result.timeStampSeconds = time_stamp;
31 29
32 result.windowsKeyCode = static_cast<int>(wparam); 30 result.windowsKeyCode = static_cast<int>(wparam);
33 // Record the scan code (along with other context bits) for this key event. 31 // Record the scan code (along with other context bits) for this key event.
34 result.nativeKeyCode = static_cast<int>(lparam); 32 result.nativeKeyCode = static_cast<int>(lparam);
35 33
36 switch (message) { 34 switch (message) {
37 case WM_SYSKEYDOWN: 35 case WM_SYSKEYDOWN:
38 result.isSystemKey = true; 36 result.isSystemKey = true;
39 case WM_KEYDOWN: 37 case WM_KEYDOWN:
sadrul 2016/08/15 15:55:13 Add a '// fallthrough' comment here.
jonross 2016/08/16 15:25:16 Done.
40 result.type = WebInputEvent::RawKeyDown; 38 result.type = WebInputEvent::RawKeyDown;
41 break; 39 break;
42 case WM_SYSKEYUP: 40 case WM_SYSKEYUP:
43 result.isSystemKey = true; 41 result.isSystemKey = true;
sadrul 2016/08/15 15:55:13 ditto
jonross 2016/08/16 15:25:16 Done.
44 case WM_KEYUP: 42 case WM_KEYUP:
45 result.type = WebInputEvent::KeyUp; 43 result.type = WebInputEvent::KeyUp;
46 break; 44 break;
47 case WM_IME_CHAR: 45 case WM_IME_CHAR:
48 result.type = WebInputEvent::Char; 46 result.type = WebInputEvent::Char;
49 break; 47 break;
50 case WM_SYSCHAR: 48 case WM_SYSCHAR:
51 result.isSystemKey = true; 49 result.isSystemKey = true;
52 result.type = WebInputEvent::Char; 50 result.type = WebInputEvent::Char;
sadrul 2016/08/15 15:55:13 Remove this, add a // fallthrough comment.
jonross 2016/08/16 15:25:16 Done.
53 case WM_CHAR: 51 case WM_CHAR:
54 result.type = WebInputEvent::Char; 52 result.type = WebInputEvent::Char;
55 break; 53 break;
56 default: 54 default:
57 NOTREACHED(); 55 NOTREACHED();
58 } 56 }
59 57
60 if (result.type == WebInputEvent::Char 58 if (result.type == WebInputEvent::Char ||
61 || result.type == WebInputEvent::RawKeyDown) { 59 result.type == WebInputEvent::RawKeyDown) {
62 result.text[0] = result.windowsKeyCode; 60 result.text[0] = result.windowsKeyCode;
63 result.unmodifiedText[0] = result.windowsKeyCode; 61 result.unmodifiedText[0] = result.windowsKeyCode;
64 } 62 }
65 result.modifiers = 63 result.modifiers =
66 ui::EventFlagsToWebEventModifiers(ui::GetModifiersFromKeyState()); 64 ui::EventFlagsToWebEventModifiers(ui::GetModifiersFromKeyState());
67 // NOTE: There doesn't seem to be a way to query the mouse button state in 65 // NOTE: There doesn't seem to be a way to query the mouse button state in
68 // this case. 66 // this case.
69 67
70 // Bit 30 of lParam represents the "previous key state". If set, the key was 68 // Bit 30 of lParam represents the "previous key state". If set, the key was
71 // already down, therefore this is an auto-repeat. Only apply this to key 69 // already down, therefore this is an auto-repeat. Only apply this to key
(...skipping 19 matching lines...) Expand all
91 WebMouseEvent WebMouseEventBuilder::Build( 89 WebMouseEvent WebMouseEventBuilder::Build(
92 HWND hwnd, 90 HWND hwnd,
93 UINT message, 91 UINT message,
94 WPARAM wparam, 92 WPARAM wparam,
95 LPARAM lparam, 93 LPARAM lparam,
96 double time_stamp, 94 double time_stamp,
97 blink::WebPointerProperties::PointerType pointer_type) { 95 blink::WebPointerProperties::PointerType pointer_type) {
98 WebMouseEvent result; 96 WebMouseEvent result;
99 97
100 switch (message) { 98 switch (message) {
101 case WM_MOUSEMOVE: 99 case WM_MOUSEMOVE:
102 result.type = WebInputEvent::MouseMove; 100 result.type = WebInputEvent::MouseMove;
103 if (wparam & MK_LBUTTON) 101 if (wparam & MK_LBUTTON)
102 result.button = WebMouseEvent::ButtonLeft;
103 else if (wparam & MK_MBUTTON)
104 result.button = WebMouseEvent::ButtonMiddle;
105 else if (wparam & MK_RBUTTON)
106 result.button = WebMouseEvent::ButtonRight;
107 else
108 result.button = WebMouseEvent::ButtonNone;
109 break;
110 case WM_MOUSELEAVE:
111 case WM_NCMOUSELEAVE:
112 // TODO(rbyers): This should be MouseLeave but is disabled temporarily.
113 // See http://crbug.com/450631
114 result.type = WebInputEvent::MouseMove;
115 result.button = WebMouseEvent::ButtonNone;
116 // set the current mouse position (relative to the client area of the
117 // current window) since none is specified for this event
118 lparam = GetRelativeCursorPos(hwnd);
119 break;
120 case WM_LBUTTONDOWN:
121 case WM_LBUTTONDBLCLK:
122 result.type = WebInputEvent::MouseDown;
104 result.button = WebMouseEvent::ButtonLeft; 123 result.button = WebMouseEvent::ButtonLeft;
105 else if (wparam & MK_MBUTTON) 124 break;
125 case WM_MBUTTONDOWN:
126 case WM_MBUTTONDBLCLK:
127 result.type = WebInputEvent::MouseDown;
106 result.button = WebMouseEvent::ButtonMiddle; 128 result.button = WebMouseEvent::ButtonMiddle;
107 else if (wparam & MK_RBUTTON) 129 break;
130 case WM_RBUTTONDOWN:
131 case WM_RBUTTONDBLCLK:
132 result.type = WebInputEvent::MouseDown;
108 result.button = WebMouseEvent::ButtonRight; 133 result.button = WebMouseEvent::ButtonRight;
109 else 134 break;
110 result.button = WebMouseEvent::ButtonNone; 135 case WM_LBUTTONUP:
111 break; 136 result.type = WebInputEvent::MouseUp;
112 case WM_MOUSELEAVE: 137 result.button = WebMouseEvent::ButtonLeft;
113 case WM_NCMOUSELEAVE: 138 break;
114 // TODO(rbyers): This should be MouseLeave but is disabled temporarily. 139 case WM_MBUTTONUP:
115 // See http://crbug.com/450631 140 result.type = WebInputEvent::MouseUp;
116 result.type = WebInputEvent::MouseMove; 141 result.button = WebMouseEvent::ButtonMiddle;
117 result.button = WebMouseEvent::ButtonNone; 142 break;
118 // set the current mouse position (relative to the client area of the 143 case WM_RBUTTONUP:
119 // current window) since none is specified for this event 144 result.type = WebInputEvent::MouseUp;
120 lparam = GetRelativeCursorPos(hwnd); 145 result.button = WebMouseEvent::ButtonRight;
121 break; 146 break;
122 case WM_LBUTTONDOWN: 147 default:
123 case WM_LBUTTONDBLCLK: 148 NOTREACHED();
124 result.type = WebInputEvent::MouseDown;
125 result.button = WebMouseEvent::ButtonLeft;
126 break;
127 case WM_MBUTTONDOWN:
128 case WM_MBUTTONDBLCLK:
129 result.type = WebInputEvent::MouseDown;
130 result.button = WebMouseEvent::ButtonMiddle;
131 break;
132 case WM_RBUTTONDOWN:
133 case WM_RBUTTONDBLCLK:
134 result.type = WebInputEvent::MouseDown;
135 result.button = WebMouseEvent::ButtonRight;
136 break;
137 case WM_LBUTTONUP:
138 result.type = WebInputEvent::MouseUp;
139 result.button = WebMouseEvent::ButtonLeft;
140 break;
141 case WM_MBUTTONUP:
142 result.type = WebInputEvent::MouseUp;
143 result.button = WebMouseEvent::ButtonMiddle;
144 break;
145 case WM_RBUTTONUP:
146 result.type = WebInputEvent::MouseUp;
147 result.button = WebMouseEvent::ButtonRight;
148 break;
149 default:
150 NOTREACHED();
151 } 149 }
152 150
153 result.timeStampSeconds = time_stamp; 151 result.timeStampSeconds = time_stamp;
154 result.pointerType = pointer_type; 152 result.pointerType = pointer_type;
155 153
156 // set position fields: 154 // set position fields:
157 155
158 result.x = static_cast<short>(LOWORD(lparam)); 156 result.x = static_cast<short>(LOWORD(lparam));
159 result.y = static_cast<short>(HIWORD(lparam)); 157 result.y = static_cast<short>(HIWORD(lparam));
160 result.windowX = result.x; 158 result.windowX = result.x;
161 result.windowY = result.y; 159 result.windowY = result.y;
162 160
163 POINT global_point = { result.x, result.y }; 161 POINT global_point = {result.x, result.y};
164 ClientToScreen(hwnd, &global_point); 162 ClientToScreen(hwnd, &global_point);
165 163
166 // We need to convert the global point back to DIP before using it. 164 // We need to convert the global point back to DIP before using it.
167 gfx::Point dip_global_point = display::win::ScreenWin::ScreenToDIPPoint( 165 gfx::Point dip_global_point = display::win::ScreenWin::ScreenToDIPPoint(
168 gfx::Point(global_point.x, global_point.y)); 166 gfx::Point(global_point.x, global_point.y));
169 167
170 result.globalX = dip_global_point.x(); 168 result.globalX = dip_global_point.x();
171 result.globalY = dip_global_point.y(); 169 result.globalY = dip_global_point.y();
172 170
173 // calculate number of clicks: 171 // calculate number of clicks:
174 172
175 // This differs slightly from the WebKit code in WebKit/win/WebView.cpp 173 // This differs slightly from the WebKit code in WebKit/win/WebView.cpp
176 // where their original code looks buggy. 174 // where their original code looks buggy.
177 static int last_click_position_x; 175 static int last_click_position_x;
178 static int last_click_position_y; 176 static int last_click_position_y;
179 static WebMouseEvent::Button last_click_button = WebMouseEvent::ButtonLeft; 177 static WebMouseEvent::Button last_click_button = WebMouseEvent::ButtonLeft;
180 178
181 double current_time = result.timeStampSeconds; 179 double current_time = result.timeStampSeconds;
182 bool cancel_previous_click = 180 bool cancel_previous_click =
183 (abs(last_click_position_x - result.x) > 181 (abs(last_click_position_x - result.x) >
184 (::GetSystemMetrics(SM_CXDOUBLECLK) / 2)) 182 (::GetSystemMetrics(SM_CXDOUBLECLK) / 2)) ||
185 || (abs(last_click_position_y - result.y) > 183 (abs(last_click_position_y - result.y) >
186 (::GetSystemMetrics(SM_CYDOUBLECLK) / 2)) 184 (::GetSystemMetrics(SM_CYDOUBLECLK) / 2)) ||
187 || ((current_time - g_last_click_time) * 1000.0 > ::GetDoubleClickTime()); 185 ((current_time - g_last_click_time) * 1000.0 > ::GetDoubleClickTime());
188 186
189 if (result.type == WebInputEvent::MouseDown) { 187 if (result.type == WebInputEvent::MouseDown) {
190 if (!cancel_previous_click && (result.button == last_click_button)) { 188 if (!cancel_previous_click && (result.button == last_click_button)) {
191 ++g_last_click_count; 189 ++g_last_click_count;
192 } else { 190 } else {
193 g_last_click_count = 1; 191 g_last_click_count = 1;
194 last_click_position_x = result.x; 192 last_click_position_x = result.x;
195 last_click_position_y = result.y; 193 last_click_position_y = result.y;
196 } 194 }
197 g_last_click_time = current_time; 195 g_last_click_time = current_time;
198 last_click_button = result.button; 196 last_click_button = result.button;
199 } else if (result.type == WebInputEvent::MouseMove 197 } else if (result.type == WebInputEvent::MouseMove ||
200 || result.type == WebInputEvent::MouseLeave) { 198 result.type == WebInputEvent::MouseLeave) {
201 if (cancel_previous_click) { 199 if (cancel_previous_click) {
202 g_last_click_count = 0; 200 g_last_click_count = 0;
203 last_click_position_x = 0; 201 last_click_position_x = 0;
204 last_click_position_y = 0; 202 last_click_position_y = 0;
205 g_last_click_time = 0; 203 g_last_click_time = 0;
206 } 204 }
207 } 205 }
208 result.clickCount = g_last_click_count; 206 result.clickCount = g_last_click_count;
209 207
210 // set modifiers: 208 // set modifiers:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 key_state |= MK_CONTROL; 256 key_state |= MK_CONTROL;
259 // NOTE: There doesn't seem to be a way to query the mouse button state 257 // NOTE: There doesn't seem to be a way to query the mouse button state
260 // in this case. 258 // in this case.
261 259
262 POINT cursor_position = {0}; 260 POINT cursor_position = {0};
263 GetCursorPos(&cursor_position); 261 GetCursorPos(&cursor_position);
264 result.globalX = cursor_position.x; 262 result.globalX = cursor_position.x;
265 result.globalY = cursor_position.y; 263 result.globalY = cursor_position.y;
266 264
267 switch (LOWORD(wparam)) { 265 switch (LOWORD(wparam)) {
268 case SB_LINEUP: // == SB_LINELEFT 266 case SB_LINEUP: // == SB_LINELEFT
269 wheel_delta = WHEEL_DELTA; 267 wheel_delta = WHEEL_DELTA;
270 break; 268 break;
271 case SB_LINEDOWN: // == SB_LINERIGHT 269 case SB_LINEDOWN: // == SB_LINERIGHT
272 wheel_delta = -WHEEL_DELTA; 270 wheel_delta = -WHEEL_DELTA;
273 break; 271 break;
274 case SB_PAGEUP: 272 case SB_PAGEUP:
275 wheel_delta = 1; 273 wheel_delta = 1;
276 result.scrollByPage = true; 274 result.scrollByPage = true;
277 break; 275 break;
278 case SB_PAGEDOWN: 276 case SB_PAGEDOWN:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 if (key_state & MK_CONTROL) 312 if (key_state & MK_CONTROL)
315 result.modifiers |= WebInputEvent::ControlKey; 313 result.modifiers |= WebInputEvent::ControlKey;
316 if (key_state & MK_LBUTTON) 314 if (key_state & MK_LBUTTON)
317 result.modifiers |= WebInputEvent::LeftButtonDown; 315 result.modifiers |= WebInputEvent::LeftButtonDown;
318 if (key_state & MK_MBUTTON) 316 if (key_state & MK_MBUTTON)
319 result.modifiers |= WebInputEvent::MiddleButtonDown; 317 result.modifiers |= WebInputEvent::MiddleButtonDown;
320 if (key_state & MK_RBUTTON) 318 if (key_state & MK_RBUTTON)
321 result.modifiers |= WebInputEvent::RightButtonDown; 319 result.modifiers |= WebInputEvent::RightButtonDown;
322 320
323 // Set coordinates by translating event coordinates from screen to client. 321 // Set coordinates by translating event coordinates from screen to client.
324 POINT client_point = { result.globalX, result.globalY }; 322 POINT client_point = {result.globalX, result.globalY};
325 MapWindowPoints(0, hwnd, &client_point, 1); 323 MapWindowPoints(0, hwnd, &client_point, 1);
326 result.x = client_point.x; 324 result.x = client_point.x;
327 result.y = client_point.y; 325 result.y = client_point.y;
328 result.windowX = result.x; 326 result.windowX = result.x;
329 result.windowY = result.y; 327 result.windowY = result.y;
330 328
331 // Convert wheel delta amount to a number of pixels to scroll. 329 // Convert wheel delta amount to a number of pixels to scroll.
332 // 330 //
333 // How many pixels should we scroll per line? Gecko uses the height of the 331 // How many pixels should we scroll per line? Gecko uses the height of the
334 // current line, which means scroll distance changes as you go through the 332 // current line, which means scroll distance changes as you go through the
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 result.deltaX = scroll_delta; 364 result.deltaX = scroll_delta;
367 result.wheelTicksX = wheel_delta; 365 result.wheelTicksX = wheel_delta;
368 } else { 366 } else {
369 result.deltaY = scroll_delta; 367 result.deltaY = scroll_delta;
370 result.wheelTicksY = wheel_delta; 368 result.wheelTicksY = wheel_delta;
371 } 369 }
372 370
373 return result; 371 return result;
374 } 372 }
375 373
376 } // namespace content 374 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698