summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authormgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-13 16:13:02 +0000
committermgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-13 16:13:02 +0000
commit316c18cecede043d5f8d21d3ca8440d718fd38cf (patch)
tree61ff270f6da05b86500932b92b7d32d93065d7b1 /ash
parent6f5517f5fa5b6d8c5beaff04f45f46610dac6306 (diff)
downloadchromium_src-316c18cecede043d5f8d21d3ca8440d718fd38cf.zip
chromium_src-316c18cecede043d5f8d21d3ca8440d718fd38cf.tar.gz
chromium_src-316c18cecede043d5f8d21d3ca8440d718fd38cf.tar.bz2
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
Diffstat (limited to 'ash')
-rw-r--r--ash/wm/app_list_controller.cc34
-rw-r--r--ash/wm/app_list_controller_unittest.cc46
2 files changed, 72 insertions, 8 deletions
diff --git a/ash/wm/app_list_controller.cc b/ash/wm/app_list_controller.cc
index 45915c4..6acf1ae 100644
--- a/ash/wm/app_list_controller.cc
+++ b/ash/wm/app_list_controller.cc
@@ -44,6 +44,9 @@ const int kMaxOverScrollShift = 48;
// result of minimal bubble arrow sizes and offsets.
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) {
return widget->GetNativeView()->layer();
}
@@ -115,8 +118,11 @@ gfx::Vector2d GetAnchorPositionOffsetToShelf(
}
// Gets the point at the center of the display that a particular view is on.
-// This calculation excludes the virtual keyboard area.
-gfx::Point GetCenterOfDisplayForView(const views::View* view) {
+// This calculation excludes the virtual keyboard area. If the height of the
+// 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(
view->GetWidget()->GetNativeView()).bounds();
@@ -129,9 +135,18 @@ gfx::Point GetCenterOfDisplayForView(const views::View* view) {
if (keyboard_controller && keyboard_controller->keyboard_visible())
bounds.Subtract(keyboard_controller->current_keyboard_bounds());
+ // Apply the |minimum_height|.
+ if (bounds.height() < minimum_height)
+ bounds.set_height(minimum_height);
+
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
////////////////////////////////////////////////////////////////////////////////
@@ -189,15 +204,19 @@ void AppListController::SetVisible(bool visible, aura::Window* window) {
Shelf::ForWindow(container)->GetAppListButtonView();
is_centered_ = view->ShouldCenterWindow();
if (is_centered_) {
- // 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).
+ // Note: We can't center the app list until we have its dimensions, so we
+ // init at (0, 0) and then reset its anchor point.
view->InitAsBubbleAtFixedLocation(
container,
pagination_model_.get(),
- GetCenterOfDisplayForView(applist_button),
+ gfx::Point(),
views::BubbleBorder::FLOAT,
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 {
gfx::Rect applist_button_bounds = applist_button->GetBoundsInScreen();
// We need the location of the button within the local screen.
@@ -340,7 +359,8 @@ void AppListController::UpdateBounds() {
view_->UpdateBounds();
if (is_centered_)
- view_->SetAnchorPoint(GetCenterOfDisplayForView(view_));
+ view_->SetAnchorPoint(GetCenterOfDisplayForView(
+ view_, GetMinimumBoundsHeightForAppList(view_)));
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/ash/wm/app_list_controller_unittest.cc b/ash/wm/app_list_controller_unittest.cc
index 7b467df..da663d6 100644
--- a/ash/wm/app_list_controller_unittest.cc
+++ b/ash/wm/app_list_controller_unittest.cc
@@ -10,12 +10,19 @@
#include "base/command_line.h"
#include "base/memory/scoped_ptr.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/test_windows.h"
#include "ui/aura/window.h"
namespace ash {
+namespace {
+
+const int kMinimalCenteredAppListMargin = 10;
+
+}
+
// The parameter is true to test the centered app list, false for normal.
// (The test name ends in "/0" for normal, "/1" for centered.)
class AppListControllerTest : public test::AshTestBase,
@@ -24,6 +31,8 @@ class AppListControllerTest : public test::AshTestBase,
AppListControllerTest();
virtual ~AppListControllerTest();
virtual void SetUp() OVERRIDE;
+
+ bool IsCentered() const;
};
AppListControllerTest::AppListControllerTest() {
@@ -34,12 +43,16 @@ AppListControllerTest::~AppListControllerTest() {
void AppListControllerTest::SetUp() {
AshTestBase::SetUp();
- if (GetParam()) {
+ if (IsCentered()) {
CommandLine* command_line = CommandLine::ForCurrentProcess();
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.
TEST_P(AppListControllerTest, HideOnFocusOut) {
Shell::GetInstance()->ToggleAppList(NULL);
@@ -137,6 +150,37 @@ TEST_P(AppListControllerTest, NonPrimaryDisplay) {
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,
AppListControllerTest,
::testing::Bool());