Clean up #includes by geometry classes
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 23 Mar 2014 08:36:14 +0000 (08:36 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 23 Mar 2014 08:36:14 +0000 (08:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=130645

Reviewed by Andreas Kling.

Pulling in <wtf/Vector.h> and <wtf/PrintStream.h> in the simple geometry
classes brings in a lot of additional headers. Fix by adding a new
GeometryUtilities file so that the basic files don't need Vector,
and including GeometryUtilities.h where necessary.

Also forward declare PrintStream.h and only bring in the header
in implementation files.

Source/WebCore:

* CMakeLists.txt:
* GNUmakefile.list.am:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.xcodeproj/project.pbxproj:
* css/CSSToStyleMap.h:
* html/HTMLCanvasElement.cpp:
* platform/cairo/WidgetBackingStoreCairo.h:
* platform/graphics/FloatPoint.cpp:
* platform/graphics/FloatPoint.h:
* platform/graphics/FloatRect.cpp:
* platform/graphics/FloatRect.h:
* platform/graphics/FloatSize.cpp:
* platform/graphics/FloatSize.h:
* platform/graphics/GeometryUtilities.cpp: Added.
(WebCore::findSlope):
(WebCore::findIntersection):
(WebCore::unionRect):
(WebCore::mapRect):
* platform/graphics/GeometryUtilities.h: Copied from Source/WebCore/platform/graphics/TextTrackRepresentation.h.
* platform/graphics/IntPoint.h:
* platform/graphics/IntRect.cpp:
* platform/graphics/IntRect.h:
* platform/graphics/IntSize.h:
* platform/graphics/TextTrackRepresentation.h:
* platform/graphics/Tile.h:
* platform/gtk/WidgetBackingStoreGtkX11.h:
* rendering/RenderBoxModelObject.cpp:
* rendering/RenderImage.cpp:
* rendering/RenderObject.cpp:

Source/WebKit2:

* UIProcess/BackingStore.h:
* UIProcess/FindIndicator.cpp:
* UIProcess/mac/WKPrintingView.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166138 268f45cc-cd09-0410-ab3c-d52691b4dbfc

34 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/CSSToStyleMap.h
Source/WebCore/html/HTMLCanvasElement.cpp
Source/WebCore/platform/cairo/WidgetBackingStoreCairo.h
Source/WebCore/platform/graphics/FloatPoint.cpp
Source/WebCore/platform/graphics/FloatPoint.h
Source/WebCore/platform/graphics/FloatRect.cpp
Source/WebCore/platform/graphics/FloatRect.h
Source/WebCore/platform/graphics/FloatSize.cpp
Source/WebCore/platform/graphics/FloatSize.h
Source/WebCore/platform/graphics/GeometryUtilities.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/GeometryUtilities.h [new file with mode: 0644]
Source/WebCore/platform/graphics/IntPoint.h
Source/WebCore/platform/graphics/IntRect.cpp
Source/WebCore/platform/graphics/IntRect.h
Source/WebCore/platform/graphics/IntSize.h
Source/WebCore/platform/graphics/TextTrackRepresentation.h
Source/WebCore/platform/graphics/Tile.h
Source/WebCore/platform/graphics/texmap/coordinated/UpdateAtlas.h
Source/WebCore/platform/gtk/WidgetBackingStoreGtkX11.h
Source/WebCore/rendering/RenderBoxModelObject.cpp
Source/WebCore/rendering/RenderImage.cpp
Source/WebCore/rendering/RenderObject.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/UpdateInfo.h
Source/WebKit2/UIProcess/BackingStore.h
Source/WebKit2/UIProcess/CoordinatedGraphics/PageViewportController.h
Source/WebKit2/UIProcess/FindIndicator.cpp
Source/WebKit2/UIProcess/mac/WKPrintingView.h

index ce0404f..d04c620 100644 (file)
@@ -1882,6 +1882,7 @@ set(WebCore_SOURCES
     platform/graphics/FontGenericFamilies.cpp
     platform/graphics/FontGlyphs.cpp
     platform/graphics/GeneratedImage.cpp
+    platform/graphics/GeometryUtilities.cpp
     platform/graphics/GlyphPageTreeNode.cpp
     platform/graphics/Gradient.cpp
     platform/graphics/GradientImage.cpp
index 62f0728..4716bae 100644 (file)
@@ -1,3 +1,49 @@
+2014-03-23  Simon Fraser  <simon.fraser@apple.com>
+
+        Clean up #includes by geometry classes
+        https://bugs.webkit.org/show_bug.cgi?id=130645
+
+        Reviewed by Andreas Kling.
+
+        Pulling in <wtf/Vector.h> and <wtf/PrintStream.h> in the simple geometry
+        classes brings in a lot of additional headers. Fix by adding a new
+        GeometryUtilities file so that the basic files don't need Vector,
+        and including GeometryUtilities.h where necessary.
+        
+        Also forward declare PrintStream.h and only bring in the header
+        in implementation files.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * WebCore.vcxproj/WebCore.vcxproj:
+        * WebCore.vcxproj/WebCore.vcxproj.filters:
+        * WebCore.xcodeproj/project.pbxproj:
+        * css/CSSToStyleMap.h:
+        * html/HTMLCanvasElement.cpp:
+        * platform/cairo/WidgetBackingStoreCairo.h:
+        * platform/graphics/FloatPoint.cpp:
+        * platform/graphics/FloatPoint.h:
+        * platform/graphics/FloatRect.cpp:
+        * platform/graphics/FloatRect.h:
+        * platform/graphics/FloatSize.cpp:
+        * platform/graphics/FloatSize.h:
+        * platform/graphics/GeometryUtilities.cpp: Added.
+        (WebCore::findSlope):
+        (WebCore::findIntersection):
+        (WebCore::unionRect):
+        (WebCore::mapRect):
+        * platform/graphics/GeometryUtilities.h: Copied from Source/WebCore/platform/graphics/TextTrackRepresentation.h.
+        * platform/graphics/IntPoint.h:
+        * platform/graphics/IntRect.cpp:
+        * platform/graphics/IntRect.h:
+        * platform/graphics/IntSize.h:
+        * platform/graphics/TextTrackRepresentation.h:
+        * platform/graphics/Tile.h:
+        * platform/gtk/WidgetBackingStoreGtkX11.h:
+        * rendering/RenderBoxModelObject.cpp:
+        * rendering/RenderImage.cpp:
+        * rendering/RenderObject.cpp:
+
 2014-03-22  Chang Shu  <cshu@webkit.org>
 
         Replace deprecatedIsCollapsibleWhitespace with RenderStyle::isCollapsibleWhiteSpace in TextIterator.
index 97505f0..9397782 100644 (file)
@@ -5768,6 +5768,8 @@ platform_sources += \
        Source/WebCore/platform/graphics/FontWidthVariant.h \
        Source/WebCore/platform/graphics/GeneratedImage.cpp \
        Source/WebCore/platform/graphics/GeneratedImage.h \
+       Source/WebCore/platform/graphics/GeometryUtilities.cpp \
+       Source/WebCore/platform/graphics/GeometryUtilities.h \
        Source/WebCore/platform/graphics/Glyph.h \
        Source/WebCore/platform/graphics/GlyphBuffer.h \
        Source/WebCore/platform/graphics/GlyphMetricsMap.h \
index 3b052f8..1b4c800 100644 (file)
     <ClCompile Include="..\platform\graphics\FontFastPath.cpp" />
     <ClCompile Include="..\platform\graphics\FontFeatureSettings.cpp" />
     <ClCompile Include="..\platform\graphics\FontPlatformData.cpp" />
+    <ClCompile Include="..\platform\graphics\GeometryUtilities.cpp" />
     <ClCompile Include="..\platform\graphics\GeneratedImage.cpp" />
     <ClCompile Include="..\platform\graphics\GlyphPageTreeNode.cpp" />
     <ClCompile Include="..\platform\graphics\Gradient.cpp" />
     <ClInclude Include="..\platform\graphics\FontSmoothingMode.h" />
     <ClInclude Include="..\platform\graphics\FontTraitsMask.h" />
     <ClInclude Include="..\platform\graphics\GeneratedImage.h" />
+    <ClInclude Include="..\platform\graphics\GeometryUtilities.h" />
     <ClInclude Include="..\platform\graphics\Glyph.h" />
     <ClInclude Include="..\platform\graphics\GlyphBuffer.h" />
     <ClInclude Include="..\platform\graphics\GlyphMetricsMap.h" />
index 8fe5fe1..9d204a0 100644 (file)
     <ClCompile Include="..\platform\graphics\GeneratedImage.cpp">
       <Filter>platform\graphics</Filter>
     </ClCompile>
+    <ClCompile Include="..\platform\graphics\GeometryUtilities.cpp">
+      <Filter>platform\graphics</Filter>
+    </ClCompile>
     <ClCompile Include="..\platform\graphics\FloatRect.cpp">
       <Filter>platform\graphics</Filter>
     </ClCompile>
index 53e4d07..479c062 100644 (file)
                0FA24D79162DF91900A3F4C0 /* GraphicsLayerUpdater.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FA24D77162DF91900A3F4C0 /* GraphicsLayerUpdater.cpp */; };
                0FA24D7A162DF91900A3F4C0 /* GraphicsLayerUpdater.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FA24D78162DF91900A3F4C0 /* GraphicsLayerUpdater.h */; settings = {ATTRIBUTES = (Private, ); }; };
                0FA88EBD16A8D1BD00F99984 /* ScrollingStateScrollingNodeMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0FA88EBC16A8D1BD00F99984 /* ScrollingStateScrollingNodeMac.mm */; };
+               0FB6252E18DE1B1500A07C05 /* GeometryUtilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FB6252C18DE1B1500A07C05 /* GeometryUtilities.cpp */; };
+               0FB6252F18DE1B1500A07C05 /* GeometryUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB6252D18DE1B1500A07C05 /* GeometryUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
                0FB8890A167D2FA10010CDA5 /* ScrollingTreeStickyNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB88908167D2FA10010CDA5 /* ScrollingTreeStickyNode.h */; settings = {ATTRIBUTES = (Private, ); }; };
                0FB8890B167D2FA10010CDA5 /* ScrollingTreeStickyNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0FB88909167D2FA10010CDA5 /* ScrollingTreeStickyNode.mm */; };
                0FB8890E167D30160010CDA5 /* ScrollingStateStickyNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FB8890C167D30160010CDA5 /* ScrollingStateStickyNode.cpp */; };
                0FA24D77162DF91900A3F4C0 /* GraphicsLayerUpdater.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsLayerUpdater.cpp; sourceTree = "<group>"; };
                0FA24D78162DF91900A3F4C0 /* GraphicsLayerUpdater.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsLayerUpdater.h; sourceTree = "<group>"; };
                0FA88EBC16A8D1BD00F99984 /* ScrollingStateScrollingNodeMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingStateScrollingNodeMac.mm; sourceTree = "<group>"; };
+               0FB6252C18DE1B1500A07C05 /* GeometryUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GeometryUtilities.cpp; sourceTree = "<group>"; };
+               0FB6252D18DE1B1500A07C05 /* GeometryUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GeometryUtilities.h; sourceTree = "<group>"; };
                0FB88908167D2FA10010CDA5 /* ScrollingTreeStickyNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollingTreeStickyNode.h; sourceTree = "<group>"; };
                0FB88909167D2FA10010CDA5 /* ScrollingTreeStickyNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingTreeStickyNode.mm; sourceTree = "<group>"; };
                0FB8890C167D30160010CDA5 /* ScrollingStateStickyNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollingStateStickyNode.cpp; sourceTree = "<group>"; };
                                7CE6CBFA187F370700D46BF5 /* FormatConverter.h */,
                                4FB390AC15EF61F3007AD51F /* GeneratedImage.cpp */,
                                BC23F0DA0DAFF4A4009FDC91 /* GeneratedImage.h */,
+                               0FB6252C18DE1B1500A07C05 /* GeometryUtilities.cpp */,
+                               0FB6252D18DE1B1500A07C05 /* GeometryUtilities.h */,
                                086BBD0E136039C2008B15D8 /* Glyph.h */,
                                B2C3DA5B0D006CD600EF6F26 /* GlyphBuffer.h */,
                                C5D4AA78116BAFB60069CA93 /* GlyphMetricsMap.h */,
                                75415D56129AB2D2003AD669 /* JSSpeechInputEvent.h in Headers */,
                                75415D58129AB2D2003AD669 /* JSSpeechInputResult.h in Headers */,
                                75415D5A129AB2D2003AD669 /* JSSpeechInputResultList.h in Headers */,
+                               0FB6252F18DE1B1500A07C05 /* GeometryUtilities.h in Headers */,
                                AA7FEEAD16A4E74B004C0C33 /* JSSpeechSynthesis.h in Headers */,
                                AA2A5AD216A4860A00976A25 /* JSSpeechSynthesisEvent.h in Headers */,
                                AA7FEEA716A4E6F3004C0C33 /* JSSpeechSynthesisUtterance.h in Headers */,
                                07969DBD17D14151007FF842 /* JSRTCSessionDescriptionCallback.cpp in Sources */,
                                07D07B141834158800ABDD3C /* JSRTCSessionDescriptionCustom.cpp in Sources */,
                                07969DBF17D14151007FF842 /* JSRTCStatsCallback.cpp in Sources */,
