2 * Copyright (C) 2011 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
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
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 // 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
39 #include "FloatRect.h"
40 #include "FractionalLayoutBoxExtent.h"
41 #include "FractionalLayoutRect.h"
42 #include "FractionalLayoutUnit.h"
45 #include <wtf/MathExtras.h>
49 typedef FractionalLayoutUnit LayoutUnit;
50 typedef FractionalLayoutPoint LayoutPoint;
51 typedef FractionalLayoutSize LayoutSize;
52 typedef FractionalLayoutRect LayoutRect;
53 typedef FractionalLayoutBoxExtent LayoutBoxExtent;
55 #define MAX_LAYOUT_UNIT LayoutUnit::max()
56 #define MIN_LAYOUT_UNIT LayoutUnit::min()
57 #define ZERO_LAYOUT_UNIT LayoutUnit(0)
59 inline FractionalLayoutRect enclosingLayoutRect(const FloatRect& rect)
61 return enclosingIntRect(rect);
64 inline LayoutSize roundedLayoutSize(const FloatSize& s)
66 #if ENABLE(SUBPIXEL_LAYOUT)
67 return FractionalLayoutSize(s);
69 return roundedIntSize(s);
73 inline IntRect pixelSnappedIntRect(LayoutUnit left, LayoutUnit top, LayoutUnit width, LayoutUnit height)
75 return IntRect(left.round(), top.round(), snapSizeToPixel(width, left), snapSizeToPixel(height, top));
78 inline IntRect pixelSnappedIntRectFromEdges(LayoutUnit left, LayoutUnit top, LayoutUnit right, LayoutUnit bottom)
80 return IntRect(left.round(), top.round(), snapSizeToPixel(right - left, left), snapSizeToPixel(bottom - top, top));
83 inline LayoutPoint roundedLayoutPoint(const FloatPoint& p)
85 #if ENABLE(SUBPIXEL_LAYOUT)
86 return FractionalLayoutPoint(p);
88 return roundedIntPoint(p);
92 inline LayoutPoint flooredLayoutPoint(const FloatPoint& p)
94 return LayoutPoint(p.x(), p.y());
97 inline LayoutPoint flooredLayoutPoint(const FloatSize& s)
99 return LayoutPoint(s.width(), s.height());
102 inline LayoutSize flooredLayoutSize(const FloatPoint& p)
104 return LayoutSize(p.x(), p.y());
107 inline int roundToInt(LayoutUnit value)
109 return value.round();
112 inline int floorToInt(LayoutUnit value)
114 return value.toInt();
117 inline LayoutUnit roundedLayoutUnit(float value)
119 #if ENABLE(SUBPIXEL_LAYOUT)
120 return FractionalLayoutUnit::fromFloatRound(value);
122 return static_cast<int>(lroundf(value));
126 inline LayoutUnit ceiledLayoutUnit(float value)
128 #if ENABLE(SUBPIXEL_LAYOUT)
129 return FractionalLayoutUnit::fromFloatCeil(value);
135 inline LayoutUnit absoluteValue(const LayoutUnit& value)
140 inline LayoutSize toLayoutSize(const LayoutPoint& p)
142 return LayoutSize(p.x(), p.y());
145 inline LayoutPoint toLayoutPoint(const LayoutSize& p)
147 return LayoutPoint(p.width(), p.height());
150 inline LayoutUnit layoutMod(const LayoutUnit& numerator, const LayoutUnit& denominator)
152 return numerator.toInt() % denominator.toInt();
155 inline LayoutUnit clampToLayoutUnit(double value)
157 return clampTo<FractionalLayoutUnit>(value, FractionalLayoutUnit::min(), FractionalLayoutUnit::max());
160 inline IntSize pixelSnappedIntSize(const FractionalLayoutSize& s, const FractionalLayoutPoint& p)
162 return IntSize(snapSizeToPixel(s.width(), p.x()), snapSizeToPixel(s.height(), p.y()));
165 inline IntRect pixelSnappedIntRect(LayoutPoint location, LayoutSize size)
167 return IntRect(roundedIntPoint(location), pixelSnappedIntSize(size, location));
170 inline bool isIntegerValue(const LayoutUnit value)
172 return value.floor() == value;
175 } // namespace WebCore
177 #endif // LayoutTypes_h