Chromium Code Reviews| 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 timeStampSeconds, | |
| 753 int x, | |
| 754 int y, | |
| 755 float deltaX, | |
| 756 float deltaY, | |
| 757 int modifiers) | |
| 758 { | |
|
jam
2012/08/06 18:33:21
nit: this function is using webkit style, please c
aelias_OOO_until_Jul13
2012/08/06 18:46:30
Done. By the way, is there a style checker tool I
| |
| 759 WebGestureEvent result; | |
| 760 | |
| 761 result.type = type; | |
| 762 result.x = x; | |
| 763 result.y = y; | |
| 764 result.deltaX = deltaX; | |
| 765 result.deltaY = deltaY; | |
| 766 result.timeStampSeconds = timeStampSeconds; | |
| 767 result.modifiers = modifiers; | |
| 768 | |
| 769 return result; | |
| 770 } | |
| 771 | |
| 772 void RenderWidgetHostImpl::SimulateTouchGestureWithMouse( | |
| 773 const WebMouseEvent& mouse_event) { | |
| 774 int x = mouse_event.x, y = mouse_event.y; | |
| 775 float dx = mouse_event.movementX, dy = mouse_event.movementY; | |
| 776 static int startX = 0, startY = 0; | |
| 777 | |
| 778 switch (mouse_event.button) { | |
| 779 case WebMouseEvent::ButtonLeft: | |
| 780 if (mouse_event.type == WebInputEvent::MouseDown) { | |
| 781 startX = x; | |
| 782 startY = y; | |
| 783 ForwardGestureEvent(makeGestureEvent( | |
| 784 WebInputEvent::GestureScrollBegin, mouse_event.timeStampSeconds, | |
| 785 x, y, 0, 0, 0)); | |
| 786 } | |
| 787 if (dx != 0 || dy != 0) { | |
| 788 ForwardGestureEvent(makeGestureEvent( | |
| 789 WebInputEvent::GestureScrollUpdate, mouse_event.timeStampSeconds, | |
| 790 x, y, dx, dy, 0)); | |
| 791 } | |
| 792 if (mouse_event.type == WebInputEvent::MouseUp) { | |
| 793 ForwardGestureEvent(makeGestureEvent( | |
| 794 WebInputEvent::GestureScrollEnd, mouse_event.timeStampSeconds, | |
| 795 x, y, dx, dy, 0)); | |
| 796 } | |
| 797 break; | |
| 798 case WebMouseEvent::ButtonMiddle: | |
| 799 if (mouse_event.type == WebInputEvent::MouseDown) { | |
| 800 startX = x; | |
| 801 startY = y; | |
| 802 ForwardGestureEvent(makeGestureEvent( | |
| 803 WebInputEvent::GestureTapDown, mouse_event.timeStampSeconds, | |
| 804 x, y, 0, 0, 0)); | |
| 805 } | |
| 806 if (mouse_event.type == WebInputEvent::MouseUp) { | |
| 807 ForwardGestureEvent(makeGestureEvent( | |
| 808 WebInputEvent::GestureTap, mouse_event.timeStampSeconds, | |
| 809 x, y, dx, dy, 0)); | |
| 810 } | |
| 811 break; | |
| 812 case WebMouseEvent::ButtonRight: | |
| 813 if (mouse_event.type == WebInputEvent::MouseDown) { | |
| 814 startX = x; | |
| 815 startY = y; | |
| 816 ForwardGestureEvent(makeGestureEvent( | |
| 817 WebInputEvent::GesturePinchBegin, mouse_event.timeStampSeconds, | |
| 818 x, y, 1, 1, 0)); | |
| 819 } | |
| 820 if (dx != 0 || dy != 0) { | |
| 821 dx = pow(dy < 0 ? 0.998 : 1.002, abs(dy)); | |
| 822 dy = dx; | |
| 823 ForwardGestureEvent(makeGestureEvent( | |
| 824 WebInputEvent::GesturePinchUpdate, mouse_event.timeStampSeconds, | |
| 825 startX, startY, dx, dy, 0)); | |
| 826 } | |
| 827 if (mouse_event.type == WebInputEvent::MouseUp) { | |
| 828 ForwardGestureEvent(makeGestureEvent( | |
| 829 WebInputEvent::GesturePinchEnd, mouse_event.timeStampSeconds, | |
| 830 x, y, dx, dy, 0)); | |
| 831 } | |
| 832 break; | |
| 833 case WebMouseEvent::ButtonNone: | |
| 834 break; | |
| 835 } | |
| 836 } | |
| 837 | |
| 750 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { | 838 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { |
| 751 TRACE_EVENT2("renderer_host", "RenderWidgetHostImpl::ForwardMouseEvent", | 839 TRACE_EVENT2("renderer_host", "RenderWidgetHostImpl::ForwardMouseEvent", |
| 752 "x", mouse_event.x, "y", mouse_event.y); | 840 "x", mouse_event.x, "y", mouse_event.y); |
| 753 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 841 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 754 return; | 842 return; |
| 755 | 843 |
| 844 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 845 switches::kSimulateTouchScreenWithMouse)) { | |
| 846 SimulateTouchGestureWithMouse(mouse_event); | |
| 847 return; | |
| 848 } | |
| 849 | |
| 756 // Avoid spamming the renderer with mouse move events. It is important | 850 // Avoid spamming the renderer with mouse move events. It is important |
| 757 // to note that WM_MOUSEMOVE events are anyways synthetic, but since our | 851 // 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 | 852 // 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. | 853 // more WM_MOUSEMOVE events than we wish to send to the renderer. |
| 760 if (mouse_event.type == WebInputEvent::MouseMove) { | 854 if (mouse_event.type == WebInputEvent::MouseMove) { |
| 761 if (mouse_move_pending_) { | 855 if (mouse_move_pending_) { |
| 762 if (!next_mouse_move_.get()) { | 856 if (!next_mouse_move_.get()) { |
| 763 next_mouse_move_.reset(new WebMouseEvent(mouse_event)); | 857 next_mouse_move_.reset(new WebMouseEvent(mouse_event)); |
| 764 } else { | 858 } else { |
| 765 // Accumulate movement deltas. | 859 // 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 | 2028 // indicate that no callback is in progress (i.e. without this line |
| 1935 // DelayedAutoResized will not get called again). | 2029 // DelayedAutoResized will not get called again). |
| 1936 new_auto_size_.SetSize(0, 0); | 2030 new_auto_size_.SetSize(0, 0); |
| 1937 if (!should_auto_resize_) | 2031 if (!should_auto_resize_) |
| 1938 return; | 2032 return; |
| 1939 | 2033 |
| 1940 OnRenderAutoResized(new_size); | 2034 OnRenderAutoResized(new_size); |
| 1941 } | 2035 } |
| 1942 | 2036 |
| 1943 } // namespace content | 2037 } // namespace content |
| OLD | NEW |