| 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..fc3c76e9fb2e002d1bddfedecf3f9857196d5c0b 100644
|
| --- a/ui/views/controls/scroll_view.cc
|
| +++ b/ui/views/controls/scroll_view.cc
|
| @@ -7,6 +7,7 @@
|
| #include "base/feature_list.h"
|
| #include "base/logging.h"
|
| #include "base/macros.h"
|
| +#include "base/threading/thread_task_runner_handle.h"
|
| #include "ui/base/material_design/material_design_controller.h"
|
| #include "ui/events/event.h"
|
| #include "ui/gfx/canvas.h"
|
| @@ -62,7 +63,7 @@ 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) {
|
| - if (!view)
|
| + if (!view || !view->layer())
|
| return;
|
|
|
| // Note that even when ScrollView::ScrollsWithLayers() is true, the header row
|
| @@ -102,6 +103,11 @@ int AdjustPosition(int current_position,
|
| return (new_position > max_position) ? max_position : new_position;
|
| }
|
|
|
| +// Set if the kToolkitViewsScrollWithLayers feature is enabled.
|
| +// TODO(ananta)
|
| +// Remove this when the feature is enabled by default.
|
| +bool g_scroll_with_layers_enabled = false;
|
| +
|
| } // namespace
|
|
|
| // Viewport contains the contents View of the ScrollView.
|
| @@ -152,7 +158,8 @@ ScrollView::ScrollView()
|
| min_height_(-1),
|
| max_height_(-1),
|
| background_color_(SK_ColorTRANSPARENT),
|
| - hide_horizontal_scrollbar_(false) {
|
| + hide_horizontal_scrollbar_(false),
|
| + weak_ptr_factory_(this) {
|
| set_notify_enter_exit_on_child(true);
|
|
|
| AddChildView(contents_viewport_);
|
| @@ -166,8 +173,11 @@ ScrollView::ScrollView()
|
| vert_sb_->set_controller(this);
|
| corner_view_->SetVisible(false);
|
|
|
| - if (!base::FeatureList::IsEnabled(kToolkitViewsScrollWithLayers))
|
| + g_scroll_with_layers_enabled =
|
| + base::FeatureList::IsEnabled(kToolkitViewsScrollWithLayers);
|
| + if (!g_scroll_with_layers_enabled)
|
| return;
|
| +
|
| EnableViewPortLayer();
|
| }
|
|
|
| @@ -527,6 +537,10 @@ void ScrollView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
|
| UpdateBorder();
|
| }
|
|
|
| +void ScrollView::ChildLayerAdded() {
|
| + EnableViewPortLayer();
|
| +}
|
| +
|
| void ScrollView::ScrollToPosition(ScrollBar* source, int position) {
|
| if (!contents_)
|
| return;
|
| @@ -717,12 +731,18 @@ void ScrollView::ScrollToOffset(const gfx::ScrollOffset& offset) {
|
| }
|
|
|
| bool ScrollView::ScrollsWithLayers() const {
|
| + if (!g_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_));
|
|
|