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