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 #include "ui/gfx/geometry/size.h"
10 #include <CoreGraphics/CoreGraphics.h>
11 #elif defined(OS_MACOSX)
12 #include <ApplicationServices/ApplicationServices.h>
15 #include "base/strings/stringprintf.h"
19 #if defined(OS_MACOSX)
20 Size::Size(const CGSize
& s
)
21 : width_(s
.width
< 0 ? 0 : s
.width
),
22 height_(s
.height
< 0 ? 0 : s
.height
) {
25 Size
& Size::operator=(const CGSize
& s
) {
33 SIZE
Size::ToSIZE() const {
39 #elif defined(OS_MACOSX)
40 CGSize
Size::ToCGSize() const {
41 return CGSizeMake(width(), height());
45 int Size::GetArea() const {
46 return width() * height();
49 void Size::Enlarge(int grow_width
, int grow_height
) {
50 SetSize(width() + grow_width
, height() + grow_height
);
53 void Size::SetToMin(const Size
& other
) {
54 width_
= width() <= other
.width() ? width() : other
.width();
55 height_
= height() <= other
.height() ? height() : other
.height();
58 void Size::SetToMax(const Size
& other
) {
59 width_
= width() >= other
.width() ? width() : other
.width();
60 height_
= height() >= other
.height() ? height() : other
.height();
63 std::string
Size::ToString() const {
64 return base::StringPrintf("%dx%d", width(), height());