0

Migrate BubbleBorder to use ui::ColorVariant

This is required to support ColorId for `BubbleDialogDelegate` and its
related classes.

Bug: b:261653838
Change-Id: I329ad051444d292c4dc082565bbe5bdb7db3a244
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6222179
Reviewed-by: Elly FJ <ellyjones@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Zoraiz Naeem <zoraiznaeem@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1417060}
This commit is contained in:
Zoraiz Naeem
2025-02-06 15:30:33 -08:00
committed by Chromium LUCI CQ
parent 67295932ed
commit 0d20027475
11 changed files with 40 additions and 43 deletions

@ -392,8 +392,8 @@ AuthDialogContentsView::AuthDialogContentsView(
auth_metadata_(auth_metadata) {
SetLayoutManager(std::make_unique<views::FillLayout>());
auto border = std::make_unique<views::BubbleBorder>(
views::BubbleBorder::FLOAT, views::BubbleBorder::STANDARD_SHADOW,
ui::kColorPrimaryBackground);
views::BubbleBorder::FLOAT, views::BubbleBorder::STANDARD_SHADOW);
border->SetColor(ui::kColorPrimaryBackground);
border->SetCornerRadius(kCornerRadius);
SetBackground(std::make_unique<views::BubbleBackground>(border.get()));
SetBorder(std::move(border));

@ -98,8 +98,8 @@ InSessionAuthDialogContentsView::InSessionAuthDialogContentsView(
.SetCollapseMargins(true);
auto border = std::make_unique<views::BubbleBorder>(
views::BubbleBorder::FLOAT, views::BubbleBorder::STANDARD_SHADOW,
ui::kColorPrimaryBackground);
views::BubbleBorder::FLOAT, views::BubbleBorder::STANDARD_SHADOW);
border->SetColor(ui::kColorPrimaryBackground);
border->SetCornerRadius(kCornerRadius);
SetBackground(std::make_unique<views::BubbleBackground>(border.get()));
SetBorder(std::move(border));

@ -42,8 +42,8 @@ ProgressBarDialogView::ProgressBarDialogView(bool is_multiple_files)
constexpr int kCornerRadius = 12;
auto border = std::make_unique<views::BubbleBorder>(
views::BubbleBorder::NONE, views::BubbleBorder::STANDARD_SHADOW,
ash::kColorAshDialogBackgroundColor);
views::BubbleBorder::NONE, views::BubbleBorder::STANDARD_SHADOW);
border->SetColor(ash::kColorAshDialogBackgroundColor);
border->SetCornerRadius(kCornerRadius);
SetBackground(std::make_unique<views::BubbleBackground>(border.get()));
SetBorder(std::move(border));

@ -75,8 +75,8 @@ constexpr int kMaxPopupWebContentsTopYOverflow = 8;
// Creates a border for a popup.
std::unique_ptr<views::Border> CreateBorder() {
auto border = std::make_unique<views::BubbleBorder>(
views::BubbleBorder::NONE, views::BubbleBorder::STANDARD_SHADOW,
ui::kColorDropdownBackground);
views::BubbleBorder::NONE, views::BubbleBorder::STANDARD_SHADOW);
border->SetColor(ui::kColorDropdownBackground);
border->SetCornerRadius(PopupBaseView::GetCornerRadius());
border->set_md_shadow_elevation(
ChromeLayoutProvider::Get()->GetShadowElevationMetric(

@ -289,8 +289,8 @@ FindBarView::FindBarView(FindBarHost* host) {
views::ShapeContextTokens::kFindBarViewRadius);
{
auto border = std::make_unique<views::BubbleBorder>(
views::BubbleBorder::NONE, views::BubbleBorder::STANDARD_SHADOW,
kColorFindBarBackground);
views::BubbleBorder::NONE, views::BubbleBorder::STANDARD_SHADOW);
border->SetColor(kColorFindBarBackground);
border->set_md_shadow_elevation(
layout_provider->GetCornerRadiusMetric(views::Emphasis::kHigh));
border->SetCornerRadius(corner_radius);

@ -447,8 +447,8 @@ void SigninViewControllerDelegateViews::DisplayModal() {
this, host_web_contents);
if (should_show_close_button_) {
auto border = std::make_unique<views::BubbleBorder>(
views::BubbleBorder::NONE, views::BubbleBorder::STANDARD_SHADOW,
kColorProfilesReauthDialogBorder);
views::BubbleBorder::NONE, views::BubbleBorder::STANDARD_SHADOW);
border->SetColor(kColorProfilesReauthDialogBorder);
GetBubbleFrameView()->SetBubbleBorder(std::move(border));
}
constrained_window::ShowModalDialog(

@ -93,8 +93,8 @@ PasspointDialogView::PasspointDialogView(
provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL));
auto border = std::make_unique<views::BubbleBorder>(
views::BubbleBorder::NONE, views::BubbleBorder::STANDARD_SHADOW,
ash::kColorAshDialogBackgroundColor);
views::BubbleBorder::NONE, views::BubbleBorder::STANDARD_SHADOW);
border->SetColor(ash::kColorAshDialogBackgroundColor);
border->SetCornerRadius(kCornerRadius);
SetBackground(std::make_unique<views::BubbleBackground>(border.get()));
SetBorder(std::move(border));

