Commit 99b711b9 authored by Vasilii Sukhanov's avatar Vasilii Sukhanov Committed by Commit Bot

Support the dark mode in the autofill dropdown on Linux.

Additionally, modify the generation prompt to have correct colors as well.

Bug: 1043765
Change-Id: I3e9701489f1c0030bd88fe940e55b6318523924d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2025599
Commit-Queue: Vasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736545}
parent 8adb84c8
...@@ -2741,8 +2741,6 @@ jumbo_static_library("ui") { ...@@ -2741,8 +2741,6 @@ jumbo_static_library("ui") {
"views/autofill/payments/save_card_sign_in_promo_bubble_views.h", "views/autofill/payments/save_card_sign_in_promo_bubble_views.h",
"views/autofill/payments/save_upi_offer_bubble_views.cc", "views/autofill/payments/save_upi_offer_bubble_views.cc",
"views/autofill/payments/save_upi_offer_bubble_views.h", "views/autofill/payments/save_upi_offer_bubble_views.h",
"views/autofill/view_util.cc",
"views/autofill/view_util.h",
"views/bookmarks/bookmark_bar_view.cc", "views/bookmarks/bookmark_bar_view.cc",
"views/bookmarks/bookmark_bar_view.h", "views/bookmarks/bookmark_bar_view.h",
"views/bookmarks/bookmark_bar_view_observer.h", "views/bookmarks/bookmark_bar_view_observer.h",
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "chrome/browser/ui/autofill/autofill_popup_controller.h" #include "chrome/browser/ui/autofill/autofill_popup_controller.h"
#include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h"
#include "chrome/browser/ui/autofill/popup_view_common.h" #include "chrome/browser/ui/autofill/popup_view_common.h"
#include "chrome/browser/ui/views/autofill/view_util.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h" #include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_typography.h" #include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/browser/ui/views/chrome_typography_provider.h" #include "chrome/browser/ui/views/chrome_typography_provider.h"
...@@ -138,6 +137,10 @@ class AutofillPopupItemView : public AutofillPopupRowView { ...@@ -138,6 +137,10 @@ class AutofillPopupItemView : public AutofillPopupRowView {
void OnGestureEvent(ui::GestureEvent* event) override; void OnGestureEvent(ui::GestureEvent* event) override;
protected: protected:
// Holds a view and a label that is stored inside the view. It can be the
// same object.
using ViewWithLabel = std::pair<std::unique_ptr<views::View>, views::Label*>;
AutofillPopupItemView(AutofillPopupViewNativeViews* popup_view, AutofillPopupItemView(AutofillPopupViewNativeViews* popup_view,
int line_number, int line_number,
int frontend_id) int frontend_id)
...@@ -146,16 +149,19 @@ class AutofillPopupItemView : public AutofillPopupRowView { ...@@ -146,16 +149,19 @@ class AutofillPopupItemView : public AutofillPopupRowView {
// AutofillPopupRowView: // AutofillPopupRowView:
void CreateContent() override; void CreateContent() override;
void RefreshStyle() override; void RefreshStyle() final;
std::unique_ptr<views::Background> CreateBackground() final;
int frontend_id() const { return frontend_id_; } int frontend_id() const { return frontend_id_; }
virtual int GetPrimaryTextStyle() = 0; virtual int GetPrimaryTextStyle() = 0;
virtual std::unique_ptr<views::View> CreateValueLabel(); // Returns a value view. The label part is optional but allow caller to keep
// track of all the labels for background color update.
virtual ViewWithLabel CreateValueLabel();
// Creates an optional label below the value. // Creates an optional label below the value.
virtual std::unique_ptr<views::View> CreateSubtextLabel(); virtual ViewWithLabel CreateSubtextLabel();
// The description view can be nullptr. // The description view can be nullptr.
virtual std::unique_ptr<views::View> CreateDescriptionLabel(); virtual ViewWithLabel CreateDescriptionLabel();
// Creates a label matching the style of the description label. // Creates a label matching the style of the description label.
std::unique_ptr<views::Label> CreateSecondaryLabel( std::unique_ptr<views::Label> CreateSecondaryLabel(
...@@ -174,10 +180,16 @@ class AutofillPopupItemView : public AutofillPopupRowView { ...@@ -174,10 +180,16 @@ class AutofillPopupItemView : public AutofillPopupRowView {
bool resize, bool resize,
views::BoxLayout* layout); views::BoxLayout* layout);
void KeepLabel(views::Label* label) {
if (label)
inner_labels_.push_back(label);
}
private: private:
const int frontend_id_; const int frontend_id_;
DISALLOW_COPY_AND_ASSIGN(AutofillPopupItemView); // All the labels inside this view.
std::vector<views::Label*> inner_labels_;
}; };
// This represents a suggestion, i.e., a row containing data that will be filled // This represents a suggestion, i.e., a row containing data that will be filled
...@@ -193,10 +205,9 @@ class AutofillPopupSuggestionView : public AutofillPopupItemView { ...@@ -193,10 +205,9 @@ class AutofillPopupSuggestionView : public AutofillPopupItemView {
protected: protected:
// AutofillPopupItemView: // AutofillPopupItemView:
std::unique_ptr<views::Background> CreateBackground() override;
int GetPrimaryTextStyle() override; int GetPrimaryTextStyle() override;
gfx::Font::Weight GetPrimaryTextWeight() const override; gfx::Font::Weight GetPrimaryTextWeight() const override;
std::unique_ptr<views::View> CreateSubtextLabel() override; ViewWithLabel CreateSubtextLabel() override;
AutofillPopupSuggestionView(AutofillPopupViewNativeViews* popup_view, AutofillPopupSuggestionView(AutofillPopupViewNativeViews* popup_view,
int line_number, int line_number,
int frontend_id); int frontend_id);
...@@ -216,9 +227,9 @@ class PasswordPopupSuggestionView : public AutofillPopupSuggestionView { ...@@ -216,9 +227,9 @@ class PasswordPopupSuggestionView : public AutofillPopupSuggestionView {
protected: protected:
// AutofillPopupItemView: // AutofillPopupItemView:
std::unique_ptr<views::View> CreateValueLabel() override; ViewWithLabel CreateValueLabel() override;
std::unique_ptr<views::View> CreateSubtextLabel() override; ViewWithLabel CreateSubtextLabel() override;
std::unique_ptr<views::View> CreateDescriptionLabel() override; ViewWithLabel CreateDescriptionLabel() override;
gfx::Font::Weight GetPrimaryTextWeight() const override; gfx::Font::Weight GetPrimaryTextWeight() const override;
private: private:
...@@ -245,7 +256,6 @@ class AutofillPopupFooterView : public AutofillPopupItemView { ...@@ -245,7 +256,6 @@ class AutofillPopupFooterView : public AutofillPopupItemView {
protected: protected:
// AutofillPopupItemView: // AutofillPopupItemView:
void CreateContent() override; void CreateContent() override;
std::unique_ptr<views::Background> CreateBackground() override;
int GetPrimaryTextStyle() override; int GetPrimaryTextStyle() override;
gfx::Font::Weight GetPrimaryTextWeight() const override; gfx::Font::Weight GetPrimaryTextWeight() const override;
...@@ -253,8 +263,6 @@ class AutofillPopupFooterView : public AutofillPopupItemView { ...@@ -253,8 +263,6 @@ class AutofillPopupFooterView : public AutofillPopupItemView {
AutofillPopupFooterView(AutofillPopupViewNativeViews* popup_view, AutofillPopupFooterView(AutofillPopupViewNativeViews* popup_view,
int line_number, int line_number,
int frontend_id); int frontend_id);
DISALLOW_COPY_AND_ASSIGN(AutofillPopupFooterView);
}; };
// Draws a separator between sections of the dropdown, namely between datalist // Draws a separator between sections of the dropdown, namely between datalist
...@@ -417,28 +425,32 @@ void AutofillPopupItemView::CreateContent() { ...@@ -417,28 +425,32 @@ void AutofillPopupItemView::CreateContent() {
/*resize=*/false, layout_manager); /*resize=*/false, layout_manager);
} }
auto lower_value_label = CreateSubtextLabel(); ViewWithLabel lower_value_label = CreateSubtextLabel();
auto value_label = CreateValueLabel(); ViewWithLabel value_label = CreateValueLabel();
auto description_label = CreateDescriptionLabel(); ViewWithLabel description_label = CreateDescriptionLabel();
std::unique_ptr<views::View> all_labels = std::make_unique<views::View>(); std::unique_ptr<views::View> all_labels = std::make_unique<views::View>();
views::GridLayout* grid_layout = views::GridLayout* grid_layout =
all_labels->SetLayoutManager(std::make_unique<views::GridLayout>()); all_labels->SetLayoutManager(std::make_unique<views::GridLayout>());
BuildColumnSet(grid_layout); BuildColumnSet(grid_layout);
grid_layout->StartRow(0, 0); grid_layout->StartRow(0, 0);
grid_layout->AddView(std::move(value_label)); grid_layout->AddView(std::move(value_label.first));
if (description_label) KeepLabel(value_label.second);
grid_layout->AddView(std::move(description_label)); if (description_label.first) {
else grid_layout->AddView(std::move(description_label.first));
KeepLabel(description_label.second);
} else {
grid_layout->SkipColumns(1); grid_layout->SkipColumns(1);
}
const int kStandardRowHeight = const int kStandardRowHeight =
views::MenuConfig::instance().touchable_menu_height; views::MenuConfig::instance().touchable_menu_height;
if (lower_value_label) { if (lower_value_label.first) {
layout_manager->set_minimum_cross_axis_size( layout_manager->set_minimum_cross_axis_size(
kStandardRowHeight + kAutofillPopupAdditionalDoubleRowHeight); kStandardRowHeight + kAutofillPopupAdditionalDoubleRowHeight);
grid_layout->StartRowWithPadding(0, 0, 0, kAdjacentLabelsVerticalSpacing); grid_layout->StartRowWithPadding(0, 0, 0, kAdjacentLabelsVerticalSpacing);
grid_layout->AddView(std::move(lower_value_label)); grid_layout->AddView(std::move(lower_value_label.first));
KeepLabel(lower_value_label.second);
grid_layout->SkipColumns(1); grid_layout->SkipColumns(1);
} else { } else {
layout_manager->set_minimum_cross_axis_size(kStandardRowHeight); layout_manager->set_minimum_cross_axis_size(kStandardRowHeight);
...@@ -456,18 +468,33 @@ void AutofillPopupItemView::CreateContent() { ...@@ -456,18 +468,33 @@ void AutofillPopupItemView::CreateContent() {
void AutofillPopupItemView::RefreshStyle() { void AutofillPopupItemView::RefreshStyle() {
SetBackground(CreateBackground()); SetBackground(CreateBackground());
SkColor bk_color = is_selected() ? popup_view()->GetSelectedBackgroundColor()
: popup_view()->GetBackgroundColor();
for (views::Label* label : inner_labels_) {
label->SetBackgroundColor(bk_color);
}
SchedulePaint(); SchedulePaint();
} }
std::unique_ptr<views::View> AutofillPopupItemView::CreateValueLabel() { std::unique_ptr<views::Background> AutofillPopupItemView::CreateBackground() {
return is_selected() ? views::CreateSolidBackground(
popup_view()->GetSelectedBackgroundColor())
: nullptr;
}
AutofillPopupItemView::ViewWithLabel AutofillPopupItemView::CreateValueLabel() {
// TODO(crbug.com/831603): Remove elision responsibilities from controller. // TODO(crbug.com/831603): Remove elision responsibilities from controller.
ViewWithLabel view_and_label;
base::string16 text = base::string16 text =
popup_view()->controller()->GetElidedValueAt(line_number()); popup_view()->controller()->GetElidedValueAt(line_number());
if (popup_view() if (popup_view()
->controller() ->controller()
->GetSuggestionAt(line_number()) ->GetSuggestionAt(line_number())
.is_value_secondary) { .is_value_secondary) {
return CreateSecondaryLabel(text); std::unique_ptr<views::Label> label = CreateSecondaryLabel(text);
view_and_label.second = label.get();
view_and_label.first = std::move(label);
return view_and_label;
} }
auto text_label = CreateLabelWithStyleAndContext( auto text_label = CreateLabelWithStyleAndContext(
...@@ -480,15 +507,19 @@ std::unique_ptr<views::View> AutofillPopupItemView::CreateValueLabel() { ...@@ -480,15 +507,19 @@ std::unique_ptr<views::View> AutofillPopupItemView::CreateValueLabel() {
text_label->font_list().DeriveWithWeight(font_weight)); text_label->font_list().DeriveWithWeight(font_weight));
} }
return text_label; view_and_label.second = text_label.get();
view_and_label.first = std::move(text_label);
return view_and_label;
} }
std::unique_ptr<views::View> AutofillPopupItemView::CreateSubtextLabel() { AutofillPopupItemView::ViewWithLabel
return nullptr; AutofillPopupItemView::CreateSubtextLabel() {
return ViewWithLabel();
} }
std::unique_ptr<views::View> AutofillPopupItemView::CreateDescriptionLabel() { AutofillPopupItemView::ViewWithLabel
return nullptr; AutofillPopupItemView::CreateDescriptionLabel() {
return ViewWithLabel();
} }
std::unique_ptr<views::Label> AutofillPopupItemView::CreateSecondaryLabel( std::unique_ptr<views::Label> AutofillPopupItemView::CreateSecondaryLabel(
...@@ -503,8 +534,7 @@ AutofillPopupItemView::CreateLabelWithStyleAndContext( ...@@ -503,8 +534,7 @@ AutofillPopupItemView::CreateLabelWithStyleAndContext(
const base::string16& text, const base::string16& text,
int text_context, int text_context,
int text_style) const { int text_style) const {
auto label = auto label = std::make_unique<views::Label>(text, text_context, text_style);
CreateLabelWithColorReadabilityDisabled(text, text_context, text_style);
label->SetHorizontalAlignment(gfx::ALIGN_LEFT); label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
return label; return label;
...@@ -539,13 +569,6 @@ AutofillPopupSuggestionView* AutofillPopupSuggestionView::Create( ...@@ -539,13 +569,6 @@ AutofillPopupSuggestionView* AutofillPopupSuggestionView::Create(
return result; return result;
} }
std::unique_ptr<views::Background>
AutofillPopupSuggestionView::CreateBackground() {
return is_selected() ? views::CreateSolidBackground(
popup_view()->GetSelectedBackgroundColor())
: nullptr;
}
int AutofillPopupSuggestionView::GetPrimaryTextStyle() { int AutofillPopupSuggestionView::GetPrimaryTextStyle() {
return views::style::TextStyle::STYLE_PRIMARY; return views::style::TextStyle::STYLE_PRIMARY;
} }
...@@ -562,16 +585,20 @@ AutofillPopupSuggestionView::AutofillPopupSuggestionView( ...@@ -562,16 +585,20 @@ AutofillPopupSuggestionView::AutofillPopupSuggestionView(
SetFocusBehavior(FocusBehavior::ALWAYS); SetFocusBehavior(FocusBehavior::ALWAYS);
} }
std::unique_ptr<views::View> AutofillPopupSuggestionView::CreateSubtextLabel() { AutofillPopupItemView::ViewWithLabel
AutofillPopupSuggestionView::CreateSubtextLabel() {
base::string16 label_text = base::string16 label_text =
popup_view()->controller()->GetSuggestionAt(line_number()).label; popup_view()->controller()->GetSuggestionAt(line_number()).label;
if (label_text.empty()) if (label_text.empty())
return nullptr; return ViewWithLabel();
auto label = CreateLabelWithStyleAndContext( auto label = CreateLabelWithStyleAndContext(
label_text, ChromeTextContext::CONTEXT_BODY_TEXT_SMALL, label_text, ChromeTextContext::CONTEXT_BODY_TEXT_SMALL,
views::style::STYLE_SECONDARY); views::style::STYLE_SECONDARY);
return label; ViewWithLabel result;
result.second = label.get();
result.first = std::move(label);
return result;
} }
/************** PasswordPopupSuggestionView **************/ /************** PasswordPopupSuggestionView **************/
...@@ -586,28 +613,37 @@ PasswordPopupSuggestionView* PasswordPopupSuggestionView::Create( ...@@ -586,28 +613,37 @@ PasswordPopupSuggestionView* PasswordPopupSuggestionView::Create(
return result; return result;
} }
std::unique_ptr<views::View> PasswordPopupSuggestionView::CreateValueLabel() { AutofillPopupItemView::ViewWithLabel
auto label = AutofillPopupSuggestionView::CreateValueLabel(); PasswordPopupSuggestionView::CreateValueLabel() {
return std::make_unique<ConstrainedWidthView>(std::move(label), ViewWithLabel label = AutofillPopupSuggestionView::CreateValueLabel();
kAutofillPopupUsernameMaxWidth); label.first = std::make_unique<ConstrainedWidthView>(
std::move(label.first), kAutofillPopupUsernameMaxWidth);
return label;
} }
std::unique_ptr<views::View> PasswordPopupSuggestionView::CreateSubtextLabel() { AutofillPopupItemView::ViewWithLabel
PasswordPopupSuggestionView::CreateSubtextLabel() {
auto label = CreateSecondaryLabel(masked_password_); auto label = CreateSecondaryLabel(masked_password_);
label->SetElideBehavior(gfx::TRUNCATE); label->SetElideBehavior(gfx::TRUNCATE);
return std::make_unique<ConstrainedWidthView>(std::move(label), ViewWithLabel result;
kAutofillPopupPasswordMaxWidth); result.second = label.get();
result.first = std::make_unique<ConstrainedWidthView>(
std::move(label), kAutofillPopupPasswordMaxWidth);
return result;
} }
std::unique_ptr<views::View> AutofillPopupItemView::ViewWithLabel
PasswordPopupSuggestionView::CreateDescriptionLabel() { PasswordPopupSuggestionView::CreateDescriptionLabel() {
if (origin_.empty()) if (origin_.empty())
return nullptr; return ViewWithLabel();
auto label = CreateSecondaryLabel(origin_); auto label = CreateSecondaryLabel(origin_);
label->SetElideBehavior(gfx::ELIDE_HEAD); label->SetElideBehavior(gfx::ELIDE_HEAD);
return std::make_unique<ConstrainedWidthView>(std::move(label), ViewWithLabel result;
kAutofillPopupUsernameMaxWidth); result.second = label.get();
result.first = std::make_unique<ConstrainedWidthView>(
std::move(label), kAutofillPopupUsernameMaxWidth);
return result;
} }
gfx::Font::Weight PasswordPopupSuggestionView::GetPrimaryTextWeight() const { gfx::Font::Weight PasswordPopupSuggestionView::GetPrimaryTextWeight() const {
...@@ -675,8 +711,9 @@ void AutofillPopupFooterView::CreateContent() { ...@@ -675,8 +711,9 @@ void AutofillPopupFooterView::CreateContent() {
views::MenuConfig::instance().touchable_menu_height + views::MenuConfig::instance().touchable_menu_height +
AutofillPopupBaseView::GetCornerRadius()); AutofillPopupBaseView::GetCornerRadius());
auto value_label = CreateValueLabel(); ViewWithLabel value_label = CreateValueLabel();
AddChildView(std::move(value_label)); AddChildView(std::move(value_label.first));
KeepLabel(value_label.second);
AddSpacerWithSize( AddSpacerWithSize(
ChromeLayoutProvider::Get()->GetDistanceMetric( ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_BETWEEN_PRIMARY_AND_SECONDARY_LABELS_HORIZONTAL), DISTANCE_BETWEEN_PRIMARY_AND_SECONDARY_LABELS_HORIZONTAL),
...@@ -688,12 +725,6 @@ void AutofillPopupFooterView::CreateContent() { ...@@ -688,12 +725,6 @@ void AutofillPopupFooterView::CreateContent() {
} }
} }
std::unique_ptr<views::Background> AutofillPopupFooterView::CreateBackground() {
return is_selected() ? views::CreateSolidBackground(
popup_view()->GetSelectedBackgroundColor())
: nullptr;
}
int AutofillPopupFooterView::GetPrimaryTextStyle() { int AutofillPopupFooterView::GetPrimaryTextStyle() {
return views::style::STYLE_SECONDARY; return views::style::STYLE_SECONDARY;
} }
...@@ -792,7 +823,7 @@ void AutofillPopupWarningView::CreateContent() { ...@@ -792,7 +823,7 @@ void AutofillPopupWarningView::CreateContent() {
SetBorder(views::CreateEmptyBorder( SetBorder(views::CreateEmptyBorder(
gfx::Insets(vertical_margin, horizontal_margin))); gfx::Insets(vertical_margin, horizontal_margin)));
auto text_label = CreateLabelWithColorReadabilityDisabled( auto text_label = std::make_unique<views::Label>(
controller->GetElidedValueAt(line_number()), controller->GetElidedValueAt(line_number()),
ChromeTextContext::CONTEXT_BODY_TEXT_LARGE, ChromeTextStyle::STYLE_RED); ChromeTextContext::CONTEXT_BODY_TEXT_LARGE, ChromeTextStyle::STYLE_RED);
text_label->SetEnabledColor(popup_view()->GetWarningColor()); text_label->SetEnabledColor(popup_view()->GetWarningColor());
...@@ -871,7 +902,6 @@ AutofillPopupViewNativeViews::AutofillPopupViewNativeViews( ...@@ -871,7 +902,6 @@ AutofillPopupViewNativeViews::AutofillPopupViewNativeViews(
layout_->set_main_axis_alignment(views::BoxLayout::MainAxisAlignment::kStart); layout_->set_main_axis_alignment(views::BoxLayout::MainAxisAlignment::kStart);
CreateChildViews(); CreateChildViews();
SetBackground(views::CreateSolidBackground(GetBackgroundColor()));
} }
AutofillPopupViewNativeViews::~AutofillPopupViewNativeViews() {} AutofillPopupViewNativeViews::~AutofillPopupViewNativeViews() {}
......
// 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.
#include "chrome/browser/ui/views/autofill/view_util.h"
#include <utility>
#include "ui/gfx/color_palette.h"
#include "ui/views/controls/label.h"
namespace autofill {
std::unique_ptr<views::Label> CreateLabelWithColorReadabilityDisabled(
const base::string16& text,
int text_context,
int text_style) {
auto label = std::make_unique<views::Label>(text, text_context, text_style);
label->SetAutoColorReadabilityEnabled(false);
// Forces the color for the required context and style to be applied. It may
// have been overridden by the default theme's color before auto-color
// readability was disabled.
label->SetEnabledColor(
views::style::GetColor(*label, text_context, text_style));
return label;
}
} // namespace autofill
// 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.
#ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_VIEW_UTIL_H_
#define CHROME_BROWSER_UI_VIEWS_AUTOFILL_VIEW_UTIL_H_
#include <memory>
#include "base/strings/string16.h"
#include "ui/views/view.h"
namespace views {
class Label;
} // namespace views
namespace autofill {
// Returns a new label with auto-color readability disabled to ensure consistent
// colors in the title when a dark native theme is applied
// (https://crbug.com/881514).
std::unique_ptr<views::Label> CreateLabelWithColorReadabilityDisabled(
const base::string16& text,
int text_context,
int text_style);
} // namespace autofill
#endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_VIEW_UTIL_H_
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/passwords/password_generation_popup_controller.h" #include "chrome/browser/ui/passwords/password_generation_popup_controller.h"
#include "chrome/browser/ui/views/autofill/view_util.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h" #include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_typography.h" #include "chrome/browser/ui/views/chrome_typography.h"
#include "ui/accessibility/ax_enums.mojom.h" #include "ui/accessibility/ax_enums.mojom.h"
...@@ -47,18 +46,27 @@ class PasswordGenerationPopupViewViews::GeneratedPasswordBox ...@@ -47,18 +46,27 @@ class PasswordGenerationPopupViewViews::GeneratedPasswordBox
password_label_->SetText(password); password_label_->SetText(password);
} }
void UpdateBackground(SkColor color) {
SetBackground(views::CreateSolidBackground(color));
// Setting a background color on the labels may change the text color to
// improve contrast.
password_label_->SetBackgroundColor(color);
suggestion_label_->SetBackgroundColor(color);
}
void reset_controller() { controller_ = nullptr; } void reset_controller() { controller_ = nullptr; }
private:
// View: // View:
void OnMouseEntered(const ui::MouseEvent& event) override; void OnMouseEntered(const ui::MouseEvent& event) override;
void OnMouseExited(const ui::MouseEvent& event) override; void OnMouseExited(const ui::MouseEvent& event) override;
void OnMouseReleased(const ui::MouseEvent& event) override; void OnMouseReleased(const ui::MouseEvent& event) override;
void OnGestureEvent(ui::GestureEvent* event) override; void OnGestureEvent(ui::GestureEvent* event) override;
private:
// Construct a ColumnSet with one view on the left and another on the right. // Construct a ColumnSet with one view on the left and another on the right.
static void BuildColumnSet(views::GridLayout* layout); static void BuildColumnSet(views::GridLayout* layout);
views::Label* suggestion_label_ = nullptr;
views::Label* password_label_ = nullptr; views::Label* password_label_ = nullptr;
PasswordGenerationPopupController* controller_ = nullptr; PasswordGenerationPopupController* controller_ = nullptr;
}; };
...@@ -71,7 +79,7 @@ void PasswordGenerationPopupViewViews::GeneratedPasswordBox::Init( ...@@ -71,7 +79,7 @@ void PasswordGenerationPopupViewViews::GeneratedPasswordBox::Init(
BuildColumnSet(layout); BuildColumnSet(layout);
layout->StartRow(views::GridLayout::kFixedSize, 0); layout->StartRow(views::GridLayout::kFixedSize, 0);
layout->AddView(autofill::CreateLabelWithColorReadabilityDisabled( suggestion_label_ = layout->AddView(std::make_unique<views::Label>(
controller_->SuggestedText(), ChromeTextContext::CONTEXT_BODY_TEXT_LARGE, controller_->SuggestedText(), ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
controller_->state() == controller_->state() ==
PasswordGenerationPopupController::kOfferGeneration PasswordGenerationPopupController::kOfferGeneration
...@@ -79,8 +87,7 @@ void PasswordGenerationPopupViewViews::GeneratedPasswordBox::Init( ...@@ -79,8 +87,7 @@ void PasswordGenerationPopupViewViews::GeneratedPasswordBox::Init(
: views::style::STYLE_SECONDARY)); : views::style::STYLE_SECONDARY));
DCHECK(!password_label_); DCHECK(!password_label_);
password_label_ = password_label_ = layout->AddView(std::make_unique<views::Label>(
layout->AddView(autofill::CreateLabelWithColorReadabilityDisabled(
controller_->password(), ChromeTextContext::CONTEXT_BODY_TEXT_LARGE, controller_->password(), ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
STYLE_SECONDARY_MONOSPACED)); STYLE_SECONDARY_MONOSPACED));
} }
...@@ -145,7 +152,6 @@ PasswordGenerationPopupViewViews::PasswordGenerationPopupViewViews( ...@@ -145,7 +152,6 @@ PasswordGenerationPopupViewViews::PasswordGenerationPopupViewViews(
: AutofillPopupBaseView(controller, parent_widget), : AutofillPopupBaseView(controller, parent_widget),
controller_(controller) { controller_(controller) {
CreateLayoutAndChildren(); CreateLayoutAndChildren();
SetBackground(views::CreateSolidBackground(GetBackgroundColor()));
} }
PasswordGenerationPopupViewViews::~PasswordGenerationPopupViewViews() = default; PasswordGenerationPopupViewViews::~PasswordGenerationPopupViewViews() = default;
...@@ -165,6 +171,7 @@ void PasswordGenerationPopupViewViews::Hide() { ...@@ -165,6 +171,7 @@ void PasswordGenerationPopupViewViews::Hide() {
void PasswordGenerationPopupViewViews::UpdateState() { void PasswordGenerationPopupViewViews::UpdateState() {
RemoveAllChildViews(true); RemoveAllChildViews(true);
password_view_ = nullptr; password_view_ = nullptr;
help_label_ = nullptr;
CreateLayoutAndChildren(); CreateLayoutAndChildren();
} }
...@@ -181,9 +188,9 @@ void PasswordGenerationPopupViewViews::PasswordSelectionUpdated() { ...@@ -181,9 +188,9 @@ void PasswordGenerationPopupViewViews::PasswordSelectionUpdated() {
if (controller_->password_selected()) if (controller_->password_selected())
NotifyAccessibilityEvent(ax::mojom::Event::kSelection, true); NotifyAccessibilityEvent(ax::mojom::Event::kSelection, true);
password_view_->SetBackground(views::CreateSolidBackground( password_view_->UpdateBackground(controller_->password_selected()
controller_->password_selected() ? GetSelectedBackgroundColor() ? GetSelectedBackgroundColor()
: GetBackgroundColor())); : GetBackgroundColor());
SchedulePaint(); SchedulePaint();
} }
...@@ -209,17 +216,23 @@ void PasswordGenerationPopupViewViews::CreateLayoutAndChildren() { ...@@ -209,17 +216,23 @@ void PasswordGenerationPopupViewViews::CreateLayoutAndChildren() {
AddChildView(password_view_); AddChildView(password_view_);
PasswordSelectionUpdated(); PasswordSelectionUpdated();
views::Label* help_label = new views::Label( help_label_ = new views::Label(controller_->HelpText(),
controller_->HelpText(), ChromeTextContext::CONTEXT_BODY_TEXT_LARGE, ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
views::style::STYLE_SECONDARY); views::style::STYLE_SECONDARY);
help_label->SetMultiLine(true); help_label_->SetMultiLine(true);
help_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); help_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
help_label->SetBackground( help_label_->SetBorder(
views::CreateSolidBackground(GetFooterBackgroundColor()));
help_label->SetBorder(
views::CreateEmptyBorder(kVerticalPadding, kHorizontalMargin, views::CreateEmptyBorder(kVerticalPadding, kHorizontalMargin,
kVerticalPadding, kHorizontalMargin)); kVerticalPadding, kHorizontalMargin));
AddChildView(help_label); AddChildView(help_label_);
}
void PasswordGenerationPopupViewViews::OnThemeChanged() {
SetBackground(views::CreateSolidBackground(GetBackgroundColor()));
password_view_->UpdateBackground(controller_->password_selected()
? GetSelectedBackgroundColor()
: GetBackgroundColor());
help_label_->SetBackgroundColor(GetFooterBackgroundColor());
} }
void PasswordGenerationPopupViewViews::OnPaint(gfx::Canvas* canvas) { void PasswordGenerationPopupViewViews::OnPaint(gfx::Canvas* canvas) {
...@@ -234,7 +247,7 @@ void PasswordGenerationPopupViewViews::OnPaint(gfx::Canvas* canvas) { ...@@ -234,7 +247,7 @@ void PasswordGenerationPopupViewViews::OnPaint(gfx::Canvas* canvas) {
gfx::Rect divider_bounds(0, password_view_->bounds().bottom(), gfx::Rect divider_bounds(0, password_view_->bounds().bottom(),
password_view_->width(), 1); password_view_->width(), 1);
canvas->FillRect(divider_bounds, GetSeparatorColor()); canvas->FillRect(divider_bounds, GetSeparatorColor());
} }
void PasswordGenerationPopupViewViews::GetAccessibleNodeData( void PasswordGenerationPopupViewViews::GetAccessibleNodeData(
ui::AXNodeData* node_data) { ui::AXNodeData* node_data) {
......
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
class PasswordGenerationPopupController; class PasswordGenerationPopupController;
namespace views {
class Label;
}
class PasswordGenerationPopupViewViews : public autofill::AutofillPopupBaseView, class PasswordGenerationPopupViewViews : public autofill::AutofillPopupBaseView,
public PasswordGenerationPopupView { public PasswordGenerationPopupView {
public: public:
...@@ -34,6 +38,7 @@ class PasswordGenerationPopupViewViews : public autofill::AutofillPopupBaseView, ...@@ -34,6 +38,7 @@ class PasswordGenerationPopupViewViews : public autofill::AutofillPopupBaseView,
void CreateLayoutAndChildren(); void CreateLayoutAndChildren();
// views:Views implementation. // views:Views implementation.
void OnThemeChanged() override;
void OnPaint(gfx::Canvas* canvas) override; void OnPaint(gfx::Canvas* canvas) override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
...@@ -41,6 +46,9 @@ class PasswordGenerationPopupViewViews : public autofill::AutofillPopupBaseView, ...@@ -41,6 +46,9 @@ class PasswordGenerationPopupViewViews : public autofill::AutofillPopupBaseView,
// Sub view that displays the actual generated password. // Sub view that displays the actual generated password.
GeneratedPasswordBox* password_view_ = nullptr; GeneratedPasswordBox* password_view_ = nullptr;
// The footer label.
views::Label* help_label_ = nullptr;
// Controller for this view. Weak reference. // Controller for this view. Weak reference.
PasswordGenerationPopupController* controller_; PasswordGenerationPopupController* controller_;
......
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