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

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: Unittest passes asan build bot. Created 4 years, 1 month 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 need_update_gpu_rasterization_status_(false), 200 need_update_gpu_rasterization_status_(false),
201 content_is_suitable_for_gpu_rasterization_(true), 201 content_is_suitable_for_gpu_rasterization_(true),
202 has_gpu_rasterization_trigger_(false), 202 has_gpu_rasterization_trigger_(false),
203 use_gpu_rasterization_(false), 203 use_gpu_rasterization_(false),
204 use_msaa_(false), 204 use_msaa_(false),
205 gpu_rasterization_status_(GpuRasterizationStatus::OFF_DEVICE), 205 gpu_rasterization_status_(GpuRasterizationStatus::OFF_DEVICE),
206 input_handler_client_(NULL), 206 input_handler_client_(NULL),
207 did_lock_scrolling_layer_(false), 207 did_lock_scrolling_layer_(false),
208 wheel_scrolling_(false), 208 wheel_scrolling_(false),
209 scroll_affects_scroll_handler_(false), 209 scroll_affects_scroll_handler_(false),
210 scroll_layer_id_when_mouse_over_scrollbar_(Layer::INVALID_ID), 210 scroll_layer_id_mouse_currently_over_(Layer::INVALID_ID),
211 captured_scrollbar_layer_id_(Layer::INVALID_ID),
212 tile_priorities_dirty_(false), 211 tile_priorities_dirty_(false),
213 settings_(settings), 212 settings_(settings),
214 visible_(false), 213 visible_(false),
215 cached_managed_memory_policy_(settings.gpu_memory_policy), 214 cached_managed_memory_policy_(settings.gpu_memory_policy),
216 is_synchronous_single_threaded_(!task_runner_provider->HasImplThread() && 215 is_synchronous_single_threaded_(!task_runner_provider->HasImplThread() &&
217 !settings.single_thread_proxy_scheduler), 216 !settings.single_thread_proxy_scheduler),
218 // Must be initialized after is_synchronous_single_threaded_ and 217 // Must be initialized after is_synchronous_single_threaded_ and
219 // task_runner_provider_. 218 // task_runner_provider_.
220 tile_manager_(this, 219 tile_manager_(this,
221 GetTaskRunner(), 220 GetTaskRunner(),
(...skipping 2986 matching lines...) Expand 10 before | Expand all | Expand 10 after
3208 gfx::Rect layer_impl_bounds(layer_impl->bounds()); 3207 gfx::Rect layer_impl_bounds(layer_impl->bounds());
3209 3208
3210 gfx::RectF device_viewport_layer_impl_bounds = MathUtil::MapClippedRect( 3209 gfx::RectF device_viewport_layer_impl_bounds = MathUtil::MapClippedRect(
3211 layer_impl->ScreenSpaceTransform(), gfx::RectF(layer_impl_bounds)); 3210 layer_impl->ScreenSpaceTransform(), gfx::RectF(layer_impl_bounds));
3212 3211
3213 return device_viewport_layer_impl_bounds.ManhattanDistanceToPoint( 3212 return device_viewport_layer_impl_bounds.ManhattanDistanceToPoint(
3214 device_viewport_point); 3213 device_viewport_point);
3215 } 3214 }
3216 3215
3217 void LayerTreeHostImpl::MouseDown() { 3216 void LayerTreeHostImpl::MouseDown() {
3218 if (scroll_layer_id_when_mouse_over_scrollbar_ == Layer::INVALID_ID)
3219 return;
3220
3221 captured_scrollbar_layer_id_ = scroll_layer_id_when_mouse_over_scrollbar_;
3222 ScrollbarAnimationController* animation_controller = 3217 ScrollbarAnimationController* animation_controller =
3223 ScrollbarAnimationControllerForId(captured_scrollbar_layer_id_); 3218 ScrollbarAnimationControllerForId(scroll_layer_id_mouse_currently_over_);
3224 if (animation_controller) 3219 if (animation_controller)
3225 animation_controller->DidCaptureScrollbarBegin(); 3220 animation_controller->DidMouseDown();
3226 } 3221 }
3227 3222
3228 void LayerTreeHostImpl::MouseUp() { 3223 void LayerTreeHostImpl::MouseUp() {
3229 if (captured_scrollbar_layer_id_ == Layer::INVALID_ID)
3230 return;
3231
3232 ScrollbarAnimationController* animation_controller = 3224 ScrollbarAnimationController* animation_controller =
3233 ScrollbarAnimationControllerForId(captured_scrollbar_layer_id_); 3225 ScrollbarAnimationControllerForId(scroll_layer_id_mouse_currently_over_);
3234 if (animation_controller) 3226 if (animation_controller)
3235 animation_controller->DidCaptureScrollbarEnd(); 3227 animation_controller->DidMouseUp();
3236 captured_scrollbar_layer_id_ = Layer::INVALID_ID;
3237 } 3228 }
3238 3229
3239 void LayerTreeHostImpl::MouseMoveAt(const gfx::Point& viewport_point) { 3230 void LayerTreeHostImpl::MouseMoveAt(const gfx::Point& viewport_point) {
3231 float distance_to_scrollbar = std::numeric_limits<float>::max();
3240 gfx::PointF device_viewport_point = gfx::ScalePoint( 3232 gfx::PointF device_viewport_point = gfx::ScalePoint(
3241 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); 3233 gfx::PointF(viewport_point), active_tree_->device_scale_factor());
3242 LayerImpl* layer_impl = 3234 LayerImpl* layer_impl =
3243 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); 3235 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point);
3244 HandleMouseOverScrollbar(layer_impl); 3236
3245 if (scroll_layer_id_when_mouse_over_scrollbar_ != Layer::INVALID_ID) 3237 // Check if mouse is over a scrollbar or not.
3238 // TODO(sahel): get rid of this extera checking when
3239 // FindScrollLayerForDeviceViewportPoint finds the proper layer for
3240 // scrolling on main thread, as well.
3241 int new_id = Layer::INVALID_ID;
3242 if (layer_impl && layer_impl->ToScrollbarLayer())
3243 new_id = layer_impl->ToScrollbarLayer()->ScrollLayerId();
3244 if (new_id != Layer::INVALID_ID) {
3245 // Mouse over a scrollbar.
3246 distance_to_scrollbar = 0;
3247 } else {
3248 bool scroll_on_main_thread = false;
3249 uint32_t main_thread_scrolling_reasons;
3250 LayerImpl* scroll_layer_impl = FindScrollLayerForDeviceViewportPoint(
3251 device_viewport_point, InputHandler::TOUCHSCREEN, layer_impl,
3252 &scroll_on_main_thread, &main_thread_scrolling_reasons);
3253
3254 // Scrollbars for the viewport are registered with the outer viewport layer.
3255 if (scroll_layer_impl == InnerViewportScrollLayer())
3256 scroll_layer_impl = OuterViewportScrollLayer();
3257
3258 new_id = scroll_layer_impl ? scroll_layer_impl->id() : Layer::INVALID_ID;
3259 }
3260
3261 if (new_id != scroll_layer_id_mouse_currently_over_) {
3262 ScrollbarAnimationController* old_animation_controller =
3263 ScrollbarAnimationControllerForId(
3264 scroll_layer_id_mouse_currently_over_);
3265 if (old_animation_controller) {
3266 old_animation_controller->DidMouseLeave();
3267 }
3268 scroll_layer_id_mouse_currently_over_ = new_id;
3269 }
3270
3271 ScrollbarAnimationController* new_animation_controller =
3272 ScrollbarAnimationControllerForId(new_id);
3273 if (!new_animation_controller)
3246 return; 3274 return;
3247 3275
3248 bool scroll_on_main_thread = false; 3276 for (ScrollbarLayerImplBase* scrollbar : ScrollbarsFor(new_id))
3249 uint32_t main_thread_scrolling_reasons;
3250 LayerImpl* scroll_layer_impl = FindScrollLayerForDeviceViewportPoint(
3251 device_viewport_point, InputHandler::TOUCHSCREEN, layer_impl,
3252 &scroll_on_main_thread, &main_thread_scrolling_reasons);
3253
3254 // Scrollbars for the viewport are registered with the outer viewport layer.
3255 if (scroll_layer_impl == InnerViewportScrollLayer())
3256 scroll_layer_impl = OuterViewportScrollLayer();
3257
3258 if (scroll_on_main_thread || !scroll_layer_impl)
3259 return;
3260
3261 ScrollbarAnimationController* animation_controller =
3262 ScrollbarAnimationControllerForId(scroll_layer_impl->id());
3263 if (!animation_controller)
3264 return;
3265
3266 float distance_to_scrollbar = std::numeric_limits<float>::max();
3267 for (ScrollbarLayerImplBase* scrollbar :
3268 ScrollbarsFor(scroll_layer_impl->id()))
3269 distance_to_scrollbar = 3277 distance_to_scrollbar =
3270 std::min(distance_to_scrollbar, 3278 std::min(distance_to_scrollbar,
3271 DeviceSpaceDistanceToLayer(device_viewport_point, scrollbar)); 3279 DeviceSpaceDistanceToLayer(device_viewport_point, scrollbar));
3272 3280 new_animation_controller->DidMouseMoveNear(
3273 animation_controller->DidMouseMoveNear(distance_to_scrollbar / 3281 distance_to_scrollbar / active_tree_->device_scale_factor());
3274 active_tree_->device_scale_factor());
3275 } 3282 }
3276 3283
3277 void LayerTreeHostImpl::MouseLeave() { 3284 void LayerTreeHostImpl::MouseLeave() {
3278 for (auto& pair : scrollbar_animation_controllers_) 3285 for (auto& pair : scrollbar_animation_controllers_)
3279 pair.second->DidMouseMoveOffScrollbar(); 3286 pair.second->DidMouseLeave();
3280 3287 scroll_layer_id_mouse_currently_over_ = Layer::INVALID_ID;
3281 scroll_layer_id_when_mouse_over_scrollbar_ = Layer::INVALID_ID;
3282 }
3283
3284 void LayerTreeHostImpl::HandleMouseOverScrollbar(LayerImpl* layer_impl) {
3285 int new_id = Layer::INVALID_ID;
3286 if (layer_impl && layer_impl->ToScrollbarLayer())
3287 new_id = layer_impl->ToScrollbarLayer()->ScrollLayerId();
3288
3289 if (new_id == scroll_layer_id_when_mouse_over_scrollbar_)
3290 return;
3291
3292 ScrollbarAnimationController* old_animation_controller =
3293 ScrollbarAnimationControllerForId(
3294 scroll_layer_id_when_mouse_over_scrollbar_);
3295 if (old_animation_controller)
3296 old_animation_controller->DidMouseMoveOffScrollbar();
3297
3298 scroll_layer_id_when_mouse_over_scrollbar_ = new_id;
3299
3300 ScrollbarAnimationController* new_animation_controller =
3301 ScrollbarAnimationControllerForId(
3302 scroll_layer_id_when_mouse_over_scrollbar_);
3303 if (new_animation_controller)
3304 new_animation_controller->DidMouseMoveNear(0);
3305 } 3288 }
3306 3289
3307 void LayerTreeHostImpl::PinchGestureBegin() { 3290 void LayerTreeHostImpl::PinchGestureBegin() {
3308 pinch_gesture_active_ = true; 3291 pinch_gesture_active_ = true;
3309 client_->RenewTreePriority(); 3292 client_->RenewTreePriority();
3310 pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer(); 3293 pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer();
3311 active_tree_->SetCurrentlyScrollingLayer(viewport()->MainScrollLayer()); 3294 active_tree_->SetCurrentlyScrollingLayer(viewport()->MainScrollLayer());
3312 top_controls_manager_->PinchBegin(); 3295 top_controls_manager_->PinchBegin();
3313 } 3296 }
3314 3297
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
4101 if (is_visible) { 4084 if (is_visible) {
4102 worker_context_visibility_ = 4085 worker_context_visibility_ =
4103 worker_context->CacheController()->ClientBecameVisible(); 4086 worker_context->CacheController()->ClientBecameVisible();
4104 } else { 4087 } else {
4105 worker_context->CacheController()->ClientBecameNotVisible( 4088 worker_context->CacheController()->ClientBecameNotVisible(
4106 std::move(worker_context_visibility_)); 4089 std::move(worker_context_visibility_));
4107 } 4090 }
4108 } 4091 }
4109 4092
4110 } // namespace cc 4093 } // 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