| 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 #include "ui/gfx/geometry/size.h" | 5 #include "ui/gfx/geometry/size.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #elif defined(OS_IOS) | 9 #elif defined(OS_IOS) |
| 10 #include <CoreGraphics/CoreGraphics.h> | 10 #include <CoreGraphics/CoreGraphics.h> |
| 11 #elif defined(OS_MACOSX) | 11 #elif defined(OS_MACOSX) |
| 12 #include <ApplicationServices/ApplicationServices.h> | 12 #include <ApplicationServices/ApplicationServices.h> |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "ui/gfx/geometry/size_conversions.h" |
| 16 | 17 |
| 17 namespace gfx { | 18 namespace gfx { |
| 18 | 19 |
| 19 #if defined(OS_MACOSX) | 20 #if defined(OS_MACOSX) |
| 20 Size::Size(const CGSize& s) | 21 Size::Size(const CGSize& s) |
| 21 : width_(s.width < 0 ? 0 : s.width), | 22 : width_(s.width < 0 ? 0 : s.width), |
| 22 height_(s.height < 0 ? 0 : s.height) { | 23 height_(s.height < 0 ? 0 : s.height) { |
| 23 } | 24 } |
| 24 | 25 |
| 25 Size& Size::operator=(const CGSize& s) { | 26 Size& Size::operator=(const CGSize& s) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 58 |
| 58 void Size::SetToMax(const Size& other) { | 59 void Size::SetToMax(const Size& other) { |
| 59 width_ = width() >= other.width() ? width() : other.width(); | 60 width_ = width() >= other.width() ? width() : other.width(); |
| 60 height_ = height() >= other.height() ? height() : other.height(); | 61 height_ = height() >= other.height() ? height() : other.height(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 std::string Size::ToString() const { | 64 std::string Size::ToString() const { |
| 64 return base::StringPrintf("%dx%d", width(), height()); | 65 return base::StringPrintf("%dx%d", width(), height()); |
| 65 } | 66 } |
| 66 | 67 |
| 68 Size ScaleToCeiledSize(const Size& size, float x_scale, float y_scale) { |
| 69 if (x_scale == 1.f && y_scale == 1.f) |
| 70 return size; |
| 71 return ToCeiledSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale)); |
| 72 } |
| 73 |
| 74 Size ScaleToCeiledSize(const Size& size, float scale) { |
| 75 if (scale == 1.f) |
| 76 return size; |
| 77 return ToCeiledSize(ScaleSize(gfx::SizeF(size), scale, scale)); |
| 78 } |
| 79 |
| 80 Size ScaleToFlooredSize(const Size& size, float x_scale, float y_scale) { |
| 81 if (x_scale == 1.f && y_scale == 1.f) |
| 82 return size; |
| 83 return ToFlooredSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale)); |
| 84 } |
| 85 |
| 86 Size ScaleToFlooredSize(const Size& size, float scale) { |
| 87 if (scale == 1.f) |
| 88 return size; |
| 89 return ToFlooredSize(ScaleSize(gfx::SizeF(size), scale, scale)); |
| 90 } |
| 91 |
| 92 Size ScaleToRoundedSize(const Size& size, float x_scale, float y_scale) { |
| 93 if (x_scale == 1.f && y_scale == 1.f) |
| 94 return size; |
| 95 return ToRoundedSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale)); |
| 96 } |
| 97 |
| 98 Size ScaleToRoundedSize(const Size& size, float scale) { |
| 99 if (scale == 1.f) |
| 100 return size; |
| 101 return ToRoundedSize(ScaleSize(gfx::SizeF(size), scale, scale)); |
| 102 } |
| 103 |
| 67 } // namespace gfx | 104 } // namespace gfx |
| OLD | NEW |