Home | History | Annotate | Download | only in platform
      1 /*
      2  * Copyright (C) 2010 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 WebFloatRect_h
     32 #define WebFloatRect_h
     33 
     34 #include "WebCommon.h"
     35 
     36 #if WEBKIT_IMPLEMENTATION
     37 #include "core/platform/graphics/FloatRect.h"
     38 #else
     39 #include <cmath>
     40 #include <ui/gfx/rect_f.h>
     41 #endif
     42 
     43 namespace WebKit {
     44 
     45 struct WebFloatRect {
     46     float x;
     47     float y;
     48     float width;
     49     float height;
     50 
     51     bool isEmpty() const { return width <= 0 || height <= 0; }
     52 
     53     WebFloatRect()
     54         : x(0)
     55         , y(0)
     56         , width(0)
     57         , height(0)
     58     {
     59     }
     60 
     61     WebFloatRect(float x, float y, float width, float height)
     62         : x(x)
     63         , y(y)
     64         , width(width)
     65         , height(height)
     66     {
     67     }
     68 
     69 #if WEBKIT_IMPLEMENTATION
     70     WebFloatRect(const WebCore::FloatRect& r)
     71         : x(r.x())
     72         , y(r.y())
     73         , width(r.width())
     74         , height(r.height())
     75     {
     76     }
     77 
     78     WebFloatRect& operator=(const WebCore::FloatRect& 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::FloatRect() const
     88     {
     89         return WebCore::FloatRect(x, y, width, height);
     90     }
     91 #else
     92     WebFloatRect(const gfx::RectF& r)
     93         : x(r.x())
     94         , y(r.y())
     95         , width(r.width())
     96         , height(r.height())
     97     {
     98     }
     99 
    100     WebFloatRect& operator=(const gfx::RectF& 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::RectF() const
    110     {
    111         return gfx::RectF(x, y, std::max(0.0f, width), std::max(0.0f, height));
    112     }
    113 #endif
    114 };
    115 
    116 inline bool operator==(const WebFloatRect& a, const WebFloatRect& 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 WebFloatRect& a, const WebFloatRect& b)
    122 {
    123     return !(a == b);
    124 }
    125 
    126 } // namespace WebKit
    127 
    128 #endif
    129