Skip to content

Commit

Permalink
[PhoneHub][Exo] Set launcher size to match Phone Hub size when it is
Browse files Browse the repository at this point in the history
bigger than default

Screenshot: https://drive.google.com/file/d/1dkAem7lcre37F8MrPSktYjdTRsSMQs4l/view?usp=share_link&resourcekey=0-uLNY3MPPxZB8cCOtyFKBBA

Fixed: b/270619247
Change-Id: I28588a6d5755382567d8eec9ce4f92bd747ff710
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4298098
Reviewed-by: Crisrael Lucero <crisrael@google.com>
Reviewed-by: Jon Mann <jonmann@chromium.org>
Commit-Queue: Pu Shi <pushi@google.com>
Cr-Commit-Position: refs/heads/main@{#1115920}
  • Loading branch information
Pu Shi authored and Chromium LUCI CQ committed Mar 10, 2023
1 parent 148e5ef commit 084bb54
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 8 deletions.
14 changes: 13 additions & 1 deletion ash/system/phonehub/app_stream_launcher_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ constexpr auto kVerticalScrollInsets = gfx::Insets::TLBR(1, 0, 1, 1);

constexpr auto kHeaderDefaultSpacing = gfx::Insets::VH(0, 0);

constexpr gfx::Size kDefaultAppListScrollViewSize = gfx::Size(400, 400);

// The horizontal interior margin for the apps page container - i.e. the margin
// between the apps page bounds and the page content.
constexpr int kHorizontalInteriorMargin = 25;
Expand Down Expand Up @@ -97,7 +99,17 @@ AppStreamLauncherView::AppStreamLauncherView(
AddChildView(CreateHeaderView());

auto* app_list_view = AddChildView(CreateAppListView());
app_list_view->SetPreferredSize(gfx::Size(400, 400));
gfx::Size launcher_size;
if (phone_hub_manager->GetAppStreamLauncherDataModel() &&
phone_hub_manager->GetAppStreamLauncherDataModel()->launcher_height() >
kDefaultAppListScrollViewSize.height()) {
launcher_size = gfx::Size(
phone_hub_manager->GetAppStreamLauncherDataModel()->launcher_width(),
phone_hub_manager->GetAppStreamLauncherDataModel()->launcher_height());
} else {
launcher_size = kDefaultAppListScrollViewSize;
}
app_list_view->SetPreferredSize(launcher_size);
app_list_view->SetProperty(
views::kFlexBehaviorKey,
views::FlexSpecification(views::MinimumFlexSizeRule::kPreferred,
Expand Down
26 changes: 20 additions & 6 deletions ash/system/phonehub/app_stream_launcher_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ class AppStreamLauncherViewTest : public views::ViewsTestBase {
feature_list_.InitWithFeatures(
/*enabled_features=*/{features::kEcheLauncher, features::kEcheSWA},
/*disabled_features=*/{features::kEcheLauncherListView});

app_stream_launcher_view_ =
std::make_unique<AppStreamLauncherView>(&fake_phone_hub_manager_);
widget_->SetContentsView(app_stream_launcher_view_.get());
widget_->Show();
widget_->LayoutRootViewIfNecessary();
}

// AshTestBase:
Expand All @@ -67,6 +61,14 @@ class AppStreamLauncherViewTest : public views::ViewsTestBase {
return app_stream_launcher_view_.get();
}

void GenerateLauncherView() {
app_stream_launcher_view_ =
std::make_unique<AppStreamLauncherView>(&fake_phone_hub_manager_);
widget_->SetContentsView(app_stream_launcher_view_.get());
widget_->Show();
widget_->LayoutRootViewIfNecessary();
}

AppStreamLauncherItem* GetItemView(int index) {
return static_cast<AppStreamLauncherItem*>(
app_stream_launcher_view()->items_container_for_test()->children().at(
Expand Down Expand Up @@ -112,10 +114,15 @@ class AppStreamLauncherViewTest : public views::ViewsTestBase {
};

TEST_F(AppStreamLauncherViewTest, OpenView) {
fake_phone_hub_manager()
->fake_app_stream_launcher_data_model()
->SetLauncherSize(1000, 1000);
GenerateLauncherView();
EXPECT_TRUE(app_stream_launcher_view()->GetVisible());
}

TEST_F(AppStreamLauncherViewTest, AddItems) {
GenerateLauncherView();
const int64_t user_id = 1;
const char16_t app_visible_name[] = u"Fake App";
const char package_name[] = "com.fakeapp";
Expand Down Expand Up @@ -145,6 +152,7 @@ TEST_F(AppStreamLauncherViewTest, AddItems) {
}

TEST_F(AppStreamLauncherViewTest, AddItemsListView) {
GenerateLauncherView();
feature_list_.Reset();
feature_list_.InitWithFeatures(
/*enabled_features=*/{features::kEcheLauncher, features::kEcheSWA,
Expand Down Expand Up @@ -174,6 +182,7 @@ TEST_F(AppStreamLauncherViewTest, AddItemsListView) {
}

TEST_F(AppStreamLauncherViewTest, RemoveItem) {
GenerateLauncherView();
const int64_t user_id = 1;
const char16_t app_visible_name[] = u"Fake App";
const char package_name[] = "com.fakeapp";
Expand Down Expand Up @@ -206,6 +215,7 @@ TEST_F(AppStreamLauncherViewTest, RemoveItem) {
}

TEST_F(AppStreamLauncherViewTest, RemoveItemListView) {
GenerateLauncherView();
feature_list_.Reset();
feature_list_.InitWithFeatures(
/*enabled_features=*/{features::kEcheLauncher, features::kEcheSWA,
Expand Down Expand Up @@ -244,6 +254,7 @@ TEST_F(AppStreamLauncherViewTest, RemoveItemListView) {
}

TEST_F(AppStreamLauncherViewTest, ClickOnItem) {
GenerateLauncherView();
const int64_t user_id = 1;
const char16_t app_visible_name[] = u"Fake App";
const char package_name[] = "com.fakeapp";
Expand Down Expand Up @@ -283,6 +294,7 @@ TEST_F(AppStreamLauncherViewTest, ClickOnItem) {
}

TEST_F(AppStreamLauncherViewTest, ClickOnItemListView) {
GenerateLauncherView();
feature_list_.Reset();
feature_list_.InitWithFeatures(
/*enabled_features=*/{features::kEcheLauncher, features::kEcheSWA,
Expand Down Expand Up @@ -327,6 +339,7 @@ TEST_F(AppStreamLauncherViewTest, ClickOnItemListView) {
}

TEST_F(AppStreamLauncherViewTest, DisabledItem) {
GenerateLauncherView();
const int64_t user_id = 1;
const char16_t app_visible_name[] = u"Fake App";
const char package_name[] = "com.fakeapp";
Expand Down Expand Up @@ -359,6 +372,7 @@ TEST_F(AppStreamLauncherViewTest, DisabledItem) {
}

TEST_F(AppStreamLauncherViewTest, DisabledItemListView) {
GenerateLauncherView();
feature_list_.Reset();
feature_list_.InitWithFeatures(
/*enabled_features=*/{features::kEcheLauncher, features::kEcheSWA,
Expand Down
19 changes: 18 additions & 1 deletion ash/system/phonehub/phone_connected_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "ui/views/controls/label.h"
#include "ui/views/controls/separator.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/view.h"

namespace ash {

Expand All @@ -46,7 +47,8 @@ constexpr auto kDarkLightModeDisabledPadding =
} // namespace

PhoneConnectedView::PhoneConnectedView(
phonehub::PhoneHubManager* phone_hub_manager) {
phonehub::PhoneHubManager* phone_hub_manager)
: phone_hub_manager_(phone_hub_manager) {
SetID(PhoneHubViewID::kPhoneConnectedView);

auto setup_layered_view = [](views::View* view) {
Expand Down Expand Up @@ -96,18 +98,33 @@ PhoneConnectedView::PhoneConnectedView(
}

phone_hub_manager->GetUserActionRecorder()->RecordUiOpened();

if (phone_hub_manager->GetAppStreamLauncherDataModel()) {
phone_hub_manager->GetAppStreamLauncherDataModel()->SetLauncherSize(
GetPreferredSize().height(), GetPreferredSize().width());
}
}

PhoneConnectedView::~PhoneConnectedView() = default;

void PhoneConnectedView::ChildPreferredSizeChanged(View* child) {
// Resize the bubble when the child change its size.
PreferredSizeChanged();
if (phone_hub_manager_ &&
phone_hub_manager_->GetAppStreamLauncherDataModel()) {
phone_hub_manager_->GetAppStreamLauncherDataModel()->SetLauncherSize(
GetPreferredSize().height(), GetPreferredSize().width());
}
}

void PhoneConnectedView::ChildVisibilityChanged(View* child) {
// Resize the bubble when the child change its visibility.
PreferredSizeChanged();
if (phone_hub_manager_ &&
phone_hub_manager_->GetAppStreamLauncherDataModel()) {
phone_hub_manager_->GetAppStreamLauncherDataModel()->SetLauncherSize(
GetPreferredSize().height(), GetPreferredSize().width());
}
}

const char* PhoneConnectedView::GetClassName() const {
Expand Down
4 changes: 4 additions & 0 deletions ash/system/phonehub/phone_connected_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "ash/ash_export.h"
#include "ash/system/phonehub/phone_hub_content_view.h"
#include "chromeos/ash/components/phonehub/phone_hub_manager.h"
#include "ui/views/view.h"

namespace ash {
Expand All @@ -29,6 +30,9 @@ class PhoneConnectedView : public PhoneHubContentView {

// PhoneHubContentView:
phone_hub_metrics::Screen GetScreenForMetrics() const override;

private:
phonehub::PhoneHubManager* phone_hub_manager_;
};

} // namespace ash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ bool AppStreamLauncherDataModel::GetShouldShowMiniLauncher() {
return should_show_app_stream_launcher_;
}

void AppStreamLauncherDataModel::SetLauncherSize(int height, int width) {
launcher_height_ = height;
launcher_width_ = width;
}

void AppStreamLauncherDataModel::ResetState() {
should_show_app_stream_launcher_ = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class AppStreamLauncherDataModel {
void SetShouldShowMiniLauncher(bool should_show_mini_launcher);
bool GetShouldShowMiniLauncher();

int launcher_height() { return launcher_height_; }
int launcher_width() { return launcher_width_; }
void SetLauncherSize(int height, int width);

// Resets the internal state w/o updating the UI.
void ResetState();

Expand All @@ -56,6 +60,8 @@ class AppStreamLauncherDataModel {
// Indicates if the Mini Launcher should be shown when the status is
// "phone connected" or not.
bool should_show_app_stream_launcher_ = false;
int launcher_height_ = 0;
int launcher_width_ = 0;
std::vector<Notification::AppMetadata> apps_list_;
std::vector<Notification::AppMetadata> apps_list_sorted_by_name_;
base::ObserverList<Observer> observer_list_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ class AppStreamLauncherDataModelTest : public testing::Test {
return app_stream_launcher_data_launcher_->GetAppsListSortedByName();
}

void SetLauncherSize(int height, int width) {
app_stream_launcher_data_launcher_->SetLauncherSize(height, width);
}

int GetLauncherHeight() {
return app_stream_launcher_data_launcher_->launcher_height();
}

int GetLauncherWidth() {
return app_stream_launcher_data_launcher_->launcher_width();
}

private:
std::unique_ptr<AppStreamLauncherDataModel>
app_stream_launcher_data_launcher_;
Expand Down Expand Up @@ -179,5 +191,11 @@ TEST_F(AppStreamLauncherDataModelTest, RemoveAppFromList) {
EXPECT_EQ(GetAppsListSortedByName()->size(), 1u);
EXPECT_EQ(GetAppsListSortedByName()->at(0).visible_app_name, u"Gboard");
}

TEST_F(AppStreamLauncherDataModelTest, SetLauncherSize) {
SetLauncherSize(/*height=*/400, /*width=*/300);
EXPECT_EQ(GetLauncherHeight(), 400);
EXPECT_EQ(GetLauncherWidth(), 300);
}
} // namespace phonehub
} // namespace ash

0 comments on commit 084bb54

Please sign in to comment.