Commit 316c18ce authored by mgiuca@chromium.org's avatar mgiuca@chromium.org

ChromeOS: The centered app list's top is now forced to be >= 10.

Previously, in small space environments (e.g., low resolution or big
virtual keyboard), the app list's top would disappear off screen. Now,
it is forced below the screen top (with a 10px margin), even if it means
forcing the bottom further off screen.

BUG=371681

Review URL: https://codereview.chromium.org/281523002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270115 0039d316-1c4b-4281-b951-d872f2087c98
parent 6f5517f5
...@@ -44,6 +44,9 @@ const int kMaxOverScrollShift = 48; ...@@ -44,6 +44,9 @@ const int kMaxOverScrollShift = 48;
// result of minimal bubble arrow sizes and offsets. // result of minimal bubble arrow sizes and offsets.
const int kMinimalAnchorPositionOffset = 57; const int kMinimalAnchorPositionOffset = 57;
// The minimal margin (in pixels) around the app list when in centered mode.
const int kMinimalCenteredAppListMargin = 10;
ui::Layer* GetLayer(views::Widget* widget) { ui::Layer* GetLayer(views::Widget* widget) {
return widget->GetNativeView()->layer(); return widget->GetNativeView()->layer();
} }
...@@ -115,8 +118,11 @@ gfx::Vector2d GetAnchorPositionOffsetToShelf( ...@@ -115,8 +118,11 @@ gfx::Vector2d GetAnchorPositionOffsetToShelf(
} }
// Gets the point at the center of the display that a particular view is on. // Gets the point at the center of the display that a particular view is on.
// This calculation excludes the virtual keyboard area. // This calculation excludes the virtual keyboard area. If the height of the
gfx::Point GetCenterOfDisplayForView(const views::View* view) { // display area is less than |minimum_height|, its bottom will be extended to
// that height (so that the app list never starts above the top of the screen).
gfx::Point GetCenterOfDisplayForView(const views::View* view,
int minimum_height) {
gfx::Rect bounds = Shell::GetScreen()->GetDisplayNearestWindow( gfx::Rect bounds = Shell::GetScreen()->GetDisplayNearestWindow(
view->GetWidget()->GetNativeView()).bounds(); view->GetWidget()->GetNativeView()).bounds();
...@@ -129,9 +135,18 @@ gfx::Point GetCenterOfDisplayForView(const views::View* view) { ...@@ -129,9 +135,18 @@ gfx::Point GetCenterOfDisplayForView(const views::View* view) {
if (keyboard_controller && keyboard_controller->keyboard_visible()) if (keyboard_controller && keyboard_controller->keyboard_visible())
bounds.Subtract(keyboard_controller->current_keyboard_bounds()); bounds.Subtract(keyboard_controller->current_keyboard_bounds());
// Apply the |minimum_height|.
if (bounds.height() < minimum_height)
bounds.set_height(minimum_height);
return bounds.CenterPoint(); return bounds.CenterPoint();
} }
// Gets the minimum height of the rectangle to center the app list in.
int GetMinimumBoundsHeightForAppList(const app_list::AppListView* app_list) {
return app_list->bounds().height() + 2 * kMinimalCenteredAppListMargin;
}
} // namespace } // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -189,15 +204,19 @@ void AppListController::SetVisible(bool visible, aura::Window* window) { ...@@ -189,15 +204,19 @@ void AppListController::SetVisible(bool visible, aura::Window* window) {
Shelf::ForWindow(container)->GetAppListButtonView(); Shelf::ForWindow(container)->GetAppListButtonView();
is_centered_ = view->ShouldCenterWindow(); is_centered_ = view->ShouldCenterWindow();
if (is_centered_) { if (is_centered_) {
// The experimental app list is centered over the display of the app list // Note: We can't center the app list until we have its dimensions, so we
// button that was pressed (if triggered via keyboard, this is the display // init at (0, 0) and then reset its anchor point.
// with the currently focused window).
view->InitAsBubbleAtFixedLocation( view->InitAsBubbleAtFixedLocation(
container, container,
pagination_model_.get(), pagination_model_.get(),
GetCenterOfDisplayForView(applist_button), gfx::Point(),
views::BubbleBorder::FLOAT, views::BubbleBorder::FLOAT,
true /* border_accepts_events */); true /* border_accepts_events */);
// The experimental app list is centered over the display of the app list
// button that was pressed (if triggered via keyboard, this is the display
// with the currently focused window).
view->SetAnchorPoint(GetCenterOfDisplayForView(
applist_button, GetMinimumBoundsHeightForAppList(view)));
} else { } else {
gfx::Rect applist_button_bounds = applist_button->GetBoundsInScreen(); gfx::Rect applist_button_bounds = applist_button->GetBoundsInScreen();
// We need the location of the button within the local screen. // We need the location of the button within the local screen.
...@@ -340,7 +359,8 @@ void AppListController::UpdateBounds() { ...@@ -340,7 +359,8 @@ void AppListController::UpdateBounds() {
view_->UpdateBounds(); view_->UpdateBounds();
if (is_centered_) if (is_centered_)
view_->SetAnchorPoint(GetCenterOfDisplayForView(view_)); view_->SetAnchorPoint(GetCenterOfDisplayForView(
view_, GetMinimumBoundsHeightForAppList(view_)));
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
......
...@@ -10,12 +10,19 @@ ...@@ -10,12 +10,19 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "ui/app_list/app_list_switches.h" #include "ui/app_list/app_list_switches.h"
#include "ui/app_list/views/app_list_view.h"
#include "ui/aura/test/event_generator.h" #include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_windows.h" #include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
namespace ash { namespace ash {
namespace {
const int kMinimalCenteredAppListMargin = 10;
}
// The parameter is true to test the centered app list, false for normal. // The parameter is true to test the centered app list, false for normal.
// (The test name ends in "/0" for normal, "/1" for centered.) // (The test name ends in "/0" for normal, "/1" for centered.)
class AppListControllerTest : public test::AshTestBase, class AppListControllerTest : public test::AshTestBase,
...@@ -24,6 +31,8 @@ class AppListControllerTest : public test::AshTestBase, ...@@ -24,6 +31,8 @@ class AppListControllerTest : public test::AshTestBase,
AppListControllerTest(); AppListControllerTest();
virtual ~AppListControllerTest(); virtual ~AppListControllerTest();
virtual void SetUp() OVERRIDE; virtual void SetUp() OVERRIDE;
bool IsCentered() const;
}; };
AppListControllerTest::AppListControllerTest() { AppListControllerTest::AppListControllerTest() {
...@@ -34,12 +43,16 @@ AppListControllerTest::~AppListControllerTest() { ...@@ -34,12 +43,16 @@ AppListControllerTest::~AppListControllerTest() {
void AppListControllerTest::SetUp() { void AppListControllerTest::SetUp() {
AshTestBase::SetUp(); AshTestBase::SetUp();
if (GetParam()) { if (IsCentered()) {
CommandLine* command_line = CommandLine::ForCurrentProcess(); CommandLine* command_line = CommandLine::ForCurrentProcess();
command_line->AppendSwitch(app_list::switches::kEnableCenteredAppList); command_line->AppendSwitch(app_list::switches::kEnableCenteredAppList);
} }
} }
bool AppListControllerTest::IsCentered() const {
return GetParam();
}
// Tests that app launcher hides when focus moves to a normal window. // Tests that app launcher hides when focus moves to a normal window.
TEST_P(AppListControllerTest, HideOnFocusOut) { TEST_P(AppListControllerTest, HideOnFocusOut) {
Shell::GetInstance()->ToggleAppList(NULL); Shell::GetInstance()->ToggleAppList(NULL);
...@@ -137,6 +150,37 @@ TEST_P(AppListControllerTest, NonPrimaryDisplay) { ...@@ -137,6 +150,37 @@ TEST_P(AppListControllerTest, NonPrimaryDisplay) {
EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility());
} }
// Tests opening the app launcher on a tiny display that is too small to contain
// it.
TEST_P(AppListControllerTest, TinyDisplay) {
// Don't test this for the non-centered app list case; it isn't designed for
// small displays. The most common case of a small display --- when the
// virtual keyboard is open --- switches into the centered app list mode, so
// we just want to run this test in that case.
if (!IsCentered())
return;
// UpdateDisplay is not supported in this case, so just skip the test.
if (!SupportsHostWindowResize())
return;
// Set up a screen with a tiny display (height smaller than the app list).
UpdateDisplay("400x300");
Shell::GetInstance()->ToggleAppList(NULL);
EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility());
// The top of the app list should be on-screen (even if the bottom is not).
// We need to manually calculate the Y coordinate of the top of the app list
// from the anchor (center) and height. There isn't a bounds rect that gives
// the actual app list position (the widget bounds include the bubble border
// which is much bigger than the actual app list size).
app_list::AppListView* app_list = Shell::GetInstance()->GetAppListView();
int app_list_view_top =
app_list->anchor_rect().y() - app_list->bounds().height() / 2;
EXPECT_GE(app_list_view_top, kMinimalCenteredAppListMargin);
}
INSTANTIATE_TEST_CASE_P(AppListControllerTestInstance, INSTANTIATE_TEST_CASE_P(AppListControllerTestInstance,
AppListControllerTest, AppListControllerTest,
::testing::Bool()); ::testing::Bool());
......
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