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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 view_being_painted_(false), | 140 view_being_painted_(false), |
141 ignore_input_events_(false), | 141 ignore_input_events_(false), |
142 text_direction_updated_(false), | 142 text_direction_updated_(false), |
143 text_direction_(WebKit::WebTextDirectionLeftToRight), | 143 text_direction_(WebKit::WebTextDirectionLeftToRight), |
144 text_direction_canceled_(false), | 144 text_direction_canceled_(false), |
145 suppress_next_char_events_(false), | 145 suppress_next_char_events_(false), |
146 pending_mouse_lock_request_(false), | 146 pending_mouse_lock_request_(false), |
147 allow_privileged_mouse_lock_(false), | 147 allow_privileged_mouse_lock_(false), |
148 has_touch_handler_(false), | 148 has_touch_handler_(false), |
149 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 149 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
150 tick_active_smooth_scroll_gestures_task_posted_(false), | |
150 gesture_event_filter_(new GestureEventFilter(this)) { | 151 gesture_event_filter_(new GestureEventFilter(this)) { |
151 CHECK(delegate_); | 152 CHECK(delegate_); |
152 if (routing_id_ == MSG_ROUTING_NONE) { | 153 if (routing_id_ == MSG_ROUTING_NONE) { |
153 routing_id_ = process_->GetNextRoutingID(); | 154 routing_id_ = process_->GetNextRoutingID(); |
154 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( | 155 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( |
155 process_->GetID(), | 156 process_->GetID(), |
156 routing_id_); | 157 routing_id_); |
157 } else { | 158 } else { |
158 // TODO(piman): This is a O(N) lookup, where we could forward the | 159 // TODO(piman): This is a O(N) lookup, where we could forward the |
159 // information from the RenderWidgetHelper. The problem is that doing so | 160 // information from the RenderWidgetHelper. The problem is that doing so |
(...skipping 1425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1585 } else if (WebInputEvent::isKeyboardEventType(type)) { | 1586 } else if (WebInputEvent::isKeyboardEventType(type)) { |
1586 ProcessKeyboardEventAck(type, processed); | 1587 ProcessKeyboardEventAck(type, processed); |
1587 } else if (type == WebInputEvent::MouseWheel) { | 1588 } else if (type == WebInputEvent::MouseWheel) { |
1588 ProcessWheelAck(processed); | 1589 ProcessWheelAck(processed); |
1589 } else if (WebInputEvent::isTouchEventType(type)) { | 1590 } else if (WebInputEvent::isTouchEventType(type)) { |
1590 ProcessTouchAck(event_type, processed); | 1591 ProcessTouchAck(event_type, processed); |
1591 } else if (WebInputEvent::isGestureEventType(type)) { | 1592 } else if (WebInputEvent::isGestureEventType(type)) { |
1592 ProcessGestureAck(processed, type); | 1593 ProcessGestureAck(processed, type); |
1593 } | 1594 } |
1594 | 1595 |
1596 // If an input ack is pending, then hold off ticking the gesture | |
1597 // until we get an input ack. | |
1598 if (in_process_event_types_.size() == 0 && | |
1599 active_smooth_scroll_gestures_.size()) | |
piman
2012/10/06 06:18:57
nit: ! .empty() instead of .size()
| |
1600 TickActiveSmoothScrollGesture(); | |
1601 | |
1595 // This is used only for testing, and the other end does not use the | 1602 // This is used only for testing, and the other end does not use the |
1596 // source object. On linux, specifying | 1603 // source object. On linux, specifying |
1597 // Source<RenderWidgetHost> results in a very strange | 1604 // Source<RenderWidgetHost> results in a very strange |
1598 // runtime error in the epilogue of the enclosing | 1605 // runtime error in the epilogue of the enclosing |
1599 // (OnMsgInputEventAck) method, but not on other platforms; using | 1606 // (OnMsgInputEventAck) method, but not on other platforms; using |
1600 // 'void' instead is just as safe (since NotificationSource | 1607 // 'void' instead is just as safe (since NotificationSource |
1601 // is not actually typesafe) and avoids this error. | 1608 // is not actually typesafe) and avoids this error. |
1602 NotificationService::current()->Notify( | 1609 NotificationService::current()->Notify( |
1603 NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_INPUT_EVENT_ACK, | 1610 NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_INPUT_EVENT_ACK, |
1604 Source<void>(this), | 1611 Source<void>(this), |
1605 Details<int>(&type)); | 1612 Details<int>(&type)); |
1606 } | 1613 } |
1607 | 1614 |
1608 void RenderWidgetHostImpl::OnMsgBeginSmoothScroll( | 1615 void RenderWidgetHostImpl::OnMsgBeginSmoothScroll( |
1609 int gesture_id, bool scroll_down, bool scroll_far) { | 1616 int gesture_id, bool scroll_down, bool scroll_far) { |
1610 if (!view_) | 1617 if (!view_) |
1611 return; | 1618 return; |
1612 active_smooth_scroll_gestures_.insert( | 1619 active_smooth_scroll_gestures_.insert( |
1613 std::make_pair(gesture_id, | 1620 std::make_pair(gesture_id, |
1614 view_->CreateSmoothScrollGesture( | 1621 view_->CreateSmoothScrollGesture( |
1615 scroll_down, scroll_far))); | 1622 scroll_down, scroll_far))); |
1623 | |
1624 // If an input ack is pending, then hold off ticking the gesture | |
1625 // until we get an input ack. | |
1626 if (in_process_event_types_.size()) | |
piman
2012/10/06 06:18:57
nit: ! .empty()
| |
1627 return; | |
1628 if (tick_active_smooth_scroll_gestures_task_posted_) | |
1629 return; | |
1616 TickActiveSmoothScrollGesture(); | 1630 TickActiveSmoothScrollGesture(); |
1617 } | 1631 } |
1618 | 1632 |
1619 void RenderWidgetHostImpl::TickActiveSmoothScrollGesture() { | 1633 void RenderWidgetHostImpl::TickActiveSmoothScrollGesture() { |
1620 if (active_smooth_scroll_gestures_.size() == 0) | 1634 TRACE_EVENT0("input", "RenderWidgetHostImpl::TickActiveSmoothScrollGesture"); |
1635 tick_active_smooth_scroll_gestures_task_posted_ = false; | |
1636 if (active_smooth_scroll_gestures_.size() == 0) { | |
piman
2012/10/06 06:18:57
nit: empty()
| |
1637 TRACE_EVENT_INSTANT0("input", "EarlyOut_NoActiveScrollGesture"); | |
1621 return; | 1638 return; |
1639 } | |
1622 | 1640 |
1623 TimeTicks now = TimeTicks::HighResNow(); | 1641 base::TimeTicks now = TimeTicks::HighResNow(); |
1642 base::TimeDelta preferred_interval = | |
1643 base::TimeDelta::FromMilliseconds(kSyntheticScrollMessageIntervalMs); | |
piman
2012/10/06 06:18:57
nit: line continuations at +4
| |
1644 base::TimeDelta time_until_next_ideal_interval = | |
1645 (last_smooth_scroll_gestures_tick_time_ + preferred_interval) - | |
piman
2012/10/06 06:18:57
+4
| |
1646 now; | |
1647 if (time_until_next_ideal_interval.InMilliseconds() > 0) { | |
1648 TRACE_EVENT_INSTANT1( | |
1649 "input", "EarlyOut_TickedTooRecently", | |
1650 "delay", time_until_next_ideal_interval.InMilliseconds()); | |
1651 // Post a task. | |
1652 tick_active_smooth_scroll_gestures_task_posted_ = true; | |
1653 MessageLoop::current()->PostDelayedTask( | |
1654 FROM_HERE, | |
1655 base::Bind(&RenderWidgetHostImpl::TickActiveSmoothScrollGesture, | |
1656 weak_factory_.GetWeakPtr()), | |
1657 time_until_next_ideal_interval); | |
1658 return; | |
1659 } | |
1624 | 1660 |
1625 // Post the next tick right away so it is regular. | 1661 last_smooth_scroll_gestures_tick_time_ = now; |
1626 MessageLoop::current()->PostDelayedTask( | |
1627 FROM_HERE, | |
1628 base::Bind(&RenderWidgetHostImpl::TickActiveSmoothScrollGesture, | |
1629 weak_factory_.GetWeakPtr()), | |
1630 base::TimeDelta::FromMilliseconds(kSyntheticScrollMessageIntervalMs)); | |
1631 | 1662 |
1632 // Separate ticking of gestures from sending their completion messages. | 1663 // Separate ticking of gestures from sending their completion messages. |
1633 std::vector<int> ids_that_are_done; | 1664 std::vector<int> ids_that_are_done; |
1634 for (SmoothScrollGestureMap::iterator it = | 1665 for (SmoothScrollGestureMap::iterator it = |
1635 active_smooth_scroll_gestures_.begin(); | 1666 active_smooth_scroll_gestures_.begin(); |
1636 it != active_smooth_scroll_gestures_.end(); | 1667 it != active_smooth_scroll_gestures_.end(); |
1637 ++it) { | 1668 ++it) { |
1638 | 1669 |
1639 bool active = it->second->ForwardInputEvents(now, this); | 1670 bool active = it->second->ForwardInputEvents(now, this); |
1640 if (!active) | 1671 if (!active) |
1641 ids_that_are_done.push_back(it->first); | 1672 ids_that_are_done.push_back(it->first); |
1642 } | 1673 } |
1643 | 1674 |
1644 // Delete completed gestures and send their completion event. | 1675 // Delete completed gestures and send their completion event. |
1645 for(size_t i = 0; i < ids_that_are_done.size(); i++) { | 1676 for(size_t i = 0; i < ids_that_are_done.size(); i++) { |
1646 int id = ids_that_are_done[i]; | 1677 int id = ids_that_are_done[i]; |
1647 SmoothScrollGestureMap::iterator it = | 1678 SmoothScrollGestureMap::iterator it = |
1648 active_smooth_scroll_gestures_.find(id); | 1679 active_smooth_scroll_gestures_.find(id); |
1649 DCHECK(it != active_smooth_scroll_gestures_.end()); | 1680 DCHECK(it != active_smooth_scroll_gestures_.end()); |
1650 active_smooth_scroll_gestures_.erase(it); | 1681 active_smooth_scroll_gestures_.erase(it); |
1651 | 1682 |
1652 Send(new ViewMsg_SmoothScrollCompleted(routing_id_, id)); | 1683 Send(new ViewMsg_SmoothScrollCompleted(routing_id_, id)); |
1653 } | 1684 } |
1685 | |
1686 // No need to ost the next tick if an input is in flight. | |
1687 if (in_process_event_types_.size() != 0) | |
piman
2012/10/06 06:18:57
!.empty()
| |
1688 return; | |
1689 | |
1690 TRACE_EVENT_INSTANT1("input", "PostTickTask", | |
1691 "delay", preferred_interval.InMilliseconds()); | |
1692 tick_active_smooth_scroll_gestures_task_posted_ = true; | |
1693 MessageLoop::current()->PostDelayedTask( | |
1694 FROM_HERE, | |
1695 base::Bind(&RenderWidgetHostImpl::TickActiveSmoothScrollGesture, | |
1696 weak_factory_.GetWeakPtr()), | |
1697 preferred_interval); | |
1654 } | 1698 } |
1655 | 1699 |
1656 void RenderWidgetHostImpl::OnMsgSelectRangeAck() { | 1700 void RenderWidgetHostImpl::OnMsgSelectRangeAck() { |
1657 select_range_pending_ = false; | 1701 select_range_pending_ = false; |
1658 if (next_selection_range_.get()) { | 1702 if (next_selection_range_.get()) { |
1659 scoped_ptr<SelectionRange> next(next_selection_range_.Pass()); | 1703 scoped_ptr<SelectionRange> next(next_selection_range_.Pass()); |
1660 SelectRange(next->start, next->end); | 1704 SelectRange(next->start, next->end); |
1661 } | 1705 } |
1662 } | 1706 } |
1663 | 1707 |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2073 return; | 2117 return; |
2074 | 2118 |
2075 OnRenderAutoResized(new_size); | 2119 OnRenderAutoResized(new_size); |
2076 } | 2120 } |
2077 | 2121 |
2078 void RenderWidgetHostImpl::DetachDelegate() { | 2122 void RenderWidgetHostImpl::DetachDelegate() { |
2079 delegate_ = NULL; | 2123 delegate_ = NULL; |
2080 } | 2124 } |
2081 | 2125 |
2082 } // namespace content | 2126 } // namespace content |
OLD | NEW |