Skip to content

Commit

Permalink
jellyroll shadow: uneven rounded corners part 1
Browse files Browse the repository at this point in the history
This cl implements the uneven rounded corners for texture layer based
shadow. The shadow based on nine patch layer will be implemented in
following cls.

Test in style viewer.

Bug: b:307326019
Change-Id: I747abd73f0b322fe2fb781c14811599ab2e6e09b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5041718
Commit-Queue: Xiaodan Zhu <zxdan@chromium.org>
Reviewed-by: Sean Kau <skau@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1227073}
  • Loading branch information
Xiaodan Zhu authored and Chromium LUCI CQ committed Nov 20, 2023
1 parent b7426fd commit bb78d90
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
10 changes: 10 additions & 0 deletions ash/style/system_shadow.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "ash/ash_export.h"
#include "ui/color/color_provider_source_observer.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/gfx/shadow_value.h"

namespace aura {
Expand Down Expand Up @@ -87,8 +88,17 @@ class ASH_EXPORT SystemShadow : public ui::ColorProviderSourceObserver {

virtual void SetContentBounds(const gfx::Rect& bounds) = 0;

// TODO(http://b/307326019): Deprecate this method when all shadow
// implementations use `gfx::RoundedCornersF`.
virtual void SetRoundedCornerRadius(int corner_radius) = 0;

// TODO(http://b/307326019): This is only used for
// `SystemShadowOnTextureLayer` for now. Should be applied to
// `SystemShadowOnNinePatchLayer` when `ui::Shadow` is able to use
// `gfx::RoundedCornersF`.
virtual void SetRoundedCorners(
const gfx::RoundedCornersF& rounded_corners) = 0;

virtual const gfx::Rect& GetContentBounds() = 0;

// Return the layer of the shadow. This function can be used by any types of
Expand Down
8 changes: 8 additions & 0 deletions ash/style/system_shadow_on_nine_patch_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ void SystemShadowOnNinePatchLayer::SetRoundedCornerRadius(int corner_radius) {
shadow()->SetRoundedCornerRadius(corner_radius);
}

void SystemShadowOnNinePatchLayer::SetRoundedCorners(
const gfx::RoundedCornersF& rounded_corners) {
// TODO(http://b/307326019): use corresponding interface of `ui::Shadow` when
// available.
NOTREACHED() << "Setting uneven rounded corners to the shadow on nine patch "
"layer is not ready.";
}

const gfx::Rect& SystemShadowOnNinePatchLayer::GetContentBounds() {
return shadow()->content_bounds();
}
Expand Down
1 change: 1 addition & 0 deletions ash/style/system_shadow_on_nine_patch_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SystemShadowOnNinePatchLayer : public SystemShadow {
void SetType(SystemShadow::Type type) override;
void SetContentBounds(const gfx::Rect& bounds) override;
void SetRoundedCornerRadius(int corner_radius) override;
void SetRoundedCorners(const gfx::RoundedCornersF& rounded_corners) override;
const gfx::Rect& GetContentBounds() override;
ui::Layer* GetLayer() override;
ui::Layer* GetNinePatchLayer() override;
Expand Down
23 changes: 20 additions & 3 deletions ash/style/system_shadow_on_texture_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ void SystemShadowOnTextureLayer::SetContentBounds(const gfx::Rect& bounds) {
}

void SystemShadowOnTextureLayer::SetRoundedCornerRadius(int corner_radius) {
corner_radius_ = corner_radius;
SetRoundedCorners(gfx::RoundedCornersF(corner_radius));
}

void SystemShadowOnTextureLayer::SetRoundedCorners(
const gfx::RoundedCornersF& rounded_corners) {
if (rounded_corners_ == rounded_corners) {
return;
}

rounded_corners_ = rounded_corners;
UpdateLayer();
}

Expand Down Expand Up @@ -83,8 +92,16 @@ void SystemShadowOnTextureLayer::OnPaintLayer(const ui::PaintContext& context) {
// Create a rounded rect of content area.
const gfx::Rect r_rect_bounds =
content_bounds_ - GetLayerBounds().OffsetFromOrigin();
const SkRRect r_rect = SkRRect::MakeRectXY(gfx::RectToSkRect(r_rect_bounds),
corner_radius_, corner_radius_);
SkRRect r_rect;
float upper_left = rounded_corners_.upper_left();
float upper_right = rounded_corners_.upper_right();
float lower_right = rounded_corners_.lower_right();
float lower_left = rounded_corners_.lower_left();
SkVector radii[4] = {{upper_left, upper_left},
{upper_right, upper_right},
{lower_right, lower_right},
{lower_left, lower_left}};
r_rect.setRectRadii(gfx::RectToSkRect(r_rect_bounds), radii);

// Clip out the center.
ui::PaintRecorder recorder(context, content_bounds_.size());
Expand Down
3 changes: 2 additions & 1 deletion ash/style/system_shadow_on_texture_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SystemShadowOnTextureLayer : public SystemShadow,
void SetType(SystemShadow::Type type) override;
void SetContentBounds(const gfx::Rect& bounds) override;
void SetRoundedCornerRadius(int corner_radius) override;
void SetRoundedCorners(const gfx::RoundedCornersF& rounded_corners) override;
const gfx::Rect& GetContentBounds() override;
ui::Layer* GetLayer() override;
ui::Layer* GetNinePatchLayer() override;
Expand Down Expand Up @@ -69,7 +70,7 @@ class SystemShadowOnTextureLayer : public SystemShadow,
gfx::ShadowValues shadow_values_;
// The bounds of the content area.
gfx::Rect content_bounds_;
int corner_radius_ = 0;
gfx::RoundedCornersF rounded_corners_;
// The shadow colors map.
ui::Shadow::ElevationToColorsMap colors_map_;
};
Expand Down

0 comments on commit bb78d90

Please sign in to comment.