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 { ...@@ -122,9 +122,8 @@ class ExpandArrowHighlightPathGenerator : public views::HighlightPathGenerator {
const ExpandArrowHighlightPathGenerator&) = delete; const ExpandArrowHighlightPathGenerator&) = delete;
// views::HighlightPathGenerator: // views::HighlightPathGenerator:
base::Optional<RoundRect> GetRoundRect(const gfx::RectF& rect) override { base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect) override {
return base::make_optional( return gfx::RRectF(gfx::RectF(GetCircleBounds()), kInkDropRadius);
RoundRect{gfx::RectF(GetCircleBounds()), kInkDropRadius});
} }
}; };
......
...@@ -33,7 +33,7 @@ class ShelfControlButtonHighlightPathGenerator ...@@ -33,7 +33,7 @@ class ShelfControlButtonHighlightPathGenerator
const ShelfControlButtonHighlightPathGenerator&) = delete; const ShelfControlButtonHighlightPathGenerator&) = delete;
// views::HighlightPathGenerator: // 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(); auto* shelf_config = ShelfConfig::Get();
// Some control buttons have a slightly larger size to fill the shelf and // 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 // maximize the click target, but we still want their "visual" size to be
...@@ -46,8 +46,7 @@ class ShelfControlButtonHighlightPathGenerator ...@@ -46,8 +46,7 @@ class ShelfControlButtonHighlightPathGenerator
visual_bounds.Inset(0, visual_bounds.Inset(0,
shelf_config->in_app_control_button_height_inset()); shelf_config->in_app_control_button_height_inset());
} }
return base::make_optional( return gfx::RRectF(visual_bounds, shelf_config->control_border_radius());
RoundRect{visual_bounds, shelf_config->control_border_radius()});
} }
}; };
......
...@@ -99,12 +99,11 @@ class HighlightPathGenerator : public views::HighlightPathGenerator { ...@@ -99,12 +99,11 @@ class HighlightPathGenerator : public views::HighlightPathGenerator {
HighlightPathGenerator& operator=(const HighlightPathGenerator&) = delete; HighlightPathGenerator& operator=(const HighlightPathGenerator&) = delete;
// HighlightPathGenerator: // 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; const float focus_ring_padding = 1.f;
gfx::RectF bounds(tray_background_view_->GetBackgroundBounds()); gfx::RectF bounds(tray_background_view_->GetBackgroundBounds());
bounds.Inset(focus_ring_padding, focus_ring_padding); bounds.Inset(focus_ring_padding, focus_ring_padding);
return base::make_optional( return gfx::RRectF(bounds, ShelfConfig::Get()->control_border_radius());
RoundRect{bounds, ShelfConfig::Get()->control_border_radius()});
} }
private: private:
......
...@@ -126,8 +126,7 @@ class HighlightPathGenerator : public views::HighlightPathGenerator { ...@@ -126,8 +126,7 @@ class HighlightPathGenerator : public views::HighlightPathGenerator {
HighlightPathGenerator& operator=(const HighlightPathGenerator&) = delete; HighlightPathGenerator& operator=(const HighlightPathGenerator&) = delete;
// views::HighlightPathGenerator: // views::HighlightPathGenerator:
base::Optional<HighlightPathGenerator::RoundRect> GetRoundRect( base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect) override {
const gfx::RectF& rect) override {
gfx::RectF bounds = rect; gfx::RectF bounds = rect;
bounds.Inset(GetInkDropInsets(ink_drop_style_)); bounds.Inset(GetInkDropInsets(ink_drop_style_));
float corner_radius = 0.f; float corner_radius = 0.f;
...@@ -143,8 +142,7 @@ class HighlightPathGenerator : public views::HighlightPathGenerator { ...@@ -143,8 +142,7 @@ class HighlightPathGenerator : public views::HighlightPathGenerator {
break; break;
} }
return base::make_optional( return gfx::RRectF(bounds, corner_radius);
HighlightPathGenerator::RoundRect{bounds, corner_radius});
} }
private: private:
......
...@@ -531,14 +531,13 @@ class NotificationViewMD::NotificationViewMDPathGenerator ...@@ -531,14 +531,13 @@ class NotificationViewMD::NotificationViewMDPathGenerator
const NotificationViewMDPathGenerator&) = delete; const NotificationViewMDPathGenerator&) = delete;
// views::HighlightPathGenerator: // views::HighlightPathGenerator:
base::Optional<RoundRect> GetRoundRect(const gfx::RectF& rect) override { base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect) override {
RoundRect round_rect; gfx::RectF bounds = rect;
round_rect.bounds = rect;
if (!preferred_size_.IsEmpty()) if (!preferred_size_.IsEmpty())
round_rect.bounds.set_size(gfx::SizeF(preferred_size_)); bounds.set_size(gfx::SizeF(preferred_size_));
round_rect.corner_radius = gfx::RoundedCornersF( gfx::RoundedCornersF corner_radius(top_radius_, top_radius_, bottom_radius_,
top_radius_, top_radius_, bottom_radius_, bottom_radius_); bottom_radius_);
return round_rect; return gfx::RRectF(bounds, corner_radius);
} }
void set_top_radius(int val) { top_radius_ = val; } void set_top_radius(int val) { top_radius_ = val; }
......
...@@ -182,13 +182,26 @@ void InkDropHostView::ResetInkDropMask() { ...@@ -182,13 +182,26 @@ void InkDropHostView::ResetInkDropMask() {
} }
bool InkDropHostView::AddInkDropClip(ui::Layer* ink_drop_layer) { bool InkDropHostView::AddInkDropClip(ui::Layer* ink_drop_layer) {
base::Optional<HighlightPathGenerator::RoundRect> clipping_data = base::Optional<gfx::RRectF> clipping_data =
HighlightPathGenerator::GetRoundRectForView(this); HighlightPathGenerator::GetRoundRectForView(this);
if (!clipping_data) if (!clipping_data)
return false; return false;
ink_drop_layer->SetClipRect(gfx::ToEnclosingRect(clipping_data->bounds));
ink_drop_layer->SetRoundedCornerRadius( ink_drop_layer->SetClipRect(gfx::ToEnclosingRect(clipping_data->rect()));
gfx::RoundedCornersF(clipping_data->corner_radius)); 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); ink_drop_layer->SetIsFastRoundedCorner(true);
return true; return true;
} }
......
...@@ -7,18 +7,13 @@ ...@@ -7,18 +7,13 @@
#include <algorithm> #include <algorithm>
#include "third_party/skia/include/core/SkRect.h" #include "third_party/skia/include/core/SkRect.h"
#include "ui/gfx/rrect_f.h"
#include "ui/gfx/skia_util.h" #include "ui/gfx/skia_util.h"
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/view_class_properties.h" #include "ui/views/view_class_properties.h"
namespace views { 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::HighlightPathGenerator()
: HighlightPathGenerator(gfx::Insets()) {} : HighlightPathGenerator(gfx::Insets()) {}
...@@ -35,8 +30,8 @@ void HighlightPathGenerator::Install( ...@@ -35,8 +30,8 @@ void HighlightPathGenerator::Install(
} }
// static // static
base::Optional<HighlightPathGenerator::RoundRect> base::Optional<gfx::RRectF> HighlightPathGenerator::GetRoundRectForView(
HighlightPathGenerator::GetRoundRectForView(const View* view) { const View* view) {
HighlightPathGenerator* path_generator = HighlightPathGenerator* path_generator =
view->GetProperty(kHighlightPathGeneratorKey); view->GetProperty(kHighlightPathGeneratorKey);
return path_generator ? path_generator->GetRoundRect(view) : base::nullopt; return path_generator ? path_generator->GetRoundRect(view) : base::nullopt;
...@@ -44,28 +39,26 @@ HighlightPathGenerator::GetRoundRectForView(const View* view) { ...@@ -44,28 +39,26 @@ HighlightPathGenerator::GetRoundRectForView(const View* view) {
SkPath HighlightPathGenerator::GetHighlightPath(const View* view) { SkPath HighlightPathGenerator::GetHighlightPath(const View* view) {
// A rounded rectangle must be supplied if using this default implementation. // A rounded rectangle must be supplied if using this default implementation.
base::Optional<HighlightPathGenerator::RoundRect> round_rect = base::Optional<gfx::RRectF> round_rect = GetRoundRect(view);
GetRoundRect(view);
DCHECK(round_rect); DCHECK(round_rect);
return SkPath().addRRect( return SkPath().addRRect(SkRRect{*round_rect});
SkRRect{gfx::RRectF(round_rect->bounds, round_rect->corner_radius)});
} }
base::Optional<HighlightPathGenerator::RoundRect> base::Optional<gfx::RRectF> HighlightPathGenerator::GetRoundRect(
HighlightPathGenerator::GetRoundRect(const gfx::RectF& rect) { const gfx::RectF& rect) {
return base::nullopt; return base::nullopt;
} }
base::Optional<HighlightPathGenerator::RoundRect> base::Optional<gfx::RRectF> HighlightPathGenerator::GetRoundRect(
HighlightPathGenerator::GetRoundRect(const View* view) { const View* view) {
gfx::Rect bounds(view->GetLocalBounds()); gfx::Rect bounds(view->GetLocalBounds());
bounds.Inset(insets_); bounds.Inset(insets_);
return GetRoundRect(gfx::RectF(bounds)); return GetRoundRect(gfx::RectF(bounds));
} }
base::Optional<HighlightPathGenerator::RoundRect> base::Optional<gfx::RRectF> EmptyHighlightPathGenerator::GetRoundRect(
EmptyHighlightPathGenerator::GetRoundRect(const gfx::RectF& rect) { const gfx::RectF& rect) {
return HighlightPathGenerator::RoundRect(); return gfx::RRectF();
} }
void InstallEmptyHighlightPathGenerator(View* view) { void InstallEmptyHighlightPathGenerator(View* view) {
...@@ -73,9 +66,9 @@ void InstallEmptyHighlightPathGenerator(View* view) { ...@@ -73,9 +66,9 @@ void InstallEmptyHighlightPathGenerator(View* view) {
view, std::make_unique<EmptyHighlightPathGenerator>()); view, std::make_unique<EmptyHighlightPathGenerator>());
} }
base::Optional<HighlightPathGenerator::RoundRect> base::Optional<gfx::RRectF> RectHighlightPathGenerator::GetRoundRect(
RectHighlightPathGenerator::GetRoundRect(const gfx::RectF& rect) { const gfx::RectF& rect) {
return HighlightPathGenerator::RoundRect{rect, /*corner_radius=*/0}; return gfx::RRectF(rect);
} }
void InstallRectHighlightPathGenerator(View* view) { void InstallRectHighlightPathGenerator(View* view) {
...@@ -87,13 +80,13 @@ CircleHighlightPathGenerator::CircleHighlightPathGenerator( ...@@ -87,13 +80,13 @@ CircleHighlightPathGenerator::CircleHighlightPathGenerator(
const gfx::Insets& insets) const gfx::Insets& insets)
: HighlightPathGenerator(insets) {} : HighlightPathGenerator(insets) {}
base::Optional<HighlightPathGenerator::RoundRect> base::Optional<gfx::RRectF> CircleHighlightPathGenerator::GetRoundRect(
CircleHighlightPathGenerator::GetRoundRect(const gfx::RectF& rect) { const gfx::RectF& rect) {
gfx::RectF bounds = rect; gfx::RectF bounds = rect;
const float corner_radius = std::min(bounds.width(), bounds.height()) / 2.f; const float corner_radius = std::min(bounds.width(), bounds.height()) / 2.f;
bounds.ClampToCenteredSize( bounds.ClampToCenteredSize(
gfx::SizeF(corner_radius * 2.f, corner_radius * 2.f)); 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) { void InstallCircleHighlightPathGenerator(View* view) {
...@@ -124,11 +117,11 @@ FixedSizeCircleHighlightPathGenerator::FixedSizeCircleHighlightPathGenerator( ...@@ -124,11 +117,11 @@ FixedSizeCircleHighlightPathGenerator::FixedSizeCircleHighlightPathGenerator(
int radius) int radius)
: radius_(radius) {} : radius_(radius) {}
base::Optional<HighlightPathGenerator::RoundRect> base::Optional<gfx::RRectF> FixedSizeCircleHighlightPathGenerator::GetRoundRect(
FixedSizeCircleHighlightPathGenerator::GetRoundRect(const gfx::RectF& rect) { const gfx::RectF& rect) {
gfx::RectF bounds = rect; gfx::RectF bounds = rect;
bounds.ClampToCenteredSize(gfx::SizeF(radius_ * 2, radius_ * 2)); bounds.ClampToCenteredSize(gfx::SizeF(radius_ * 2, radius_ * 2));
return HighlightPathGenerator::RoundRect{bounds, radius_}; return gfx::RRectF(bounds, radius_);
} }
void InstallFixedSizeCircleHighlightPathGenerator(View* view, int radius) { void InstallFixedSizeCircleHighlightPathGenerator(View* view, int radius) {
...@@ -141,9 +134,9 @@ RoundRectHighlightPathGenerator::RoundRectHighlightPathGenerator( ...@@ -141,9 +134,9 @@ RoundRectHighlightPathGenerator::RoundRectHighlightPathGenerator(
int corner_radius) int corner_radius)
: HighlightPathGenerator(insets), corner_radius_(corner_radius) {} : HighlightPathGenerator(insets), corner_radius_(corner_radius) {}
base::Optional<HighlightPathGenerator::RoundRect> base::Optional<gfx::RRectF> RoundRectHighlightPathGenerator::GetRoundRect(
RoundRectHighlightPathGenerator::GetRoundRect(const gfx::RectF& rect) { const gfx::RectF& rect) {
return HighlightPathGenerator::RoundRect{rect, corner_radius_}; return gfx::RRectF(rect, corner_radius_);
} }
void InstallRoundRectHighlightPathGenerator(View* view, void InstallRoundRectHighlightPathGenerator(View* view,
......
...@@ -11,9 +11,12 @@ ...@@ -11,9 +11,12 @@
#include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/core/SkPath.h"
#include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect_f.h" #include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
namespace gfx {
class RRectF;
}
namespace views { namespace views {
class View; class View;
...@@ -23,17 +26,6 @@ class View; ...@@ -23,17 +26,6 @@ class View;
// effects. // effects.
class VIEWS_EXPORT HighlightPathGenerator { class VIEWS_EXPORT HighlightPathGenerator {
public: 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 // TODO(http://crbug.com/1056490): Remove this constructor in favor of the one
// that takes |insets|. // that takes |insets|.
HighlightPathGenerator(); HighlightPathGenerator();
...@@ -45,18 +37,18 @@ class VIEWS_EXPORT HighlightPathGenerator { ...@@ -45,18 +37,18 @@ class VIEWS_EXPORT HighlightPathGenerator {
static void Install(View* host, static void Install(View* host,
std::unique_ptr<HighlightPathGenerator> generator); 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 // TODO(http://crbug.com/1056490): Deprecate |GetHighlightPath()| in favor of
// |GetRoundRect()|. // |GetRoundRect()|.
virtual SkPath GetHighlightPath(const View* view); 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. // highlight. Note that |rect| is in the coordinate system of the view.
// TODO(http://crbug.com/1056490): Once |GetHighlightPath()| is deprecated, // TODO(http://crbug.com/1056490): Once |GetHighlightPath()| is deprecated,
// make this a pure virtual function and make the return not optional. // make this a pure virtual function and make the return not optional.
virtual base::Optional<RoundRect> GetRoundRect(const gfx::RectF& rect); virtual base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect);
base::Optional<RoundRect> GetRoundRect(const View* view); base::Optional<gfx::RRectF> GetRoundRect(const View* view);
private: private:
const gfx::Insets insets_; const gfx::Insets insets_;
...@@ -74,7 +66,7 @@ class VIEWS_EXPORT EmptyHighlightPathGenerator : public HighlightPathGenerator { ...@@ -74,7 +66,7 @@ class VIEWS_EXPORT EmptyHighlightPathGenerator : public HighlightPathGenerator {
delete; delete;
// HighlightPathGenerator: // 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); void VIEWS_EXPORT InstallEmptyHighlightPathGenerator(View* view);
...@@ -89,7 +81,7 @@ class VIEWS_EXPORT RectHighlightPathGenerator : public HighlightPathGenerator { ...@@ -89,7 +81,7 @@ class VIEWS_EXPORT RectHighlightPathGenerator : public HighlightPathGenerator {
delete; delete;
// HighlightPathGenerator: // 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); void VIEWS_EXPORT InstallRectHighlightPathGenerator(View* view);
...@@ -105,7 +97,7 @@ class VIEWS_EXPORT CircleHighlightPathGenerator ...@@ -105,7 +97,7 @@ class VIEWS_EXPORT CircleHighlightPathGenerator
delete; delete;
// HighlightPathGenerator: // 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); void VIEWS_EXPORT InstallCircleHighlightPathGenerator(View* view);
...@@ -143,7 +135,7 @@ class VIEWS_EXPORT FixedSizeCircleHighlightPathGenerator ...@@ -143,7 +135,7 @@ class VIEWS_EXPORT FixedSizeCircleHighlightPathGenerator
const FixedSizeCircleHighlightPathGenerator&) = delete; const FixedSizeCircleHighlightPathGenerator&) = delete;
// HighlightPathGenerator: // HighlightPathGenerator:
base::Optional<RoundRect> GetRoundRect(const gfx::RectF& rect) override; base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect) override;
private: private:
const int radius_; const int radius_;
...@@ -164,7 +156,7 @@ class VIEWS_EXPORT RoundRectHighlightPathGenerator ...@@ -164,7 +156,7 @@ class VIEWS_EXPORT RoundRectHighlightPathGenerator
const RoundRectHighlightPathGenerator&) = delete; const RoundRectHighlightPathGenerator&) = delete;
// HighlightPathGenerator: // HighlightPathGenerator:
base::Optional<RoundRect> GetRoundRect(const gfx::RectF& rect) override; base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect) override;
private: private:
const int corner_radius_; 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