Commit 54ab4083 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

overview: Keep no recent items centered.

Test: manual
Bug: 818373
Change-Id: I05efc0528fbee5d088947fc2893267d4a601ba93
Reviewed-on: https://chromium-review.googlesource.com/951633Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541860}
parent 73fc9d2e
......@@ -173,21 +173,28 @@ class WindowGrid::ShieldView : public views::View {
label_container_->SetVisible(visible);
}
bool IsLabelVisible() const { return label_container_->visible(); }
protected:
// views::View:
void Layout() override {
background_view_->SetBoundsRect(GetLocalBounds());
gfx::Rect GetLabelBounds() const {
return label_container_->GetBoundsInScreen();
}
// ShieldView takes up the whole workspace since it changes opacity of the
// whole wallpaper. The bounds of the grid may be smaller in some cases of
// splitview. The label should be centered in the bounds of the grid.
void SetGridBounds(const gfx::Rect& bounds) {
const int label_width = label_->GetPreferredSize().width() +
2 * kNoItemsIndicatorHorizontalPaddingDp;
gfx::Rect label_container_bounds = GetLocalBounds();
gfx::Rect label_container_bounds = bounds;
label_container_bounds.ClampToCenteredSize(
gfx::Size(label_width, kNoItemsIndicatorHeightDp));
label_container_->SetBoundsRect(label_container_bounds);
}
bool IsLabelVisible() const { return label_container_->visible(); }
protected:
// views::View:
void Layout() override { background_view_->SetBoundsRect(GetLocalBounds()); }
private:
// Owned by views heirarchy.
views::View* background_view_ = nullptr;
......@@ -509,6 +516,8 @@ void WindowGrid::AddItem(aura::Window* window) {
window_list_.push_back(
std::make_unique<WindowSelectorItem>(window, window_selector_, this));
window_list_.back()->PrepareForOverview();
if (shield_view_)
shield_view_->SetLabelVisibility(false);
PositionWindows(/*animate=*/true);
}
......@@ -524,6 +533,8 @@ void WindowGrid::RemoveItem(WindowSelectorItem* selector_item) {
window_state_observer_.Remove(
wm::GetWindowState(selector_item->GetWindow()));
window_list_.erase(iter);
if (shield_view_)
shield_view_->SetLabelVisibility(empty());
}
}
......@@ -555,6 +566,8 @@ void WindowGrid::WindowClosing(WindowSelectorItem* window) {
void WindowGrid::SetBoundsAndUpdatePositions(const gfx::Rect& bounds) {
bounds_ = bounds;
if (shield_view_)
shield_view_->SetGridBounds(bounds_);
PositionWindows(/*animate=*/true);
}
......@@ -562,6 +575,8 @@ void WindowGrid::SetBoundsAndUpdatePositionsIgnoringWindow(
const gfx::Rect& bounds,
WindowSelectorItem* ignored_item) {
bounds_ = bounds;
if (shield_view_)
shield_view_->SetGridBounds(bounds_);
PositionWindows(/*animate=*/true, ignored_item);
}
......@@ -672,6 +687,13 @@ bool WindowGrid::IsNoItemsIndicatorLabelVisibleForTesting() {
return shield_view_ && shield_view_->IsLabelVisible();
}
gfx::Rect WindowGrid::GetNoItemsIndicatorLabelBoundsForTesting() const {
if (!shield_view_)
return gfx::Rect();
return shield_view_->GetLabelBounds();
}
void WindowGrid::SetWindowListAnimationStates(
WindowSelectorItem* selected_item,
WindowSelector::OverviewTransition transition) {
......@@ -771,6 +793,7 @@ void WindowGrid::InitShieldWidget() {
shield_view_ = new ShieldView();
shield_view_->SetBackgroundColor(shield_color);
shield_view_->SetLabelVisibility(empty());
shield_view_->SetGridBounds(bounds_);
shield_widget_->SetContentsView(shield_view_);
shield_widget_->SetOpacity(initial_opacity);
}
......
......@@ -162,6 +162,8 @@ class ASH_EXPORT WindowGrid : public aura::WindowObserver,
bool IsNoItemsIndicatorLabelVisibleForTesting();
gfx::Rect GetNoItemsIndicatorLabelBoundsForTesting() const;
WindowSelector* window_selector() { return window_selector_; }
void set_window_animation_observer(
......
......@@ -19,6 +19,7 @@
#include "ash/public/cpp/window_properties.h"
#include "ash/screen_util.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_constants.h"
#include "ash/shelf/shelf_view_test_api.h"
#include "ash/shell.h"
#include "ash/shell_test_api.h"
......@@ -2060,6 +2061,53 @@ TEST_F(WindowSelectorTest, OverviewNoWindowsIndicator) {
->IsNoItemsIndicatorLabelVisibleForTesting());
}
// Verify that the overview no windows indicator position is as expected.
TEST_F(WindowSelectorTest, OverviewNoWindowsIndicatorPosition) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kAshEnableNewOverviewUi);
UpdateDisplay("400x300");
// Midpoint of height minus shelf.
const int expected_y = (300 - kShelfSize) / 2;
// Helper to check points. Uses EXPECT_NEAR on each coordinate to account for
// rounding.
auto check_point = [](const gfx::Point& expected, const gfx::Point& actual) {
EXPECT_NEAR(expected.x(), actual.x(), 1);
EXPECT_NEAR(expected.y(), actual.y(), 1);
};
ToggleOverview();
ASSERT_TRUE(window_selector());
// Verify that originally the label is in the center of the workspace.
WindowGrid* grid = window_selector()->grid_list_for_testing()[0].get();
check_point(gfx::Point(200, expected_y),
grid->GetNoItemsIndicatorLabelBoundsForTesting().CenterPoint());
// Verify that when grid bounds are on the left, the label is centered on the
// left side of the workspace.
grid->SetBoundsAndUpdatePositions(gfx::Rect(0, 0, 200, 300 - kShelfSize));
check_point(gfx::Point(100, expected_y),
grid->GetNoItemsIndicatorLabelBoundsForTesting().CenterPoint());
// Verify that when grid bounds are on the right, the label is centered on the
// right side of the workspace.
grid->SetBoundsAndUpdatePositions(gfx::Rect(200, 0, 200, 300 - kShelfSize));
check_point(gfx::Point(300, expected_y),
grid->GetNoItemsIndicatorLabelBoundsForTesting().CenterPoint());
// Verify that after rotating the display, the label is centered in the
// workspace 300x(400-shelf).
display::Screen* screen = display::Screen::GetScreen();
const display::Display& display = screen->GetPrimaryDisplay();
display_manager()->SetDisplayRotation(
display.id(), display::Display::ROTATE_90,
display::Display::RotationSource::ACTIVE);
check_point(gfx::Point(150, (400 - kShelfSize) / 2),
grid->GetNoItemsIndicatorLabelBoundsForTesting().CenterPoint());
}
// Verify that when opening overview mode with multiple displays, the no items
// indicator appears on the grid(s) if it has no windows.
TEST_F(WindowSelectorTest, OverviewNoWindowsIndicatorMultiDisplay) {
......
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