Reviewed by Eric.
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Apr 2006 17:05:49 +0000 (17:05 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Apr 2006 17:05:49 +0000 (17:05 +0000)
        - http://bugzilla.opendarwin.org/show_bug.cgi?id=8608
          make GraphicsContext more suitable for cross-platform use, step 2

        - Changed GraphicsContext to use NSGraphicsContext as little as possible.
        - Removed the printing flag from GraphicsContext.
        - Changed GraphicsContext to assume the NSGraphicsContext is always flipped,
          and got rid of parameters to pass the flipped boolean around.

        * WebCore.vcproj/WebCore/WebCore.vcproj: Add GraphicsTypes.h/cpp and remove
        CompositeOperator.h/cpp.
        * WebCore.xcodeproj/project.pbxproj: Ditto.

        * bridge/mac/FrameMac.mm: (WebCore::FrameMac::setDisplaysWithFocusAttributes):
        * bridge/mac/WebCoreFrameBridge.mm: (-[WebCoreFrameBridge drawRect:]):
        * html/CanvasPattern.cpp: (WebCore::patternCallback):
        * html/HTMLCanvasElement.cpp: (WebCore::HTMLCanvasElement::createDrawingContext):
        * kcanvas/device/quartz/KRenderingDeviceQuartz.mm:
        (WebCore::KRenderingDeviceContextQuartz::createGraphicsContext):
        * platform/mac/WidgetMac.mm: (WebCore::Widget::lockDrawingFocus):
        Update for changes to GraphicsContext constructor (no flipped or printing boolean).

        * html/CanvasRenderingContext2D.h: Added a Path to the context state. Changed the
        LineCap and LineJoin types to use the new ones in GraphicsTypes.h instead of defining
        types here in this class. Changed m_platformContextStrokeStyleIsPattern and
        m_platformContextFillStyleIsPattern to be named m_appliedStrokePattern and
        m_appliedFillPattern and moved them outside the __APPLE__ ifdefs. Removed the
        platformContext() function. Moved applyStrokePattern and applyFillPattern out of
        the __APPLE__ ifdef.

        * html/CanvasRenderingContext2D.cpp:
        (WebCore::CanvasRenderingContext2D::State::State): Moved the stroke pattern
        booleans out of Mac-specific ifdef.
        (WebCore::CanvasRenderingContext2D::save): Changed to use GraphicsContext instead
        of using CGContext directly.
        (WebCore::CanvasRenderingContext2D::restore): Ditto.
        (WebCore::CanvasRenderingContext2D::setStrokeStyle): Ditto.
        (WebCore::CanvasRenderingContext2D::setFillStyle): Ditto.
        (WebCore::CanvasRenderingContext2D::setLineWidth): Ditto.
        (WebCore::CanvasRenderingContext2D::lineCap): Ditto.
        (WebCore::CanvasRenderingContext2D::setLineCap): Ditto.
        (WebCore::CanvasRenderingContext2D::lineJoin): Ditto.
        (WebCore::CanvasRenderingContext2D::setLineJoin): Ditto.
        (WebCore::CanvasRenderingContext2D::setMiterLimit): Ditto.
        (WebCore::CanvasRenderingContext2D::shadowColor): Ditto.
        (WebCore::CanvasRenderingContext2D::setGlobalAlpha): Ditto.
        (WebCore::CanvasRenderingContext2D::setGlobalCompositeOperation): Ditto.
        (WebCore::CanvasRenderingContext2D::scale): Update since platformContext() function
        no longer exists.
        (WebCore::CanvasRenderingContext2D::rotate): Ditto.
        (WebCore::CanvasRenderingContext2D::translate): Ditto.
        (WebCore::CanvasRenderingContext2D::beginPath): Changed to use GraphicsContext instead
        of using CGContext directly.
        (WebCore::CanvasRenderingContext2D::closePath): Ditto.
        (WebCore::CanvasRenderingContext2D::moveTo): Ditto.
        (WebCore::CanvasRenderingContext2D::lineTo): Ditto.
        (WebCore::CanvasRenderingContext2D::quadraticCurveTo): Ditto.
        (WebCore::CanvasRenderingContext2D::bezierCurveTo): Ditto.
        (WebCore::CanvasRenderingContext2D::arcTo): Ditto.
        (WebCore::CanvasRenderingContext2D::arc): Ditto.
        (WebCore::CanvasRenderingContext2D::rect): Ditto.
        (WebCore::CanvasRenderingContext2D::fill): Changed to use the current path from this class
        instead of relying on the CGContext's current path.
        (WebCore::CanvasRenderingContext2D::stroke): Ditto.
        (WebCore::CanvasRenderingContext2D::clip): Changed to use the current path and use the
        GraphicsContext instead of using CGContext directly.
        (WebCore::CanvasRenderingContext2D::clearRect): Changed to use GraphicsContext instead
        of using CGContext directly.
        (WebCore::CanvasRenderingContext2D::fillRect): Update since platformContext() function
        no longer exists.
        (WebCore::CanvasRenderingContext2D::strokeRect): Ditto.
        (WebCore::CanvasRenderingContext2D::setShadow): Ditto.
        (WebCore::CanvasRenderingContext2D::applyShadow): Ditto.
        (WebCore::CanvasRenderingContext2D::drawImage): Ditto.
        (WebCore::CanvasRenderingContext2D::drawImageFromRect): Ditto.
        (WebCore::CanvasRenderingContext2D::createPattern): Ditto.
        (WebCore::CanvasRenderingContext2D::applyStrokePattern): Made a tiny bit of this function
        cross-platform. The bulk is still Mac-specific.
        (WebCore::CanvasRenderingContext2D::applyFillPattern): Ditto.

        * html/CanvasStyle.h: Changed to use GraphicsContext instead of CGContext. Now the
        platform-specific stuff is in the implementation, not the header.
        * html/CanvasStyle.cpp:
        (WebCore::CanvasStyle::applyStrokeColor): Moved the ifdefs inside the function, getting
        us one step closer to platform independence.
        (WebCore::CanvasStyle::applyFillColor): Ditto.

        * html/html_imageimpl.cpp:
        (WebCore::HTMLAreaElement::getRect): Update for changes to the Path class.
        (WebCore::HTMLAreaElement::getRegion): Ditto.

        * page/Frame.cpp:
        (WebCore::Frame::paint): Change to check printing flag on the document, rather than on
        the GraphicsContext, since there is no printing flag for GraphicsContext any more.
        (WebCore::Frame::adjustPageHeight): Update for change to GraphicsContext constructor.

        * platform/GraphicsContext.h: Define a type called PlatformGraphicsContext so the
        platform-specific getter and constructor don't have to be ifdef'd. Added clearRect,
        strokeRect, setLineWidth, setLineCap, setLineJoin, setMiterLimit, setAlpha, setCompositeOperation,
        and clip functions. Removed the isForPrinting parameter from createGraphicsContextPrivate.
        * platform/GraphicsContext.cpp:
        (WebCore::GraphicsContextPrivate::GraphicsContextPrivate): Removed isForPrinting.
        (WebCore::GraphicsContext::createGraphicsContextPrivate): Ditto.
        * platform/mac/GraphicsContextMac.mm:
        (WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate):
        Removed NSGraphicsContext.
        (WebCore::GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate):
        Ditto.
        (WebCore::GraphicsContext::GraphicsContext): Removed constructor that
        takes an NSGraphicsContext. Removed the flipText and forPrinting parameters
        to the other constructor.
        (WebCore::GraphicsContext::savePlatformState): Removed NSGraphicsContext code.
        (WebCore::GraphicsContext::restorePlatformState): Ditto.
        (WebCore::GraphicsContext::drawRect): Updated assertion to more-precisely
        reflect the limitation of the current version of this function.
        (WebCore::GraphicsContext::setColorFromFillColor): Ditto.
        (WebCore::GraphicsContext::setColorFromPen): Ditto.
        (WebCore::GraphicsContext::drawLine): Updated assertion to more-precisely
        reflect the limitation of the current version of this function.
        (WebCore::setCompositeOperation):
        (WebCore::GraphicsContext::fillRect): Ditto.
        (WebCore::GraphicsContext::setLineWidth): Added.
        (WebCore::GraphicsContext::setMiterLimit): Added.
        (WebCore::GraphicsContext::setAlpha): Added.
        (WebCore::GraphicsContext::setCompositeOperation): Added.
        (WebCore::GraphicsContext::clearRect): Added.
        (WebCore::GraphicsContext::strokeRect): Added.
        (WebCore::GraphicsContext::setLineCap): Added.
        (WebCore::GraphicsContext::setLineJoin): Added.
        (WebCore::GraphicsContext::clip): Added.

        * platform/CompositeOperator.cpp: Removed.
        * platform/CompositeOperator.h: Removed.
        * platform/GraphicsTypes.cpp: Added. Includes CompositeOperator, LineCap, and LineJoin.
        * platform/GraphicsTypes.h: Added.

        * platform/Image.h: Changed include to GraphicsTypes.h from CompositeOperator.h.

        * platform/Path.h: Removed constructors that take a Rect and an array of points. Made
        the Path mutable. Changed the types for contains and boundingRect to be float-based
        instead of int-based. Changed translate to take a FloatSize instead of two integers.
        Added clear, moveTo, addLineTo, addQuadCurveTo, addBezierCurveTo, addArcTo, closeSubpath,
        addArc, addRect, addEllipse, and platformPath functions. Defined a PlatformPath type
        so we don't have to ifdef the header so much.
        * platform/cg/PathCG.cpp:
        (WebCore::Path::Path): Changed class to always have a mutable path.
        (WebCore::Path::operator=): Changed to make a mutable copy.
        (WebCore::Path::contains): Changed to take a FloatPoint instead of IntPoint.
        (WebCore::Path::translate): Changed to use a FloatSize instead of two ints.
        (WebCore::Path::boundingRect): Changed to return a FloatRect.
        (WebCore::Path::moveTo): Added.
        (WebCore::Path::addLineTo): Added.
        (WebCore::Path::addQuadCurveTo): Added.
        (WebCore::Path::addBezierCurveTo): Added.
        (WebCore::Path::addArcTo): Added.
        (WebCore::Path::closeSubpath): Added.
        (WebCore::Path::addArc): Added.
        (WebCore::Path::addRect): Added.
        (WebCore::Path::addEllipse): Added.
        (WebCore::Path::clear): Added.

        * platform/mac/ImageMac.mm:
        (WebCore::fillSolidColorInRect): Changed to take a GraphicsContext instead of
        a CGContext.
        (WebCore::Image::checkForSolidColor): Changed to use the new setCompositeOperation
        in GraphicsContex.
        (WebCore::Image::draw): Changed to use the new PDF image and fillSolidColorInRect
        function that take GraphicsContext instead of CGContext.
        (WebCore::Image::drawTiled): Ditto.

        * platform/mac/PDFDocumentImage.h: Made most functions private. Changed to
        use GraphicsContext and FloatRect instead of CGContext and NSRect. Also
        removed the unused alpha and flipped booleans.
        * platform/mac/PDFDocumentImage.mm:
        (WebCore::PDFDocumentImage::bounds): Update for change in types.
        (WebCore::PDFDocumentImage::adjustCTM): Ditto.
        (WebCore::PDFDocumentImage::setCurrentPage): Ditto.
        (WebCore::PDFDocumentImage::draw): Ditto.

        * platform/win/TemporaryLinkStubs.cpp: Added lots of new stubs.

        * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paint): Changed to get
        printing boolean from document instead graphics context.
        * rendering/RenderBlock.cpp:
        (WebCore::RenderBlock::paintChildren): Ditto.
        (WebCore::RenderBlock::paintObject): Ditto.
        * rendering/RenderFlow.cpp: (WebCore::RenderFlow::paintLines): Ditto.
        * rendering/RenderHTMLCanvas.cpp: (WebCore::RenderHTMLCanvas::paint): Ditto.
        * rendering/RenderImage.cpp: (WebCore::RenderImage::paint): Ditto.
        * rendering/RenderThemeMac.mm: (WebCore::RenderThemeMac::paintButton): Ditto.
        * rendering/render_list.cpp: (WebCore::RenderListMarker::paint): Ditto.
        * rendering/render_replaced.cpp: (WebCore::RenderWidget::paint): Ditto.

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

36 files changed:
WebCore/ChangeLog
WebCore/WebCore.vcproj/WebCore/WebCore.vcproj
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/bridge/mac/FrameMac.mm
WebCore/bridge/mac/WebCoreFrameBridge.mm
WebCore/html/CanvasPattern.cpp
WebCore/html/CanvasRenderingContext2D.cpp
WebCore/html/CanvasRenderingContext2D.h
WebCore/html/CanvasStyle.cpp
WebCore/html/CanvasStyle.h
WebCore/html/HTMLCanvasElement.cpp
WebCore/html/html_imageimpl.cpp
WebCore/kcanvas/device/quartz/KRenderingDeviceQuartz.mm
WebCore/page/Frame.cpp
WebCore/platform/GraphicsContext.cpp
WebCore/platform/GraphicsContext.h
WebCore/platform/GraphicsTypes.cpp [moved from WebCore/platform/CompositeOperator.cpp with 62% similarity]
WebCore/platform/GraphicsTypes.h [moved from WebCore/platform/CompositeOperator.h with 87% similarity]
WebCore/platform/Image.cpp
WebCore/platform/Image.h
WebCore/platform/Path.h
WebCore/platform/cg/PathCG.cpp
WebCore/platform/mac/GraphicsContextMac.mm
WebCore/platform/mac/ImageMac.mm
WebCore/platform/mac/PDFDocumentImage.h
WebCore/platform/mac/PDFDocumentImage.mm
WebCore/platform/mac/WidgetMac.mm
WebCore/platform/win/TemporaryLinkStubs.cpp
WebCore/rendering/InlineTextBox.cpp
WebCore/rendering/RenderBlock.cpp
WebCore/rendering/RenderFlow.cpp
WebCore/rendering/RenderHTMLCanvas.cpp
WebCore/rendering/RenderImage.cpp
WebCore/rendering/RenderThemeMac.mm
WebCore/rendering/render_list.cpp
WebCore/rendering/render_replaced.cpp

