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