| OLD | NEW |
| 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_H_ | 5 #ifndef UI_GFX_GEOMETRY_SIZE_H_ |
| 6 #define UI_GFX_GEOMETRY_SIZE_H_ | 6 #define UI_GFX_GEOMETRY_SIZE_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/numerics/safe_math.h" | 12 #include "base/numerics/safe_math.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "ui/gfx/gfx_export.h" | 14 #include "ui/gfx/gfx_export.h" |
| 15 | 15 |
| 16 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
| 17 typedef struct tagSIZE SIZE; | 17 typedef struct tagSIZE SIZE; |
| 18 #elif defined(OS_MACOSX) | 18 #elif defined(OS_MACOSX) |
| 19 typedef struct CGSize CGSize; | 19 typedef struct CGSize CGSize; |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 namespace gfx { | 22 namespace gfx { |
| 23 | 23 |
| 24 // A size has width and height values. | 24 // A size has width and height values. |
| 25 class GFX_EXPORT Size { | 25 class GFX_EXPORT Size { |
| 26 public: | 26 public: |
| 27 Size() : width_(0), height_(0) {} | 27 constexpr Size() : width_(0), height_(0) {} |
| 28 Size(int width, int height) | 28 constexpr Size(int width, int height) |
| 29 : width_(width < 0 ? 0 : width), height_(height < 0 ? 0 : height) {} | 29 : width_(width < 0 ? 0 : width), height_(height < 0 ? 0 : height) {} |
| 30 #if defined(OS_MACOSX) | 30 #if defined(OS_MACOSX) |
| 31 explicit Size(const CGSize& s); | 31 explicit Size(const CGSize& s); |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 ~Size() {} | |
| 35 | |
| 36 #if defined(OS_MACOSX) | 34 #if defined(OS_MACOSX) |
| 37 Size& operator=(const CGSize& s); | 35 Size& operator=(const CGSize& s); |
| 38 #endif | 36 #endif |
| 39 | 37 |
| 40 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
| 41 SIZE ToSIZE() const; | 39 SIZE ToSIZE() const; |
| 42 #elif defined(OS_MACOSX) | 40 #elif defined(OS_MACOSX) |
| 43 CGSize ToCGSize() const; | 41 CGSize ToCGSize() const; |
| 44 #endif | 42 #endif |
| 45 | 43 |
| 46 int width() const { return width_; } | 44 constexpr int width() const { return width_; } |
| 47 int height() const { return height_; } | 45 constexpr int height() const { return height_; } |
| 48 | 46 |
| 49 void set_width(int width) { width_ = width < 0 ? 0 : width; } | 47 void set_width(int width) { width_ = width < 0 ? 0 : width; } |
| 50 void set_height(int height) { height_ = height < 0 ? 0 : height; } | 48 void set_height(int height) { height_ = height < 0 ? 0 : height; } |
| 51 | 49 |
| 52 // This call will CHECK if the area of this size would overflow int. | 50 // This call will CHECK if the area of this size would overflow int. |
| 53 int GetArea() const; | 51 int GetArea() const; |
| 54 // Returns a checked numeric representation of the area. | 52 // Returns a checked numeric representation of the area. |
| 55 base::CheckedNumeric<int> GetCheckedArea() const; | 53 base::CheckedNumeric<int> GetCheckedArea() const; |
| 56 | 54 |
| 57 void SetSize(int width, int height) { | 55 void SetSize(int width, int height) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 float y_scale); | 94 float y_scale); |
| 97 GFX_EXPORT Size ScaleToFlooredSize(const Size& size, float x_scale); | 95 GFX_EXPORT Size ScaleToFlooredSize(const Size& size, float x_scale); |
| 98 GFX_EXPORT Size ScaleToRoundedSize(const Size& size, | 96 GFX_EXPORT Size ScaleToRoundedSize(const Size& size, |
| 99 float x_scale, | 97 float x_scale, |
| 100 float y_scale); | 98 float y_scale); |
| 101 GFX_EXPORT Size ScaleToRoundedSize(const Size& size, float x_scale); | 99 GFX_EXPORT Size ScaleToRoundedSize(const Size& size, float x_scale); |
| 102 | 100 |
| 103 } // namespace gfx | 101 } // namespace gfx |
| 104 | 102 |
| 105 #endif // UI_GFX_GEOMETRY_SIZE_H_ | 103 #endif // UI_GFX_GEOMETRY_SIZE_H_ |
| OLD | NEW |