Update about_credits.html by re-running license.py
[chromium-blink-merge.git] / gfx / size.h
blob99896f838a5027aacd00f14cfdbd7dd99b8e3eb3
1 // Copyright (c) 2010 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 #ifndef GFX_SIZE_H_
6 #define GFX_SIZE_H_
7 #pragma once
9 #include "build/build_config.h"
11 #include <iosfwd>
13 #if defined(OS_WIN)
14 typedef struct tagSIZE SIZE;
15 #elif defined(OS_MACOSX)
16 #include <ApplicationServices/ApplicationServices.h>
17 #endif
19 namespace gfx {
21 // A size has width and height values.
22 class Size {
23 public:
24 Size() : width_(0), height_(0) {}
25 Size(int width, int height);
26 #if defined(OS_MACOSX)
27 explicit Size(const CGSize& s);
28 #endif
30 ~Size() {}
32 #if defined(OS_MACOSX)
33 Size& operator=(const CGSize& s);
34 #endif
36 int width() const { return width_; }
37 int height() const { return height_; }
39 int GetArea() const { return width_ * height_; }
41 void SetSize(int width, int height) {
42 set_width(width);
43 set_height(height);
46 void Enlarge(int width, int height) {
47 set_width(width_ + width);
48 set_height(height_ + height);
51 void set_width(int width);
52 void set_height(int height);
54 bool operator==(const Size& s) const {
55 return width_ == s.width_ && height_ == s.height_;
58 bool operator!=(const Size& s) const {
59 return !(*this == s);
62 bool IsEmpty() const {
63 // Size doesn't allow negative dimensions, so testing for 0 is enough.
64 return (width_ == 0) || (height_ == 0);
67 #if defined(OS_WIN)
68 SIZE ToSIZE() const;
69 #elif defined(OS_MACOSX)
70 CGSize ToCGSize() const;
71 #endif
73 private:
74 int width_;
75 int height_;
78 std::ostream& operator<<(std::ostream& out, const gfx::Size& s);
80 } // namespace gfx
82 #endif // GFX_SIZE_H_