Commit 865c2686 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

views: Replace HighlightPathGenerator::RoundRect with gfx::RRectF.

Test: none
Bug: 1056490
Change-Id: Ice9fef7222f5af17725dd3812ff633b0fa0a8f92
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2131151
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760161}
parent 47e07fe9
......@@ -122,9 +122,8 @@ class ExpandArrowHighlightPathGenerator : public views::HighlightPathGenerator {
const ExpandArrowHighlightPathGenerator&) = delete;
// views::HighlightPathGenerator:
base::Optional<RoundRect> GetRoundRect(const gfx::RectF& rect) override {
return base::make_optional(
RoundRect{gfx::RectF(GetCircleBounds()), kInkDropRadius});
base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect) override {
return gfx::RRectF(gfx::RectF(GetCircleBounds()), kInkDropRadius);
}
};
......
......@@ -33,7 +33,7 @@ class ShelfControlButtonHighlightPathGenerator
const ShelfControlButtonHighlightPathGenerator&) = delete;
// views::HighlightPathGenerator:
base::Optional<RoundRect> GetRoundRect(const gfx::RectF& rect) override {
base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect) override {
auto* shelf_config = ShelfConfig::Get();
// Some control buttons have a slightly larger size to fill the shelf and
// maximize the click target, but we still want their "visual" size to be
......@@ -46,8 +46,7 @@ class ShelfControlButtonHighlightPathGenerator
visual_bounds.Inset(0,
shelf_config->in_app_control_button_height_inset());
}
return base::make_optional(
RoundRect{visual_bounds, shelf_config->control_border_radius()});
return gfx::RRectF(visual_bounds, shelf_config->control_border_radius());
}
};
......
......@@ -99,12 +99,11 @@ class HighlightPathGenerator : public views::HighlightPathGenerator {
HighlightPathGenerator& operator=(const HighlightPathGenerator&) = delete;
// HighlightPathGenerator:
base::Optional<RoundRect> GetRoundRect(const gfx::RectF& rect) override {
base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect) override {
const float focus_ring_padding = 1.f;
gfx::RectF bounds(tray_background_view_->GetBackgroundBounds());
bounds.Inset(focus_ring_padding, focus_ring_padding);
return base::make_optional(
RoundRect{bounds, ShelfConfig::Get()->control_border_radius()});
return gfx::RRectF(bounds, ShelfConfig::Get()->control_border_radius());
}
private:
......
......@@ -126,8 +126,7 @@ class HighlightPathGenerator : public views::HighlightPathGenerator {
HighlightPathGenerator& operator=(const HighlightPathGenerator&) = delete;
// views::HighlightPathGenerator:
base::Optional<HighlightPathGenerator::RoundRect> GetRoundRect(
const gfx::RectF& rect) override {
base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect) override {
gfx::RectF bounds = rect;
bounds.Inset(GetInkDropInsets(ink_drop_style_));
float corner_radius = 0.f;
......@@ -143,8 +142,7 @@ class HighlightPathGenerator : public views::HighlightPathGenerator {
break;
}
return base::make_optional(
HighlightPathGenerator::RoundRect{bounds, corner_radius});
return gfx::RRectF(bounds, corner_radius);
}
private:
......
......@@ -531,14 +531,13 @@ class NotificationViewMD::NotificationViewMDPathGenerator
const NotificationViewMDPathGenerator&) = delete;
// views::HighlightPathGenerator:
base::Optional<RoundRect> GetRoundRect(const gfx::RectF& rect) override {
RoundRect round_rect;
round_rect.bounds = rect;
base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect) override {
gfx::RectF bounds = rect;
if (!preferred_size_.IsEmpty())
round_rect.bounds.set_size(gfx::SizeF(preferred_size_));
round_rect.corner_radius = gfx::RoundedCornersF(
top_radius_, top_radius_, bottom_radius_, bottom_radius_);
return round_rect;
bounds.set_size(gfx::SizeF(preferred_size_));
gfx::RoundedCornersF corner_radius(top_radius_, top_radius_, bottom_radius_,
bottom_radius_);
return gfx::RRectF(bounds, corner_radius);
}
void set_top_radius(int val) { top_radius_ = val; }
......
......@@ -182,13 +182,26 @@ void InkDropHostView::ResetInkDropMask() {
}
bool InkDropHostView::AddInkDropClip(ui::Layer* ink_drop_layer) {
base::Optional<HighlightPathGenerator::RoundRect> clipping_data =
base::Optional<gfx::RRectF> clipping_data =
HighlightPathGenerator::GetRoundRectForView(this);
if (!clipping_data)
return false;
ink_drop_layer->SetClipRect(gfx::ToEnclosingRect(clipping_data->bounds));
ink_drop_layer->SetRoundedCornerRadius(
gfx::RoundedCornersF(clipping_data->corner_radius));
ink_drop_layer->SetClipRect(gfx::ToEnclosingRect(clipping_data->rect()));
auto get_corner_radii =
[&clipping_data](gfx::RRectF::Corner corner) -> float {
return clipping_data.value().GetCornerRadii(corner).x();
};
gfx::RoundedCornersF rounded_corners;
rounded_corners.set_upper_left(
get_corner_radii(gfx::RRectF::Corner::kUpperLeft));
rounded_corners.set_upper_right(
get_corner_radii(gfx::RRectF::Corner::kUpperRight));
rounded_corners.set_lower_right(
get_corner_radii(gfx::RRectF::Corner::kLowerRight));
rounded_corners.set_lower_left(
get_corner_radii(gfx::RRectF::Corner::kLowerLeft));
ink_drop_layer->SetRoundedCornerRadius(rounded_corners);
ink_drop_layer->SetIsFastRoundedCorner(true);
return true;
}
......
......@@ -7,18 +7,13 @@
#include <algorithm>
#include "third_party/skia/include/core/SkRect.h"
#include "ui/gfx/rrect_f.h"
#include "ui/gfx/skia_util.h"
#include "ui/views/view.h"
#include "ui/views/view_class_properties.h"
namespace views {
HighlightPathGenerator::RoundRect::RoundRect() = default;
HighlightPathGenerator::RoundRect::RoundRect(const gfx::RectF& bounds,
float corner_radius)
: bounds(bounds), corner_radius(corner_radius) {}
HighlightPathGenerator::HighlightPathGenerator()
: HighlightPathGenerator(gfx::Insets()) {}
......@@ -35,8 +30,8 @@ void HighlightPathGenerator::Install(
}
// static
base::Optional<HighlightPathGenerator::RoundRect>
HighlightPathGenerator::GetRoundRectForView(const View* view) {
base::Optional<gfx::RRectF> HighlightPathGenerator::GetRoundRectForView(
const View* view) {
HighlightPathGenerator* path_generator =
view->GetProperty(kHighlightPathGeneratorKey);
return path_generator ? path_generator->GetRoundRect(view) : base::nullopt;
......@@ -44,28 +39,26 @@ HighlightPathGenerator::GetRoundRectForView(const View* view) {
SkPath HighlightPathGenerator::GetHighlightPath(const View* view) {
// A rounded rectangle must be supplied if using this default implementation.
base::Optional<HighlightPathGenerator::RoundRect> round_rect =
GetRoundRect(view);
base::Optional<gfx::RRectF> round_rect = GetRoundRect(view);
DCHECK(round_rect);
return SkPath().addRRect(
SkRRect{gfx::RRectF(round_rect->bounds, round_rect->corner_radius)});
return SkPath().addRRect(SkRRect{*round_rect});
}
base::Optional<HighlightPathGenerator::RoundRect>
HighlightPathGenerator::GetRoundRect(const gfx::RectF& rect) {
base::Optional<gfx::RRectF> HighlightPathGenerator::GetRoundRect(
const gfx::RectF& rect) {
return base::nullopt;
}
base::Optional<HighlightPathGenerator::RoundRect>
HighlightPathGenerator::GetRoundRect(const View* view) {
base::Optional<gfx::RRectF> HighlightPathGenerator::GetRoundRect(
const View* view) {
gfx::Rect bounds(view->GetLocalBounds());
bounds.Inset(insets_);
return GetRoundRect(gfx::RectF(bounds));
}
base::Optional<HighlightPathGenerator::RoundRect>
EmptyHighlightPathGenerator::GetRoundRect(const gfx::RectF& rect) {
return HighlightPathGenerator::RoundRect();
base::Optional<gfx::RRectF> EmptyHighlightPathGenerator::GetRoundRect(
const gfx::RectF& rect) {
return gfx::RRectF();
}
void InstallEmptyHighlightPathGenerator(View* view) {
......@@ -73,9 +66,9 @@ void InstallEmptyHighlightPathGenerator(View* view) {
view, std::make_unique<EmptyHighlightPathGenerator>());
}
base::Optional<HighlightPathGenerator::RoundRect>
RectHighlightPathGenerator::GetRoundRect(const gfx::RectF& rect) {
return HighlightPathGenerator::RoundRect{rect, /*corner_radius=*/0};
base::Optional<gfx::RRectF> RectHighlightPathGenerator::GetRoundRect(
const gfx::RectF& rect) {
return gfx::RRectF(rect);
}
void InstallRectHighlightPathGenerator(View* view) {
......@@ -87,13 +80,13 @@ CircleHighlightPathGenerator::CircleHighlightPathGenerator(
const gfx::Insets& insets)
: HighlightPathGenerator(insets) {}
base::Optional<HighlightPathGenerator::RoundRect>
CircleHighlightPathGenerator::GetRoundRect(const gfx::RectF& rect) {
base::Optional<gfx::RRectF> CircleHighlightPathGenerator::GetRoundRect(
const gfx::RectF& rect) {
gfx::RectF bounds = rect;
const float corner_radius = std::min(bounds.width(), bounds.height()) / 2.f;
bounds.ClampToCenteredSize(
gfx::SizeF(corner_radius * 2.f, corner_radius * 2.f));
return HighlightPathGenerator::RoundRect{bounds, corner_radius};
return gfx::RRectF(bounds, corner_radius);
}
void InstallCircleHighlightPathGenerator(View* view) {
......@@ -124,11 +117,11 @@ FixedSizeCircleHighlightPathGenerator::FixedSizeCircleHighlightPathGenerator(
int radius)
: radius_(radius) {}
base::Optional<HighlightPathGenerator::RoundRect>
FixedSizeCircleHighlightPathGenerator::GetRoundRect(const gfx::RectF& rect) {
base::Optional<gfx::RRectF> FixedSizeCircleHighlightPathGenerator::GetRoundRect(
const gfx::RectF& rect) {
gfx::RectF bounds = rect;
bounds.ClampToCenteredSize(gfx::SizeF(radius_ * 2, radius_ * 2));
return HighlightPathGenerator::RoundRect{bounds, radius_};
return gfx::RRectF(bounds, radius_);
}
void InstallFixedSizeCircleHighlightPathGenerator(View* view, int radius) {
......@@ -141,9 +134,9 @@ RoundRectHighlightPathGenerator::RoundRectHighlightPathGenerator(
int corner_radius)
: HighlightPathGenerator(insets), corner_radius_(corner_radius) {}
base::Optional<HighlightPathGenerator::RoundRect>
RoundRectHighlightPathGenerator::GetRoundRect(const gfx::RectF& rect) {
return HighlightPathGenerator::RoundRect{rect, corner_radius_};
base::Optional<gfx::RRectF> RoundRectHighlightPathGenerator::GetRoundRect(
const gfx::RectF& rect) {
return gfx::RRectF(rect, corner_radius_);
}
void InstallRoundRectHighlightPathGenerator(View* view,
......
......@@ -11,9 +11,12 @@
#include "third_party/skia/include/core/SkPath.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/views/views_export.h"
namespace gfx {
class RRectF;
}
namespace views {
class View;
......@@ -23,17 +26,6 @@ class View;
// effects.
class VIEWS_EXPORT HighlightPathGenerator {
public:
struct VIEWS_EXPORT RoundRect {
// TODO(http://crbug.com/1056490): Remove these constructors and have
// callsites create a gfx::RoundedCornersF explicitly, or replace this
// struct with a gfx::RRectF.
RoundRect();
RoundRect(const gfx::RectF& bounds, float corner_radius);
gfx::RectF bounds;
gfx::RoundedCornersF corner_radius;
};
// TODO(http://crbug.com/1056490): Remove this constructor in favor of the one
// that takes |insets|.
HighlightPathGenerator();
......@@ -45,18 +37,18 @@ class VIEWS_EXPORT HighlightPathGenerator {
static void Install(View* host,
std::unique_ptr<HighlightPathGenerator> generator);
static base::Optional<RoundRect> GetRoundRectForView(const View* view);
static base::Optional<gfx::RRectF> GetRoundRectForView(const View* view);
// TODO(http://crbug.com/1056490): Deprecate |GetHighlightPath()| in favor of
// |GetRoundRect()|.
virtual SkPath GetHighlightPath(const View* view);
// Optionally returns a RoundRect struct which contains data for drawing a
// Optionally returns a gfx::RRectF which contains data for drawing a
// highlight. Note that |rect| is in the coordinate system of the view.
// TODO(http://crbug.com/1056490): Once |GetHighlightPath()| is deprecated,
// make this a pure virtual function and make the return not optional.
virtual base::Optional<RoundRect> GetRoundRect(const gfx::RectF& rect);
base::Optional<RoundRect> GetRoundRect(const View* view);
virtual base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect);
base::Optional<gfx::RRectF> GetRoundRect(const View* view);
private:
const gfx::Insets insets_;
......@@ -74,7 +66,7 @@ class VIEWS_EXPORT EmptyHighlightPathGenerator : public HighlightPathGenerator {
delete;
// HighlightPathGenerator:
base::Optional<RoundRect> GetRoundRect(const gfx::RectF& rect) override;
base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect) override;
};
void VIEWS_EXPORT InstallEmptyHighlightPathGenerator(View* view);
......@@ -89,7 +81,7 @@ class VIEWS_EXPORT RectHighlightPathGenerator : public HighlightPathGenerator {
delete;
// HighlightPathGenerator:
base::Optional<RoundRect> GetRoundRect(const gfx::RectF& rect) override;
base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect) override;
};
void VIEWS_EXPORT InstallRectHighlightPathGenerator(View* view);
......@@ -105,7 +97,7 @@ class VIEWS_EXPORT CircleHighlightPathGenerator
delete;
// HighlightPathGenerator:
base::Optional<RoundRect> GetRoundRect(const gfx::RectF& rect) override;
base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect) override;
};
void VIEWS_EXPORT InstallCircleHighlightPathGenerator(View* view);
......@@ -143,7 +135,7 @@ class VIEWS_EXPORT FixedSizeCircleHighlightPathGenerator
const FixedSizeCircleHighlightPathGenerator&) = delete;
// HighlightPathGenerator:
base::Optional<RoundRect> GetRoundRect(const gfx::RectF& rect) override;
base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect) override;
private:
const int radius_;
......@@ -164,7 +156,7 @@ class VIEWS_EXPORT RoundRectHighlightPathGenerator
const RoundRectHighlightPathGenerator&) = delete;
// HighlightPathGenerator:
base::Optional<RoundRect> GetRoundRect(const gfx::RectF& rect) override;
base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect) override;
private:
const int corner_radius_;
......
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