| OLD | NEW |
| 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/input_router_impl.h" | 5 #include "content/browser/renderer_host/input/input_router_impl.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 return TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE; | 92 return TouchEventQueue::TOUCH_SCROLLING_MODE_ASYNC_TOUCHMOVE; |
| 93 if (modeString == switches::kTouchScrollingModeSyncTouchmove) | 93 if (modeString == switches::kTouchScrollingModeSyncTouchmove) |
| 94 return TouchEventQueue::TOUCH_SCROLLING_MODE_SYNC_TOUCHMOVE; | 94 return TouchEventQueue::TOUCH_SCROLLING_MODE_SYNC_TOUCHMOVE; |
| 95 if (modeString == switches::kTouchScrollingModeTouchcancel) | 95 if (modeString == switches::kTouchScrollingModeTouchcancel) |
| 96 return TouchEventQueue::TOUCH_SCROLLING_MODE_TOUCHCANCEL; | 96 return TouchEventQueue::TOUCH_SCROLLING_MODE_TOUCHCANCEL; |
| 97 if (modeString != "") | 97 if (modeString != "") |
| 98 LOG(ERROR) << "Invalid --touch-scrolling-mode option: " << modeString; | 98 LOG(ERROR) << "Invalid --touch-scrolling-mode option: " << modeString; |
| 99 return TouchEventQueue::TOUCH_SCROLLING_MODE_DEFAULT; | 99 return TouchEventQueue::TOUCH_SCROLLING_MODE_DEFAULT; |
| 100 } | 100 } |
| 101 | 101 |
| 102 GestureEventWithLatencyInfo MakeGestureEvent(WebInputEvent::Type type, | |
| 103 double timestamp_seconds, | |
| 104 int x, | |
| 105 int y, | |
| 106 int modifiers, | |
| 107 const ui::LatencyInfo& latency) { | |
| 108 WebGestureEvent result; | |
| 109 | |
| 110 result.type = type; | |
| 111 result.x = x; | |
| 112 result.y = y; | |
| 113 result.sourceDevice = WebGestureEvent::Touchscreen; | |
| 114 result.timeStampSeconds = timestamp_seconds; | |
| 115 result.modifiers = modifiers; | |
| 116 | |
| 117 return GestureEventWithLatencyInfo(result, latency); | |
| 118 } | |
| 119 | |
| 120 const char* GetEventAckName(InputEventAckState ack_result) { | 102 const char* GetEventAckName(InputEventAckState ack_result) { |
| 121 switch(ack_result) { | 103 switch(ack_result) { |
| 122 case INPUT_EVENT_ACK_STATE_UNKNOWN: return "UNKNOWN"; | 104 case INPUT_EVENT_ACK_STATE_UNKNOWN: return "UNKNOWN"; |
| 123 case INPUT_EVENT_ACK_STATE_CONSUMED: return "CONSUMED"; | 105 case INPUT_EVENT_ACK_STATE_CONSUMED: return "CONSUMED"; |
| 124 case INPUT_EVENT_ACK_STATE_NOT_CONSUMED: return "NOT_CONSUMED"; | 106 case INPUT_EVENT_ACK_STATE_NOT_CONSUMED: return "NOT_CONSUMED"; |
| 125 case INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS: return "NO_CONSUMER_EXISTS"; | 107 case INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS: return "NO_CONSUMER_EXISTS"; |
| 126 case INPUT_EVENT_ACK_STATE_IGNORED: return "IGNORED"; | 108 case INPUT_EVENT_ACK_STATE_IGNORED: return "IGNORED"; |
| 127 } | 109 } |
| 128 DLOG(WARNING) << "Unhandled InputEventAckState in GetEventAckName."; | 110 DLOG(WARNING) << "Unhandled InputEventAckState in GetEventAckName."; |
| 129 return ""; | 111 return ""; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 case InputMsg_HandleInputEvent::ID: | 159 case InputMsg_HandleInputEvent::ID: |
| 178 NOTREACHED() << "WebInputEvents should never be sent via SendInput."; | 160 NOTREACHED() << "WebInputEvents should never be sent via SendInput."; |
| 179 return false; | 161 return false; |
| 180 default: | 162 default: |
| 181 return Send(message.release()); | 163 return Send(message.release()); |
| 182 } | 164 } |
| 183 } | 165 } |
| 184 | 166 |
| 185 void InputRouterImpl::SendMouseEvent( | 167 void InputRouterImpl::SendMouseEvent( |
| 186 const MouseEventWithLatencyInfo& mouse_event) { | 168 const MouseEventWithLatencyInfo& mouse_event) { |
| 187 // Order is important here; we need to convert all MouseEvents before they | |
| 188 // propagate further, e.g., to the tap suppression controller. | |
| 189 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 190 switches::kSimulateTouchScreenWithMouse)) { | |
| 191 SimulateTouchGestureWithMouse(mouse_event); | |
| 192 return; | |
| 193 } | |
| 194 | |
| 195 if (mouse_event.event.type == WebInputEvent::MouseDown && | 169 if (mouse_event.event.type == WebInputEvent::MouseDown && |
| 196 gesture_event_queue_.GetTouchpadTapSuppressionController()-> | 170 gesture_event_queue_.GetTouchpadTapSuppressionController()-> |
| 197 ShouldDeferMouseDown(mouse_event)) | 171 ShouldDeferMouseDown(mouse_event)) |
| 198 return; | 172 return; |
| 199 if (mouse_event.event.type == WebInputEvent::MouseUp && | 173 if (mouse_event.event.type == WebInputEvent::MouseUp && |
| 200 gesture_event_queue_.GetTouchpadTapSuppressionController()-> | 174 gesture_event_queue_.GetTouchpadTapSuppressionController()-> |
| 201 ShouldSuppressMouseUp()) | 175 ShouldSuppressMouseUp()) |
| 202 return; | 176 return; |
| 203 | 177 |
| 204 SendMouseEventImmediately(mouse_event); | 178 SendMouseEventImmediately(mouse_event); |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 return; | 695 return; |
| 722 | 696 |
| 723 OverscrollController* controller = client_->GetOverscrollController(); | 697 OverscrollController* controller = client_->GetOverscrollController(); |
| 724 if (!controller) | 698 if (!controller) |
| 725 return; | 699 return; |
| 726 | 700 |
| 727 controller->ReceivedEventACK( | 701 controller->ReceivedEventACK( |
| 728 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result)); | 702 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result)); |
| 729 } | 703 } |
| 730 | 704 |
| 731 void InputRouterImpl::SimulateTouchGestureWithMouse( | |
| 732 const MouseEventWithLatencyInfo& event) { | |
| 733 const WebMouseEvent& mouse_event = event.event; | |
| 734 int x = mouse_event.x, y = mouse_event.y; | |
| 735 float dx = mouse_event.movementX, dy = mouse_event.movementY; | |
| 736 static int startX = 0, startY = 0; | |
| 737 | |
| 738 switch (mouse_event.button) { | |
| 739 case WebMouseEvent::ButtonLeft: | |
| 740 if (mouse_event.type == WebInputEvent::MouseDown) { | |
| 741 startX = x; | |
| 742 startY = y; | |
| 743 SendGestureEvent(MakeGestureEvent( | |
| 744 WebInputEvent::GestureScrollBegin, mouse_event.timeStampSeconds, | |
| 745 x, y, 0, event.latency)); | |
| 746 } | |
| 747 if (dx != 0 || dy != 0) { | |
| 748 GestureEventWithLatencyInfo gesture_event = MakeGestureEvent( | |
| 749 WebInputEvent::GestureScrollUpdate, mouse_event.timeStampSeconds, | |
| 750 x, y, 0, event.latency); | |
| 751 gesture_event.event.data.scrollUpdate.deltaX = dx; | |
| 752 gesture_event.event.data.scrollUpdate.deltaY = dy; | |
| 753 SendGestureEvent(gesture_event); | |
| 754 } | |
| 755 if (mouse_event.type == WebInputEvent::MouseUp) { | |
| 756 SendGestureEvent(MakeGestureEvent( | |
| 757 WebInputEvent::GestureScrollEnd, mouse_event.timeStampSeconds, | |
| 758 x, y, 0, event.latency)); | |
| 759 } | |
| 760 break; | |
| 761 case WebMouseEvent::ButtonMiddle: | |
| 762 if (mouse_event.type == WebInputEvent::MouseDown) { | |
| 763 startX = x; | |
| 764 startY = y; | |
| 765 SendGestureEvent(MakeGestureEvent( | |
| 766 WebInputEvent::GestureShowPress, mouse_event.timeStampSeconds, | |
| 767 x, y, 0, event.latency)); | |
| 768 SendGestureEvent(MakeGestureEvent( | |
| 769 WebInputEvent::GestureTapDown, mouse_event.timeStampSeconds, | |
| 770 x, y, 0, event.latency)); | |
| 771 } | |
| 772 if (mouse_event.type == WebInputEvent::MouseUp) { | |
| 773 SendGestureEvent(MakeGestureEvent( | |
| 774 WebInputEvent::GestureTap, mouse_event.timeStampSeconds, | |
| 775 x, y, 0, event.latency)); | |
| 776 } | |
| 777 break; | |
| 778 case WebMouseEvent::ButtonRight: | |
| 779 if (mouse_event.type == WebInputEvent::MouseDown) { | |
| 780 startX = x; | |
| 781 startY = y; | |
| 782 SendGestureEvent(MakeGestureEvent( | |
| 783 WebInputEvent::GestureScrollBegin, mouse_event.timeStampSeconds, | |
| 784 x, y, 0, event.latency)); | |
| 785 SendGestureEvent(MakeGestureEvent( | |
| 786 WebInputEvent::GesturePinchBegin, mouse_event.timeStampSeconds, | |
| 787 x, y, 0, event.latency)); | |
| 788 } | |
| 789 if (dx != 0 || dy != 0) { | |
| 790 dx = pow(dy < 0 ? 0.998f : 1.002f, fabs(dy)); | |
| 791 GestureEventWithLatencyInfo gesture_event = MakeGestureEvent( | |
| 792 WebInputEvent::GesturePinchUpdate, mouse_event.timeStampSeconds, | |
| 793 startX, startY, 0, event.latency); | |
| 794 gesture_event.event.data.pinchUpdate.scale = dx; | |
| 795 SendGestureEvent(gesture_event); | |
| 796 } | |
| 797 if (mouse_event.type == WebInputEvent::MouseUp) { | |
| 798 SendGestureEvent(MakeGestureEvent( | |
| 799 WebInputEvent::GesturePinchEnd, mouse_event.timeStampSeconds, | |
| 800 x, y, 0, event.latency)); | |
| 801 SendGestureEvent(MakeGestureEvent( | |
| 802 WebInputEvent::GestureScrollEnd, mouse_event.timeStampSeconds, | |
| 803 x, y, 0, event.latency)); | |
| 804 } | |
| 805 break; | |
| 806 case WebMouseEvent::ButtonNone: | |
| 807 break; | |
| 808 } | |
| 809 } | |
| 810 | |
| 811 void InputRouterImpl::UpdateTouchAckTimeoutEnabled() { | 705 void InputRouterImpl::UpdateTouchAckTimeoutEnabled() { |
| 812 if (!touch_ack_timeout_supported_) { | 706 if (!touch_ack_timeout_supported_) { |
| 813 touch_event_queue_.SetAckTimeoutEnabled(false, base::TimeDelta()); | 707 touch_event_queue_.SetAckTimeoutEnabled(false, base::TimeDelta()); |
| 814 return; | 708 return; |
| 815 } | 709 } |
| 816 | 710 |
| 817 // Mobile sites tend to be well-behaved with respect to touch handling, so | 711 // Mobile sites tend to be well-behaved with respect to touch handling, so |
| 818 // they have less need for the touch timeout fallback. | 712 // they have less need for the touch timeout fallback. |
| 819 const bool fixed_page_scale = (current_view_flags_ & FIXED_PAGE_SCALE) != 0; | 713 const bool fixed_page_scale = (current_view_flags_ & FIXED_PAGE_SCALE) != 0; |
| 820 const bool mobile_viewport = (current_view_flags_ & MOBILE_VIEWPORT) != 0; | 714 const bool mobile_viewport = (current_view_flags_ & MOBILE_VIEWPORT) != 0; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 select_range_pending_ || | 746 select_range_pending_ || |
| 853 move_caret_pending_; | 747 move_caret_pending_; |
| 854 } | 748 } |
| 855 | 749 |
| 856 bool InputRouterImpl::IsInOverscrollGesture() const { | 750 bool InputRouterImpl::IsInOverscrollGesture() const { |
| 857 OverscrollController* controller = client_->GetOverscrollController(); | 751 OverscrollController* controller = client_->GetOverscrollController(); |
| 858 return controller && controller->overscroll_mode() != OVERSCROLL_NONE; | 752 return controller && controller->overscroll_mode() != OVERSCROLL_NONE; |
| 859 } | 753 } |
| 860 | 754 |
| 861 } // namespace content | 755 } // namespace content |
| OLD | NEW |