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

Side by Side Diff: ui/gfx/geometry/size.h

Issue 662273002: gfx:: De-templatize Size and SizeF. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: inlines-size: . Created 6 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
« no previous file with comments | « ui/gfx/geometry/BUILD.gn ('k') | ui/gfx/geometry/size.cc » ('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_GEOMETRY_SIZE_H_ 5 #ifndef UI_GFX_GEOMETRY_SIZE_H_
6 #define UI_GFX_GEOMETRY_SIZE_H_ 6 #define UI_GFX_GEOMETRY_SIZE_H_
7 7
8 #include <iosfwd> 8 #include <iosfwd>
9 #include <string> 9 #include <string>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "ui/gfx/geometry/size_base.h"
13 #include "ui/gfx/geometry/size_f.h" 12 #include "ui/gfx/geometry/size_f.h"
14 #include "ui/gfx/gfx_export.h" 13 #include "ui/gfx/gfx_export.h"
15 14
16 #if defined(OS_WIN) 15 #if defined(OS_WIN)
17 typedef struct tagSIZE SIZE; 16 typedef struct tagSIZE SIZE;
18 #elif defined(OS_IOS) 17 #elif defined(OS_IOS)
19 #include <CoreGraphics/CoreGraphics.h> 18 #include <CoreGraphics/CoreGraphics.h>
20 #elif defined(OS_MACOSX) 19 #elif defined(OS_MACOSX)
21 #include <ApplicationServices/ApplicationServices.h> 20 #include <ApplicationServices/ApplicationServices.h>
22 #endif 21 #endif
23 22
24 namespace gfx { 23 namespace gfx {
25 24
26 // A size has width and height values. 25 // A size has width and height values.
27 class GFX_EXPORT Size : public SizeBase<Size, int> { 26 class GFX_EXPORT Size {
28 public: 27 public:
29 Size() : SizeBase<Size, int>(0, 0) {} 28 Size() : width_(0), height_(0) {}
30 Size(int width, int height) : SizeBase<Size, int>(width, height) {} 29 Size(int width, int height)
30 : width_(width < 0 ? 0 : width), height_(height < 0 ? 0 : height) {}
31 #if defined(OS_MACOSX) 31 #if defined(OS_MACOSX)
32 explicit Size(const CGSize& s); 32 explicit Size(const CGSize& s)
33 : width_(s.width < 0 ? 0 : s.width),
34 height_(s.height < 0 ? 0 : s.height) {}
33 #endif 35 #endif
34 36
35 ~Size() {} 37 ~Size() {}
36 38
37 #if defined(OS_MACOSX) 39 #if defined(OS_MACOSX)
38 Size& operator=(const CGSize& s); 40 Size& operator=(const CGSize& s);
39 #endif 41 #endif
40 42
41 #if defined(OS_WIN) 43 #if defined(OS_WIN)
42 SIZE ToSIZE() const; 44 SIZE ToSIZE() const;
43 #elif defined(OS_MACOSX) 45 #elif defined(OS_MACOSX)
44 CGSize ToCGSize() const; 46 CGSize ToCGSize() const { return CGSizeMake(width(), height()); }
45 #endif 47 #endif
46 48
49 int width() const { return width_; }
50 int height() const { return height_; }
51
52 void set_width(int width) { width_ = width < 0 ? 0 : width; }
53 void set_height(int height) { height_ = height < 0 ? 0 : height; }
54
55 int GetArea() const;
56
57 void SetSize(int width, int height) {
58 set_width(width);
59 set_height(height);
60 }
61
62 void Enlarge(int grow_width, int grow_height);
63
64 void SetToMin(const Size& other);
65 void SetToMax(const Size& other);
66
67 bool IsEmpty() const { return !width() || !height(); }
68
47 operator SizeF() const { 69 operator SizeF() const {
48 return SizeF(width(), height()); 70 return SizeF(width(), height());
49 } 71 }
50 72
51 std::string ToString() const; 73 std::string ToString() const;
74
75 private:
76 int width_;
77 int height_;
52 }; 78 };
53 79
54 inline bool operator==(const Size& lhs, const Size& rhs) { 80 inline bool operator==(const Size& lhs, const Size& rhs) {
55 return lhs.width() == rhs.width() && lhs.height() == rhs.height(); 81 return lhs.width() == rhs.width() && lhs.height() == rhs.height();
56 } 82 }
57 83
58 inline bool operator!=(const Size& lhs, const Size& rhs) { 84 inline bool operator!=(const Size& lhs, const Size& rhs) {
59 return !(lhs == rhs); 85 return !(lhs == rhs);
60 } 86 }
61 87
62 #if !defined(COMPILER_MSVC) && !defined(__native_client__)
63 extern template class SizeBase<Size, int>;
64 #endif
65
66 // This is declared here for use in gtest-based unit tests but is defined in 88 // This is declared here for use in gtest-based unit tests but is defined in
67 // the gfx_test_support target. Depend on that to use this in your unit test. 89 // the gfx_test_support target. Depend on that to use this in your unit test.
68 // This should not be used in production code - call ToString() instead. 90 // This should not be used in production code - call ToString() instead.
69 void PrintTo(const Size& size, ::std::ostream* os); 91 void PrintTo(const Size& size, ::std::ostream* os);
70 92
71 } // namespace gfx 93 } // namespace gfx
72 94
73 #endif // UI_GFX_GEOMETRY_SIZE_H_ 95 #endif // UI_GFX_GEOMETRY_SIZE_H_
OLDNEW
« no previous file with comments | « ui/gfx/geometry/BUILD.gn ('k') | ui/gfx/geometry/size.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698