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) { width_ = width; } | 35 void set_width(Type width); |
36 void set_height(Type height) { height_ = height; } | 36 void set_height(Type 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; | |
57 } | 50 } |
58 | 51 |
59 protected: | 52 protected: |
60 SizeBase(Type width, Type height) | 53 SizeBase(Type width, Type height); |
61 : width_(width), | |
62 height_(height) {} | |
63 | 54 |
64 // Destructor is intentionally made non virtual and protected. | 55 // Destructor is intentionally made non virtual and protected. |
65 // Do not make this public. | 56 // Do not make this public. |
66 ~SizeBase() {} | 57 ~SizeBase() {} |
67 | 58 |
68 private: | 59 private: |
69 Type width_; | 60 Type width_; |
70 Type height_; | 61 Type height_; |
71 }; | 62 }; |
72 | 63 |
73 } // namespace gfx | 64 } // namespace gfx |
74 | 65 |
75 #endif // UI_GFX_SIZE_BASE_H_ | 66 #endif // UI_GFX_SIZE_BASE_H_ |
OLD | NEW |