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

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

Issue 1357423009: gfx: Make conversions from Size to SizeF be explicit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sizefconvert-gfx: . Created 5 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/size.cc ('k') | ui/gfx/geometry/size_unittest.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_F_H_ 5 #ifndef UI_GFX_GEOMETRY_SIZE_F_H_
6 #define UI_GFX_GEOMETRY_SIZE_F_H_ 6 #define UI_GFX_GEOMETRY_SIZE_F_H_
7 7
8 #include <cmath> 8 #include <cmath>
9 #include <iosfwd> 9 #include <iosfwd>
10 #include <string> 10 #include <string>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "ui/gfx/geometry/size.h"
13 #include "ui/gfx/gfx_export.h" 14 #include "ui/gfx/gfx_export.h"
14 15
15 namespace gfx { 16 namespace gfx {
16 17
17 // A floating version of gfx::Size. 18 // A floating version of gfx::Size.
18 class GFX_EXPORT SizeF { 19 class GFX_EXPORT SizeF {
19 public: 20 public:
20 SizeF() : width_(0.f), height_(0.f) {} 21 SizeF() : width_(0.f), height_(0.f) {}
21 SizeF(float width, float height) 22 SizeF(float width, float height)
22 : width_(fmaxf(0, width)), height_(fmaxf(0, height)) {} 23 : width_(fmaxf(0, width)), height_(fmaxf(0, height)) {}
23 ~SizeF() {} 24 ~SizeF() {}
24 25
26 explicit SizeF(const Size& size)
27 : SizeF(static_cast<float>(size.width()),
28 static_cast<float>(size.height())) {}
29
25 float width() const { return width_; } 30 float width() const { return width_; }
26 float height() const { return height_; } 31 float height() const { return height_; }
27 32
28 void set_width(float width) { width_ = fmaxf(0, width); } 33 void set_width(float width) { width_ = fmaxf(0, width); }
29 void set_height(float height) { height_ = fmaxf(0, height); } 34 void set_height(float height) { height_ = fmaxf(0, height); }
30 35
31 float GetArea() const; 36 float GetArea() const;
32 37
33 void SetSize(float width, float height) { 38 void SetSize(float width, float height) {
34 set_width(width); 39 set_width(width);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 77 }
73 78
74 // This is declared here for use in gtest-based unit tests but is defined in 79 // 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. 80 // 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. 81 // This should not be used in production code - call ToString() instead.
77 void PrintTo(const SizeF& size, ::std::ostream* os); 82 void PrintTo(const SizeF& size, ::std::ostream* os);
78 83
79 } // namespace gfx 84 } // namespace gfx
80 85
81 #endif // UI_GFX_GEOMETRY_SIZE_F_H_ 86 #endif // UI_GFX_GEOMETRY_SIZE_F_H_
OLDNEW
« no previous file with comments | « ui/gfx/geometry/size.cc ('k') | ui/gfx/geometry/size_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698