Chromium Code Reviews| Index: ui/views/controls/scroll_view.cc |
| diff --git a/ui/views/controls/scroll_view.cc b/ui/views/controls/scroll_view.cc |
| index 74cefcc61f7e9dd75aea8fc1593af824d7066290..533f4821edc51aa7e25e2f21d46c29a8a660002e 100644 |
| --- a/ui/views/controls/scroll_view.cc |
| +++ b/ui/views/controls/scroll_view.cc |
| @@ -61,13 +61,16 @@ int CheckScrollBounds(int viewport_size, int content_size, int current_pos) { |
| } |
| // Make sure the content is not scrolled out of bounds |
| -void ConstrainScrollToBounds(View* viewport, View* view) { |
| +void ConstrainScrollToBounds(View* viewport, |
| + View* view, |
| + bool scroll_with_layers_enabled) { |
| if (!view) |
| return; |
| // Note that even when ScrollView::ScrollsWithLayers() is true, the header row |
| // scrolls by repainting. |
| - const bool scrolls_with_layers = viewport->layer() != nullptr; |
| + const bool scrolls_with_layers = |
| + scroll_with_layers_enabled && viewport->layer() != nullptr; |
| if (scrolls_with_layers) { |
| DCHECK(view->layer()); |
| DCHECK_EQ(0, view->x()); |
| @@ -166,8 +169,11 @@ ScrollView::ScrollView() |
| vert_sb_->set_controller(this); |
| corner_view_->SetVisible(false); |
| - if (!base::FeatureList::IsEnabled(kToolkitViewsScrollWithLayers)) |
| + scroll_with_layers_enabled_ = |
| + base::FeatureList::IsEnabled(kToolkitViewsScrollWithLayers); |
| + if (!scroll_with_layers_enabled_) |
| return; |
| + |
| EnableViewPortLayer(); |
| } |
| @@ -450,8 +456,10 @@ void ScrollView::Layout() { |
| if (header_) |
| header_->Layout(); |
| - ConstrainScrollToBounds(header_viewport_, header_); |
| - ConstrainScrollToBounds(contents_viewport_, contents_); |
| + ConstrainScrollToBounds(header_viewport_, header_, |
| + scroll_with_layers_enabled_); |
| + ConstrainScrollToBounds(contents_viewport_, contents_, |
| + scroll_with_layers_enabled_); |
| SchedulePaint(); |
| UpdateScrollBarPositions(); |
| } |
| @@ -527,6 +535,16 @@ void ScrollView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| UpdateBorder(); |
| } |
| +void ScrollView::ViewHierarchyChanged( |
| + const ViewHierarchyChangedDetails& details) { |
| + if (details.is_add) |
|
sky
2017/04/18 15:35:47
This should be:
details.is_add && Contains(details
ananta
2017/04/18 22:22:39
Done.
|
| + EnableLayeringRecursivelyForChild(details.child); |
| +} |
| + |
| +void ScrollView::OnChildLayerChanged(View* child) { |
| + EnableViewPortLayer(); |
| +} |
| + |
| void ScrollView::ScrollToPosition(ScrollBar* source, int position) { |
| if (!contents_) |
| return; |
| @@ -717,12 +735,18 @@ void ScrollView::ScrollToOffset(const gfx::ScrollOffset& offset) { |
| } |
| bool ScrollView::ScrollsWithLayers() const { |
| + if (!scroll_with_layers_enabled_) |
| + return false; |
| // Just check for the presence of a layer since it's cheaper than querying the |
| // Feature flag each time. |
| return contents_viewport_->layer() != nullptr; |
| } |
| void ScrollView::EnableViewPortLayer() { |
| + if (viewport_layer_enabled_) |
| + return; |
| + |
| + viewport_layer_enabled_ = true; |
| background_color_ = SK_ColorWHITE; |
| contents_viewport_->set_background( |
| Background::CreateSolidBackground(background_color_)); |
| @@ -763,6 +787,19 @@ void ScrollView::UpdateBorder() { |
| : ui::NativeTheme::kColorId_UnfocusedBorderColor))); |
| } |
| +bool ScrollView::EnableLayeringRecursivelyForChild(View* view) { |
| + if (view->layer()) { |
|
sky
2017/04/18 15:35:47
Early out if viewport_layer_enabled_ or scroll_wit
ananta
2017/04/18 22:22:39
Done.
|
| + EnableViewPortLayer(); |
| + return true; |
| + } |
| + |
| + for (int i = 0; i < view->child_count(); ++i) { |
| + if (EnableLayeringRecursivelyForChild(view->child_at(i))) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| // VariableRowHeightScrollHelper ---------------------------------------------- |
| VariableRowHeightScrollHelper::VariableRowHeightScrollHelper( |