Fix search results being clipped in app list.
[chromium-blink-merge.git] / ui / gfx / geometry / size.h
blob74857c521e27d18c5ea61f57798958f4a46f1309
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_
8 #include <iosfwd>
9 #include <string>
11 #include "base/compiler_specific.h"
12 #include "ui/gfx/geometry/size_f.h"
13 #include "ui/gfx/gfx_export.h"
15 #if defined(OS_WIN)
16 typedef struct tagSIZE SIZE;
17 #elif defined(OS_IOS)
18 #include <CoreGraphics/CoreGraphics.h>
19 #elif defined(OS_MACOSX)
20 #include <ApplicationServices/ApplicationServices.h>
21 #endif
23 namespace gfx {
25 // A size has width and height values.
26 class GFX_EXPORT Size {
27 public:
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) {}
35 #endif
37 ~Size() {}
39 #if defined(OS_MACOSX)
40 Size& operator=(const CGSize& s);
41 #endif
43 #if defined(OS_WIN)
44 SIZE ToSIZE() const;
45 #elif defined(OS_MACOSX)
46 CGSize ToCGSize() const { return CGSizeMake(width(), height()); }
47 #endif
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; }
55 int GetArea() const;
57 void SetSize(int width, int height) {
58 set_width(width);
59 set_height(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;
75 private:
76 int width_;
77 int height_;
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) {
85 return !(lhs == 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);
93 } // namespace gfx
95 #endif // UI_GFX_GEOMETRY_SIZE_H_