Skip to content

Commit

Permalink
Implement more details of LauncherSearchIph
Browse files Browse the repository at this point in the history
- Add backgrounds for LauncherSearchIph view and assistant button.
- LauncherSearchIph won't be shown if Assistant is not available.
- Add stylings, etc.

Bug: b:272370530
Test: ash_pixeltests --gtest_filter=*AppListViewLauncherSearchIphTest*
Test: browser_tests --gtest_filter=*AppListIphBrowserTest*
Change-Id: Ia8c5b5f4d6e88fefc5c4509fed42a2fdfc0b49b6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4370619
Commit-Queue: Yuki Awano <yawano@google.com>
Quick-Run: Yuki Awano <yawano@google.com>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Toni Barzic <tbarzic@chromium.org>
Reviewed-by: Tao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1123353}
  • Loading branch information
Yuki Awano authored and Chromium LUCI CQ committed Mar 28, 2023
1 parent a76f6f9 commit 682129d
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 51 deletions.
41 changes: 36 additions & 5 deletions ash/app_list/views/app_list_view_pixeltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "ash/app_list/views/apps_container_view.h"
#include "ash/app_list/views/apps_grid_view_test_api.h"
#include "ash/app_list/views/search_box_view.h"
#include "ash/assistant/test/assistant_ash_test_base.h"
#include "ash/public/cpp/style/dark_light_mode_controller.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_navigation_widget.h"
#include "ash/shell.h"
Expand Down Expand Up @@ -186,19 +188,44 @@ TEST_P(AppListViewPixelRTLTest, GradientZone) {
GetPrimaryShelf()->navigation_widget()));
}

class LauncherSearchIphParams {
public:
LauncherSearchIphParams(bool rtl, bool dark_theme)
: rtl_(rtl), dark_theme_(dark_theme) {}

static std::string ToTestSuffix(
const testing::TestParamInfo<LauncherSearchIphParams>& info) {
std::string suffix;
suffix.append(info.param.rtl() ? "rtl" : "ltr");
suffix.append("_");
suffix.append(info.param.dark_theme() ? "dark" : "light");
return suffix;
}

bool rtl() const { return rtl_; }
bool dark_theme() const { return dark_theme_; }

private:
bool rtl_;
bool dark_theme_;
};

