Commit d4804851 authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Reduce layers in overview mode

* Change ShieldWidget's layer to NOW_DRAWN because it's always transparent.
* Remove layer on image_view/title_view
* Create an layer for unsnappable lable on demand.

Bug: 897870
Test: no functional change. Updated the unit test.
Change-Id: I23093ade07bc943ad16572d2704b78b13883c3bd
Reviewed-on: https://chromium-review.googlesource.com/c/1295335
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarSammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601859}
parent ea76f526
...@@ -209,7 +209,7 @@ std::unique_ptr<views::Widget> CreateBackgroundWidget(aura::Window* root_window, ...@@ -209,7 +209,7 @@ std::unique_ptr<views::Widget> CreateBackgroundWidget(aura::Window* root_window,
wm::GetWindowState(widget_window)->set_ignored_by_shelf(true); wm::GetWindowState(widget_window)->set_ignored_by_shelf(true);
if (params.layer_type == ui::LAYER_SOLID_COLOR) { if (params.layer_type == ui::LAYER_SOLID_COLOR) {
widget_window->layer()->SetColor(background_color); widget_window->layer()->SetColor(background_color);
} else { } else if (params.layer_type == ui::LAYER_TEXTURED) {
views::View* content_view = new views::View(); views::View* content_view = new views::View();
content_view->SetBackground(std::make_unique<BackgroundWith1PxBorder>( content_view->SetBackground(std::make_unique<BackgroundWith1PxBorder>(
background_color, border_color, border_thickness, border_radius)); background_color, border_color, border_thickness, border_radius));
......
...@@ -1091,7 +1091,7 @@ void WindowGrid::InitShieldWidget() { ...@@ -1091,7 +1091,7 @@ void WindowGrid::InitShieldWidget() {
? 1.f ? 1.f
: 0.f; : 0.f;
shield_widget_ = CreateBackgroundWidget( shield_widget_ = CreateBackgroundWidget(
root_window_, ui::LAYER_SOLID_COLOR, SK_ColorTRANSPARENT, 0, 0, root_window_, ui::LAYER_NOT_DRAWN, SK_ColorTRANSPARENT, 0, 0,
SK_ColorTRANSPARENT, initial_opacity, /*parent=*/nullptr, SK_ColorTRANSPARENT, initial_opacity, /*parent=*/nullptr,
/*stack_on_top=*/true); /*stack_on_top=*/true);
aura::Window* widget_window = shield_widget_->GetNativeWindow(); aura::Window* widget_window = shield_widget_->GetNativeWindow();
......
...@@ -316,38 +316,44 @@ class WindowSelectorItem::CaptionContainerView : public views::View { ...@@ -316,38 +316,44 @@ class WindowSelectorItem::CaptionContainerView : public views::View {
close_button_(close_button) { close_button_(close_button) {
AddChildView(listener_button_); AddChildView(listener_button_);
// Helper function to add a child view to a parent view and make it paint to
// layer.
auto add_child_with_layer = [](views::View* parent, views::View* child) {
child->SetPaintToLayer();
child->layer()->SetFillsBoundsOpaquely(false);
parent->AddChildView(child);
};
header_view_ = new views::View(); header_view_ = new views::View();
views::BoxLayout* layout = views::BoxLayout* layout =
header_view_->SetLayoutManager(std::make_unique<views::BoxLayout>( header_view_->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::kHorizontal, gfx::Insets(), views::BoxLayout::kHorizontal, gfx::Insets(),
kHorizontalLabelPaddingDp)); kHorizontalLabelPaddingDp));
if (image_view_) if (image_view_)
add_child_with_layer(header_view_, image_view_); header_view_->AddChildView(image_view_);
add_child_with_layer(header_view_, title_label_); header_view_->AddChildView(title_label_);
add_child_with_layer(header_view_, close_button_); AddChildWithLayer(header_view_, close_button_);
add_child_with_layer(this, header_view_); AddChildWithLayer(this, header_view_);
layout->SetFlexForView(title_label_, 1); layout->SetFlexForView(title_label_, 1);
}
// Use |cannot_snap_container_| to specify the padding surrounding ~CaptionContainerView() override {
// |cannot_snap_label_| and to give the label rounded corners. // If the cannot snap container was never created, delete cannot_snap_label_
cannot_snap_container_ = new RoundedRectView( // manually.
kSplitviewLabelRoundRectRadiusDp, kSplitviewLabelBackgroundColor); if (!cannot_snap_container_)
cannot_snap_container_->SetLayoutManager(std::make_unique<views::BoxLayout>( delete cannot_snap_label_;
views::BoxLayout::kVertical, }
gfx::Insets(kSplitviewLabelVerticalInsetDp,
kSplitviewLabelHorizontalInsetDp))); RoundedRectView* GetCannotSnapContainer() {
cannot_snap_container_->AddChildView(cannot_snap_label_); if (!cannot_snap_container_) {
cannot_snap_container_->set_can_process_events_within_subtree(false); // Use |cannot_snap_container_| to specify the padding surrounding
add_child_with_layer(this, cannot_snap_container_); // |cannot_snap_label_| and to give the label rounded corners.
cannot_snap_container_->layer()->SetOpacity(0.f); cannot_snap_container_ = new RoundedRectView(
kSplitviewLabelRoundRectRadiusDp, kSplitviewLabelBackgroundColor);
cannot_snap_container_->SetLayoutManager(
std::make_unique<views::BoxLayout>(
views::BoxLayout::kVertical,
gfx::Insets(kSplitviewLabelVerticalInsetDp,
kSplitviewLabelHorizontalInsetDp)));
cannot_snap_container_->AddChildView(cannot_snap_label_);
cannot_snap_container_->set_can_process_events_within_subtree(false);
AddChildWithLayer(this, cannot_snap_container_);
cannot_snap_container_->layer()->SetOpacity(0.f);
Layout();
}
return cannot_snap_container_;
} }
ShieldButton* listener_button() { return listener_button_; } ShieldButton* listener_button() { return listener_button_; }
...@@ -370,8 +376,11 @@ class WindowSelectorItem::CaptionContainerView : public views::View { ...@@ -370,8 +376,11 @@ class WindowSelectorItem::CaptionContainerView : public views::View {
} }
void SetCannotSnapLabelVisibility(bool visible) { void SetCannotSnapLabelVisibility(bool visible) {
if (!cannot_snap_container_ && !visible)
return;
DoSplitviewOpacityAnimation( DoSplitviewOpacityAnimation(
cannot_snap_container_->layer(), GetCannotSnapContainer()->layer(),
visible ? SPLITVIEW_ANIMATION_SELECTOR_ITEM_FADE_IN visible ? SPLITVIEW_ANIMATION_SELECTOR_ITEM_FADE_IN
: SPLITVIEW_ANIMATION_SELECTOR_ITEM_FADE_OUT); : SPLITVIEW_ANIMATION_SELECTOR_ITEM_FADE_OUT);
} }
...@@ -399,12 +408,14 @@ class WindowSelectorItem::CaptionContainerView : public views::View { ...@@ -399,12 +408,14 @@ class WindowSelectorItem::CaptionContainerView : public views::View {
backdrop_bounds_ = bounds; backdrop_bounds_ = bounds;
backdrop_bounds_.Inset(0, visible_height, 0, 0); backdrop_bounds_.Inset(0, visible_height, 0, 0);
// Position the cannot snap label in the middle of the item, minus the if (cannot_snap_container_) {
// title. // Position the cannot snap label in the middle of the item, minus the
gfx::Rect cannot_snap_bounds = GetLocalBounds(); // title.
cannot_snap_bounds.Inset(0, visible_height, 0, 0); gfx::Rect cannot_snap_bounds = GetLocalBounds();
cannot_snap_bounds.ClampToCenteredSize(label_size); cannot_snap_bounds.Inset(0, visible_height, 0, 0);
cannot_snap_container_->SetBoundsRect(cannot_snap_bounds); cannot_snap_bounds.ClampToCenteredSize(label_size);
cannot_snap_container_->SetBoundsRect(cannot_snap_bounds);
}
// Position the header at the top. The left should be indented to match // Position the header at the top. The left should be indented to match
// the transformed window, but not the right because the close button hit // the transformed window, but not the right because the close button hit
...@@ -446,11 +457,19 @@ class WindowSelectorItem::CaptionContainerView : public views::View { ...@@ -446,11 +457,19 @@ class WindowSelectorItem::CaptionContainerView : public views::View {
} }
} }
// Helper function to add a child view to a parent view and make it paint to
// layer.
static void AddChildWithLayer(views::View* parent, views::View* child) {
child->SetPaintToLayer();
child->layer()->SetFillsBoundsOpaquely(false);
parent->AddChildView(child);
};
ShieldButton* listener_button_; ShieldButton* listener_button_;
views::ImageView* image_view_; views::ImageView* image_view_;
views::Label* title_label_; views::Label* title_label_;
views::Label* cannot_snap_label_; views::Label* cannot_snap_label_;
RoundedRectView* cannot_snap_container_; RoundedRectView* cannot_snap_container_ = nullptr;
views::ImageButton* close_button_; views::ImageButton* close_button_;
// View which contains the icon, title and close button. // View which contains the icon, title and close button.
views::View* header_view_ = nullptr; views::View* header_view_ = nullptr;
......
...@@ -4461,25 +4461,29 @@ TEST_F(SplitViewWindowSelectorTest, OverviewUnsnappableIndicatorVisibility) { ...@@ -4461,25 +4461,29 @@ TEST_F(SplitViewWindowSelectorTest, OverviewUnsnappableIndicatorVisibility) {
WindowSelectorItem* unsnappable_selector_item = WindowSelectorItem* unsnappable_selector_item =
GetWindowItemForWindow(grid_index, unsnappable_window.get()); GetWindowItemForWindow(grid_index, unsnappable_window.get());
// Note: Check opacities of |cannot_snap_label_view_|'s parent (which handles // Note: the container for |cannot_snap_label_view_| will be created
// the padding and rounded corners) is actually the item whose layer's opacity // on demand, and its parent remains null until the container is created.
// gets altered. EXPECT_FALSE(snappable_selector_item->cannot_snap_label_view_->parent());
ui::Layer* snappable_layer = ASSERT_FALSE(unsnappable_selector_item->cannot_snap_label_view_->parent());
snappable_selector_item->cannot_snap_label_view_->parent()->layer();
ui::Layer* unsnappable_layer =
unsnappable_selector_item->cannot_snap_label_view_->parent()->layer();
ASSERT_TRUE(snappable_layer);
ASSERT_TRUE(unsnappable_layer);
EXPECT_EQ(0.f, snappable_layer->opacity());
EXPECT_EQ(0.f, unsnappable_layer->opacity());
// Snap the extra snappable window to enter split view mode. // Snap the extra snappable window to enter split view mode.
split_view_controller()->SnapWindow(window1.get(), SplitViewController::LEFT); split_view_controller()->SnapWindow(window1.get(), SplitViewController::LEFT);
ASSERT_TRUE(split_view_controller()->IsSplitViewModeActive()); ASSERT_TRUE(split_view_controller()->IsSplitViewModeActive());
EXPECT_FALSE(snappable_selector_item->cannot_snap_label_view_->parent());
EXPECT_EQ(0.f, snappable_layer->opacity()); ASSERT_TRUE(unsnappable_selector_item->cannot_snap_label_view_->parent());
ui::Layer* unsnappable_layer =
unsnappable_selector_item->cannot_snap_label_view_->parent()->layer();
EXPECT_EQ(1.f, unsnappable_layer->opacity()); EXPECT_EQ(1.f, unsnappable_layer->opacity());
// Exiting the splitview will hide the unsnappable label.
const gfx::Rect divider_bounds =
GetSplitViewDividerBounds(/*is_dragging=*/false);
ui::test::EventGenerator* generator = GetEventGenerator();
generator->set_current_location(divider_bounds.CenterPoint());
generator->DragMouseTo(0, 0);
EXPECT_FALSE(split_view_controller()->IsSplitViewModeActive());
EXPECT_EQ(0.f, unsnappable_layer->opacity());
} }
// Test that when splitview mode and overview mode are both active at the same // Test that when splitview mode and overview mode are both active at the same
......
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