| 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..27e5aa4bfbb2a9df2f2e354ca9a81089a8212cb7 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 && Contains(details.parent) && !viewport_layer_enabled_)
|
| + 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,22 @@ void ScrollView::UpdateBorder() {
|
| : ui::NativeTheme::kColorId_UnfocusedBorderColor)));
|
| }
|
|
|
| +bool ScrollView::EnableLayeringRecursivelyForChild(View* view) {
|
| + if (viewport_layer_enabled_ || scroll_with_layers_enabled_)
|
| + return true;
|
| +
|
| + if (view->layer()) {
|
| + 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(
|
|
|