+                               0FB6252E18DE1B1500A07C05 /* GeometryUtilities.cpp in Sources */,
                                07969DC117D14151007FF842 /* JSRTCStatsReport.cpp in Sources */,
                                07969DC317D14151007FF842 /* JSRTCStatsResponse.cpp in Sources */,
                                07DC5FD417D3EEE90099F890 /* JSRTCStatsResponseCustom.cpp in Sources */,
index cf50c85..1a13d83 100644 (file)
@@ -24,6 +24,8 @@
 
 #include "CSSPropertyNames.h"
 #include "LengthBox.h"
+#include <wtf/FastMalloc.h>
+#include <wtf/Noncopyable.h>
 
 namespace WebCore {
 
index 31d5ebd..c410d05 100644 (file)
@@ -38,6 +38,7 @@
 #include "ExceptionCode.h"
 #include "Frame.h"
 #include "FrameLoaderClient.h"
+#include "GeometryUtilities.h"
 #include "GraphicsContext.h"
 #include "HTMLNames.h"
 #include "ImageData.h"
index 9b0e0f7..39d2657 100644 (file)
@@ -20,6 +20,7 @@
 #define WidgetBackingStoreCairo_h
 
 #include "WidgetBackingStore.h"
+#include <wtf/RefPtr.h>
 
 namespace WebCore {
 
index 791e03f..95bfea3 100644 (file)
@@ -80,45 +80,6 @@ FloatPoint FloatPoint::narrowPrecision(double x, double y)
     return FloatPoint(narrowPrecisionToFloat(x), narrowPrecisionToFloat(y));
 }
 
-float findSlope(const FloatPoint& p1, const FloatPoint& p2, float& c)
-{
-    if (p2.x() == p1.x())
-        return std::numeric_limits<float>::infinity();
-
-    // y = mx + c
-    float slope = (p2.y() - p1.y()) / (p2.x() - p1.x());
-    c = p1.y() - slope * p1.x();
-    return slope;
-}
-
-bool findIntersection(const FloatPoint& p1, const FloatPoint& p2, const FloatPoint& d1, const FloatPoint& d2, FloatPoint& intersection) 
-{
-    float pOffset = 0;
-    float pSlope = findSlope(p1, p2, pOffset);
-
-    float dOffset = 0;
-    float dSlope = findSlope(d1, d2, dOffset);
-
-    if (dSlope == pSlope)
-        return false;
-    
-    if (pSlope == std::numeric_limits<float>::infinity()) {
-        intersection.setX(p1.x());
-        intersection.setY(dSlope * intersection.x() + dOffset);
-        return true;
-    }
-    if (dSlope == std::numeric_limits<float>::infinity()) {
-        intersection.setX(d1.x());
-        intersection.setY(pSlope * intersection.x() + pOffset);
-        return true;
-    }
-    
-    // Find x at intersection, where ys overlap; x = (c' - c) / (m - m')
-    intersection.setX((dOffset - pOffset) / (pSlope - dSlope));
-    intersection.setY(pSlope * intersection.x() + pOffset);
-    return true;
-}
-
 void FloatPoint::dump(PrintStream& out) const
 {
     out.printf("(%f, %f)", x(), y());
index ddc33dd..5398c0c 100644 (file)
@@ -144,7 +144,7 @@ public:
     FloatPoint matrixTransform(const TransformationMatrix&) const;
     FloatPoint matrixTransform(const AffineTransform&) const;
 
-    void dump(PrintStream& out) const;
+    void dump(WTF::PrintStream& out) const;
 
 private:
     float m_x, m_y;
@@ -235,11 +235,6 @@ inline FloatSize toFloatSize(const FloatPoint& a)
     return FloatSize(a.x(), a.y());
 }
 
-float findSlope(const FloatPoint& p1, const FloatPoint& p2, float& c);
-
-// Find point where lines through the two pairs of points intersect. Returns false if the lines don't intersect.
-bool findIntersection(const FloatPoint& p1, const FloatPoint& p2, const FloatPoint& d1, const FloatPoint& d2, FloatPoint& intersection);
-
 }
 
 #endif
index fe706b7..a7c08e6 100644 (file)
@@ -147,17 +147,6 @@ void FloatRect::scale(float sx, float sy)
     m_size.setHeight(height() * sy);
 }
 
-FloatRect unionRect(const Vector<FloatRect>& rects)
-{
-    FloatRect result;
-
-    size_t count = rects.size();
-    for (size_t i = 0; i < count; ++i)
-        result.unite(rects[i]);
-
-    return result;
-}
-
 void FloatRect::fitToPoints(const FloatPoint& p0, const FloatPoint& p1)
 {
     float left = std::min(p0.x(), p1.x());
@@ -240,18 +229,6 @@ IntRect roundedIntRect(const FloatRect& rect)
     return IntRect(roundedIntPoint(rect.location()), roundedIntSize(rect.size()));
 }
 
-FloatRect mapRect(const FloatRect& r, const FloatRect& srcRect, const FloatRect& destRect)
-{
-    if (srcRect.width() == 0 || srcRect.height() == 0)
-        return FloatRect();
-
-    float widthScale = destRect.width() / srcRect.width();
-    float heightScale = destRect.height() / srcRect.height();
-    return FloatRect(destRect.x() + (r.x() - srcRect.x()) * widthScale,
-                     destRect.y() + (r.y() - srcRect.y()) * heightScale,
-                     r.width() * widthScale, r.height() * heightScale);
-}
-
 void FloatRect::dump(PrintStream& out) const
 {
     out.print(location(), " ", size());
index 11f1ea9..d346dd5 100644 (file)
@@ -28,7 +28,6 @@
 #define FloatRect_h
 
 #include "FloatPoint.h"
-#include <wtf/Vector.h>
 
 #if USE(CG)
 typedef struct CGRect CGRect;
@@ -177,7 +176,7 @@ public:
     operator cairo_rectangle_t() const;
 #endif
 
-    void dump(PrintStream& out) const;
+    void dump(WTF::PrintStream& out) const;
 
     static FloatRect infiniteRect();
     bool isInfinite() const;
@@ -208,8 +207,6 @@ inline FloatRect unionRect(const FloatRect& a, const FloatRect& b)
     return c;
 }
 
