Pine: Change PineItemView arguments
Change PineItemView to accept an AppInfo object in its constructor, rather than its individual fields. Bug: b/328830102 Change-Id: I1dfed9b0cdf3bc7d761245c4dcb9d721e8683525 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5386536 Reviewed-by: Min Chen <minch@chromium.org> Commit-Queue: Elijah Hewer <hewer@chromium.org> Cr-Commit-Position: refs/heads/main@{#1277895}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
c03444f9bf
commit
2f98c12b2a
@@ -9,9 +9,12 @@
|
|||||||
#include "ash/shell.h"
|
#include "ash/shell.h"
|
||||||
#include "ash/style/typography.h"
|
#include "ash/style/typography.h"
|
||||||
#include "ash/wm/window_restore/pine_constants.h"
|
#include "ash/wm/window_restore/pine_constants.h"
|
||||||
|
#include "ash/wm/window_restore/window_restore_util.h"
|
||||||
#include "base/barrier_callback.h"
|
#include "base/barrier_callback.h"
|
||||||
#include "base/i18n/number_formatting.h"
|
#include "base/i18n/number_formatting.h"
|
||||||
#include "base/task/cancelable_task_tracker.h"
|
#include "base/task/cancelable_task_tracker.h"
|
||||||
|
#include "components/services/app_service/public/cpp/app_registry_cache.h"
|
||||||
|
#include "components/services/app_service/public/cpp/app_registry_cache_wrapper.h"
|
||||||
#include "ui/gfx/image/image_skia.h"
|
#include "ui/gfx/image/image_skia.h"
|
||||||
#include "ui/gfx/image/image_skia_operations.h"
|
#include "ui/gfx/image/image_skia_operations.h"
|
||||||
#include "ui/views/background.h"
|
#include "ui/views/background.h"
|
||||||
@@ -36,12 +39,10 @@ constexpr int kTabCountRounding = 6;
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
PineItemView::PineItemView(const std::u16string& app_title,
|
PineItemView::PineItemView(const PineContentsData::AppInfo& app_info,
|
||||||
const std::vector<GURL>& favicons,
|
|
||||||
const size_t tab_count,
|
|
||||||
bool inside_screenshot)
|
bool inside_screenshot)
|
||||||
: tab_count_(tab_count), inside_screenshot_(inside_screenshot) {
|
: tab_count_(app_info.tab_count), inside_screenshot_(inside_screenshot) {
|
||||||
SetBetweenChildSpacing(inside_screenshot
|
SetBetweenChildSpacing(inside_screenshot_
|
||||||
? pine::kScreenshotIconRowChildSpacing
|
? pine::kScreenshotIconRowChildSpacing
|
||||||
: pine::kItemChildSpacing);
|
: pine::kItemChildSpacing);
|
||||||
SetCrossAxisAlignment(views::BoxLayout::CrossAxisAlignment::kCenter);
|
SetCrossAxisAlignment(views::BoxLayout::CrossAxisAlignment::kCenter);
|
||||||
@@ -50,14 +51,14 @@ PineItemView::PineItemView(const std::u16string& app_title,
|
|||||||
auto* browser_image_view = AddChildView(
|
auto* browser_image_view = AddChildView(
|
||||||
views::Builder<views::ImageView>()
|
views::Builder<views::ImageView>()
|
||||||
.CopyAddressTo(&image_view_)
|
.CopyAddressTo(&image_view_)
|
||||||
.SetImageSize(inside_screenshot
|
.SetImageSize(inside_screenshot_
|
||||||
? pine::kScreenshotIconRowImageViewSize
|
? pine::kScreenshotIconRowImageViewSize
|
||||||
: kItemIconPreferredSize)
|
: kItemIconPreferredSize)
|
||||||
.SetPreferredSize(inside_screenshot
|
.SetPreferredSize(inside_screenshot_
|
||||||
? pine::kScreenshotIconRowImageViewSize
|
? pine::kScreenshotIconRowImageViewSize
|
||||||
: pine::kItemIconBackgroundPreferredSize)
|
: pine::kItemIconBackgroundPreferredSize)
|
||||||
.Build());
|
.Build());
|
||||||
if (inside_screenshot) {
|
if (inside_screenshot_) {
|
||||||
views::Separator* separator =
|
views::Separator* separator =
|
||||||
AddChildView(std::make_unique<views::Separator>());
|
AddChildView(std::make_unique<views::Separator>());
|
||||||
separator->SetColorId(ui::kColorAshSystemUIMenuSeparator);
|
separator->SetColorId(ui::kColorAshSystemUIMenuSeparator);
|
||||||
@@ -69,7 +70,7 @@ PineItemView::PineItemView(const std::u16string& app_title,
|
|||||||
|
|
||||||
// Add nested `BoxLayoutView`s, so we can have the title of the window on
|
// Add nested `BoxLayoutView`s, so we can have the title of the window on
|
||||||
// top, and a row of favicons on the bottom.
|
// top, and a row of favicons on the bottom.
|
||||||
if (inside_screenshot) {
|
if (inside_screenshot_) {
|
||||||
AddChildView(
|
AddChildView(
|
||||||
views::Builder<views::BoxLayoutView>()
|
views::Builder<views::BoxLayoutView>()
|
||||||
.CopyAddressTo(&favicon_container_view_)
|
.CopyAddressTo(&favicon_container_view_)
|
||||||
@@ -78,6 +79,25 @@ PineItemView::PineItemView(const std::u16string& app_title,
|
|||||||
.SetBetweenChildSpacing(pine::kScreenshotFaviconSpacing)
|
.SetBetweenChildSpacing(pine::kScreenshotFaviconSpacing)
|
||||||
.Build());
|
.Build());
|
||||||
} else {
|
} else {
|
||||||
|
// TODO(http://b/328830102): Handle case where the app is not ready or
|
||||||
|
// installed.
|
||||||
|
apps::AppRegistryCache* cache =
|
||||||
|
apps::AppRegistryCacheWrapper::Get().GetAppRegistryCache(
|
||||||
|
Shell::Get()->session_controller()->GetActiveAccountId());
|
||||||
|
|
||||||
|
// `title` will be the window title from the previous session stored in the
|
||||||
|
// full restore file. The title fetched from the app service would more
|
||||||
|
// accurate, but the app might not be installed yet. Browsers are always
|
||||||
|
// installed and `title` will be the active tab title fetched from session
|
||||||
|
// restore. `cache` might be null in a test environment.
|
||||||
|
// TODO(http://b/328830102): Title should be updated once app is installed.
|
||||||
|
std::string title = app_info.title;
|
||||||
|
if (cache && !IsBrowserAppId(app_info.app_id)) {
|
||||||
|
cache->ForOneApp(
|
||||||
|
app_info.app_id,
|
||||||
|
[&title](const apps::AppUpdate& update) { title = update.Name(); });
|
||||||
|
}
|
||||||
|
|
||||||
AddChildView(
|
AddChildView(
|
||||||
views::Builder<views::BoxLayoutView>()
|
views::Builder<views::BoxLayoutView>()
|
||||||
.SetOrientation(views::BoxLayout::Orientation::kVertical)
|
.SetOrientation(views::BoxLayout::Orientation::kVertical)
|
||||||
@@ -90,7 +110,7 @@ PineItemView::PineItemView(const std::u16string& app_title,
|
|||||||
pine::kItemTitleFontSize,
|
pine::kItemTitleFontSize,
|
||||||
gfx::Font::Weight::BOLD))
|
gfx::Font::Weight::BOLD))
|
||||||
.SetHorizontalAlignment(gfx::ALIGN_LEFT)
|
.SetHorizontalAlignment(gfx::ALIGN_LEFT)
|
||||||
.SetText(app_title),
|
.SetText(base::UTF8ToUTF16(title)),
|
||||||
views::Builder<views::BoxLayoutView>()
|
views::Builder<views::BoxLayoutView>()
|
||||||
.CopyAddressTo(&favicon_container_view_)
|
.CopyAddressTo(&favicon_container_view_)
|
||||||
.SetOrientation(views::BoxLayout::Orientation::kHorizontal)
|
.SetOrientation(views::BoxLayout::Orientation::kHorizontal)
|
||||||
@@ -100,6 +120,7 @@ PineItemView::PineItemView(const std::u16string& app_title,
|
|||||||
.Build());
|
.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::vector<GURL>& favicons = app_info.tab_urls;
|
||||||
if (favicons.empty()) {
|
if (favicons.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
#define ASH_WM_WINDOW_RESTORE_PINE_ITEM_VIEW_H_
|
#define ASH_WM_WINDOW_RESTORE_PINE_ITEM_VIEW_H_
|
||||||
|
|
||||||
#include "ash/ash_export.h"
|
#include "ash/ash_export.h"
|
||||||
|
#include "ash/wm/window_restore/pine_contents_data.h"
|
||||||
#include "base/task/cancelable_task_tracker.h"
|
#include "base/task/cancelable_task_tracker.h"
|
||||||
#include "ui/base/metadata/metadata_impl_macros.h"
|
#include "ui/base/metadata/metadata_impl_macros.h"
|
||||||
#include "ui/views/layout/box_layout_view.h"
|
#include "ui/views/layout/box_layout_view.h"
|
||||||
@@ -26,9 +27,7 @@ class ASH_EXPORT PineItemView : public views::BoxLayoutView {
|
|||||||
METADATA_HEADER(PineItemView, views::BoxLayoutView)
|
METADATA_HEADER(PineItemView, views::BoxLayoutView)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PineItemView(const std::u16string& app_title,
|
PineItemView(const PineContentsData::AppInfo& app_info,
|
||||||
const std::vector<GURL>& favicons,
|
|
||||||
const size_t tab_count,
|
|
||||||
bool inside_screenshot);
|
bool inside_screenshot);
|
||||||
PineItemView(const PineItemView&) = delete;
|
PineItemView(const PineItemView&) = delete;
|
||||||
PineItemView& operator=(const PineItemView&) = delete;
|
PineItemView& operator=(const PineItemView&) = delete;
|
||||||
|
@@ -9,9 +9,6 @@
|
|||||||
#include "ash/wm/window_restore/pine_constants.h"
|
#include "ash/wm/window_restore/pine_constants.h"
|
||||||
#include "ash/wm/window_restore/pine_item_view.h"
|
#include "ash/wm/window_restore/pine_item_view.h"
|
||||||
#include "ash/wm/window_restore/pine_items_overflow_view.h"
|
#include "ash/wm/window_restore/pine_items_overflow_view.h"
|
||||||
#include "ash/wm/window_restore/window_restore_util.h"
|
|
||||||
#include "components/services/app_service/public/cpp/app_registry_cache.h"
|
|
||||||
#include "components/services/app_service/public/cpp/app_registry_cache_wrapper.h"
|
|
||||||
#include "ui/chromeos/styles/cros_tokens_color_mappings.h"
|
#include "ui/chromeos/styles/cros_tokens_color_mappings.h"
|
||||||
#include "ui/gfx/image/image_skia.h"
|
#include "ui/gfx/image/image_skia.h"
|
||||||
#include "ui/views/background.h"
|
#include "ui/views/background.h"
|
||||||
@@ -39,13 +36,6 @@ PineItemsContainerView::PineItemsContainerView(
|
|||||||
SetMainAxisAlignment(views::BoxLayout::MainAxisAlignment::kStart);
|
SetMainAxisAlignment(views::BoxLayout::MainAxisAlignment::kStart);
|
||||||
SetOrientation(views::BoxLayout::Orientation::kVertical);
|
SetOrientation(views::BoxLayout::Orientation::kVertical);
|
||||||
|
|
||||||
// TODO(http://b/328830102): Handle case where the app is not ready or
|
|
||||||
// installed.
|
|
||||||
apps::AppRegistryCache* cache =
|
|
||||||
apps::AppRegistryCacheWrapper::Get().GetAppRegistryCache(
|
|
||||||
Shell::Get()->session_controller()->GetActiveAccountId());
|
|
||||||
auto* delegate = Shell::Get()->saved_desk_delegate();
|
|
||||||
|
|
||||||
for (int i = 0; i < elements; ++i) {
|
for (int i = 0; i < elements; ++i) {
|
||||||
const PineContentsData::AppInfo& app_info = apps_infos[i];
|
const PineContentsData::AppInfo& app_info = apps_infos[i];
|
||||||
// If there are more than four elements, we will need to save the last
|
// If there are more than four elements, we will need to save the last
|
||||||
@@ -56,36 +46,21 @@ PineItemsContainerView::PineItemsContainerView(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// `title` will be the window title from the previous session stored in the
|
PineItemView* item_view = AddChildView(
|
||||||
// full restore file. The title fetched from the app service would more
|
std::make_unique<PineItemView>(app_info, /*inside_screenshot=*/false));
|
||||||
// accurate, but the app might not be installed yet. Browsers are always
|
|
||||||
// installed and `title` will be the active tab title fetched from session
|
|
||||||
// restore. `cache` might be null in a test environment.
|
|
||||||
// TODO(http://b/328830102): Title should be updated once app is installed.
|
|
||||||
std::string title = app_info.title;
|
|
||||||
if (cache && !IsBrowserAppId(app_info.app_id)) {
|
|
||||||
cache->ForOneApp(
|
|
||||||
app_info.app_id,
|
|
||||||
[&title](const apps::AppUpdate& update) { title = update.Name(); });
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(hewer|sammiequon): `PineItemView` should just take `app_info` and
|
|
||||||
// `cache` as a constructor argument.
|
|
||||||
PineItemView* item_view = AddChildView(std::make_unique<PineItemView>(
|
|
||||||
base::UTF8ToUTF16(title), app_info.tab_urls, app_info.tab_count,
|
|
||||||
/*inside_screenshot=*/false));
|
|
||||||
|
|
||||||
// The callback may be called synchronously.
|
// The callback may be called synchronously.
|
||||||
delegate->GetIconForAppId(app_info.app_id, pine::kAppImageSize,
|
Shell::Get()->saved_desk_delegate()->GetIconForAppId(
|
||||||
base::BindOnce(
|
app_info.app_id, pine::kAppImageSize,
|
||||||
[](base::WeakPtr<PineItemView> item_view_ptr,
|
base::BindOnce(
|
||||||
const gfx::ImageSkia& icon) {
|
[](base::WeakPtr<PineItemView> item_view_ptr,
|
||||||
if (item_view_ptr) {
|
const gfx::ImageSkia& icon) {
|
||||||
item_view_ptr->image_view()->SetImage(
|
if (item_view_ptr) {
|
||||||
ui::ImageModel::FromImageSkia(icon));
|
item_view_ptr->image_view()->SetImage(
|
||||||
}
|
ui::ImageModel::FromImageSkia(icon));
|
||||||
},
|
}
|
||||||
item_view->GetWeakPtr()));
|
},
|
||||||
|
item_view->GetWeakPtr()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -68,9 +68,7 @@ PineScreenshotIconRowView::PineScreenshotIconRowView(
|
|||||||
const PineContentsData::AppInfo& app_info = apps_infos[0];
|
const PineContentsData::AppInfo& app_info = apps_infos[0];
|
||||||
|
|
||||||
PineItemView* item_view = AddChildView(
|
PineItemView* item_view = AddChildView(
|
||||||
std::make_unique<PineItemView>(base::UTF8ToUTF16(app_info.title),
|
std::make_unique<PineItemView>(app_info, /*inside_screenshot=*/true));
|
||||||
app_info.tab_urls, app_info.tab_count,
|
|
||||||
/*inside_screenshot=*/true));
|
|
||||||
|
|
||||||
// The callback may be called synchronously.
|
// The callback may be called synchronously.
|
||||||
Shell::Get()->saved_desk_delegate()->GetIconForAppId(
|
Shell::Get()->saved_desk_delegate()->GetIconForAppId(
|
||||||
|
@@ -503,10 +503,13 @@ TEST_F(PineTest, ClickRestoreToExit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PineTest, PineItemView) {
|
TEST_F(PineTest, PineItemView) {
|
||||||
|
PineContentsData::AppInfo app_info(
|
||||||
|
"TEST_ID", "TEST_TITLE",
|
||||||
|
std::vector<GURL>{GURL(), GURL(), GURL(), GURL()}, 4u);
|
||||||
|
|
||||||
// Test when the tab count is within regular limits.
|
// Test when the tab count is within regular limits.
|
||||||
auto item_view = std::make_unique<PineItemView>(
|
auto item_view =
|
||||||
u"TEST", std::vector<GURL>{GURL(), GURL(), GURL(), GURL()}, 4u,
|
std::make_unique<PineItemView>(app_info, /*inside_screenshot=*/false);
|
||||||
/*inside_screenshot=*/false);
|
|
||||||
EXPECT_EQ(PineItemViewTestApi(item_view.get())
|
EXPECT_EQ(PineItemViewTestApi(item_view.get())
|
||||||
.favicon_container_view_for_testing()
|
.favicon_container_view_for_testing()
|
||||||
->children()
|
->children()
|
||||||
@@ -515,9 +518,9 @@ TEST_F(PineTest, PineItemView) {
|
|||||||
item_view.reset();
|
item_view.reset();
|
||||||
|
|
||||||
// Test the when the tab count has overflow.
|
// Test the when the tab count has overflow.
|
||||||
item_view = std::make_unique<PineItemView>(
|
app_info.tab_count = 10u;
|
||||||
u"TEST", std::vector<GURL>{GURL(), GURL(), GURL(), GURL(), GURL()}, 10u,
|
item_view =
|
||||||
/*inside_screenshot=*/false);
|
std::make_unique<PineItemView>(app_info, /*inside_screenshot=*/false);
|
||||||
EXPECT_EQ(PineItemViewTestApi(item_view.get())
|
EXPECT_EQ(PineItemViewTestApi(item_view.get())
|
||||||
.favicon_container_view_for_testing()
|
.favicon_container_view_for_testing()
|
||||||
->children()
|
->children()
|
||||||
|
Reference in New Issue
Block a user