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 14 matching lines...) Expand all Loading... |
25 #include "base/win/wrapped_window_proc.h" | 25 #include "base/win/wrapped_window_proc.h" |
26 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 26 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
27 #include "content/browser/accessibility/browser_accessibility_win.h" | 27 #include "content/browser/accessibility/browser_accessibility_win.h" |
28 #include "content/browser/gpu/gpu_data_manager_impl.h" | 28 #include "content/browser/gpu/gpu_data_manager_impl.h" |
29 #include "content/browser/gpu/gpu_process_host.h" | 29 #include "content/browser/gpu/gpu_process_host.h" |
30 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 30 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
31 #include "content/browser/renderer_host/backing_store.h" | 31 #include "content/browser/renderer_host/backing_store.h" |
32 #include "content/browser/renderer_host/backing_store_win.h" | 32 #include "content/browser/renderer_host/backing_store_win.h" |
33 #include "content/browser/renderer_host/render_process_host_impl.h" | 33 #include "content/browser/renderer_host/render_process_host_impl.h" |
34 #include "content/browser/renderer_host/render_widget_host_impl.h" | 34 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 35 #include "content/browser/renderer_host/ui_events_helper.h" |
35 #include "content/common/accessibility_messages.h" | 36 #include "content/common/accessibility_messages.h" |
36 #include "content/common/gpu/gpu_messages.h" | 37 #include "content/common/gpu/gpu_messages.h" |
37 #include "content/common/plugin_messages.h" | 38 #include "content/common/plugin_messages.h" |
38 #include "content/common/view_messages.h" | 39 #include "content/common/view_messages.h" |
39 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
40 #include "content/public/browser/child_process_data.h" | 41 #include "content/public/browser/child_process_data.h" |
41 #include "content/public/browser/content_browser_client.h" | 42 #include "content/public/browser/content_browser_client.h" |
42 #include "content/public/browser/native_web_keyboard_event.h" | 43 #include "content/public/browser/native_web_keyboard_event.h" |
43 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
44 #include "content/public/browser/notification_types.h" | 45 #include "content/public/browser/notification_types.h" |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 | 404 |
404 // Marks all active touchpoints as released. | 405 // Marks all active touchpoints as released. |
405 bool ReleaseTouchPoints(); | 406 bool ReleaseTouchPoints(); |
406 | 407 |
407 // The contained WebTouchEvent. | 408 // The contained WebTouchEvent. |
408 const WebKit::WebTouchEvent& touch_event() { return touch_event_; } | 409 const WebKit::WebTouchEvent& touch_event() { return touch_event_; } |
409 | 410 |
410 // Returns if any touches are modified in the event. | 411 // Returns if any touches are modified in the event. |
411 bool is_changed() { return touch_event_.changedTouchesLength != 0; } | 412 bool is_changed() { return touch_event_.changedTouchesLength != 0; } |
412 | 413 |
413 void QueueEvents(ui::GestureConsumer* consumer, ui::GestureRecognizer* gr) { | |
414 if (touch_event_.touchesLength > 0) | |
415 touch_count_.push(touch_event_.touchesLength); | |
416 base::TimeDelta timestamp = base::TimeDelta::FromMilliseconds( | |
417 touch_event_.timeStampSeconds * 1000); | |
418 for (size_t i = 0; i < touch_event_.touchesLength; ++i) { | |
419 gr->QueueTouchEventForGesture(consumer, | |
420 TouchEventFromWebTouchPoint(touch_event_.touches[i], timestamp)); | |
421 } | |
422 } | |
423 | |
424 int GetNextTouchCount() { | |
425 DCHECK(!touch_count_.empty()); | |
426 int result = touch_count_.top(); | |
427 touch_count_.pop(); | |
428 return result; | |
429 } | |
430 | |
431 private: | 414 private: |
432 typedef std::map<unsigned int, int> MapType; | 415 typedef std::map<unsigned int, int> MapType; |
433 | 416 |
434 // Adds a touch point or returns NULL if there's not enough space. | 417 // Adds a touch point or returns NULL if there's not enough space. |
435 WebKit::WebTouchPoint* AddTouchPoint(TOUCHINPUT* touch_input); | 418 WebKit::WebTouchPoint* AddTouchPoint(TOUCHINPUT* touch_input); |
436 | 419 |
437 // Copy details from a TOUCHINPUT to an existing WebTouchPoint, returning | 420 // Copy details from a TOUCHINPUT to an existing WebTouchPoint, returning |
438 // true if the resulting point is a stationary move. | 421 // true if the resulting point is a stationary move. |
439 bool UpdateTouchPoint(WebKit::WebTouchPoint* touch_point, | 422 bool UpdateTouchPoint(WebKit::WebTouchPoint* touch_point, |
440 TOUCHINPUT* touch_input); | 423 TOUCHINPUT* touch_input); |
441 | 424 |
442 // Find (or create) a mapping for _os_touch_id_. | 425 // Find (or create) a mapping for _os_touch_id_. |
443 unsigned int GetMappedTouch(unsigned int os_touch_id); | 426 unsigned int GetMappedTouch(unsigned int os_touch_id); |
444 | 427 |
445 // Remove any mappings that are no longer in use. | 428 // Remove any mappings that are no longer in use. |
446 void RemoveExpiredMappings(); | 429 void RemoveExpiredMappings(); |
447 | 430 |
448 // The gesture recognizer processes touch events one at a time, but WebKit | |
449 // (ForwardTouchEvent) takes a set of touch events. |touchCount_| tracks how | |
450 // many individual touch events were sent to ForwardTouchEvent, so we can | |
451 // send the correct number of AdvanceTouchQueue's | |
452 std::stack<int> touch_count_; | |
453 | |
454 WebKit::WebTouchEvent touch_event_; | 431 WebKit::WebTouchEvent touch_event_; |
455 const RenderWidgetHostViewWin* const window_; | 432 const RenderWidgetHostViewWin* const window_; |
456 | 433 |
457 // Maps OS touch Id's into an internal (WebKit-friendly) touch-id. | 434 // Maps OS touch Id's into an internal (WebKit-friendly) touch-id. |
458 // WebKit expects small consecutive integers, starting at 0. | 435 // WebKit expects small consecutive integers, starting at 0. |
459 MapType touch_map_; | 436 MapType touch_map_; |
460 | 437 |
461 DISALLOW_COPY_AND_ASSIGN(WebTouchState); | 438 DISALLOW_COPY_AND_ASSIGN(WebTouchState); |
462 }; | 439 }; |
463 | 440 |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 } | 924 } |
948 | 925 |
949 void RenderWidgetHostViewWin::SetBackground(const SkBitmap& background) { | 926 void RenderWidgetHostViewWin::SetBackground(const SkBitmap& background) { |
950 RenderWidgetHostViewBase::SetBackground(background); | 927 RenderWidgetHostViewBase::SetBackground(background); |
951 render_widget_host_->SetBackground(background); | 928 render_widget_host_->SetBackground(background); |
952 } | 929 } |
953 | 930 |
954 void RenderWidgetHostViewWin::ProcessAckedTouchEvent( | 931 void RenderWidgetHostViewWin::ProcessAckedTouchEvent( |
955 const WebKit::WebTouchEvent& touch, | 932 const WebKit::WebTouchEvent& touch, |
956 bool processed) { | 933 bool processed) { |
957 DCHECK(render_widget_host_->has_touch_handler() && | 934 DCHECK(touch_events_enabled_); |
958 touch_events_enabled_); | |
959 | 935 |
960 int touch_count = touch_state_->GetNextTouchCount(); | 936 ScopedVector<ui::TouchEvent> events; |
961 for (int i = 0; i < touch_count; ++i) { | 937 if (!MakeUITouchEventsFromWebTouchEvents(touch, &events)) |
| 938 return; |
| 939 |
| 940 ui::EventResult result = processed ? ui::ER_HANDLED : ui::ER_UNHANDLED; |
| 941 for (ScopedVector<ui::TouchEvent>::iterator iter = events.begin(), |
| 942 end = events.end(); iter != end; ++iter) { |
962 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; | 943 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; |
963 gestures.reset(gesture_recognizer_->AdvanceTouchQueue(this, processed)); | 944 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture( |
| 945 *(*iter), result, this)); |
964 ProcessGestures(gestures.get()); | 946 ProcessGestures(gestures.get()); |
965 } | 947 } |
966 } | 948 } |
967 | 949 |
968 void RenderWidgetHostViewWin::UpdateDesiredTouchMode() { | 950 void RenderWidgetHostViewWin::UpdateDesiredTouchMode() { |
969 // Make sure that touch events even make sense. | 951 // Make sure that touch events even make sense. |
970 static bool touch_mode = base::win::GetVersion() >= base::win::VERSION_WIN7 && | 952 static bool touch_mode = base::win::GetVersion() >= base::win::VERSION_WIN7 && |
971 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableTouchEvents); | 953 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableTouchEvents); |
972 | 954 |
973 if (!touch_mode) | 955 if (!touch_mode) |
(...skipping 21 matching lines...) Expand all Loading... |
995 } | 977 } |
996 } | 978 } |
997 | 979 |
998 bool RenderWidgetHostViewWin::DispatchLongPressGestureEvent( | 980 bool RenderWidgetHostViewWin::DispatchLongPressGestureEvent( |
999 ui::GestureEvent* event) { | 981 ui::GestureEvent* event) { |
1000 return ForwardGestureEventToRenderer(event); | 982 return ForwardGestureEventToRenderer(event); |
1001 } | 983 } |
1002 | 984 |
1003 bool RenderWidgetHostViewWin::DispatchCancelTouchEvent( | 985 bool RenderWidgetHostViewWin::DispatchCancelTouchEvent( |
1004 ui::TouchEvent* event) { | 986 ui::TouchEvent* event) { |
1005 if (!render_widget_host_ || !touch_events_enabled_) | 987 if (!render_widget_host_ || !touch_events_enabled_ || |
| 988 !render_widget_host_->ShouldForwardTouchEvent()) { |
1006 return false; | 989 return false; |
| 990 } |
1007 DCHECK(event->type() == WebKit::WebInputEvent::TouchCancel); | 991 DCHECK(event->type() == WebKit::WebInputEvent::TouchCancel); |
1008 WebKit::WebTouchEvent cancel_event; | 992 WebKit::WebTouchEvent cancel_event; |
1009 cancel_event.type = WebKit::WebInputEvent::TouchCancel; | 993 cancel_event.type = WebKit::WebInputEvent::TouchCancel; |
1010 cancel_event.timeStampSeconds = event->time_stamp().InSecondsF(); | 994 cancel_event.timeStampSeconds = event->time_stamp().InSecondsF(); |
1011 render_widget_host_->ForwardTouchEvent(cancel_event); | 995 render_widget_host_->ForwardTouchEvent(cancel_event); |
1012 return true; | 996 return true; |
1013 } | 997 } |
1014 | 998 |
1015 void RenderWidgetHostViewWin::SetHasHorizontalScrollbar( | 999 void RenderWidgetHostViewWin::SetHasHorizontalScrollbar( |
1016 bool has_horizontal_scrollbar) { | 1000 bool has_horizontal_scrollbar) { |
(...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2217 return 0; | 2201 return 0; |
2218 } | 2202 } |
2219 | 2203 |
2220 if (total == 1 && (points[0].dwFlags & TOUCHEVENTF_DOWN)) { | 2204 if (total == 1 && (points[0].dwFlags & TOUCHEVENTF_DOWN)) { |
2221 pointer_down_context_ = true; | 2205 pointer_down_context_ = true; |
2222 last_touch_location_ = gfx::Point( | 2206 last_touch_location_ = gfx::Point( |
2223 TOUCH_COORD_TO_PIXEL(points[0].x), | 2207 TOUCH_COORD_TO_PIXEL(points[0].x), |
2224 TOUCH_COORD_TO_PIXEL(points[0].y)); | 2208 TOUCH_COORD_TO_PIXEL(points[0].y)); |
2225 } | 2209 } |
2226 | 2210 |
2227 bool has_touch_handler = render_widget_host_->has_touch_handler() && | 2211 bool should_forward = render_widget_host_->ShouldForwardTouchEvent() && |
2228 touch_events_enabled_; | 2212 touch_events_enabled_; |
2229 | 2213 |
2230 // Send a copy of the touch events on to the gesture recognizer. | 2214 // Send a copy of the touch events on to the gesture recognizer. |
2231 for (size_t start = 0; start < total;) { | 2215 for (size_t start = 0; start < total;) { |
2232 start += touch_state_->UpdateTouchPoints(points + start, total - start); | 2216 start += touch_state_->UpdateTouchPoints(points + start, total - start); |
2233 if (has_touch_handler) { | 2217 if (should_forward) { |
2234 if (touch_state_->is_changed()) { | 2218 if (touch_state_->is_changed()) |
2235 render_widget_host_->ForwardTouchEvent(touch_state_->touch_event()); | 2219 render_widget_host_->ForwardTouchEvent(touch_state_->touch_event()); |
2236 touch_state_->QueueEvents(this, gesture_recognizer_.get()); | |
2237 } | |
2238 } else { | 2220 } else { |
2239 const WebKit::WebTouchEvent& touch_event = touch_state_->touch_event(); | 2221 const WebKit::WebTouchEvent& touch_event = touch_state_->touch_event(); |
2240 base::TimeDelta timestamp = base::TimeDelta::FromMilliseconds( | 2222 base::TimeDelta timestamp = base::TimeDelta::FromMilliseconds( |
2241 touch_event.timeStampSeconds * 1000); | 2223 touch_event.timeStampSeconds * 1000); |
2242 for (size_t i = 0; i < touch_event.touchesLength; ++i) { | 2224 for (size_t i = 0; i < touch_event.touchesLength; ++i) { |
2243 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; | 2225 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; |
2244 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture( | 2226 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture( |
2245 TouchEventFromWebTouchPoint(touch_event.touches[i], timestamp), | 2227 TouchEventFromWebTouchPoint(touch_event.touches[i], timestamp), |
2246 ui::ER_UNHANDLED, this)); | 2228 ui::ER_UNHANDLED, this)); |
2247 ProcessGestures(gestures.get()); | 2229 ProcessGestures(gestures.get()); |
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3100 // receive a focus change in the context of a pointer down message, it means | 3082 // receive a focus change in the context of a pointer down message, it means |
3101 // that the pointer down message occurred on the edit field and we should | 3083 // that the pointer down message occurred on the edit field and we should |
3102 // display the on screen keyboard | 3084 // display the on screen keyboard |
3103 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_) | 3085 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_) |
3104 DisplayOnScreenKeyboardIfNeeded(); | 3086 DisplayOnScreenKeyboardIfNeeded(); |
3105 received_focus_change_after_pointer_down_ = false; | 3087 received_focus_change_after_pointer_down_ = false; |
3106 pointer_down_context_ = false; | 3088 pointer_down_context_ = false; |
3107 } | 3089 } |
3108 | 3090 |
3109 } // namespace content | 3091 } // namespace content |
OLD | NEW |