Commit aa96666b authored by Patti's avatar Patti Committed by Commit Bot

Omnibox/Views: Fix KeywordHintView colors for touch.

The KeywordHintView should be dark in incognito mode in touch. Fix.

This patch also fixes a bug where the KeywordHintView would not update itself if
the browser window was resized with it showing.

See screenshots -
https://drive.google.com/file/d/1RM2TC9Wg3Js6UCrntkWc808pj_S3A59b/view?usp=sharing

Bug: 830328
Change-Id: If9bb98d447454d34448cd9d63d31e6afc471cecc
Reviewed-on: https://chromium-review.googlesource.com/1004714Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Patti <patricialor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550511}
parent 7a9ab1ca
......@@ -98,6 +98,7 @@ ui::NativeTheme::ColorId GetLegacyColorId(ui::NativeTheme* native_theme,
case OmniboxPart::LOCATION_BAR_SECURITY_CHIP:
case OmniboxPart::LOCATION_BAR_TEXT_DIMMED:
case OmniboxPart::LOCATION_BAR_BUBBLE_OUTLINE:
case OmniboxPart::RESULTS_ICON:
case OmniboxPart::RESULTS_TEXT_INVISIBLE:
NOTREACHED();
......@@ -256,6 +257,10 @@ SkColor GetOmniboxColor(OmniboxPart part,
case OmniboxPart::RESULTS_TEXT_URL:
return dark ? gfx::kGoogleBlueDark600 : gfx::kGoogleBlue600;
case OmniboxPart::LOCATION_BAR_BUBBLE_OUTLINE:
return dark ? gfx::kGoogleGrey100
: SkColorSetA(gfx::kGoogleGrey900, 0x24);
// TODO(tapted): Add these.
case OmniboxPart::LOCATION_BAR_CLEAR_ALL:
case OmniboxPart::LOCATION_BAR_IME_AUTOCOMPLETE_BACKGROUND:
......
......@@ -17,6 +17,7 @@ enum class OmniboxPart {
LOCATION_BAR_SELECTED_KEYWORD,
LOCATION_BAR_TEXT_DEFAULT,
LOCATION_BAR_TEXT_DIMMED,
LOCATION_BAR_BUBBLE_OUTLINE,
RESULTS_BACKGROUND, // Background of the results dropdown.
RESULTS_ICON,
......
......@@ -13,6 +13,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/omnibox/omnibox_theme.h"
#include "chrome/browser/ui/views/harmony/chrome_typography.h"
#include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
......@@ -20,6 +21,7 @@
#include "components/search_engines/template_url_service.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/gfx/color_utils.h"
#include "ui/strings/grit/ui_strings.h"
#include "ui/views/accessibility/view_accessibility.h"
......@@ -29,8 +31,7 @@
KeywordHintView::KeywordHintView(views::ButtonListener* listener,
Profile* profile,
SkColor text_color,
SkColor background_color)
OmniboxTint tint)
: Button(listener),
profile_(profile),
leading_label_(nullptr),
......@@ -38,6 +39,14 @@ KeywordHintView::KeywordHintView(views::ButtonListener* listener,
chip_label_(
new views::Label(base::string16(), CONTEXT_OMNIBOX_DECORATION)),
trailing_label_(nullptr) {
const bool is_newer_material =
ui::MaterialDesignController::IsNewerMaterialUi();
SkColor text_color =
is_newer_material
? GetOmniboxColor(OmniboxPart::LOCATION_BAR_TEXT_DEFAULT, tint)
: GetOmniboxColor(OmniboxPart::LOCATION_BAR_TEXT_DIMMED, tint);
SkColor background_color =
GetOmniboxColor(OmniboxPart::LOCATION_BAR_BACKGROUND, tint);
leading_label_ = CreateLabel(text_color, background_color);
constexpr int kPaddingInsideBorder = 5;
......@@ -49,10 +58,16 @@ KeywordHintView::KeywordHintView(views::ButtonListener* listener,
chip_label_->SetBorder(
views::CreateEmptyBorder(gfx::Insets(0, horizontal_padding)));
chip_label_->SetEnabledColor(text_color);
bool inverted = color_utils::IsDark(background_color);
SkColor tab_bg_color =
inverted ? SK_ColorWHITE : SkColorSetA(text_color, 0x13);
SkColor tab_border_color = inverted ? SK_ColorWHITE : text_color;
if (is_newer_material) {
tab_bg_color = background_color;
tab_border_color =
GetOmniboxColor(OmniboxPart::LOCATION_BAR_BUBBLE_OUTLINE, tint);
}
chip_label_->SetBackgroundColor(tab_bg_color);
chip_container_->SetBorder(views::CreateEmptyBorder(
......@@ -75,7 +90,20 @@ KeywordHintView::KeywordHintView(views::ButtonListener* listener,
KeywordHintView::~KeywordHintView() {}
void KeywordHintView::SetKeyword(const base::string16& keyword) {
void KeywordHintView::SetKeyword(const base::string16& keyword,
bool popup_open,
OmniboxTint tint) {
// In the newer MD style, the KeywordHintView chip background should match the
// LocationBarView's background, which changes when the popup is open.
if (ui::MaterialDesignController::IsNewerMaterialUi()) {
OmniboxPart background_part = popup_open
? OmniboxPart::RESULTS_BACKGROUND
: OmniboxPart::LOCATION_BAR_BACKGROUND;
SkColor tab_bg_color = GetOmniboxColor(background_part, tint);
chip_label_->SetBackgroundColor(tab_bg_color);
chip_container_->background()->SetNativeControlColor(tab_bg_color);
}
// When the virtual keyboard is visible, we show a modified touch UI
// containing only the chip and no surrounding labels.
const bool was_touch_ui = leading_label_->text().empty();
......@@ -197,12 +225,13 @@ gfx::Size KeywordHintView::CalculatePreferredSize() const {
}
void KeywordHintView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
if (!BackgroundWith1PxBorder::IsRounded())
return;
const int chip_corner_radius = GetCornerRadius();
chip_label_->SetBorder(views::CreateEmptyBorder(
gfx::Insets(GetInsets().top(), chip_corner_radius, GetInsets().bottom(),
chip_corner_radius)));
if (BackgroundWith1PxBorder::IsRounded()) {
const int chip_corner_radius = GetCornerRadius();
chip_label_->SetBorder(views::CreateEmptyBorder(
gfx::Insets(GetInsets().top(), chip_corner_radius, GetInsets().bottom(),
chip_corner_radius)));
}
views::Button::OnBoundsChanged(previous_bounds);
}
views::Label* KeywordHintView::CreateLabel(SkColor text_color,
......
......@@ -13,6 +13,7 @@
#include "ui/views/controls/button/button.h"
class Profile;
enum class OmniboxTint;
namespace views {
class Label;
......@@ -31,11 +32,12 @@ class KeywordHintView : public views::Button {
public:
KeywordHintView(views::ButtonListener* listener,
Profile* profile,
SkColor text_color,
SkColor background_color);
OmniboxTint tint);
~KeywordHintView() override;
void SetKeyword(const base::string16& keyword);
void SetKeyword(const base::string16& keyword,
bool popup_open,
OmniboxTint tint);
// views::View:
gfx::Insets GetInsets() const override;
......
......@@ -194,8 +194,6 @@ void LocationBarView::Init() {
const gfx::FontList& font_list = views::style::GetFont(
CONTEXT_OMNIBOX_PRIMARY, views::style::STYLE_PRIMARY);
const SkColor background_color =
GetColor(OmniboxPart::LOCATION_BAR_BACKGROUND);
location_icon_view_ = new LocationIconView(font_list, this);
location_icon_view_->set_drag_controller(this);
AddChildView(location_icon_view_);
......@@ -225,9 +223,7 @@ void LocationBarView::Init() {
selected_keyword_view_ = new SelectedKeywordView(this, font_list, profile());
AddChildView(selected_keyword_view_);
keyword_hint_view_ = new KeywordHintView(
this, profile(), GetColor(OmniboxPart::LOCATION_BAR_TEXT_DIMMED),
background_color);
keyword_hint_view_ = new KeywordHintView(this, profile(), tint());
AddChildView(keyword_hint_view_);
std::vector<std::unique_ptr<ContentSettingImageModel>> models =
......@@ -552,7 +548,8 @@ void LocationBarView::Layout() {
trailing_decorations.AddDecoration(vertical_padding, location_height, true,
0, item_padding, item_padding,
keyword_hint_view_);
keyword_hint_view_->SetKeyword(keyword);
keyword_hint_view_->SetKeyword(keyword, GetOmniboxPopupView()->IsOpen(),
tint());
}
add_trailing_decoration(clear_all_button_);
......
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