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) { width_ = width < 0 ? 0 : width; } |
sky
2012/11/09 17:03:55
Where we previously doing this? I thought previous
danakj
2012/11/09 17:06:57
There were DCHECKs previously.
| |
36 void set_height(Type height) { height_ = height; } | 36 void set_height(Type height) { height_ = height < 0 ? 0 : height; } |
37 | 37 |
38 bool IsEmpty() const { | 38 bool IsEmpty() const { |
39 return (width_ <= 0) || (height_ <= 0); | 39 return (width_ == 0) || (height_ == 0); |
40 } | |
41 | |
42 void ClampToNonNegative() { | |
43 if (width_ < 0) | |
44 width_ = 0; | |
45 if (height_ < 0) | |
46 height_ = 0; | |
47 } | 40 } |
48 | 41 |
49 protected: | 42 protected: |
50 SizeBase(Type width, Type height) | 43 SizeBase(Type width, Type height) |
51 : width_(width), | 44 : width_(width < 0 ? 0 : width), |
52 height_(height) {} | 45 height_(height < 0 ? 0 : height) {} |
53 | 46 |
54 // Destructor is intentionally made non virtual and protected. | 47 // Destructor is intentionally made non virtual and protected. |
55 // Do not make this public. | 48 // Do not make this public. |
56 ~SizeBase() {} | 49 ~SizeBase() {} |
57 | 50 |
58 private: | 51 private: |
59 Type width_; | 52 Type width_; |
60 Type height_; | 53 Type height_; |
61 }; | 54 }; |
62 | 55 |
63 } // namespace gfx | 56 } // namespace gfx |
64 | 57 |
65 #endif // UI_GFX_SIZE_BASE_H_ | 58 #endif // UI_GFX_SIZE_BASE_H_ |
OLD | NEW |