Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: ui/gfx/geometry/insets.h

Issue 2051343002: Make various gfx classes more amenable to use as compile-time constants. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Delete destructor Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/geometry/box_f.h ('k') | ui/gfx/geometry/insets.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_GFX_GEOMETRY_INSETS_H_ 5 #ifndef UI_GFX_GEOMETRY_INSETS_H_
6 #define UI_GFX_GEOMETRY_INSETS_H_ 6 #define UI_GFX_GEOMETRY_INSETS_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "ui/gfx/geometry/insets_f.h" 10 #include "ui/gfx/geometry/insets_f.h"
11 #include "ui/gfx/gfx_export.h" 11 #include "ui/gfx/gfx_export.h"
12 12
13 namespace gfx { 13 namespace gfx {
14 14
15 class GFX_EXPORT Insets { 15 class GFX_EXPORT Insets {
16 public: 16 public:
17 Insets(); 17 constexpr Insets() : top_(0), left_(0), bottom_(0), right_(0) {}
18 explicit Insets(int all); 18 constexpr explicit Insets(int all)
19 Insets(int vertical, int horizontal); 19 : top_(all), left_(all), bottom_(all), right_(all) {}
20 Insets(int top, int left, int bottom, int right); 20 constexpr Insets(int vertical, int horizontal)
21 : top_(vertical),
22 left_(horizontal),
23 bottom_(vertical),
24 right_(horizontal) {}
25 constexpr Insets(int top, int left, int bottom, int right)
26 : top_(top), left_(left), bottom_(bottom), right_(right) {}
21 27
22 ~Insets(); 28 constexpr int top() const { return top_; }
23 29 constexpr int left() const { return left_; }
24 int top() const { return top_; } 30 constexpr int bottom() const { return bottom_; }
25 int left() const { return left_; } 31 constexpr int right() const { return right_; }
26 int bottom() const { return bottom_; }
27 int right() const { return right_; }
28 32
29 // Returns the total width taken up by the insets, which is the sum of the 33 // Returns the total width taken up by the insets, which is the sum of the
30 // left and right insets. 34 // left and right insets.
31 int width() const { return left_ + right_; } 35 constexpr int width() const { return left_ + right_; }
32 36
33 // Returns the total height taken up by the insets, which is the sum of the 37 // Returns the total height taken up by the insets, which is the sum of the
34 // top and bottom insets. 38 // top and bottom insets.
35 int height() const { return top_ + bottom_; } 39 constexpr int height() const { return top_ + bottom_; }
36 40
37 // Returns true if the insets are empty. 41 // Returns true if the insets are empty.
38 bool IsEmpty() const { return width() == 0 && height() == 0; } 42 bool IsEmpty() const { return width() == 0 && height() == 0; }
39 43
40 void Set(int top, int left, int bottom, int right) { 44 void Set(int top, int left, int bottom, int right) {
41 top_ = top; 45 top_ = top;
42 left_ = left; 46 left_ = left;
43 bottom_ = bottom; 47 bottom_ = bottom;
44 right_ = right; 48 right_ = right;
45 } 49 }
46 50
47 bool operator==(const Insets& insets) const { 51 bool operator==(const Insets& insets) const {
48 return top_ == insets.top_ && left_ == insets.left_ && 52 return top_ == insets.top_ && left_ == insets.left_ &&
49 bottom_ == insets.bottom_ && right_ == insets.right_; 53 bottom_ == insets.bottom_ && right_ == insets.right_;
50 } 54 }
51 55
52 bool operator!=(const Insets& insets) const { 56 bool operator!=(const Insets& insets) const {
53 return !(*this == insets); 57 return !(*this == insets);
54 } 58 }
55 59
56 void operator+=(const Insets& insets) { 60 void operator+=(const Insets& insets) {
57 top_ += insets.top_; 61 top_ += insets.top_;
58 left_ += insets.left_; 62 left_ += insets.left_;
59 bottom_ += insets.bottom_; 63 bottom_ += insets.bottom_;
60 right_ += insets.right_; 64 right_ += insets.right_;
61 } 65 }
62 66
67 void operator-=(const Insets& insets) {
68 top_ -= insets.top_;
69 left_ -= insets.left_;
70 bottom_ -= insets.bottom_;
71 right_ -= insets.right_;
72 }
73
63 Insets operator-() const { 74 Insets operator-() const {
64 return Insets(-top_, -left_, -bottom_, -right_); 75 return Insets(-top_, -left_, -bottom_, -right_);
65 } 76 }
66 77
67 Insets Scale(float scale) const { 78 Insets Scale(float scale) const {
68 return Scale(scale, scale); 79 return Scale(scale, scale);
69 } 80 }
70 81
71 Insets Scale(float x_scale, float y_scale) const { 82 Insets Scale(float x_scale, float y_scale) const {
72 return Insets(static_cast<int>(top() * y_scale), 83 return Insets(static_cast<int>(top() * y_scale),
(...skipping 10 matching lines...) Expand all
83 // Returns a string representation of the insets. 94 // Returns a string representation of the insets.
84 std::string ToString() const; 95 std::string ToString() const;
85 96
86 private: 97 private:
87 int top_; 98 int top_;
88 int left_; 99 int left_;
89 int bottom_; 100 int bottom_;
90 int right_; 101 int right_;
91 }; 102 };
92 103
104 inline Insets operator+(Insets lhs, const Insets& rhs) {
105 lhs += rhs;
106 return lhs;
107 }
108
109 inline Insets operator-(Insets lhs, const Insets& rhs) {
110 lhs -= rhs;
111 return lhs;
112 }
113
93 } // namespace gfx 114 } // namespace gfx
94 115
95 #endif // UI_GFX_GEOMETRY_INSETS_H_ 116 #endif // UI_GFX_GEOMETRY_INSETS_H_
OLDNEW
« no previous file with comments | « ui/gfx/geometry/box_f.h ('k') | ui/gfx/geometry/insets.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698