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",
......
// 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,10 +87,9 @@ void PasswordGenerationPopupViewViews::GeneratedPasswordBox::Init( ...@@ -79,10 +87,9 @@ 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));
} }
void PasswordGenerationPopupViewViews::GeneratedPasswordBox::OnMouseEntered( void PasswordGenerationPopupViewViews::GeneratedPasswordBox::OnMouseEntered(
...@@ -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