5#ifndef UI_GFX_GEOMETRY_INSETS_H_
6#define UI_GFX_GEOMETRY_INSETS_H_
28 constexpr Insets() : top_(0), left_(0), bottom_(0), right_(0) {}
32 bottom_(GetClampedValue(all, all)),
33 right_(GetClampedValue(all, all)) {}
34 constexpr explicit Insets(
int vertical,
int horizontal)
37 bottom_(GetClampedValue(vertical, vertical)),
38 right_(GetClampedValue(horizontal, horizontal)) {}
42 bottom_(GetClampedValue(top, bottom)),
45 constexpr int top()
const {
return top_; }
46 constexpr int left()
const {
return left_; }
47 constexpr int bottom()
const {
return bottom_; }
48 constexpr int right()
const {
return right_; }
52 constexpr int width()
const {
return left_ + right_; }
56 constexpr int height()
const {
return top_ + bottom_; }
67 bottom_ = GetClampedValue(top_, bottom_);
71 right_ = GetClampedValue(left_, right_);
73 void set_bottom(
int bottom) { bottom_ = GetClampedValue(top_, bottom); }
79 bottom_ = GetClampedValue(top_, bottom);
80 right_ = GetClampedValue(left_,
right);
84 return top_ == insets.top_ && left_ == insets.left_ &&
85 bottom_ == insets.bottom_ && right_ == insets.right_;
91 top_ = base::ClampAdd(top_, insets.top_);
92 left_ = base::ClampAdd(left_, insets.left_);
93 bottom_ = GetClampedValue(top_, base::ClampAdd(bottom_, insets.bottom_));
94 right_ = GetClampedValue(left_, base::ClampAdd(right_, insets.right_));
98 top_ = base::ClampSub(top_, insets.top_);
99 left_ = base::ClampSub(left_, insets.left_);
100 bottom_ = GetClampedValue(top_, base::ClampSub(bottom_, insets.bottom_));
101 right_ = GetClampedValue(left_, base::ClampSub(right_, insets.right_));
105 return Insets(-base::MakeClampedNum(top_), -base::MakeClampedNum(left_),
106 -base::MakeClampedNum(bottom_),
107 -base::MakeClampedNum(right_));
113 return Insets(
static_cast<int>(base::ClampMul(top(), y_scale)),
114 static_cast<int>(base::ClampMul(
left(), x_scale)),
115 static_cast<int>(base::ClampMul(bottom(), y_scale)),
116 static_cast<int>(base::ClampMul(
right(), x_scale)));
125 return InsetsF(
static_cast<float>(top()),
static_cast<float>(
left()),
126 static_cast<float>(bottom()),
static_cast<float>(
right()));
130 std::string ToString()
const;
140 static constexpr bool AddWouldOverflow(
int a,
int b) {
147 return a > 0 &&
b > 0 &&
148 static_cast<unsigned>(std::numeric_limits<int>::max() -
a) <
149 static_cast<unsigned>(
b);
153 static constexpr bool AddWouldUnderflow(
int a,
int b) {
154 return a < 0 && b < 0 && std::numeric_limits<int>::min() -
a >
b;
162 static constexpr int GetClampedValue(
int top_or_left,
int bottom_or_right) {
163 if (AddWouldOverflow(top_or_left, bottom_or_right)) {
164 return std::numeric_limits<int>::max() - top_or_left;
165 }
else if (AddWouldUnderflow(top_or_left, bottom_or_right)) {
168 return std::numeric_limits<int>::min() - top_or_left;
170 return bottom_or_right;
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
void Set(int top, int left, int bottom, int right)
constexpr int width() const
constexpr int right() const
void set_right(int right)
constexpr int bottom() const
Insets Scale(float scale) const
constexpr Insets(int vertical, int horizontal)
constexpr Insets(int top, int left, int bottom, int right)
Insets Scale(float x_scale, float y_scale) const
constexpr Size size() const
bool operator!=(const Insets &insets) const
void set_bottom(int bottom)
constexpr int top() const
constexpr Insets(int all)
constexpr int height() const
constexpr int left() const
void operator+=(const Insets &insets)
void operator-=(const Insets &insets)
bool operator==(const Insets &insets) const
Insets operator+(Insets lhs, const Insets &rhs)
Insets operator-(Insets lhs, const Insets &rhs)