Commit ea382e39 authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

Apply the mask layer gradient shader only when needed

ScrollableShelfView's layer is masked to create the gradient shader.
In fact, when the scrollable shelf is not in overflow mode, the mask
layer is not needed. This CL sets the mask layer to null when the
scrollable shelf is not in overflow mode.

Bug: 1045265
Change-Id: I32fce5bd13da47a1d0b89968a5be54cd68a13738
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2033540
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738053}
parent 6767b2e5
...@@ -878,7 +878,7 @@ void ScrollableShelfView::Layout() { ...@@ -878,7 +878,7 @@ void ScrollableShelfView::Layout() {
// Layer::Clone(), which may be triggered by screen rotation, does not copy // Layer::Clone(), which may be triggered by screen rotation, does not copy
// the mask layer. So we may need to reset the mask layer. // the mask layer. So we may need to reset the mask layer.
if (!layer()->layer_mask_layer()) { if (ShouldApplyMaskLayerGradientZone() && !layer()->layer_mask_layer()) {
DCHECK(!gradient_layer_delegate_->layer()->layer_mask_back_link()); DCHECK(!gradient_layer_delegate_->layer()->layer_mask_back_link());
layer()->SetMaskLayer(gradient_layer_delegate_->layer()); layer()->SetMaskLayer(gradient_layer_delegate_->layer());
} }
...@@ -942,8 +942,10 @@ void ScrollableShelfView::GetAccessibleNodeData(ui::AXNodeData* node_data) { ...@@ -942,8 +942,10 @@ void ScrollableShelfView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
} }
void ScrollableShelfView::OnBoundsChanged(const gfx::Rect& previous_bounds) { void ScrollableShelfView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
if (gradient_layer_delegate_->layer()->bounds() != layer()->bounds()) if (ShouldApplyMaskLayerGradientZone() &&
gradient_layer_delegate_->layer()->bounds() != layer()->bounds()) {
gradient_layer_delegate_->layer()->SetBounds(layer()->bounds()); gradient_layer_delegate_->layer()->SetBounds(layer()->bounds());
}
const gfx::Insets old_padding_insets = padding_insets_; const gfx::Insets old_padding_insets = padding_insets_;
const gfx::Vector2dF old_scroll_offset = scroll_offset_; const gfx::Vector2dF old_scroll_offset = scroll_offset_;
...@@ -1768,6 +1770,9 @@ void ScrollableShelfView::UpdateGradientZoneState() { ...@@ -1768,6 +1770,9 @@ void ScrollableShelfView::UpdateGradientZoneState() {
} }
void ScrollableShelfView::MaybeUpdateGradientZone() { void ScrollableShelfView::MaybeUpdateGradientZone() {
if (!ShouldApplyMaskLayerGradientZone())
return;
// Fade zones should be updated if: // Fade zones should be updated if:
// (1) Fade zone's visibility changes. // (1) Fade zone's visibility changes.
// (2) Fade zone should show and the arrow button's location changes. // (2) Fade zone should show and the arrow button's location changes.
...@@ -1786,15 +1791,21 @@ void ScrollableShelfView::MaybeUpdateGradientZone() { ...@@ -1786,15 +1791,21 @@ void ScrollableShelfView::MaybeUpdateGradientZone() {
if (!should_update_start_fade_zone && !should_update_end_fade_zone) if (!should_update_start_fade_zone && !should_update_end_fade_zone)
return; return;
if (should_update_start_fade_zone) PaintGradientZone(CalculateStartGradientZone(), CalculateEndGradientZone());
gradient_layer_delegate_->set_start_fade_zone(target_start_fade_zone); }
if (should_update_end_fade_zone) void ScrollableShelfView::PaintGradientZone(const FadeZone& start_rect,
gradient_layer_delegate_->set_end_fade_zone(target_end_fade_zone); const FadeZone& end_rect) {
gradient_layer_delegate_->set_start_fade_zone(start_rect);
gradient_layer_delegate_->set_end_fade_zone(end_rect);
SchedulePaint(); SchedulePaint();
} }
bool ScrollableShelfView::ShouldApplyMaskLayerGradientZone() const {
return layout_strategy_ != LayoutStrategy::kNotShowArrowButtons;
}
int ScrollableShelfView::GetActualScrollOffset( int ScrollableShelfView::GetActualScrollOffset(
int main_axis_scroll_distance, int main_axis_scroll_distance,
LayoutStrategy layout_strategy) const { LayoutStrategy layout_strategy) const {
...@@ -2141,6 +2152,15 @@ void ScrollableShelfView::UpdateScrollOffset(float target_offset) { ...@@ -2141,6 +2152,15 @@ void ScrollableShelfView::UpdateScrollOffset(float target_offset) {
const bool strategy_needs_update = (layout_strategy_ != new_strategy); const bool strategy_needs_update = (layout_strategy_ != new_strategy);
if (strategy_needs_update) { if (strategy_needs_update) {
layout_strategy_ = new_strategy; layout_strategy_ = new_strategy;
const bool has_gradient_zone = layer()->layer_mask_layer();
const bool should_have_gradient_zone = ShouldApplyMaskLayerGradientZone();
if (has_gradient_zone && !should_have_gradient_zone) {
PaintGradientZone(FadeZone(), FadeZone());
layer()->SetMaskLayer(nullptr);
} else if (!has_gradient_zone && should_have_gradient_zone) {
gradient_layer_delegate_->layer()->SetBounds(layer()->bounds());
layer()->SetMaskLayer(gradient_layer_delegate_->layer());
}
InvalidateLayout(); InvalidateLayout();
} }
......
...@@ -312,6 +312,11 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView, ...@@ -312,6 +312,11 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView,
// different from the actual values. // different from the actual values.
void MaybeUpdateGradientZone(); void MaybeUpdateGradientZone();
void PaintGradientZone(const FadeZone& start_gradient_zone,
const FadeZone& end_gradient_zone);
bool ShouldApplyMaskLayerGradientZone() const;
// Returns the actual scroll offset for the given scroll distance along the // Returns the actual scroll offset for the given scroll distance along the
// main axis under the specific layout strategy. When the left arrow button // main axis under the specific layout strategy. When the left arrow button
// shows, |shelf_view_| is translated due to the change in // shows, |shelf_view_| is translated due to the change in
......
...@@ -241,6 +241,20 @@ TEST_F(ScrollableShelfViewTest, CorrectUIAfterDisplayRotationLongToShort) { ...@@ -241,6 +241,20 @@ TEST_F(ScrollableShelfViewTest, CorrectUIAfterDisplayRotationLongToShort) {
EXPECT_FALSE(scrollable_shelf_view_->ShouldAdjustForTest()); EXPECT_FALSE(scrollable_shelf_view_->ShouldAdjustForTest());
} }
// Verifies that the mask layer gradient shader is not applied when no arrow
// button shows.
TEST_F(ScrollableShelfViewTest, VerifyApplyMaskGradientShaderWhenNeeded) {
AddAppShortcut();
ASSERT_EQ(ScrollableShelfView::LayoutStrategy::kNotShowArrowButtons,
scrollable_shelf_view_->layout_strategy_for_test());
EXPECT_FALSE(scrollable_shelf_view_->layer()->layer_mask_layer());
AddAppShortcutsUntilOverflow();
ASSERT_EQ(ScrollableShelfView::LayoutStrategy::kShowRightArrowButton,
scrollable_shelf_view_->layout_strategy_for_test());
EXPECT_TRUE(scrollable_shelf_view_->layer()->layer_mask_layer());
}
// When hovering mouse on a shelf icon, the tooltip only shows for the visible // When hovering mouse on a shelf icon, the tooltip only shows for the visible
// icon (see https://crbug.com/997807). // icon (see https://crbug.com/997807).
TEST_F(ScrollableShelfViewTest, NotShowTooltipForHiddenIcons) { TEST_F(ScrollableShelfViewTest, NotShowTooltipForHiddenIcons) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment