Diff
Modified: trunk/Source/WebCore/ChangeLog (108422 => 108423)
--- trunk/Source/WebCore/ChangeLog 2012-02-22 01:04:21 UTC (rev 108422)
+++ trunk/Source/WebCore/ChangeLog 2012-02-22 01:19:11 UTC (rev 108423)
@@ -1,3 +1,88 @@
+2012-02-21 Emil A Eklund <[email protected]>
+
+ Add FractionalLayoutRect for sub-pixel layout
+ https://bugs.webkit.org/show_bug.cgi?id=78924
+
+ Reviewed by Eric Seidel.
+
+ Add FractionalLayoutUnit version of Rect class. Uses FractionalLayoutPoint
+ and FractionalLayoutSize internally.
+
+ Also add conversions to int/float versions of same.
+
+ No new tests.
+
+ * GNUmakefile.list.am:
+ * WebCore.vcproj/WebCore.vcproj:
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/graphics/FloatRect.cpp:
+ (WebCore::FloatRect::FloatRect):
+ (WebCore):
+ * platform/graphics/FloatRect.h:
+ (WebCore):
+ (FloatRect):
+ * platform/graphics/FractionalLayoutRect.cpp: Added.
+ (WebCore):
+ (WebCore::FractionalLayoutRect::FractionalLayoutRect):
+ (WebCore::FractionalLayoutRect::intersects):
+ (WebCore::FractionalLayoutRect::contains):
+ (WebCore::FractionalLayoutRect::intersect):
+ (WebCore::FractionalLayoutRect::unite):
+ (WebCore::FractionalLayoutRect::uniteIfNonZero):
+ (WebCore::FractionalLayoutRect::scale):
+ (WebCore::unionRect):
+ (WebCore::enclosingIntRect):
+ (WebCore::enclosingFractionalLayoutRect):
+ (WebCore::pixelSnappedIntRect):
+ * platform/graphics/FractionalLayoutRect.h: Added.
+ (WebCore):
+ (FractionalLayoutRect):
+ (WebCore::FractionalLayoutRect::FractionalLayoutRect):
+ (WebCore::FractionalLayoutRect::location):
+ (WebCore::FractionalLayoutRect::size):
+ (WebCore::FractionalLayoutRect::setLocation):
+ (WebCore::FractionalLayoutRect::setSize):
+ (WebCore::FractionalLayoutRect::x):
+ (WebCore::FractionalLayoutRect::y):
+ (WebCore::FractionalLayoutRect::maxX):
+ (WebCore::FractionalLayoutRect::maxY):
+ (WebCore::FractionalLayoutRect::width):
+ (WebCore::FractionalLayoutRect::height):
+ (WebCore::FractionalLayoutRect::setX):
+ (WebCore::FractionalLayoutRect::setY):
+ (WebCore::FractionalLayoutRect::setWidth):
+ (WebCore::FractionalLayoutRect::setHeight):
+ (WebCore::FractionalLayoutRect::isEmpty):
+ (WebCore::FractionalLayoutRect::center):
+ (WebCore::FractionalLayoutRect::move):
+ (WebCore::FractionalLayoutRect::moveBy):
+ (WebCore::FractionalLayoutRect::expand):
+ (WebCore::FractionalLayoutRect::contract):
+ (WebCore::FractionalLayoutRect::shiftXEdgeTo):
+ (WebCore::FractionalLayoutRect::shiftMaxXEdgeTo):
+ (WebCore::FractionalLayoutRect::shiftYEdgeTo):
+ (WebCore::FractionalLayoutRect::shiftMaxYEdgeTo):
+ (WebCore::FractionalLayoutRect::minXMinYCorner):
+ (WebCore::FractionalLayoutRect::maxXMinYCorner):
+ (WebCore::FractionalLayoutRect::minXMaxYCorner):
+ (WebCore::FractionalLayoutRect::maxXMaxYCorner):
+ (WebCore::FractionalLayoutRect::contains):
+ (WebCore::FractionalLayoutRect::inflateX):
+ (WebCore::FractionalLayoutRect::inflateY):
+ (WebCore::FractionalLayoutRect::inflate):
+ (WebCore::FractionalLayoutRect::transposedRect):
+ (WebCore::FractionalLayoutRect::infiniteRect):
+ (WebCore::intersection):
+ (WebCore::unionRect):
+ (WebCore::operator==):
+ (WebCore::operator!=):
+ * platform/graphics/IntRect.cpp:
+ (WebCore::IntRect::IntRect):
+ (WebCore):
+ * platform/graphics/IntRect.h:
+ (WebCore):
+ (IntRect):
+
2012-02-21 James Robinson <[email protected]>
Enable ScrollingCoordinator in chromium whenever compositing is enabled
Modified: trunk/Source/WebCore/GNUmakefile.list.am (108422 => 108423)
--- trunk/Source/WebCore/GNUmakefile.list.am 2012-02-22 01:04:21 UTC (rev 108422)
+++ trunk/Source/WebCore/GNUmakefile.list.am 2012-02-22 01:19:11 UTC (rev 108423)
@@ -2999,6 +2999,8 @@
Source/WebCore/platform/graphics/FontTraitsMask.h \
Source/WebCore/platform/graphics/FontWidthVariant.h \
Source/WebCore/platform/graphics/FractionalLayoutPoint.h \
+ Source/WebCore/platform/graphics/FractionalLayoutRect.cpp \
+ Source/WebCore/platform/graphics/FractionalLayoutRect.h \
Source/WebCore/platform/graphics/FractionalLayoutSize.cpp \
Source/WebCore/platform/graphics/FractionalLayoutSize.h \
Source/WebCore/platform/graphics/GeneratorGeneratedImage.cpp \
Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (108422 => 108423)
--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj 2012-02-22 01:04:21 UTC (rev 108422)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj 2012-02-22 01:19:11 UTC (rev 108423)
@@ -27573,6 +27573,14 @@
>
</File>
<File
+ RelativePath="..\platform\graphics\FractionalLayoutRect.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\platform\graphics\FractionalLayoutRect.h"
+ >
+ </File>
+ <File
RelativePath="..\platform\graphics\FractionalLayoutSize.cpp"
>
</File>
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (108422 => 108423)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2012-02-22 01:04:21 UTC (rev 108422)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2012-02-22 01:19:11 UTC (rev 108423)
@@ -300,6 +300,8 @@
144FCE5214EC79BC000D17A3 /* FractionalLayoutUnit.h in Headers */ = {isa = PBXBuildFile; fileRef = 144FCE5114EC79BC000D17A3 /* FractionalLayoutUnit.h */; settings = {ATTRIBUTES = (Private, ); }; };
144FCE5C14EC79E7000D17A3 /* FractionalLayoutSize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 144FCE5714EC79E7000D17A3 /* FractionalLayoutSize.cpp */; };
144FCE5D14EC79E7000D17A3 /* FractionalLayoutSize.h in Headers */ = {isa = PBXBuildFile; fileRef = 144FCE5814EC79E7000D17A3 /* FractionalLayoutSize.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 144FCFE014EF2509000D17A3 /* FractionalLayoutRect.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 144FCFDE14EF2509000D17A3 /* FractionalLayoutRect.cpp */; };
+ 144FCFE114EF2509000D17A3 /* FractionalLayoutRect.h in Headers */ = {isa = PBXBuildFile; fileRef = 144FCFDF14EF2509000D17A3 /* FractionalLayoutRect.h */; settings = {ATTRIBUTES = (Private, ); }; };
1464E06C135EC10600FDB00A /* JSMediaListCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1464E06B135EC10600FDB00A /* JSMediaListCustom.cpp */; };
1477E7760BF4134A00152872 /* PageCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1477E7740BF4134A00152872 /* PageCache.cpp */; };
1477E7770BF4134A00152872 /* PageCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 1477E7750BF4134A00152872 /* PageCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -7024,6 +7026,8 @@
144FCE5414EC79E7000D17A3 /* FractionalLayoutPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FractionalLayoutPoint.h; sourceTree = "<group>"; };
144FCE5714EC79E7000D17A3 /* FractionalLayoutSize.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FractionalLayoutSize.cpp; sourceTree = "<group>"; };
144FCE5814EC79E7000D17A3 /* FractionalLayoutSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FractionalLayoutSize.h; sourceTree = "<group>"; };
+ 144FCFDE14EF2509000D17A3 /* FractionalLayoutRect.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FractionalLayoutRect.cpp; sourceTree = "<group>"; };
+ 144FCFDF14EF2509000D17A3 /* FractionalLayoutRect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FractionalLayoutRect.h; sourceTree = "<group>"; };
1464E06B135EC10600FDB00A /* JSMediaListCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaListCustom.cpp; sourceTree = "<group>"; };
1477E7740BF4134A00152872 /* PageCache.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = PageCache.cpp; sourceTree = "<group>"; };
1477E7750BF4134A00152872 /* PageCache.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PageCache.h; sourceTree = "<group>"; };
@@ -18938,6 +18942,8 @@
3784C34A0E11AA34007D8D48 /* FontTraitsMask.h */,
BCE4413512F7490B009B84B8 /* FontWidthVariant.h */,
144FCE5414EC79E7000D17A3 /* FractionalLayoutPoint.h */,
+ 144FCFDE14EF2509000D17A3 /* FractionalLayoutRect.cpp */,
+ 144FCFDF14EF2509000D17A3 /* FractionalLayoutRect.h */,
144FCE5714EC79E7000D17A3 /* FractionalLayoutSize.cpp */,
144FCE5814EC79E7000D17A3 /* FractionalLayoutSize.h */,
BC23F0DA0DAFF4A4009FDC91 /* GeneratedImage.h */,
@@ -24291,6 +24297,7 @@
977E2E0F12F0FC9C00C13379 /* XSSAuditor.h in Headers */,
FD537353137B651800008DCE /* ZeroPole.h in Headers */,
E4BBED0F14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.h in Headers */,
+ 144FCFE114EF2509000D17A3 /* FractionalLayoutRect.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -27238,6 +27245,7 @@
977E2E0E12F0FC9C00C13379 /* XSSAuditor.cpp in Sources */,
FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
E4BBED0E14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.cpp in Sources */,
+ 144FCFE014EF2509000D17A3 /* FractionalLayoutRect.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Modified: trunk/Source/WebCore/platform/graphics/FloatRect.cpp (108422 => 108423)
--- trunk/Source/WebCore/platform/graphics/FloatRect.cpp 2012-02-22 01:04:21 UTC (rev 108422)
+++ trunk/Source/WebCore/platform/graphics/FloatRect.cpp 2012-02-22 01:19:11 UTC (rev 108423)
@@ -28,6 +28,7 @@
#include "FloatRect.h"
#include "FloatConversion.h"
+#include "FractionalLayoutRect.h"
#include "IntRect.h"
#include <algorithm>
#include <math.h>
@@ -42,6 +43,10 @@
{
}
+FloatRect::FloatRect(const FractionalLayoutRect& r) : m_location(r.location()), m_size(r.size())
+{
+}
+
FloatRect FloatRect::narrowPrecision(double x, double y, double width, double height)
{
return FloatRect(narrowPrecisionToFloat(x), narrowPrecisionToFloat(y), narrowPrecisionToFloat(width), narrowPrecisionToFloat(height));
Modified: trunk/Source/WebCore/platform/graphics/FloatRect.h (108422 => 108423)
--- trunk/Source/WebCore/platform/graphics/FloatRect.h 2012-02-22 01:04:21 UTC (rev 108422)
+++ trunk/Source/WebCore/platform/graphics/FloatRect.h 2012-02-22 01:19:11 UTC (rev 108423)
@@ -66,6 +66,7 @@
class VGRect;
#endif
+class FractionalLayoutRect;
class IntRect;
class IntPoint;
@@ -82,6 +83,7 @@
FloatRect(float x, float y, float width, float height)
: m_location(FloatPoint(x, y)), m_size(FloatSize(width, height)) { }
FloatRect(const IntRect&);
+ FloatRect(const FractionalLayoutRect&);
static FloatRect narrowPrecision(double x, double y, double width, double height);
Added: trunk/Source/WebCore/platform/graphics/FractionalLayoutRect.cpp (0 => 108423)
--- trunk/Source/WebCore/platform/graphics/FractionalLayoutRect.cpp (rev 0)
+++ trunk/Source/WebCore/platform/graphics/FractionalLayoutRect.cpp 2012-02-22 01:19:11 UTC (rev 108423)
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2012, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "FractionalLayoutRect.h"
+
+#include "FloatRect.h"
+#include "FractionalLayoutUnit.h"
+#include <algorithm>
+
+using std::max;
+using std::min;
+
+namespace WebCore {
+
+FractionalLayoutRect::FractionalLayoutRect(const FloatRect& r)
+ : m_location(FractionalLayoutPoint(r.location()))
+ , m_size(FractionalLayoutSize(r.size()))
+{
+}
+
+bool FractionalLayoutRect::intersects(const FractionalLayoutRect& other) const
+{
+ // Checking emptiness handles negative widths as well as zero.
+ return !isEmpty() && !other.isEmpty()
+ && x() < other.maxX() && other.x() < maxX()
+ && y() < other.maxY() && other.y() < maxY();
+}
+
+bool FractionalLayoutRect::contains(const FractionalLayoutRect& other) const
+{
+ return x() <= other.x() && maxX() >= other.maxX()
+ && y() <= other.y() && maxY() >= other.maxY();
+}
+
+void FractionalLayoutRect::intersect(const FractionalLayoutRect& other)
+{
+ FractionalLayoutPoint newLocation(max(x(), other.x()), max(y(), other.y()));
+ FractionalLayoutPoint newMaxPoint(min(maxX(), other.maxX()), min(maxY(), other.maxY()));
+
+ // Return a clean empty rectangle for non-intersecting cases.
+ if (newLocation.x() >= newMaxPoint.x() || newLocation.y() >= newMaxPoint.y()) {
+ newLocation = FractionalLayoutPoint(0, 0);
+ newMaxPoint = FractionalLayoutPoint(0, 0);
+ }
+
+ m_location = newLocation;
+ m_size = newMaxPoint - newLocation;
+}
+
+void FractionalLayoutRect::unite(const FractionalLayoutRect& other)
+{
+ // Handle empty special cases first.
+ if (other.isEmpty())
+ return;
+ if (isEmpty()) {
+ *this = other;
+ return;
+ }
+
+ FractionalLayoutPoint newLocation(min(x(), other.x()), min(y(), other.y()));
+ FractionalLayoutPoint newMaxPoint(max(maxX(), other.maxX()), max(maxY(), other.maxY()));
+
+ m_location = newLocation;
+ m_size = newMaxPoint - newLocation;
+}
+
+void FractionalLayoutRect::uniteIfNonZero(const FractionalLayoutRect& other)
+{
+ // Handle empty special cases first.
+ if (!other.width() && !other.height())
+ return;
+ if (!width() && !height()) {
+ *this = other;
+ return;
+ }
+
+ FractionalLayoutPoint newLocation(min(x(), other.x()), min(y(), other.y()));
+ FractionalLayoutPoint newMaxPoint(max(maxX(), other.maxX()), max(maxY(), other.maxY()));
+
+ m_location = newLocation;
+ m_size = newMaxPoint - newLocation;
+}
+
+void FractionalLayoutRect::scale(float s)
+{
+ m_location.scale(s, s);
+ m_size.scale(s);
+}
+
+FractionalLayoutRect unionRect(const Vector<FractionalLayoutRect>& rects)
+{
+ FractionalLayoutRect result;
+
+ size_t count = rects.size();
+ for (size_t i = 0; i < count; ++i)
+ result.unite(rects[i]);
+
+ return result;
+}
+
+IntRect enclosingIntRect(const FractionalLayoutRect& rect)
+{
+ float x = floorf(rect.x().toFloat());
+ float y = floorf(rect.y().toFloat());
+ float width = ceilf(rect.maxX().toFloat()) - x;
+ float height = ceilf(rect.maxY().toFloat()) - y;
+
+ return IntRect(clampToInteger(x), clampToInteger(y),
+ clampToInteger(width), clampToInteger(height));
+}
+
+FractionalLayoutRect enclosingFractionalLayoutRect(const FloatRect& rect)
+{
+ return FractionalLayoutRect(rect.x(), rect.y(),
+ rect.maxX() - rect.x() + FractionalLayoutUnit::epsilon(),
+ rect.maxY() - rect.y() + FractionalLayoutUnit::epsilon());
+}
+
+IntRect pixelSnappedIntRect(const FractionalLayoutRect& rect)
+{
+ IntPoint roundedLocation = roundedIntPoint(rect.location());
+ return IntRect(roundedLocation, IntSize((rect.x() + rect.width()).round() - roundedLocation.x(),
+ (rect.y() + rect.height()).round() - roundedLocation.y()));
+}
+
+} // namespace WebCore
Added: trunk/Source/WebCore/platform/graphics/FractionalLayoutRect.h (0 => 108423)
--- trunk/Source/WebCore/platform/graphics/FractionalLayoutRect.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/FractionalLayoutRect.h 2012-02-22 01:19:11 UTC (rev 108423)
@@ -0,0 +1,183 @@
+/*
+ * Copyright (c) 2012, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FractionalLayoutRect_h
+#define FractionalLayoutRect_h
+
+#include "FractionalLayoutPoint.h"
+#include "IntRect.h"
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class FloatRect;
+
+class FractionalLayoutRect {
+public:
+ FractionalLayoutRect() { }
+ FractionalLayoutRect(const FractionalLayoutPoint& location, const FractionalLayoutSize& size)
+ : m_location(location), m_size(size) { }
+ FractionalLayoutRect(FractionalLayoutUnit x, FractionalLayoutUnit y, FractionalLayoutUnit width, FractionalLayoutUnit height)
+ : m_location(FractionalLayoutPoint(x, y)), m_size(FractionalLayoutSize(width, height)) { }
+ FractionalLayoutRect(const FloatPoint& location, const FloatSize& size)
+ : m_location(location), m_size(size) { }
+ FractionalLayoutRect(const IntRect& rect) : m_location(rect.location()), m_size(rect.size()) { }
+
+ explicit FractionalLayoutRect(const FloatRect&); // don't do this implicitly since it's lossy
+
+ FractionalLayoutPoint location() const { return m_location; }
+ FractionalLayoutSize size() const { return m_size; }
+
+ void setLocation(const FractionalLayoutPoint& location) { m_location = location; }
+ void setSize(const FractionalLayoutSize& size) { m_size = size; }
+
+ FractionalLayoutUnit x() const { return m_location.x(); }
+ FractionalLayoutUnit y() const { return m_location.y(); }
+ FractionalLayoutUnit maxX() const { return x() + width(); }
+ FractionalLayoutUnit maxY() const { return y() + height(); }
+ FractionalLayoutUnit width() const { return m_size.width(); }
+ FractionalLayoutUnit height() const { return m_size.height(); }
+
+ void setX(FractionalLayoutUnit x) { m_location.setX(x); }
+ void setY(FractionalLayoutUnit y) { m_location.setY(y); }
+ void setWidth(FractionalLayoutUnit width) { m_size.setWidth(width); }
+ void setHeight(FractionalLayoutUnit height) { m_size.setHeight(height); }
+
+ bool isEmpty() const { return m_size.isEmpty(); }
+
+ // NOTE: The result is rounded to integer values, and thus may be not the exact
+ // center point.
+ FractionalLayoutPoint center() const { return FractionalLayoutPoint(x() + width() / 2, y() + height() / 2); }
+
+ void move(const FractionalLayoutSize& size) { m_location += size; }
+ void moveBy(const FractionalLayoutPoint& offset) { m_location.move(offset.x(), offset.y()); }
+ void move(FractionalLayoutUnit dx, FractionalLayoutUnit dy) { m_location.move(dx, dy); }
+
+ void expand(const FractionalLayoutSize& size) { m_size += size; }
+ void expand(FractionalLayoutUnit dw, FractionalLayoutUnit dh) { m_size.expand(dw, dh); }
+ void contract(const FractionalLayoutSize& size) { m_size -= size; }
+ void contract(FractionalLayoutUnit dw, FractionalLayoutUnit dh) { m_size.expand(-dw, -dh); }
+
+ void shiftXEdgeTo(FractionalLayoutUnit edge)
+ {
+ FractionalLayoutUnit delta = edge - x();
+ setX(edge);
+ setWidth(std::max<FractionalLayoutUnit>(0, width() - delta));
+ }
+ void shiftMaxXEdgeTo(FractionalLayoutUnit edge)
+ {
+ FractionalLayoutUnit delta = edge - maxX();
+ setWidth(std::max<FractionalLayoutUnit>(0, width() + delta));
+ }
+ void shiftYEdgeTo(FractionalLayoutUnit edge)
+ {
+ FractionalLayoutUnit delta = edge - y();
+ setY(edge);
+ setHeight(std::max<FractionalLayoutUnit>(0, height() - delta));
+ }
+ void shiftMaxYEdgeTo(FractionalLayoutUnit edge)
+ {
+ FractionalLayoutUnit delta = edge - maxY();
+ setHeight(std::max<FractionalLayoutUnit>(0, height() + delta));
+ }
+
+ FractionalLayoutPoint minXMinYCorner() const { return m_location; } // typically topLeft
+ FractionalLayoutPoint maxXMinYCorner() const { return FractionalLayoutPoint(m_location.x() + m_size.width(), m_location.y()); } // typically topRight
+ FractionalLayoutPoint minXMaxYCorner() const { return FractionalLayoutPoint(m_location.x(), m_location.y() + m_size.height()); } // typically bottomLeft
+ FractionalLayoutPoint maxXMaxYCorner() const { return FractionalLayoutPoint(m_location.x() + m_size.width(), m_location.y() + m_size.height()); } // typically bottomRight
+
+ bool intersects(const FractionalLayoutRect&) const;
+ bool contains(const FractionalLayoutRect&) const;
+
+ // This checks to see if the rect contains x,y in the traditional sense.
+ // Equivalent to checking if the rect contains a 1x1 rect below and to the right of (px,py).
+ bool contains(FractionalLayoutUnit px, FractionalLayoutUnit py) const
+ { return px >= x() && px < maxX() && py >= y() && py < maxY(); }
+ bool contains(const FractionalLayoutPoint& point) const { return contains(point.x(), point.y()); }
+
+ void intersect(const FractionalLayoutRect&);
+ void unite(const FractionalLayoutRect&);
+ void uniteIfNonZero(const FractionalLayoutRect&);
+
+ void inflateX(FractionalLayoutUnit dx)
+ {
+ m_location.setX(m_location.x() - dx);
+ m_size.setWidth(m_size.width() + dx + dx);
+ }
+ void inflateY(FractionalLayoutUnit dy)
+ {
+ m_location.setY(m_location.y() - dy);
+ m_size.setHeight(m_size.height() + dy + dy);
+ }
+ void inflate(FractionalLayoutUnit d) { inflateX(d); inflateY(d); }
+ void scale(float s);
+
+ FractionalLayoutRect transposedRect() const { return FractionalLayoutRect(m_location.transposedPoint(), m_size.transposedSize()); }
+
+ static FractionalLayoutRect infiniteRect() {return FractionalLayoutRect(FractionalLayoutUnit::min() / 2, FractionalLayoutUnit::min() / 2, FractionalLayoutUnit::max(), FractionalLayoutUnit::max()); }
+
+private:
+ FractionalLayoutPoint m_location;
+ FractionalLayoutSize m_size;
+};
+
+inline FractionalLayoutRect intersection(const FractionalLayoutRect& a, const FractionalLayoutRect& b)
+{
+ FractionalLayoutRect c = a;
+ c.intersect(b);
+ return c;
+}
+
+inline FractionalLayoutRect unionRect(const FractionalLayoutRect& a, const FractionalLayoutRect& b)
+{
+ FractionalLayoutRect c = a;
+ c.unite(b);
+ return c;
+}
+
+FractionalLayoutRect unionRect(const Vector<FractionalLayoutRect>&);
+
+inline bool operator==(const FractionalLayoutRect& a, const FractionalLayoutRect& b)
+{
+ return a.location() == b.location() && a.size() == b.size();
+}
+
+inline bool operator!=(const FractionalLayoutRect& a, const FractionalLayoutRect& b)
+{
+ return a.location() != b.location() || a.size() != b.size();
+}
+
+IntRect enclosingIntRect(const FractionalLayoutRect&);
+FractionalLayoutRect enclosingFractionalLayoutRect(const FloatRect&);
+IntRect pixelSnappedIntRect(const FractionalLayoutRect&);
+
+} // namespace WebCore
+
+#endif // FractionalLayoutRect_h
Modified: trunk/Source/WebCore/platform/graphics/IntRect.cpp (108422 => 108423)
--- trunk/Source/WebCore/platform/graphics/IntRect.cpp 2012-02-22 01:04:21 UTC (rev 108422)
+++ trunk/Source/WebCore/platform/graphics/IntRect.cpp 2012-02-22 01:19:11 UTC (rev 108423)
@@ -26,6 +26,7 @@
#include "config.h"
#include "IntRect.h"
+#include "FractionalLayoutRect.h"
#include "FloatRect.h"
#include <algorithm>
@@ -40,6 +41,12 @@
{
}
+IntRect::IntRect(const FractionalLayoutRect& r)
+ : m_location(flooredIntPoint(r.location()))
+ , m_size(flooredIntSize(r.size()))
+{
+}
+
bool IntRect::intersects(const IntRect& other) const
{
// Checking emptiness handles negative widths as well as zero.
Modified: trunk/Source/WebCore/platform/graphics/IntRect.h (108422 => 108423)
--- trunk/Source/WebCore/platform/graphics/IntRect.h 2012-02-22 01:04:21 UTC (rev 108422)
+++ trunk/Source/WebCore/platform/graphics/IntRect.h 2012-02-22 01:19:11 UTC (rev 108423)
@@ -71,6 +71,7 @@
namespace WebCore {
class FloatRect;
+class FractionalLayoutRect;
class IntRect {
public:
@@ -80,7 +81,8 @@
IntRect(int x, int y, int width, int height)
: m_location(IntPoint(x, y)), m_size(IntSize(width, height)) { }
- explicit IntRect(const FloatRect& rect); // don't do this implicitly since it's lossy
+ explicit IntRect(const FloatRect&); // don't do this implicitly since it's lossy
+ explicit IntRect(const FractionalLayoutRect&); // don't do this implicitly since it's lossy
IntPoint location() const { return m_location; }
IntSize size() const { return m_size; }