OLD | NEW |
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_SIZE_BASE_H_ | 5 #ifndef UI_GFX_SIZE_BASE_H_ |
6 #define UI_GFX_SIZE_BASE_H_ | 6 #define UI_GFX_SIZE_BASE_H_ |
7 | 7 |
8 #include "ui/base/ui_export.h" | 8 #include "ui/base/ui_export.h" |
9 | 9 |
10 namespace gfx { | 10 namespace gfx { |
(...skipping 10 matching lines...) Expand all Loading... |
21 void SetSize(Type width, Type height) { | 21 void SetSize(Type width, Type height) { |
22 set_width(width); | 22 set_width(width); |
23 set_height(height); | 23 set_height(height); |
24 } | 24 } |
25 | 25 |
26 void Enlarge(Type width, Type height) { | 26 void Enlarge(Type width, Type height) { |
27 set_width(width_ + width); | 27 set_width(width_ + width); |
28 set_height(height_ + height); | 28 set_height(height_ + height); |
29 } | 29 } |
30 | 30 |
31 void set_width(Type width); | 31 void set_width(Type width) { width_ = width; } |
32 void set_height(Type height); | 32 void set_height(Type height) { height_ = height; } |
33 | 33 |
34 void ClampToMax(const Class& max) { | 34 void ClampToMax(const Class& max) { |
35 width_ = width_ <= max.width_ ? width_ : max.width_; | 35 width_ = width_ <= max.width_ ? width_ : max.width_; |
36 height_ = height_ <= max.height_ ? height_ : max.height_; | 36 height_ = height_ <= max.height_ ? height_ : max.height_; |
37 } | 37 } |
38 | 38 |
39 void ClampToMin(const Class& min) { | 39 void ClampToMin(const Class& min) { |
40 width_ = width_ >= min.width_ ? width_ : min.width_; | 40 width_ = width_ >= min.width_ ? width_ : min.width_; |
41 height_ = height_ >= min.height_ ? height_ : min.height_; | 41 height_ = height_ >= min.height_ ? height_ : min.height_; |
42 } | 42 } |
43 | 43 |
44 bool IsEmpty() const { | 44 bool IsEmpty() const { |
45 return (width_ == 0) || (height_ == 0); | 45 return (width_ <= 0) || (height_ <= 0); |
| 46 } |
| 47 |
| 48 void ClampToNonNegative() { |
| 49 if (width_ < 0) |
| 50 width_ = 0; |
| 51 if (height_ < 0) |
| 52 height_ = 0; |
46 } | 53 } |
47 | 54 |
48 protected: | 55 protected: |
49 SizeBase(Type width, Type height); | 56 SizeBase(Type width, Type height) |
| 57 : width_(width), |
| 58 height_(height) {} |
50 | 59 |
51 // Destructor is intentionally made non virtual and protected. | 60 // Destructor is intentionally made non virtual and protected. |
52 // Do not make this public. | 61 // Do not make this public. |
53 ~SizeBase() {} | 62 ~SizeBase() {} |
54 | 63 |
55 private: | 64 private: |
56 Type width_; | 65 Type width_; |
57 Type height_; | 66 Type height_; |
58 }; | 67 }; |
59 | 68 |
60 } // namespace gfx | 69 } // namespace gfx |
61 | 70 |
62 #endif // UI_GFX_SIZE_BASE_H_ | 71 #endif // UI_GFX_SIZE_BASE_H_ |
OLD | NEW |