Commit 80fd94e1 authored by Toni Barzic's avatar Toni Barzic Committed by Commit Bot

Fix initial search box position for app list view state transition

If app list view state transition is started during app list page
transition, the initial search box position should be calculated as a
position for the current app list page, otherwise the search box
will initially be misplaced.

BUG=999273

Change-Id: I053ab7f962b7c0a00914be97a0532f9ea445af42
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1824363Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Toni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699977}
parent 0f29a100
......@@ -132,6 +132,7 @@ void ContentsView::Init(AppListModel* model) {
}
void ContentsView::ResetForShow() {
target_page_for_last_view_state_update_ = base::nullopt;
GetAppsContainerView()->ResetForShowApps();
// SearchBoxView::ResetForShow() before SetActiveState(). It clears the search
// query internally, which can show the search results page through
......@@ -752,6 +753,8 @@ void ContentsView::UpdateYPositionAndOpacity() {
GetAppsContainerView()->UpdateYPositionAndOpacity(apps_container_progress,
restore_opacity);
}
target_page_for_last_view_state_update_ = current_state;
}
void ContentsView::AnimateToViewState(ash::AppListViewState target_view_state,
......@@ -822,17 +825,6 @@ void ContentsView::AnimateToViewState(ash::AppListViewState target_view_state,
// offset and apply the transform to the whole contents view.
const gfx::Rect target_search_box_bounds =
GetSearchBoxBoundsForViewState(target_page, target_view_state);
const gfx::Rect current_search_box_bounds =
GetSearchBoxExpectedBoundsForProgress(
target_page,
app_list_view_->GetAppListTransitionProgress(
AppListView::kProgressFlagWithTransform |
(target_page == ash::AppListState::kStateSearchResults
? AppListView::kProgressFlagSearchResults
: AppListView::kProgressFlagNone)));
const int y_offset =
current_search_box_bounds.y() - target_search_box_bounds.y();
SearchBoxView* search_box = GetSearchBoxView();
const gfx::Rect target_search_box_widget_bounds =
......@@ -840,6 +832,32 @@ void ContentsView::AnimateToViewState(ash::AppListViewState target_view_state,
ConvertRectToWidgetWithoutTransform(target_search_box_bounds));
search_box->GetWidget()->SetBounds(target_search_box_widget_bounds);
// Even though the target bounds are calculated for the target page, use the
// last page for which app list view state was updated - in case page
// transition is in progress, the total search box position change can be
// described as composite of:
// 1. Change in contents view padding due to app list view state change.
// 2. Change in contents view padding due to page change.
// Only the first part is expected to be handled by this animation, and this
// uses the last used page as reference.
// The second change will be handled by the page transition animation.
const ash::AppListState selected_page =
target_page_for_last_view_state_update_.value_or(
GetStateForPageIndex(pagination_model_.selected_page()));
const int progress_baseline_flag =
selected_page == ash::AppListState::kStateSearchResults
? AppListView::kProgressFlagSearchResults
: AppListView::kProgressFlagNone;
const gfx::Rect current_search_box_bounds =
GetSearchBoxExpectedBoundsForProgress(
selected_page, app_list_view_->GetAppListTransitionProgress(
AppListView::kProgressFlagWithTransform |
progress_baseline_flag));
const int y_offset =
current_search_box_bounds.y() -
GetSearchBoxBoundsForViewState(selected_page, target_view_state).y();
// For search box, animate the search_box view layer instead of the widget
// layer to avoid conflict with pagination model transitions (which update the
// search box widget layer transform as the transition progresses).
......@@ -857,6 +875,7 @@ void ContentsView::AnimateToViewState(ash::AppListViewState target_view_state,
GetAppsContainerView()->UpdateYPositionAndOpacity(
AppListView::GetTransitionProgressForState(target_view_state),
target_view_state != ash::AppListViewState::kClosed /*restore_opacity*/);
target_page_for_last_view_state_update_ = target_page;
// Schedule expand arrow repaint to ensure the view picks up the new target
// state.
......
......@@ -326,6 +326,13 @@ class APP_LIST_EXPORT ContentsView : public views::View,
// If true, SetActiveState immediately.
bool set_active_state_without_animation_ = false;
// If set, the app list page that was used to determine the search box
// placement when the contents view layout was last updated for app list view
// state (either using UpdateYPositionAndOpacity() or AnimateToViewState()).
// Used primarily to determine the initial search box position when animating
// to a new app list view state.
base::Optional<ash::AppListState> target_page_for_last_view_state_update_;
base::ObserverList<SearchBoxUpdateObserver> search_box_observers_;
DISALLOW_COPY_AND_ASSIGN(ContentsView);
......
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