OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/render_widget_host_view_win.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_win.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <peninputpanel_i.c> | 9 #include <peninputpanel_i.c> |
10 #include <stack> | 10 #include <stack> |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 case ui::ET_TOUCH_RELEASED: | 365 case ui::ET_TOUCH_RELEASED: |
366 return WebKit::WebInputEvent::TouchEnd; | 366 return WebKit::WebInputEvent::TouchEnd; |
367 case ui::ET_TOUCH_CANCELLED: | 367 case ui::ET_TOUCH_CANCELLED: |
368 return WebKit::WebInputEvent::TouchCancel; | 368 return WebKit::WebInputEvent::TouchCancel; |
369 default: | 369 default: |
370 DCHECK(false) << "Unexpected ui type. " << t; | 370 DCHECK(false) << "Unexpected ui type. " << t; |
371 return WebKit::WebInputEvent::Undefined; | 371 return WebKit::WebInputEvent::Undefined; |
372 } | 372 } |
373 } | 373 } |
374 | 374 |
375 class LocalGestureEvent : public ui::GestureEvent { | 375 WebKit::WebGestureEvent CreateWebGestureEvent(HWND hwnd, |
376 public: | 376 const ui::GestureEvent& gesture) { |
377 LocalGestureEvent(HWND hwnd, | 377 POINT client_point = gesture.location().ToPOINT(); |
378 const ui::GestureEventDetails& details, | 378 POINT screen_point = gesture.location().ToPOINT(); |
379 const gfx::Point& location, | 379 MapWindowPoints(::GetParent(hwnd), hwnd, &client_point, 1); |
380 int flags, | 380 MapWindowPoints(hwnd, HWND_DESKTOP, &screen_point, 1); |
381 base::Time time, | 381 |
382 unsigned int touch_id_bitfield) | 382 WebKit::WebGestureEvent gesture_event; |
383 : ui::GestureEvent(details.type(), location.x(), location.y(), flags, | 383 gesture_event.type = ConvertToWebInputEvent(gesture.type()); |
384 time, details, touch_id_bitfield), | 384 gesture_event.x = client_point.x; |
385 client_point_(location.ToPOINT()), | 385 gesture_event.y = client_point.y; |
386 screen_point_(location.ToPOINT()) { | 386 gesture_event.globalX = screen_point.x; |
387 MapWindowPoints(::GetParent(hwnd), hwnd, &client_point_, 1); | 387 gesture_event.globalY = screen_point.y; |
388 MapWindowPoints(hwnd, HWND_DESKTOP, &screen_point_, 1); | 388 gesture_event.boundingBox = gesture.details().bounding_box(); |
| 389 |
| 390 // Copy any event-type specific data. |
| 391 switch (gesture.type()) { |
| 392 case ui::ET_GESTURE_TAP: |
| 393 gesture_event.deltaX = gesture.details().tap_count(); |
| 394 break; |
| 395 case ui::ET_GESTURE_SCROLL_UPDATE: |
| 396 gesture_event.deltaX = gesture.details().scroll_x(); |
| 397 gesture_event.deltaY = gesture.details().scroll_y(); |
| 398 break; |
| 399 case ui::ET_GESTURE_PINCH_UPDATE: |
| 400 gesture_event.deltaX = gesture.details().scale(); |
| 401 break; |
| 402 case ui::ET_SCROLL_FLING_START: |
| 403 gesture_event.deltaX = gesture.details().velocity_x(); |
| 404 gesture_event.deltaY = gesture.details().velocity_y(); |
| 405 default: |
| 406 break; |
389 } | 407 } |
390 | 408 return gesture_event; |
391 virtual ~LocalGestureEvent() {} | 409 } |
392 | |
393 WebKit::WebGestureEvent ToWebGestureEvent() { | |
394 WebKit::WebGestureEvent gesture_event; | |
395 gesture_event.type = ConvertToWebInputEvent(type()); | |
396 gesture_event.x = client_point_.x; | |
397 gesture_event.y = client_point_.y; | |
398 gesture_event.globalX = screen_point_.x; | |
399 gesture_event.globalY = screen_point_.y; | |
400 gesture_event.boundingBox = details().bounding_box(); | |
401 | |
402 // Copy any event-type specific data. | |
403 switch (type()) { | |
404 case ui::ET_GESTURE_TAP: | |
405 gesture_event.deltaX = details().tap_count(); | |
406 break; | |
407 case ui::ET_GESTURE_SCROLL_UPDATE: | |
408 gesture_event.deltaX = details().scroll_x(); | |
409 gesture_event.deltaY = details().scroll_y(); | |
410 break; | |
411 case ui::ET_GESTURE_PINCH_UPDATE: | |
412 gesture_event.deltaX = details().scale(); | |
413 break; | |
414 case ui::ET_SCROLL_FLING_START: | |
415 gesture_event.deltaX = details().velocity_x(); | |
416 gesture_event.deltaY = details().velocity_y(); | |
417 default: | |
418 break; | |
419 } | |
420 return gesture_event; | |
421 } | |
422 | |
423 private: | |
424 POINT client_point_; | |
425 POINT screen_point_; | |
426 | |
427 DISALLOW_COPY_AND_ASSIGN(LocalGestureEvent); | |
428 }; | |
429 | 410 |
430 class TouchEventFromWebTouchPoint : public ui::TouchEvent { | 411 class TouchEventFromWebTouchPoint : public ui::TouchEvent { |
431 public: | 412 public: |
432 TouchEventFromWebTouchPoint(const WebKit::WebTouchPoint& touch_point, | 413 TouchEventFromWebTouchPoint(const WebKit::WebTouchPoint& touch_point, |
433 base::TimeDelta& timestamp) | 414 base::TimeDelta& timestamp) |
434 : ui::TouchEvent(ConvertToUIEvent(touch_point.state), | 415 : ui::TouchEvent(ConvertToUIEvent(touch_point.state), |
435 touch_point.position, | 416 touch_point.position, |
436 touch_point.id, | 417 touch_point.id, |
437 timestamp) { | 418 timestamp) { |
438 set_radius(touch_point.radiusX, touch_point.radiusY); | 419 set_radius(touch_point.radiusX, touch_point.radiusY); |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 // state. If we want touch mode, then we attempt to register for touch | 1188 // state. If we want touch mode, then we attempt to register for touch |
1208 // events, and otherwise to unregister. | 1189 // events, and otherwise to unregister. |
1209 if (touch_mode) { | 1190 if (touch_mode) { |
1210 touch_mode = SetToTouchMode(); | 1191 touch_mode = SetToTouchMode(); |
1211 } | 1192 } |
1212 if (!touch_mode) { | 1193 if (!touch_mode) { |
1213 SetToGestureMode(); | 1194 SetToGestureMode(); |
1214 } | 1195 } |
1215 } | 1196 } |
1216 | 1197 |
1217 ui::GestureEvent* RenderWidgetHostViewWin::CreateGestureEvent( | |
1218 const ui::GestureEventDetails& details, | |
1219 const gfx::Point& location, | |
1220 int flags, | |
1221 base::Time time, | |
1222 unsigned int touch_id_bitfield) { | |
1223 return new LocalGestureEvent(m_hWnd, details, location, flags, time, | |
1224 touch_id_bitfield); | |
1225 } | |
1226 | |
1227 ui::TouchEvent* RenderWidgetHostViewWin::CreateTouchEvent( | |
1228 ui::EventType type, | |
1229 const gfx::Point& location, | |
1230 int touch_id, | |
1231 base::TimeDelta time_stamp) { | |
1232 return new ui::TouchEvent(type, location, touch_id, time_stamp); | |
1233 } | |
1234 | |
1235 bool RenderWidgetHostViewWin::DispatchLongPressGestureEvent( | 1198 bool RenderWidgetHostViewWin::DispatchLongPressGestureEvent( |
1236 ui::GestureEvent* event) { | 1199 ui::GestureEvent* event) { |
1237 return ForwardGestureEventToRenderer(event); | 1200 return ForwardGestureEventToRenderer(event); |
1238 } | 1201 } |
1239 | 1202 |
1240 bool RenderWidgetHostViewWin::DispatchCancelTouchEvent( | 1203 bool RenderWidgetHostViewWin::DispatchCancelTouchEvent( |
1241 ui::TouchEvent* event) { | 1204 ui::TouchEvent* event) { |
1242 if (!render_widget_host_ || !touch_events_enabled_) | 1205 if (!render_widget_host_ || !touch_events_enabled_) |
1243 return false; | 1206 return false; |
1244 DCHECK(event->type() == WebKit::WebInputEvent::TouchCancel); | 1207 DCHECK(event->type() == WebKit::WebInputEvent::TouchCancel); |
(...skipping 1545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2790 if (::IsWindow(tooltip_hwnd_)) | 2753 if (::IsWindow(tooltip_hwnd_)) |
2791 ::DestroyWindow(tooltip_hwnd_); | 2754 ::DestroyWindow(tooltip_hwnd_); |
2792 tooltip_hwnd_ = NULL; | 2755 tooltip_hwnd_ = NULL; |
2793 } | 2756 } |
2794 | 2757 |
2795 bool RenderWidgetHostViewWin::ForwardGestureEventToRenderer( | 2758 bool RenderWidgetHostViewWin::ForwardGestureEventToRenderer( |
2796 ui::GestureEvent* gesture) { | 2759 ui::GestureEvent* gesture) { |
2797 if (!render_widget_host_) | 2760 if (!render_widget_host_) |
2798 return false; | 2761 return false; |
2799 | 2762 |
2800 LocalGestureEvent* local = static_cast<LocalGestureEvent*>(gesture); | 2763 WebKit::WebGestureEvent web_gesture = CreateWebGestureEvent(m_hWnd, *gesture); |
2801 WebKit::WebGestureEvent gesture_event = local->ToWebGestureEvent(); | 2764 if (web_gesture.type == WebKit::WebGestureEvent::Undefined) |
2802 if (gesture_event.type == WebKit::WebGestureEvent::Undefined) | |
2803 return false; | 2765 return false; |
2804 render_widget_host_->ForwardGestureEvent(gesture_event); | 2766 render_widget_host_->ForwardGestureEvent(web_gesture); |
2805 return true; | 2767 return true; |
2806 } | 2768 } |
2807 | 2769 |
2808 void RenderWidgetHostViewWin::ForwardMouseEventToRenderer(UINT message, | 2770 void RenderWidgetHostViewWin::ForwardMouseEventToRenderer(UINT message, |
2809 WPARAM wparam, | 2771 WPARAM wparam, |
2810 LPARAM lparam) { | 2772 LPARAM lparam) { |
2811 TRACE_EVENT0("browser", | 2773 TRACE_EVENT0("browser", |
2812 "RenderWidgetHostViewWin::ForwardMouseEventToRenderer"); | 2774 "RenderWidgetHostViewWin::ForwardMouseEventToRenderer"); |
2813 if (!render_widget_host_) { | 2775 if (!render_widget_host_) { |
2814 TRACE_EVENT0("browser", "EarlyOut_NoRWH"); | 2776 TRACE_EVENT0("browser", "EarlyOut_NoRWH"); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3084 // receive a focus change in the context of a pointer down message, it means | 3046 // receive a focus change in the context of a pointer down message, it means |
3085 // that the pointer down message occurred on the edit field and we should | 3047 // that the pointer down message occurred on the edit field and we should |
3086 // display the on screen keyboard | 3048 // display the on screen keyboard |
3087 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_) | 3049 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_) |
3088 DisplayOnScreenKeyboardIfNeeded(); | 3050 DisplayOnScreenKeyboardIfNeeded(); |
3089 received_focus_change_after_pointer_down_ = false; | 3051 received_focus_change_after_pointer_down_ = false; |
3090 pointer_down_context_ = false; | 3052 pointer_down_context_ = false; |
3091 } | 3053 } |
3092 | 3054 |
3093 } // namespace content | 3055 } // namespace content |
OLD | NEW |