Commit 1c9d329c authored by Vasilii Sukhanov's avatar Vasilii Sukhanov Committed by Commit Bot

Share the autofill constants between the password generation and autofill views.

As a nice side effect, the issue with transparency in the generation prompt is
fixed.

Bug: 864978
Change-Id: I58d4d04053297dda1b2a4aa5cfce381b0062eadd
Reviewed-on: https://chromium-review.googlesource.com/1141962
Commit-Queue: Vasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarTommy Martino <tmartino@chromium.org>
Reviewed-by: default avatarFabio Tirelo <ftirelo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576503}
parent 72b1dbe9
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_features.h" #include "ui/base/ui_features.h"
#include "ui/gfx/color_palette.h"
#include "ui/native_theme/native_theme.h" #include "ui/native_theme/native_theme.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/bubble/bubble_border.h" #include "ui/views/bubble/bubble_border.h"
...@@ -24,6 +25,17 @@ ...@@ -24,6 +25,17 @@
namespace autofill { namespace autofill {
// TODO(crbug.com/831603): Determine how colors should be shared with menus
// and/or omnibox, and how these should interact (if at all) with native
// theme colors.
const SkColor AutofillPopupBaseView::kBackgroundColor = SK_ColorWHITE;
const SkColor AutofillPopupBaseView::kSelectedBackgroundColor =
gfx::kGoogleGrey200;
const SkColor AutofillPopupBaseView::kFooterBackgroundColor =
gfx::kGoogleGrey050;
const SkColor AutofillPopupBaseView::kSeparatorColor = gfx::kGoogleGrey200;
const SkColor AutofillPopupBaseView::kWarningColor = gfx::kGoogleRed600;
int AutofillPopupBaseView::GetCornerRadius() { int AutofillPopupBaseView::GetCornerRadius() {
return ChromeLayoutProvider::Get()->GetCornerRadiusMetric( return ChromeLayoutProvider::Get()->GetCornerRadiusMetric(
views::EMPHASIS_MEDIUM); views::EMPHASIS_MEDIUM);
......
...@@ -31,6 +31,12 @@ class AutofillPopupBaseView : public views::WidgetDelegateView, ...@@ -31,6 +31,12 @@ class AutofillPopupBaseView : public views::WidgetDelegateView,
public views::WidgetFocusChangeListener, public views::WidgetFocusChangeListener,
public views::WidgetObserver { public views::WidgetObserver {
public: public:
static const SkColor kBackgroundColor;
static const SkColor kSelectedBackgroundColor;
static const SkColor kFooterBackgroundColor;
static const SkColor kSeparatorColor;
static const SkColor kWarningColor;
static int GetCornerRadius(); static int GetCornerRadius();
protected: protected:
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "ui/accessibility/ax_node_data.h" #include "ui/accessibility/ax_node_data.h"
#include "ui/accessibility/platform/ax_platform_node.h" #include "ui/accessibility/platform/ax_platform_node.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/font.h" #include "ui/gfx/font.h"
#include "ui/gfx/geometry/rect_conversions.h" #include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/shadow_value.h" #include "ui/gfx/shadow_value.h"
...@@ -46,15 +45,6 @@ const int kAutofillPopupWidthMultiple = 12; ...@@ -46,15 +45,6 @@ const int kAutofillPopupWidthMultiple = 12;
const int kAutofillPopupMinWidth = 64; const int kAutofillPopupMinWidth = 64;
const int kAutofillPopupMaxWidth = 456; const int kAutofillPopupMaxWidth = 456;
// TODO(crbug.com/831603): Determine how colors should be shared with menus
// and/or omnibox, and how these should interact (if at all) with native
// theme colors.
const SkColor kAutofillPopupBackgroundColor = SK_ColorWHITE;
const SkColor kAutofillPopupSelectedBackgroundColor = gfx::kGoogleGrey200;
const SkColor kAutofillPopupFooterBackgroundColor = gfx::kGoogleGrey050;
const SkColor kAutofillPopupSeparatorColor = gfx::kGoogleGrey200;
const SkColor kAutofillPopupWarningColor = gfx::kGoogleRed600;
// A space between the input element and the dropdown, so that the dropdown's // A space between the input element and the dropdown, so that the dropdown's
// border doesn't look too close to the element. // border doesn't look too close to the element.
constexpr int kElementBorderPadding = 1; constexpr int kElementBorderPadding = 1;
...@@ -350,8 +340,8 @@ AutofillPopupSuggestionView* AutofillPopupSuggestionView::Create( ...@@ -350,8 +340,8 @@ AutofillPopupSuggestionView* AutofillPopupSuggestionView::Create(
std::unique_ptr<views::Background> std::unique_ptr<views::Background>
AutofillPopupSuggestionView::CreateBackground() { AutofillPopupSuggestionView::CreateBackground() {
return views::CreateSolidBackground( return views::CreateSolidBackground(
is_selected_ ? kAutofillPopupSelectedBackgroundColor is_selected_ ? AutofillPopupBaseView::kSelectedBackgroundColor
: kAutofillPopupBackgroundColor); : AutofillPopupBaseView::kBackgroundColor);
} }
int AutofillPopupSuggestionView::GetPrimaryTextStyle() { int AutofillPopupSuggestionView::GetPrimaryTextStyle() {
...@@ -381,14 +371,14 @@ void AutofillPopupFooterView::CreateContent() { ...@@ -381,14 +371,14 @@ void AutofillPopupFooterView::CreateContent() {
/*left=*/0, /*left=*/0,
/*bottom=*/0, /*bottom=*/0,
/*right=*/0, /*right=*/0,
/*color=*/kAutofillPopupSeparatorColor)); /*color=*/AutofillPopupBaseView::kSeparatorColor));
AutofillPopupItemView::CreateContent(); AutofillPopupItemView::CreateContent();
} }
std::unique_ptr<views::Background> AutofillPopupFooterView::CreateBackground() { std::unique_ptr<views::Background> AutofillPopupFooterView::CreateBackground() {
return views::CreateSolidBackground( return views::CreateSolidBackground(
is_selected_ ? kAutofillPopupSelectedBackgroundColor is_selected_ ? AutofillPopupBaseView::kSelectedBackgroundColor
: kAutofillPopupFooterBackgroundColor); : AutofillPopupBaseView::kFooterBackgroundColor);
} }
int AutofillPopupFooterView::GetPrimaryTextStyle() { int AutofillPopupFooterView::GetPrimaryTextStyle() {
...@@ -422,7 +412,7 @@ void AutofillPopupSeparatorView::CreateContent() { ...@@ -422,7 +412,7 @@ void AutofillPopupSeparatorView::CreateContent() {
SetLayoutManager(std::make_unique<views::FillLayout>()); SetLayoutManager(std::make_unique<views::FillLayout>());
views::Separator* separator = new views::Separator(); views::Separator* separator = new views::Separator();
separator->SetColor(kAutofillPopupSeparatorColor); separator->SetColor(AutofillPopupBaseView::kSeparatorColor);
// Add some spacing between the the previous item and the separator. // Add some spacing between the the previous item and the separator.
separator->SetPreferredHeight( separator->SetPreferredHeight(
views::MenuConfig::instance().separator_thickness); views::MenuConfig::instance().separator_thickness);
...@@ -484,7 +474,7 @@ void AutofillPopupWarningView::CreateContent() { ...@@ -484,7 +474,7 @@ void AutofillPopupWarningView::CreateContent() {
controller->GetElidedValueAt(line_number_), controller->GetElidedValueAt(line_number_),
{views::style::GetFont(ChromeTextContext::CONTEXT_BODY_TEXT_LARGE, {views::style::GetFont(ChromeTextContext::CONTEXT_BODY_TEXT_LARGE,
ChromeTextStyle::STYLE_RED)}); ChromeTextStyle::STYLE_RED)});
text_label->SetEnabledColor(kAutofillPopupWarningColor); text_label->SetEnabledColor(AutofillPopupBaseView::kWarningColor);
text_label->SetMultiLine(true); text_label->SetMultiLine(true);
int max_width = int max_width =
std::min(kAutofillPopupMaxWidth, std::min(kAutofillPopupMaxWidth,
...@@ -544,7 +534,7 @@ AutofillPopupViewNativeViews::AutofillPopupViewNativeViews( ...@@ -544,7 +534,7 @@ AutofillPopupViewNativeViews::AutofillPopupViewNativeViews(
layout_->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); layout_->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
CreateChildViews(); CreateChildViews();
SetBackground(views::CreateSolidBackground(kAutofillPopupBackgroundColor)); SetBackground(views::CreateSolidBackground(kBackgroundColor));
} }
AutofillPopupViewNativeViews::~AutofillPopupViewNativeViews() {} AutofillPopupViewNativeViews::~AutofillPopupViewNativeViews() {}
...@@ -668,7 +658,7 @@ void AutofillPopupViewNativeViews::CreateChildViews() { ...@@ -668,7 +658,7 @@ void AutofillPopupViewNativeViews::CreateChildViews() {
if (has_footer) { if (has_footer) {
views::View* footer_container = new views::View(); views::View* footer_container = new views::View();
footer_container->SetBackground( footer_container->SetBackground(
views::CreateSolidBackground(kAutofillPopupFooterBackgroundColor)); views::CreateSolidBackground(kFooterBackgroundColor));
views::BoxLayout* footer_layout = footer_container->SetLayoutManager( views::BoxLayout* footer_layout = footer_container->SetLayoutManager(
std::make_unique<views::BoxLayout>(views::BoxLayout::kVertical)); std::make_unique<views::BoxLayout>(views::BoxLayout::kVertical));
......
...@@ -24,17 +24,6 @@ ...@@ -24,17 +24,6 @@
#include "ui/views/layout/grid_layout.h" #include "ui/views/layout/grid_layout.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
namespace {
// Background color of the bottom part of the prompt.
constexpr SkColor kPasswordGenerationPopupFooterBackgroundColor =
gfx::kGoogleGrey050;
// Color of the separator between the password and help sections.
constexpr SkColor kPasswordGenerationPopupSeparatorColor = gfx::kGoogleGrey200;
} // namespace
// Class that shows the generated password and associated UI (currently an // Class that shows the generated password and associated UI (currently an
// explanatory text). // explanatory text).
class PasswordGenerationPopupViewViews::GeneratedPasswordBox class PasswordGenerationPopupViewViews::GeneratedPasswordBox
...@@ -141,11 +130,10 @@ void PasswordGenerationPopupViewViews::PasswordSelectionUpdated() { ...@@ -141,11 +130,10 @@ 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::CreateThemedSolidBackground( password_view_->SetBackground(views::CreateSolidBackground(
password_view_, controller_->password_selected() ? kSelectedBackgroundColor
controller_->password_selected() : kBackgroundColor));
? ui::NativeTheme::kColorId_ResultsTableHoveredBackground SchedulePaint();
: ui::NativeTheme::kColorId_ResultsTableNormalBackground));
} }
bool PasswordGenerationPopupViewViews::IsPointInPasswordBounds( bool PasswordGenerationPopupViewViews::IsPointInPasswordBounds(
...@@ -191,8 +179,8 @@ void PasswordGenerationPopupViewViews::CreateLayoutAndChildren() { ...@@ -191,8 +179,8 @@ void PasswordGenerationPopupViewViews::CreateLayoutAndChildren() {
link_style.disable_line_wrapping = false; link_style.disable_line_wrapping = false;
help_label->AddStyleRange(controller_->HelpTextLinkRange(), link_style); help_label->AddStyleRange(controller_->HelpTextLinkRange(), link_style);
help_label->SetBackground(views::CreateSolidBackground( help_label->SetBackground(
kPasswordGenerationPopupFooterBackgroundColor)); views::CreateSolidBackground(kFooterBackgroundColor));
help_label->SetBorder( help_label->SetBorder(
views::CreateEmptyBorder(kVerticalPadding, kHorizontalMargin, views::CreateEmptyBorder(kVerticalPadding, kHorizontalMargin,
kVerticalPadding, kHorizontalMargin)); kVerticalPadding, kHorizontalMargin));
...@@ -211,7 +199,7 @@ void PasswordGenerationPopupViewViews::OnPaint(gfx::Canvas* canvas) { ...@@ -211,7 +199,7 @@ void PasswordGenerationPopupViewViews::OnPaint(gfx::Canvas* canvas) {
if (password_view_) { if (password_view_) {
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, kPasswordGenerationPopupSeparatorColor); canvas->FillRect(divider_bounds, kSeparatorColor);
} }
} }
......
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