| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/events/blink/web_input_event_builders_win.h" | 5 #include "ui/events/blink/web_input_event_builders_win.h" |
| 6 | 6 |
| 7 #include "ui/display/win/screen_win.h" | 7 #include "ui/display/win/screen_win.h" |
| 8 #include "ui/events/blink/blink_event_util.h" | 8 #include "ui/events/blink/blink_event_util.h" |
| 9 #include "ui/events/event_utils.h" | 9 #include "ui/events/event_utils.h" |
| 10 | 10 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 modifiers |= WebInputEvent::MiddleButtonDown; | 163 modifiers |= WebInputEvent::MiddleButtonDown; |
| 164 if (wparam & MK_RBUTTON) | 164 if (wparam & MK_RBUTTON) |
| 165 modifiers |= WebInputEvent::RightButtonDown; | 165 modifiers |= WebInputEvent::RightButtonDown; |
| 166 | 166 |
| 167 WebMouseEvent result(type, modifiers, time_stamp); | 167 WebMouseEvent result(type, modifiers, time_stamp); |
| 168 result.pointerType = pointer_type; | 168 result.pointerType = pointer_type; |
| 169 result.button = button; | 169 result.button = button; |
| 170 result.id = ui::PointerEvent::kMousePointerId; | 170 result.id = ui::PointerEvent::kMousePointerId; |
| 171 | 171 |
| 172 // set position fields: | 172 // set position fields: |
| 173 result.x = static_cast<short>(LOWORD(lparam)); | 173 result.setPositionInWidget(static_cast<short>(LOWORD(lparam)), |
| 174 result.y = static_cast<short>(HIWORD(lparam)); | 174 static_cast<short>(HIWORD(lparam))); |
| 175 | 175 |
| 176 POINT global_point = {result.x, result.y}; | 176 POINT global_point = {result.positionInWidget().x, |
| 177 result.positionInWidget().y}; |
| 177 ClientToScreen(hwnd, &global_point); | 178 ClientToScreen(hwnd, &global_point); |
| 178 | 179 |
| 179 // We need to convert the global point back to DIP before using it. | 180 // We need to convert the global point back to DIP before using it. |
| 180 gfx::Point dip_global_point = display::win::ScreenWin::ScreenToDIPPoint( | 181 gfx::Point dip_global_point = display::win::ScreenWin::ScreenToDIPPoint( |
| 181 gfx::Point(global_point.x, global_point.y)); | 182 gfx::Point(global_point.x, global_point.y)); |
| 182 | 183 |
| 183 result.globalX = dip_global_point.x(); | 184 result.setPositionInScreen(dip_global_point.x(), dip_global_point.y()); |
| 184 result.globalY = dip_global_point.y(); | |
| 185 | 185 |
| 186 // calculate number of clicks: | 186 // calculate number of clicks: |
| 187 | 187 |
| 188 // This differs slightly from the WebKit code in WebKit/win/WebView.cpp | 188 // This differs slightly from the WebKit code in WebKit/win/WebView.cpp |
| 189 // where their original code looks buggy. | 189 // where their original code looks buggy. |
| 190 static int last_click_position_x; | 190 static int last_click_position_x; |
| 191 static int last_click_position_y; | 191 static int last_click_position_y; |
| 192 static WebMouseEvent::Button last_click_button = WebMouseEvent::Button::Left; | 192 static WebMouseEvent::Button last_click_button = WebMouseEvent::Button::Left; |
| 193 | 193 |
| 194 double current_time = result.timeStampSeconds(); | 194 double current_time = result.timeStampSeconds(); |
| 195 bool cancel_previous_click = | 195 bool cancel_previous_click = |
| 196 (abs(last_click_position_x - result.x) > | 196 (abs(last_click_position_x - result.positionInWidget().x) > |
| 197 (::GetSystemMetrics(SM_CXDOUBLECLK) / 2)) || | 197 (::GetSystemMetrics(SM_CXDOUBLECLK) / 2)) || |
| 198 (abs(last_click_position_y - result.y) > | 198 (abs(last_click_position_y - result.positionInWidget().y) > |
| 199 (::GetSystemMetrics(SM_CYDOUBLECLK) / 2)) || | 199 (::GetSystemMetrics(SM_CYDOUBLECLK) / 2)) || |
| 200 ((current_time - g_last_click_time) * 1000.0 > ::GetDoubleClickTime()); | 200 ((current_time - g_last_click_time) * 1000.0 > ::GetDoubleClickTime()); |
| 201 | 201 |
| 202 if (result.type() == WebInputEvent::MouseDown) { | 202 if (result.type() == WebInputEvent::MouseDown) { |
| 203 if (!cancel_previous_click && (result.button == last_click_button)) { | 203 if (!cancel_previous_click && (result.button == last_click_button)) { |
| 204 ++g_last_click_count; | 204 ++g_last_click_count; |
| 205 } else { | 205 } else { |
| 206 g_last_click_count = 1; | 206 g_last_click_count = 1; |
| 207 last_click_position_x = result.x; | 207 last_click_position_x = result.positionInWidget().x; |
| 208 last_click_position_y = result.y; | 208 last_click_position_y = result.positionInWidget().y; |
| 209 } | 209 } |
| 210 g_last_click_time = current_time; | 210 g_last_click_time = current_time; |
| 211 last_click_button = result.button; | 211 last_click_button = result.button; |
| 212 } else if (result.type() == WebInputEvent::MouseMove || | 212 } else if (result.type() == WebInputEvent::MouseMove || |
| 213 result.type() == WebInputEvent::MouseLeave) { | 213 result.type() == WebInputEvent::MouseLeave) { |
| 214 if (cancel_previous_click) { | 214 if (cancel_previous_click) { |
| 215 g_last_click_count = 0; | 215 g_last_click_count = 0; |
| 216 last_click_position_x = 0; | 216 last_click_position_x = 0; |
| 217 last_click_position_y = 0; | 217 last_click_position_y = 0; |
| 218 g_last_click_time = 0; | 218 g_last_click_time = 0; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 key_state = 0; | 252 key_state = 0; |
| 253 if (GetAsyncKeyState(VK_SHIFT) & 0x8000) | 253 if (GetAsyncKeyState(VK_SHIFT) & 0x8000) |
| 254 key_state |= MK_SHIFT; | 254 key_state |= MK_SHIFT; |
| 255 if (GetAsyncKeyState(VK_CONTROL) & 0x8000) | 255 if (GetAsyncKeyState(VK_CONTROL) & 0x8000) |
| 256 key_state |= MK_CONTROL; | 256 key_state |= MK_CONTROL; |
| 257 // 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 |
| 258 // in this case. | 258 // in this case. |
| 259 | 259 |
| 260 POINT cursor_position = {0}; | 260 POINT cursor_position = {0}; |
| 261 GetCursorPos(&cursor_position); | 261 GetCursorPos(&cursor_position); |
| 262 result.globalX = cursor_position.x; | 262 result.setPositionInScreen(cursor_position.x, cursor_position.y); |
| 263 result.globalY = cursor_position.y; | |
| 264 | 263 |
| 265 switch (LOWORD(wparam)) { | 264 switch (LOWORD(wparam)) { |
| 266 case SB_LINEUP: // == SB_LINELEFT | 265 case SB_LINEUP: // == SB_LINELEFT |
| 267 wheel_delta = WHEEL_DELTA; | 266 wheel_delta = WHEEL_DELTA; |
| 268 break; | 267 break; |
| 269 case SB_LINEDOWN: // == SB_LINERIGHT | 268 case SB_LINEDOWN: // == SB_LINERIGHT |
| 270 wheel_delta = -WHEEL_DELTA; | 269 wheel_delta = -WHEEL_DELTA; |
| 271 break; | 270 break; |
| 272 case SB_PAGEUP: | 271 case SB_PAGEUP: |
| 273 wheel_delta = 1; | 272 wheel_delta = 1; |
| 274 result.scrollByPage = true; | 273 result.scrollByPage = true; |
| 275 break; | 274 break; |
| 276 case SB_PAGEDOWN: | 275 case SB_PAGEDOWN: |
| 277 wheel_delta = -1; | 276 wheel_delta = -1; |
| 278 result.scrollByPage = true; | 277 result.scrollByPage = true; |
| 279 break; | 278 break; |
| 280 default: // We don't supoprt SB_THUMBPOSITION or SB_THUMBTRACK here. | 279 default: // We don't supoprt SB_THUMBPOSITION or SB_THUMBTRACK here. |
| 281 wheel_delta = 0; | 280 wheel_delta = 0; |
| 282 break; | 281 break; |
| 283 } | 282 } |
| 284 | 283 |
| 285 if (message == WM_HSCROLL) | 284 if (message == WM_HSCROLL) |
| 286 horizontal_scroll = true; | 285 horizontal_scroll = true; |
| 287 } else { | 286 } else { |
| 288 // Non-synthesized event; we can just read data off the event. | 287 // Non-synthesized event; we can just read data off the event. |
| 289 key_state = GET_KEYSTATE_WPARAM(wparam); | 288 key_state = GET_KEYSTATE_WPARAM(wparam); |
| 290 | 289 |
| 291 result.globalX = static_cast<short>(LOWORD(lparam)); | 290 result.setPositionInScreen(static_cast<short>(LOWORD(lparam)), |
| 292 result.globalY = static_cast<short>(HIWORD(lparam)); | 291 static_cast<short>(HIWORD(lparam))); |
| 293 | 292 |
| 294 // Currently we leave hasPreciseScrollingDeltas false, even for trackpad | 293 // Currently we leave hasPreciseScrollingDeltas false, even for trackpad |
| 295 // scrolls that generate WM_MOUSEWHEEL, since we don't have a good way to | 294 // scrolls that generate WM_MOUSEWHEEL, since we don't have a good way to |
| 296 // distinguish these from real mouse wheels (crbug.com/545234). | 295 // distinguish these from real mouse wheels (crbug.com/545234). |
| 297 wheel_delta = static_cast<float>(GET_WHEEL_DELTA_WPARAM(wparam)); | 296 wheel_delta = static_cast<float>(GET_WHEEL_DELTA_WPARAM(wparam)); |
| 298 | 297 |
| 299 if (message == WM_MOUSEHWHEEL) { | 298 if (message == WM_MOUSEHWHEEL) { |
| 300 horizontal_scroll = true; | 299 horizontal_scroll = true; |
| 301 wheel_delta = -wheel_delta; // Windows is <- -/+ ->, WebKit <- +/- ->. | 300 wheel_delta = -wheel_delta; // Windows is <- -/+ ->, WebKit <- +/- ->. |
| 302 } | 301 } |
| 303 } | 302 } |
| 304 | 303 |
| 305 // Set modifiers based on key state. | 304 // Set modifiers based on key state. |
| 306 int modifiers = result.modifiers(); | 305 int modifiers = result.modifiers(); |
| 307 if (key_state & MK_SHIFT) | 306 if (key_state & MK_SHIFT) |
| 308 modifiers |= WebInputEvent::ShiftKey; | 307 modifiers |= WebInputEvent::ShiftKey; |
| 309 if (key_state & MK_CONTROL) | 308 if (key_state & MK_CONTROL) |
| 310 modifiers |= WebInputEvent::ControlKey; | 309 modifiers |= WebInputEvent::ControlKey; |
| 311 if (key_state & MK_LBUTTON) | 310 if (key_state & MK_LBUTTON) |
| 312 modifiers |= WebInputEvent::LeftButtonDown; | 311 modifiers |= WebInputEvent::LeftButtonDown; |
| 313 if (key_state & MK_MBUTTON) | 312 if (key_state & MK_MBUTTON) |
| 314 modifiers |= WebInputEvent::MiddleButtonDown; | 313 modifiers |= WebInputEvent::MiddleButtonDown; |
| 315 if (key_state & MK_RBUTTON) | 314 if (key_state & MK_RBUTTON) |
| 316 modifiers |= WebInputEvent::RightButtonDown; | 315 modifiers |= WebInputEvent::RightButtonDown; |
| 317 result.setModifiers(modifiers); | 316 result.setModifiers(modifiers); |
| 318 | 317 |
| 319 // Set coordinates by translating event coordinates from screen to client. | 318 // Set coordinates by translating event coordinates from screen to client. |
| 320 POINT client_point = {result.globalX, result.globalY}; | 319 POINT client_point = {result.positionInScreen().x, |
| 320 result.positionInScreen().y}; |
| 321 MapWindowPoints(0, hwnd, &client_point, 1); | 321 MapWindowPoints(0, hwnd, &client_point, 1); |
| 322 result.x = client_point.x; | 322 result.setPositionInWidget(client_point.x, client_point.y); |
| 323 result.y = client_point.y; | |
| 324 | 323 |
| 325 // Convert wheel delta amount to a number of pixels to scroll. | 324 // Convert wheel delta amount to a number of pixels to scroll. |
| 326 // | 325 // |
| 327 // How many pixels should we scroll per line? Gecko uses the height of the | 326 // How many pixels should we scroll per line? Gecko uses the height of the |
| 328 // current line, which means scroll distance changes as you go through the | 327 // current line, which means scroll distance changes as you go through the |
| 329 // page or go to different pages. IE 8 is ~60 px/line, although the value | 328 // page or go to different pages. IE 8 is ~60 px/line, although the value |
| 330 // seems to vary slightly by page and zoom level. Also, IE defaults to | 329 // seems to vary slightly by page and zoom level. Also, IE defaults to |
| 331 // smooth scrolling while Firefox doesn't, so it can get away with somewhat | 330 // smooth scrolling while Firefox doesn't, so it can get away with somewhat |
| 332 // larger scroll values without feeling as jerky. Here we use 100 px per | 331 // larger scroll values without feeling as jerky. Here we use 100 px per |
| 333 // three lines (the default scroll amount is three lines per wheel tick). | 332 // three lines (the default scroll amount is three lines per wheel tick). |
| (...skipping 27 matching lines...) Expand all Loading... |
| 361 result.wheelTicksX = wheel_delta; | 360 result.wheelTicksX = wheel_delta; |
| 362 } else { | 361 } else { |
| 363 result.deltaY = scroll_delta; | 362 result.deltaY = scroll_delta; |
| 364 result.wheelTicksY = wheel_delta; | 363 result.wheelTicksY = wheel_delta; |
| 365 } | 364 } |
| 366 | 365 |
| 367 return result; | 366 return result; |
| 368 } | 367 } |
| 369 | 368 |
| 370 } // namespace ui | 369 } // namespace ui |
| OLD | NEW |