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

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: 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
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 // TODO(danakj): Change these to checked_cast?
vmpstr 2015/09/23 23:04:25 Why?
danakj 2015/09/23 23:08:20 Well, I think that putting an int that is too big
28 : SizeF(static_cast<float>(size.width()),
29 static_cast<float>(size.height())) {}
30
25 float width() const { return width_; } 31 float width() const { return width_; }
26 float height() const { return height_; } 32 float height() const { return height_; }
27 33
28 void set_width(float width) { width_ = fmaxf(0, width); } 34 void set_width(float width) { width_ = fmaxf(0, width); }
29 void set_height(float height) { height_ = fmaxf(0, height); } 35 void set_height(float height) { height_ = fmaxf(0, height); }
30 36
31 float GetArea() const; 37 float GetArea() const;
32 38
33 void SetSize(float width, float height) { 39 void SetSize(float width, float height) {
34 set_width(width); 40 set_width(width);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 78 }
73 79
74 // This is declared here for use in gtest-based unit tests but is defined in 80 // 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. 81 // 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. 82 // This should not be used in production code - call ToString() instead.
77 void PrintTo(const SizeF& size, ::std::ostream* os); 83 void PrintTo(const SizeF& size, ::std::ostream* os);
78 84
79 } // namespace gfx 85 } // namespace gfx
80 86
81 #endif // UI_GFX_GEOMETRY_SIZE_F_H_ 87 #endif // UI_GFX_GEOMETRY_SIZE_F_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698