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

Unified Diff: cc/layers/scrollbar_layer_impl_base.cc

Issue 254643002: Scrollbars should get notifications from all scrollable layers up to container. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test issues. Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | cc/layers/scrollbar_layer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/layers/scrollbar_layer_impl_base.cc
diff --git a/cc/layers/scrollbar_layer_impl_base.cc b/cc/layers/scrollbar_layer_impl_base.cc
index 978e8b8bb0e8eb5b81ba9432cca0d8969564ff4a..dc9b92ec683731ef3f52a942878221461e8f9ae7 100644
--- a/cc/layers/scrollbar_layer_impl_base.cc
+++ b/cc/layers/scrollbar_layer_impl_base.cc
@@ -47,16 +47,44 @@ ScrollbarLayerImplBase* ScrollbarLayerImplBase::ToScrollbarLayer() {
return this;
}
+namespace {
+
+typedef void (LayerImpl::*ScrollbarRegistrationOperation)(
+ ScrollbarLayerImplBase*);
+
+void RegisterScrollbarWithLayers(ScrollbarLayerImplBase* scrollbar,
+ LayerImpl* container_layer,
+ LayerImpl* scroll_layer,
+ ScrollbarRegistrationOperation operation) {
+ if (!container_layer || !scroll_layer)
+ return;
+
+ DCHECK(scrollbar);
+
+ // Scrollbars must be notifed of changes to their scroll and container layers
+ // and all scrollable layers in between.
+ for (LayerImpl* current_layer = scroll_layer;
+ current_layer && current_layer != container_layer->parent();
+ current_layer = current_layer->parent()) {
+ // TODO(wjmaclean) We shouldn't need to exempt the scroll_layer from the
+ // scrollable() test below. https://crbug.com/367858.
+ if (current_layer->scrollable() || current_layer == container_layer ||
+ current_layer == scroll_layer)
+ (current_layer->*operation)(scrollbar);
+ }
+}
+} // namespace
+
void ScrollbarLayerImplBase::SetScrollLayerById(int id) {
LayerImpl* scroll_layer = layer_tree_impl()->LayerById(id);
if (scroll_layer_ == scroll_layer)
return;
- if (scroll_layer_)
- scroll_layer_->RemoveScrollbar(this);
+ RegisterScrollbarWithLayers(
+ this, clip_layer_, scroll_layer_, &LayerImpl::RemoveScrollbar);
scroll_layer_ = scroll_layer;
- if (scroll_layer_)
- scroll_layer_->AddScrollbar(this);
+ RegisterScrollbarWithLayers(
+ this, clip_layer_, scroll_layer_, &LayerImpl::AddScrollbar);
}
void ScrollbarLayerImplBase::SetClipLayerById(int id) {
@@ -64,11 +92,11 @@ void ScrollbarLayerImplBase::SetClipLayerById(int id) {
if (clip_layer_ == clip_layer)
return;
- if (clip_layer_)
- clip_layer_->RemoveScrollbar(this);
+ RegisterScrollbarWithLayers(
+ this, clip_layer_, scroll_layer_, &LayerImpl::RemoveScrollbar);
clip_layer_ = clip_layer;
- if (clip_layer_)
- clip_layer_->AddScrollbar(this);
+ RegisterScrollbarWithLayers(
+ this, clip_layer_, scroll_layer_, &LayerImpl::AddScrollbar);
}
gfx::Rect ScrollbarLayerImplBase::ScrollbarLayerRectToContentRect(
« no previous file with comments | « no previous file | cc/layers/scrollbar_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698