index 9ad9fe28365ba7f69fb067c98ee2e201788d7f79..bc803fe98908dcdf230e5525e4378e9fd9900ab4 100644 (file)
@@ -1,3 +1,199 @@
+2006-04-28  Darin Adler  <darin@apple.com>
+
+        Reviewed by Eric.
+
+        - http://bugzilla.opendarwin.org/show_bug.cgi?id=8608
+          make GraphicsContext more suitable for cross-platform use, step 2
+
+        - Changed GraphicsContext to use NSGraphicsContext as little as possible.
+        - Removed the printing flag from GraphicsContext.
+        - Changed GraphicsContext to assume the NSGraphicsContext is always flipped,
+          and got rid of parameters to pass the flipped boolean around.
+
+        * WebCore.vcproj/WebCore/WebCore.vcproj: Add GraphicsTypes.h/cpp and remove
+        CompositeOperator.h/cpp.
+        * WebCore.xcodeproj/project.pbxproj: Ditto.
+
+        * bridge/mac/FrameMac.mm: (WebCore::FrameMac::setDisplaysWithFocusAttributes):
+        * bridge/mac/WebCoreFrameBridge.mm: (-[WebCoreFrameBridge drawRect:]):
+        * html/CanvasPattern.cpp: (WebCore::patternCallback):
+        * html/HTMLCanvasElement.cpp: (WebCore::HTMLCanvasElement::createDrawingContext):
+        * kcanvas/device/quartz/KRenderingDeviceQuartz.mm:
+        (WebCore::KRenderingDeviceContextQuartz::createGraphicsContext):
+        * platform/mac/WidgetMac.mm: (WebCore::Widget::lockDrawingFocus):
+        Update for changes to GraphicsContext constructor (no flipped or printing boolean).
+
+        * html/CanvasRenderingContext2D.h: Added a Path to the context state. Changed the
+        LineCap and LineJoin types to use the new ones in GraphicsTypes.h instead of defining
+        types here in this class. Changed m_platformContextStrokeStyleIsPattern and
+        m_platformContextFillStyleIsPattern to be named m_appliedStrokePattern and
+        m_appliedFillPattern and moved them outside the __APPLE__ ifdefs. Removed the
+        platformContext() function. Moved applyStrokePattern and applyFillPattern out of
+        the __APPLE__ ifdef.
+
+        * html/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::State::State): Moved the stroke pattern
+        booleans out of Mac-specific ifdef.
+        (WebCore::CanvasRenderingContext2D::save): Changed to use GraphicsContext instead
+        of using CGContext directly.
+        (WebCore::CanvasRenderingContext2D::restore): Ditto.
+        (WebCore::CanvasRenderingContext2D::setStrokeStyle): Ditto.
+        (WebCore::CanvasRenderingContext2D::setFillStyle): Ditto.
+        (WebCore::CanvasRenderingContext2D::setLineWidth): Ditto.
+        (WebCore::CanvasRenderingContext2D::lineCap): Ditto.
+        (WebCore::CanvasRenderingContext2D::setLineCap): Ditto.
+        (WebCore::CanvasRenderingContext2D::lineJoin): Ditto.
+        (WebCore::CanvasRenderingContext2D::setLineJoin): Ditto.
+        (WebCore::CanvasRenderingContext2D::setMiterLimit): Ditto.
+        (WebCore::CanvasRenderingContext2D::shadowColor): Ditto.
+        (WebCore::CanvasRenderingContext2D::setGlobalAlpha): Ditto.
+        (WebCore::CanvasRenderingContext2D::setGlobalCompositeOperation): Ditto.
+        (WebCore::CanvasRenderingContext2D::scale): Update since platformContext() function
+        no longer exists.
+        (WebCore::CanvasRenderingContext2D::rotate): Ditto.
+        (WebCore::CanvasRenderingContext2D::translate): Ditto.
+        (WebCore::CanvasRenderingContext2D::beginPath): Changed to use GraphicsContext instead
+        of using CGContext directly.
+        (WebCore::CanvasRenderingContext2D::closePath): Ditto.
+        (WebCore::CanvasRenderingContext2D::moveTo): Ditto.
+        (WebCore::CanvasRenderingContext2D::lineTo): Ditto.
+        (WebCore::CanvasRenderingContext2D::quadraticCurveTo): Ditto.
+        (WebCore::CanvasRenderingContext2D::bezierCurveTo): Ditto.
+        (WebCore::CanvasRenderingContext2D::arcTo): Ditto.
+        (WebCore::CanvasRenderingContext2D::arc): Ditto.
+        (WebCore::CanvasRenderingContext2D::rect): Ditto.
+        (WebCore::CanvasRenderingContext2D::fill): Changed to use the current path from this class
+        instead of relying on the CGContext's current path.
+        (WebCore::CanvasRenderingContext2D::stroke): Ditto.
+        (WebCore::CanvasRenderingContext2D::clip): Changed to use the current path and use the
+        GraphicsContext instead of using CGContext directly.
+        (WebCore::CanvasRenderingContext2D::clearRect): Changed to use GraphicsContext instead
+        of using CGContext directly.
+        (WebCore::CanvasRenderingContext2D::fillRect): Update since platformContext() function
+        no longer exists.
+        (WebCore::CanvasRenderingContext2D::strokeRect): Ditto.
+        (WebCore::CanvasRenderingContext2D::setShadow): Ditto.
+        (WebCore::CanvasRenderingContext2D::applyShadow): Ditto.
+        (WebCore::CanvasRenderingContext2D::drawImage): Ditto.
+        (WebCore::CanvasRenderingContext2D::drawImageFromRect): Ditto.
+        (WebCore::CanvasRenderingContext2D::createPattern): Ditto.
+        (WebCore::CanvasRenderingContext2D::applyStrokePattern): Made a tiny bit of this function
+        cross-platform. The bulk is still Mac-specific.
+        (WebCore::CanvasRenderingContext2D::applyFillPattern): Ditto.
+
+        * html/CanvasStyle.h: Changed to use GraphicsContext instead of CGContext. Now the
+        platform-specific stuff is in the implementation, not the header.
+        * html/CanvasStyle.cpp:
+        (WebCore::CanvasStyle::applyStrokeColor): Moved the ifdefs inside the function, getting
+        us one step closer to platform independence.
+        (WebCore::CanvasStyle::applyFillColor): Ditto.
+
+        * html/html_imageimpl.cpp:
+        (WebCore::HTMLAreaElement::getRect): Update for changes to the Path class.
+        (WebCore::HTMLAreaElement::getRegion): Ditto.
+
+        * page/Frame.cpp:
+        (WebCore::Frame::paint): Change to check printing flag on the document, rather than on
+        the GraphicsContext, since there is no printing flag for GraphicsContext any more.
+        (WebCore::Frame::adjustPageHeight): Update for change to GraphicsContext constructor.
+
+        * platform/GraphicsContext.h: Define a type called PlatformGraphicsContext so the
+        platform-specific getter and constructor don't have to be ifdef'd. Added clearRect,
+        strokeRect, setLineWidth, setLineCap, setLineJoin, setMiterLimit, setAlpha, setCompositeOperation,
+        and clip functions. Removed the isForPrinting parameter from createGraphicsContextPrivate.
+        * platform/GraphicsContext.cpp:
+        (WebCore::GraphicsContextPrivate::GraphicsContextPrivate): Removed isForPrinting.
+        (WebCore::GraphicsContext::createGraphicsContextPrivate): Ditto.
+        * platform/mac/GraphicsContextMac.mm:
+        (WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate):
+        Removed NSGraphicsContext.
+        (WebCore::GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate):
+        Ditto.
+        (WebCore::GraphicsContext::GraphicsContext): Removed constructor that
+        takes an NSGraphicsContext. Removed the flipText and forPrinting parameters
+        to the other constructor.
+        (WebCore::GraphicsContext::savePlatformState): Removed NSGraphicsContext code.
+        (WebCore::GraphicsContext::restorePlatformState): Ditto.
+        (WebCore::GraphicsContext::drawRect): Updated assertion to more-precisely
+        reflect the limitation of the current version of this function.
+        (WebCore::GraphicsContext::setColorFromFillColor): Ditto.
+        (WebCore::GraphicsContext::setColorFromPen): Ditto.
+        (WebCore::GraphicsContext::drawLine): Updated assertion to more-precisely
+        reflect the limitation of the current version of this function.
+        (WebCore::setCompositeOperation):
+        (WebCore::GraphicsContext::fillRect): Ditto.
+        (WebCore::GraphicsContext::setLineWidth): Added.
+        (WebCore::GraphicsContext::setMiterLimit): Added.
+        (WebCore::GraphicsContext::setAlpha): Added.
+        (WebCore::GraphicsContext::setCompositeOperation): Added.
+        (WebCore::GraphicsContext::clearRect): Added.
+        (WebCore::GraphicsContext::strokeRect): Added.
+        (WebCore::GraphicsContext::setLineCap): Added.
+        (WebCore::GraphicsContext::setLineJoin): Added.
+        (WebCore::GraphicsContext::clip): Added.
+
+        * platform/CompositeOperator.cpp: Removed.
+        * platform/CompositeOperator.h: Removed.
+        * platform/GraphicsTypes.cpp: Added. Includes CompositeOperator, LineCap, and LineJoin.
+        * platform/GraphicsTypes.h: Added.
+
+        * platform/Image.h: Changed include to GraphicsTypes.h from CompositeOperator.h.
+
+        * platform/Path.h: Removed constructors that take a Rect and an array of points. Made
+        the Path mutable. Changed the types for contains and boundingRect to be float-based
+        instead of int-based. Changed translate to take a FloatSize instead of two integers.
+        Added clear, moveTo, addLineTo, addQuadCurveTo, addBezierCurveTo, addArcTo, closeSubpath,
+        addArc, addRect, addEllipse, and platformPath functions. Defined a PlatformPath type
+        so we don't have to ifdef the header so much.
+        * platform/cg/PathCG.cpp:
+        (WebCore::Path::Path): Changed class to always have a mutable path.
+        (WebCore::Path::operator=): Changed to make a mutable copy.
+        (WebCore::Path::contains): Changed to take a FloatPoint instead of IntPoint.
+        (WebCore::Path::translate): Changed to use a FloatSize instead of two ints.
+        (WebCore::Path::boundingRect): Changed to return a FloatRect.
+        (WebCore::Path::moveTo): Added.
+        (WebCore::Path::addLineTo): Added.
+        (WebCore::Path::addQuadCurveTo): Added.
+        (WebCore::Path::addBezierCurveTo): Added.
+        (WebCore::Path::addArcTo): Added.
+        (WebCore::Path::closeSubpath): Added.
+        (WebCore::Path::addArc): Added.
+        (WebCore::Path::addRect): Added.
+        (WebCore::Path::addEllipse): Added.
+        (WebCore::Path::clear): Added.
+
+        * platform/mac/ImageMac.mm:
+        (WebCore::fillSolidColorInRect): Changed to take a GraphicsContext instead of
+        a CGContext.
+        (WebCore::Image::checkForSolidColor): Changed to use the new setCompositeOperation
+        in GraphicsContex.
+        (WebCore::Image::draw): Changed to use the new PDF image and fillSolidColorInRect
+        function that take GraphicsContext instead of CGContext.
+        (WebCore::Image::drawTiled): Ditto.
+
+        * platform/mac/PDFDocumentImage.h: Made most functions private. Changed to
+        use GraphicsContext and FloatRect instead of CGContext and NSRect. Also
+        removed the unused alpha and flipped booleans.
+        * platform/mac/PDFDocumentImage.mm:
+        (WebCore::PDFDocumentImage::bounds): Update for change in types.
+        (WebCore::PDFDocumentImage::adjustCTM): Ditto.
+        (WebCore::PDFDocumentImage::setCurrentPage): Ditto.
+        (WebCore::PDFDocumentImage::draw): Ditto.
+
+        * platform/win/TemporaryLinkStubs.cpp: Added lots of new stubs.
+
+        * rendering/InlineTextBox.cpp: (WebCore::InlineTextBox::paint): Changed to get
+        printing boolean from document instead graphics context.
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::paintChildren): Ditto.
+        (WebCore::RenderBlock::paintObject): Ditto.
+        * rendering/RenderFlow.cpp: (WebCore::RenderFlow::paintLines): Ditto.
+        * rendering/RenderHTMLCanvas.cpp: (WebCore::RenderHTMLCanvas::paint): Ditto.
+        * rendering/RenderImage.cpp: (WebCore::RenderImage::paint): Ditto.
+        * rendering/RenderThemeMac.mm: (WebCore::RenderThemeMac::paintButton): Ditto.
+        * rendering/render_list.cpp: (WebCore::RenderListMarker::paint): Ditto.
+        * rendering/render_replaced.cpp: (WebCore::RenderWidget::paint): Ditto.
+
 2006-04-28  Mitz Pettel  <opendarwin.org@mitzpettel.com>
 
         Reviewed by hyatt, landed by ap.
index c600186f3b8597fab5622ba8b2bdbe6b0fcf6678..e608199a9ac7dff65fb56ead8c7632d4b9b7dcd5 100644 (file)
                                RelativePath="..\..\platform\CookieJar.h"\r
                                >\r
                        </File>\r
-                       <File\r
-                               RelativePath="..\..\platform\CompositeOperator.h"\r
-                               >\r
-                       </File>\r
-                       <File\r
-                               RelativePath="..\..\platform\CompositeOperator.cpp"\r
-                               >\r
-                       </File>\r
                        <File\r
                                RelativePath="..\..\platform\Cursor.h"\r
                                >\r
                                RelativePath="..\..\platform\GraphicsContext.h"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\..\platform\GraphicsTypes.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\platform\GraphicsTypes.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="..\..\platform\Image.cpp"\r
                                >\r
index 26d94836821ff4329cd0d0cfa5d6aca4c205ceb6..a6c4643d7827c180abfb329b27e87df2a0c2ba7a 100644 (file)
                938E65F709F0985D008A48EC /* JSHTMLElementWrapperFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 938E65F609F0985D008A48EC /* JSHTMLElementWrapperFactory.cpp */; };
                938E666009F09B81008A48EC /* JSHTMLCanvasElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 938E665F09F09B81008A48EC /* JSHTMLCanvasElement.cpp */; };
                938E666209F09B87008A48EC /* JSHTMLCanvasElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 938E666109F09B87008A48EC /* JSHTMLCanvasElement.h */; };
-               938E683C09F0BD7B008A48EC /* CompositeOperator.h in Headers */ = {isa = PBXBuildFile; fileRef = 938E683B09F0BD7A008A48EC /* CompositeOperator.h */; };
-               938E685409F0BE04008A48EC /* CompositeOperator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 938E685309F0BE04008A48EC /* CompositeOperator.cpp */; };
+               938E683C09F0BD7B008A48EC /* GraphicsTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 938E683B09F0BD7A008A48EC /* GraphicsTypes.h */; };
+               938E685409F0BE04008A48EC /* GraphicsTypes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 938E685309F0BE04008A48EC /* GraphicsTypes.cpp */; };
                939885C308B7E3D100E707C4 /* EventNames.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 939885C108B7E3D100E707C4 /* EventNames.cpp */; };
                939885C408B7E3D100E707C4 /* EventNames.h in Headers */ = {isa = PBXBuildFile; fileRef = 939885C208B7E3D100E707C4 /* EventNames.h */; };
                93B70D5B09EB0C7C009D8468 /* JSDOMParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93B70D3F09EB0C7C009D8468 /* JSDOMParser.cpp */; };
                938E662509F09956008A48EC /* HTMLCanvasElement.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = HTMLCanvasElement.idl; sourceTree = "<group>"; };
                938E665F09F09B81008A48EC /* JSHTMLCanvasElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLCanvasElement.cpp; sourceTree = "<group>"; };
                938E666109F09B87008A48EC /* JSHTMLCanvasElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSHTMLCanvasElement.h; sourceTree = "<group>"; };
-               938E683B09F0BD7A008A48EC /* CompositeOperator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompositeOperator.h; sourceTree = "<group>"; };
-               938E685309F0BE04008A48EC /* CompositeOperator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CompositeOperator.cpp; sourceTree = "<group>"; };
+               938E683B09F0BD7A008A48EC /* GraphicsTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsTypes.h; sourceTree = "<group>"; };
+               938E685309F0BE04008A48EC /* GraphicsTypes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsTypes.cpp; sourceTree = "<group>"; };
                9394E0A403AA5BBE008635CE /* KWQPageState.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = KWQPageState.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                9394E0A503AA5BBE008635CE /* KWQPageState.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = KWQPageState.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                93955A4103D72932008635CE /* RenderTreeAsText.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = RenderTreeAsText.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                                BCC8CFC80986CD2400140BF2 /* Color.cpp */,
                                BCC8CFC90986CD2400140BF2 /* Color.h */,
                                BCC8CFCA0986CD2400140BF2 /* ColorData.gperf */,
-                               938E685309F0BE04008A48EC /* CompositeOperator.cpp */,
-                               938E683B09F0BD7A008A48EC /* CompositeOperator.h */,
                                9352088109BD45E900F2038D /* CookieJar.h */,
                                F587868402DE3B8601EA4122 /* Cursor.h */,
                                BCB16B880979B01400467741 /* DeprecatedArray.h */,
                                BCC47E2509A3D6F100ADB771 /* FontFamily.h */,
                                A823A75B09B6E53900B60641 /* GraphicsContext.cpp */,
                                935367E409AF77DD00D35CD6 /* GraphicsContext.h */,
+                               938E685309F0BE04008A48EC /* GraphicsTypes.cpp */,
+                               938E683B09F0BD7A008A48EC /* GraphicsTypes.h */,
                                BC6B7BAE0993603C0052867B /* Image.cpp */,
                                BCD75ABB0989A446003E28DF /* Image.h */,
                                BC9C328A09933A6D001D6924 /* ImageAnimationObserver.h */,
                                14CF7B3409F6ECD700EB3665 /* JSCSSRule.h in Headers */,
                                938E65F109F09840008A48EC /* JSHTMLElementWrapperFactory.h in Headers */,
                                938E666209F09B87008A48EC /* JSHTMLCanvasElement.h in Headers */,
-                               938E683C09F0BD7B008A48EC /* CompositeOperator.h in Headers */,
+                               938E683C09F0BD7B008A48EC /* GraphicsTypes.h in Headers */,
                                8116896009F2A4A000772CA0 /* SVGTRefElement.h in Headers */,
                                14115B5209F84B7100CA4FC1 /* Node.h in Headers */,
                                14115B7309F84CD600CA4FC1 /* JSNodeFilter.h in Headers */,
                                14CF7B3309F6ECD700EB3665 /* JSCSSRule.cpp in Sources */,
                                938E65F709F0985D008A48EC /* JSHTMLElementWrapperFactory.cpp in Sources */,
                                938E666009F09B81008A48EC /* JSHTMLCanvasElement.cpp in Sources */,
