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 WebRect_h 32 #define WebRect_h 33 34 #include "WebCommon.h" 35 36 #if WEBKIT_IMPLEMENTATION 37 #include "core/platform/graphics/IntRect.h" 38 #else 39 #include <cmath> 40 #include <ui/gfx/rect.h> 41 #endif 42 43 namespace WebKit { 44 45 struct WebRect { 46 int x; 47 int y; 48 int width; 49 int height; 50 51 bool isEmpty() const { return width <= 0 || height <= 0; } 52 53 WebRect() 54 : x(0) 55 , y(0) 56 , width(0) 57 , height(0) 58 { 59 } 60 61 WebRect(int x, int y, int width, int height) 62 : x(x) 63 , y(y) 64 , width(width) 65 , height(height) 66 { 67 } 68 69 #if WEBKIT_IMPLEMENTATION 70 WebRect(const WebCore::IntRect& r) 71 : x(r.x()) 72 , y(r.y()) 73 , width(r.width()) 74 , height(r.height()) 75 { 76 } 77 78 WebRect& operator=(const WebCore::IntRect& r) 79 { 80 x = r.x(); 81 y = r.y(); 82 width = r.width(); 83 height = r.height(); 84 return *this; 85 } 86 87 operator WebCore::IntRect() const 88 { 89 return WebCore::IntRect(x, y, width, height); 90 } 91 #else 92 WebRect(const gfx::Rect& r) 93 : x(r.x()) 94 , y(r.y()) 95 , width(r.width()) 96 , height(r.height()) 97 { 98 } 99 100 WebRect& operator=(const gfx::Rect& r) 101 { 102 x = r.x(); 103 y = r.y(); 104 width = r.width(); 105 height = r.height(); 106 return *this; 107 } 108 109 operator gfx::Rect() const 110 { 111 return gfx::Rect(x, y, std::max(0, width), std::max(0, height)); 112 } 113 #endif 114 }; 115 116 inline bool operator==(const WebRect& a, const WebRect& b) 117 { 118 return a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height; 119 } 120 121 inline bool operator!=(const WebRect& a, const WebRect& b) 122 { 123 return !(a == b); 124 } 125 126 } // namespace WebKit 127 128 #endif 129