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
3 // found in the LICENSE file.
5 #ifndef UI_GFX_GEOMETRY_SIZE_H_
6 #define UI_GFX_GEOMETRY_SIZE_H_
11 #include "base/compiler_specific.h"
12 #include "ui/gfx/geometry/size_f.h"
13 #include "ui/gfx/gfx_export.h"
16 typedef struct tagSIZE SIZE
;
18 #include <CoreGraphics/CoreGraphics.h>
19 #elif defined(OS_MACOSX)
20 #include <ApplicationServices/ApplicationServices.h>
25 // A size has width and height values.
26 class GFX_EXPORT Size
{
28 Size() : width_(0), height_(0) {}
29 Size(int width
, int height
)
30 : width_(width
< 0 ? 0 : width
), height_(height
< 0 ? 0 : height
) {}
31 #if defined(OS_MACOSX)
32 explicit Size(const CGSize
& s
)
33 : width_(s
.width
< 0 ? 0 : s
.width
),
34 height_(s
.height
< 0 ? 0 : s
.height
) {}
39 #if defined(OS_MACOSX)
40 Size
& operator=(const CGSize
& s
);
45 #elif defined(OS_MACOSX)
46 CGSize
ToCGSize() const { return CGSizeMake(width(), height()); }
49 int width() const { return width_
; }
50 int height() const { return height_
; }
52 void set_width(int width
) { width_
= width
< 0 ? 0 : width
; }
53 void set_height(int height
) { height_
= height
< 0 ? 0 : height
; }
57 void SetSize(int width
, int height
) {
62 void Enlarge(int grow_width
, int grow_height
);
64 void SetToMin(const Size
& other
);
65 void SetToMax(const Size
& other
);
67 bool IsEmpty() const { return !width() || !height(); }
69 operator SizeF() const {
70 return SizeF(static_cast<float>(width()), static_cast<float>(height()));
73 std::string
ToString() const;
80 inline bool operator==(const Size
& lhs
, const Size
& rhs
) {
81 return lhs
.width() == rhs
.width() && lhs
.height() == rhs
.height();
84 inline bool operator!=(const Size
& lhs
, const Size
& rhs
) {
88 // This is declared here for use in gtest-based unit tests but is defined in
89 // the gfx_test_support target. Depend on that to use this in your unit test.
90 // This should not be used in production code - call ToString() instead.
91 void PrintTo(const Size
& size
, ::std::ostream
* os
);
95 #endif // UI_GFX_GEOMETRY_SIZE_H_