-                               938E685409F0BE04008A48EC /* CompositeOperator.cpp in Sources */,
+                               938E685409F0BE04008A48EC /* GraphicsTypes.cpp in Sources */,
                                8116895F09F2A4A000772CA0 /* SVGTRefElement.cpp in Sources */,
                                14115B7209F84CD600CA4FC1 /* JSNodeFilter.cpp in Sources */,
                                14E8378409F85D1C00B85AE4 /* JSEvent.cpp in Sources */,
index 83bb21b97caae92960e1881c0e85cd2b448f4811..4eb100f9ec517e81d1670804f4ace81005ce885b 100644 (file)
@@ -2874,7 +2874,7 @@ void FrameMac::setDisplaysWithFocusAttributes(bool flag)
     if (doc && d->m_view && d->m_view->getDocumentView() && theme()->supportsControlTints() && renderer()) {
         doc->updateLayout(); // Ensure layout is up to date.
         IntRect visibleRect(enclosingIntRect(d->m_view->visibleContentRect()));
-        GraphicsContext context(0, false, false);
+        GraphicsContext context(0);
         context.setUpdatingControlTints(true);
         paint(&context, visibleRect);
     }
index 588dbb141beb188f383008cbd9ce62616ea9aebd..0eaf44896865a0c12ce8cc2e4834b390da8a34e8 100644 (file)
@@ -834,7 +834,10 @@ static BOOL nowPrinting(WebCoreFrameBridge *self)
 
 - (void)drawRect:(NSRect)rect
 {
-    GraphicsContext context([NSGraphicsContext currentContext]);
+    PlatformGraphicsContext* platformContext = static_cast<PlatformGraphicsContext*>([[NSGraphicsContext currentContext] graphicsPort]);
+    ASSERT([[NSGraphicsContext currentContext] isFlipped]);
+    ASSERT(!m_frame->document() || m_frame->document()->printing() == ![NSGraphicsContext currentContextDrawingToScreen]);
+    GraphicsContext context(platformContext);
     context.setUsesInactiveTextBackgroundColor(!m_frame->displaysWithFocusAttributes());
     [self _setupRootForPrinting:YES];
     m_frame->paint(&context, enclosingIntRect(rect));
index 574c042ae60fbed3781705c27039eb0434bd7de0..382775844785dec4e578d8f1714ee7c3c3064dc6 100644 (file)
@@ -123,9 +123,7 @@ static void patternCallback(void* info, CGContextRef context)
         return;
     }
 
-    // FIXME: Won't handle text flipping right for image types that include text
-    // since we just pass false for the context's flipped state.
-    GraphicsContext(context, false, false).drawImage(image, rect);
+    GraphicsContext(context).drawImage(image, rect);
 }
 
 static void patternReleaseCallback(void* info)
index 99dc69d2b81d8f01ebcdfd702d8633487858fed2..e4407fb8a456e8fdc816aa0a3403055f75c7acc5 100644 (file)
@@ -63,10 +63,8 @@ CanvasRenderingContext2D::State::State()
     , m_shadowColor("black")
     , m_globalAlpha(1)
     , m_globalComposite(CompositeSourceOver)
-#if __APPLE__
-    , m_platformContextStrokeStyleIsPattern(false)
-    , m_platformContextFillStyleIsPattern(false)
-#endif
+    , m_appliedStrokePattern(false)
+    , m_appliedFillPattern(false)
 {
 }
 
@@ -74,14 +72,10 @@ void CanvasRenderingContext2D::save()
 {
     ASSERT(m_stateStack.size() >= 1);
     m_stateStack.append(state());
-
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
+    GraphicsContext* c = drawingContext();
     if (!c)
         return;
-    CGContextSaveGState(c);
-#endif
+    c->save();
 }
 
 void CanvasRenderingContext2D::restore()
@@ -90,14 +84,10 @@ void CanvasRenderingContext2D::restore()
     if (m_stateStack.size() <= 1)
         return;
     m_stateStack.removeLast();
-
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
+    GraphicsContext* c = drawingContext();
     if (!c)
         return;
-    CGContextRestoreGState(c);
-#endif
+    c->restore();
 }
 
 CanvasStyle* CanvasRenderingContext2D::strokeStyle() const
@@ -110,12 +100,11 @@ void CanvasRenderingContext2D::setStrokeStyle(PassRefPtr<CanvasStyle> style)
     if (!style)
         return;
     state().m_strokeStyle = style;
-
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    state().m_strokeStyle->applyStrokeColor(platformContext());
-    state().m_platformContextStrokeStyleIsPattern = false;
-#endif
+    GraphicsContext* c = drawingContext();
+    if (!c)
+        return;
+    state().m_strokeStyle->applyStrokeColor(c);
+    state().m_appliedStrokePattern = false;
 }
 
 CanvasStyle* CanvasRenderingContext2D::fillStyle() const
@@ -128,12 +117,11 @@ void CanvasRenderingContext2D::setFillStyle(PassRefPtr<CanvasStyle> style)
     if (!style)
         return;
     state().m_fillStyle = style;
-
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    state().m_fillStyle->applyFillColor(platformContext());
-    state().m_platformContextFillStyleIsPattern = false;
-#endif
+    GraphicsContext* c = drawingContext();
+    if (!c)
+        return;
+    state().m_fillStyle->applyFillColor(c);
+    state().m_appliedFillPattern = false;
 }
 
 float CanvasRenderingContext2D::lineWidth() const
@@ -145,85 +133,45 @@ void CanvasRenderingContext2D::setLineWidth(float width)
 {
     if (!(width > 0))
         return;
-
     state().m_lineWidth = width;
-
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextSetLineWidth(platformContext(), width);
-#endif
+    GraphicsContext* c = drawingContext();
+    if (!c)
+        return;
+    c->setLineWidth(width);
 }
 
 String CanvasRenderingContext2D::lineCap() const
 {
-    const char* const names[3] = { "butt", "round", "square" };
-    return names[state().m_lineCap];
+    return lineCapName(state().m_lineCap);
 }
 
 void CanvasRenderingContext2D::setLineCap(const String& s)
 {
-    Cap cap;
-    if (s == "butt")
-        cap = ButtCap;
-    else if (s == "round")
-        cap = RoundCap;
-    else if (s == "square")
-        cap = SquareCap;
-    else
+    LineCap cap;
+    if (!parseLineCap(s, cap))
         return;
-
     state().m_lineCap = cap;
-
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    switch (cap) {
-        case ButtCap:
-            CGContextSetLineCap(platformContext(), kCGLineCapButt);
-            break;
-        case RoundCap:
-            CGContextSetLineCap(platformContext(), kCGLineCapRound);
-            break;
-        case SquareCap:
-            CGContextSetLineCap(platformContext(), kCGLineCapSquare);
-            break;
-    }
-#endif
+    GraphicsContext* c = drawingContext();
+    if (!c)
+        return;
+    c->setLineCap(cap);
 }
 
 String CanvasRenderingContext2D::lineJoin() const
 {
-    const char* const names[3] = { "miter", "round", "bevel" };
-    return names[state().m_lineJoin];
+    return lineJoinName(state().m_lineJoin);
 }
 
 void CanvasRenderingContext2D::setLineJoin(const String& s)
 {
-    Join join;
-    if (s == "miter")
-        join = MiterJoin;
-    else if (s == "round")
-        join = RoundJoin;
-    else if (s == "bevel")
-        join = BevelJoin;
-    else
+    LineJoin join;
+    if (!parseLineJoin(s, join))
         return;
-
     state().m_lineJoin = join;
-
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    switch (join) {
-        case MiterJoin:
-            CGContextSetLineJoin(platformContext(), kCGLineJoinMiter);
-            break;
-        case RoundJoin:
-            CGContextSetLineJoin(platformContext(), kCGLineJoinRound);
-            break;
-        case BevelJoin:
-            CGContextSetLineJoin(platformContext(), kCGLineJoinBevel);
-            break;
-    }
-#endif
+    GraphicsContext* c = drawingContext();
+    if (!c)
+        return;
+    c->setLineJoin(join);
 }
 
 float CanvasRenderingContext2D::miterLimit() const
@@ -235,13 +183,11 @@ void CanvasRenderingContext2D::setMiterLimit(float limit)
 {
     if (!(limit > 0))
         return;
-
     state().m_miterLimit = limit;
-
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextSetMiterLimit(platformContext(), limit);
-#endif
+    GraphicsContext* c = drawingContext();
+    if (!c)
+        return;
+    c->setMiterLimit(limit);
 }
 
 float CanvasRenderingContext2D::shadowOffsetX() const
@@ -279,7 +225,7 @@ void CanvasRenderingContext2D::setShadowBlur(float blur)
 
 String CanvasRenderingContext2D::shadowColor() const
 {
-    // FIXME: What should this return if you called setShadow with a non-string color.
+    // FIXME: What should this return if you called setShadow with a non-string color?
     return state().m_shadowColor;
 }
 
@@ -298,13 +244,11 @@ void CanvasRenderingContext2D::setGlobalAlpha(float alpha)
 {
     if (!(alpha >= 0 && alpha <= 1))
         return;
-
     state().m_globalAlpha = alpha;
-
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextSetAlpha(platformContext(), alpha);
-#endif
+    GraphicsContext* c = drawingContext();
+    if (!c)
+        return;
+    c->setAlpha(alpha);
 }
 
 String CanvasRenderingContext2D::globalCompositeOperation() const
@@ -317,36 +261,43 @@ void CanvasRenderingContext2D::setGlobalCompositeOperation(const String& operati
     CompositeOperator op;
     if (!parseCompositeOperator(operation, op))
         return;
-
     state().m_globalComposite = op;
-
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    WebCore::setCompositeOperation(platformContext(), op);
-#endif
+    GraphicsContext* c = drawingContext();
+    if (!c)
+        return;
+    c->setCompositeOperation(op);
 }
 
 void CanvasRenderingContext2D::scale(float sx, float sy)
 {
+    GraphicsContext* c = drawingContext();
+    if (!c)
+        return;
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextScaleCTM(platformContext(), sx, sy);
+    CGContextScaleCTM(c->platformContext(), sx, sy);
 #endif
 }
 
 void CanvasRenderingContext2D::rotate(float angleInRadians)
 {
+    GraphicsContext* c = drawingContext();
+    if (!c)
+        return;
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRotateCTM(platformContext(), angleInRadians);
+    CGContextRotateCTM(c->platformContext(), angleInRadians);
 #endif
 }
 
 void CanvasRenderingContext2D::translate(float tx, float ty)
 {
+    GraphicsContext* c = drawingContext();
+    if (!c)
+        return;
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextTranslateCTM(platformContext(), tx, ty);
+    CGContextTranslateCTM(c->platformContext(), tx, ty);
 #endif
 }
 
@@ -412,209 +363,142 @@ void CanvasRenderingContext2D::setFillColor(float c, float m, float y, float k,
 
 void CanvasRenderingContext2D::beginPath()
 {
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
-    if (!c)
-        return;
-    CGContextBeginPath(c);
-#endif
+    state().m_path.clear();
 }
 
 void CanvasRenderingContext2D::closePath()
 {
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
-    if (!c)
-        return;
-    CGContextClosePath(c);
-#endif
+    state().m_path.closeSubpath();
 }
 
 void CanvasRenderingContext2D::moveTo(float x, float y)
 {
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
-    if (!c)
-        return;
-    CGContextMoveToPoint(c, x, y);
-#endif
+    state().m_path.moveTo(FloatPoint(x, y));
 }
 
 void CanvasRenderingContext2D::lineTo(float x, float y)
 {
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
-    if (!c)
-        return;
-    CGContextAddLineToPoint(c, x, y);
-#endif
+    state().m_path.addLineTo(FloatPoint(x, y));
 }
 
 void CanvasRenderingContext2D::quadraticCurveTo(float cpx, float cpy, float x, float y)
 {
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
-    if (!c)
-        return;
-    CGContextAddQuadCurveToPoint(c, cpx, cpy, x, y);
-#endif
+    state().m_path.addQuadCurveTo(FloatPoint(cpx, cpy), FloatPoint(x, y));
 }
 
 void CanvasRenderingContext2D::bezierCurveTo(float cp1x, float cp1y, float cp2x, float cp2y, float x, float y)
 {
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
-    if (!c)
-        return;
-    CGContextAddCurveToPoint(c, cp1x, cp1y, cp2x, cp2y, x, y);
-#endif
+    state().m_path.addBezierCurveTo(FloatPoint(cp1x, cp1y), FloatPoint(cp2x, cp2y), FloatPoint(x, y));
 }
 
-void CanvasRenderingContext2D::arcTo(float x0, float y0, float x1, float y1, float radius, ExceptionCode& ec)
+void CanvasRenderingContext2D::arcTo(float x0, float y0, float x1, float y1, float r, ExceptionCode& ec)
 {
     ec = 0;
-
-    if (!(radius > 0)) {
+    if (!(r > 0)) {
         ec = INDEX_SIZE_ERR;
         return;
     }
-
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
-    if (!c)
-        return;
-    CGContextAddArcToPoint(c, x0, y0, x1, y1, radius);
-#endif
+    state().m_path.addArcTo(FloatPoint(x0, y0), FloatPoint(x1, y1), r);
 }
 
 void CanvasRenderingContext2D::arc(float x, float y, float r, float sa, float ea, bool clockwise, ExceptionCode& ec)
 {
     ec = 0;
-
     if (!(r > 0)) {
         ec = INDEX_SIZE_ERR;
         return;
     }
-
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
-    if (!c)
-        return;
-    CGContextAddArc(c, x, y, r, sa, ea, clockwise);
-#endif
+    state().m_path.addArc(FloatPoint(x, y), r, sa, ea, clockwise);
 }
 
 void CanvasRenderingContext2D::rect(float x, float y, float width, float height, ExceptionCode& ec)
 {
     ec = 0;
-
     if (!(width > 0 && height > 0)) {
         ec = INDEX_SIZE_ERR;
         return;
     }
-
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
-    if (!c)
-        return;
-    CGContextAddRect(c, CGRectMake(x, y, width, height));
-#endif
+    state().m_path.addRect(FloatRect(x, y, width, height));
 }
 
 void CanvasRenderingContext2D::fill()
 {
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
+    GraphicsContext* c = drawingContext();
     if (!c)
         return;
+    // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
+    CGContextBeginPath(c->platformContext());
+    CGContextAddPath(c->platformContext(), state().m_path.platformPath());
 
-    willDraw(CGContextGetPathBoundingBox(c));
+    willDraw(CGContextGetPathBoundingBox(c->platformContext()));
 
     if (state().m_fillStyle->gradient()) {
         // Shading works on the entire clip region, so convert the current path to a clip.
-        CGContextSaveGState(c);        
-        CGContextClip(c);
-        CGContextDrawShading(c, state().m_fillStyle->gradient()->platformShading());        
-        CGContextRestoreGState(c);
+        c->save();
+        CGContextClip(c->platformContext());
+        CGContextDrawShading(c->platformContext(), state().m_fillStyle->gradient()->platformShading());        
+        c->restore();
     } else {
         if (state().m_fillStyle->pattern())
             applyFillPattern();
-        CGContextFillPath(c);
+        CGContextFillPath(c->platformContext());
     }
 #endif
 }
 
 void CanvasRenderingContext2D::stroke()
 {
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
+    GraphicsContext* c = drawingContext();
     if (!c)
         return;
+    // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
+    CGContextBeginPath(c->platformContext());
+    CGContextAddPath(c->platformContext(), state().m_path.platformPath());
 
-    // FIXME: Is this right for negative widths?
     float lineWidth = state().m_lineWidth;
     float inset = -lineWidth / 2;
-    CGRect boundingRect = CGRectInset(CGContextGetPathBoundingBox(c), inset, inset);
+    CGRect boundingRect = CGRectInset(CGContextGetPathBoundingBox(c->platformContext()), inset, inset);
 
     willDraw(boundingRect);
 
     if (state().m_strokeStyle->gradient()) {
         // Shading works on the entire clip region, so convert the current path to a clip.
-        CGContextSaveGState(c);        
-        CGContextReplacePathWithStrokedPath(c);
-        CGContextClip(c);
-        CGContextDrawShading(c, state().m_strokeStyle->gradient()->platformShading());        
-        CGContextRestoreGState(c);
+        c->save();
+        CGContextReplacePathWithStrokedPath(c->platformContext());
+        CGContextClip(c->platformContext());
+        CGContextDrawShading(c->platformContext(), state().m_strokeStyle->gradient()->platformShading());        
+        c->restore();
     } else {
         if (state().m_strokeStyle->pattern())
             applyStrokePattern();
-        CGContextStrokePath(c);
+        CGContextStrokePath(c->platformContext());
     }
 #endif
 }
 
 void CanvasRenderingContext2D::clip()
 {
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
+    GraphicsContext* c = drawingContext();
     if (!c)
         return;
-    CGContextClip(c);
-#endif
+    c->clip(state().m_path);
 }
 
 void CanvasRenderingContext2D::clearRect(float x, float y, float width, float height, ExceptionCode& ec)
 {
     ec = 0;
-
     if (!(width > 0 && height > 0)) {
         ec = INDEX_SIZE_ERR;
         return;
     }
-
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
+    GraphicsContext* c = drawingContext();
     if (!c)
         return;
-    CGRect rect = CGRectMake(x, y, width, height);
-
+    FloatRect rect(x, y, width, height);
     willDraw(rect);
-
-    CGContextClearRect(c, rect);
-#endif
+    c->clearRect(rect);
 }
 
 void CanvasRenderingContext2D::fillRect(float x, float y, float width, float height, ExceptionCode& ec)
@@ -626,25 +510,25 @@ void CanvasRenderingContext2D::fillRect(float x, float y, float width, float hei
         return;
     }
 
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
+    GraphicsContext* c = drawingContext();
     if (!c)
         return;
+    // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
     CGRect rect = CGRectMake(x, y, width, height);
 
     willDraw(rect);
 
     if (state().m_fillStyle->gradient()) {
         // Shading works on the entire clip region, so convert the rect to a clip.
-        CGContextSaveGState(c);        
-        CGContextClipToRect(c, rect);
-        CGContextDrawShading(c, state().m_fillStyle->gradient()->platformShading());        
-        CGContextRestoreGState(c);
+        c->save();
+        CGContextClipToRect(c->platformContext(), rect);
+        CGContextDrawShading(c->platformContext(), state().m_fillStyle->gradient()->platformShading());        
+        c->restore();
     } else {
         if (state().m_fillStyle->pattern())
             applyFillPattern();
-        CGContextFillRect(c, rect);
+        CGContextFillRect(c->platformContext(), rect);
     }
 #endif
 }
@@ -663,24 +547,21 @@ void CanvasRenderingContext2D::strokeRect(float x, float y, float width, float h
         return;
     }
 
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
+    GraphicsContext* c = drawingContext();
     if (!c)
         return;
 
-    // FIXME: Is this right for negative widths?
-    float inset = -lineWidth / 2;
-    CGRect rect = CGRectMake(x, y, width, height);
-    CGRect boundingRect = CGRectInset(rect, inset, inset);
+    FloatRect rect(x, y, width, height);
 
+    FloatRect boundingRect = rect;
+    boundingRect.inflate(lineWidth / 2);
     willDraw(boundingRect);
 
     // FIXME: No support for gradients!
     if (state().m_strokeStyle->pattern())
         applyStrokePattern();
-    CGContextStrokeRectWithWidth(c, rect, lineWidth);
-#endif
+
+    c->strokeRect(rect, lineWidth);
 }
 
 void CanvasRenderingContext2D::setShadow(float width, float height, float blur)
