Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: cc/trees/layer_tree_host_impl.cc

Issue 2422353002: Iframe/div MD scrollbars get idle when mouse leaves the nested elements. (Closed)
Patch Set: Move the scrollbar animation logic to animation controllers. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 need_update_gpu_rasterization_status_(false), 201 need_update_gpu_rasterization_status_(false),
202 content_is_suitable_for_gpu_rasterization_(true), 202 content_is_suitable_for_gpu_rasterization_(true),
203 has_gpu_rasterization_trigger_(false), 203 has_gpu_rasterization_trigger_(false),
204 use_gpu_rasterization_(false), 204 use_gpu_rasterization_(false),
205 use_msaa_(false), 205 use_msaa_(false),
206 gpu_rasterization_status_(GpuRasterizationStatus::OFF_DEVICE), 206 gpu_rasterization_status_(GpuRasterizationStatus::OFF_DEVICE),
207 input_handler_client_(NULL), 207 input_handler_client_(NULL),
208 did_lock_scrolling_layer_(false), 208 did_lock_scrolling_layer_(false),
209 wheel_scrolling_(false), 209 wheel_scrolling_(false),
210 scroll_affects_scroll_handler_(false), 210 scroll_affects_scroll_handler_(false),
211 scroll_layer_id_when_mouse_over_scrollbar_(Layer::INVALID_ID), 211 scroll_layer_id_mouse_currently_over_(Layer::INVALID_ID),
212 captured_scrollbar_layer_id_(Layer::INVALID_ID),
213 tile_priorities_dirty_(false), 212 tile_priorities_dirty_(false),
214 settings_(settings), 213 settings_(settings),
215 visible_(false), 214 visible_(false),
216 cached_managed_memory_policy_(settings.gpu_memory_policy), 215 cached_managed_memory_policy_(settings.gpu_memory_policy),
217 is_synchronous_single_threaded_(!task_runner_provider->HasImplThread() && 216 is_synchronous_single_threaded_(!task_runner_provider->HasImplThread() &&
218 !settings.single_thread_proxy_scheduler), 217 !settings.single_thread_proxy_scheduler),
219 // Must be initialized after is_synchronous_single_threaded_ and 218 // Must be initialized after is_synchronous_single_threaded_ and
220 // task_runner_provider_. 219 // task_runner_provider_.
221 tile_manager_(this, 220 tile_manager_(this,
222 GetTaskRunner(), 221 GetTaskRunner(),
(...skipping 2990 matching lines...) Expand 10 before | Expand all | Expand 10 after
3213 gfx::Rect layer_impl_bounds(layer_impl->bounds()); 3212 gfx::Rect layer_impl_bounds(layer_impl->bounds());
3214 3213
3215 gfx::RectF device_viewport_layer_impl_bounds = MathUtil::MapClippedRect( 3214 gfx::RectF device_viewport_layer_impl_bounds = MathUtil::MapClippedRect(
3216 layer_impl->ScreenSpaceTransform(), gfx::RectF(layer_impl_bounds)); 3215 layer_impl->ScreenSpaceTransform(), gfx::RectF(layer_impl_bounds));
3217 3216
3218 return device_viewport_layer_impl_bounds.ManhattanDistanceToPoint( 3217 return device_viewport_layer_impl_bounds.ManhattanDistanceToPoint(
3219 device_viewport_point); 3218 device_viewport_point);
3220 } 3219 }
3221 3220
3222 void LayerTreeHostImpl::MouseDown() { 3221 void LayerTreeHostImpl::MouseDown() {
3223 if (scroll_layer_id_when_mouse_over_scrollbar_ == Layer::INVALID_ID)
3224 return;
3225
3226 captured_scrollbar_layer_id_ = scroll_layer_id_when_mouse_over_scrollbar_;
3227 ScrollbarAnimationController* animation_controller = 3222 ScrollbarAnimationController* animation_controller =
3228 ScrollbarAnimationControllerForId(captured_scrollbar_layer_id_); 3223 ScrollbarAnimationControllerForId(scroll_layer_id_mouse_currently_over_);
3229 if (animation_controller) 3224 if (animation_controller)
3230 animation_controller->DidCaptureScrollbarBegin(); 3225 animation_controller->DidMouseDown();
3231 } 3226 }
3232 3227
3233 void LayerTreeHostImpl::MouseUp() { 3228 void LayerTreeHostImpl::MouseUp() {
3234 if (captured_scrollbar_layer_id_ == Layer::INVALID_ID)
3235 return;
3236
3237 ScrollbarAnimationController* animation_controller = 3229 ScrollbarAnimationController* animation_controller =
3238 ScrollbarAnimationControllerForId(captured_scrollbar_layer_id_); 3230 ScrollbarAnimationControllerForId(scroll_layer_id_mouse_currently_over_);
3239 if (animation_controller) 3231 if (animation_controller)
3240 animation_controller->DidCaptureScrollbarEnd(); 3232 animation_controller->DidMouseUp();
3241 captured_scrollbar_layer_id_ = Layer::INVALID_ID;
3242 } 3233 }
3243 3234
3244 void LayerTreeHostImpl::MouseMoveAt(const gfx::Point& viewport_point) { 3235 void LayerTreeHostImpl::MouseMoveAt(const gfx::Point& viewport_point) {
3236 float distance_to_scrollbar = std::numeric_limits<float>::max();
3245 gfx::PointF device_viewport_point = gfx::ScalePoint( 3237 gfx::PointF device_viewport_point = gfx::ScalePoint(
3246 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); 3238 gfx::PointF(viewport_point), active_tree_->device_scale_factor());
3247 LayerImpl* layer_impl = 3239 LayerImpl* layer_impl =
3248 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); 3240 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point);
3249 HandleMouseOverScrollbar(layer_impl); 3241
3250 if (scroll_layer_id_when_mouse_over_scrollbar_ != Layer::INVALID_ID) 3242 // Check if mouse is over a scrollbar or not.
3243 // TODO(sahel): get rid of this extera checking when
3244 // FindScrollLayerForDeviceViewportPoint finds the proper layer for
3245 // scrolling on main thread, as well.
3246 int new_id = Layer::INVALID_ID;
3247 if (layer_impl && layer_impl->ToScrollbarLayer())
3248 new_id = layer_impl->ToScrollbarLayer()->ScrollLayerId();
3249 if (new_id != Layer::INVALID_ID) {
3250 // Mouse over a scrollbar.
3251 distance_to_scrollbar = 0;
3252 } else {
3253 bool scroll_on_main_thread = false;
3254 uint32_t main_thread_scrolling_reasons;
3255 LayerImpl* scroll_layer_impl = FindScrollLayerForDeviceViewportPoint(
3256 device_viewport_point, InputHandler::TOUCHSCREEN, layer_impl,
3257 &scroll_on_main_thread, &main_thread_scrolling_reasons);
3258
3259 // Scrollbars for the viewport are registered with the outer viewport layer.
3260 if (scroll_layer_impl == InnerViewportScrollLayer())
3261 scroll_layer_impl = OuterViewportScrollLayer();
3262
3263 new_id = scroll_layer_impl ? scroll_layer_impl->id() : Layer::INVALID_ID;
3264 }
3265
3266 if (new_id != scroll_layer_id_mouse_currently_over_) {
3267 ScrollbarAnimationController* old_animation_controller =
3268 ScrollbarAnimationControllerForId(
3269 scroll_layer_id_mouse_currently_over_);
3270 if (old_animation_controller) {
3271 old_animation_controller->DidMouseMoveOffScrollbar();
bokan 2016/10/20 14:58:08 Seems to me DidMouseMoveOffScrollbar should really
sahel 2016/10/24 21:22:05 Done.
3272 }
3273 scroll_layer_id_mouse_currently_over_ = new_id;
3274 }
3275
3276 ScrollbarAnimationController* new_animation_controller =
3277 ScrollbarAnimationControllerForId(new_id);
3278 if (!new_animation_controller)
3251 return; 3279 return;
3252 3280
3253 bool scroll_on_main_thread = false; 3281 for (ScrollbarLayerImplBase* scrollbar : ScrollbarsFor(new_id))
3254 uint32_t main_thread_scrolling_reasons;
3255 LayerImpl* scroll_layer_impl = FindScrollLayerForDeviceViewportPoint(
3256 device_viewport_point, InputHandler::TOUCHSCREEN, layer_impl,
3257 &scroll_on_main_thread, &main_thread_scrolling_reasons);
3258
3259 // Scrollbars for the viewport are registered with the outer viewport layer.
3260 if (scroll_layer_impl == InnerViewportScrollLayer())
3261 scroll_layer_impl = OuterViewportScrollLayer();
3262
3263 if (scroll_on_main_thread || !scroll_layer_impl)
3264 return;
3265
3266 ScrollbarAnimationController* animation_controller =
3267 ScrollbarAnimationControllerForId(scroll_layer_impl->id());
3268 if (!animation_controller)
3269 return;
3270
3271 float distance_to_scrollbar = std::numeric_limits<float>::max();
3272 for (ScrollbarLayerImplBase* scrollbar :
3273 ScrollbarsFor(scroll_layer_impl->id()))
3274 distance_to_scrollbar = 3282 distance_to_scrollbar =
3275 std::min(distance_to_scrollbar, 3283 std::min(distance_to_scrollbar,
3276 DeviceSpaceDistanceToLayer(device_viewport_point, scrollbar)); 3284 DeviceSpaceDistanceToLayer(device_viewport_point, scrollbar));
3277 3285 new_animation_controller->DidMouseMoveNear(
3278 animation_controller->DidMouseMoveNear(distance_to_scrollbar / 3286 distance_to_scrollbar / active_tree_->device_scale_factor());
3279 active_tree_->device_scale_factor());
3280 } 3287 }
3281 3288
3282 void LayerTreeHostImpl::MouseLeave() { 3289 void LayerTreeHostImpl::MouseLeave() {
3283 for (auto& pair : scrollbar_animation_controllers_) 3290 for (auto& pair : scrollbar_animation_controllers_)
3284 pair.second->DidMouseMoveOffScrollbar(); 3291 pair.second->DidMouseMoveOffScrollbar();
3285 3292 scroll_layer_id_mouse_currently_over_ = Layer::INVALID_ID;
3286 scroll_layer_id_when_mouse_over_scrollbar_ = Layer::INVALID_ID;
3287 }
3288
3289 void LayerTreeHostImpl::HandleMouseOverScrollbar(LayerImpl* layer_impl) {
3290 int new_id = Layer::INVALID_ID;
3291 if (layer_impl && layer_impl->ToScrollbarLayer())
3292 new_id = layer_impl->ToScrollbarLayer()->ScrollLayerId();
3293
3294 if (new_id == scroll_layer_id_when_mouse_over_scrollbar_)
3295 return;
3296
3297 ScrollbarAnimationController* old_animation_controller =
3298 ScrollbarAnimationControllerForId(
3299 scroll_layer_id_when_mouse_over_scrollbar_);
3300 if (old_animation_controller)
3301 old_animation_controller->DidMouseMoveOffScrollbar();
3302
3303 scroll_layer_id_when_mouse_over_scrollbar_ = new_id;
3304
3305 ScrollbarAnimationController* new_animation_controller =
3306 ScrollbarAnimationControllerForId(
3307 scroll_layer_id_when_mouse_over_scrollbar_);
3308 if (new_animation_controller)
3309 new_animation_controller->DidMouseMoveNear(0);
3310 } 3293 }
3311 3294
3312 void LayerTreeHostImpl::PinchGestureBegin() { 3295 void LayerTreeHostImpl::PinchGestureBegin() {
3313 pinch_gesture_active_ = true; 3296 pinch_gesture_active_ = true;
3314 client_->RenewTreePriority(); 3297 client_->RenewTreePriority();
3315 pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer(); 3298 pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer();
3316 active_tree_->SetCurrentlyScrollingLayer(viewport()->MainScrollLayer()); 3299 active_tree_->SetCurrentlyScrollingLayer(viewport()->MainScrollLayer());
3317 top_controls_manager_->PinchBegin(); 3300 top_controls_manager_->PinchBegin();
3318 } 3301 }
3319 3302
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
4102 if (is_visible) { 4085 if (is_visible) {
4103 worker_context_visibility_ = 4086 worker_context_visibility_ =
4104 worker_context->CacheController()->ClientBecameVisible(); 4087 worker_context->CacheController()->ClientBecameVisible();
4105 } else { 4088 } else {
4106 worker_context->CacheController()->ClientBecameNotVisible( 4089 worker_context->CacheController()->ClientBecameNotVisible(
4107 std::move(worker_context_visibility_)); 4090 std::move(worker_context_visibility_));
4108 } 4091 }
4109 } 4092 }
4110 4093
4111 } // namespace cc 4094 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698