0

Migrate ash/wm/resize_shadow to use ui::ColorVariant

Bug: b:394420459
Change-Id: Id13393d5daa70a81a29791b9e92b8973ebc9c8c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6231216
Reviewed-by: Sammie Quon <sammiequon@chromium.org>
Commit-Queue: Zoraiz Naeem <zoraiznaeem@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1417077}
This commit is contained in:
Zoraiz Naeem
2025-02-06 16:15:21 -08:00
committed by Chromium LUCI CQ
parent 2aed2baf14
commit 21901ec184
3 changed files with 34 additions and 33 deletions

@ -90,15 +90,10 @@ const gfx::Insets CalculateOutsets(int hit, int thickness) {
const gfx::ImageSkia& MakeShadowImageOnce(
const ash::ResizeShadow::InitParams& params,
const ui::ColorProvider* color_provider) {
// Resolve the color with color type. If given a color ID, use color provider
// to get the color value.
SkColor color;
if (absl::holds_alternative<SkColor>(params.color)) {
color = absl::get<SkColor>(params.color);
} else {
CHECK(!!color_provider);
color = color_provider->GetColor(absl::get<ui::ColorId>(params.color));
}
// Resolve the color with color type.
const SkColor color = params.color.GetSkColor()
? *params.color.GetSkColor()
: params.color.ConvertToSkColor(color_provider);
// Generate the shadow features key.
const ShadowFeaturesKey features_key{ShadowImageSize(params),
@ -132,6 +127,14 @@ const gfx::ImageSkia& MakeShadowImageOnce(
namespace ash {
ResizeShadow::InitParams::InitParams() = default;
ResizeShadow::InitParams::InitParams(const InitParams& other) = default;
ResizeShadow::InitParams& ResizeShadow::InitParams::operator=(
const InitParams& other) = default;
ResizeShadow::InitParams::~InitParams() = default;
ResizeShadow::ResizeShadow(aura::Window* window,
const InitParams& params,
ResizeShadowType type)
@ -143,9 +146,10 @@ ResizeShadow::ResizeShadow(aura::Window* window,
layer_->SetFillsBoundsOpaquely(false);
layer_->SetOpacity(0.f);
layer_->SetVisible(false);
// If use static color, create the shadow image. Otherwise, observe the color
// provider source to update the shadow color.
if (absl::holds_alternative<SkColor>(params.color)) {
if (params_.color.GetSkColor()) {
UpdateShadowLayer();
} else {
Observe(RootWindowController::ForWindow(window)->color_provider_source());
@ -169,14 +173,13 @@ ResizeShadow::~ResizeShadow() = default;
void ResizeShadow::OnColorProviderChanged() {
// This function will also be called when the color provider source is
// destroyed. We should guarantee the color provider exists.
if (absl::holds_alternative<ui::ColorId>(params_.color) &&
GetColorProviderSource()) {
if (params_.color.GetColorId() && GetColorProviderSource()) {
UpdateShadowLayer();
}
}
void ResizeShadow::OnWindowParentToRootWindow() {
if (absl::holds_alternative<ui::ColorId>(params_.color)) {
if (params_.color.GetColorId()) {
Observe(RootWindowController::ForWindow(window_)->color_provider_source());
}
}

@ -10,10 +10,9 @@
#include "ash/public/cpp/resize_shadow_type.h"
#include "ash/style/ash_color_id.h"
#include "base/memory/raw_ptr.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/hit_test.h"
#include "ui/color/color_provider_source_observer.h"
#include "ui/color/color_variant.h"
namespace aura {
class Window;
@ -32,9 +31,16 @@ namespace ash {
// handled by the EventFilter.
class ResizeShadow : public ui::ColorProviderSourceObserver {
public:
// Resize shadow parameters. Default params values are unresizable window
// Resize shadow parameters. Default params values are non-resizable window
// shadow.
struct InitParams {
InitParams();
InitParams(const InitParams& other);
InitParams& operator=(const InitParams& other);
~InitParams();
// The width of the resize shadow that appears on edge of the window.
int thickness = 8;
// The corner radius of the resize shadow.
@ -44,7 +50,7 @@ class ResizeShadow : public ui::ColorProviderSourceObserver {
// The opacity of the resize shadow.
float opacity = 0.6f;
// The color of the resize shadow.
absl::variant<SkColor, ui::ColorId> color = kColorAshResizeShadowColor;
ui::ColorVariant color = kColorAshResizeShadowColor;
// Controls whether the resize shadow shall respond to hit testing or not.
bool hit_test_enabled = true;
int hide_duration_ms = 100;

@ -19,21 +19,6 @@
namespace ash {
namespace {
// Lock shadow params
constexpr ResizeShadow::InitParams kLockParams{
.thickness = 6,
.shadow_corner_radius = 6,
.window_corner_radius = 2,
.opacity = 0.3f,
.color = gfx::kGoogleGrey900,
.hit_test_enabled = false,
.hide_duration_ms = 0,
};
} // namespace
ResizeShadowController::ResizeShadowController() = default;
ResizeShadowController::~ResizeShadowController() {
@ -179,7 +164,14 @@ void ResizeShadowController::RecreateShadowIfNeeded(aura::Window* window) {
ResizeShadow::InitParams params;
if (type == ResizeShadowType::kLock) {
params = kLockParams;
params.thickness = 6;
params.shadow_corner_radius = 6;
params.window_corner_radius = 2;
params.opacity = 0.3f;
params.color = gfx::kGoogleGrey900;
params.hit_test_enabled = false;
params.hide_duration_ms = 0;
params.is_for_rounded_window = false;
}
// Configure window and shadow corner radius when `window` has rounded