@@ -705,16 +586,16 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
     state().m_shadowBlur = blur;
     state().m_shadowColor = "";
 
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
+    GraphicsContext* c = drawingContext();
     if (!c)
         return;
+    // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
     const CGFloat components[2] = { grayLevel, 1 };
     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
     CGColorRef color = CGColorCreate(colorSpace, components);
     CGColorSpaceRelease(colorSpace);
-    CGContextSetShadowWithColor(c, CGSizeMake(width, height), blur, color);
+    CGContextSetShadowWithColor(c->platformContext(), CGSizeMake(width, height), blur, color);
     CGColorRelease(color);
 #endif
 }
@@ -725,11 +606,11 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
     state().m_shadowBlur = blur;
     state().m_shadowColor = color;
 
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
+    GraphicsContext* c = drawingContext();
     if (!c)
         return;
+    // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
     RGBA32 rgba = CSSParser::parseColor(color);
     const CGFloat components[4] = {
         ((rgba >> 16) & 0xFF) / 255.0,
@@ -740,7 +621,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
     CGColorRef shadowColor = CGColorCreate(colorSpace, components);
     CGColorSpaceRelease(colorSpace);
-    CGContextSetShadowWithColor(c, CGSizeMake(width, height), blur, shadowColor);
+    CGContextSetShadowWithColor(c->platformContext(), CGSizeMake(width, height), blur, shadowColor);
     CGColorRelease(shadowColor);
 #endif
 }
@@ -751,16 +632,16 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
     state().m_shadowBlur = blur;
     state().m_shadowColor = "";
 
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
+    GraphicsContext* c = drawingContext();
     if (!c)
         return;
+    // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
     const CGFloat components[2] = { grayLevel, alpha };
     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
     CGColorRef color = CGColorCreate(colorSpace, components);
     CGColorSpaceRelease(colorSpace);
-    CGContextSetShadowWithColor(c, CGSizeMake(width, height), blur, color);
+    CGContextSetShadowWithColor(c->platformContext(), CGSizeMake(width, height), blur, color);
     CGColorRelease(color);
 #endif
 }
@@ -771,16 +652,16 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
     state().m_shadowBlur = blur;
     state().m_shadowColor = "";
 
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
+    GraphicsContext* c = drawingContext();
     if (!c)
         return;
+    // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
     const CGFloat components[4] = { r, g, b, a };
     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
     CGColorRef shadowColor = CGColorCreate(colorSpace, components);
     CGColorSpaceRelease(colorSpace);
-    CGContextSetShadowWithColor(c, CGSizeMake(width, height), blur, shadowColor);
+    CGContextSetShadowWithColor(c->platformContext(), CGSizeMake(width, height), blur, shadowColor);
     CGColorRelease(shadowColor);
 #endif
 }
@@ -791,16 +672,16 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
     state().m_shadowBlur = blur;
     state().m_shadowColor = "";
 
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef dc = platformContext();
+    GraphicsContext* dc = drawingContext();
     if (!dc)
         return;
+    // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
     const CGFloat components[5] = { c, m, y, k, a };
     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceCMYK();
     CGColorRef shadowColor = CGColorCreate(colorSpace, components);
     CGColorSpaceRelease(colorSpace);
-    CGContextSetShadowWithColor(dc, CGSizeMake(width, height), blur, shadowColor);
+    CGContextSetShadowWithColor(dc->platformContext(), CGSizeMake(width, height), blur, shadowColor);
     CGColorRelease(shadowColor);
 #endif
 }
