Commit 05c5d5ab authored by calamity's avatar calamity Committed by Commit bot

Make start page fill app list bounds.

This CL makes the start page fully fill the app list bounds. This will
ensure the start page WebContents has maximal space. In order to do this,
this CL decouples code from some layout assumptions and uses more
future-proof calculations instead.

BUG=453205

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

Cr-Commit-Position: refs/heads/master@{#315273}
parent 64121b7f
......@@ -246,7 +246,7 @@ bool AppListViewTestContext::IsStateShown(AppListModel::State state) {
bool success = true;
for (int i = 0; i < contents_view->NumLauncherPages(); ++i) {
success = success &&
(i == index) == (contents_view->GetDefaultContentsBounds() ==
(i == index) == (contents_view->GetOnscreenPageBounds(i) ==
contents_view->GetPageView(i)->bounds());
}
return success && state == delegate_->GetTestModel()->state();
......@@ -507,30 +507,40 @@ void AppListViewTestContext::RunPageSwitchingAnimationTest() {
contents_view->SetActivePage(0);
contents_view->Layout();
const gfx::Rect expected_bounds = contents_view->GetDefaultContentsBounds();
EXPECT_EQ(expected_bounds, contents_view->GetPageView(0)->bounds());
EXPECT_NE(expected_bounds, contents_view->GetPageView(1)->bounds());
EXPECT_NE(expected_bounds, contents_view->GetPageView(2)->bounds());
EXPECT_EQ(contents_view->GetOnscreenPageBounds(0),
contents_view->GetPageView(0)->bounds());
EXPECT_NE(contents_view->GetOnscreenPageBounds(1),
contents_view->GetPageView(1)->bounds());
EXPECT_NE(contents_view->GetOnscreenPageBounds(2),
contents_view->GetPageView(2)->bounds());
// Change pages. View should not have moved without Layout().
contents_view->SetActivePage(1);
EXPECT_EQ(expected_bounds, contents_view->GetPageView(0)->bounds());
EXPECT_NE(expected_bounds, contents_view->GetPageView(1)->bounds());
EXPECT_NE(expected_bounds, contents_view->GetPageView(2)->bounds());
EXPECT_EQ(contents_view->GetOnscreenPageBounds(0),
contents_view->GetPageView(0)->bounds());
EXPECT_NE(contents_view->GetOnscreenPageBounds(1),
contents_view->GetPageView(1)->bounds());
EXPECT_NE(contents_view->GetOnscreenPageBounds(2),
contents_view->GetPageView(2)->bounds());
// Change to a third page. This queues up the second animation behind the
// first.
contents_view->SetActivePage(2);
EXPECT_EQ(expected_bounds, contents_view->GetPageView(0)->bounds());
EXPECT_NE(expected_bounds, contents_view->GetPageView(1)->bounds());
EXPECT_NE(expected_bounds, contents_view->GetPageView(2)->bounds());
EXPECT_EQ(contents_view->GetOnscreenPageBounds(0),
contents_view->GetPageView(0)->bounds());
EXPECT_NE(contents_view->GetOnscreenPageBounds(1),
contents_view->GetPageView(1)->bounds());
EXPECT_NE(contents_view->GetOnscreenPageBounds(2),
contents_view->GetPageView(2)->bounds());
// Call Layout(). Should jump to the third page.
contents_view->Layout();
EXPECT_NE(expected_bounds, contents_view->GetPageView(0)->bounds());
EXPECT_NE(expected_bounds, contents_view->GetPageView(1)->bounds());
EXPECT_EQ(expected_bounds, contents_view->GetPageView(2)->bounds());
EXPECT_NE(contents_view->GetOnscreenPageBounds(0),
contents_view->GetPageView(0)->bounds());
EXPECT_NE(contents_view->GetOnscreenPageBounds(1),
contents_view->GetPageView(1)->bounds());
EXPECT_EQ(contents_view->GetOnscreenPageBounds(2),
contents_view->GetPageView(2)->bounds());
}
Close();
......@@ -600,31 +610,20 @@ void AppListViewTestContext::RunSearchResultsTest() {
contents_view->Layout();
EXPECT_TRUE(contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS));
const gfx::Rect default_contents_bounds =
contents_view->GetDefaultContentsBounds();
EXPECT_EQ(AppListModel::STATE_SEARCH_RESULTS,
delegate_->GetTestModel()->state());
EXPECT_EQ(default_contents_bounds,
contents_view->search_results_page_view()->bounds());
EXPECT_TRUE(IsStateShown(AppListModel::STATE_SEARCH_RESULTS));
// Hide the search results.
contents_view->ShowSearchResults(false);
contents_view->Layout();
// Check that we return to the page that we were on before the search.
EXPECT_TRUE(contents_view->IsStateActive(AppListModel::STATE_APPS));
EXPECT_EQ(AppListModel::STATE_APPS, delegate_->GetTestModel()->state());
EXPECT_EQ(default_contents_bounds,
contents_view->apps_container_view()->bounds());
EXPECT_TRUE(IsStateShown(AppListModel::STATE_APPS));
if (test_type_ == EXPERIMENTAL) {
// Check that typing into the search box triggers the search page.
EXPECT_TRUE(SetAppListState(AppListModel::STATE_START));
view_->Layout();
EXPECT_EQ(default_contents_bounds,
contents_view->start_page_view()->bounds());
EXPECT_TRUE(CheckSearchBoxWidget(
contents_view->GetSearchBoxBoundsForState(AppListModel::STATE_START)));
EXPECT_TRUE(IsStateShown(AppListModel::STATE_START));
base::string16 search_text = base::UTF8ToUTF16("test");
main_view->search_box_view()->search_box()->SetText(base::string16());
......@@ -641,8 +640,7 @@ void AppListViewTestContext::RunSearchResultsTest() {
// Check that typing into the search box triggers the search page.
EXPECT_TRUE(SetAppListState(AppListModel::STATE_APPS));
contents_view->Layout();
EXPECT_EQ(default_contents_bounds,
contents_view->apps_container_view()->bounds());
EXPECT_TRUE(IsStateShown(AppListModel::STATE_APPS));
EXPECT_TRUE(
CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds()));
......@@ -654,8 +652,7 @@ void AppListViewTestContext::RunSearchResultsTest() {
EXPECT_EQ(new_search_text,
main_view->search_box_view()->search_box()->text());
contents_view->Layout();
EXPECT_TRUE(
contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS));
EXPECT_TRUE(IsStateShown(AppListModel::STATE_SEARCH_RESULTS));
EXPECT_TRUE(
CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds()));
}
......
......@@ -36,27 +36,6 @@ ContentsAnimator::ContentsAnimator(ContentsView* contents_view)
ContentsAnimator::~ContentsAnimator() {
}
gfx::Rect ContentsAnimator::GetOnscreenPageBounds(int page_index) const {
return contents_view_->GetPageIndexForState(
AppListModel::STATE_CUSTOM_LAUNCHER_PAGE) == page_index
? contents_view_->GetContentsBounds()
: contents_view_->GetDefaultContentsBounds();
}
gfx::Rect ContentsAnimator::GetOffscreenPageBounds(int page_index) const {
gfx::Rect bounds(GetOnscreenPageBounds(page_index));
// The start page and search page origins are above; all other pages' origins
// are below.
bool origin_above = contents_view_->GetPageIndexForState(
AppListModel::STATE_START) == page_index ||
contents_view_->GetPageIndexForState(
AppListModel::STATE_SEARCH_RESULTS) == page_index;
bounds.set_y(origin_above
? -bounds.height()
: contents_view_->GetContentsBounds().height() + bounds.y());
return bounds;
}
void ContentsAnimator::UpdateCustomPageForDefaultAnimation(double progress,
int from_page,
int to_page) const {
......@@ -73,7 +52,8 @@ void ContentsAnimator::UpdateCustomPageForDefaultAnimation(double progress,
views::View* custom_page = contents_view()->GetPageView(custom_page_index);
gfx::Rect custom_page_collapsed(
contents_view()->GetCustomPageCollapsedBounds());
gfx::Rect custom_page_origin(GetOffscreenPageBounds(custom_page_index));
gfx::Rect custom_page_origin(
contents_view()->GetOffscreenPageBounds(custom_page_index));
gfx::Rect custom_page_rect;
if (from_page == start_page_index) {
......@@ -157,10 +137,12 @@ std::string DefaultAnimator::NameForTests() const {
void DefaultAnimator::Update(double progress, int from_page, int to_page) {
// Move the from page from 0 to its origin. Move the to page from its origin
// to 0.
gfx::Rect from_page_onscreen(GetOnscreenPageBounds(from_page));
gfx::Rect to_page_onscreen(GetOnscreenPageBounds(to_page));
gfx::Rect from_page_origin(GetOffscreenPageBounds(from_page));
gfx::Rect to_page_origin(GetOffscreenPageBounds(to_page));
gfx::Rect from_page_onscreen(
contents_view()->GetOnscreenPageBounds(from_page));
gfx::Rect to_page_onscreen(contents_view()->GetOnscreenPageBounds(to_page));
gfx::Rect from_page_origin(
contents_view()->GetOffscreenPageBounds(from_page));
gfx::Rect to_page_origin(contents_view()->GetOffscreenPageBounds(to_page));
gfx::Rect from_page_rect(gfx::Tween::RectValueBetween(
progress, from_page_onscreen, from_page_origin));
gfx::Rect to_page_rect(
......@@ -193,13 +175,16 @@ void StartToAppsAnimator::Update(double progress,
int apps_page) {
// TODO(mgiuca): This is just a clone of DefaultAnimator's animation. Write a
// custom animation for the All Apps button on the Start page.
gfx::Rect on_screen(contents_view()->GetDefaultContentsBounds());
gfx::Rect from_page_origin(GetOffscreenPageBounds(start_page));
gfx::Rect to_page_origin(GetOffscreenPageBounds(apps_page));
gfx::Rect from_page_rect(
gfx::Tween::RectValueBetween(progress, on_screen, from_page_origin));
gfx::Rect from_page_onscreen(
contents_view()->GetOnscreenPageBounds(start_page));
gfx::Rect to_page_onscreen(contents_view()->GetOnscreenPageBounds(apps_page));
gfx::Rect from_page_origin(
contents_view()->GetOffscreenPageBounds(start_page));
gfx::Rect to_page_origin(contents_view()->GetOffscreenPageBounds(apps_page));
gfx::Rect from_page_rect(gfx::Tween::RectValueBetween(
progress, from_page_onscreen, from_page_origin));
gfx::Rect to_page_rect(
gfx::Tween::RectValueBetween(progress, to_page_origin, on_screen));
gfx::Tween::RectValueBetween(progress, to_page_origin, to_page_onscreen));
contents_view()->GetPageView(start_page)->SetBoundsRect(from_page_rect);
contents_view()->GetPageView(apps_page)->SetBoundsRect(to_page_rect);
......@@ -221,9 +206,12 @@ std::string StartToCustomAnimator::NameForTests() const {
void StartToCustomAnimator::Update(double progress,
int start_page,
int custom_page) {
gfx::Rect start_page_on_screen(GetOnscreenPageBounds(start_page));
gfx::Rect custom_page_on_screen(GetOnscreenPageBounds(custom_page));
gfx::Rect start_page_origin(GetOffscreenPageBounds(start_page));
gfx::Rect start_page_on_screen(
contents_view()->GetOnscreenPageBounds(start_page));
gfx::Rect custom_page_on_screen(
contents_view()->GetOnscreenPageBounds(custom_page));
gfx::Rect start_page_origin(
contents_view()->GetOffscreenPageBounds(start_page));
gfx::Rect custom_page_origin(contents_view()->GetCustomPageCollapsedBounds());
gfx::Rect start_page_rect(gfx::Tween::RectValueBetween(
progress, start_page_on_screen, start_page_origin));
......
......@@ -39,14 +39,6 @@ class ContentsAnimator {
protected:
const ContentsView* contents_view() const { return contents_view_; }
// Gets the on-screen page bounds for a given launcher page with index
// |page_index|.
gfx::Rect GetOnscreenPageBounds(int page_index) const;
// Gets the origin (the off-screen resting place) for a given launcher page
// with index |page_index|.
gfx::Rect GetOffscreenPageBounds(int page_index) const;
// Updates the position of the custom launcher page view (if it exists), in
// the default way for start page <-> other page transitions. This places it
// into collapsed state on the start page, and hidden on any other page. Any
......
......@@ -352,6 +352,26 @@ int ContentsView::AddLauncherPage(views::View* view,
return page_index;
}
gfx::Rect ContentsView::GetOnscreenPageBounds(int page_index) const {
AppListModel::State state = GetStateForPageIndex(page_index);
bool fills_contents_view =
state == AppListModel::STATE_CUSTOM_LAUNCHER_PAGE ||
state == AppListModel::STATE_START;
return fills_contents_view ? GetContentsBounds() : GetDefaultContentsBounds();
}
gfx::Rect ContentsView::GetOffscreenPageBounds(int page_index) const {
AppListModel::State state = GetStateForPageIndex(page_index);
gfx::Rect bounds(GetOnscreenPageBounds(page_index));
// The start page and search page origins are above; all other pages' origins
// are below.
bool origin_above = state == AppListModel::STATE_START ||
state == AppListModel::STATE_SEARCH_RESULTS;
bounds.set_y(origin_above ? -bounds.height()
: GetContentsBounds().height() + bounds.y());
return bounds;
}
gfx::Rect ContentsView::GetDefaultSearchBoxBounds() const {
gfx::Rect search_box_bounds(0, 0, GetDefaultContentsSize().width(),
GetSearchBoxView()->GetPreferredSize().height());
......@@ -370,7 +390,8 @@ gfx::Rect ContentsView::GetSearchBoxBoundsForState(
// Convert to ContentsView space, assuming that the StartPageView is in the
// ContentsView's default bounds.
return start_page_view_->GetSearchBoxBounds() +
GetDefaultContentsBounds().OffsetFromOrigin();
GetOnscreenPageBounds(GetPageIndexForState(state))
.OffsetFromOrigin();
}
return GetDefaultSearchBoxBounds();
......@@ -459,14 +480,9 @@ void ContentsView::Layout() {
// Move the current view onto the screen, and all other views off screen to
// the left. (Since we are not animating, we don't need to be careful about
// which side we place the off-screen views onto.)
gfx::Rect rect(GetDefaultContentsBounds());
// Custom pages are aligned to the top of the window, not under the search
// box.
double progress = 0;
if (IsStateActive(AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) {
rect = GetContentsBounds();
progress = 1;
}
gfx::Rect rect = GetOnscreenPageBounds(GetActivePageIndex());
double progress =
IsStateActive(AppListModel::STATE_CUSTOM_LAUNCHER_PAGE) ? 1 : 0;
// Notify the custom launcher page that the active page has changed.
app_list_main_view_->view_delegate()->CustomLauncherPageAnimationChanged(
......
......@@ -114,6 +114,14 @@ class APP_LIST_EXPORT ContentsView : public views::View,
// Returns the pagination model for the ContentsView.
const PaginationModel& pagination_model() { return pagination_model_; }
// Gets the on-screen page bounds for a given launcher page with index
// |page_index|.
gfx::Rect GetOnscreenPageBounds(int page_index) const;
// Gets the the off-screen resting place for a given launcher page with index
// |page_index|.
gfx::Rect GetOffscreenPageBounds(int page_index) const;
// Returns search box bounds to use for content views that do not specify
// their own custom layout.
gfx::Rect GetDefaultSearchBoxBounds() const;
......
......@@ -36,7 +36,7 @@ const int kStartPageSearchBoxWidth = 480;
// WebView constants.
const int kWebViewWidth = 700;
const int kWebViewHeight = 189;
const int kWebViewHeight = 254;
// Tile container constants.
const size_t kNumStartPageTiles = 4;
......
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