-FloatRect unionRect(const Vector<FloatRect>&);
-
 inline FloatRect& operator+=(FloatRect& a, const FloatRect& b)
 {
     a.move(b.x(), b.y());
@@ -253,9 +250,6 @@ IntRect enclosedIntRect(const FloatRect&);
 
 IntRect roundedIntRect(const FloatRect&);
 
-// Map rect r from srcRect to an equivalent rect in destRect.
-FloatRect mapRect(const FloatRect& r, const FloatRect& srcRect, const FloatRect& destRect);
-
 }
 
 #endif
index 6ee4c40..e7eb42d 100644 (file)
@@ -31,6 +31,7 @@
 #include "IntSize.h"
 #include <limits>
 #include <math.h>
+#include <wtf/PrintStream.h>
 
 namespace WebCore {
 
index 232565c..73cc0fe 100644 (file)
@@ -118,7 +118,7 @@ public:
     operator NSSize() const;
 #endif
 
-    void dump(PrintStream& out) const;
+    void dump(WTF::PrintStream& out) const;
 
 private:
     float m_width, m_height;
diff --git a/Source/WebCore/platform/graphics/GeometryUtilities.cpp b/Source/WebCore/platform/graphics/GeometryUtilities.cpp
new file mode 100644 (file)
index 0000000..90c9725
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2014 Apple 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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 "GeometryUtilities.h"
+
+namespace WebCore {
+
+float findSlope(const FloatPoint& p1, const FloatPoint& p2, float& c)
+{
+    if (p2.x() == p1.x())
+        return std::numeric_limits<float>::infinity();
+
+    // y = mx + c
+    float slope = (p2.y() - p1.y()) / (p2.x() - p1.x());
+    c = p1.y() - slope * p1.x();
+    return slope;
+}
+
+bool findIntersection(const FloatPoint& p1, const FloatPoint& p2, const FloatPoint& d1, const FloatPoint& d2, FloatPoint& intersection) 
+{
+    float pOffset = 0;
+    float pSlope = findSlope(p1, p2, pOffset);
+
+    float dOffset = 0;
+    float dSlope = findSlope(d1, d2, dOffset);
+
+    if (dSlope == pSlope)
+        return false;
+    
+    if (pSlope == std::numeric_limits<float>::infinity()) {
+        intersection.setX(p1.x());
+        intersection.setY(dSlope * intersection.x() + dOffset);
+        return true;
+    }
+    if (dSlope == std::numeric_limits<float>::infinity()) {
+        intersection.setX(d1.x());
+        intersection.setY(pSlope * intersection.x() + pOffset);
+        return true;
+    }
+    
+    // Find x at intersection, where ys overlap; x = (c' - c) / (m - m')
+    intersection.setX((dOffset - pOffset) / (pSlope - dSlope));
+    intersection.setY(pSlope * intersection.x() + pOffset);
+    return true;
+}
+
+IntRect unionRect(const Vector<IntRect>& rects)
+{
+    IntRect result;
+
+    size_t count = rects.size();
+    for (size_t i = 0; i < count; ++i)
+        result.unite(rects[i]);
+
+    return result;
+}
+
+FloatRect unionRect(const Vector<FloatRect>& rects)
+{
+    FloatRect result;
+
+    size_t count = rects.size();
+    for (size_t i = 0; i < count; ++i)
+        result.unite(rects[i]);
+
+    return result;
+}
+
+FloatRect mapRect(const FloatRect& r, const FloatRect& srcRect, const FloatRect& destRect)
+{
+    if (!srcRect.width() || !srcRect.height())
+        return FloatRect();
+
+    float widthScale = destRect.width() / srcRect.width();
+    float heightScale = destRect.height() / srcRect.height();
+    return FloatRect(destRect.x() + (r.x() - srcRect.x()) * widthScale,
+        destRect.y() + (r.y() - srcRect.y()) * heightScale,
+        r.width() * widthScale, r.height() * heightScale);
+}
+
+}
diff --git a/Source/WebCore/platform/graphics/GeometryUtilities.h b/Source/WebCore/platform/graphics/GeometryUtilities.h
new file mode 100644 (file)
index 0000000..5e37318
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2014 Apple 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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 GeometryUtilities_h
+#define GeometryUtilities_h
+
+#include "FloatRect.h"
+#include "IntRect.h"
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+float findSlope(const FloatPoint& p1, const FloatPoint& p2, float& c);
+
+// Find point where lines through the two pairs of points intersect. Returns false if the lines don't intersect.
+bool findIntersection(const FloatPoint& p1, const FloatPoint& p2, const FloatPoint& d1, const FloatPoint& d2, FloatPoint& intersection);
+
+IntRect unionRect(const Vector<IntRect>&);
+FloatRect unionRect(const Vector<FloatRect>&);
+
+// Map rect r from srcRect to an equivalent rect in destRect.
+FloatRect mapRect(const FloatRect&, const FloatRect& srcRect, const FloatRect& destRect);
+
+}
+
+#endif // GeometryUtilities_h
index 91997de..09f6d50 100644 (file)
@@ -127,7 +127,7 @@ public:
     operator Evas_Point() const;
 #endif
 
-    void dump(PrintStream& out) const;
+    void dump(WTF::PrintStream& out) const;
 
 private:
     int m_x, m_y;
index 0e8ff97..78e0d57 100644 (file)
@@ -146,17 +146,6 @@ IntSize IntRect::differenceToPoint(const IntPoint& point) const
     return IntSize(xdistance, ydistance);
 }
 
-IntRect unionRect(const Vector<IntRect>& rects)
-{
-    IntRect result;
-
-    size_t count = rects.size();
-    for (size_t i = 0; i < count; ++i)
-        result.unite(rects[i]);
-
-    return result;
-}
-
 void IntRect::dump(PrintStream& out) const
 {
     out.print(location(), " ", size());
index 4606b0e..bf02379 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "IntPoint.h"
 #include "LayoutUnit.h"
-#include <wtf/Vector.h>
 
 #if USE(CG)
 typedef struct CGRect CGRect;
@@ -197,7 +196,7 @@ public:
     operator NSRect() const;
 #endif
 
-    void dump(PrintStream& out) const;
+    void dump(WTF::PrintStream& out) const;
 
     static IntRect infiniteRect();
     bool isInfinite() const;
@@ -221,8 +220,6 @@ inline IntRect unionRect(const IntRect& a, const IntRect& b)
     return c;
 }
 
