1/* 2 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31#ifndef WebSize_h 32#define WebSize_h 33 34#include "WebCommon.h" 35 36#if INSIDE_BLINK 37#include "platform/geometry/IntSize.h" 38#else 39#include <algorithm> 40#include <cmath> 41#include <ui/gfx/geometry/size.h> 42#include <ui/gfx/geometry/vector2d.h> 43#endif 44 45namespace blink { 46 47struct WebSize { 48 int width; 49 int height; 50 51 bool isEmpty() const { return width <= 0 || height <= 0; } 52 53 WebSize() 54 : width(0) 55 , height(0) 56 { 57 } 58 59 WebSize(int width, int height) 60 : width(width) 61 , height(height) 62 { 63 } 64 65#if INSIDE_BLINK 66 WebSize(const IntSize& s) 67 : width(s.width()) 68 , height(s.height()) 69 { 70 } 71 72 WebSize& operator=(const IntSize& s) 73 { 74 width = s.width(); 75 height = s.height(); 76 return *this; 77 } 78 79 operator IntSize() const 80 { 81 return IntSize(width, height); 82 } 83#else 84 WebSize(const gfx::Size& s) 85 : width(s.width()) 86 , height(s.height()) 87 { 88 } 89 90 WebSize(const gfx::Vector2d& v) 91 : width(v.x()) 92 , height(v.y()) 93 { 94 } 95 96 WebSize& operator=(const gfx::Size& s) 97 { 98 width = s.width(); 99 height = s.height(); 100 return *this; 101 } 102 103 WebSize& operator=(const gfx::Vector2d& v) 104 { 105 width = v.x(); 106 height = v.y(); 107 return *this; 108 } 109 110 operator gfx::Size() const 111 { 112 return gfx::Size(std::max(0, width), std::max(0, height)); 113 } 114 115 operator gfx::Vector2d() const 116 { 117 return gfx::Vector2d(width, height); 118 } 119#endif 120}; 121 122inline bool operator==(const WebSize& a, const WebSize& b) 123{ 124 return a.width == b.width && a.height == b.height; 125} 126 127inline bool operator!=(const WebSize& a, const WebSize& b) 128{ 129 return !(a == b); 130} 131 132} // namespace blink 133 134#endif 135