Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / public / platform / WebSize.h
blobfb1d8920bf97d24421763043b6b027e04cd65f5a
1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
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.
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.
31 #ifndef WebSize_h
32 #define WebSize_h
34 #include "WebCommon.h"
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
45 namespace blink {
47 struct WebSize {
48 int width;
49 int height;
51 bool isEmpty() const { return width <= 0 || height <= 0; }
53 WebSize()
54 : width(0)
55 , height(0)
59 WebSize(int width, int height)
60 : width(width)
61 , height(height)
65 #if INSIDE_BLINK
66 WebSize(const IntSize& s)
67 : width(s.width())
68 , height(s.height())
72 WebSize& operator=(const IntSize& s)
74 width = s.width();
75 height = s.height();
76 return *this;
79 operator IntSize() const
81 return IntSize(width, height);
83 #else
84 WebSize(const gfx::Size& s)
85 : width(s.width())
86 , height(s.height())
90 WebSize(const gfx::Vector2d& v)
91 : width(v.x())
92 , height(v.y())
96 WebSize& operator=(const gfx::Size& s)
98 width = s.width();
99 height = s.height();
100 return *this;
103 WebSize& operator=(const gfx::Vector2d& v)
105 width = v.x();
106 height = v.y();
107 return *this;
110 operator gfx::Size() const
112 return gfx::Size(std::max(0, width), std::max(0, height));
115 operator gfx::Vector2d() const
117 return gfx::Vector2d(width, height);
119 #endif
122 inline bool operator==(const WebSize& a, const WebSize& b)
124 return a.width == b.width && a.height == b.height;
127 inline bool operator!=(const WebSize& a, const WebSize& b)
129 return !(a == b);
132 } // namespace blink
134 #endif