-IntRect unionRect(const Vector<IntRect>&);
-
 inline bool operator==(const IntRect& a, const IntRect& b)
 {
     return a.location() == b.location() && a.size() == b.size();
index 7c5b58c..9b54fb6 100644 (file)
@@ -27,7 +27,6 @@
 #define IntSize_h
 
 #include <algorithm>
-#include <wtf/PrintStream.h>
 
 #if USE(CG)
 typedef struct CGSize CGSize;
@@ -51,6 +50,10 @@ typedef struct _NSSize NSSize;
 typedef struct tagSIZE SIZE;
 #endif
 
+namespace WTF {
+class PrintStream;
+}
+
 namespace WebCore {
 
 class IntSize {
@@ -139,7 +142,7 @@ public:
     operator SIZE() const;
 #endif
 
-    void dump(PrintStream& out) const;
+    void dump(WTF::PrintStream& out) const;
 
 private:
     int m_width, m_height;
index 9e1c83b..f4b3831 100644 (file)
@@ -31,6 +31,7 @@
 #include "IntRect.h"
 #include "PlatformLayer.h"
 #include <wtf/PassOwnPtr.h>
+#include <wtf/PassRefPtr.h>
 
 namespace WebCore {
 
index fa25ca2..500dbac 100644 (file)
@@ -26,6 +26,7 @@
 #include "IntPointHash.h"
 #include "IntRect.h"
 #include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
 
 namespace WebCore {
 
index 32530b3..cf86782 100644 (file)
@@ -24,6 +24,8 @@
 #include "AreaAllocator.h"
 #include "CoordinatedSurface.h"
 #include "IntSize.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
 
 #if USE(COORDINATED_GRAPHICS)
 
index 62b87df..7a4b11f 100644 (file)
@@ -20,6 +20,7 @@
 #define WidgetBackingStoreGtkX11_h
 
 #include "WidgetBackingStore.h"
+#include <wtf/RefPtr.h>
 
 #include <X11/Xlib.h>
 
index 726da60..08dba7d 100644 (file)
@@ -30,6 +30,7 @@
 #include "FloatRoundedRect.h"
 #include "Frame.h"
 #include "FrameView.h"
+#include "GeometryUtilities.h"
 #include "GraphicsContext.h"
 #include "HTMLFrameOwnerElement.h"
 #include "HTMLNames.h"
index c18668d..fc64df9 100644 (file)
@@ -34,6 +34,7 @@
 #include "FontCache.h"
 #include "Frame.h"
 #include "FrameSelection.h"
+#include "GeometryUtilities.h"
 #include "GraphicsContext.h"
 #include "HTMLAreaElement.h"
 #include "HTMLImageElement.h"
index d6269b2..00b9ba9 100644 (file)
@@ -35,6 +35,7 @@
 #include "Frame.h"
 #include "FrameSelection.h"
 #include "FrameView.h"
+#include "GeometryUtilities.h"
 #include "GraphicsContext.h"
 #include "HTMLAnchorElement.h"
 #include "HTMLElement.h"
index 30ac212..d3c9510 100644 (file)
@@ -1,3 +1,22 @@
+2014-03-23  Simon Fraser  <simon.fraser@apple.com>
+
+        Clean up #includes by geometry classes
+        https://bugs.webkit.org/show_bug.cgi?id=130645
+
+        Reviewed by Andreas Kling.
+
+        Pulling in <wtf/Vector.h> and <wtf/PrintStream.h> in the simple geometry
+        classes brings in a lot of additional headers. Fix by adding a new
+        GeometryUtilities file so that the basic files don't need Vector,
+        and including GeometryUtilities.h where necessary.
+        
+        Also forward declare PrintStream.h and only bring in the header
+        in implementation files.
+
+        * UIProcess/BackingStore.h:
+        * UIProcess/FindIndicator.cpp:
+        * UIProcess/mac/WKPrintingView.h:
+
 2014-03-22  Alexey Proskuryakov  <ap@apple.com>
 
         Assertions in WebPage::rangeFromEditingRange when requested range location is NSNotFound
index d4c110d..e00af83 100644 (file)
@@ -29,6 +29,7 @@
 #include "ShareableBitmap.h"
 #include <WebCore/IntRect.h>
 #include <wtf/Noncopyable.h>
+#include <wtf/Vector.h>
 
 namespace IPC {
     class ArgumentDecoder;
index 0a9fe9a..9786050 100644 (file)
@@ -32,6 +32,7 @@
 #if USE(CAIRO)
 #include <RefPtrCairo.h>
 #include <WebCore/WidgetBackingStore.h>
+#include <wtf/OwnPtr.h>
 #endif
 
 namespace WebKit {
index 3164efd..fe29327 100644 (file)
@@ -26,6 +26,7 @@
 #include <WebCore/FloatRect.h>
 #include <WebCore/FloatSize.h>
 #include <WebCore/ViewportArguments.h>
+#include <wtf/Noncopyable.h>
 
 namespace WebCore {
 class IntPoint;
index 2ad193f..950373e 100644 (file)
@@ -27,6 +27,7 @@
 #include "FindIndicator.h"
 
 #include "ShareableBitmap.h"
+#include <WebCore/GeometryUtilities.h>
 #include <WebCore/Gradient.h>
 #include <WebCore/GraphicsContext.h>
 #include <WebCore/IntRect.h>
index 85e6a1a..c8c7c44 100644 (file)
@@ -28,6 +28,7 @@
 #import <WebCore/IntRectHash.h>
 #import <condition_variable>
 #import <wtf/RetainPtr.h>
+#import <wtf/Vector.h>
 
 @class WKPrintingViewData;
 @class PDFDocument;