Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1014)

Side by Side Diff: ui/gfx/size_base.h

Issue 11365160: ui: Remove gfx::Size::ClampToNonNegative, prevent negative sizes always. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add test Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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_
OLDNEW
« ui/gfx/rect_f.h ('K') | « ui/gfx/rect_f.h ('k') | ui/gfx/size_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698