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 11 matching lines...) Expand all Loading... | |
22 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 22 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
23 #include "content/browser/gpu/gpu_surface_tracker.h" | 23 #include "content/browser/gpu/gpu_surface_tracker.h" |
24 #include "content/browser/renderer_host/backing_store.h" | 24 #include "content/browser/renderer_host/backing_store.h" |
25 #include "content/browser/renderer_host/backing_store_manager.h" | 25 #include "content/browser/renderer_host/backing_store_manager.h" |
26 #include "content/browser/renderer_host/gesture_event_filter.h" | 26 #include "content/browser/renderer_host/gesture_event_filter.h" |
27 #include "content/browser/renderer_host/overscroll_controller.h" | 27 #include "content/browser/renderer_host/overscroll_controller.h" |
28 #include "content/browser/renderer_host/render_process_host_impl.h" | 28 #include "content/browser/renderer_host/render_process_host_impl.h" |
29 #include "content/browser/renderer_host/render_view_host_impl.h" | 29 #include "content/browser/renderer_host/render_view_host_impl.h" |
30 #include "content/browser/renderer_host/render_widget_helper.h" | 30 #include "content/browser/renderer_host/render_widget_helper.h" |
31 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 31 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
32 #include "content/browser/renderer_host/smooth_scroll_gesture_controller.h" | |
32 #include "content/browser/renderer_host/tap_suppression_controller.h" | 33 #include "content/browser/renderer_host/tap_suppression_controller.h" |
33 #include "content/browser/renderer_host/touch_event_queue.h" | 34 #include "content/browser/renderer_host/touch_event_queue.h" |
34 #include "content/common/accessibility_messages.h" | 35 #include "content/common/accessibility_messages.h" |
35 #include "content/common/content_constants_internal.h" | 36 #include "content/common/content_constants_internal.h" |
36 #include "content/common/gpu/gpu_messages.h" | 37 #include "content/common/gpu/gpu_messages.h" |
37 #include "content/common/view_messages.h" | 38 #include "content/common/view_messages.h" |
38 #include "content/port/browser/render_widget_host_view_port.h" | 39 #include "content/port/browser/render_widget_host_view_port.h" |
39 #include "content/port/browser/smooth_scroll_gesture.h" | |
40 #include "content/public/browser/compositor_util.h" | 40 #include "content/public/browser/compositor_util.h" |
41 #include "content/public/browser/native_web_keyboard_event.h" | 41 #include "content/public/browser/native_web_keyboard_event.h" |
42 #include "content/public/browser/notification_service.h" | 42 #include "content/public/browser/notification_service.h" |
43 #include "content/public/browser/notification_types.h" | 43 #include "content/public/browser/notification_types.h" |
44 #include "content/public/browser/user_metrics.h" | 44 #include "content/public/browser/user_metrics.h" |
45 #include "content/public/common/content_constants.h" | 45 #include "content/public/common/content_constants.h" |
46 #include "content/public/common/content_switches.h" | 46 #include "content/public/common/content_switches.h" |
47 #include "content/public/common/result_codes.h" | 47 #include "content/public/common/result_codes.h" |
48 #include "skia/ext/image_operations.h" | 48 #include "skia/ext/image_operations.h" |
49 #include "skia/ext/platform_canvas.h" | 49 #include "skia/ext/platform_canvas.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
80 | 80 |
81 namespace content { | 81 namespace content { |
82 namespace { | 82 namespace { |
83 | 83 |
84 // How long to (synchronously) wait for the renderer to respond with a | 84 // How long to (synchronously) wait for the renderer to respond with a |
85 // PaintRect message, when our backing-store is invalid, before giving up and | 85 // PaintRect message, when our backing-store is invalid, before giving up and |
86 // returning a null or incorrectly sized backing-store from GetBackingStore. | 86 // returning a null or incorrectly sized backing-store from GetBackingStore. |
87 // This timeout impacts the "choppiness" of our window resize perf. | 87 // This timeout impacts the "choppiness" of our window resize perf. |
88 const int kPaintMsgTimeoutMS = 50; | 88 const int kPaintMsgTimeoutMS = 50; |
89 | 89 |
90 // How many milliseconds apart synthetic scroll messages should be sent. | |
91 static const int kSyntheticScrollMessageIntervalMs = 8; | |
92 | |
93 // Returns |true| if the two wheel events should be coalesced. | 90 // Returns |true| if the two wheel events should be coalesced. |
94 bool ShouldCoalesceMouseWheelEvents(const WebMouseWheelEvent& last_event, | 91 bool ShouldCoalesceMouseWheelEvents(const WebMouseWheelEvent& last_event, |
95 const WebMouseWheelEvent& new_event) { | 92 const WebMouseWheelEvent& new_event) { |
96 return last_event.modifiers == new_event.modifiers && | 93 return last_event.modifiers == new_event.modifiers && |
97 last_event.scrollByPage == new_event.scrollByPage && | 94 last_event.scrollByPage == new_event.scrollByPage && |
98 last_event.hasPreciseScrollingDeltas | 95 last_event.hasPreciseScrollingDeltas |
99 == new_event.hasPreciseScrollingDeltas && | 96 == new_event.hasPreciseScrollingDeltas && |
100 last_event.phase == new_event.phase && | 97 last_event.phase == new_event.phase && |
101 last_event.momentumPhase == new_event.momentumPhase; | 98 last_event.momentumPhase == new_event.momentumPhase; |
102 } | 99 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 view_being_painted_(false), | 144 view_being_painted_(false), |
148 ignore_input_events_(false), | 145 ignore_input_events_(false), |
149 text_direction_updated_(false), | 146 text_direction_updated_(false), |
150 text_direction_(WebKit::WebTextDirectionLeftToRight), | 147 text_direction_(WebKit::WebTextDirectionLeftToRight), |
151 text_direction_canceled_(false), | 148 text_direction_canceled_(false), |
152 suppress_next_char_events_(false), | 149 suppress_next_char_events_(false), |
153 pending_mouse_lock_request_(false), | 150 pending_mouse_lock_request_(false), |
154 allow_privileged_mouse_lock_(false), | 151 allow_privileged_mouse_lock_(false), |
155 has_touch_handler_(false), | 152 has_touch_handler_(false), |
156 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 153 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
157 tick_active_smooth_scroll_gestures_task_posted_(false), | 154 smooth_scroll_gesture_controller_(new SmoothScrollGestureController()), |
158 touch_event_queue_(new TouchEventQueue(this)), | 155 touch_event_queue_(new TouchEventQueue(this)), |
159 gesture_event_filter_(new GestureEventFilter(this)) { | 156 gesture_event_filter_(new GestureEventFilter(this)) { |
160 CHECK(delegate_); | 157 CHECK(delegate_); |
161 if (routing_id_ == MSG_ROUTING_NONE) { | 158 if (routing_id_ == MSG_ROUTING_NONE) { |
162 routing_id_ = process_->GetNextRoutingID(); | 159 routing_id_ = process_->GetNextRoutingID(); |
163 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( | 160 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( |
164 process_->GetID(), | 161 process_->GetID(), |
165 routing_id_); | 162 routing_id_); |
166 } else { | 163 } else { |
167 // TODO(piman): This is a O(N) lookup, where we could forward the | 164 // TODO(piman): This is a O(N) lookup, where we could forward the |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 if (!view_) | 271 if (!view_) |
275 return; | 272 return; |
276 | 273 |
277 last_view_screen_rect_ = view_->GetViewBounds(); | 274 last_view_screen_rect_ = view_->GetViewBounds(); |
278 last_window_screen_rect_ = view_->GetBoundsInRootWindow(); | 275 last_window_screen_rect_ = view_->GetBoundsInRootWindow(); |
279 Send(new ViewMsg_UpdateScreenRects( | 276 Send(new ViewMsg_UpdateScreenRects( |
280 GetRoutingID(), last_view_screen_rect_, last_window_screen_rect_)); | 277 GetRoutingID(), last_view_screen_rect_, last_window_screen_rect_)); |
281 waiting_for_screen_rects_ack_ = true; | 278 waiting_for_screen_rects_ack_ = true; |
282 } | 279 } |
283 | 280 |
284 int RenderWidgetHostImpl::SyntheticScrollMessageInterval() const { | 281 int RenderWidgetHostImpl::SyntheticScrollMessageInterval() const { |
rjkroege
2013/02/11 22:47:27
who accesses this? perhaps they could speak to the
| |
285 return kSyntheticScrollMessageIntervalMs; | 282 return smooth_scroll_gesture_controller_->SyntheticScrollMessageInterval(); |
286 } | 283 } |
287 | 284 |
288 void RenderWidgetHostImpl::Init() { | 285 void RenderWidgetHostImpl::Init() { |
289 DCHECK(process_->HasConnection()); | 286 DCHECK(process_->HasConnection()); |
290 | 287 |
291 renderer_initialized_ = true; | 288 renderer_initialized_ = true; |
292 | 289 |
293 GpuSurfaceTracker::Get()->SetSurfaceHandle( | 290 GpuSurfaceTracker::Get()->SetSurfaceHandle( |
294 surface_id_, GetCompositingSurface()); | 291 surface_id_, GetCompositingSurface()); |
295 | 292 |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1135 // However, the touch-events are not sent to the renderer. So send and ACK | 1132 // However, the touch-events are not sent to the renderer. So send and ACK |
1136 // to the touch-event queue immediately. Mark the event as not processed, | 1133 // to the touch-event queue immediately. Mark the event as not processed, |
1137 // to make sure that the touch-scroll gesture that initiated the | 1134 // to make sure that the touch-scroll gesture that initiated the |
1138 // overscroll is updated properly. | 1135 // overscroll is updated properly. |
1139 touch_event_queue_->ProcessTouchAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1136 touch_event_queue_->ProcessTouchAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1140 } | 1137 } |
1141 return; | 1138 return; |
1142 } | 1139 } |
1143 | 1140 |
1144 in_process_event_types_.push(input_event.type); | 1141 in_process_event_types_.push(input_event.type); |
1142 smooth_scroll_gesture_controller_->OnForwardInputEvent(); | |
1145 | 1143 |
1146 // Transmit any pending wheel events on a non-wheel event. This ensures that | 1144 // Transmit any pending wheel events on a non-wheel event. This ensures that |
1147 // the renderer receives the final PhaseEnded wheel event, which is necessary | 1145 // the renderer receives the final PhaseEnded wheel event, which is necessary |
1148 // to terminate rubber-banding, for example. | 1146 // to terminate rubber-banding, for example. |
1149 if (input_event.type != WebInputEvent::MouseWheel) { | 1147 if (input_event.type != WebInputEvent::MouseWheel) { |
1150 for (size_t i = 0; i < coalesced_mouse_wheel_events_.size(); ++i) { | 1148 for (size_t i = 0; i < coalesced_mouse_wheel_events_.size(); ++i) { |
1151 SendInputEvent(coalesced_mouse_wheel_events_[i], | 1149 SendInputEvent(coalesced_mouse_wheel_events_[i], |
1152 sizeof(WebMouseWheelEvent), false); | 1150 sizeof(WebMouseWheelEvent), false); |
1153 } | 1151 } |
1154 coalesced_mouse_wheel_events_.clear(); | 1152 coalesced_mouse_wheel_events_.clear(); |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1706 in_process_event_types_.pop(); | 1704 in_process_event_types_.pop(); |
1707 | 1705 |
1708 // Log the time delta for processing an input event. | 1706 // Log the time delta for processing an input event. |
1709 TimeDelta delta = TimeTicks::Now() - input_event_start_time_; | 1707 TimeDelta delta = TimeTicks::Now() - input_event_start_time_; |
1710 UMA_HISTOGRAM_TIMES("MPArch.RWH_InputEventDelta", delta); | 1708 UMA_HISTOGRAM_TIMES("MPArch.RWH_InputEventDelta", delta); |
1711 | 1709 |
1712 // Cancel pending hung renderer checks since the renderer is responsive. | 1710 // Cancel pending hung renderer checks since the renderer is responsive. |
1713 if (decrement_in_flight_event_count() == 0) | 1711 if (decrement_in_flight_event_count() == 0) |
1714 StopHangMonitorTimeout(); | 1712 StopHangMonitorTimeout(); |
1715 | 1713 |
1716 // If an input ack is pending, then hold off ticking the gesture | 1714 smooth_scroll_gesture_controller_->OnInputEventACK(this); |
1717 // until we get an input ack. | |
1718 if (in_process_event_types_.empty() && | |
1719 !active_smooth_scroll_gestures_.empty()) | |
1720 TickActiveSmoothScrollGesture(); | |
1721 | 1715 |
1722 int type = static_cast<int>(event_type); | 1716 int type = static_cast<int>(event_type); |
1723 if (type < WebInputEvent::Undefined) { | 1717 if (type < WebInputEvent::Undefined) { |
1724 RecordAction(UserMetricsAction("BadMessageTerminate_RWH2")); | 1718 RecordAction(UserMetricsAction("BadMessageTerminate_RWH2")); |
1725 process_->ReceivedBadMessage(); | 1719 process_->ReceivedBadMessage(); |
1726 } else if (type == WebInputEvent::MouseMove) { | 1720 } else if (type == WebInputEvent::MouseMove) { |
1727 mouse_move_pending_ = false; | 1721 mouse_move_pending_ = false; |
1728 | 1722 |
1729 // now, we can send the next mouse move event | 1723 // now, we can send the next mouse move event |
1730 if (next_mouse_move_.get()) { | 1724 if (next_mouse_move_.get()) { |
(...skipping 19 matching lines...) Expand all Loading... | |
1750 // (OnInputEventAck) method, but not on other platforms; using | 1744 // (OnInputEventAck) method, but not on other platforms; using |
1751 // 'void' instead is just as safe (since NotificationSource | 1745 // 'void' instead is just as safe (since NotificationSource |
1752 // is not actually typesafe) and avoids this error. | 1746 // is not actually typesafe) and avoids this error. |
1753 NotificationService::current()->Notify( | 1747 NotificationService::current()->Notify( |
1754 NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_INPUT_EVENT_ACK, | 1748 NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_INPUT_EVENT_ACK, |
1755 Source<void>(this), | 1749 Source<void>(this), |
1756 Details<int>(&type)); | 1750 Details<int>(&type)); |
1757 } | 1751 } |
1758 | 1752 |
1759 void RenderWidgetHostImpl::OnBeginSmoothScroll( | 1753 void RenderWidgetHostImpl::OnBeginSmoothScroll( |
1760 int gesture_id, const ViewHostMsg_BeginSmoothScroll_Params ¶ms) { | 1754 int gesture_id, const ViewHostMsg_BeginSmoothScroll_Params& params) { |
1761 if (!view_) | 1755 if (!view_) |
1762 return; | 1756 return; |
1763 active_smooth_scroll_gestures_.insert( | 1757 smooth_scroll_gesture_controller_->OnBeginSmoothScroll( |
1764 std::make_pair(gesture_id, | 1758 view_, gesture_id, params); |
1765 view_->CreateSmoothScrollGesture( | |
1766 params.scroll_down, params.pixels_to_scroll, | |
1767 params.mouse_event_x, params.mouse_event_y))); | |
1768 | |
1769 // If an input ack is pending, then hold off ticking the gesture | |
1770 // until we get an input ack. | |
1771 if (!in_process_event_types_.empty()) | |
1772 return; | |
1773 if (tick_active_smooth_scroll_gestures_task_posted_) | |
1774 return; | |
1775 TickActiveSmoothScrollGesture(); | |
1776 } | |
1777 | |
1778 void RenderWidgetHostImpl::TickActiveSmoothScrollGesture() { | |
1779 TRACE_EVENT0("input", "RenderWidgetHostImpl::TickActiveSmoothScrollGesture"); | |
1780 tick_active_smooth_scroll_gestures_task_posted_ = false; | |
1781 if (active_smooth_scroll_gestures_.empty()) { | |
1782 TRACE_EVENT_INSTANT0("input", "EarlyOut_NoActiveScrollGesture"); | |
1783 return; | |
1784 } | |
1785 | |
1786 base::TimeTicks now = TimeTicks::HighResNow(); | |
1787 base::TimeDelta preferred_interval = | |
1788 base::TimeDelta::FromMilliseconds(kSyntheticScrollMessageIntervalMs); | |
1789 base::TimeDelta time_until_next_ideal_interval = | |
1790 (last_smooth_scroll_gestures_tick_time_ + preferred_interval) - | |
1791 now; | |
1792 if (time_until_next_ideal_interval.InMilliseconds() > 0) { | |
1793 TRACE_EVENT_INSTANT1( | |
1794 "input", "EarlyOut_TickedTooRecently", | |
1795 "delay", time_until_next_ideal_interval.InMilliseconds()); | |
1796 // Post a task. | |
1797 tick_active_smooth_scroll_gestures_task_posted_ = true; | |
1798 MessageLoop::current()->PostDelayedTask( | |
1799 FROM_HERE, | |
1800 base::Bind(&RenderWidgetHostImpl::TickActiveSmoothScrollGesture, | |
1801 weak_factory_.GetWeakPtr()), | |
1802 time_until_next_ideal_interval); | |
1803 return; | |
1804 } | |
1805 | |
1806 last_smooth_scroll_gestures_tick_time_ = now; | |
1807 | |
1808 // Separate ticking of gestures from sending their completion messages. | |
1809 std::vector<int> ids_that_are_done; | |
1810 for (SmoothScrollGestureMap::iterator it = | |
1811 active_smooth_scroll_gestures_.begin(); | |
1812 it != active_smooth_scroll_gestures_.end(); | |
1813 ++it) { | |
1814 | |
1815 bool active = it->second->ForwardInputEvents(now, this); | |
1816 if (!active) | |
1817 ids_that_are_done.push_back(it->first); | |
1818 } | |
1819 | |
1820 // Delete completed gestures and send their completion event. | |
1821 for(size_t i = 0; i < ids_that_are_done.size(); i++) { | |
1822 int id = ids_that_are_done[i]; | |
1823 SmoothScrollGestureMap::iterator it = | |
1824 active_smooth_scroll_gestures_.find(id); | |
1825 DCHECK(it != active_smooth_scroll_gestures_.end()); | |
1826 active_smooth_scroll_gestures_.erase(it); | |
1827 | |
1828 Send(new ViewMsg_SmoothScrollCompleted(routing_id_, id)); | |
1829 } | |
1830 | |
1831 // No need to post the next tick if an input is in flight. | |
1832 if (!in_process_event_types_.empty()) | |
1833 return; | |
1834 | |
1835 TRACE_EVENT_INSTANT1("input", "PostTickTask", | |
1836 "delay", preferred_interval.InMilliseconds()); | |
1837 tick_active_smooth_scroll_gestures_task_posted_ = true; | |
1838 MessageLoop::current()->PostDelayedTask( | |
1839 FROM_HERE, | |
1840 base::Bind(&RenderWidgetHostImpl::TickActiveSmoothScrollGesture, | |
1841 weak_factory_.GetWeakPtr()), | |
1842 preferred_interval); | |
1843 } | 1759 } |
1844 | 1760 |
1845 void RenderWidgetHostImpl::OnSelectRangeAck() { | 1761 void RenderWidgetHostImpl::OnSelectRangeAck() { |
1846 select_range_pending_ = false; | 1762 select_range_pending_ = false; |
1847 if (next_selection_range_.get()) { | 1763 if (next_selection_range_.get()) { |
1848 scoped_ptr<SelectionRange> next(next_selection_range_.Pass()); | 1764 scoped_ptr<SelectionRange> next(next_selection_range_.Pass()); |
1849 SelectRange(next->start, next->end); | 1765 SelectRange(next->start, next->end); |
1850 } | 1766 } |
1851 } | 1767 } |
1852 | 1768 |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2362 return; | 2278 return; |
2363 | 2279 |
2364 OnRenderAutoResized(new_size); | 2280 OnRenderAutoResized(new_size); |
2365 } | 2281 } |
2366 | 2282 |
2367 void RenderWidgetHostImpl::DetachDelegate() { | 2283 void RenderWidgetHostImpl::DetachDelegate() { |
2368 delegate_ = NULL; | 2284 delegate_ = NULL; |
2369 } | 2285 } |
2370 | 2286 |
2371 } // namespace content | 2287 } // namespace content |
OLD | NEW |