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_view_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 #include "ui/aura/window_tracker.h" | 58 #include "ui/aura/window_tracker.h" |
59 #include "ui/aura/window_tree_host.h" | 59 #include "ui/aura/window_tree_host.h" |
60 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 60 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
61 #include "ui/base/hit_test.h" | 61 #include "ui/base/hit_test.h" |
62 #include "ui/base/ime/input_method.h" | 62 #include "ui/base/ime/input_method.h" |
63 #include "ui/base/ui_base_types.h" | 63 #include "ui/base/ui_base_types.h" |
64 #include "ui/compositor/compositor_vsync_manager.h" | 64 #include "ui/compositor/compositor_vsync_manager.h" |
65 #include "ui/compositor/dip_util.h" | 65 #include "ui/compositor/dip_util.h" |
66 #include "ui/events/event.h" | 66 #include "ui/events/event.h" |
67 #include "ui/events/event_utils.h" | 67 #include "ui/events/event_utils.h" |
| 68 #include "ui/events/gestures/fling_curve.h" |
68 #include "ui/events/gestures/gesture_recognizer.h" | 69 #include "ui/events/gestures/gesture_recognizer.h" |
69 #include "ui/gfx/canvas.h" | 70 #include "ui/gfx/canvas.h" |
70 #include "ui/gfx/display.h" | 71 #include "ui/gfx/display.h" |
| 72 #include "ui/gfx/frame_time.h" |
71 #include "ui/gfx/rect_conversions.h" | 73 #include "ui/gfx/rect_conversions.h" |
72 #include "ui/gfx/screen.h" | 74 #include "ui/gfx/screen.h" |
73 #include "ui/gfx/size_conversions.h" | 75 #include "ui/gfx/size_conversions.h" |
74 #include "ui/gfx/skia_util.h" | 76 #include "ui/gfx/skia_util.h" |
75 #include "ui/wm/public/activation_client.h" | 77 #include "ui/wm/public/activation_client.h" |
76 #include "ui/wm/public/scoped_tooltip_disabler.h" | 78 #include "ui/wm/public/scoped_tooltip_disabler.h" |
77 #include "ui/wm/public/tooltip_client.h" | 79 #include "ui/wm/public/tooltip_client.h" |
78 #include "ui/wm/public/transient_window_client.h" | 80 #include "ui/wm/public/transient_window_client.h" |
79 #include "ui/wm/public/window_types.h" | 81 #include "ui/wm/public/window_types.h" |
80 | 82 |
(...skipping 16 matching lines...) Expand all Loading... |
97 using gfx::RectToSkIRect; | 99 using gfx::RectToSkIRect; |
98 using gfx::SkIRectToRect; | 100 using gfx::SkIRectToRect; |
99 | 101 |
100 using blink::WebScreenInfo; | 102 using blink::WebScreenInfo; |
101 using blink::WebInputEvent; | 103 using blink::WebInputEvent; |
102 using blink::WebGestureEvent; | 104 using blink::WebGestureEvent; |
103 using blink::WebTouchEvent; | 105 using blink::WebTouchEvent; |
104 | 106 |
105 namespace content { | 107 namespace content { |
106 | 108 |
| 109 class Flinger : public ui::CompositorAnimationObserver { |
| 110 public: |
| 111 class Delegate { |
| 112 public: |
| 113 virtual ~Delegate() {} |
| 114 |
| 115 virtual void OnScroll(const gfx::Vector2dF& scroll_delta) = 0; |
| 116 |
| 117 virtual void OnScrollEnd() = 0; |
| 118 }; |
| 119 |
| 120 Flinger(Delegate* delegate, |
| 121 const gfx::Vector2dF& velocity, |
| 122 ui::Compositor* compositor) |
| 123 : delegate_(delegate), |
| 124 compositor_(compositor), |
| 125 fling_curve_(velocity, gfx::FrameTime::Now()) { |
| 126 CHECK(delegate_); |
| 127 compositor_->AddAnimationObserver(this); |
| 128 } |
| 129 |
| 130 virtual ~Flinger() { Done(); } |
| 131 |
| 132 private: |
| 133 void Done() { |
| 134 if (!delegate_) |
| 135 return; |
| 136 compositor_->RemoveAnimationObserver(this); |
| 137 Delegate* delegate = delegate_; |
| 138 delegate_ = NULL; |
| 139 delegate->OnScrollEnd(); |
| 140 } |
| 141 |
| 142 // ui::CompositorAnimationObserver: |
| 143 virtual void OnAnimationStep(base::TimeTicks timestamp) OVERRIDE { |
| 144 CHECK(delegate_); |
| 145 if (fling_curve_.start_timestamp() > timestamp) |
| 146 return; |
| 147 gfx::Vector2dF scroll = fling_curve_.GetScrollAmountAtTime(timestamp); |
| 148 if (scroll.IsZero()) |
| 149 Done(); |
| 150 else |
| 151 delegate_->OnScroll(scroll); |
| 152 } |
| 153 |
| 154 Delegate* delegate_; |
| 155 ui::Compositor* compositor_; |
| 156 ui::FlingCurve fling_curve_; |
| 157 |
| 158 DISALLOW_COPY_AND_ASSIGN(Flinger); |
| 159 }; |
| 160 |
| 161 class FlingerDelegate : public Flinger::Delegate { |
| 162 public: |
| 163 FlingerDelegate(RenderWidgetHostView* view, |
| 164 const blink::WebGestureEvent& gesture_event) |
| 165 : view_(view), gesture_(gesture_event) {} |
| 166 |
| 167 virtual ~FlingerDelegate() {} |
| 168 |
| 169 private: |
| 170 // Flinger::Delegate: |
| 171 virtual void OnScroll(const gfx::Vector2dF& scroll_delta) OVERRIDE { |
| 172 blink::WebGestureEvent gesture = gesture_; |
| 173 gesture.type = blink::WebInputEvent::GestureScrollUpdateWithoutPropagation; |
| 174 gesture.data.scrollUpdate.deltaX = scroll_delta.x(); |
| 175 gesture.data.scrollUpdate.deltaY = scroll_delta.y(); |
| 176 RenderWidgetHostImpl::From(view_->GetRenderWidgetHost()) |
| 177 ->ForwardGestureEvent(gesture); |
| 178 } |
| 179 |
| 180 virtual void OnScrollEnd() OVERRIDE { |
| 181 blink::WebGestureEvent gesture = gesture_; |
| 182 gesture.type = blink::WebInputEvent::GestureScrollEnd; |
| 183 RenderWidgetHostImpl::From(view_->GetRenderWidgetHost()) |
| 184 ->ForwardGestureEvent(gesture); |
| 185 delete this; |
| 186 } |
| 187 |
| 188 RenderWidgetHostView* view_; |
| 189 blink::WebGestureEvent gesture_; |
| 190 |
| 191 DISALLOW_COPY_AND_ASSIGN(FlingerDelegate); |
| 192 }; |
| 193 |
107 namespace { | 194 namespace { |
108 | 195 |
109 // In mouse lock mode, we need to prevent the (invisible) cursor from hitting | 196 // In mouse lock mode, we need to prevent the (invisible) cursor from hitting |
110 // the border of the view, in order to get valid movement information. However, | 197 // the border of the view, in order to get valid movement information. However, |
111 // forcing the cursor back to the center of the view after each mouse move | 198 // forcing the cursor back to the center of the view after each mouse move |
112 // doesn't work well. It reduces the frequency of useful mouse move messages | 199 // doesn't work well. It reduces the frequency of useful mouse move messages |
113 // significantly. Therefore, we move the cursor to the center of the view only | 200 // significantly. Therefore, we move the cursor to the center of the view only |
114 // if it approaches the border. |kMouseLockBorderPercentage| specifies the width | 201 // if it approaches the border. |kMouseLockBorderPercentage| specifies the width |
115 // of the border area, in percentage of the corresponding dimension. | 202 // of the border area, in percentage of the corresponding dimension. |
116 const int kMouseLockBorderPercentage = 15; | 203 const int kMouseLockBorderPercentage = 15; |
(...skipping 1841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1958 return; | 2045 return; |
1959 } | 2046 } |
1960 | 2047 |
1961 if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event)) | 2048 if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event)) |
1962 return; | 2049 return; |
1963 | 2050 |
1964 RenderViewHostDelegate* delegate = NULL; | 2051 RenderViewHostDelegate* delegate = NULL; |
1965 if (host_->IsRenderView()) | 2052 if (host_->IsRenderView()) |
1966 delegate = RenderViewHost::From(host_)->GetDelegate(); | 2053 delegate = RenderViewHost::From(host_)->GetDelegate(); |
1967 | 2054 |
| 2055 // If there is an active fling, then any incoming new gesture event should |
| 2056 // terminate the fling. |
| 2057 if (flinger_ && event->type() == ui::ET_GESTURE_BEGIN) |
| 2058 flinger_.reset(); |
| 2059 |
1968 if (delegate && event->type() == ui::ET_GESTURE_BEGIN && | 2060 if (delegate && event->type() == ui::ET_GESTURE_BEGIN && |
1969 event->details().touch_points() == 1) { | 2061 event->details().touch_points() == 1) { |
1970 delegate->HandleGestureBegin(); | 2062 delegate->HandleGestureBegin(); |
1971 } | 2063 } |
1972 | 2064 |
1973 blink::WebGestureEvent gesture = MakeWebGestureEvent(event); | 2065 blink::WebGestureEvent gesture = MakeWebGestureEvent(event); |
1974 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | 2066 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
1975 // Webkit does not stop a fling-scroll on tap-down. So explicitly send an | 2067 // Webkit does not stop a fling-scroll on tap-down. So explicitly send an |
1976 // event to stop any in-progress flings. | 2068 // event to stop any in-progress flings. |
1977 blink::WebGestureEvent fling_cancel = gesture; | 2069 blink::WebGestureEvent fling_cancel = gesture; |
1978 fling_cancel.type = blink::WebInputEvent::GestureFlingCancel; | 2070 fling_cancel.type = blink::WebInputEvent::GestureFlingCancel; |
1979 fling_cancel.sourceDevice = blink::WebGestureDeviceTouchscreen; | 2071 fling_cancel.sourceDevice = blink::WebGestureDeviceTouchscreen; |
1980 host_->ForwardGestureEvent(fling_cancel); | 2072 host_->ForwardGestureEvent(fling_cancel); |
1981 } | 2073 } |
1982 | 2074 |
1983 if (gesture.type != blink::WebInputEvent::Undefined) { | 2075 if (gesture.type == blink::WebInputEvent::GestureFlingStart) { |
| 2076 flinger_.reset( |
| 2077 new Flinger(new FlingerDelegate(this, gesture), |
| 2078 gfx::Vector2dF(gesture.data.flingStart.velocityX, |
| 2079 gesture.data.flingStart.velocityY), |
| 2080 window_->GetHost()->compositor())); |
| 2081 } else if (gesture.type != blink::WebInputEvent::Undefined) { |
1984 host_->ForwardGestureEventWithLatencyInfo(gesture, *event->latency()); | 2082 host_->ForwardGestureEventWithLatencyInfo(gesture, *event->latency()); |
1985 | 2083 |
1986 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN || | 2084 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN || |
1987 event->type() == ui::ET_GESTURE_SCROLL_UPDATE || | 2085 event->type() == ui::ET_GESTURE_SCROLL_UPDATE || |
1988 event->type() == ui::ET_GESTURE_SCROLL_END) { | 2086 event->type() == ui::ET_GESTURE_SCROLL_END) { |
1989 RecordAction(base::UserMetricsAction("TouchscreenScroll")); | 2087 RecordAction(base::UserMetricsAction("TouchscreenScroll")); |
1990 } else if (event->type() == ui::ET_SCROLL_FLING_START) { | 2088 } else if (event->type() == ui::ET_SCROLL_FLING_START) { |
1991 RecordAction(base::UserMetricsAction("TouchscreenScrollFling")); | 2089 RecordAction(base::UserMetricsAction("TouchscreenScrollFling")); |
1992 } | 2090 } |
1993 } | 2091 } |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2503 | 2601 |
2504 //////////////////////////////////////////////////////////////////////////////// | 2602 //////////////////////////////////////////////////////////////////////////////// |
2505 // RenderWidgetHostViewBase, public: | 2603 // RenderWidgetHostViewBase, public: |
2506 | 2604 |
2507 // static | 2605 // static |
2508 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2606 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
2509 GetScreenInfoForWindow(results, NULL); | 2607 GetScreenInfoForWindow(results, NULL); |
2510 } | 2608 } |
2511 | 2609 |
2512 } // namespace content | 2610 } // namespace content |
OLD | NEW |