Commit 86650271 authored by Maajid's avatar Maajid Committed by Commit Bot

Use the magnifying glass icon instead of the Google icon for the search box when the default search

provider is not Google.

Bug:736038
TEST:unit tested, device tested with --enable-features=EnableFullcreenAppList

Change-Id: Ib305fbbdfea06b7f21fad2aa717af91e0f20aec0
Reviewed-on: https://chromium-review.googlesource.com/557505
Commit-Queue: Maajid <maajid@chromium.org>
Reviewed-by: default avatarYury Khmel <khmel@chromium.org>
Reviewed-by: default avatarQiang(Joe) Xu <warx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486215}
parent e5700f47
......@@ -290,6 +290,7 @@ test("app_list_unittests") {
]
deps += [
"//ui/accessibility",
"//ui/app_list/vector_icons",
"//ui/views",
"//ui/views:test_support",
]
......
......@@ -160,6 +160,14 @@ const char kSearchResultDistanceFromOrigin[] =
// The height of tiles in search result.
const int kSearchTileHeight = 92;
// The size of the search icon in the search box.
const int kSearchIconSize = 24;
// Default color used when wallpaper customized color is not available for
// searchbox, #000 at 87% opacity.
const SkColor kDefaultSearchboxColor =
SkColorSetARGBMacro(0xDE, 0x00, 0x00, 0x00);
gfx::ShadowValue GetShadowForZHeight(int z_height) {
if (z_height <= 0)
return gfx::ShadowValue();
......
......@@ -110,6 +110,9 @@ APP_LIST_EXPORT extern const char kSearchResultDistanceFromOrigin[];
APP_LIST_EXPORT extern const int kSearchTileHeight;
APP_LIST_EXPORT extern const int kSearchIconSize;
APP_LIST_EXPORT extern const SkColor kDefaultSearchboxColor;
// Returns the shadow values for a view at |z_height|.
APP_LIST_EXPORT gfx::ShadowValue GetShadowForZHeight(int z_height);
......
......@@ -89,5 +89,9 @@ void AppListTestViewDelegate::ReplaceTestModel(int item_count) {
model_->PopulateApps(item_count);
}
void AppListTestViewDelegate::SetSearchEngineIsGoogle(bool is_google) {
model_->SetSearchEngineIsGoogle(is_google);
}
} // namespace test
} // namespace app_list
......@@ -47,6 +47,9 @@ class AppListTestViewDelegate : public AppListViewDelegate {
// value to 0.
int GetStopSpeechRecognitionCountAndReset();
// Sets whether the search engine is Google or not.
void SetSearchEngineIsGoogle(bool is_google);
// AppListViewDelegate overrides:
AppListModel* GetModel() override;
SpeechUIModel* GetSpeechUI() override;
......
......@@ -20,6 +20,8 @@ aggregate_vector_icons("app_list_vector_icons") {
"ic_google_black.icon",
"ic_mic_black.1x.icon",
"ic_mic_black.icon",
"ic_search_engine_not_google.1x.icon",
"ic_search_engine_not_google.icon",
]
}
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
CANVAS_DIMENSIONS, 24,
MOVE_TO, 15.5f, 14,
LINE_TO, 14.71f, 14,
LINE_TO, 14.43f, 13.73f,
CUBIC_TO, 15.41f, 12.59f, 16, 11.11f, 16, 9.5f,
CUBIC_TO, 16, 5.91f, 13.09f, 3, 9.5f, 3,
CUBIC_TO, 5.91f, 3, 3, 5.91f, 3, 9.5f,
CUBIC_TO, 3, 13.09f, 5.91f, 16, 9.5f, 16,
CUBIC_TO, 11.11f, 16, 12.59f, 15.41f, 13.73f, 14.43f,
LINE_TO, 14, 14.71f,
LINE_TO, 14, 15.5f,
LINE_TO, 19, 20.49f,
LINE_TO, 20.49f, 19,
LINE_TO, 15.5f, 14,
CLOSE,
MOVE_TO, 9.5f, 14,
CUBIC_TO, 7.01f, 14, 5, 11.99f, 5, 9.5f,
CUBIC_TO, 5, 7.01f, 7.01f, 5, 9.5f, 5,
CUBIC_TO, 11.99f, 5, 14, 7.01f, 14, 9.5f,
CUBIC_TO, 14, 11.99f, 11.99f, 14, 9.5f, 14,
CLOSE,
END
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
MOVE_TO, 31, 28,
LINE_TO, 29.42f, 28,
LINE_TO, 28.86f, 27.46f,
CUBIC_TO, 30.82f, 25.18f, 32, 22.22f, 32, 19,
CUBIC_TO, 32, 11.82f, 26.18f, 6, 19, 6,
CUBIC_TO, 11.82f, 6, 6, 11.82f, 6, 19,
CUBIC_TO, 6, 26.18f, 11.82f, 32, 19, 32,
CUBIC_TO, 22.22f, 32, 25.18f, 30.82f, 27.46f, 28.86f,
LINE_TO, 28, 29.42f,
LINE_TO, 28, 31,
LINE_TO, 38, 40.98f,
LINE_TO, 40.98f, 38,
LINE_TO, 31, 28,
CLOSE,
MOVE_TO, 19, 28,
CUBIC_TO, 14.02f, 28, 10, 23.98f, 10, 19,
CUBIC_TO, 10, 14.02f, 14.02f, 10, 19, 10,
CUBIC_TO, 23.98f, 10, 28, 14.02f, 28, 19,
CUBIC_TO, 28, 23.98f, 23.98f, 28, 19, 28,
CLOSE,
END
......@@ -58,14 +58,8 @@ constexpr SkColor kHintTextColor = SkColorSetARGBMacro(0xFF, 0xA0, 0xA0, 0xA0);
constexpr int kBackgroundBorderCornerRadius = 2;
constexpr int kBackgroundBorderCornerRadiusFullscreen = 24;
constexpr int kGoogleIconSize = 24;
constexpr int kMicIconSize = 24;
// Default color used when wallpaper customized color is not available for
// searchbox, #000 at 87% opacity.
constexpr SkColor kDefaultSearchboxColor =
SkColorSetARGBMacro(0xDE, 0x00, 0x00, 0x00);
constexpr int kLightVibrantBlendAlpha = 0xB3;
// Color of placeholder text in zero query state.
......@@ -152,7 +146,7 @@ SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate,
view_delegate_(view_delegate),
model_(nullptr),
content_container_(new views::View),
google_icon_(nullptr),
search_icon_(nullptr),
back_button_(nullptr),
speech_button_(nullptr),
search_box_(new views::Textfield),
......@@ -195,11 +189,10 @@ SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate,
content_container_->AddChildView(back_button_);
if (is_fullscreen_app_list_enabled_) {
google_icon_ = new views::ImageView();
google_icon_->SetImage(gfx::CreateVectorIcon(
kIcGoogleBlackIcon, kGoogleIconSize, kDefaultSearchboxColor));
content_container_->AddChildView(google_icon_);
search_icon_ = new views::ImageView();
UpdateSearchIcon(view_delegate_->GetModel()->search_engine_is_google(),
kDefaultSearchboxColor);
content_container_->AddChildView(search_icon_);
search_box_->set_placeholder_text_color(kDefaultSearchboxColor);
search_box_->set_placeholder_text_draw_flags(
gfx::Canvas::TEXT_ALIGN_CENTER);
......@@ -227,6 +220,8 @@ void SearchBoxView::ModelChanged() {
model_ = view_delegate_->GetModel();
DCHECK(model_);
if (is_fullscreen_app_list_enabled_)
UpdateSearchIcon(model_->search_engine_is_google(), kDefaultSearchboxColor);
model_->search_box()->AddObserver(this);
SpeechRecognitionButtonPropChanged();
HintTextChanged();
......@@ -356,7 +351,7 @@ void SearchBoxView::ShowBackOrGoogleIcon(bool show_back_button) {
if (!is_fullscreen_app_list_enabled_)
return;
google_icon_->SetVisible(!show_back_button);
search_icon_->SetVisible(!show_back_button);
back_button_->SetVisible(show_back_button);
content_container_->Layout();
}
......@@ -600,29 +595,24 @@ void SearchBoxView::WallpaperProminentColorsChanged() {
prominent_colors.size());
const SkColor dark_muted =
prominent_colors[static_cast<int>(ColorProfileType::DARK_MUTED)];
const bool dark_muted_available = SK_ColorTRANSPARENT != dark_muted;
google_icon_->SetImage(gfx::CreateVectorIcon(
kIcGoogleBlackIcon, kGoogleIconSize,
dark_muted_available ? dark_muted : kDefaultSearchboxColor));
const SkColor search_box_color =
SK_ColorTRANSPARENT == dark_muted ? kDefaultSearchboxColor : dark_muted;
UpdateSearchIcon(model_->search_engine_is_google(), search_box_color);
speech_button_->SetImage(
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(
kIcMicBlackIcon, kMicIconSize,
dark_muted_available ? dark_muted : kDefaultSearchboxColor));
search_box_->set_placeholder_text_color(
dark_muted_available ? dark_muted : kDefaultSearchboxColor);
gfx::CreateVectorIcon(kIcMicBlackIcon, kMicIconSize, search_box_color));
search_box_->set_placeholder_text_color(search_box_color);
const SkColor light_vibrant =
prominent_colors[static_cast<int>(ColorProfileType::LIGHT_VIBRANT)];
const SkColor light_vibrant_mixed = color_utils::AlphaBlend(
SK_ColorWHITE, light_vibrant, kLightVibrantBlendAlpha);
const bool light_vibrant_available = SK_ColorTRANSPARENT != light_vibrant;
content_container_->SetBackground(base::MakeUnique<SearchBoxBackground>(
light_vibrant_available ? light_vibrant_mixed
: kSearchBoxBackgroundDefault));
search_box_->SetBackgroundColor(light_vibrant_available
? light_vibrant_mixed
: kSearchBoxBackgroundDefault);
const SkColor background_color = SK_ColorTRANSPARENT == light_vibrant
? kSearchBoxBackgroundDefault
: light_vibrant_mixed;
content_container_->SetBackground(
base::MakeUnique<SearchBoxBackground>(background_color));
search_box_->SetBackgroundColor(background_color);
SchedulePaint();
}
......@@ -633,4 +623,12 @@ void SearchBoxView::OnSpeechRecognitionStateChanged(
SchedulePaint();
}
void SearchBoxView::UpdateSearchIcon(bool is_google,
const SkColor& search_box_color) {
const gfx::VectorIcon& icon =
is_google ? kIcGoogleBlackIcon : kIcSearchEngineNotGoogleIcon;
search_icon_->SetImage(
gfx::CreateVectorIcon(icon, kSearchIconSize, search_box_color));
}
} // namespace app_list
......@@ -107,6 +107,9 @@ class APP_LIST_EXPORT SearchBoxView : public views::View,
void OnGestureEvent(ui::GestureEvent* event) override;
void OnMouseEvent(ui::MouseEvent* event) override;
// Used only in the tests to get the current search icon.
views::ImageView* get_search_icon_for_test() { return search_icon_; }
private:
// Updates model text and selection model with current Textfield info.
void UpdateModel();
......@@ -114,6 +117,9 @@ class APP_LIST_EXPORT SearchBoxView : public views::View,
// Fires query change notification.
void NotifyQueryChanged();
// Updates the search icon.
void UpdateSearchIcon(bool is_google, const SkColor& search_box_color);
// Overridden from views::TextfieldController:
void ContentsChanged(views::Textfield* sender,
const base::string16& new_contents) override;
......@@ -143,7 +149,7 @@ class APP_LIST_EXPORT SearchBoxView : public views::View,
AppListModel* model_; // Owned by the profile-keyed service.
views::View* content_container_; // Owned by views hierarchy.
views::ImageView* google_icon_; // Owned by views hierarchy.
views::ImageView* search_icon_; // Owned by views hierarchy.
SearchBoxImageButton* back_button_; // Owned by views hierarchy.
SearchBoxImageButton* speech_button_; // Owned by views hierarchy.
views::Textfield* search_box_; // Owned by views hierarchy.
......
......@@ -9,8 +9,16 @@
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "ui/app_list/app_list_constants.h"
#include "ui/app_list/app_list_features.h"
#include "ui/app_list/test/app_list_test_view_delegate.h"
#include "ui/app_list/vector_icons/vector_icons.h"
#include "ui/app_list/views/search_box_view_delegate.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_unittest_util.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/test/widget_test.h"
......@@ -127,6 +135,43 @@ class SearchBoxViewTest : public views::test::WidgetTest,
DISALLOW_COPY_AND_ASSIGN(SearchBoxViewTest);
};
class SearchBoxViewFullScreenTest : public views::test::WidgetTest {
public:
SearchBoxViewFullScreenTest() {}
~SearchBoxViewFullScreenTest() override {}
// Overridden from testing::Test:
void SetUp() override {
views::test::WidgetTest::SetUp();
scoped_feature_list_.InitAndEnableFeature(
app_list::features::kEnableFullscreenAppList);
widget_ = CreateTopLevelPlatformWidget();
widget_->SetBounds(gfx::Rect(0, 0, 300, 200));
view_ = new SearchBoxView(nullptr, &view_delegate_);
}
void TearDown() override {
widget_->CloseNow();
views::test::WidgetTest::TearDown();
}
protected:
SearchBoxView* view() { return view_; }
void SetSearchEngineIsGoogle(bool is_google) {
view_delegate_.SetSearchEngineIsGoogle(is_google);
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
AppListTestViewDelegate view_delegate_;
views::Widget* widget_;
SearchBoxView* view_;
DISALLOW_COPY_AND_ASSIGN(SearchBoxViewFullScreenTest);
};
TEST_F(SearchBoxViewTest, Basic) {
KeyPress(ui::VKEY_A);
EXPECT_EQ("a", GetLastQueryAndReset());
......@@ -164,5 +209,29 @@ TEST_F(SearchBoxViewTest, CancelAutoLaunch) {
EXPECT_EQ(base::TimeDelta(), GetAutoLaunchTimeout());
}
TEST_F(SearchBoxViewFullScreenTest, SearchEngineGoogle) {
SetSearchEngineIsGoogle(true);
gfx::ImageSkia expected_icon = gfx::CreateVectorIcon(
kIcGoogleBlackIcon, kSearchIconSize, kDefaultSearchboxColor);
view()->ModelChanged();
gfx::ImageSkia actual_icon = view()->get_search_icon_for_test()->GetImage();
EXPECT_TRUE(gfx::test::AreBitmapsEqual(*expected_icon.bitmap(),
*actual_icon.bitmap()));
}
TEST_F(SearchBoxViewFullScreenTest, SearchEngineNotGoogle) {
SetSearchEngineIsGoogle(false);
gfx::ImageSkia expected_icon = gfx::CreateVectorIcon(
kIcSearchEngineNotGoogleIcon, kSearchIconSize, kDefaultSearchboxColor);
view()->ModelChanged();
gfx::ImageSkia actual_icon = view()->get_search_icon_for_test()->GetImage();
EXPECT_TRUE(gfx::test::AreBitmapsEqual(*expected_icon.bitmap(),
*actual_icon.bitmap()));
}
} // namespace test
} // namespace app_list
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