Fix the issue that Web Audio test case fails on PR3.
[framework/web/webkit-efl.git] / Source / WebCore / rendering / LayoutTypes.h
1 /*
2  * Copyright (C) 2011 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 // These typedefs are being used to abstract layout and hit testing off
32 // of integers and eventually replace them with floats. Once this transition
33 // is complete, these types will be removed. Progress can be tracked at
34 // https://bugs.webkit.org/show_bug.cgi?id=60318
35
36 #ifndef LayoutTypes_h
37 #define LayoutTypes_h
38
39 #include "FloatRect.h"
40 #include "FractionalLayoutBoxExtent.h"
41 #include "FractionalLayoutRect.h"
42 #include "FractionalLayoutUnit.h"
43 #include "IntRect.h"
44
45 #include <wtf/MathExtras.h>
46
47 namespace WebCore {
48
49 typedef FractionalLayoutUnit LayoutUnit;
50 typedef FractionalLayoutPoint LayoutPoint;
51 typedef FractionalLayoutSize LayoutSize;
52 typedef FractionalLayoutRect LayoutRect;
53 typedef FractionalLayoutBoxExtent LayoutBoxExtent;
54
55 #define MAX_LAYOUT_UNIT LayoutUnit::max()
56 #define MIN_LAYOUT_UNIT LayoutUnit::min()
57 #define ZERO_LAYOUT_UNIT LayoutUnit(0)
58
59 inline FractionalLayoutRect enclosingLayoutRect(const FloatRect& rect)
60 {
61     return enclosingIntRect(rect);
62 }
63
64 inline LayoutSize roundedLayoutSize(const FloatSize& s)
65 {
66 #if ENABLE(SUBPIXEL_LAYOUT)
67     return FractionalLayoutSize(s);
68 #else
69     return roundedIntSize(s);
70 #endif
71 }
72
73 inline IntRect pixelSnappedIntRect(LayoutUnit left, LayoutUnit top, LayoutUnit width, LayoutUnit height)
74 {
75     return IntRect(left.round(), top.round(), snapSizeToPixel(width, left), snapSizeToPixel(height, top));
76 }
77
78 inline IntRect pixelSnappedIntRectFromEdges(LayoutUnit left, LayoutUnit top, LayoutUnit right, LayoutUnit bottom)
79 {
80     return IntRect(left.round(), top.round(), snapSizeToPixel(right - left, left), snapSizeToPixel(bottom - top, top));
81 }
82
83 inline LayoutPoint roundedLayoutPoint(const FloatPoint& p)
84 {
85 #if ENABLE(SUBPIXEL_LAYOUT)
86     return FractionalLayoutPoint(p);
87 #else
88     return roundedIntPoint(p);
89 #endif
90 }
91
92 inline LayoutPoint flooredLayoutPoint(const FloatPoint& p)
93 {
94     return LayoutPoint(p.x(), p.y());
95 }
96
97 inline LayoutPoint flooredLayoutPoint(const FloatSize& s)
98 {
99     return LayoutPoint(s.width(), s.height());
100 }
101
102 inline LayoutSize flooredLayoutSize(const FloatPoint& p)
103 {
104     return LayoutSize(p.x(), p.y());
105 }
106
107 inline int roundToInt(LayoutUnit value)
108 {
109     return value.round();
110 }
111
112 inline int floorToInt(LayoutUnit value)
113 {
114     return value.toInt();
115 }
116
117 inline LayoutUnit roundedLayoutUnit(float value)
118 {
119 #if ENABLE(SUBPIXEL_LAYOUT)
120     return FractionalLayoutUnit::fromFloatRound(value);
121 #else
122     return static_cast<int>(lroundf(value));
123 #endif
124 }
125
126 inline LayoutUnit ceiledLayoutUnit(float value)
127 {
128 #if ENABLE(SUBPIXEL_LAYOUT)
129     return FractionalLayoutUnit::fromFloatCeil(value);
130 #else
131     return ceilf(value);
132 #endif
133 }
134
135 inline LayoutUnit absoluteValue(const LayoutUnit& value)
136 {
137     return value.abs();
138 }
139
140 inline LayoutSize toLayoutSize(const LayoutPoint& p)
141 {
142     return LayoutSize(p.x(), p.y());
143 }
144
145 inline LayoutPoint toLayoutPoint(const LayoutSize& p)
146 {
147     return LayoutPoint(p.width(), p.height());
148 }
149
150 inline LayoutUnit layoutMod(const LayoutUnit& numerator, const LayoutUnit& denominator)
151 {
152     return numerator.toInt() % denominator.toInt();
153 }
154
155 inline LayoutUnit clampToLayoutUnit(double value)
156 {
157     return clampTo<FractionalLayoutUnit>(value, FractionalLayoutUnit::min(), FractionalLayoutUnit::max());
158 }
159
160 inline IntSize pixelSnappedIntSize(const FractionalLayoutSize& s, const FractionalLayoutPoint& p)
161 {
162     return IntSize(snapSizeToPixel(s.width(), p.x()), snapSizeToPixel(s.height(), p.y()));
163 }
164
165 inline IntRect pixelSnappedIntRect(LayoutPoint location, LayoutSize size)
166 {
167     return IntRect(roundedIntPoint(location), pixelSnappedIntSize(size, location));
168 }
169
170 inline bool isIntegerValue(const LayoutUnit value)
171 {
172     return value.floor() == value;
173 }
174
175 } // namespace WebCore
176
177 #endif // LayoutTypes_h