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 #include "ui/gfx/size_base.h" | 5 #include "ui/gfx/size_base.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 | 9 |
10 // This file provides the implementation for SizeBaese template and | 10 // This file provides the implementation for SizeBaese template and |
11 // used to instantiate the base class for Size and SizeF classes. | 11 // used to instantiate the base class for Size and SizeF classes. |
12 #if !defined(UI_IMPLEMENTATION) | 12 #if !defined(UI_IMPLEMENTATION) |
13 #error "This file is intended for UI implementation only" | 13 #error "This file is intended for UI implementation only" |
14 #endif | 14 #endif |
15 | 15 |
16 namespace gfx { | 16 namespace gfx { |
17 | 17 |
18 template<typename Class, typename Type> | 18 template<typename Class, typename Type> |
19 SizeBase<Class, Type>::SizeBase(Type width, Type height) { | 19 SizeBase<Class, Type>::SizeBase(Type width, Type height) |
| 20 : allow_negative_size_(false), |
| 21 crash_if_negative_(false) { |
20 set_width(width); | 22 set_width(width); |
21 set_height(height); | 23 set_height(height); |
22 } | 24 } |
23 | 25 |
24 template<typename Class, typename Type> | 26 template<typename Class, typename Type> |
25 SizeBase<Class, Type>::~SizeBase() {} | 27 SizeBase<Class, Type>::~SizeBase() {} |
26 | 28 |
27 template<typename Class, typename Type> | 29 template<typename Class, typename Type> |
28 void SizeBase<Class, Type>::set_width(Type width) { | 30 void SizeBase<Class, Type>::set_width(Type width) { |
29 if (width < 0) { | 31 if (!allow_negative_size_ && width < 0) { |
30 NOTREACHED() << "negative width:" << width; | 32 if (crash_if_negative_) |
| 33 NOTREACHED() << "negative width:" << width; |
31 width = 0; | 34 width = 0; |
32 } | 35 } |
33 width_ = width; | 36 width_ = width; |
34 } | 37 } |
35 | 38 |
36 template<typename Class, typename Type> | 39 template<typename Class, typename Type> |
37 void SizeBase<Class, Type>::set_height(Type height) { | 40 void SizeBase<Class, Type>::set_height(Type height) { |
38 if (height < 0) { | 41 if (!allow_negative_size_ && height < 0) { |
39 NOTREACHED() << "negative height:" << height; | 42 if (crash_if_negative_) |
| 43 NOTREACHED() << "negative height:" << height; |
40 height = 0; | 44 height = 0; |
41 } | 45 } |
42 height_ = height; | 46 height_ = height; |
43 } | 47 } |
44 | 48 |
45 } // namespace gfx | 49 } // namespace gfx |
OLD | NEW |