Skip to content

Commit 1579d98

Browse files
Jan Keitelchromeos-ci-prod
authored andcommitted
Modernize equality operators in //ui
This CL is pure clean-up and contains no functionality changes. Depending on the files covered in the CL (since the CL was generated using git cl split), it does a subset of the following: the following: - Remove unneeded operator!= declarations/definitions since C++20 can automatically derive those from operator==. - Default operator== where this is equivalent to the current behavior. - Default operator<=> where this is equivalent to the current behavior. This CL was uploaded by git cl split. [email protected] Bug: 40256175 Change-Id: Ia3f2c7d6214d609e2830f53d8dc7d1ecfadd6940 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6533702 Commit-Queue: Ian Vollick <[email protected]> Auto-Submit: Jan Keitel <[email protected]> Reviewed-by: Ian Vollick <[email protected]> Cr-Commit-Position: refs/heads/main@{#1458822} CrOS-Libchrome-Original-Commit: 69d651809451905cd6ca86f5e9d47b569033eae9
1 parent 272ec41 commit 1579d98

21 files changed

+44
-165
lines changed

ui/gfx/geometry/axis_transform2d.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,8 @@ class COMPONENT_EXPORT(GEOMETRY) AxisTransform2d {
3737
return AxisTransform2d(scale, translation);
3838
}
3939

40-
constexpr bool operator==(const AxisTransform2d& other) const {
41-
return scale_ == other.scale_ && translation_ == other.translation_;
42-
}
43-
constexpr bool operator!=(const AxisTransform2d& other) const {
44-
return !(*this == other);
45-
}
40+
friend constexpr bool operator==(const AxisTransform2d&,
41+
const AxisTransform2d&) = default;
4642

4743
void PreScale(const Vector2dF& scale) { scale_.Scale(scale.x(), scale.y()); }
4844
void PostScale(const Vector2dF& scale) {

ui/gfx/geometry/box_f.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class COMPONENT_EXPORT(GEOMETRY) BoxF {
100100
// |origin_|.
101101
void ExpandTo(const BoxF& box);
102102

103+
friend bool operator==(const BoxF&, const BoxF&) = default;
104+
103105
private:
104106
// Expands the box to contain the two given points. It is required that each
105107
// component of |min| is less than or equal to the corresponding component in
@@ -133,15 +135,6 @@ inline BoxF ScaleBox(const BoxF& b, float scale) {
133135
return ScaleBox(b, scale, scale, scale);
134136
}
135137

136-
inline bool operator==(const BoxF& a, const BoxF& b) {
137-
return a.origin() == b.origin() && a.width() == b.width() &&
138-
a.height() == b.height() && a.depth() == b.depth();
139-
}
140-
141-
inline bool operator!=(const BoxF& a, const BoxF& b) {
142-
return !(a == b);
143-
}
144-
145138
inline BoxF operator+(const BoxF& b, const Vector3dF& v) {
146139
return BoxF(b.x() + v.x(),
147140
b.y() + v.y(),

ui/gfx/geometry/insets_outsets_base.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,8 @@ class InsetsOutsetsBase {
107107
right_ = std::max(right_, other.right_);
108108
}
109109

110-
bool operator==(const InsetsOutsetsBase<T>& other) const {
111-
return top_ == other.top_ && left_ == other.left_ &&
112-
bottom_ == other.bottom_ && right_ == other.right_;
113-
}
114-
115-
bool operator!=(const InsetsOutsetsBase<T>& other) const {
116-
return !(*this == other);
117-
}
110+
friend bool operator==(const InsetsOutsetsBase<T>&,
111+
const InsetsOutsetsBase<T>&) = default;
118112

119113
void operator+=(const T& other) {
120114
top_ = base::ClampAdd(top_, other.top_);

ui/gfx/geometry/insets_outsets_f_base.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,8 @@ class InsetsOutsetsFBase {
9090
}
9191
void Scale(float scale) { Scale(scale, scale); }
9292

93-
bool operator==(const InsetsOutsetsFBase<T>& other) const {
94-
return top_ == other.top_ && left_ == other.left_ &&
95-
bottom_ == other.bottom_ && right_ == other.right_;
96-
}
97-
98-
bool operator!=(const InsetsOutsetsFBase<T>& other) const {
99-
return !(*this == other);
100-
}
93+
friend bool operator==(const InsetsOutsetsFBase<T>&,
94+
const InsetsOutsetsFBase<T>&) = default;
10195

10296
void operator+=(const T& other) {
10397
top_ += other.top_;

ui/gfx/geometry/linear_gradient.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class COMPONENT_EXPORT(GEOMETRY_SKIA) LinearGradient {
3535
float fraction = 0;
3636
// Alpha, from 0 to 255.
3737
uint8_t alpha = 0;
38+
39+
friend bool operator==(const Step&, const Step&) = default;
3840
};
3941
static LinearGradient& GetEmpty();
4042

@@ -69,27 +71,16 @@ class COMPONENT_EXPORT(GEOMETRY_SKIA) LinearGradient {
6971

7072
std::string ToString() const;
7173

74+
friend bool operator==(const LinearGradient&,
75+
const LinearGradient&) = default;
76+
7277
private:
7378
// angle in degrees.
7479
int16_t angle_ = 0;
7580
size_t step_count_ = 0;
7681
StepArray steps_;
7782
};
7883

79-
inline bool operator==(const LinearGradient::Step& lhs,
80-
const LinearGradient::Step& rhs) {
81-
return lhs.fraction == rhs.fraction && lhs.alpha == rhs.alpha;
82-
}
83-
84-
inline bool operator==(const LinearGradient& lhs, const LinearGradient& rhs) {
85-
return lhs.angle() == rhs.angle() && lhs.step_count() == rhs.step_count() &&
86-
lhs.steps() == rhs.steps();
87-
}
88-
89-
inline bool operator!=(const LinearGradient& lhs, const LinearGradient& rhs) {
90-
return !(lhs == rhs);
91-
}
92-
9384
} // namespace gfx
9485

9586
#endif // UI_GFX_GEOMETRY_LINEAR_GRADIENT_H_

ui/gfx/geometry/mask_filter_info.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class COMPONENT_EXPORT(GEOMETRY_SKIA) MaskFilterInfo {
6666

6767
std::string ToString() const;
6868

69+
friend bool operator==(const MaskFilterInfo&,
70+
const MaskFilterInfo&) = default;
71+
6972
private:
7073
// The rounded corner bounds. This also defines the bounds that the mask
7174
// filter will be applied to.
@@ -75,15 +78,6 @@ class COMPONENT_EXPORT(GEOMETRY_SKIA) MaskFilterInfo {
7578
std::optional<gfx::LinearGradient> gradient_mask_;
7679
};
7780

78-
inline bool operator==(const MaskFilterInfo& lhs, const MaskFilterInfo& rhs) {
79-
return (lhs.rounded_corner_bounds() == rhs.rounded_corner_bounds()) &&
80-
(lhs.gradient_mask() == rhs.gradient_mask());
81-
}
82-
83-
inline bool operator!=(const MaskFilterInfo& lhs, const MaskFilterInfo& rhs) {
84-
return !(lhs == rhs);
85-
}
86-
8781
// This is declared here for use in gtest-based unit tests but is defined in
8882
// the //ui/gfx:test_support target. Depend on that to use this in your unit
8983
// test. This should not be used in production code - call ToString() instead.

ui/gfx/geometry/matrix44.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ class COMPONENT_EXPORT(GEOMETRY_SKIA) Matrix44 {
6666
return AllTrue(Col(0) == other.Col(0)) && AllTrue(Col(1) == other.Col(1)) &&
6767
AllTrue(Col(2) == other.Col(2)) && AllTrue(Col(3) == other.Col(3));
6868
}
69-
bool operator!=(const Matrix44& other) const { return !(other == *this); }
70-
7169
// Returns true if the matrix is identity.
7270
bool IsIdentity() const { return *this == Matrix44(); }
7371

ui/gfx/geometry/point.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,13 @@ class COMPONENT_EXPORT(GEOMETRY) Point {
9595
// Returns a string representation of point.
9696
std::string ToString() const;
9797

98+
friend constexpr bool operator==(const Point&, const Point&) = default;
99+
98100
private:
99101
int x_;
100102
int y_;
101103
};
102104

103-
constexpr bool operator==(const Point& lhs, const Point& rhs) {
104-
return lhs.x() == rhs.x() && lhs.y() == rhs.y();
105-
}
106-
107-
inline bool operator!=(const Point& lhs, const Point& rhs) {
108-
return !(lhs == rhs);
109-
}
110-
111105
inline Point operator+(const Point& lhs, const Vector2d& rhs) {
112106
Point result(lhs);
113107
result += rhs;

ui/gfx/geometry/point3_f.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class COMPONENT_EXPORT(GEOMETRY) Point3F {
7676
// Returns a string representation of 3d point.
7777
std::string ToString() const;
7878

79+
friend bool operator==(const Point3F&, const Point3F&) = default;
80+
7981
private:
8082
float x_;
8183
float y_;
@@ -84,14 +86,6 @@ class COMPONENT_EXPORT(GEOMETRY) Point3F {
8486
// copy/assign are allowed.
8587
};
8688

87-
inline bool operator==(const Point3F& lhs, const Point3F& rhs) {
88-
return lhs.x() == rhs.x() && lhs.y() == rhs.y() && lhs.z() == rhs.z();
89-
}
90-
91-
inline bool operator!=(const Point3F& lhs, const Point3F& rhs) {
92-
return !(lhs == rhs);
93-
}
94-
9589
// Add a vector to a point, producing a new point offset by the vector.
9690
COMPONENT_EXPORT(GEOMETRY)
9791
Point3F operator+(const Point3F& lhs, const Vector3dF& rhs);

ui/gfx/geometry/point_f.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,13 @@ class COMPONENT_EXPORT(GEOMETRY) PointF {
112112
// Write a represtation of this object into a trace event argument.
113113
void WriteIntoTrace(perfetto::TracedValue) const;
114114

115+
friend constexpr bool operator==(const PointF&, const PointF&) = default;
116+
115117
private:
116118
float x_;
117119
float y_;
118120
};
119121

120-
constexpr bool operator==(const PointF& lhs, const PointF& rhs) {
121-
return lhs.x() == rhs.x() && lhs.y() == rhs.y();
122-
}
123-
124-
constexpr bool operator!=(const PointF& lhs, const PointF& rhs) {
125-
return !(lhs == rhs);
126-
}
127-
128122
constexpr PointF operator+(const PointF& lhs, const Vector2dF& rhs) {
129123
PointF result(lhs);
130124
result += rhs;

0 commit comments

Comments
 (0)