class AppListViewLauncherSearchIphTest
: public AshTestBase,
public testing::WithParamInterface</*rtl=*/bool> {
: public AssistantAshTestBase,
public testing::WithParamInterface<LauncherSearchIphParams> {
public:
absl::optional<pixel_test::InitParams> CreatePixelTestInitParams()
const override {
pixel_test::InitParams init_params;
init_params.under_rtl = GetParam();
init_params.under_rtl = GetParam().rtl();
return init_params;
}

void SetUp() override {
AshTestBase::SetUp();
AssistantAshTestBase::SetUp();

DarkLightModeController::Get()->SetDarkModeEnabledForTest(
GetParam().dark_theme());

AppListTestHelper* test_helper = GetAppListTestHelper();
test_helper->ShowAppList();
Expand All @@ -210,7 +237,11 @@ class AppListViewLauncherSearchIphTest

INSTANTIATE_TEST_SUITE_P(RTL,
AppListViewLauncherSearchIphTest,
testing::Bool());
testing::Values(LauncherSearchIphParams(false, false),
LauncherSearchIphParams(false, true),
LauncherSearchIphParams(true, false),
LauncherSearchIphParams(true, true)),
&LauncherSearchIphParams::ToTestSuffix);

TEST_P(AppListViewLauncherSearchIphTest, Basic) {
// Wait re-layout for adding IPH view.
Expand Down
55 changes: 41 additions & 14 deletions ash/app_list/views/launcher_search_iph_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
#include <string>
#include <utility>

#include "ash/assistant/ui/main_stage/chip_view.h"
#include "ash/public/cpp/app_list/app_list_client.h"
#include "ash/style/ash_color_id.h"
#include "ash/style/pill_button.h"
#include "ash/style/typography.h"
#include "base/functional/bind.h"
#include "base/i18n/rtl.h"
#include "ui/color/color_id.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/text_constants.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
Expand All @@ -23,9 +29,6 @@ namespace {
constexpr int kVerticalInset = 20;
constexpr int kHorizontalInset = 24;

constexpr int kTitleTextFontSize = 20;
constexpr int kDescriptionTextFontSize = 16;

constexpr int kMainLayoutBetweenChildSpacing = 16;
constexpr int kActionContainerBetweenChildSpacing = 8;

Expand All @@ -37,6 +40,17 @@ constexpr char16_t kChipTwoQueryPlaceholder[] = u"1+1";
constexpr char16_t kChipThreeQueryPlaceholder[] = u"5 cm in inches";

constexpr char16_t kAssistantButtonPlaceholder[] = u"Assistant";

constexpr views::Radii kBackgroundRadiiLTR = {.top_left = 16.0f,
.top_right = 4.0f,
.bottom_right = 16.0f,
.bottom_left = 16.0f};

constexpr views::Radii kBackgroundRadiiRTL = {.top_left = 4.0f,
.top_right = 16.0f,
.bottom_right = 16.0f,
.bottom_left = 16.0f};

} // namespace

LauncherSearchIphView::LauncherSearchIphView(
Expand Down Expand Up @@ -64,18 +78,23 @@ LauncherSearchIphView::LauncherSearchIphView(

raw_ptr<views::Label> title_label = text_container->AddChildView(
std::make_unique<views::Label>(kTitleTextPlaceholder));
title_label->SetFontList(gfx::FontList().DeriveWithSizeDelta(
kTitleTextFontSize - gfx::FontList().GetFontSize()));
title_label->SetLineHeight(kTitleTextFontSize);
title_label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_TO_HEAD);
title_label->SetEnabledColorId(kColorAshTextColorPrimary);

raw_ptr<views::Label> description_label = text_container->AddChildView(
std::make_unique<views::Label>(kDescriptionTextPlaceholder));
description_label->SetFontList(gfx::FontList().DeriveWithSizeDelta(
kDescriptionTextFontSize - gfx::FontList().GetFontSize()));
description_label->SetLineHeight(kDescriptionTextFontSize);
description_label->SetHorizontalAlignment(
gfx::HorizontalAlignment::ALIGN_TO_HEAD);
description_label->SetEnabledColorId(kColorAshTextColorPrimary);

raw_ptr<const TypographyProvider> typography_provider =
TypographyProvider::Get();
DCHECK(typography_provider) << "TypographyProvider must not be null";
if (typography_provider) {
typography_provider->StyleLabel(TypographyToken::kCrosTitle1, *title_label);
typography_provider->StyleLabel(TypographyToken::kCrosBody2,
*description_label);
}

raw_ptr<views::BoxLayoutView> actions_container =
AddChildView(std::make_unique<views::BoxLayoutView>());
Expand All @@ -87,11 +106,12 @@ LauncherSearchIphView::LauncherSearchIphView(
for (const std::u16string& query :
{kChipOneQueryPlaceholder, kChipTwoQueryPlaceholder,
kChipThreeQueryPlaceholder}) {
raw_ptr<ash::PillButton> chip =
actions_container->AddChildView(std::make_unique<ash::PillButton>(
base::BindRepeating(&LauncherSearchIphView::RunLauncherSearchQuery,
weak_ptr_factory_.GetWeakPtr(), query),
query));
raw_ptr<ChipView> chip = actions_container->AddChildView(
std::make_unique<ChipView>(ChipView::Type::kLarge));
chip->SetText(query);
chip->SetCallback(
base::BindRepeating(&LauncherSearchIphView::RunLauncherSearchQuery,
weak_ptr_factory_.GetWeakPtr(), query));
chip->SetID(query_chip_view_id);
query_chip_view_id++;
}
Expand All @@ -106,6 +126,13 @@ LauncherSearchIphView::LauncherSearchIphView(
weak_ptr_factory_.GetWeakPtr()),
kAssistantButtonPlaceholder));
assistant_button->SetID(ViewId::kAssistant);
assistant_button->SetPillButtonType(
PillButton::Type::kDefaultLargeWithoutIcon);

SetBackground(views::CreateThemedRoundedRectBackground(
kColorAshControlBackgroundColorInactive,
base::i18n::IsRTL() ? kBackgroundRadiiRTL : kBackgroundRadiiLTR,
/*for_border_thickness=*/0));
}

LauncherSearchIphView::~LauncherSearchIphView() = default;
Expand Down
37 changes: 35 additions & 2 deletions ash/app_list/views/search_box_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_id.h"
#include "ash/style/ash_color_provider.h"
#include "base/i18n/rtl.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
Expand All @@ -54,6 +55,7 @@
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/context_menu_controller.h"
#include "ui/views/controls/button/image_button.h"
Expand Down Expand Up @@ -104,6 +106,20 @@ constexpr SearchBoxView::PlaceholderTextType kGamingPlaceholders[4] = {
SearchBoxView::PlaceholderTextType::kGames,
};

constexpr views::Radii kAssistantButtonBackgroundRadiiLTR = {
.top_left = 18.0f,
.top_right = 18.0f,
.bottom_right = 4.0f,
.bottom_left = 18.0f,
};

constexpr views::Radii kAssistantButtonBackgroundRadiiRTL = {
.top_left = 18.0f,
.top_right = 18.0f,
.bottom_right = 18.0f,
.bottom_left = 4.0f,
};

bool IsTrimmedQueryEmpty(const std::u16string& query) {
std::u16string trimmed_query;
base::TrimWhitespace(query, base::TrimPositions::TRIM_ALL, &trimmed_query);
Expand Down Expand Up @@ -1223,15 +1239,25 @@ void SearchBoxView::ShowAssistantChanged() {
->search_model()
->search_box()
->show_assistant_button());

// `LauncherSearchIphView` and an Assistant button have synchronized
// backgrounds. The IPH UI is integrated with the Assistant button. We don't
// show an IPH if Assistant is disabled. Both `LauncherSearchIphView` and the
// Assistant button are hosted by `SearchBoxViewBase`.
UpdateIphViewVisibility();
}

void SearchBoxView::UpdateIphViewVisibility() {
const bool show_assistant_button = AppListModelProvider::Get()
->search_model()
->search_box()
->show_assistant_button();
const bool would_trigger_iph =
AppListModelProvider::Get()->search_model()->would_trigger_iph();
const bool is_iph_showing = iph_view() != nullptr;

const bool should_show_iph =
is_iph_allowed_ && (would_trigger_iph || is_iph_showing);
const bool should_show_iph = show_assistant_button && is_iph_allowed_ &&
(would_trigger_iph || is_iph_showing);

if (should_show_iph == is_iph_showing) {
return;
Expand All @@ -1246,8 +1272,15 @@ void SearchBoxView::UpdateIphViewVisibility() {

SetIphView(std::make_unique<LauncherSearchIphView>(
std::move(scoped_iph_session), /*delegate=*/this));

assistant_button()->SetBackground(views::CreateThemedRoundedRectBackground(
kColorAshControlBackgroundColorInactive,
base::i18n::IsRTL() ? kAssistantButtonBackgroundRadiiRTL
: kAssistantButtonBackgroundRadiiLTR,
/*for_border_thickness=*/0));
} else {
DeleteIphView();
assistant_button()->SetBackground(nullptr);
}
}

Expand Down
31 changes: 25 additions & 6 deletions ash/assistant/ui/main_stage/chip_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "ash/assistant/ui/assistant_view_ids.h"
#include "ash/style/ash_color_id.h"
#include "ash/style/typography.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/color/color_id.h"
#include "ui/color/color_provider.h"
Expand All @@ -33,10 +34,11 @@ constexpr int kFocusedStrokeWidthDip = 2;

constexpr int kIconMarginDip = 8;
constexpr int kChipPaddingDip = 16;
constexpr int kPreferredHeightDip = 32;
constexpr int kPreferredHeightDipDefault = 32;
constexpr int kPreferredHeightDipLarge = 36;
} // namespace

ChipView::ChipView() {
ChipView::ChipView(Type type) : type_(type) {
// Focus.
// 1. Dark light mode is OFF
// We change background color of a suggestion chip view. No focus ring is
Expand Down Expand Up @@ -77,9 +79,25 @@ ChipView::ChipView() {
text_view_->SetID(kSuggestionChipViewLabel);
text_view_->SetAutoColorReadabilityEnabled(false);
text_view_->SetSubpixelRenderingEnabled(false);
const gfx::FontList& font_list = assistant::ui::GetDefaultFontList();
text_view_->SetFontList(font_list.Derive(
/*size_delta=*/1, font_list.GetFontStyle(), gfx::Font::Weight::MEDIUM));

switch (type_) {
case Type::kDefault: {
const gfx::FontList& font_list = assistant::ui::GetDefaultFontList();
text_view_->SetFontList(font_list.Derive(
/*size_delta=*/1, font_list.GetFontStyle(),
gfx::Font::Weight::MEDIUM));
break;
}
case Type::kLarge: {
raw_ptr<const TypographyProvider> typography_provider =
TypographyProvider::Get();
DCHECK(typography_provider) << "TypographyProvider must not be null";
if (typography_provider) {
typography_provider->StyleLabel(TypographyToken::kCrosButton1,
*text_view_);
}
} break;
}
}

ChipView::~ChipView() = default;
Expand All @@ -90,7 +108,8 @@ gfx::Size ChipView::CalculatePreferredSize() const {
}

int ChipView::GetHeightForWidth(int width) const {
return kPreferredHeightDip;
return type_ == Type::kDefault ? kPreferredHeightDipDefault
: kPreferredHeightDipLarge;
}

void ChipView::ChildVisibilityChanged(views::View* child) {
Expand Down
5 changes: 4 additions & 1 deletion ash/assistant/ui/main_stage/chip_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ namespace ash {

class COMPONENT_EXPORT(ASSISTANT_UI) ChipView : public views::Button {
public:
enum Type { kDefault, kLarge };

static constexpr int kIconSizeDip = 16;

ChipView();
explicit ChipView(Type type);
~ChipView() override;

// views::View:
Expand All @@ -42,6 +44,7 @@ class COMPONENT_EXPORT(ASSISTANT_UI) ChipView : public views::Button {
METADATA_HEADER(ChipView);

private:
const Type type_;
raw_ptr<views::BoxLayout> layout_manager_;
raw_ptr<views::ImageView> icon_view_;
raw_ptr<views::Label> text_view_;
Expand Down
4 changes: 3 additions & 1 deletion ash/assistant/ui/main_stage/suggestion_chip_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ namespace ash {

SuggestionChipView::SuggestionChipView(AssistantViewDelegate* delegate,
const AssistantSuggestion& suggestion)
: delegate_(delegate), suggestion_id_(suggestion.id) {
: ChipView(Type::kDefault),
delegate_(delegate),
suggestion_id_(suggestion.id) {
SetText(base::UTF8ToUTF16(suggestion.text));

const GURL& url = suggestion.icon_url;
Expand Down
Loading

0 comments on commit 682129d

Please sign in to comment.