| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 GFX_SIZE_H_ | 5 #ifndef GFX_SIZE_H_ |
| 6 #define GFX_SIZE_H_ | 6 #define GFX_SIZE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "build/build_config.h" | 9 #include "ui/gfx/size.h" |
| 10 | 10 // TODO(sail): remove this file once all includes have been updated. |
| 11 #include <iosfwd> | |
| 12 | |
| 13 #if defined(OS_WIN) | |
| 14 typedef struct tagSIZE SIZE; | |
| 15 #elif defined(OS_MACOSX) | |
| 16 #include <ApplicationServices/ApplicationServices.h> | |
| 17 #endif | |
| 18 | |
| 19 namespace gfx { | |
| 20 | |
| 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 | |
| 29 | |
| 30 ~Size() {} | |
| 31 | |
| 32 #if defined(OS_MACOSX) | |
| 33 Size& operator=(const CGSize& s); | |
| 34 #endif | |
| 35 | |
| 36 int width() const { return width_; } | |
| 37 int height() const { return height_; } | |
| 38 | |
| 39 int GetArea() const { return width_ * height_; } | |
| 40 | |
| 41 void SetSize(int width, int height) { | |
| 42 set_width(width); | |
| 43 set_height(height); | |
| 44 } | |
| 45 | |
| 46 void Enlarge(int width, int height) { | |
| 47 set_width(width_ + width); | |
| 48 set_height(height_ + height); | |
| 49 } | |
| 50 | |
| 51 void set_width(int width); | |
| 52 void set_height(int height); | |
| 53 | |
| 54 bool operator==(const Size& s) const { | |
| 55 return width_ == s.width_ && height_ == s.height_; | |
| 56 } | |
| 57 | |
| 58 bool operator!=(const Size& s) const { | |
| 59 return !(*this == s); | |
| 60 } | |
| 61 | |
| 62 bool IsEmpty() const { | |
| 63 // Size doesn't allow negative dimensions, so testing for 0 is enough. | |
| 64 return (width_ == 0) || (height_ == 0); | |
| 65 } | |
| 66 | |
| 67 #if defined(OS_WIN) | |
| 68 SIZE ToSIZE() const; | |
| 69 #elif defined(OS_MACOSX) | |
| 70 CGSize ToCGSize() const; | |
| 71 #endif | |
| 72 | |
| 73 private: | |
| 74 int width_; | |
| 75 int height_; | |
| 76 }; | |
| 77 | |
| 78 std::ostream& operator<<(std::ostream& out, const gfx::Size& s); | |
| 79 | |
| 80 } // namespace gfx | |
| 81 | 11 |
| 82 #endif // GFX_SIZE_H_ | 12 #endif // GFX_SIZE_H_ |
| OLD | NEW |