Commit 6301c76e authored by Toni Barzic's avatar Toni Barzic Committed by Commit Bot

Fix apps container layout after app list config change

After app list config change, the apps container was not clearing cached
margins for current app list bounds, even though they depended on the
app list config. So if app list config was updated after bounds change
(and the associated layout), the apps container was getting laid out
using obsolete apps container margins.
This cl fixes the issue.

Also, when AppListView updates the widget bounds (e.g. because the
display, and thus root window bounds change), update app list config
before setting new bounds, so the app list uses the new config while
laying out the app list view for bounds change (and avoid another pass
for the app list config update).

BUG=1053911

Change-Id: Ic6249a86f350c11ba3a2be006368aefba9975719
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2067445
Commit-Queue: Toni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743327}
parent 9ea54f9f
......@@ -883,11 +883,10 @@ void AppListView::UpdateAppListConfig(aura::Window* parent_window) {
// Initial config should be set before the app list main view is initialized.
DCHECK(!is_initial_config || !app_list_main_view_);
// If the config changed, notify apps grids the config has changed.
if (!is_initial_config) {
GetFolderAppsGridView()->OnAppListConfigUpdated();
GetRootAppsGridView()->OnAppListConfigUpdated();
}
// If the config changed, notify apps container the config has changed, so
// root and folder apps grids are updated for the new config.
if (!is_initial_config)
GetAppsContainerView()->OnAppListConfigUpdated();
}
void AppListView::UpdateWidget() {
......@@ -1217,6 +1216,12 @@ void AppListView::EnsureWidgetBoundsMatchCurrentState() {
if (new_target_bounds == window->GetTargetBounds())
return;
// Update the app list config to match the new window bounds - do this before
// updating the bounds, so app list config is updated before apps container is
// laid out (to avoid separate layouts for window bounds change and app list
// config change).
UpdateAppListConfig(GetWidget()->GetNativeView());
// Set the widget size to fit the new display metrics.
GetWidget()->GetNativeView()->SetBounds(new_target_bounds);
ResetSubpixelPositionOffset(GetWidget()->GetNativeView()->layer());
......
......@@ -2999,6 +2999,35 @@ TEST_F(AppListViewScalableLayoutTest,
80 /*expected_item_size*/);
}
// Tests fullscreen apps grid sizing and layout gets updated to correct bounds
// when app list config changes.
TEST_F(AppListViewScalableLayoutTest, AppListViewLayoutAfterConfigChage) {
const gfx::Size window_size = gfx::Size(500, 800);
gfx::NativeView parent = GetContext();
parent->SetBounds(gfx::Rect(window_size));
Initialize(false /*is_tablet_mode*/);
delegate_->GetTestModel()->PopulateApps(kInitialItems);
Show();
view_->SetState(ash::AppListViewState::kFullscreenAllApps);
int expected_vertical_margin = (window_size.height() - ShelfSize()) / 16;
VerifyAppsContainerLayout(window_size, 4 /*column_count*/, 5 /*row_count*/,
56 /*expected_horizontal_margin*/,
expected_vertical_margin,
80 /*expected_item_size*/);
const gfx::Size updated_window_size = gfx::Size(800, 1200);
parent->SetBounds(gfx::Rect(updated_window_size));
view_->OnParentWindowBoundsChanged();
expected_vertical_margin = (updated_window_size.height() - ShelfSize()) / 16;
VerifyAppsContainerLayout(
updated_window_size, 4 /*column_count*/, 5 /*row_count*/,
updated_window_size.width() / 12 /*expected_horizontal_margin*/,
expected_vertical_margin, 120 /*expected_item_size*/);
}
// Tests that page switching in folder doesn't record AppListPageSwitcherSource
// metric.
TEST_F(AppListViewFocusTest, PageSwitchingNotRecordingMetric) {
......
......@@ -517,6 +517,16 @@ const gfx::Insets& AppsContainerView::CalculateMarginsForAvailableBounds(
return cached_container_margins_.margins;
}
void AppsContainerView::OnAppListConfigUpdated() {
// Invalidate the cached container margins - app list config change generally
// changes preferred apps grid margins, which can influence the container
// margins.
cached_container_margins_ = CachedContainerMargins();
apps_grid_view()->OnAppListConfigUpdated();
app_list_folder_view()->items_grid_view()->OnAppListConfigUpdated();
}
void AppsContainerView::UpdateSuggestionChips() {
suggestion_chip_container_view_->SetResults(
contents_view_->GetAppListMainView()
......
......@@ -136,6 +136,9 @@ class APP_LIST_EXPORT AppsContainerView : public HorizontalPage {
AppListFolderView* app_list_folder_view() { return app_list_folder_view_; }
PageSwitcher* page_switcher() { return page_switcher_; }
// Called by app list view when the app list config changes.
void OnAppListConfigUpdated();
// Updates suggestion chips from app list model.
void UpdateSuggestionChips();
......
......@@ -2119,7 +2119,7 @@ void AppsGridView::OnAppListConfigUpdated() {
for (int i = 0; i < view_model_.view_size(); ++i)
view_model_.view_at(i)->RefreshIcon();
Layout();
InvalidateLayout();
}
const AppListConfig& AppsGridView::GetAppListConfig() const {
......
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