| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // Returns |true| if two gesture events should be coalesced. | 95 // Returns |true| if two gesture events should be coalesced. |
| 96 bool ShouldCoalesceGestureEvents(const WebKit::WebGestureEvent& last_event, | 96 bool ShouldCoalesceGestureEvents(const WebKit::WebGestureEvent& last_event, |
| 97 const WebKit::WebGestureEvent& new_event) { | 97 const WebKit::WebGestureEvent& new_event) { |
| 98 return new_event.type == WebInputEvent::GestureScrollUpdate && | 98 return new_event.type == WebInputEvent::GestureScrollUpdate && |
| 99 last_event.type == new_event.type && | 99 last_event.type == new_event.type && |
| 100 last_event.modifiers == new_event.modifiers; | 100 last_event.modifiers == new_event.modifiers; |
| 101 } | 101 } |
| 102 | 102 |
| 103 } // namespace | 103 } // namespace |
| 104 | 104 |
| 105 |
| 105 // static | 106 // static |
| 106 void RenderWidgetHost::RemoveAllBackingStores() { | 107 void RenderWidgetHost::RemoveAllBackingStores() { |
| 107 BackingStoreManager::RemoveAllBackingStores(); | 108 BackingStoreManager::RemoveAllBackingStores(); |
| 108 } | 109 } |
| 109 | 110 |
| 110 // static | 111 // static |
| 111 size_t RenderWidgetHost::BackingStoreMemorySize() { | 112 size_t RenderWidgetHost::BackingStoreMemorySize() { |
| 112 return BackingStoreManager::MemorySize(); | 113 return BackingStoreManager::MemorySize(); |
| 113 } | 114 } |
| 114 | 115 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 143 view_being_painted_(false), | 144 view_being_painted_(false), |
| 144 ignore_input_events_(false), | 145 ignore_input_events_(false), |
| 145 text_direction_updated_(false), | 146 text_direction_updated_(false), |
| 146 text_direction_(WebKit::WebTextDirectionLeftToRight), | 147 text_direction_(WebKit::WebTextDirectionLeftToRight), |
| 147 text_direction_canceled_(false), | 148 text_direction_canceled_(false), |
| 148 suppress_next_char_events_(false), | 149 suppress_next_char_events_(false), |
| 149 pending_mouse_lock_request_(false), | 150 pending_mouse_lock_request_(false), |
| 150 allow_privileged_mouse_lock_(false), | 151 allow_privileged_mouse_lock_(false), |
| 151 has_touch_handler_(false), | 152 has_touch_handler_(false), |
| 152 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 153 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 153 tap_suppression_controller_(new TapSuppressionController(this)) { | 154 tap_suppression_controller_(new TapSuppressionController(this)), |
| 155 fling_in_progress_(false) { |
| 154 CHECK(delegate_); | 156 CHECK(delegate_); |
| 155 if (routing_id_ == MSG_ROUTING_NONE) { | 157 if (routing_id_ == MSG_ROUTING_NONE) { |
| 156 routing_id_ = process_->GetNextRoutingID(); | 158 routing_id_ = process_->GetNextRoutingID(); |
| 157 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( | 159 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( |
| 158 process_->GetID(), | 160 process_->GetID(), |
| 159 routing_id_); | 161 routing_id_); |
| 160 } else { | 162 } else { |
| 161 // TODO(piman): This is a O(N) lookup, where we could forward the | 163 // TODO(piman): This is a O(N) lookup, where we could forward the |
| 162 // information from the RenderWidgetHelper. The problem is that doing so | 164 // information from the RenderWidgetHelper. The problem is that doing so |
| 163 // currently leaks outside of content all the way to chrome classes, and | 165 // currently leaks outside of content all the way to chrome classes, and |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 void RenderWidgetHostImpl::ViewDestroyed() { | 485 void RenderWidgetHostImpl::ViewDestroyed() { |
| 484 RejectMouseLockOrUnlockIfNecessary(); | 486 RejectMouseLockOrUnlockIfNecessary(); |
| 485 | 487 |
| 486 // TODO(evanm): tracking this may no longer be necessary; | 488 // TODO(evanm): tracking this may no longer be necessary; |
| 487 // eliminate this function if so. | 489 // eliminate this function if so. |
| 488 SetView(NULL); | 490 SetView(NULL); |
| 489 } | 491 } |
| 490 | 492 |
| 491 void RenderWidgetHostImpl::SetIsLoading(bool is_loading) { | 493 void RenderWidgetHostImpl::SetIsLoading(bool is_loading) { |
| 492 is_loading_ = is_loading; | 494 is_loading_ = is_loading; |
| 495 fling_in_progress_ = false; |
| 493 if (!view_) | 496 if (!view_) |
| 494 return; | 497 return; |
| 495 view_->SetIsLoading(is_loading); | 498 view_->SetIsLoading(is_loading); |
| 496 } | 499 } |
| 497 | 500 |
| 498 void RenderWidgetHostImpl::CopyFromBackingStore( | 501 void RenderWidgetHostImpl::CopyFromBackingStore( |
| 499 const gfx::Rect& src_subrect, | 502 const gfx::Rect& src_subrect, |
| 500 const gfx::Size& accelerated_dst_size, | 503 const gfx::Size& accelerated_dst_size, |
| 501 const base::Callback<void(bool)>& callback, | 504 const base::Callback<void(bool)>& callback, |
| 502 skia::PlatformCanvas* output) { | 505 skia::PlatformCanvas* output) { |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 | 826 |
| 824 ForwardInputEvent(wheel_event, sizeof(WebMouseWheelEvent), false); | 827 ForwardInputEvent(wheel_event, sizeof(WebMouseWheelEvent), false); |
| 825 } | 828 } |
| 826 | 829 |
| 827 void RenderWidgetHostImpl::ForwardGestureEvent( | 830 void RenderWidgetHostImpl::ForwardGestureEvent( |
| 828 const WebKit::WebGestureEvent& gesture_event) { | 831 const WebKit::WebGestureEvent& gesture_event) { |
| 829 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardGestureEvent"); | 832 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardGestureEvent"); |
| 830 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 833 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 831 return; | 834 return; |
| 832 | 835 |
| 836 if (gesture_event.type == WebInputEvent::GestureFlingCancel) { |
| 837 if (ShouldDiscardFlingCancelEvent(gesture_event)) |
| 838 return; |
| 839 fling_in_progress_ = false; |
| 840 } |
| 841 |
| 833 if (gesture_event_pending_) { | 842 if (gesture_event_pending_) { |
| 834 if (coalesced_gesture_events_.empty() || | 843 if (coalesced_gesture_events_.empty() || |
| 835 !ShouldCoalesceGestureEvents(coalesced_gesture_events_.back(), | 844 !ShouldCoalesceGestureEvents(coalesced_gesture_events_.back(), |
| 836 gesture_event)) { | 845 gesture_event)) { |
| 837 coalesced_gesture_events_.push_back(gesture_event); | 846 coalesced_gesture_events_.push_back(gesture_event); |
| 838 } else { | 847 } else { |
| 839 WebGestureEvent* last_gesture_event = | 848 WebGestureEvent* last_gesture_event = |
| 840 &coalesced_gesture_events_.back(); | 849 &coalesced_gesture_events_.back(); |
| 841 last_gesture_event->deltaX += gesture_event.deltaX; | 850 last_gesture_event->deltaX += gesture_event.deltaX; |
| 842 last_gesture_event->deltaY += gesture_event.deltaY; | 851 last_gesture_event->deltaY += gesture_event.deltaY; |
| 843 DCHECK_GE(gesture_event.timeStampSeconds, | 852 DCHECK_GE(gesture_event.timeStampSeconds, |
| 844 last_gesture_event->timeStampSeconds); | 853 last_gesture_event->timeStampSeconds); |
| 845 last_gesture_event->timeStampSeconds = gesture_event.timeStampSeconds; | 854 last_gesture_event->timeStampSeconds = gesture_event.timeStampSeconds; |
| 846 } | 855 } |
| 847 return; | 856 return; |
| 848 } | 857 } |
| 849 gesture_event_pending_ = true; | 858 gesture_event_pending_ = true; |
| 850 | 859 |
| 851 if (gesture_event.type == WebInputEvent::GestureFlingCancel) | 860 if (gesture_event.type == WebInputEvent::GestureFlingCancel) { |
| 852 tap_suppression_controller_->GestureFlingCancel( | 861 tap_suppression_controller_->GestureFlingCancel( |
| 853 gesture_event.timeStampSeconds); | 862 gesture_event.timeStampSeconds); |
| 863 } else if (gesture_event.type == WebInputEvent::GestureFlingStart) { |
| 864 fling_in_progress_ = true; |
| 865 } |
| 866 |
| 854 ForwardInputEvent(gesture_event, sizeof(WebGestureEvent), false); | 867 ForwardInputEvent(gesture_event, sizeof(WebGestureEvent), false); |
| 855 } | 868 } |
| 856 | 869 |
| 857 void RenderWidgetHostImpl::ForwardKeyboardEvent( | 870 void RenderWidgetHostImpl::ForwardKeyboardEvent( |
| 858 const NativeWebKeyboardEvent& key_event) { | 871 const NativeWebKeyboardEvent& key_event) { |
| 859 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardKeyboardEvent"); | 872 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardKeyboardEvent"); |
| 860 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 873 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 861 return; | 874 return; |
| 862 | 875 |
| 863 if (key_event.type == WebKeyboardEvent::Char && | 876 if (key_event.type == WebKeyboardEvent::Char && |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 // Don't add this key to the queue if we have no way to send the message... | 919 // Don't add this key to the queue if we have no way to send the message... |
| 907 if (!process_->HasConnection()) | 920 if (!process_->HasConnection()) |
| 908 return; | 921 return; |
| 909 | 922 |
| 910 // Put all WebKeyboardEvent objects in a queue since we can't trust the | 923 // Put all WebKeyboardEvent objects in a queue since we can't trust the |
| 911 // renderer and we need to give something to the HandleKeyboardEvent | 924 // renderer and we need to give something to the HandleKeyboardEvent |
| 912 // handler. | 925 // handler. |
| 913 key_queue_.push_back(key_event); | 926 key_queue_.push_back(key_event); |
| 914 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); | 927 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); |
| 915 | 928 |
| 929 fling_in_progress_ = false; // Key events always stop flings. |
| 930 |
| 916 // Only forward the non-native portions of our event. | 931 // Only forward the non-native portions of our event. |
| 917 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent), | 932 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent), |
| 918 is_keyboard_shortcut); | 933 is_keyboard_shortcut); |
| 919 } | 934 } |
| 920 } | 935 } |
| 921 | 936 |
| 922 void RenderWidgetHostImpl::ForwardInputEvent(const WebInputEvent& input_event, | 937 void RenderWidgetHostImpl::ForwardInputEvent(const WebInputEvent& input_event, |
| 923 int event_size, | 938 int event_size, |
| 924 bool is_keyboard_shortcut) { | 939 bool is_keyboard_shortcut) { |
| 925 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardInputEvent"); | 940 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardInputEvent"); |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1506 base::TimeDelta::FromMilliseconds(kSyntheticScrollMessageIntervalMs)); | 1521 base::TimeDelta::FromMilliseconds(kSyntheticScrollMessageIntervalMs)); |
| 1507 | 1522 |
| 1508 | 1523 |
| 1509 bool active = active_smooth_scroll_gesture_->ForwardInputEvents(now, this); | 1524 bool active = active_smooth_scroll_gesture_->ForwardInputEvents(now, this); |
| 1510 if (!active) { | 1525 if (!active) { |
| 1511 active_smooth_scroll_gesture_.reset(); | 1526 active_smooth_scroll_gesture_.reset(); |
| 1512 // TODO(nduca): send "smooth scroll done" event to RenderWidget. | 1527 // TODO(nduca): send "smooth scroll done" event to RenderWidget. |
| 1513 } | 1528 } |
| 1514 } | 1529 } |
| 1515 | 1530 |
| 1531 bool RenderWidgetHostImpl::ShouldDiscardFlingCancelEvent( |
| 1532 const WebKit::WebGestureEvent& gesture_event) { |
| 1533 DCHECK(gesture_event.type == WebInputEvent::GestureFlingCancel); |
| 1534 if (coalesced_gesture_events_.empty() && fling_in_progress_) |
| 1535 return false; |
| 1536 GestureEventQueue::reverse_iterator it = |
| 1537 coalesced_gesture_events_.rbegin(); |
| 1538 while (it != coalesced_gesture_events_.rend()) { |
| 1539 if (it->type == WebInputEvent::GestureFlingStart) |
| 1540 return false; |
| 1541 if (it->type == WebInputEvent::GestureFlingCancel) |
| 1542 return true; |
| 1543 it++; |
| 1544 } |
| 1545 return true; |
| 1546 } |
| 1547 |
| 1516 void RenderWidgetHostImpl::ProcessWheelAck(bool processed) { | 1548 void RenderWidgetHostImpl::ProcessWheelAck(bool processed) { |
| 1517 mouse_wheel_pending_ = false; | 1549 mouse_wheel_pending_ = false; |
| 1518 | 1550 |
| 1519 // Now send the next (coalesced) mouse wheel event. | 1551 // Now send the next (coalesced) mouse wheel event. |
| 1520 if (!coalesced_mouse_wheel_events_.empty()) { | 1552 if (!coalesced_mouse_wheel_events_.empty()) { |
| 1521 WebMouseWheelEvent next_wheel_event = | 1553 WebMouseWheelEvent next_wheel_event = |
| 1522 coalesced_mouse_wheel_events_.front(); | 1554 coalesced_mouse_wheel_events_.front(); |
| 1523 coalesced_mouse_wheel_events_.pop_front(); | 1555 coalesced_mouse_wheel_events_.pop_front(); |
| 1524 ForwardWheelEvent(next_wheel_event); | 1556 ForwardWheelEvent(next_wheel_event); |
| 1525 } | 1557 } |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1934 // indicate that no callback is in progress (i.e. without this line | 1966 // indicate that no callback is in progress (i.e. without this line |
| 1935 // DelayedAutoResized will not get called again). | 1967 // DelayedAutoResized will not get called again). |
| 1936 new_auto_size_.SetSize(0, 0); | 1968 new_auto_size_.SetSize(0, 0); |
| 1937 if (!should_auto_resize_) | 1969 if (!should_auto_resize_) |
| 1938 return; | 1970 return; |
| 1939 | 1971 |
| 1940 OnRenderAutoResized(new_size); | 1972 OnRenderAutoResized(new_size); |
| 1941 } | 1973 } |
| 1942 | 1974 |
| 1943 } // namespace content | 1975 } // namespace content |
| OLD | NEW |