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

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

Issue 10996037: Do not convert from RectF to Rect by flooring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing mac build. Created 8 years, 2 months 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
« no previous file with comments | « ui/gfx/size.cc ('k') | ui/gfx/size_base_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 23 matching lines...) Expand all
34 34
35 Class Scale(float scale) const WARN_UNUSED_RESULT { 35 Class Scale(float scale) const WARN_UNUSED_RESULT {
36 return Scale(scale, scale); 36 return Scale(scale, scale);
37 } 37 }
38 38
39 Class Scale(float x_scale, float y_scale) const WARN_UNUSED_RESULT { 39 Class Scale(float x_scale, float y_scale) const WARN_UNUSED_RESULT {
40 return Class(static_cast<Type>(width_ * x_scale), 40 return Class(static_cast<Type>(width_ * x_scale),
41 static_cast<Type>(height_ * y_scale)); 41 static_cast<Type>(height_ * y_scale));
42 } 42 }
43 43
44 void set_width(Type width); 44 void set_width(Type width) { width_ = width; }
45 void set_height(Type height); 45 void set_height(Type height) { height_ = height; }
46 46
47 bool operator==(const Class& s) const { 47 bool operator==(const Class& s) const {
48 return width_ == s.width_ && height_ == s.height_; 48 return width_ == s.width_ && height_ == s.height_;
49 } 49 }
50 50
51 bool operator!=(const Class& s) const { 51 bool operator!=(const Class& s) const {
52 return !(*this == s); 52 return !(*this == s);
53 } 53 }
54 54
55 bool IsEmpty() const { 55 bool IsEmpty() const {
56 // Size doesn't allow negative dimensions, so testing for 0 is enough. 56 return (width_ <= 0) || (height_ <= 0);
57 return (width_ == 0) || (height_ == 0); 57 }
58
59 void ClampToNonNegative() {
60 if (width_ < 0)
61 width_ = 0;
62 if (height_ < 0)
63 height_ = 0;
58 } 64 }
59 65
60 protected: 66 protected:
61 SizeBase(Type width, Type height); 67 SizeBase(Type width, Type height)
68 : width_(width),
69 height_(height) {}
70
62 // Destructor is intentionally made non virtual and protected. 71 // Destructor is intentionally made non virtual and protected.
63 // Do not make this public. 72 // Do not make this public.
64 ~SizeBase(); 73 ~SizeBase() {}
65 74
66 private: 75 private:
67 Type width_; 76 Type width_;
68 Type height_; 77 Type height_;
69 }; 78 };
70 79
71 } // namespace gfx 80 } // namespace gfx
72 81
73 #endif // UI_GFX_SIZE_BASE_H_ 82 #endif // UI_GFX_SIZE_BASE_H_
OLDNEW
« no previous file with comments | « ui/gfx/size.cc ('k') | ui/gfx/size_base_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698