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_impl.h" | 5 #include "content/browser/renderer_host/render_widget_host_impl.h" |
6 | 6 |
| 7 #include <math.h> |
7 #include <utility> | 8 #include <utility> |
8 | 9 |
9 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
13 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
14 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
15 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
16 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 time_when_considered_hung_ = Time(); | 741 time_when_considered_hung_ = Time(); |
741 RendererIsResponsive(); | 742 RendererIsResponsive(); |
742 // We do not bother to stop the hung_renderer_timer_ here in case it will be | 743 // We do not bother to stop the hung_renderer_timer_ here in case it will be |
743 // started again shortly, which happens to be the common use case. | 744 // started again shortly, which happens to be the common use case. |
744 } | 745 } |
745 | 746 |
746 void RenderWidgetHostImpl::EnableFullAccessibilityMode() { | 747 void RenderWidgetHostImpl::EnableFullAccessibilityMode() { |
747 SetAccessibilityMode(AccessibilityModeComplete); | 748 SetAccessibilityMode(AccessibilityModeComplete); |
748 } | 749 } |
749 | 750 |
| 751 static WebGestureEvent MakeGestureEvent(WebInputEvent::Type type, |
| 752 double timestamp_seconds, |
| 753 int x, |
| 754 int y, |
| 755 float delta_x, |
| 756 float delta_y, |
| 757 int modifiers) { |
| 758 WebGestureEvent result; |
| 759 |
| 760 result.type = type; |
| 761 result.x = x; |
| 762 result.y = y; |
| 763 result.deltaX = delta_x; |
| 764 result.deltaY = delta_y; |
| 765 result.timeStampSeconds = timestamp_seconds; |
| 766 result.modifiers = modifiers; |
| 767 |
| 768 return result; |
| 769 } |
| 770 |
| 771 void RenderWidgetHostImpl::SimulateTouchGestureWithMouse( |
| 772 const WebMouseEvent& mouse_event) { |
| 773 int x = mouse_event.x, y = mouse_event.y; |
| 774 float dx = mouse_event.movementX, dy = mouse_event.movementY; |
| 775 static int startX = 0, startY = 0; |
| 776 |
| 777 switch (mouse_event.button) { |
| 778 case WebMouseEvent::ButtonLeft: |
| 779 if (mouse_event.type == WebInputEvent::MouseDown) { |
| 780 startX = x; |
| 781 startY = y; |
| 782 ForwardGestureEvent(MakeGestureEvent( |
| 783 WebInputEvent::GestureScrollBegin, mouse_event.timeStampSeconds, |
| 784 x, y, 0, 0, 0)); |
| 785 } |
| 786 if (dx != 0 || dy != 0) { |
| 787 ForwardGestureEvent(MakeGestureEvent( |
| 788 WebInputEvent::GestureScrollUpdate, mouse_event.timeStampSeconds, |
| 789 x, y, dx, dy, 0)); |
| 790 } |
| 791 if (mouse_event.type == WebInputEvent::MouseUp) { |
| 792 ForwardGestureEvent(MakeGestureEvent( |
| 793 WebInputEvent::GestureScrollEnd, mouse_event.timeStampSeconds, |
| 794 x, y, dx, dy, 0)); |
| 795 } |
| 796 break; |
| 797 case WebMouseEvent::ButtonMiddle: |
| 798 if (mouse_event.type == WebInputEvent::MouseDown) { |
| 799 startX = x; |
| 800 startY = y; |
| 801 ForwardGestureEvent(MakeGestureEvent( |
| 802 WebInputEvent::GestureTapDown, mouse_event.timeStampSeconds, |
| 803 x, y, 0, 0, 0)); |
| 804 } |
| 805 if (mouse_event.type == WebInputEvent::MouseUp) { |
| 806 ForwardGestureEvent(MakeGestureEvent( |
| 807 WebInputEvent::GestureTap, mouse_event.timeStampSeconds, |
| 808 x, y, dx, dy, 0)); |
| 809 } |
| 810 break; |
| 811 case WebMouseEvent::ButtonRight: |
| 812 if (mouse_event.type == WebInputEvent::MouseDown) { |
| 813 startX = x; |
| 814 startY = y; |
| 815 ForwardGestureEvent(MakeGestureEvent( |
| 816 WebInputEvent::GesturePinchBegin, mouse_event.timeStampSeconds, |
| 817 x, y, 1, 1, 0)); |
| 818 } |
| 819 if (dx != 0 || dy != 0) { |
| 820 dx = pow(dy < 0 ? 0.998f : 1.002f, fabs(dy)); |
| 821 dy = dx; |
| 822 ForwardGestureEvent(MakeGestureEvent( |
| 823 WebInputEvent::GesturePinchUpdate, mouse_event.timeStampSeconds, |
| 824 startX, startY, dx, dy, 0)); |
| 825 } |
| 826 if (mouse_event.type == WebInputEvent::MouseUp) { |
| 827 ForwardGestureEvent(MakeGestureEvent( |
| 828 WebInputEvent::GesturePinchEnd, mouse_event.timeStampSeconds, |
| 829 x, y, dx, dy, 0)); |
| 830 } |
| 831 break; |
| 832 case WebMouseEvent::ButtonNone: |
| 833 break; |
| 834 } |
| 835 } |
| 836 |
750 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { | 837 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { |
751 TRACE_EVENT2("renderer_host", "RenderWidgetHostImpl::ForwardMouseEvent", | 838 TRACE_EVENT2("renderer_host", "RenderWidgetHostImpl::ForwardMouseEvent", |
752 "x", mouse_event.x, "y", mouse_event.y); | 839 "x", mouse_event.x, "y", mouse_event.y); |
753 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 840 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
754 return; | 841 return; |
755 | 842 |
| 843 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 844 switches::kSimulateTouchScreenWithMouse)) { |
| 845 SimulateTouchGestureWithMouse(mouse_event); |
| 846 return; |
| 847 } |
| 848 |
756 // Avoid spamming the renderer with mouse move events. It is important | 849 // Avoid spamming the renderer with mouse move events. It is important |
757 // to note that WM_MOUSEMOVE events are anyways synthetic, but since our | 850 // to note that WM_MOUSEMOVE events are anyways synthetic, but since our |
758 // thread is able to rapidly consume WM_MOUSEMOVE events, we may get way | 851 // thread is able to rapidly consume WM_MOUSEMOVE events, we may get way |
759 // more WM_MOUSEMOVE events than we wish to send to the renderer. | 852 // more WM_MOUSEMOVE events than we wish to send to the renderer. |
760 if (mouse_event.type == WebInputEvent::MouseMove) { | 853 if (mouse_event.type == WebInputEvent::MouseMove) { |
761 if (mouse_move_pending_) { | 854 if (mouse_move_pending_) { |
762 if (!next_mouse_move_.get()) { | 855 if (!next_mouse_move_.get()) { |
763 next_mouse_move_.reset(new WebMouseEvent(mouse_event)); | 856 next_mouse_move_.reset(new WebMouseEvent(mouse_event)); |
764 } else { | 857 } else { |
765 // Accumulate movement deltas. | 858 // Accumulate movement deltas. |
(...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1934 // indicate that no callback is in progress (i.e. without this line | 2027 // indicate that no callback is in progress (i.e. without this line |
1935 // DelayedAutoResized will not get called again). | 2028 // DelayedAutoResized will not get called again). |
1936 new_auto_size_.SetSize(0, 0); | 2029 new_auto_size_.SetSize(0, 0); |
1937 if (!should_auto_resize_) | 2030 if (!should_auto_resize_) |
1938 return; | 2031 return; |
1939 | 2032 |
1940 OnRenderAutoResized(new_size); | 2033 OnRenderAutoResized(new_size); |
1941 } | 2034 } |
1942 | 2035 |
1943 } // namespace content | 2036 } // namespace content |
OLD | NEW |