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 <math.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "content/browser/gpu/gpu_surface_tracker.h" | 25 #include "content/browser/gpu/gpu_surface_tracker.h" |
26 #include "content/browser/renderer_host/backing_store.h" | 26 #include "content/browser/renderer_host/backing_store.h" |
27 #include "content/browser/renderer_host/backing_store_manager.h" | 27 #include "content/browser/renderer_host/backing_store_manager.h" |
28 #include "content/browser/renderer_host/dip_util.h" | 28 #include "content/browser/renderer_host/dip_util.h" |
29 #include "content/browser/renderer_host/gesture_event_filter.h" | 29 #include "content/browser/renderer_host/gesture_event_filter.h" |
30 #include "content/browser/renderer_host/overscroll_controller.h" | 30 #include "content/browser/renderer_host/overscroll_controller.h" |
31 #include "content/browser/renderer_host/render_process_host_impl.h" | 31 #include "content/browser/renderer_host/render_process_host_impl.h" |
32 #include "content/browser/renderer_host/render_view_host_impl.h" | 32 #include "content/browser/renderer_host/render_view_host_impl.h" |
33 #include "content/browser/renderer_host/render_widget_helper.h" | 33 #include "content/browser/renderer_host/render_widget_helper.h" |
34 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 34 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 35 #include "content/browser/renderer_host/smooth_scroll_gesture_controller.h" |
35 #include "content/browser/renderer_host/touch_event_queue.h" | 36 #include "content/browser/renderer_host/touch_event_queue.h" |
36 #include "content/browser/renderer_host/touchpad_tap_suppression_controller.h" | 37 #include "content/browser/renderer_host/touchpad_tap_suppression_controller.h" |
37 #include "content/common/accessibility_messages.h" | 38 #include "content/common/accessibility_messages.h" |
38 #include "content/common/content_constants_internal.h" | 39 #include "content/common/content_constants_internal.h" |
39 #include "content/common/gpu/gpu_messages.h" | 40 #include "content/common/gpu/gpu_messages.h" |
40 #include "content/common/view_messages.h" | 41 #include "content/common/view_messages.h" |
41 #include "content/port/browser/render_widget_host_view_port.h" | 42 #include "content/port/browser/render_widget_host_view_port.h" |
42 #include "content/port/browser/smooth_scroll_gesture.h" | |
43 #include "content/public/browser/compositor_util.h" | 43 #include "content/public/browser/compositor_util.h" |
44 #include "content/public/browser/native_web_keyboard_event.h" | 44 #include "content/public/browser/native_web_keyboard_event.h" |
45 #include "content/public/browser/notification_service.h" | 45 #include "content/public/browser/notification_service.h" |
46 #include "content/public/browser/notification_types.h" | 46 #include "content/public/browser/notification_types.h" |
47 #include "content/public/browser/user_metrics.h" | 47 #include "content/public/browser/user_metrics.h" |
48 #include "content/public/common/content_constants.h" | 48 #include "content/public/common/content_constants.h" |
49 #include "content/public/common/content_switches.h" | 49 #include "content/public/common/content_switches.h" |
50 #include "content/public/common/result_codes.h" | 50 #include "content/public/common/result_codes.h" |
51 #include "skia/ext/image_operations.h" | 51 #include "skia/ext/image_operations.h" |
52 #include "skia/ext/platform_canvas.h" | 52 #include "skia/ext/platform_canvas.h" |
(...skipping 30 matching lines...) Expand all Loading... |
83 | 83 |
84 namespace content { | 84 namespace content { |
85 namespace { | 85 namespace { |
86 | 86 |
87 // How long to (synchronously) wait for the renderer to respond with a | 87 // How long to (synchronously) wait for the renderer to respond with a |
88 // PaintRect message, when our backing-store is invalid, before giving up and | 88 // PaintRect message, when our backing-store is invalid, before giving up and |
89 // returning a null or incorrectly sized backing-store from GetBackingStore. | 89 // returning a null or incorrectly sized backing-store from GetBackingStore. |
90 // This timeout impacts the "choppiness" of our window resize perf. | 90 // This timeout impacts the "choppiness" of our window resize perf. |
91 const int kPaintMsgTimeoutMS = 50; | 91 const int kPaintMsgTimeoutMS = 50; |
92 | 92 |
93 // How many milliseconds apart synthetic scroll messages should be sent. | |
94 static const int kSyntheticScrollMessageIntervalMs = 8; | |
95 | |
96 // Returns |true| if the two wheel events should be coalesced. | 93 // Returns |true| if the two wheel events should be coalesced. |
97 bool ShouldCoalesceMouseWheelEvents(const WebMouseWheelEvent& last_event, | 94 bool ShouldCoalesceMouseWheelEvents(const WebMouseWheelEvent& last_event, |
98 const WebMouseWheelEvent& new_event) { | 95 const WebMouseWheelEvent& new_event) { |
99 return last_event.modifiers == new_event.modifiers && | 96 return last_event.modifiers == new_event.modifiers && |
100 last_event.scrollByPage == new_event.scrollByPage && | 97 last_event.scrollByPage == new_event.scrollByPage && |
101 last_event.hasPreciseScrollingDeltas | 98 last_event.hasPreciseScrollingDeltas |
102 == new_event.hasPreciseScrollingDeltas && | 99 == new_event.hasPreciseScrollingDeltas && |
103 last_event.phase == new_event.phase && | 100 last_event.phase == new_event.phase && |
104 last_event.momentumPhase == new_event.momentumPhase; | 101 last_event.momentumPhase == new_event.momentumPhase; |
105 } | 102 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 view_being_painted_(false), | 159 view_being_painted_(false), |
163 ignore_input_events_(false), | 160 ignore_input_events_(false), |
164 text_direction_updated_(false), | 161 text_direction_updated_(false), |
165 text_direction_(WebKit::WebTextDirectionLeftToRight), | 162 text_direction_(WebKit::WebTextDirectionLeftToRight), |
166 text_direction_canceled_(false), | 163 text_direction_canceled_(false), |
167 suppress_next_char_events_(false), | 164 suppress_next_char_events_(false), |
168 pending_mouse_lock_request_(false), | 165 pending_mouse_lock_request_(false), |
169 allow_privileged_mouse_lock_(false), | 166 allow_privileged_mouse_lock_(false), |
170 has_touch_handler_(false), | 167 has_touch_handler_(false), |
171 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 168 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
172 tick_active_smooth_scroll_gestures_task_posted_(false), | 169 smooth_scroll_gesture_controller_(new SmoothScrollGestureController()), |
173 touch_event_queue_(new TouchEventQueue(this)), | 170 touch_event_queue_(new TouchEventQueue(this)), |
174 gesture_event_filter_(new GestureEventFilter(this)) { | 171 gesture_event_filter_(new GestureEventFilter(this)) { |
175 CHECK(delegate_); | 172 CHECK(delegate_); |
176 if (routing_id_ == MSG_ROUTING_NONE) { | 173 if (routing_id_ == MSG_ROUTING_NONE) { |
177 routing_id_ = process_->GetNextRoutingID(); | 174 routing_id_ = process_->GetNextRoutingID(); |
178 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( | 175 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( |
179 process_->GetID(), | 176 process_->GetID(), |
180 routing_id_); | 177 routing_id_); |
181 } else { | 178 } else { |
182 // TODO(piman): This is a O(N) lookup, where we could forward the | 179 // TODO(piman): This is a O(N) lookup, where we could forward the |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 return; | 289 return; |
293 | 290 |
294 last_view_screen_rect_ = view_->GetViewBounds(); | 291 last_view_screen_rect_ = view_->GetViewBounds(); |
295 last_window_screen_rect_ = view_->GetBoundsInRootWindow(); | 292 last_window_screen_rect_ = view_->GetBoundsInRootWindow(); |
296 Send(new ViewMsg_UpdateScreenRects( | 293 Send(new ViewMsg_UpdateScreenRects( |
297 GetRoutingID(), last_view_screen_rect_, last_window_screen_rect_)); | 294 GetRoutingID(), last_view_screen_rect_, last_window_screen_rect_)); |
298 waiting_for_screen_rects_ack_ = true; | 295 waiting_for_screen_rects_ack_ = true; |
299 } | 296 } |
300 | 297 |
301 int RenderWidgetHostImpl::SyntheticScrollMessageInterval() const { | 298 int RenderWidgetHostImpl::SyntheticScrollMessageInterval() const { |
302 return kSyntheticScrollMessageIntervalMs; | 299 return smooth_scroll_gesture_controller_->SyntheticScrollMessageInterval(); |
303 } | 300 } |
304 | 301 |
305 void RenderWidgetHostImpl::SetOverscrollControllerEnabled(bool enabled) { | 302 void RenderWidgetHostImpl::SetOverscrollControllerEnabled(bool enabled) { |
306 if (!enabled) | 303 if (!enabled) |
307 overscroll_controller_.reset(); | 304 overscroll_controller_.reset(); |
308 else if (!overscroll_controller_.get()) | 305 else if (!overscroll_controller_.get()) |
309 overscroll_controller_.reset(new OverscrollController(this)); | 306 overscroll_controller_.reset(new OverscrollController(this)); |
310 } | 307 } |
311 | 308 |
312 void RenderWidgetHostImpl::SuppressNextCharEvents() { | 309 void RenderWidgetHostImpl::SuppressNextCharEvents() { |
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1134 // Only forward the non-native portions of our event. | 1131 // Only forward the non-native portions of our event. |
1135 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent), | 1132 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent), |
1136 is_keyboard_shortcut); | 1133 is_keyboard_shortcut); |
1137 } | 1134 } |
1138 } | 1135 } |
1139 | 1136 |
1140 void RenderWidgetHostImpl::SendInputEvent(const WebInputEvent& input_event, | 1137 void RenderWidgetHostImpl::SendInputEvent(const WebInputEvent& input_event, |
1141 int event_size, | 1138 int event_size, |
1142 bool is_keyboard_shortcut) { | 1139 bool is_keyboard_shortcut) { |
1143 input_event_start_time_ = TimeTicks::Now(); | 1140 input_event_start_time_ = TimeTicks::Now(); |
| 1141 in_process_event_types_.push(input_event.type); |
| 1142 smooth_scroll_gesture_controller_->OnForwardInputEvent(); |
1144 Send(new ViewMsg_HandleInputEvent( | 1143 Send(new ViewMsg_HandleInputEvent( |
1145 routing_id_, &input_event, is_keyboard_shortcut)); | 1144 routing_id_, &input_event, is_keyboard_shortcut)); |
1146 increment_in_flight_event_count(); | 1145 increment_in_flight_event_count(); |
1147 } | 1146 } |
1148 | 1147 |
1149 void RenderWidgetHostImpl::ForwardInputEvent(const WebInputEvent& input_event, | 1148 void RenderWidgetHostImpl::ForwardInputEvent(const WebInputEvent& input_event, |
1150 int event_size, | 1149 int event_size, |
1151 bool is_keyboard_shortcut) { | 1150 bool is_keyboard_shortcut) { |
1152 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardInputEvent"); | 1151 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardInputEvent"); |
1153 | 1152 |
(...skipping 20 matching lines...) Expand all Loading... |
1174 // touch-events do not reset or contribute to the overscroll gesture. | 1173 // touch-events do not reset or contribute to the overscroll gesture. |
1175 // However, the touch-events are not sent to the renderer. So send and ACK | 1174 // However, the touch-events are not sent to the renderer. So send and ACK |
1176 // to the touch-event queue immediately. Mark the event as not processed, | 1175 // to the touch-event queue immediately. Mark the event as not processed, |
1177 // to make sure that the touch-scroll gesture that initiated the | 1176 // to make sure that the touch-scroll gesture that initiated the |
1178 // overscroll is updated properly. | 1177 // overscroll is updated properly. |
1179 touch_event_queue_->ProcessTouchAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1178 touch_event_queue_->ProcessTouchAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1180 } | 1179 } |
1181 return; | 1180 return; |
1182 } | 1181 } |
1183 | 1182 |
1184 in_process_event_types_.push(input_event.type); | |
1185 | |
1186 // Transmit any pending wheel events on a non-wheel event. This ensures that | 1183 // Transmit any pending wheel events on a non-wheel event. This ensures that |
1187 // the renderer receives the final PhaseEnded wheel event, which is necessary | 1184 // the renderer receives the final PhaseEnded wheel event, which is necessary |
1188 // to terminate rubber-banding, for example. | 1185 // to terminate rubber-banding, for example. |
1189 if (input_event.type != WebInputEvent::MouseWheel) { | 1186 if (input_event.type != WebInputEvent::MouseWheel) { |
1190 for (size_t i = 0; i < coalesced_mouse_wheel_events_.size(); ++i) { | 1187 for (size_t i = 0; i < coalesced_mouse_wheel_events_.size(); ++i) { |
1191 SendInputEvent(coalesced_mouse_wheel_events_[i], | 1188 SendInputEvent(coalesced_mouse_wheel_events_[i], |
1192 sizeof(WebMouseWheelEvent), false); | 1189 sizeof(WebMouseWheelEvent), false); |
1193 } | 1190 } |
1194 coalesced_mouse_wheel_events_.clear(); | 1191 coalesced_mouse_wheel_events_.clear(); |
1195 } | 1192 } |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1805 in_process_event_types_.pop(); | 1802 in_process_event_types_.pop(); |
1806 | 1803 |
1807 // Log the time delta for processing an input event. | 1804 // Log the time delta for processing an input event. |
1808 TimeDelta delta = TimeTicks::Now() - input_event_start_time_; | 1805 TimeDelta delta = TimeTicks::Now() - input_event_start_time_; |
1809 UMA_HISTOGRAM_TIMES("MPArch.RWH_InputEventDelta", delta); | 1806 UMA_HISTOGRAM_TIMES("MPArch.RWH_InputEventDelta", delta); |
1810 | 1807 |
1811 // Cancel pending hung renderer checks since the renderer is responsive. | 1808 // Cancel pending hung renderer checks since the renderer is responsive. |
1812 if (decrement_in_flight_event_count() == 0) | 1809 if (decrement_in_flight_event_count() == 0) |
1813 StopHangMonitorTimeout(); | 1810 StopHangMonitorTimeout(); |
1814 | 1811 |
1815 // If an input ack is pending, then hold off ticking the gesture | 1812 smooth_scroll_gesture_controller_->OnInputEventACK(this); |
1816 // until we get an input ack. | |
1817 if (in_process_event_types_.empty() && | |
1818 !active_smooth_scroll_gestures_.empty()) | |
1819 TickActiveSmoothScrollGesture(); | |
1820 | 1813 |
1821 int type = static_cast<int>(event_type); | 1814 int type = static_cast<int>(event_type); |
1822 if (type < WebInputEvent::Undefined) { | 1815 if (type < WebInputEvent::Undefined) { |
1823 RecordAction(UserMetricsAction("BadMessageTerminate_RWH2")); | 1816 RecordAction(UserMetricsAction("BadMessageTerminate_RWH2")); |
1824 process_->ReceivedBadMessage(); | 1817 process_->ReceivedBadMessage(); |
1825 } else if (type == WebInputEvent::MouseMove) { | 1818 } else if (type == WebInputEvent::MouseMove) { |
1826 mouse_move_pending_ = false; | 1819 mouse_move_pending_ = false; |
1827 | 1820 |
1828 // now, we can send the next mouse move event | 1821 // now, we can send the next mouse move event |
1829 if (next_mouse_move_.get()) { | 1822 if (next_mouse_move_.get()) { |
(...skipping 19 matching lines...) Expand all Loading... |
1849 // (OnInputEventAck) method, but not on other platforms; using | 1842 // (OnInputEventAck) method, but not on other platforms; using |
1850 // 'void' instead is just as safe (since NotificationSource | 1843 // 'void' instead is just as safe (since NotificationSource |
1851 // is not actually typesafe) and avoids this error. | 1844 // is not actually typesafe) and avoids this error. |
1852 NotificationService::current()->Notify( | 1845 NotificationService::current()->Notify( |
1853 NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_INPUT_EVENT_ACK, | 1846 NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_INPUT_EVENT_ACK, |
1854 Source<void>(this), | 1847 Source<void>(this), |
1855 Details<int>(&type)); | 1848 Details<int>(&type)); |
1856 } | 1849 } |
1857 | 1850 |
1858 void RenderWidgetHostImpl::OnBeginSmoothScroll( | 1851 void RenderWidgetHostImpl::OnBeginSmoothScroll( |
1859 int gesture_id, const ViewHostMsg_BeginSmoothScroll_Params ¶ms) { | 1852 const ViewHostMsg_BeginSmoothScroll_Params& params, |
| 1853 bool* smooth_scroll_started) { |
1860 if (!view_) | 1854 if (!view_) |
1861 return; | 1855 return; |
1862 active_smooth_scroll_gestures_.insert( | 1856 *smooth_scroll_started = |
1863 std::make_pair(gesture_id, | 1857 smooth_scroll_gesture_controller_->OnBeginSmoothScroll(view_, params); |
1864 view_->CreateSmoothScrollGesture( | |
1865 params.scroll_down, params.pixels_to_scroll, | |
1866 params.mouse_event_x, params.mouse_event_y))); | |
1867 | 1858 |
1868 // If an input ack is pending, then hold off ticking the gesture | |
1869 // until we get an input ack. | |
1870 if (!in_process_event_types_.empty()) | |
1871 return; | |
1872 if (tick_active_smooth_scroll_gestures_task_posted_) | |
1873 return; | |
1874 TickActiveSmoothScrollGesture(); | |
1875 } | |
1876 | |
1877 void RenderWidgetHostImpl::TickActiveSmoothScrollGesture() { | |
1878 TRACE_EVENT0("input", "RenderWidgetHostImpl::TickActiveSmoothScrollGesture"); | |
1879 tick_active_smooth_scroll_gestures_task_posted_ = false; | |
1880 if (active_smooth_scroll_gestures_.empty()) { | |
1881 TRACE_EVENT_INSTANT0("input", "EarlyOut_NoActiveScrollGesture", | |
1882 TRACE_EVENT_SCOPE_THREAD); | |
1883 return; | |
1884 } | |
1885 | |
1886 base::TimeTicks now = TimeTicks::HighResNow(); | |
1887 base::TimeDelta preferred_interval = | |
1888 base::TimeDelta::FromMilliseconds(kSyntheticScrollMessageIntervalMs); | |
1889 base::TimeDelta time_until_next_ideal_interval = | |
1890 (last_smooth_scroll_gestures_tick_time_ + preferred_interval) - | |
1891 now; | |
1892 if (time_until_next_ideal_interval.InMilliseconds() > 0) { | |
1893 TRACE_EVENT_INSTANT1( | |
1894 "input", "EarlyOut_TickedTooRecently", TRACE_EVENT_SCOPE_THREAD, | |
1895 "delay", time_until_next_ideal_interval.InMilliseconds()); | |
1896 // Post a task. | |
1897 tick_active_smooth_scroll_gestures_task_posted_ = true; | |
1898 MessageLoop::current()->PostDelayedTask( | |
1899 FROM_HERE, | |
1900 base::Bind(&RenderWidgetHostImpl::TickActiveSmoothScrollGesture, | |
1901 weak_factory_.GetWeakPtr()), | |
1902 time_until_next_ideal_interval); | |
1903 return; | |
1904 } | |
1905 | |
1906 last_smooth_scroll_gestures_tick_time_ = now; | |
1907 | |
1908 // Separate ticking of gestures from sending their completion messages. | |
1909 std::vector<int> ids_that_are_done; | |
1910 for (SmoothScrollGestureMap::iterator it = | |
1911 active_smooth_scroll_gestures_.begin(); | |
1912 it != active_smooth_scroll_gestures_.end(); | |
1913 ++it) { | |
1914 | |
1915 bool active = it->second->ForwardInputEvents(now, this); | |
1916 if (!active) | |
1917 ids_that_are_done.push_back(it->first); | |
1918 } | |
1919 | |
1920 // Delete completed gestures and send their completion event. | |
1921 for(size_t i = 0; i < ids_that_are_done.size(); i++) { | |
1922 int id = ids_that_are_done[i]; | |
1923 SmoothScrollGestureMap::iterator it = | |
1924 active_smooth_scroll_gestures_.find(id); | |
1925 DCHECK(it != active_smooth_scroll_gestures_.end()); | |
1926 active_smooth_scroll_gestures_.erase(it); | |
1927 | |
1928 Send(new ViewMsg_SmoothScrollCompleted(routing_id_, id)); | |
1929 } | |
1930 | |
1931 // No need to post the next tick if an input is in flight. | |
1932 if (!in_process_event_types_.empty()) | |
1933 return; | |
1934 | |
1935 TRACE_EVENT_INSTANT1("input", "PostTickTask", TRACE_EVENT_SCOPE_THREAD, | |
1936 "delay", preferred_interval.InMilliseconds()); | |
1937 tick_active_smooth_scroll_gestures_task_posted_ = true; | |
1938 MessageLoop::current()->PostDelayedTask( | |
1939 FROM_HERE, | |
1940 base::Bind(&RenderWidgetHostImpl::TickActiveSmoothScrollGesture, | |
1941 weak_factory_.GetWeakPtr()), | |
1942 preferred_interval); | |
1943 } | 1859 } |
1944 | 1860 |
1945 void RenderWidgetHostImpl::OnSelectRangeAck() { | 1861 void RenderWidgetHostImpl::OnSelectRangeAck() { |
1946 select_range_pending_ = false; | 1862 select_range_pending_ = false; |
1947 if (next_selection_range_.get()) { | 1863 if (next_selection_range_.get()) { |
1948 scoped_ptr<SelectionRange> next(next_selection_range_.Pass()); | 1864 scoped_ptr<SelectionRange> next(next_selection_range_.Pass()); |
1949 SelectRange(next->start, next->end); | 1865 SelectRange(next->start, next->end); |
1950 } | 1866 } |
1951 } | 1867 } |
1952 | 1868 |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2469 return; | 2385 return; |
2470 | 2386 |
2471 OnRenderAutoResized(new_size); | 2387 OnRenderAutoResized(new_size); |
2472 } | 2388 } |
2473 | 2389 |
2474 void RenderWidgetHostImpl::DetachDelegate() { | 2390 void RenderWidgetHostImpl::DetachDelegate() { |
2475 delegate_ = NULL; | 2391 delegate_ = NULL; |
2476 } | 2392 } |
2477 | 2393 |
2478 } // namespace content | 2394 } // namespace content |
OLD | NEW |