Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / gfx / geometry / size.cc
blob03aa69660190df7f7eb10b65cdf625bd1c7df8e6
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"
7 #if defined(OS_WIN)
8 #include <windows.h>
9 #elif defined(OS_IOS)
10 #include <CoreGraphics/CoreGraphics.h>
11 #elif defined(OS_MACOSX)
12 #include <ApplicationServices/ApplicationServices.h>
13 #endif
15 #include "base/strings/stringprintf.h"
17 namespace gfx {
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) {
26 set_width(s.width);
27 set_height(s.height);
28 return *this;
30 #endif
32 #if defined(OS_WIN)
33 SIZE Size::ToSIZE() const {
34 SIZE s;
35 s.cx = width();
36 s.cy = height();
37 return s;
39 #elif defined(OS_MACOSX)
40 CGSize Size::ToCGSize() const {
41 return CGSizeMake(width(), height());
43 #endif
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());
67 } // namespace gfx