@ -15,6 +15,7 @@
#include "cc/paint/paint_flags.h"
#include "third_party/skia/include/core/SkBlendMode.h"
#include "third_party/skia/include/core/SkClipOp.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkPoint.h"
#include "third_party/skia/include/core/SkRRect.h"
@ -22,6 +23,7 @@
#include "third_party/skia/include/core/SkScalar.h"
#include "ui/color/color_id.h"
#include "ui/color/color_provider.h"
#include "ui/color/color_variant.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/geometry/rect.h"
@ -260,8 +262,8 @@ void DrawBorderAndShadowImpl(
} // namespace
BubbleBorder::BubbleBorder(Arrow arrow, Shadow shadow, ui::ColorId color_id)
: arrow_(arrow), shadow_(shadow), color_id_(color_id) {
BubbleBorder::BubbleBorder(Arrow arrow, Shadow shadow)
: arrow_(arrow), shadow_(shadow) {
DCHECK_LT(shadow_, SHADOW_COUNT);
}
@ -284,9 +286,8 @@ void BubbleBorder::SetCornerRadius(int corner_radius) {
corner_radius_ = corner_radius;
}
void BubbleBorder::SetColor(SkColor color) {
requested_color_ = color;
UpdateColor(nullptr);
void BubbleBorder::SetColor(ui::ColorVariant color) {
color_ = color;
}
gfx::Rect BubbleBorder::GetBounds(const gfx::Rect& anchor_rect,
@ -502,7 +503,8 @@ gfx::Size BubbleBorder::GetMinimumSize() const {
}
void BubbleBorder::OnViewThemeChanged(View* view) {
UpdateColor(view);
resolved_color_ = color_.ConvertToSkColor(view->GetColorProvider());
view->SchedulePaint();
}
gfx::Size BubbleBorder::GetSizeForContentsSize(
@ -689,16 +691,6 @@ bool BubbleBorder::ShouldDrawStroke() const {
shadow_);
}
void BubbleBorder::UpdateColor(View* view) {
const SkColor computed_color =
view ? view->GetColorProvider()->GetColor(color_id_)
: gfx::kPlaceholderColor;
color_ = requested_color_.value_or(computed_color);
if (view) {
view->SchedulePaint();
}
}
void BubbleBorder::PaintNoShadow(const View& view, gfx::Canvas* canvas) {
gfx::ScopedCanvas scoped(canvas);
canvas->sk_canvas()->clipRRect(GetClientRect(view), SkClipOp::kDifference,

@ -15,6 +15,8 @@
#include "third_party/skia/include/core/SkRRect.h"
#include "ui/base/metadata/base_type_conversion.h"
#include "ui/color/color_id.h"
#include "ui/color/color_variant.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
@ -111,9 +113,7 @@ class VIEWS_EXPORT BubbleBorder : public Border {
// arrow if one is present.
static constexpr int kVisibleArrowBuffer = 12;
BubbleBorder(Arrow arrow,
Shadow shadow,
ui::ColorId color_id = ui::kColorDialogBackground);
BubbleBorder(Arrow arrow, Shadow shadow);
BubbleBorder(const BubbleBorder&) = delete;
BubbleBorder& operator=(const BubbleBorder&) = delete;
@ -192,8 +192,10 @@ class VIEWS_EXPORT BubbleBorder : public Border {
Shadow shadow() const { return shadow_; }
// Get or set the color for the bubble and arrow body.
void SetColor(SkColor color);
SkColor color() const { return color_; }
// Note: `color()` will not return updated color, until `OnViewThemeChanged()`
// is called.
SkColor color() const { return resolved_color_; }
void SetColor(ui::ColorVariant color);
// Sets a desired pixel distance between the arrow tip and the outside edge of
// the neighboring border image. For example: |----offset----|
@ -299,10 +301,6 @@ class VIEWS_EXPORT BubbleBorder : public Border {
// iff there is a visible shadow and it does not have a custom elevation.
bool ShouldDrawStroke() const;
// Sets `color_` appropriately, using `view` to obtain a ColorProvider.
// `view` may be null if `requested_color_` is set.
void UpdateColor(View* view);
// Paint for the NO_SHADOW shadow type. This just paints transparent pixels
// to make the window shape based on insets and GetBorderCornerRadius().
void PaintNoShadow(const View& view, gfx::Canvas* canvas);
@ -329,9 +327,8 @@ class VIEWS_EXPORT BubbleBorder : public Border {
std::optional<bool> draw_border_stroke_;
Shadow shadow_;
std::optional<int> md_shadow_elevation_;
ui::ColorId color_id_;
std::optional<SkColor> requested_color_;
SkColor color_ = gfx::kPlaceholderColor;
SkColor resolved_color_ = gfx::kPlaceholderColor;
ui::ColorVariant color_{ui::kColorDialogBackground};
bool avoid_shadow_overlap_ = false;
std::optional<gfx::Insets> insets_;
};

@ -824,6 +824,10 @@ bool BubbleFrameView::GetDisplayVisibleArrow() const {
void BubbleFrameView::SetBackgroundColor(SkColor color) {
bubble_border_->SetColor(color);
// Ensures that border updates the its color. See `BubbleBorder::color()` for
// more details.
bubble_border_->OnViewThemeChanged(this);
UpdateClientViewBackground();
SchedulePaint();
}

@ -23,6 +23,7 @@
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/color/color_id.h"
#include "ui/color/color_provider.h"
#include "ui/color/color_variant.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_tree_owner.h"
#include "ui/gfx/canvas.h"
@ -472,7 +473,10 @@ void MenuScrollViewContainer::CreateBubbleBorder() {
}
#endif
id = border_color_id_.value_or(id);
auto bubble_border = std::make_unique<BubbleBorder>(arrow_, shadow_type, id);
auto bubble_border = std::make_unique<BubbleBorder>(arrow_, shadow_type);
bubble_border->SetColor(id);
const MenuConfig& menu_config = MenuConfig::instance();
bubble_border->set_md_shadow_elevation(
content_view_->GetMenuItem()->GetParentMenuItem()