OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 2199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2210 bool LayerTreeHostImpl::ScrollBy(const gfx::Point& viewport_point, | 2210 bool LayerTreeHostImpl::ScrollBy(const gfx::Point& viewport_point, |
2211 const gfx::Vector2dF& scroll_delta) { | 2211 const gfx::Vector2dF& scroll_delta) { |
2212 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); | 2212 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); |
2213 if (!CurrentlyScrollingLayer()) | 2213 if (!CurrentlyScrollingLayer()) |
2214 return false; | 2214 return false; |
2215 | 2215 |
2216 gfx::Vector2dF pending_delta = scroll_delta; | 2216 gfx::Vector2dF pending_delta = scroll_delta; |
2217 gfx::Vector2dF unused_root_delta; | 2217 gfx::Vector2dF unused_root_delta; |
2218 bool did_scroll_x = false; | 2218 bool did_scroll_x = false; |
2219 bool did_scroll_y = false; | 2219 bool did_scroll_y = false; |
| 2220 bool did_scroll_top_controls = false; |
2220 // TODO(wjmaclean) Should we guard against CurrentlyScrollingLayer() == 0 | 2221 // TODO(wjmaclean) Should we guard against CurrentlyScrollingLayer() == 0 |
2221 // here? | 2222 // here? |
2222 bool consume_by_top_controls = | 2223 bool consume_by_top_controls = |
2223 top_controls_manager_ && | 2224 top_controls_manager_ && |
2224 (((CurrentlyScrollingLayer() == InnerViewportScrollLayer() || | 2225 (((CurrentlyScrollingLayer() == InnerViewportScrollLayer() || |
2225 CurrentlyScrollingLayer() == OuterViewportScrollLayer()) && | 2226 CurrentlyScrollingLayer() == OuterViewportScrollLayer()) && |
2226 InnerViewportScrollLayer()->MaxScrollOffset().y() > 0) || | 2227 InnerViewportScrollLayer()->MaxScrollOffset().y() > 0) || |
2227 scroll_delta.y() < 0); | 2228 scroll_delta.y() < 0); |
2228 | 2229 |
2229 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); | 2230 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); |
2230 layer_impl; | 2231 layer_impl; |
2231 layer_impl = layer_impl->parent()) { | 2232 layer_impl = layer_impl->parent()) { |
2232 if (!layer_impl->scrollable()) | 2233 if (!layer_impl->scrollable()) |
2233 continue; | 2234 continue; |
2234 | 2235 |
2235 if (layer_impl == InnerViewportScrollLayer()) { | 2236 if (layer_impl == InnerViewportScrollLayer()) { |
2236 // Only allow bubble scrolling when the scroll is in the direction to make | 2237 // Only allow bubble scrolling when the scroll is in the direction to make |
2237 // the top controls visible. | 2238 // the top controls visible. |
2238 gfx::Vector2dF applied_delta; | 2239 gfx::Vector2dF applied_delta; |
2239 gfx::Vector2dF excess_delta; | 2240 gfx::Vector2dF excess_delta; |
2240 if (consume_by_top_controls) { | 2241 if (consume_by_top_controls) { |
2241 excess_delta = top_controls_manager_->ScrollBy(pending_delta); | 2242 excess_delta = top_controls_manager_->ScrollBy(pending_delta); |
2242 applied_delta = pending_delta - excess_delta; | 2243 applied_delta = pending_delta - excess_delta; |
2243 pending_delta = excess_delta; | 2244 pending_delta = excess_delta; |
2244 // Force updating of vertical adjust values if needed. | 2245 // Force updating of vertical adjust values if needed. |
2245 if (applied_delta.y() != 0) | 2246 if (applied_delta.y() != 0) { |
| 2247 did_scroll_top_controls = true; |
2246 layer_impl->ScrollbarParametersDidChange(); | 2248 layer_impl->ScrollbarParametersDidChange(); |
| 2249 } |
2247 } | 2250 } |
2248 // Track root layer deltas for reporting overscroll. | 2251 // Track root layer deltas for reporting overscroll. |
2249 unused_root_delta = pending_delta; | 2252 unused_root_delta = pending_delta; |
2250 } | 2253 } |
2251 | 2254 |
2252 gfx::Vector2dF applied_delta; | 2255 gfx::Vector2dF applied_delta; |
2253 // Gesture events need to be transformed from viewport coordinates to local | 2256 // Gesture events need to be transformed from viewport coordinates to local |
2254 // layer coordinates so that the scrolling contents exactly follow the | 2257 // layer coordinates so that the scrolling contents exactly follow the |
2255 // user's finger. In contrast, wheel events represent a fixed amount of | 2258 // user's finger. In contrast, wheel events represent a fixed amount of |
2256 // scrolling so we can just apply them directly. | 2259 // scrolling so we can just apply them directly. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2300 | 2303 |
2301 // Allow further movement only on an axis perpendicular to the direction in | 2304 // Allow further movement only on an axis perpendicular to the direction in |
2302 // which the layer moved. | 2305 // which the layer moved. |
2303 gfx::Vector2dF perpendicular_axis(-applied_delta.y(), applied_delta.x()); | 2306 gfx::Vector2dF perpendicular_axis(-applied_delta.y(), applied_delta.x()); |
2304 pending_delta = MathUtil::ProjectVector(pending_delta, perpendicular_axis); | 2307 pending_delta = MathUtil::ProjectVector(pending_delta, perpendicular_axis); |
2305 | 2308 |
2306 if (gfx::ToRoundedVector2d(pending_delta).IsZero()) | 2309 if (gfx::ToRoundedVector2d(pending_delta).IsZero()) |
2307 break; | 2310 break; |
2308 } | 2311 } |
2309 | 2312 |
2310 bool did_scroll = did_scroll_x || did_scroll_y; | 2313 bool did_scroll_content = did_scroll_x || did_scroll_y; |
2311 if (did_scroll) { | 2314 if (did_scroll_content) { |
2312 client_->SetNeedsCommitOnImplThread(); | 2315 client_->SetNeedsCommitOnImplThread(); |
2313 SetNeedsRedraw(); | 2316 SetNeedsRedraw(); |
2314 client_->RenewTreePriority(); | 2317 client_->RenewTreePriority(); |
2315 } | 2318 } |
2316 | 2319 |
2317 // Scrolling along an axis resets accumulated root overscroll for that axis. | 2320 // Scrolling along an axis resets accumulated root overscroll for that axis. |
2318 if (did_scroll_x) | 2321 if (did_scroll_x) |
2319 accumulated_root_overscroll_.set_x(0); | 2322 accumulated_root_overscroll_.set_x(0); |
2320 if (did_scroll_y) | 2323 if (did_scroll_y) |
2321 accumulated_root_overscroll_.set_y(0); | 2324 accumulated_root_overscroll_.set_y(0); |
2322 | 2325 |
2323 accumulated_root_overscroll_ += unused_root_delta; | 2326 accumulated_root_overscroll_ += unused_root_delta; |
2324 bool did_overscroll = !gfx::ToRoundedVector2d(unused_root_delta).IsZero(); | 2327 bool did_overscroll = !gfx::ToRoundedVector2d(unused_root_delta).IsZero(); |
2325 if (did_overscroll && input_handler_client_) { | 2328 if (did_overscroll && input_handler_client_) { |
2326 DidOverscrollParams params; | 2329 DidOverscrollParams params; |
2327 params.accumulated_overscroll = accumulated_root_overscroll_; | 2330 params.accumulated_overscroll = accumulated_root_overscroll_; |
2328 params.latest_overscroll_delta = unused_root_delta; | 2331 params.latest_overscroll_delta = unused_root_delta; |
2329 params.current_fling_velocity = current_fling_velocity_; | 2332 params.current_fling_velocity = current_fling_velocity_; |
2330 input_handler_client_->DidOverscroll(params); | 2333 input_handler_client_->DidOverscroll(params); |
2331 } | 2334 } |
2332 | 2335 |
2333 return did_scroll; | 2336 return did_scroll_content || did_scroll_top_controls; |
2334 } | 2337 } |
2335 | 2338 |
2336 // This implements scrolling by page as described here: | 2339 // This implements scrolling by page as described here: |
2337 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms645601(v=vs.85).asp
x#_win32_The_Mouse_Wheel | 2340 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms645601(v=vs.85).asp
x#_win32_The_Mouse_Wheel |
2338 // for events with WHEEL_PAGESCROLL set. | 2341 // for events with WHEEL_PAGESCROLL set. |
2339 bool LayerTreeHostImpl::ScrollVerticallyByPage(const gfx::Point& viewport_point, | 2342 bool LayerTreeHostImpl::ScrollVerticallyByPage(const gfx::Point& viewport_point, |
2340 ScrollDirection direction) { | 2343 ScrollDirection direction) { |
2341 DCHECK(wheel_scrolling_); | 2344 DCHECK(wheel_scrolling_); |
2342 | 2345 |
2343 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); | 2346 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3033 swap_promise_monitor_.erase(monitor); | 3036 swap_promise_monitor_.erase(monitor); |
3034 } | 3037 } |
3035 | 3038 |
3036 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { | 3039 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { |
3037 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); | 3040 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); |
3038 for (; it != swap_promise_monitor_.end(); it++) | 3041 for (; it != swap_promise_monitor_.end(); it++) |
3039 (*it)->OnSetNeedsRedrawOnImpl(); | 3042 (*it)->OnSetNeedsRedrawOnImpl(); |
3040 } | 3043 } |
3041 | 3044 |
3042 } // namespace cc | 3045 } // namespace cc |
OLD | NEW |