Commit 64679b34 authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

Support rounded rects that don't have the same radius on all 4 corners

Bug: 805612
Change-Id: I86af86a62fe2e46691db6bfb2b24da404c93ec1d
Reviewed-on: https://chromium-review.googlesource.com/1130059
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#573528}
parent 0839b2d2
......@@ -10,16 +10,33 @@
namespace ash {
RoundedRectView::RoundedRectView(int corner_radius, SkColor background_color)
: corner_radius_(corner_radius), background_color_(background_color) {}
: RoundedRectView(corner_radius,
corner_radius,
corner_radius,
corner_radius,
background_color) {}
RoundedRectView::RoundedRectView(int top_left_radius,
int top_right_radius,
int bottom_right_radius,
int bottom_left_radius,
SkColor background_color)
: top_left_radius_(top_left_radius),
top_right_radius_(top_right_radius),
bottom_right_radius_(bottom_right_radius),
bottom_left_radius_(bottom_left_radius),
background_color_(background_color) {}
RoundedRectView::~RoundedRectView() = default;
void RoundedRectView::OnPaint(gfx::Canvas* canvas) {
views::View::OnPaint(canvas);
SkScalar radius = SkIntToScalar(corner_radius_);
const SkScalar kRadius[8] = {radius, radius, radius, radius,
radius, radius, radius, radius};
const SkScalar kRadius[8] = {
SkIntToScalar(top_left_radius_), SkIntToScalar(top_left_radius_),
SkIntToScalar(top_right_radius_), SkIntToScalar(top_right_radius_),
SkIntToScalar(bottom_right_radius_), SkIntToScalar(bottom_right_radius_),
SkIntToScalar(bottom_left_radius_), SkIntToScalar(bottom_left_radius_)};
SkPath path;
gfx::Rect bounds(size());
path.addRoundRect(gfx::RectToSkRect(bounds), kRadius);
......@@ -36,12 +53,26 @@ void RoundedRectView::SetBackgroundColor(SkColor background_color) {
SchedulePaint();
}
void RoundedRectView::SetCornerRadius(int radius) {
if (corner_radius_ == radius)
void RoundedRectView::SetCornerRadius(int top_left_radius,
int top_right_radius,
int bottom_right_radius,
int bottom_left_radius) {
if (top_left_radius_ == top_left_radius &&
top_right_radius_ == top_right_radius &&
bottom_right_radius_ == bottom_right_radius &&
bottom_left_radius_ == bottom_left_radius) {
return;
}
corner_radius_ = radius;
top_left_radius_ = top_left_radius;
top_right_radius_ = top_right_radius;
bottom_right_radius_ = bottom_right_radius;
bottom_left_radius_ = bottom_left_radius;
SchedulePaint();
}
void RoundedRectView::SetCornerRadius(int radius) {
SetCornerRadius(radius, radius, radius, radius);
}
} // namespace ash
......@@ -20,16 +20,28 @@ namespace ash {
class RoundedRectView : public views::View {
public:
RoundedRectView(int corner_radius, SkColor background_color);
RoundedRectView(int top_left_radius,
int top_right_radius,
int bottom_right_radius,
int bottom_left_radius,
SkColor background_color);
~RoundedRectView() override;
void SetBackgroundColor(SkColor background_color);
void SetCornerRadius(int top_left_radius,
int top_right_radius,
int bottom_right_radius,
int bottom_left_radius);
void SetCornerRadius(int radius);
// views::View:
void OnPaint(gfx::Canvas* canvas) override;
private:
int corner_radius_;
int top_left_radius_;
int top_right_radius_;
int bottom_right_radius_;
int bottom_left_radius_;
SkColor background_color_;
DISALLOW_COPY_AND_ASSIGN(RoundedRectView);
......
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