Fix search results being clipped in app list.
[chromium-blink-merge.git] / ui / gfx / geometry / size_f.h
blob66080f09c12d660c78bcab789e5e6caaeb38597e
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_F_H_
6 #define UI_GFX_GEOMETRY_SIZE_F_H_
8 #include <cmath>
9 #include <iosfwd>
10 #include <string>
12 #include "base/compiler_specific.h"
13 #include "ui/gfx/gfx_export.h"
15 namespace gfx {
17 // A floating version of gfx::Size.
18 class GFX_EXPORT SizeF {
19 public:
20 SizeF() : width_(0.f), height_(0.f) {}
21 SizeF(float width, float height)
22 : width_(fmaxf(0, width)), height_(fmaxf(0, height)) {}
23 ~SizeF() {}
25 float width() const { return width_; }
26 float height() const { return height_; }
28 void set_width(float width) { width_ = fmaxf(0, width); }
29 void set_height(float height) { height_ = fmaxf(0, height); }
31 float GetArea() const;
33 void SetSize(float width, float height) {
34 set_width(width);
35 set_height(height);
38 void Enlarge(float grow_width, float grow_height);
40 void SetToMin(const SizeF& other);
41 void SetToMax(const SizeF& other);
43 bool IsEmpty() const { return !width() || !height(); }
45 void Scale(float scale) {
46 Scale(scale, scale);
49 void Scale(float x_scale, float y_scale) {
50 SetSize(width() * x_scale, height() * y_scale);
53 std::string ToString() const;
55 private:
56 float width_;
57 float height_;
60 inline bool operator==(const SizeF& lhs, const SizeF& rhs) {
61 return lhs.width() == rhs.width() && lhs.height() == rhs.height();
64 inline bool operator!=(const SizeF& lhs, const SizeF& rhs) {
65 return !(lhs == rhs);
68 GFX_EXPORT SizeF ScaleSize(const SizeF& p, float x_scale, float y_scale);
70 inline SizeF ScaleSize(const SizeF& p, float scale) {
71 return ScaleSize(p, scale, scale);
74 // This is declared here for use in gtest-based unit tests but is defined in
75 // the gfx_test_support target. Depend on that to use this in your unit test.
76 // This should not be used in production code - call ToString() instead.
77 void PrintTo(const SizeF& size, ::std::ostream* os);
79 } // namespace gfx
81 #endif // UI_GFX_GEOMETRY_SIZE_F_H_