@@ -815,11 +696,11 @@ void CanvasRenderingContext2D::clearShadow()
 
 void CanvasRenderingContext2D::applyShadow()
 {
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
+    GraphicsContext* c = drawingContext();
     if (!c)
         return;
+    // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
     RGBA32 rgba = state().m_shadowColor.isEmpty() ? 0 : CSSParser::parseColor(state().m_shadowColor);
     const CGFloat components[4] = {
         ((rgba >> 16) & 0xFF) / 255.0,
@@ -830,7 +711,7 @@ void CanvasRenderingContext2D::applyShadow()
     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
     CGColorRef color = CGColorCreate(colorSpace, components);
     CGColorSpaceRelease(colorSpace);
-    CGContextSetShadowWithColor(c, state().m_shadowOffset, state().m_shadowBlur, color);
+    CGContextSetShadowWithColor(c->platformContext(), state().m_shadowOffset, state().m_shadowBlur, color);
     CGColorRelease(color);
 #endif
 }
@@ -917,12 +798,11 @@ void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas,
     if (!canvas)
         return;
 
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = platformContext();
+    GraphicsContext* c = drawingContext();
     if (!c)
         return;
-
+    // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
     CGImageRef platformImage = canvas->createPlatformImage();
     if (!platformImage)
         return;
@@ -934,7 +814,7 @@ void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas,
     float ih = CGImageGetHeight(platformImage);
     if (sx == 0 && sy == 0 && iw == sw && ih == sh) {
         // Fast path, yay!
-        CGContextDrawImage(c, CGRectMake(dx, dy, dw, dh), platformImage);
+        CGContextDrawImage(c->platformContext(), CGRectMake(dx, dy, dw, dh), platformImage);
     } else {
         // Slow path, boo!
         // Create a new bitmap of the appropriate size and then draw that into our context.
@@ -955,7 +835,7 @@ void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas,
         CGImageRef clippedSourceImage = CGBitmapContextCreateImage(clippedSourceContext);
         CGContextRelease(clippedSourceContext);
 
-        CGContextDrawImage(c, CGRectMake(dx, dy, dw, dh), clippedSourceImage);
+        CGContextDrawImage(c->platformContext(), CGRectMake(dx, dy, dw, dh), clippedSourceImage);
         CGImageRelease(clippedSourceImage);
         
         fastFree(buffer);
@@ -986,7 +866,6 @@ void CanvasRenderingContext2D::drawImageFromRect(HTMLImageElement* image,
     if (!parseCompositeOperator(compositeOperation, op))
         op = CompositeSourceOver;
 
-    // FIXME: Do this through platform-independent GraphicsContext API.
     FloatRect destRect = FloatRect(dx, dy, dw, dh);
     willDraw(destRect);
     c->drawImage(cachedImage->image(), destRect, FloatRect(sx, sy, sw, sh), op);
@@ -1029,6 +908,7 @@ PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLCanvasElem
     CanvasPattern::parseRepetitionType(repetitionType, repeatX, repeatY, ec);
     if (ec)
         return 0;
+    // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
     CGImageRef image = canvas->createPlatformImage();
     if (!image)
@@ -1055,25 +935,16 @@ GraphicsContext* CanvasRenderingContext2D::drawingContext() const
     return m_canvas->drawingContext();
 }
 
-#if __APPLE__
-
-CGContextRef CanvasRenderingContext2D::platformContext() const
-{
-    GraphicsContext* c = drawingContext();
-    if (!c)
-        return 0;
-    return c->platformContext();
-}
-
 void CanvasRenderingContext2D::applyStrokePattern()
 {
-    CGContextRef c = platformContext();
+    GraphicsContext* c = drawingContext();
     if (!c)
         return;
 
+#if __APPLE__
     // Check for case where the pattern is already set.
-    CGAffineTransform m = CGContextGetCTM(c);
-    if (state().m_platformContextStrokeStyleIsPattern
+    CGAffineTransform m = CGContextGetCTM(c->platformContext());
+    if (state().m_appliedStrokePattern
             && CGAffineTransformEqualToTransform(m, state().m_strokeStylePatternTransform))
         return;
 
@@ -1086,26 +957,28 @@ void CanvasRenderingContext2D::applyStrokePattern()
         return;
 
     CGColorSpaceRef patternSpace = CGColorSpaceCreatePattern(0);
-    CGContextSetStrokeColorSpace(c, patternSpace);
+    CGContextSetStrokeColorSpace(c->platformContext(), patternSpace);
     CGColorSpaceRelease(patternSpace);
 
     const CGFloat patternAlpha = 1;
-    CGContextSetStrokePattern(c, platformPattern, &patternAlpha);
+    CGContextSetStrokePattern(c->platformContext(), platformPattern, &patternAlpha);
     CGPatternRelease(platformPattern);
 
-    state().m_platformContextStrokeStyleIsPattern = true;
     state().m_strokeStylePatternTransform = m;
+#endif
+    state().m_appliedStrokePattern = true;
 }
 
 void CanvasRenderingContext2D::applyFillPattern()
 {
-    CGContextRef c = platformContext();
+    GraphicsContext* c = drawingContext();
     if (!c)
         return;
 
+#if __APPLE__
     // Check for case where the pattern is already set.
-    CGAffineTransform m = CGContextGetCTM(c);
-    if (state().m_platformContextFillStyleIsPattern
+    CGAffineTransform m = CGContextGetCTM(c->platformContext());
+    if (state().m_appliedFillPattern
             && CGAffineTransformEqualToTransform(m, state().m_fillStylePatternTransform))
         return;
 
@@ -1118,17 +991,16 @@ void CanvasRenderingContext2D::applyFillPattern()
         return;
 
     CGColorSpaceRef patternSpace = CGColorSpaceCreatePattern(0);
-    CGContextSetFillColorSpace(c, patternSpace);
+    CGContextSetFillColorSpace(c->platformContext(), patternSpace);
     CGColorSpaceRelease(patternSpace);
 
     const CGFloat patternAlpha = 1;
-    CGContextSetFillPattern(c, platformPattern, &patternAlpha);
+    CGContextSetFillPattern(c->platformContext(), platformPattern, &patternAlpha);
     CGPatternRelease(platformPattern);
 
-    state().m_platformContextFillStyleIsPattern = true;
     state().m_fillStylePatternTransform = m;
-}
-
 #endif
+    state().m_appliedFillPattern = true;
+}
 
 } // namespace WebCore
index 202e2131b2d15db29805238aa0b1497168546277..79ba15b01a67a558e2d6d67235da82e2b8ee8acb 100644 (file)
@@ -26,8 +26,9 @@
 #ifndef HTMLCanvas2DContext_h
 #define HTMLCanvas2DContext_h
 
-#include "CompositeOperator.h"
-#include "FloatRect.h"
+#include "FloatSize.h"
+#include "GraphicsTypes.h"
+#include "Path.h"
 #include "PlatformString.h"
 #include <kxmlcore/Vector.h>
 
@@ -40,6 +41,7 @@ namespace WebCore {
     class CanvasGradient;
     class CanvasPattern;
     class CanvasStyle;
+    class FloatRect;
     class GraphicsContext;
     class HTMLCanvasElement;
     class HTMLImageElement;
@@ -164,27 +166,25 @@ namespace WebCore {
         void detachCanvas() { m_canvas = 0; }
 
     private:
-        enum Cap { ButtCap, RoundCap, SquareCap };
-        enum Join { MiterJoin, RoundJoin, BevelJoin };
-
         struct State {
             State();
 
             RefPtr<CanvasStyle> m_strokeStyle;
             RefPtr<CanvasStyle> m_fillStyle;
+            Path m_path;
             float m_lineWidth;
-            Cap m_lineCap;
-            Join m_lineJoin;
+            LineCap m_lineCap;
+            LineJoin m_lineJoin;
             float m_miterLimit;
             FloatSize m_shadowOffset;
             float m_shadowBlur;
             String m_shadowColor;
             float m_globalAlpha;
             CompositeOperator m_globalComposite;
+            bool m_appliedStrokePattern;
+            bool m_appliedFillPattern;
 #if __APPLE__
-            bool m_platformContextStrokeStyleIsPattern;
             CGAffineTransform m_strokeStylePatternTransform;
-            bool m_platformContextFillStyleIsPattern;
             CGAffineTransform m_fillStylePatternTransform;
 #endif
         };
@@ -198,13 +198,9 @@ namespace WebCore {
 
         GraphicsContext* drawingContext() const;
 
-#if __APPLE__
         void applyStrokePattern();
         void applyFillPattern();
 
-        CGContextRef platformContext() const;
-#endif
-
         HTMLCanvasElement* m_canvas;
         Vector<State, 1> m_stateStack;
     };
index b1dd37b2cfe61584988d3f479ef4736eacb734a5..feab48628b98bd3d6d54095072768ce94f3ad02d 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "CanvasGradient.h"
 #include "CanvasPattern.h"
+#include "GraphicsContext.h"
 #include "cssparser.h"
 #include <kxmlcore/PassRefPtr.h>
 
@@ -73,39 +74,52 @@ CanvasStyle::CanvasStyle(PassRefPtr<CanvasPattern> pattern)
 {
 }
 
-#if __APPLE__
-
-void CanvasStyle::applyStrokeColor(CGContextRef context)
+void CanvasStyle::applyStrokeColor(GraphicsContext* context)
 {
     if (!context)
         return;
     switch (m_type) {
         case ColorString: {
             RGBA32 color = CSSParser::parseColor(m_color);
-            CGContextSetRGBStrokeColor(context,
+            // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
+            CGContextSetRGBStrokeColor(context->platformContext(),
                 ((color >> 16) & 0xFF) / 255.0,
                 ((color >> 8) & 0xFF) / 255.0,
                 (color & 0xFF) / 255.0,
                 ((color >> 24) & 0xFF) / 255.0);
+#endif
             break;
         }
         case ColorStringWithAlpha: {
             RGBA32 color = CSSParser::parseColor(m_color);
-            CGContextSetRGBStrokeColor(context,
+            // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
+            CGContextSetRGBStrokeColor(context->platformContext(),
                 ((color >> 16) & 0xFF) / 255.0,
                 ((color >> 8) & 0xFF) / 255.0,
                 (color & 0xFF) / 255.0,
                 m_alpha);
+#endif
             break;
         }
         case GrayLevel:
-            CGContextSetGrayStrokeColor(context, m_grayLevel, m_alpha);
+            // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
+            CGContextSetGrayStrokeColor(context->platformContext(), m_grayLevel, m_alpha);
+#endif
             break;
         case RGBA:
-            CGContextSetRGBStrokeColor(context, m_red, m_green, m_blue, m_alpha);
+            // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
+            CGContextSetRGBStrokeColor(context->platformContext(), m_red, m_green, m_blue, m_alpha);
+#endif
             break;
         case CMYKA:
-            CGContextSetCMYKStrokeColor(context, m_cyan, m_magenta, m_yellow, m_black, m_alpha);
+            // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
+            CGContextSetCMYKStrokeColor(context->platformContext(), m_cyan, m_magenta, m_yellow, m_black, m_alpha);
+#endif
             break;
         case Gradient:
         case ImagePattern:
@@ -113,37 +127,52 @@ void CanvasStyle::applyStrokeColor(CGContextRef context)
     }
 }
 
-void CanvasStyle::applyFillColor(CGContextRef context)
+void CanvasStyle::applyFillColor(GraphicsContext* context)
 {
     if (!context)
         return;
     switch (m_type) {
         case ColorString: {
             RGBA32 color = CSSParser::parseColor(m_color);
-            CGContextSetRGBFillColor(context,
+            // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
+            CGContextSetRGBFillColor(context->platformContext(),
                 ((color >> 16) & 0xFF) / 255.0,
                 ((color >> 8) & 0xFF) / 255.0,
                 (color & 0xFF) / 255.0,
                 ((color >> 24) & 0xFF) / 255.0);
+#endif
             break;
         }
         case ColorStringWithAlpha: {
             RGBA32 color = CSSParser::parseColor(m_color);
-            CGContextSetRGBFillColor(context,
+            // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
+            CGContextSetRGBFillColor(context->platformContext(),
                 ((color >> 16) & 0xFF) / 255.0,
                 ((color >> 8) & 0xFF) / 255.0,
                 (color & 0xFF) / 255.0,
                 m_alpha);
+#endif
             break;
         }
         case GrayLevel:
-            CGContextSetGrayFillColor(context, m_grayLevel, m_alpha);
+            // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
+            CGContextSetGrayFillColor(context->platformContext(), m_grayLevel, m_alpha);
+#endif
             break;
         case RGBA:
-            CGContextSetRGBFillColor(context, m_red, m_green, m_blue, m_alpha);
+            // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
+            CGContextSetRGBFillColor(context->platformContext(), m_red, m_green, m_blue, m_alpha);
+#endif
             break;
         case CMYKA:
-            CGContextSetCMYKFillColor(context, m_cyan, m_magenta, m_yellow, m_black, m_alpha);
+            // FIXME: Do this through platform-independent GraphicsContext API.
+#if __APPLE__
+            CGContextSetCMYKFillColor(context->platformContext(), m_cyan, m_magenta, m_yellow, m_black, m_alpha);
+#endif
             break;
         case Gradient:
         case ImagePattern:
@@ -151,6 +180,4 @@ void CanvasStyle::applyFillColor(CGContextRef context)
     }
 }
 
-#endif
-
 }
index 8ef1e3f4e50b275b40af469799800d5812d0bfca..570f6547fbea2530ff07f1f743a5caeef78ba734 100644 (file)
 
 #include "PlatformString.h"
 
-#if __APPLE__
-typedef struct CGContext* CGContextRef;
-#endif
-
 namespace WebCore {
 
     class CanvasGradient;
     class CanvasPattern;
+    class GraphicsContext;
 
     class CanvasStyle : public Shared<CanvasStyle> {
     public:
@@ -52,11 +49,9 @@ namespace WebCore {
         CanvasGradient* gradient() const { return m_gradient.get(); }
         CanvasPattern* pattern() const { return m_pattern.get(); }
 
-#if __APPLE__
         // These do nothing for gradients or patterns.
-        void applyFillColor(CGContextRef);
-        void applyStrokeColor(CGContextRef);
-#endif
+        void applyFillColor(GraphicsContext*);
+        void applyStrokeColor(GraphicsContext*);
 
     private:
         enum Type { ColorString, ColorStringWithAlpha, GrayLevel, RGBA, CMYKA, Gradient, ImagePattern };
index 33689b951a00c3b252f2b607d969c5d816993ecf..0a7f0f9e611dac5ddd9ddfc71864f06a1e1ec12f 100644 (file)
@@ -162,7 +162,7 @@ void HTMLCanvasElement::createDrawingContext() const
     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
     CGContextRef bitmapContext = CGBitmapContextCreate(m_data, w, height(), 8, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);
     CGColorSpaceRelease(colorSpace);
-    m_drawingContext = new GraphicsContext(bitmapContext, false, false);
+    m_drawingContext = new GraphicsContext(bitmapContext);
     CGContextRelease(bitmapContext);
 #endif
 }
index 60fb25496595e61c91c8207b55a5ba606674dbe9..8588074038728e3e2fb6820ad1653d38bff81e99 100644 (file)
@@ -26,8 +26,8 @@
 
 #include "DocLoader.h"
 #include "EventNames.h"
+#include "FloatRect.h"
 #include "HTMLFormElement.h"
-#include "IntPointArray.h"
 #include "csshelper.h"
 #include "CSSPropertyNames.h"
 #include "CSSValueKeywords.h"
@@ -572,9 +572,9 @@ IntRect HTMLAreaElement::getRect(RenderObject* obj) const
 {
     int dx, dy;
     obj->absolutePosition(dx, dy);
-    Path p = getRegion(lastw,lasth);
-    p.translate(dx, dy);
-    return p.boundingRect();
+    Path p = getRegion(lastw, lasth);
+    p.translate(IntSize(dx, dy));
+    return enclosingIntRect(p.boundingRect());
 }
 
 Path HTMLAreaElement::getRegion(int width, int height) const
@@ -593,22 +593,24 @@ Path HTMLAreaElement::getRegion(int width, int height) const
             shape = Poly;
     }
 
+    Path path;
     switch (shape) {
         case Poly:
             if (m_coordsLen >= 6) {
+                Path path;
                 int numPoints = m_coordsLen / 2;
-                IntPointArray points(numPoints);
-                for (int i = 0; i < numPoints; ++i)
-                    points.setPoint(i, m_coords[i * 2].calcMinValue(width), m_coords[i * 2 + 1].calcMinValue(height));
-                return Path(points);
+                path.moveTo(FloatPoint(m_coords[0].calcMinValue(width), m_coords[1].calcMinValue(height)));
+                for (int i = 1; i < numPoints; ++i)
+                    path.addLineTo(FloatPoint(m_coords[i * 2].calcMinValue(width), m_coords[i * 2 + 1].calcMinValue(height)));
+                path.closeSubpath();
             }
             break;
         case Circle:
             if (m_coordsLen >= 3) {
                 Length radius = m_coords[2];
                 int r = min(radius.calcMinValue(width), radius.calcMinValue(height));
-                return Path(IntRect(m_coords[0].calcMinValue(width) - r, m_coords[1].calcMinValue(height) - r,
-                    2 * r, 2 * r), Path::Ellipse);
+                path.addEllipse(FloatRect(m_coords[0].calcMinValue(width) - r, m_coords[1].calcMinValue(height) - r,
+                    2 * r, 2 * r));
             }
             break;
         case Rect:
@@ -617,16 +619,17 @@ Path HTMLAreaElement::getRegion(int width, int height) const
                 int y0 = m_coords[1].calcMinValue(height);
                 int x1 = m_coords[2].calcMinValue(width);
                 int y1 = m_coords[3].calcMinValue(height);
-                return Path(IntRect(x0, y0, x1 - x0, y1 - y0));
+                path.addRect(FloatRect(x0, y0, x1 - x0, y1 - y0));
             }
             break;
         case Default:
-            return Path(IntRect(0, 0, width, height));
+            path.addRect(FloatRect(0, 0, width, height));
+            break;
         case Unknown:
             break;
     }
 
-    return Path();
+    return path;
 }
 
 String HTMLAreaElement::accessKey() const
index 4b2cff077e0307dfebce68411113679012f97dfb..c9d6ac7201e52d360c619db2ad4a340356aad4ef 100644 (file)
@@ -100,7 +100,7 @@ NSGraphicsContext *KRenderingDeviceContextQuartz::nsGraphicsContext()
 
 GraphicsContext* KRenderingDeviceContextQuartz::createGraphicsContext()
 {
-    return new GraphicsContext(m_cgContext, false, false);
+    return new GraphicsContext(m_cgContext);
 }
 
 static bool __useFilters = true;
index 10340f0401e017652277708d8a2aac1a8c4775b2..e5c386aaa2be659067d073d1e4b72e9e22ead113 100644 (file)
@@ -112,7 +112,7 @@ private:
     CachedCSSStyleSheet* m_cachedSheet;
 };
 
-#if !NDEBUG
+#ifndef NDEBUG
 struct FrameCounter { 
     static int count; 
     ~FrameCounter() { if (count != 0) fprintf(stderr, "LEAK: %d Frame\n", count); }
@@ -145,7 +145,7 @@ Frame::Frame(Page* page, RenderPart* ownerRenderer)
     // FIXME: Frames were originally created with a refcount of 1, leave this
     // ref call here until we can straighten that out.
     ref();
-#if !NDEBUG
+#ifndef NDEBUG
     ++FrameCounter::count;
 #endif
 
@@ -157,7 +157,7 @@ Frame::~Frame()
 {
     ASSERT(!d->m_lifeSupportTimer.isActive());
 
-#if !NDEBUG
+#ifndef NDEBUG
     --FrameCounter::count;
 #endif
 
@@ -2358,13 +2358,13 @@ bool Frame::isCharacterSmartReplaceExempt(const QChar&, bool)
     return true;
 }
 
-#if !NDEBUG
+#ifndef NDEBUG
 static HashSet<Frame*> lifeSupportSet;
 #endif
 
 void Frame::endAllLifeSupport()
 {
-#if !NDEBUG
+#ifndef NDEBUG
     HashSet<Frame*> lifeSupportCopy = lifeSupportSet;
     HashSet<Frame*>::iterator end = lifeSupportCopy.end();
     for (HashSet<Frame*>::iterator it = lifeSupportCopy.begin(); it != end; ++it)
@@ -2377,7 +2377,7 @@ void Frame::keepAlive()
     if (d->m_lifeSupportTimer.isActive())
         return;
     ref();
-#if !NDEBUG
+#ifndef NDEBUG
     lifeSupportSet.add(this);
 #endif
     d->m_lifeSupportTimer.startOneShot(0);
@@ -2388,7 +2388,7 @@ void Frame::endLifeSupport()
     if (!d->m_lifeSupportTimer.isActive())
         return;
     d->m_lifeSupportTimer.stop();
-#if !NDEBUG
+#ifndef NDEBUG
     lifeSupportSet.remove(this);
 #endif
     deref();
@@ -2396,7 +2396,7 @@ void Frame::endLifeSupport()
 
 void Frame::lifeSupportTimerFired(Timer<Frame>*)
 {
-#if !NDEBUG
+#ifndef NDEBUG
     lifeSupportSet.remove(this);
 #endif
     deref();
@@ -2740,11 +2740,11 @@ void Frame::stopAutoscrollTimer()
 // FIXME: why is this here instead of on the FrameView?
 void Frame::paint(GraphicsContext* p, const IntRect& rect)
 {
-#if !NDEBUG
+#ifndef NDEBUG
     bool fillWithRed;
-    if (p->printing())
+    if (!document() || document()->printing())
         fillWithRed = false; // Printing, don't fill with red (can't remember why).
-    else if (!document() || document()->ownerElement())
+    else if (document()->ownerElement())
         fillWithRed = false; // Subframe, don't fill with red.
     else if (view() && view()->isTransparent())
         fillWithRed = false; // Transparent, don't fill with red.
@@ -2779,8 +2779,8 @@ void Frame::adjustPageHeight(float *newBottom, float oldTop, float oldBottom, fl
 {
     RenderCanvas *root = static_cast<RenderCanvas *>(document()->renderer());
     if (root) {
-        // Use a context with painting disabled but with "for printer" set to true.
-        GraphicsContext context(0, false, true);
+        // Use a context with painting disabled.
+        GraphicsContext context(0);
         root->setTruncatedAt((int)floorf(oldBottom));
         IntRect dirtyRect(0, (int)floorf(oldTop), root->docWidth(), (int)ceilf(oldBottom - oldTop));
         root->layer()->paint(&context, dirtyRect);
index 255181638cc55a0c746abf33e839e84246fd28b5..941ff46d3ea25dedfb13b3ffdf58f704d16712c7 100644 (file)
@@ -45,30 +45,28 @@ struct GraphicsContextState {
         
 class GraphicsContextPrivate {
 public:
-    GraphicsContextPrivate(bool isForPrinting);
+    GraphicsContextPrivate();
     
     GraphicsContextState state;
     Vector<GraphicsContextState> stack;
     Vector<IntRect> m_focusRingRects;
     int m_focusRingWidth;
     int m_focusRingOffset;
-    bool m_isForPrinting;
     bool m_usesInactiveTextBackgroundColor;
     bool m_updatingControlTints;
 };
 
-GraphicsContextPrivate::GraphicsContextPrivate(bool isForPrinting)
+GraphicsContextPrivate::GraphicsContextPrivate()
     : m_focusRingWidth(0)
     , m_focusRingOffset(0)
-    , m_isForPrinting(isForPrinting)
     , m_usesInactiveTextBackgroundColor(false)
     , m_updatingControlTints(false)
 {
 }
 
-GraphicsContextPrivate* GraphicsContext::createGraphicsContextPrivate(bool isForPrinting)
+GraphicsContextPrivate* GraphicsContext::createGraphicsContextPrivate()
 {
-    return new GraphicsContextPrivate(isForPrinting);
+    return new GraphicsContextPrivate;
 }
 
 void GraphicsContext::destroyGraphicsContextPrivate(GraphicsContextPrivate* deleteMe)
@@ -176,11 +174,6 @@ bool GraphicsContext::paintingDisabled() const
     return m_common->state.paintingDisabled;
 }
 
-bool GraphicsContext::printing() const
-{
-    return m_common->m_isForPrinting;
-}
-
 void GraphicsContext::drawImage(Image* image, const IntPoint& p, CompositeOperator op)
 {        
     drawImage(image, p, IntRect(0, 0, -1, -1), op);
index 9da7ecf5e4afc4d830c655e9bf81bbd3ff64baff..38d85a70a1ff10774a7e4fd4a88cac748d76e3f7 100644 (file)
 #include <kxmlcore/Noncopyable.h>
 
 #if __APPLE__
-#if __OBJC__
-@class NSGraphicsContext;
-#else
-class NSGraphicsContext;
-#endif
-typedef struct CGContext* CGContextRef;
-#endif
-
-#if WIN32
+typedef struct CGContext PlatformGraphicsContext;
+#elif WIN32
 typedef struct HDC__* HDC;
-typedef struct _cairo cairo_t;
+typedef struct _cairo PlatformGraphicsContext;
+#else
+typedef void PlatformGraphicsContext;
 #endif
 
 class DeprecatedString;
@@ -57,20 +52,19 @@ namespace WebCore {
     class GraphicsContextPlatformPrivate;
     class IntPoint;
     class IntPointArray;
+    class Path;
 
 #if SVG_SUPPORT
     class KRenderingDeviceContext;
 #endif
 
-#if __APPLE__
-    CGContextRef currentCGContext();
-    void setCompositeOperation(CGContextRef, CompositeOperator);
-#endif
-
     class GraphicsContext : Noncopyable {
     public:
+        GraphicsContext(PlatformGraphicsContext*);
         ~GraphicsContext();
        
+        PlatformGraphicsContext* platformContext() const;
+
         const Font& font() const;
         void setFont(const Font&);
         
@@ -92,6 +86,8 @@ namespace WebCore {
         void drawConvexPolygon(const IntPointArray&);
 
         void fillRect(const IntRect&, const Color&);
+        void clearRect(const FloatRect&);
+        void strokeRect(const FloatRect&, float lineWidth);
 
         void drawImage(Image*, const IntPoint&, CompositeOperator = CompositeSourceOver);
         void drawImage(Image*, const IntRect&, CompositeOperator = CompositeSourceOver);
@@ -143,32 +139,23 @@ namespace WebCore {
         void drawFocusRing(const Color&);
         void clearFocusRing();
 
-        bool printing() const;
+        void setLineWidth(float);
+        void setLineCap(LineCap);
+        void setLineJoin(LineJoin);
+        void setMiterLimit(float);
+
+        void setAlpha(float);
+
+        void setCompositeOperation(CompositeOperator);
+
+        void clip(const Path&);
 
 #if SVG_SUPPORT
         KRenderingDeviceContext* createRenderingDeviceContext();
 #endif
 
-#if __APPLE__
-        GraphicsContext(NSGraphicsContext*);
-        GraphicsContext(CGContextRef, bool flipText, bool forPrinting);
-        CGContextRef platformContext() const;
-#endif
-
 #if WIN32
-        // It's possible to use GetDC to grab the current context from
-        // an HWND; however, we currently require clients to pass in the
-        // Device Context handle directly.  Printing will also
-        // eventually require clients to pass some sort of printer-info
-        // struct to that we can CreateDC the printer device correctly.
-        GraphicsContext(HDC);
-
-        // This is temporarily public to allow Spinneret to do double-buffering.
-        // Long term, we should get the GraphicsContext from the FrameView
-        // and then have a blit() method on the FrameView.
-        GraphicsContext(cairo_t* context);
-
-        cairo_t* platformContext() const;
+        GraphicsContext(HDC); // FIXME: To be removed.
 #endif
 
     private:
@@ -182,7 +169,7 @@ namespace WebCore {
         int focusRingOffset() const;
         const Vector<IntRect>& focusRingRects() const;
         
-        static GraphicsContextPrivate* createGraphicsContextPrivate(bool isForPrinting = false);
+        static GraphicsContextPrivate* createGraphicsContextPrivate();
         static void destroyGraphicsContextPrivate(GraphicsContextPrivate*);
         
         GraphicsContextPrivate* m_common;
similarity index 62%
rename from WebCore/platform/CompositeOperator.cpp
rename to WebCore/platform/GraphicsTypes.cpp
index eacc071a10f6489dcb860d395739b8c2f5085a7c..ff466d88bd815f0f87a26bdf84bd262f65c8c6ee 100644 (file)
  */
 
 #include "config.h"
-#include "CompositeOperator.h"
+#include "GraphicsTypes.h"
 
 #include "PlatformString.h"
+#include <kxmlcore/Assertions.h>
 
 namespace WebCore {
 
@@ -46,11 +47,11 @@ static const char* const compositeOperatorNames[] = {
     "highlight",
     "lighter"
 };
+const int numCompositeOperatorNames = sizeof(compositeOperatorNames) / sizeof(compositeOperatorNames[0]);
 
 bool parseCompositeOperator(const String& s, CompositeOperator& op)
 {
-    const int num = sizeof(compositeOperatorNames) / sizeof(compositeOperatorNames[0]);
-    for (int i = 0; i < num; i++)
+    for (int i = 0; i < numCompositeOperatorNames; i++)
         if (s == compositeOperatorNames[i]) {
             op = static_cast<CompositeOperator>(i);
             return true;
@@ -60,7 +61,59 @@ bool parseCompositeOperator(const String& s, CompositeOperator& op)
 
 String compositeOperatorName(CompositeOperator op)
 {
+    ASSERT(op >= 0);
+    ASSERT(op < numCompositeOperatorNames);
     return compositeOperatorNames[op];
 }
 
+bool parseLineCap(const String& s, LineCap& cap)
+{
+    if (s == "butt") {
+        cap = ButtCap;
+        return true;
+    }
+    if (s == "round") {
+        cap = RoundCap;
+        return true;
+    }
+    if (s == "square") {
+        cap = SquareCap;
+        return true;
+    }
+    return false;
+}
+
+String lineCapName(LineCap cap)
+{
+    ASSERT(cap >= 0);
+    ASSERT(cap < 3);
+    const char* const names[3] = { "butt", "round", "square" };
+    return names[cap];
+}
+
+bool parseLineJoin(const String& s, LineJoin& join)
+{
+    if (s == "miter") {
+        join = MiterJoin;
+        return true;
+    }
+    if (s == "round") {
+        join = RoundJoin;
+        return true;
+    }
+    if (s == "bevel") {
+        join = BevelJoin;
+        return true;
+    }
+    return false;
+}
+
+String lineJoinName(LineJoin join)
+{
+    ASSERT(join >= 0);
+    ASSERT(join < 3);
+    const char* const names[3] = { "miter", "round", "bevel" };
+    return names[join];
+}
+
 }
similarity index 87%
rename from WebCore/platform/CompositeOperator.h
rename to WebCore/platform/GraphicsTypes.h
index 7625647af2550a542defcc2660c4af6dd34745de..1393b0934c6bd3239560822578d33a6434f33ae2 100644 (file)
@@ -23,8 +23,8 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef CompositeOperator_h
-#define CompositeOperator_h
+#ifndef GraphicsTypes_h
+#define GraphicsTypes_h
 
 namespace WebCore {
 
@@ -50,9 +50,19 @@ namespace WebCore {
         CompositePlusLighter
     };
 
+    enum LineCap { ButtCap, RoundCap, SquareCap };
+
+    enum LineJoin { MiterJoin, RoundJoin, BevelJoin };
+
     String compositeOperatorName(CompositeOperator);
     bool parseCompositeOperator(const String&, CompositeOperator&);
 
+    String lineCapName(LineCap);
+    bool parseLineCap(const String&, LineCap&);
+
+    String lineJoinName(LineJoin);
+    bool parseLineJoin(const String&, LineJoin&);
+
 }
 
 #endif
index 2225bfda47171421a006059d9de885adb4701663..5ded93a514e38ee5ee4c6d7f0c75826c14fa84c1 100644 (file)
@@ -113,11 +113,10 @@ IntSize Image::size() const
     // FIXME: Will go away when we make PDF a subclass.
     if (m_isPDF) {
         if (m_PDFDoc) {
-            CGRect mediaBox = m_PDFDoc->mediaBox();
-            return IntSize((int)mediaBox.size.width, (int)mediaBox.size.height);
+            FloatSize size = m_PDFDoc->size();
+            return IntSize((int)size.width(), (int)size.height());
         }
-    } 
-    else
+    } else
 #endif
     
     if (m_sizeAvailable && !m_haveSize) {
@@ -163,7 +162,7 @@ bool Image::setNativeData(NativeBytePtr data, bool allDataReceived)
     // FIXME: Will go away when we make PDF a subclass.
     if (m_isPDF) {
         if (allDataReceived && !m_PDFDoc)
-            m_PDFDoc = new PDFDocumentImage((NSData*)data);
+            m_PDFDoc = new PDFDocumentImage(data);
         return m_PDFDoc;
     }
 #endif
index 32e385720a072d1da97eecefe6ae0cc5f8caef28..efca12833d263741eaf263c6f2b1c120088baab3 100644 (file)
@@ -26,8 +26,8 @@
 #ifndef IMAGE_H_
 #define IMAGE_H_
 
-#include "CompositeOperator.h"
 #include "DeprecatedArray.h"
+#include "GraphicsTypes.h"
 #include "ImageSource.h"
 #include "IntSize.h"
 #include "FloatSize.h"
index cacb05be4f66ece359651feea1f794aa07a16482..fe93ac0108f646fc6a80e358110cf3098ea0dadb 100644 (file)
 #define Path_h
 
 #if __APPLE__
-typedef const struct CGPath* CGPathRef;
+typedef struct CGPath PlatformPath;
+#else
+typedef void PlatformPath;
 #endif
 
 namespace WebCore {
 
-    class IntPoint;
-    class IntPointArray;
-    class IntRect;
+    class FloatPoint;
+    class FloatSize;
+    class FloatRect;
 
     class Path {
     public:
-        enum Type { Ellipse, Rectangle };
-
         Path();
-        Path(const IntRect&, Type = Rectangle);
-        Path(const IntPointArray&);
         ~Path();
 
         Path(const Path&);
         Path& operator=(const Path&);
 
-        bool contains(const IntPoint&) const;
-        IntRect boundingRect() const;
+        bool contains(const FloatPoint&) const;
+        FloatRect boundingRect() const;
+
+        void clear();
+
+        void moveTo(const FloatPoint&);
+        void addLineTo(const FloatPoint&);
+        void addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& point);
+        void addBezierCurveTo(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint&);
+        void addArcTo(const FloatPoint&, const FloatPoint&, float radius);
+        void closeSubpath();
+
+        void addArc(const FloatPoint&, float radius, float startAngle, float endAngle, bool clockwise);
+        void addRect(const FloatRect&);
+        void addEllipse(const FloatRect&);
 
-        void translate(int deltaX, int deltaY);
+        void translate(const FloatSize&);
+
+        PlatformPath* platformPath() const { return m_path; }
 
     private:
-#if __APPLE__
-        CGPathRef m_path;
-#endif
+        PlatformPath* m_path;
     };
 
 }
index 100e347a19902975569e90654e010e3fe6738062..05033f9e2f711fd4bb829d5b7168abc9fddd9544 100644 (file)
 #include "config.h"
 #include "Path.h"
 
-#include "IntPointArray.h"
-#include "IntRect.h"
+#include "FloatRect.h"
 #include <ApplicationServices/ApplicationServices.h>
 
 namespace WebCore {
 
 Path::Path()
-    : m_path(0)
+    : m_path(CGPathCreateMutable())
 {
 }
 
-Path::Path(const IntRect& r, Type t)
-{
-    CGMutablePathRef path = CGPathCreateMutable();
-    if (t == Rectangle)
-        CGPathAddRect(path, 0, r);
-    else // Ellipse
-        CGPathAddEllipseInRect(path, 0, r);
-    m_path = path;
-}
-
-Path::Path(const IntPointArray& arr)
-{
-    CGMutablePathRef path = CGPathCreateMutable();
-    CGPathMoveToPoint(path, 0, arr[0].x(), arr[0].y());
-    for (unsigned i = 1; i < arr.count(); ++i)
-        CGPathAddLineToPoint(path, 0, arr[i].x(), arr[i].y());
-    CGPathCloseSubpath(path);
-    m_path = path;
-}
-
 Path::~Path()
 {
     CGPathRelease(m_path);
 }
 
 Path::Path(const Path& other)
-    : m_path(CGPathCreateCopy(other.m_path))
+    : m_path(CGPathCreateMutableCopy(other.m_path))
 {
 }
 
 Path& Path::operator=(const Path& other)
 {
-    CGPathRef path = CGPathCreateCopy(other.m_path);
+    CGMutablePathRef path = CGPathCreateMutableCopy(other.m_path);
     CGPathRelease(m_path);
     m_path = path;
     return *this;
 }
 
-bool Path::contains(const IntPoint& point) const
+bool Path::contains(const FloatPoint& point) const
 {
     return CGPathContainsPoint(m_path, 0, point, false);
 }
 
-void Path::translate(int deltaX, int deltaY)
+void Path::translate(const FloatSize& size)
 {
-    CGAffineTransform translation = CGAffineTransformMake(1, 0, 0, 1, deltaX, deltaY);
+    CGAffineTransform translation = CGAffineTransformMake(1, 0, 0, 1, size.width(), size.height());
     CGMutablePathRef newPath = CGPathCreateMutable();
     CGPathAddPath(newPath, &translation, m_path);
     CGPathRelease(m_path);
     m_path = newPath;
 }
 
-IntRect Path::boundingRect() const
+FloatRect Path::boundingRect() const
+{
+    return CGPathGetBoundingBox(m_path);
+}
+
+void Path::moveTo(const FloatPoint& point)
+{
+    CGPathMoveToPoint(m_path, 0, point.x(), point.y());
+}
+
+void Path::addLineTo(const FloatPoint& p)
+{
+    CGPathAddLineToPoint(m_path, 0, p.x(), p.y());
+}
+
+void Path::addQuadCurveTo(const FloatPoint& cp, const FloatPoint& p)
+{
+    CGPathAddQuadCurveToPoint(m_path, 0, cp.x(), cp.y(), p.x(), p.y());
+}
+
+void Path::addBezierCurveTo(const FloatPoint& cp1, const FloatPoint& cp2, const FloatPoint& p)
 {
-    return m_path ? enclosingIntRect(CGPathGetBoundingBox(m_path)) : IntRect();
+    CGPathAddCurveToPoint(m_path, 0, cp1.x(), cp1.y(), cp2.x(), cp2.y(), p.x(), p.y());
+}
+
+void Path::addArcTo(const FloatPoint& p1, const FloatPoint& p2, float radius)
+{
+    CGPathAddArcToPoint(m_path, 0, p1.x(), p1.y(), p2.x(), p2.y(), radius);
+}
+
+void Path::closeSubpath()
+{
+    CGPathCloseSubpath(m_path);
+}
+
+void Path::addArc(const FloatPoint& p, float r, float sa, float ea, bool clockwise)
+{
+    CGPathAddArc(m_path, 0, p.x(), p.y(), r, sa, ea, clockwise);
+}
+
+void Path::addRect(const FloatRect& r)
+{
+    CGPathAddRect(m_path, 0, r);
+}
+
+void Path::addEllipse(const FloatRect& r)
+{
+    CGPathAddEllipseInRect(m_path, 0, r);
+}
+
+void Path::clear()
+{
+    CGPathRelease(m_path);
+    m_path = CGPathCreateMutable();
 }
 
 }
index 2460f636d8d88cbd1193af52748b248ba5cc3f46..25ea0a22e8c184c11927a45ab46c441acf83b898 100644 (file)
@@ -32,6 +32,7 @@
 #import "FoundationExtras.h"
 #import "IntPointArray.h"
 #import "KRenderingDeviceQuartz.h"
+#import "Path.h"
 #import "WebCoreSystemInterface.h"
 
 // FIXME: A lot more of this should use CoreGraphics instead of AppKit.
@@ -47,11 +48,10 @@ namespace WebCore {
 
 class GraphicsContextPlatformPrivate {
 public:
-    GraphicsContextPlatformPrivate(CGContextRef, NSGraphicsContext*);
+    GraphicsContextPlatformPrivate(CGContextRef);
     ~GraphicsContextPlatformPrivate();
 
     CGContextRef m_cgContext;
-    NSGraphicsContext* m_nsContext;
     IntRect m_focusRingClip; // Work around CG bug in focus ring clipping.
 };
 
@@ -62,37 +62,20 @@ static inline void fillRectSourceOver(const FloatRect& rect, const Color& col)
     NSRectFillUsingOperation(rect, NSCompositeSourceOver);
 }
 
-GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate(CGContextRef cgContext, NSGraphicsContext* nsContext)
+GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate(CGContextRef cgContext)
 {
-    if (cgContext)
-        m_cgContext = cgContext;
-    else if (nsContext)
-        m_cgContext = static_cast<CGContextRef>([nsContext graphicsPort]);
-    else
-        m_cgContext = 0;
-
-    m_nsContext = nsContext;
-
+    m_cgContext = cgContext;
     CGContextRetain(m_cgContext);
-    KWQRetain(m_nsContext);
 }
 
 GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate()
 {
     CGContextRelease(m_cgContext);
-    KWQRelease(m_nsContext);
-}
-
-GraphicsContext::GraphicsContext(NSGraphicsContext* nsContext)
-    : m_common(createGraphicsContextPrivate(nsContext && ![nsContext isDrawingToScreen]))
-    , m_data(new GraphicsContextPlatformPrivate(0, nsContext))
-{
-    setPaintingDisabled(!nsContext);
 }
 
-GraphicsContext::GraphicsContext(CGContextRef cgContext, bool /*flipText*/, bool forPrinting)
-    : m_common(createGraphicsContextPrivate(forPrinting))
-    , m_data(new GraphicsContextPlatformPrivate(cgContext, 0))
+GraphicsContext::GraphicsContext(CGContextRef cgContext)
+    : m_common(createGraphicsContextPrivate())
+    , m_data(new GraphicsContextPlatformPrivate(cgContext))
 {
     setPaintingDisabled(!cgContext);
 }
@@ -105,22 +88,12 @@ GraphicsContext::~GraphicsContext()
 
 void GraphicsContext::savePlatformState()
 {
-    if (m_data->m_nsContext)
-        [m_data->m_nsContext saveGraphicsState];
-    else if (m_data->m_cgContext)
-        CGContextSaveGState(m_data->m_cgContext);
-    else
-        ASSERT_NOT_REACHED();
+    CGContextSaveGState(platformContext());
 }
 
 void GraphicsContext::restorePlatformState()
 {
-    if (m_data->m_nsContext)
-        [m_data->m_nsContext restoreGraphicsState];
-    else if (m_data->m_cgContext)
-        CGContextRestoreGState(m_data->m_cgContext);
-    else
-        ASSERT_NOT_REACHED();
+    CGContextRestoreGState(platformContext());
 }
 
 // Draws a filled rectangle with a stroked border.
@@ -129,9 +102,8 @@ void GraphicsContext::drawRect(const IntRect& rect)
     if (paintingDisabled())
         return;
 
-    // This function currently works only with NSGraphicsContext.
-    ASSERT(m_data->m_nsContext);
-    ASSERT(m_data->m_nsContext == [NSGraphicsContext currentContext]);
+    // FIXME: This function currently works only when the current context is the current NSGraphicsContext.
+    ASSERT(platformContext() == [[NSGraphicsContext currentContext] graphicsPort]);
 
     if (fillColor() & 0xFF000000)
         fillRectSourceOver(rect, fillColor());
@@ -144,31 +116,28 @@ void GraphicsContext::drawRect(const IntRect& rect)
 
 void GraphicsContext::setColorFromFillColor()
 {
-    // This function currently works only with NSGraphicsContext.
-    ASSERT(m_data->m_nsContext);
-    ASSERT(m_data->m_nsContext == [NSGraphicsContext currentContext]);
+    // FIXME: This function currently works only when the current context is the current NSGraphicsContext.
+    ASSERT(platformContext() == [[NSGraphicsContext currentContext] graphicsPort]);
 
     [nsColor(fillColor()) set];
 }
   
 void GraphicsContext::setColorFromPen()
 {
-    // This function currently works only with NSGraphicsContext.
-    ASSERT(m_data->m_nsContext);
-    ASSERT(m_data->m_nsContext == [NSGraphicsContext currentContext]);
+    // FIXME: This function currently works only when the current context is the current NSGraphicsContext.
+    ASSERT(platformContext() == [[NSGraphicsContext currentContext] graphicsPort]);
 
     [nsColor(pen().color()) set];
 }
   
-  // This is only used to draw borders.
+// This is only used to draw borders.
 void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2)
 {
     if (paintingDisabled())
         return;
 
-    // This function currently works only with NSGraphicsContext.
-    ASSERT(m_data->m_nsContext);
-    ASSERT(m_data->m_nsContext == [NSGraphicsContext currentContext]);
+    // FIXME: This function currently works only when the current context is the current NSGraphicsContext.
+    ASSERT(platformContext() == [[NSGraphicsContext currentContext] graphicsPort]);
 
     Pen::PenStyle penStyle = pen().style();
     if (penStyle == Pen::Pen::NoPen)
@@ -223,11 +192,11 @@ void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2)
         break;
     }
 
+    CGContextSaveGState(platformContext());
+
     setColorFromPen();
-    
-    NSGraphicsContext *graphicsContext = [NSGraphicsContext currentContext];
-    BOOL flag = [graphicsContext shouldAntialias];
-    [graphicsContext setShouldAntialias: NO];
+
+    CGContextSetShouldAntialias(platformContext(), false);
     
     if (patWidth) {
         // Do a rect fill of our endpoints.  This ensures we always have the
@@ -282,7 +251,7 @@ void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2)
     
     [path release];
 
-    [graphicsContext setShouldAntialias: flag];
+    CGContextRestoreGState(platformContext());
 }
 
 
@@ -385,13 +354,6 @@ void GraphicsContext::drawConvexPolygon(const IntPointArray& points)
     CGContextRestoreGState(context);
 }
 
-void setCompositeOperation(CGContextRef context, CompositeOperator op)
-{
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-    [[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO] setCompositingOperation:(NSCompositingOperation)op];
-    [pool release];
-}
-
 static int getBlendedColorComponent(int c, int a)
 {
     // We use white.
@@ -426,9 +388,8 @@ void GraphicsContext::fillRect(const IntRect& rect, const Color& color)
     if (paintingDisabled())
         return;
 
-    // This function currently works only with NSGraphicsContext.
-    ASSERT(m_data->m_nsContext);
-    ASSERT(m_data->m_nsContext == [NSGraphicsContext currentContext]);
+    // FIXME: This function currently works only when the current context is the current NSGraphicsContext.
+    ASSERT(platformContext() == [[NSGraphicsContext currentContext] graphicsPort]);
 
     if (color.alpha())
         fillRectSourceOver(rect, color.rgb());
@@ -614,4 +575,74 @@ CGContextRef GraphicsContext::platformContext() const
     return m_data->m_cgContext;
 }
 
+void GraphicsContext::setLineWidth(float width)
+{
+    CGContextSetLineWidth(platformContext(), width);
+}
+
+void GraphicsContext::setMiterLimit(float limit)
+{
+    CGContextSetMiterLimit(platformContext(), limit);
+}
+
+void GraphicsContext::setAlpha(float alpha)
+{
+    CGContextSetAlpha(platformContext(), alpha);
+}
+
+void GraphicsContext::setCompositeOperation(CompositeOperator op)
+{
+    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+    [[NSGraphicsContext graphicsContextWithGraphicsPort:platformContext() flipped:YES]
+        setCompositingOperation:(NSCompositingOperation)op];
+    [pool release];
+}
+
+void GraphicsContext::clearRect(const FloatRect& r)
+{
+    CGContextClearRect(platformContext(), r);
+}
+
+void GraphicsContext::strokeRect(const FloatRect& r, float lineWidth)
+{
+    CGContextStrokeRectWithWidth(platformContext(), r, lineWidth);
+}
+
+void GraphicsContext::setLineCap(LineCap cap)
+{
+    switch (cap) {
+        case ButtCap:
+            CGContextSetLineCap(platformContext(), kCGLineCapButt);
+            break;
+        case RoundCap:
+            CGContextSetLineCap(platformContext(), kCGLineCapRound);
+            break;
+        case SquareCap:
+            CGContextSetLineCap(platformContext(), kCGLineCapSquare);
+            break;
+    }
+}
+
+void GraphicsContext::setLineJoin(LineJoin join)
+{
+    switch (join) {
+        case MiterJoin:
+            CGContextSetLineJoin(platformContext(), kCGLineJoinMiter);
+            break;
+        case RoundJoin:
+            CGContextSetLineJoin(platformContext(), kCGLineJoinRound);
+            break;
+        case BevelJoin:
+            CGContextSetLineJoin(platformContext(), kCGLineJoinBevel);
+            break;
+    }
+}
+
+void GraphicsContext::clip(const Path& path)
+{
+    CGContextBeginPath(platformContext());
+    CGContextAddPath(platformContext(), path.platformPath());
+    CGContextClip(platformContext());
+}
+
 }
index ac980dc6e8529c06cb7ccaa6bc8c1d65366832ba..b83159df4a9f95eb89513aecb1b50aba1ce00026 100644 (file)
@@ -104,14 +104,14 @@ bool Image::supportsType(const String& type)
 
 // Drawing Routines
 
-static void fillSolidColorInRect(CGColorRef color, CGRect rect, CompositeOperator op, CGContextRef context)
+static void fillSolidColorInRect(GraphicsContext* context, CGColorRef color, CGRect rect, CompositeOperator op)
 {
     if (color) {
-        CGContextSaveGState(context);
-        CGContextSetFillColorWithColor(context, color);
-        setCompositeOperation(context, op);
-        CGContextFillRect(context, rect);
-        CGContextRestoreGState(context);
+        context->save();
+        CGContextSetFillColorWithColor(context->platformContext(), color);
+        context->setCompositeOperation(op);
+        CGContextFillRect(context->platformContext(), rect);
+        context->restore();
     }
 }
 
@@ -136,7 +136,7 @@ void Image::checkForSolidColor(CGImageRef image)
             kCGImageAlphaPremultipliedLast | kCGBitmapFloatComponents | kCGBitmapByteOrder32Host);
 #endif
         if (bmap) {
-            setCompositeOperation(bmap, CompositeCopy);
+            GraphicsContext(bmap).setCompositeOperation(CompositeCopy);
             CGRect dst = { {0, 0}, {1, 1} };
             CGContextDrawImage(bmap, dst, image);
             if (pixel[3] > 0)
@@ -190,10 +190,9 @@ CGImageRef Image::getCGImageRef()
 
 void Image::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator compositeOp)
 {
-    CGContextRef context = ctxt->platformContext();
     if (m_isPDF) {
         if (m_PDFDoc)
-            m_PDFDoc->draw(srcRect, dstRect, compositeOp, 1.0, true, context);
+            m_PDFDoc->draw(ctxt, srcRect, dstRect, compositeOp);
         return;
     } 
     
@@ -208,9 +207,11 @@ void Image::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRec
         return;
 
     if (m_isSolidColor && m_currentFrame == 0)
-        return fillSolidColorInRect(m_solidColor, ir, compositeOp, context);
+        return fillSolidColorInRect(ctxt, m_solidColor, ir, compositeOp);
+
+    CGContextRef context = ctxt->platformContext();
 
-    CGContextSaveGState(context);
+    ctxt->save();
         
     // Get the height (in adjusted, i.e. scaled, coords) of the portion of the image
     // that is currently decoded.  This could be less that the actual height.
@@ -233,7 +234,7 @@ void Image::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRec
     }
 
     // Flip the coords.
-    setCompositeOperation(context, compositeOp);
+    ctxt->setCompositeOperation(compositeOp);
     CGContextTranslateCTM(context, ir.origin.x, ir.origin.y);
     CGContextScaleCTM(context, 1, -1);
     CGContextTranslateCTM(context, 0, -ir.size.height);
@@ -261,7 +262,7 @@ void Image::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRec
     } else // Draw the whole image.
         CGContextDrawImage(context, ir, image);
 
-    CGContextRestoreGState(context);
+    ctxt->restore();
     
     startAnimation();
 
@@ -284,10 +285,8 @@ void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const Fl
     if (!image)
         return;
 
-    CGContextRef context = ctxt->platformContext();
-
     if (m_currentFrame == 0 && m_isSolidColor) {
-        fillSolidColorInRect(m_solidColor, destRect, CompositeSourceOver, context);
+        fillSolidColorInRect(ctxt, m_solidColor, destRect, CompositeSourceOver);
         return;
     }
 
@@ -336,7 +335,9 @@ void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const Fl
                                            kCGPatternTilingConstantSpacing, true, &patternCallbacks);
     
     if (pattern) {
-        CGContextSaveGState(context);
+        CGContextRef context = ctxt->platformContext();
+
+        ctxt->save();
 
         CGPoint tileOrigin = CGPointMake(oneTileRect.origin.x, oneTileRect.origin.y);
         [[WebCoreImageRendererFactory sharedFactory] setPatternPhaseForContext:context inUserSpace:tileOrigin];
@@ -348,11 +349,11 @@ void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const Fl
         CGFloat patternAlpha = 1;
         CGContextSetFillPattern(context, pattern, &patternAlpha);
 
-        setCompositeOperation(context, CompositeSourceOver);
+        ctxt->setCompositeOperation(CompositeSourceOver);
 
         CGContextFillRect(context, destRect);
 
-        CGContextRestoreGState(context);
+        ctxt->restore();
 
         CGPatternRelease(pattern);
     }
@@ -367,12 +368,11 @@ void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& dstRect, const Flo
     if (!image)
         return;
 
-    CGContextRef context = ctxt->platformContext();
-    
     if (m_currentFrame == 0 && m_isSolidColor)
-        return fillSolidColorInRect(m_solidColor, dstRect, CompositeSourceOver, context);
+        return fillSolidColorInRect(ctxt, m_solidColor, dstRect, CompositeSourceOver);
+
+    ctxt->save();
 
-    CGContextSaveGState(context);
     CGSize tileSize = srcRect.size();
     CGRect ir = dstRect;
     CGRect fr = srcRect;
@@ -412,6 +412,8 @@ void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& dstRect, const Flo
                                            patternTransform, tileSize.width, tileSize.height, 
                                            kCGPatternTilingConstantSpacing, true, &patternCallbacks);
     if (pattern) {
+        CGContextRef context = ctxt->platformContext();
+    
         // We want to construct the phase such that the pattern is centered (when stretch is not
         // set for a particular rule).
         float hPhase = scaleX * fr.origin.x;
@@ -431,14 +433,14 @@ void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& dstRect, const Flo
         CGFloat patternAlpha = 1;
         CGContextSetFillPattern(context, pattern, &patternAlpha);
 
-        setCompositeOperation(context, CompositeSourceOver);
+        ctxt->setCompositeOperation(CompositeSourceOver);
         
         CGContextFillRect(context, ir);
 
-        CGPatternRelease (pattern);
+        CGPatternRelease(pattern);
     }
 
-    CGContextRestoreGState(context);
+    ctxt->restore();
 
     startAnimation();
 }
index 3bc0f921960df0453e90f978973a19292214479a..b6b838a1fc6cbaed347bfd81ff68e27f9fd81ca8 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-// ================================================
-// PDF Images (Apple-Only)
-// ================================================
+#include "FloatRect.h"
+#include "GraphicsTypes.h"
 
-#if __APPLE__
 #include <ApplicationServices/ApplicationServices.h>
-#if __OBJC__
-@class NSData;
-#else
-class NSData;
-#endif
-#endif
 
 namespace WebCore {
 
-class PDFDocumentImage {
-public:
-    PDFDocumentImage(NSData* data);
-    ~PDFDocumentImage();
-    
-    CGPDFDocumentRef documentRef();
-    CGRect mediaBox();
-    CGRect bounds(); // adjust for rotation
-    void setCurrentPage(int page);
-    int currentPage();
-    int pageCount();
-    void adjustCTM(CGContextRef context);
+    class GraphicsContext;
 
-    void draw(NSRect fromRect, NSRect toRect, CompositeOperator, float alpha, bool flipped, CGContextRef);
+    class PDFDocumentImage {
+    public:
+        PDFDocumentImage(CFDataRef);
+        ~PDFDocumentImage();
 
-private:
-    CGPDFDocumentRef m_document;
-    CGRect           m_mediaBox;
-    CGRect           m_cropBox;
-    float            m_rotation;
-    int              m_currentPage;
-};
+        FloatSize size() const { return m_mediaBox.size(); }
+        void draw(GraphicsContext*, const FloatRect& fromRect, const FloatRect& toRect, CompositeOperator) const;
+
+    private:
+        void setCurrentPage(int page);
+        int pageCount() const;
+        void adjustCTM(GraphicsContext*) const;
+
+        CGPDFDocumentRef m_document;
+        FloatRect m_mediaBox;
+        FloatRect m_cropBox;
+        float m_rotation;
+        int m_currentPage;
+    };
 
 }
index b424e0618971953a99c272c19a6be4b73ba2ef5e..537695c2f4ed35817ef00c8d2f386c543e5a331e 100644 (file)
  */
 
 #import "config.h"
-#import "Image.h"
 #import "PDFDocumentImage.h"
 
-namespace WebCore {
+#import "GraphicsContext.h"
 
-static void releasePDFDocumentData(void *info, const void *data, size_t size)
-{
-    [(id)info autorelease];
-}
+using namespace std;
 
-PDFDocumentImage::PDFDocumentImage(NSData* data)
+namespace WebCore {
+
+PDFDocumentImage::PDFDocumentImage(CFDataRef data)
 {
-    if (data != nil) {
-        CGDataProviderRef dataProvider = CGDataProviderCreateWithData([data retain], [data bytes], [data length], releasePDFDocumentData);
+    if (data) {
+        CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(data);
         m_document = CGPDFDocumentCreateWithProvider(dataProvider);
         CGDataProviderRelease(dataProvider);
     }
@@ -50,135 +48,91 @@ PDFDocumentImage::~PDFDocumentImage()
     CGPDFDocumentRelease(m_document);
 }
 
-CGPDFDocumentRef PDFDocumentImage::documentRef()
-{
-    return m_document;
-}
-
-CGRect PDFDocumentImage::mediaBox()
-{
-    return m_mediaBox;
-}
-
-CGRect PDFDocumentImage::bounds()
-{
-    CGRect rotatedRect;
-
-    // rotate the media box and calculate bounding box
-    float sina   = sinf(m_rotation);
-    float cosa   = cosf(m_rotation);
-    float width  = m_cropBox.size.width;
-    float height = m_cropBox.size.height;
-
-    // calculate rotated x and y axis
-    NSPoint rx = NSMakePoint( width  * cosa, width  * sina);
-    NSPoint ry = NSMakePoint(-height * sina, height * cosa);
-
-    // find delta width and height of rotated points
-    rotatedRect.origin      = m_cropBox.origin;
-    rotatedRect.size.width  = ceilf(fabs(rx.x - ry.x));
-    rotatedRect.size.height = ceilf(fabs(ry.y - rx.y));
-
-    return rotatedRect;
-}
-
-void PDFDocumentImage::adjustCTM(CGContextRef context)
+void PDFDocumentImage::adjustCTM(GraphicsContext* context) const
 {
     // rotate the crop box and calculate bounding box
-    float sina   = sinf(-m_rotation);
-    float cosa   = cosf(-m_rotation);
-    float width  = m_cropBox.size.width;
-    float height = m_cropBox.size.height;
+    float sina = sinf(-m_rotation);
+    float cosa = cosf(-m_rotation);
+    float width = m_cropBox.width();
+    float height = m_cropBox.height();
 
     // calculate rotated x and y edges of the corp box. if they're negative, it means part of the image has
     // been rotated outside of the bounds and we need to shift over the image so it lies inside the bounds again
-    NSPoint rx = NSMakePoint( width  * cosa, width  * sina);
+    NSPoint rx = NSMakePoint(width * cosa, width * sina);
     NSPoint ry = NSMakePoint(-height * sina, height * cosa);
 
     // adjust so we are at the crop box origin
-    CGContextTranslateCTM(context, floorf(-MIN(0,MIN(rx.x, ry.x))), floorf(-MIN(0,MIN(rx.y, ry.y))));
+    const CGFloat zero = 0;
+    CGContextTranslateCTM(context->platformContext(), floorf(-min(zero, min(rx.x, ry.x))), floorf(-min(zero, min(rx.y, ry.y))));
 
     // rotate -ve to remove rotation
-    CGContextRotateCTM(context, -m_rotation);
+    CGContextRotateCTM(context->platformContext(), -m_rotation);
 
     // shift so we are completely within media box
-    CGContextTranslateCTM(context, m_mediaBox.origin.x - m_cropBox.origin.x, m_mediaBox.origin.y - m_cropBox.origin.y);
+    CGContextTranslateCTM(context->platformContext(), m_mediaBox.x() - m_cropBox.x(), m_mediaBox.y() - m_cropBox.y());
 }
 
 void PDFDocumentImage::setCurrentPage(int page)
 {
-    if (page != m_currentPage && page >= 0 && page < pageCount()) {
+    if (!m_document)
+        return;
 
-        CGRect r;
+    if (page == m_currentPage)
+        return;
 
-        m_currentPage = page;
+    if (!(page >= 0 && page < pageCount()))
+        return;
 
-        // get media box (guaranteed)
-        m_mediaBox = CGPDFDocumentGetMediaBox(m_document, page + 1);
+    m_currentPage = page;
 
-        // get crop box (not always there). if not, use _mediaBox
-        r = CGPDFDocumentGetCropBox(m_document, page + 1);
-        if (!CGRectIsEmpty(r)) {
-            m_cropBox = CGRectMake(r.origin.x, r.origin.y, r.size.width, r.size.height);
-        } else {
-            m_cropBox = CGRectMake(m_mediaBox.origin.x, m_mediaBox.origin.y, m_mediaBox.size.width, m_mediaBox.size.height);
-        }
+    // get media box (guaranteed)
+    m_mediaBox = CGPDFDocumentGetMediaBox(m_document, page + 1);
 
-        // get page rotation angle
-        m_rotation = CGPDFDocumentGetRotationAngle(m_document, page + 1) * M_PI / 180.0; // to radians
-    }
-}
+    // get crop box (not always there). if not, use media box
+    CGRect r = CGPDFDocumentGetCropBox(m_document, page + 1);
+    if (!CGRectIsEmpty(r))
+        m_cropBox = r;
+    else
+        m_cropBox = m_mediaBox;
 
-int PDFDocumentImage::currentPage()
-{
-    return m_currentPage;
+    // get page rotation angle
+    m_rotation = CGPDFDocumentGetRotationAngle(m_document, page + 1) * M_PI / 180.0; // to radians
 }
 
-int PDFDocumentImage::pageCount()
+int PDFDocumentImage::pageCount() const
 {
-    return CGPDFDocumentGetNumberOfPages(m_document);
+    return m_document ? CGPDFDocumentGetNumberOfPages(m_document) : 0;
 }
 
-void PDFDocumentImage::draw(NSRect srcRect, NSRect dstRect, CompositeOperator op, 
-                            float alpha, bool flipped, CGContextRef context)
+void PDFDocumentImage::draw(GraphicsContext* context, const FloatRect& srcRect, const FloatRect& dstRect, CompositeOperator op) const
 {
-    CGContextSaveGState(context);
-
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-    [[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO] setCompositingOperation:(NSCompositingOperation)op];
-    [pool release];
+    if (!m_document || m_currentPage == -1)
+        return;
 
-    // Scale and translate so the document is rendered in the correct location.
-    float hScale = dstRect.size.width  / srcRect.size.width;
-    float vScale = dstRect.size.height / srcRect.size.height;
+    context->save();
 
-    CGContextTranslateCTM(context, dstRect.origin.x - srcRect.origin.x * hScale, dstRect.origin.y - srcRect.origin.y * vScale);
-    CGContextScaleCTM(context, hScale, vScale);
+    context->setCompositeOperation(op);
 
-    // Reverse if flipped image.
-    if (flipped) {
-        CGContextScaleCTM(context, 1, -1);
-        CGContextTranslateCTM(context, 0, -dstRect.size.height);
-    }
-
-    // Clip to destination in case we are imaging part of the source only
-    CGContextClipToRect(context, CGRectIntegral(*(CGRect*)&srcRect));
+    float hScale = dstRect.width() / srcRect.width();
+    float vScale = dstRect.height() / srcRect.height();
 
-    // and draw
-    if (m_document) {
-        CGContextSaveGState(context);
-        // Rotate translate image into position according to doc properties.
-        adjustCTM(context);
+    // Scale and translate so the document is rendered in the correct location,
+    // including accounting for the fact that a GraphicsContext is always flipped
+    // and doing appropriate flipping.
+    CGContextTranslateCTM(context->platformContext(), dstRect.x() - srcRect.x() * hScale, dstRect.y() - srcRect.y() * vScale);
+    CGContextScaleCTM(context->platformContext(), hScale, vScale);
+    CGContextScaleCTM(context->platformContext(), 1, -1);
+    CGContextTranslateCTM(context->platformContext(), 0, -dstRect.height());
+    CGContextClipToRect(context->platformContext(), CGRectIntegral(srcRect));
 
-        // Media box may have non-zero origin which we ignore. CGPDFDocumentShowPage pages start
-        // at 1, not 0.
-        CGContextDrawPDFDocument(context, CGRectMake(0, 0, m_mediaBox.size.width, m_mediaBox.size.height), m_document, 1);
+    // Rotate translate image into position according to doc properties.
+    adjustCTM(context);
 
-        CGContextRestoreGState(context);
-    }
+    // Media box may have non-zero origin which we ignore. Pass 1 for the page number.
+    CGContextDrawPDFDocument(context->platformContext(), FloatRect(FloatPoint(), size()),
+        m_document, m_currentPage + 1);
 
-    // done with our fancy transforms
-    CGContextRestoreGState(context);
+    context->restore();
 }
 
 }
index 6250ca129638390c92da698c838946e669e32bf5..79d01acf8343b4b14ca91663f3c335182f1f1d9e 100644 (file)
@@ -315,12 +315,16 @@ NSView* Widget::getOuterView() const
     return view;
 }
 
+// FIXME: Get rid of the single use of these next two functions (frame resizing), and remove them.
+
 GraphicsContext* Widget::lockDrawingFocus()
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
     [getView() lockFocus];
     END_BLOCK_OBJC_EXCEPTIONS;
-    return new GraphicsContext([NSGraphicsContext currentContext]);
+    PlatformGraphicsContext* platformContext = static_cast<PlatformGraphicsContext*>([[NSGraphicsContext currentContext] graphicsPort]);
+    ASSERT([[NSGraphicsContext currentContext] isFlipped]);
+    return new GraphicsContext(platformContext);
 }
 
 void Widget::unlockDrawingFocus(GraphicsContext* context)
index 833e46c05ae0b5565656118bba56d092bdee1504..079cc35fc49c5eeae409eef5a49cd31c10bc61d7 100644 (file)
@@ -273,16 +273,33 @@ void GraphicsContext::beginTransparencyLayer(float) { }
 void GraphicsContext::endTransparencyLayer() { }
 Color GraphicsContext::selectedTextBackgroundColor() const { return Color(0,0,255); }
 void GraphicsContext::addRoundedRectClip(IntRect const&,IntSize const&,IntSize const&,IntSize const&,IntSize const&) { }
+void GraphicsContext::clearRect(const FloatRect&) { }
+void GraphicsContext::strokeRect(const FloatRect&, float) { }
+void GraphicsContext::setLineWidth(float) { }
+void GraphicsContext::setLineCap(LineCap) { }
+void GraphicsContext::setLineJoin(LineJoin) { }
+void GraphicsContext::setMiterLimit(float) { }
+void GraphicsContext::setAlpha(float) { }
+void GraphicsContext::setCompositeOperation(CompositeOperator) { }
+void GraphicsContext::clip(const Path&) { }
 
 Path::Path(){ }
 Path::~Path(){ }
 Path::Path(const Path&){ }
-Path::Path(const IntRect&, Type){ }
-Path::Path(const IntPointArray&){ }
 bool Path::contains(const IntPoint&) const{ return false; }
-void Path::translate(int, int){ }
+void Path::translate(const FloatSize&){ }
 IntRect Path::boundingRect() const { return IntRect(); }
 Path& Path::operator=(const Path&){ return*this; }
+void Path::clear() { }
+void Path::moveTo(const FloatPoint&) { }
+void Path::addLineTo(const FloatPoint&) { }
+void Path::addQuadCurveTo(const FloatPoint&, const FloatPoint&) { }
+void Path::addBezierCurveTo(const FloatPoint&, const FloatPoint&, const FloatPoint&) { }
+void Path::addArcTo(const FloatPoint&, const FloatPoint&, float) { }
+void Path::closeSubpath() { }
+void Path::addArc(const FloatPoint&, float, float, float, bool) { }
+void Path::addRect(const FloatRect&) { }
+void Path::addEllipse(const FloatRect&) { }
 
 QLineEdit::QLineEdit(QLineEdit::Type) { }
 QLineEdit::~QLineEdit() { }
index 2501bdbea724a9d8cf34a01325aff98006b52d18..2e95547acc3426a244a37289d51983c5c56dfcf6 100644 (file)
@@ -244,8 +244,8 @@ void InlineTextBox::paint(RenderObject::PaintInfo& i, int tx, int ty)
     int w = width() + 2 * parent()->maxHorizontalShadow();
     if (xPos >= i.r.right() || xPos + w <= i.r.x())
         return;
-        
-    bool isPrinting = i.p->printing();
+
+    bool isPrinting = textObject()->document()->printing();
     
     // Determine whether or not we're selected.
     bool haveSelection = !isPrinting && selectionState() != RenderObject::SelectionNone;
index cb3e64c921fb0cb1537a2a3d18ed2c24193ea849..460184c01c93e49e7ed098acdb09dde75ceb7659 100644 (file)
@@ -1261,7 +1261,7 @@ void RenderBlock::paintChildren(PaintInfo& i, int _tx, int _ty)
     // We don't paint our own background, but we do let the kids paint their backgrounds.
     PaintInfo paintInfo(i);
     paintInfo.phase = newPhase;
-    bool isPrinting = i.p->printing();
+    bool isPrinting = document()->printing();
 
     for (RenderObject *child = firstChild(); child; child = child->nextSibling()) {        
         // Check for page-break-before: always, and if it's set, break and bail.
@@ -1332,7 +1332,7 @@ void RenderBlock::paintObject(PaintInfo& i, int _tx, int _ty)
     }
     
     // 3. paint selection
-    bool isPrinting = i.p->printing();
+    bool isPrinting = document()->printing();
     if (!inlineFlow && !isPrinting)
         paintSelection(i, scrolledX, scrolledY); // Fill in gaps in selection on lines and between blocks.
 
index 2ce8f2af2a3a3ab6ef3b9ba058502a9c758aae36..aa91b9bd36f78bb98cf901aba2ce529cc02ce9c3 100644 (file)
@@ -378,7 +378,7 @@ void RenderFlow::paintLines(PaintInfo& i, int _tx, int _ty)
     // See if our root lines intersect with the dirty rect.  If so, then we paint
     // them.  Note that boxes can easily overlap, so we can't make any assumptions
     // based off positions of our first line box or our last line box.
-    bool isPrinting = info.p->printing();
+    bool isPrinting = document()->printing();
     for (InlineFlowBox* curr = firstLineBox(); curr; curr = curr->nextFlowBox()) {
         if (isPrinting) {
             // FIXME: This is a feeble effort to avoid splitting a line across two pages.
index 24f505947cda4ad1cecc1fd5e5e6da64bbbaf40e..d8202f741a70a0a91918f5419fb92b91fa547d98 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "RenderHTMLCanvas.h"
 
+#include "Document.h"
 #include "GraphicsContext.h"
 #include "HTMLCanvasElement.h"
 #include "HTMLNames.h"
@@ -64,7 +65,7 @@ void RenderHTMLCanvas::paint(PaintInfo& i, int tx, int ty)
     if (!shouldPaintWithinRoot(i))
         return;
 
-    bool drawSelectionTint = selectionState() != SelectionNone && !i.p->printing();
+    bool drawSelectionTint = selectionState() != SelectionNone && !document()->printing();
     if (i.phase == PaintPhaseSelection) {
         if (selectionState() == SelectionNone)
             return;
index 7beb84a1edd3076795d80e30f9b5bc639e550e29..d86e01c93e316230f2037d8af4e8845c0f212c10 100644 (file)
@@ -187,7 +187,7 @@ void RenderImage::paint(PaintInfo& i, int _tx, int _ty)
     if (!shouldPaintWithinRoot(i))
         return;
         
-    bool isPrinting = i.p->printing();
+    bool isPrinting = document()->printing();
     bool drawSelectionTint = isSelected() && !isPrinting;
     if (i.phase == PaintPhaseSelection) {
         if (selectionState() == SelectionNone)
index dfc2413ae80cb6bbcc364d44221e685c07487668..78a5442b417d119962969af2a8496cb7f8b49aba 100644 (file)
@@ -517,7 +517,7 @@ bool RenderThemeMac::paintButton(RenderObject* o, const RenderObject::PaintInfo&
     }
 
     [button drawWithFrame:NSRect(inflatedRect) inView:o->canvas()->view()->getDocumentView()];
-    [button setControlView: nil];
+    [button setControlView:nil];
 
     return false;
 }
index ec73d6259df0eae8c2deeb5a3a8f1a0463f16949..ee3a17721a711d58f23ee685d226ed864cd3e0df 100644 (file)
@@ -402,7 +402,7 @@ void RenderListMarker::paint(PaintInfo& i, int _tx, int _ty)
     GraphicsContext* p = i.p;
     p->setFont(style()->font());
 
-    if (p->printing()) {
+    if (document()->printing()) {
         if (box.y() < i.r.y())
             // This has been printed already we suppose.
             return;
index f916b0673cea0b22f0ea5761ad908d08c6be2eb9..fe1102323598a450fc488f2109502876765b51e6 100644 (file)
@@ -386,7 +386,7 @@ void RenderWidget::paint(PaintInfo& i, int tx, int ty)
     }
 
     // Paint a partially transparent wash over selected widgets.
-    if (isSelected() && !i.p->printing())
+    if (isSelected() && !document()->printing())
         i.p->fillRect(selectionRect(), selectionColor(i.p));
 }