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

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

Issue 11361186: ui: Add methods to clamp Sizes, Points, and Vectors from above or below. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: BottomRight 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 17 matching lines...) Expand all
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; }
36 void set_height(Type height) { height_ = height; } 36 void set_height(Type height) { height_ = height; }
37 37
38 void ClampFromAbove(const Class& other) {
sky 2012/11/09 18:23:12 The name here is even more confusing. Sizes genera
danakj 2012/11/09 18:24:25 Oh, hm. I hadn't thought of it in terms of directi
39 width_ = width_ <= other.width_ ? width_ : other.width_;
40 height_ = height_ <= other.height_ ? height_ : other.height_;
41 }
42
43 void ClampFromBelow(const Class& other) {
44 width_ = width_ >= other.width_ ? width_ : other.width_;
45 height_ = height_ >= other.height_ ? height_ : other.height_;
46 }
47
38 bool IsEmpty() const { 48 bool IsEmpty() const {
39 return (width_ <= 0) || (height_ <= 0); 49 return (width_ <= 0) || (height_ <= 0);
40 } 50 }
41 51
42 void ClampToNonNegative() { 52 void ClampToNonNegative() {
43 if (width_ < 0) 53 if (width_ < 0)
44 width_ = 0; 54 width_ = 0;
45 if (height_ < 0) 55 if (height_ < 0)
46 height_ = 0; 56 height_ = 0;
47 } 57 }
48 58
49 protected: 59 protected:
50 SizeBase(Type width, Type height) 60 SizeBase(Type width, Type height)
51 : width_(width), 61 : width_(width),
52 height_(height) {} 62 height_(height) {}
53 63
54 // Destructor is intentionally made non virtual and protected. 64 // Destructor is intentionally made non virtual and protected.
55 // Do not make this public. 65 // Do not make this public.
56 ~SizeBase() {} 66 ~SizeBase() {}
57 67
58 private: 68 private:
59 Type width_; 69 Type width_;
60 Type height_; 70 Type height_;
61 }; 71 };
62 72
63 } // namespace gfx 73 } // namespace gfx
64 74
65 #endif // UI_GFX_SIZE_BASE_H_ 75 #endif // UI_GFX_SIZE_BASE_H_
OLDNEW
« ui/gfx/point_base.h ('K') | « ui/gfx/point_unittest.cc ('k') | ui/gfx/size_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698