Skip to content

Commit

Permalink
Update search box view to use themed colors in default base constructor.
Browse files Browse the repository at this point in the history
Bug: 1146141
Change-Id: I9d3a6dcb37f0435e29ee506bb0c7c2d678435332
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2522632
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: Toni Baržić <tbarzic@chromium.org>
Reviewed-by: Yulun Wu <yulunwu@chromium.org>
Commit-Queue: Yulun Wu <yulunwu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825011}
  • Loading branch information
Yulun Wu authored and Commit Bot committed Nov 6, 2020
1 parent bf58a86 commit 5566182
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
1 change: 1 addition & 0 deletions ash/search_box/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ source_set("search_box") {
]

deps = [
"//ash/public/cpp",
"//base",
"//skia",
"//ui/base",
Expand Down
15 changes: 10 additions & 5 deletions ash/search_box/search_box_view_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <memory>
#include <vector>

#include "ash/public/cpp/app_list/app_list_color_provider.h"
#include "ash/search_box/search_box_view_delegate.h"
#include "base/macros.h"
#include "third_party/skia/include/core/SkPath.h"
Expand Down Expand Up @@ -233,7 +234,8 @@ SearchBoxViewBase::SearchBoxViewBase(SearchBoxViewDelegate* delegate)
AddChildView(content_container_);

content_container_->SetBackground(std::make_unique<SearchBoxBackground>(
kSearchBoxBorderCornerRadius, kSearchBoxBackgroundDefault));
kSearchBoxBorderCornerRadius,
ash::AppListColorProvider::Get()->GetSearchBoxBackgroundColor()));

box_layout_ =
content_container_->SetLayoutManager(std::make_unique<views::BoxLayout>(
Expand All @@ -260,7 +262,8 @@ SearchBoxViewBase::SearchBoxViewBase(SearchBoxViewDelegate* delegate)
search_icon_ = new views::ImageView();
content_container_->AddChildView(search_icon_);
search_box_->set_placeholder_text_color(
kDefaultSearchboxPlaceholderTextColor);
ash::AppListColorProvider::Get()->GetSearchBoxSecondaryTextColor(
kDefaultSearchboxPlaceholderTextColor));
search_box_->set_placeholder_text_draw_flags(gfx::Canvas::TEXT_ALIGN_CENTER);
search_box_->SetFontList(search_box_->GetFontList().DeriveWithSizeDelta(2));
search_box_->SetCursorEnabled(is_search_box_active_);
Expand Down Expand Up @@ -335,14 +338,16 @@ void SearchBoxViewBase::SetSearchBoxActive(bool active,

is_search_box_active_ = active;
UpdateSearchIcon();
UpdateBackgroundColor(kSearchBoxBackgroundDefault);
UpdateBackgroundColor(
ash::AppListColorProvider::Get()->GetSearchBoxBackgroundColor());
search_box_->set_placeholder_text_draw_flags(
active ? (base::i18n::IsRTL() ? gfx::Canvas::TEXT_ALIGN_RIGHT
: gfx::Canvas::TEXT_ALIGN_LEFT)
: gfx::Canvas::TEXT_ALIGN_CENTER);
search_box_->set_placeholder_text_color(
active ? kZeroQuerySearchboxColor
: kDefaultSearchboxPlaceholderTextColor);
ash::AppListColorProvider::Get()->GetSearchBoxSecondaryTextColor(
active ? kZeroQuerySearchboxColor
: kDefaultSearchboxPlaceholderTextColor));
search_box_->SetCursorEnabled(active);

if (active) {
Expand Down
24 changes: 15 additions & 9 deletions ash/shortcut_viewer/views/ksv_search_box_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "ash/shortcut_viewer/views/ksv_search_box_view.h"

#include "ash/public/cpp/app_list/app_list_color_provider.h"
#include "ash/search_box/search_box_view_delegate.h"
#include "ash/shortcut_viewer/strings/grit/shortcut_viewer_strings.h"
#include "ash/shortcut_viewer/vector_icons/vector_icons.h"
Expand All @@ -20,9 +21,6 @@ namespace keyboard_shortcut_viewer {

namespace {

constexpr SkColor kDefaultSearchBoxBackgroundColor =
SkColorSetARGB(0x28, 0x5F, 0x63, 0x68);

constexpr int kIconSize = 20;

// Border corner radius of the search box.
Expand All @@ -33,16 +31,21 @@ constexpr int kBorderCornerRadius = 32;
KSVSearchBoxView::KSVSearchBoxView(ash::SearchBoxViewDelegate* delegate)
: ash::SearchBoxViewBase(delegate) {
SetSearchBoxBackgroundCornerRadius(kBorderCornerRadius);
UpdateBackgroundColor(kDefaultSearchBoxBackgroundColor);
UpdateBackgroundColor(
ash::AppListColorProvider::Get()->GetSearchBoxBackgroundColor());
search_box()->SetBackgroundColor(SK_ColorTRANSPARENT);
search_box()->SetColor(gfx::kGoogleGrey900);
search_box()->SetColor(
ash::AppListColorProvider::Get()->GetSearchBoxTextColor(
gfx::kGoogleGrey900));
SetPlaceholderTextAttributes();
const base::string16 search_box_name(
l10n_util::GetStringUTF16(IDS_KSV_SEARCH_BOX_ACCESSIBILITY_NAME));
search_box()->SetPlaceholderText(search_box_name);
search_box()->SetAccessibleName(search_box_name);
SetSearchIconImage(
gfx::CreateVectorIcon(kKsvSearchBarIcon, gfx::kGoogleGrey900));
SetSearchIconImage(gfx::CreateVectorIcon(
kKsvSearchBarIcon,
ash::AppListColorProvider::Get()->GetSearchBoxIconColor(
gfx::kGoogleGrey900)));
}

gfx::Size KSVSearchBoxView::CalculatePreferredSize() const {
Expand Down Expand Up @@ -95,7 +98,8 @@ void KSVSearchBoxView::UpdateSearchBoxBorder() {
}
SetBorder(views::CreateRoundedRectBorder(
kBorderThichness, kBorderCornerRadius, SK_ColorTRANSPARENT));
UpdateBackgroundColor(kDefaultSearchBoxBackgroundColor);
UpdateBackgroundColor(
ash::AppListColorProvider::Get()->GetSearchBoxBackgroundColor());
}

void KSVSearchBoxView::SetupCloseButton() {
Expand Down Expand Up @@ -144,7 +148,9 @@ void KSVSearchBoxView::OnSearchBoxActiveChanged(bool active) {
}

void KSVSearchBoxView::SetPlaceholderTextAttributes() {
search_box()->set_placeholder_text_color(ash::kZeroQuerySearchboxColor);
search_box()->set_placeholder_text_color(
ash::AppListColorProvider::Get()->GetSearchBoxSecondaryTextColor(
ash::kZeroQuerySearchboxColor));
search_box()->set_placeholder_text_draw_flags(
base::i18n::IsRTL() ? gfx::Canvas::TEXT_ALIGN_RIGHT
: gfx::Canvas::TEXT_ALIGN_LEFT);
Expand Down

0 comments on commit 5566182

Please sign in to comment.