Home | History | Annotate | Download | only in gfx
      1 // Copyright (c) 2006-2008 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.
      4 
      5 #include "base/gfx/size.h"
      6 
      7 #if defined(OS_WIN)
      8 #include <windows.h>
      9 #elif defined(OS_MACOSX)
     10 #include <CoreGraphics/CGGeometry.h>
     11 #endif
     12 
     13 #include <iostream>
     14 
     15 #include "base/logging.h"
     16 
     17 namespace gfx {
     18 
     19 Size::Size(int width, int height) {
     20   set_width(width);
     21   set_height(height);
     22 }
     23 
     24 #if defined(OS_MACOSX)
     25 Size::Size(const CGSize& s) {
     26   set_width(s.width);
     27   set_height(s.height);
     28 }
     29 
     30 Size& Size::operator=(const CGSize& s) {
     31   set_width(s.width);
     32   set_height(s.height);
     33   return *this;
     34 }
     35 #endif
     36 
     37 #if defined(OS_WIN)
     38 SIZE Size::ToSIZE() const {
     39   SIZE s;
     40   s.cx = width_;
     41   s.cy = height_;
     42   return s;
     43 }
     44 #elif defined(OS_MACOSX)
     45 CGSize Size::ToCGSize() const {
     46   return CGSizeMake(width_, height_);
     47 }
     48 #endif
     49 
     50 void Size::set_width(int width) {
     51   if (width < 0) {
     52     NOTREACHED();
     53     width = 0;
     54   }
     55   width_ = width;
     56 }
     57 
     58 void Size::set_height(int height) {
     59   if (height < 0) {
     60     NOTREACHED();
     61     height = 0;
     62   }
     63   height_ = height;
     64 }
     65 
     66 }  // namespace gfx
     67 
     68 std::ostream& operator<<(std::ostream& out, const gfx::Size& s) {
     69   return out << s.width() << "x" << s.height();
     70 }
     71