Reviewed by Hyatt.
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Apr 2006 06:52:11 +0000 (06:52 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Apr 2006 06:52:11 +0000 (06:52 +0000)
        - make <canvas> element and related API behave more like the draft of
          the WhatWG Web Application specification, checking parameter validity
          and raising exceptions
        - changed HTMLCanvasElement bindings to be auto-generated, fixing all
          issues so we can generate bindings for classes drived from HTMLElement
        - change GraphicsContext API to use IntRect/Point/Size in more cases
        - change GraphicsContext so it is closer to truly wrapping a graphics
          context rather than representing the current NSGraphicsContext; there
          are still some things like text and rectangle fills that are tied to
          NSGraphicsContext, but we're most of the way there
        - removed Brush class since it just amounted to a color, using an RGBA32
          instead where we used to use a Brush

        * DerivedSources.make: Added JSHTMLCanvasElement.h.
        * WebCore.xcodeproj/project.pbxproj: Added new files.

        * bindings/js/JSCanvasRenderingContext2DBase.h: Added toJS.
        * bindings/js/JSCanvasRenderingContext2DBase.cpp:
        (WebCore::JSCanvasRenderingContext2DBaseProtoFunc::callAsFunction):
        Added exception code handling for strokeRect, drawImage, and createPattern.
        Added version of createPattern that takes a canvas. Use TYPE_MISMATCH_ERR
        instead of JavaScript TypeError when parameter is neither an image or canvas
        element. Adapt for new HTMLCanvasElement binding.
        (WebCore::toJS): Added. Converts context object to JS wrapper.

        * bindings/js/JSHTMLElementWrapperFactory.h: Added.
        * bindings/js/JSHTMLElementWrapperFactory.cpp: Added. Creates a JavaScript
        wrapper for an arbitrary HTML element. Better than putting this all in the
        DOM node class toJS function.

        * bindings/js/JSXMLSerializer.cpp: Tweaked to make it build.
        * bindings/js/kjs_dom.cpp: (KJS::toJS): Changed to call the
        JSHTMLElementWrapperFactory function createJSWrapper, instead
        of always creating a JSHTMLElement.

        * bindings/js/kjs_html.h: Removed canvas-related stuff. Added HTMLElement
        prototype.
        * bindings/js/kjs_html.cpp:
        (KJS::JSHTMLElement::classInfo): Removed canvas element.
        (KJS::JSHTMLElement::accessors): Ditto.
        (KJS::JSHTMLElementProtoFunc::callAsFunction): Added, to help the auto-binding
        machiner cope with HTMLElement.
        (KJS::HTMLElementFunction::callAsFunction): Removed canvas element.

        * bindings/scripts/CodeGeneratorJS.pm: Added types needed for HTMLCanvasElement.

        * bridge/mac/FrameMac.mm: (WebCore::FrameMac::setDisplaysWithFocusAttributes):
        Changed to create a GraphicsContext with the new constructor that takes
        a CGContextRef.
        * bridge/mac/WebCoreFrameBridge.mm: (-[WebCoreFrameBridge drawRect:]):
        Changed to create a GraphicsContext with the new constructor that takes
        a NSGraphicsContext.
        * page/Frame.cpp: (WebCore::Frame::adjustPageHeight): Changed to create a
        GraphicsContext with the new constructor that takes a CGContextRef.

        * editing/SelectionController.cpp: (WebCore::SelectionController::paintCaret):
        Eliminated a use of obsolete class Brush.

        * html/CanvasPattern.h:
        * html/CanvasPattern.cpp:
        (WebCore::CanvasPattern::parseRepetitionType): Added. Parses a repetition
        type. Different from the old logic in that it is case-sensitive and rejects
        anything other than null, empty string, or the four repeat types.
        (WebCore::CanvasPattern::CanvasPattern): Added constructor that takes
        a CGImageRef. Changed constructor to take two booleans instead of the repetition
        type string. It's the caller's responsibility to parse the string.
        (WebCore::CanvasPattern::~CanvasPattern): Release the CGImage.
        (WebCore::patternCallback): Handle the CGImage case. Also changed the code
        to create a GraphicsContext as needed and call the image drawing code with that.
        (WebCore::CanvasPattern::createPattern): Handle both the image element case and
        the canvas element case.

        * html/CanvasRenderingContext2D.h:
        * html/CanvasRenderingContext2D.cpp:
        (WebCore::CanvasRenderingContext2D::State::State): Change line cap, line join,
        and global composite to store enum values instead of strings.
        (WebCore::CanvasRenderingContext2D::setLineWidth): Do nothing if width is NaN
        or <= 0.
        (WebCore::CanvasRenderingContext2D::lineCap): Return a string based on a
        stored enum, rather than returning a stored string.
        (WebCore::CanvasRenderingContext2D::setLineCap): Do nothing if the string is
        not one of the standard line cap types. Also case sensitive and stores enum
        rather than the string.
        (WebCore::CanvasRenderingContext2D::lineJoin): Return a string based on a
        stored enum, rather than returning a stored string.
        (WebCore::CanvasRenderingContext2D::setLineJoin): Do nothing if the string is
        not one of the standard line join types. Also case sensitive and stores enum
        rather than the string.
        (WebCore::CanvasRenderingContext2D::setMiterLimit): Do nothing if limit is NaN
        or <= 0.
        (WebCore::CanvasRenderingContext2D::setGlobalAlpha): Do nothing if alpha is NaN
        or < 0 or > 1.
        (WebCore::CanvasRenderingContext2D::globalCompositeOperation): Return a string
        based on a stored enum, rather than returning a stored string.
        (WebCore::CanvasRenderingContext2D::setGlobalCompositeOperation): Do nothing if
        the string is not one of the standard compositing modes. Also case sensitive and
        stores enum rather than the string.
        (WebCore::CanvasRenderingContext2D::arcTo): Generate INDEX_SIZE_ERR exception
        if radius is NaN or <= 0.
        (WebCore::CanvasRenderingContext2D::arc): Ditto.
        (WebCore::CanvasRenderingContext2D::rect): Generate INDEX_SIZE_ERR exception
        if width or height is NaN or <= 0.
        (WebCore::CanvasRenderingContext2D::clearRect): Ditto.
        (WebCore::CanvasRenderingContext2D::fillRect): Ditto.
        (WebCore::CanvasRenderingContext2D::strokeRect): Ditto, same for line width.
        Changed the case where the line width is not specified to share code with the
        case where it is.
        (WebCore::size): Renamed from imageSize, since C++ overloads based on parameter
        types anyway.
        (WebCore::CanvasRenderingContext2D::drawImage): Generate INDEX_SIZE_ERR exception
        if the source rect is not entirely inside the image rect, or if the width or height
        of either the source or destination rect is NaN or <= 0. Changed image drawing
        code to be platform-independent for the image element case, but not yet for the
        canvas case.
        (WebCore::CanvasRenderingContext2D::drawImageFromRect): Change code to parse the
        composite operation to use the new code shared with Image.
        (WebCore::CanvasRenderingContext2D::createPattern): Added code to parse the
        repetition type separately before creating the pattern. Added an overload for
        canvas elements.
        (WebCore::CanvasRenderingContext2D::drawingContext): Changed to return a
        GraphicsContext*.
        (WebCore::CanvasRenderingContext2D::platformContext): Added. Now does what
        drawingContext used to do.

        * html/CanvasRenderingContext2D.idl: Added exception declarations as needed
        for changes above.

        * html/HTMLCanvasElement.h:
        * html/HTMLCanvasElement.cpp:
        (WebCore::HTMLCanvasElement::HTMLCanvasElement): Changed m_drawingContext
        to be a GraphicsContext instead of a CGContextRef.
        (WebCore::HTMLCanvasElement::~HTMLCanvasElement): Ditto.
        (WebCore::HTMLCanvasElement::getContext): Removed special cases for null
        and empty string. Only give a 2D graphics context if the string is "2d".
        (WebCore::HTMLCanvasElement::reset): Updated for change to GraphicsContext
        from CGContextRef.
        (WebCore::HTMLCanvasElement::paint): Ditto.
        (WebCore::HTMLCanvasElement::createDrawingContext): Changed to create a
        GraphicsContext* instead of a CGContextRef.
        (WebCore::HTMLCanvasElement::drawingContext): Changed to return a
        GraphicsContext* instead of a CGContextRef.
        (WebCore::HTMLCanvasElement::createPlatformImage): Updated for changes above.

        * html/HTMLCanvasElement.idl: Added.

        * html/HTMLParser.h:
        * html/HTMLParser.cpp:
        (WebCore::HTMLParser::canvasCreateErrorCheck): Added. An attempt to implement the
        fallback behavior for canvas elements when JavaScript is off.
        (WebCore::HTMLParser::getNode): Sorted list of functions. Added case for canvas.

        * html/html_imageimpl.h:
        * html/html_imageimpl.cpp:
        (WebCore::HTMLImageElement::HTMLImageElement): Changed m_compositeOperator to be
        an enum instead of a string.
        (WebCore::HTMLImageElement::parseMappedAttribute): Parse the enum here.

        * kcanvas/KCanvasResources.h:
        * kcanvas/KCanvasResources.cpp: (WebCore::KCanvasMarker::draw): Changed to take a
        GraphicsContext parameter.

        * kcanvas/RenderPath.h: Added GraphicsContext parameter to drawMarkersIfNeeded.

        * kcanvas/RenderPath.cpp: (WebCore::RenderPath::paint):
        * kcanvas/RenderSVGImage.cpp: (WebCore::RenderSVGImage::paint):
        * kcanvas/RenderSVGText.cpp: (WebCore::RenderSVGText::paint):
        Changed to generate and use an appropriate GraphicsContext.

        * kcanvas/device/quartz/KCanvasItemQuartz.h: Added GraphicsContext parameter to
        drawMarkersIfNeeded.
        * kcanvas/device/quartz/KCanvasItemQuartz.mm:
        (WebCore::DrawMarkersData::DrawMarkersData): Added GraphicsContext*.
        (WebCore::drawMarkerWithData): Pass along a GraphicsContext*.
        (WebCore::drawStartAndMidMarkers): Ditto.
        (WebCore::KCanvasItemQuartz::drawMarkersIfNeeded): Pass a long a GraphicsContext*.

        * kcanvas/device/KRenderingDevice.h: Added a pure virtual createGraphicsContext
        to bridge back to a GraphicsContext. Long term that class will replace this one.
        * kcanvas/device/quartz/KRenderingDeviceQuartz.h:
        * kcanvas/device/quartz/KRenderingDeviceQuartz.mm:
        (WebCore::KRenderingDeviceContextQuartz::createGraphicsContext): Added.

        * ksvg2/svg/SVGMaskElement.cpp: (WebCore::SVGMaskElement::drawMaskerContent):
        Create and pass a GraphicsContext -- old code used the default constructor for
        GraphicsContext which meant "current context", and that no longer exists.
        * ksvg2/svg/SVGPatternElement.cpp:
        (WebCore::SVGPatternElement::drawPatternContentIntoTile): Ditto.

        * platform/Brush.h: Removed.
        * platform/CompositeOperator.h: Added.
        * platform/CompositeOperator.cpp: Added.

        * platform/Font.h: Changed calls to use IntPoint instead of pairs of ints.
        Also removed the const from all the uses of GraphicsContext*.

        * platform/GraphicsContext.h: Eliminated default constructor and constructor
        that takes only a boolean. Replaced with constructors that take platform
        graphics contexts only. Replaced brush-related calls with fill color calls.
        Replaced use of Brush with use of Color. Changed Image::CompositeOperator to
        just plain CompositeOperator. Changed tuples of ints into IntRect and IntPoint.
        Moved setFocusRingClip and clearFocusRingClip out of ifdefs. Removed unused
        getCompositeOperation and string-based setCompositeOperation. Moved
        currentCGContext and the other setCompositeOperation out of the GraphicsContext
        class and made them global functions. Fixed platformContext so it won't always
        return the CGContextRef of the current NSGraphicsContext. Instead, it will
        return the appropriate CGContextRef for the GraphicsContext. This eliminates
        the need to use void* for the image-drawing functions.

        * platform/GraphicsContext.cpp:
        (WebCore::GraphicsContextState::GraphicsContextState): Replaced Brush with
        an RGBA fill color.
        (WebCore::GraphicsContext::setFillColor): Renamed from setBrush.
        (WebCore::GraphicsContext::fillColor): Renamed from brush.
        (WebCore::GraphicsContext::drawImage): Changed to use IntRect.
        (WebCore::GraphicsContext::drawTiledImage): Moved here from GraphicsContextMac.mm.
        (WebCore::GraphicsContext::drawText): Changed to use IntPoint.
        (WebCore::GraphicsContext::drawHighlightForText): Ditto.
        (WebCore::GraphicsContext::drawLineForText): Ditto.
        (WebCore::GraphicsContext::drawLineForMisspelling): Ditto.

        * platform/Image.h: Removed CompositeOperator and related functions.
        Removed void* context parameters from draw functions.

        * platform/Image.cpp: Removed compositeOperatorFromString.

        * platform/Widget.h: Added a GraphicsContext* return value from lockDrawingFocus
        that you pass back to unlockDrawingFocus (for deletion).

        * platform/mac/FontMac.mm:
        (WebCore::Font::selectionRectForText): Changed parameter to point and removed
        const on GraphicsContext* parameter.
        (WebCore::Font::drawText): Ditto.
        (WebCore::Font::drawHighlightForText): Ditto.
        (WebCore::Font::drawLineForText): Ditto.
        (WebCore::Font::drawLineForMisspelling): Ditto.
        (WebCore::Font::misspellingLineThickness): Removed const.

        * platform/mac/GraphicsContextMac.mm:
        (WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate):
        Added fields to store a CGContextRef and an NSGraphicsContext.
        (WebCore::GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate):
        Release both the CGContextRef and the NSGraphicsContext.
        (WebCore::GraphicsContext::GraphicsContext): Implement to set up both the
        CGContextRef and the NSGraphicsContext in one case, and only the CGContextRef
        in the other.
        (WebCore::GraphicsContext::savePlatformState): Implement for the CGContext-only
        case.
        (WebCore::GraphicsContext::restorePlatformState): Ditto.
        (WebCore::GraphicsContext::drawRect): Assert that the NS context is present
        and
        (WebCore::GraphicsContext::setColorFromFillColor): Renamed from
        setColorFromBrush.
        (WebCore::GraphicsContext::setColorFromPen): Added assertion.
        (WebCore::GraphicsContext::drawLine): Added assertion.
        (WebCore::GraphicsContext::drawEllipse): Get CGContext from the platformContext
        function instead of currentCGContext, and changed to use fillColor.
        (WebCore::GraphicsContext::drawArc): Ditto.
        (WebCore::GraphicsContext::drawConvexPolygon): Ditto.
        (WebCore::setCompositeOperation): Changed to global function and also changed
        to do the work here -- no need to use WebCoreImageRendererFactory.
        (WebCore::GraphicsContext::drawImage): Move most of this into GraphicsContext.cpp.
        Remove the void* context parameter. Changed to take rects instead of separate coordinates.
        (WebCore::GraphicsContext::fillRect): Changed to take color instead of Brush.
        (WebCore::GraphicsContext::addClip): Added assertion.
        (WebCore::GraphicsContext::addRoundedRectClip): Get CGContextRef from the platformContext
        function instead of currentCGContext.
        (WebCore::GraphicsContext::createRenderingDeviceContext): Ditto.
        (WebCore::GraphicsContext::beginTransparencyLayer): Ditto.
        (WebCore::GraphicsContext::endTransparencyLayer): Ditto.
        (WebCore::GraphicsContext::setShadow): Change to take size instead of x,y. Also get
        CGCOntextRef from the platformContext function instead of currentCGContext.
        (WebCore::GraphicsContext::clearShadow): Get CGContextRef from the platformContext
        function instead of currentCGContext.
        (WebCore::GraphicsContext::platformContext): Added. Returns m_data->m_cgContext.

        * platform/mac/ImageMac.mm:
        (WebCore::fillSolidColorInRect): Updated for change in CompositeOperator type.
        (WebCore::Image::checkForSolidColor): Ditto.
        (WebCore::Image::draw): Removed void* context parameter and replaced it with
        a GraphicsContext* parameter. Renamed from drawInRect.
        (WebCore::Image::drawTiled): Ditto. Renamed from tileInRect and scaleAndTileInRect.

        * platform/mac/PDFDocumentImage.h: Updated for change in CompositeOperator type.
        * platform/mac/PDFDocumentImage.mm: (WebCore::PDFDocumentImage::draw): Ditto.

        * platform/mac/WidgetMac.mm:
        (WebCore::Widget::lockDrawingFocus): Changed to return a GraphicsContext*.
        (WebCore::Widget::unlockDrawingFocus): Changed to take a GraphicsContext*.

        * rendering/InlineTextBox.cpp:
        (WebCore::InlineTextBox::selectionRect): Changed to pass IntPoint.
        (WebCore::InlineTextBox::paint): Changed to pass IntSize.
        (WebCore::InlineTextBox::paintSelection): More of the same.
        (WebCore::InlineTextBox::paintMarkedTextBackground): Ditto.
        (WebCore::InlineTextBox::paintDecoration): Ditto.
        (WebCore::InlineTextBox::paintSpellingMarker): Ditto.
        (WebCore::InlineTextBox::paintTextMatchMarker): Ditto.
        (WebCore::InlineTextBox::paintMarkedTextUnderline): Ditto.
        (WebCore::InlineTextBox::positionForOffset): Ditto.
        * rendering/RenderBlock.cpp:
        (WebCore::RenderBlock::fillHorizontalSelectionGap): Ditto.
        (WebCore::RenderBlock::fillVerticalSelectionGap): Ditto.
        (WebCore::RenderBlock::fillLeftSelectionGap): Ditto.
        (WebCore::RenderBlock::fillRightSelectionGap): Ditto.
        * rendering/RenderBox.cpp:
        (WebCore::RenderBox::paintBackgroundExtended): Ditto.
        (WebCore::RenderBox::outlineBox): Ditto.
        * rendering/RenderImage.cpp:
        (WebCore::RenderImage::paint): Ditto.
        * rendering/RenderLayer.cpp:
        (WebCore::setClip): Take out ifdefs. We'll do that inside GraphicsContext instead.
        (WebCore::restoreClip): Ditto.
        * rendering/RenderObject.cpp:
        (WebCore::RenderObject::drawBorder): More of the same.
        (WebCore::RenderObject::paintBorderImage): Ditto.
        * rendering/render_line.cpp:
        (WebCore::InlineFlowBox::paintDecorations): Ditto.
        (WebCore::EllipsisBox::paint): Ditto.
        * rendering/render_list.cpp:
        (WebCore::RenderListMarker::paint): Ditto.

        * rendering/render_frames.cpp: (WebCore::RenderFrameSet::userResize): Set up a graphics
        context by calling lockDrawingFocus. Also changed a color here to be a constant.

        * platform/cairo/GraphicsContextCairo.cpp:
        (WebCore::GraphicsContext::drawImage): Update for parameter type changes.
        (WebCore::GraphicsContext::drawScaledAndTiledImage):
        (WebCore::GraphicsContext::setFocusRingClip):
        (WebCore::GraphicsContext::clearFocusRingClip):
        * platform/cairo/ImageCairo.cpp:
        (WebCore::setCompositingOperation):
        (WebCore::Image::tileInRect):
        (WebCore::Image::scaleAndTileInRect):

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

68 files changed:
WebCore/ChangeLog
WebCore/DerivedSources.make
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/bindings/js/JSCanvasRenderingContext2DBase.cpp
WebCore/bindings/js/JSCanvasRenderingContext2DBase.h
WebCore/bindings/js/JSHTMLElementWrapperFactory.cpp [new file with mode: 0644]
WebCore/bindings/js/JSHTMLElementWrapperFactory.h [new file with mode: 0644]
WebCore/bindings/js/JSXMLSerializer.cpp
WebCore/bindings/js/kjs_dom.cpp
WebCore/bindings/js/kjs_html.cpp
WebCore/bindings/js/kjs_html.h
WebCore/bindings/scripts/CodeGeneratorJS.pm
WebCore/bridge/mac/FrameMac.mm
WebCore/bridge/mac/WebCoreFrameBridge.mm
WebCore/editing/SelectionController.cpp
WebCore/html/CanvasPattern.cpp
WebCore/html/CanvasPattern.h
WebCore/html/CanvasRenderingContext2D.cpp
WebCore/html/CanvasRenderingContext2D.h
WebCore/html/CanvasRenderingContext2D.idl
WebCore/html/HTMLCanvasElement.cpp
WebCore/html/HTMLCanvasElement.h
WebCore/html/HTMLCanvasElement.idl [new file with mode: 0644]
WebCore/html/HTMLParser.cpp
WebCore/html/HTMLParser.h
WebCore/html/html_imageimpl.cpp
WebCore/html/html_imageimpl.h
WebCore/kcanvas/KCanvasResources.cpp
WebCore/kcanvas/KCanvasResources.h
WebCore/kcanvas/RenderPath.cpp
WebCore/kcanvas/RenderPath.h
WebCore/kcanvas/RenderSVGImage.cpp
WebCore/kcanvas/RenderSVGText.cpp
WebCore/kcanvas/device/KRenderingDevice.h
WebCore/kcanvas/device/quartz/KCanvasItemQuartz.h
WebCore/kcanvas/device/quartz/KCanvasItemQuartz.mm
WebCore/kcanvas/device/quartz/KRenderingDeviceQuartz.h
WebCore/kcanvas/device/quartz/KRenderingDeviceQuartz.mm
WebCore/ksvg2/svg/SVGMaskElement.cpp
WebCore/ksvg2/svg/SVGPatternElement.cpp
WebCore/page/Frame.cpp
WebCore/platform/CompositeOperator.cpp [moved from WebCore/platform/Brush.h with 60% similarity]
WebCore/platform/CompositeOperator.h [new file with mode: 0644]
WebCore/platform/Font.h
WebCore/platform/GraphicsContext.cpp
WebCore/platform/GraphicsContext.h
WebCore/platform/Image.cpp
WebCore/platform/Image.h
WebCore/platform/Widget.h
WebCore/platform/cairo/GraphicsContextCairo.cpp
WebCore/platform/cairo/ImageCairo.cpp
WebCore/platform/mac/FontMac.mm
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/FontWin.cpp
WebCore/platform/win/TemporaryLinkStubs.cpp
WebCore/rendering/InlineTextBox.cpp
WebCore/rendering/RenderBlock.cpp
WebCore/rendering/RenderBox.cpp
WebCore/rendering/RenderImage.cpp
WebCore/rendering/RenderLayer.cpp
WebCore/rendering/RenderObject.cpp
WebCore/rendering/render_frames.cpp
WebCore/rendering/render_line.cpp
WebCore/rendering/render_list.cpp

index f49081f0232f8fcf1d76927b842ab5312ea0d0bb..a23c72ea19a2d198f1d27b88bc789fc912ee8b6f 100644 (file)
@@ -1,3 +1,341 @@
+2006-04-20  Darin Adler  <darin@apple.com>
+
+        Reviewed by Hyatt.
+
+        - make <canvas> element and related API behave more like the draft of
+          the WhatWG Web Application specification, checking parameter validity
+          and raising exceptions
+        - changed HTMLCanvasElement bindings to be auto-generated, fixing all
+          issues so we can generate bindings for classes drived from HTMLElement
+        - change GraphicsContext API to use IntRect/Point/Size in more cases
+        - change GraphicsContext so it is closer to truly wrapping a graphics
+          context rather than representing the current NSGraphicsContext; there
+          are still some things like text and rectangle fills that are tied to
+          NSGraphicsContext, but we're most of the way there
+        - removed Brush class since it just amounted to a color, using an RGBA32
+          instead where we used to use a Brush
+
+        * DerivedSources.make: Added JSHTMLCanvasElement.h.
+        * WebCore.xcodeproj/project.pbxproj: Added new files.
+
+        * bindings/js/JSCanvasRenderingContext2DBase.h: Added toJS.
+        * bindings/js/JSCanvasRenderingContext2DBase.cpp:
+        (WebCore::JSCanvasRenderingContext2DBaseProtoFunc::callAsFunction):
+        Added exception code handling for strokeRect, drawImage, and createPattern.
+        Added version of createPattern that takes a canvas. Use TYPE_MISMATCH_ERR
+        instead of JavaScript TypeError when parameter is neither an image or canvas
+        element. Adapt for new HTMLCanvasElement binding.
+        (WebCore::toJS): Added. Converts context object to JS wrapper.
+
+        * bindings/js/JSHTMLElementWrapperFactory.h: Added.
+        * bindings/js/JSHTMLElementWrapperFactory.cpp: Added. Creates a JavaScript
+        wrapper for an arbitrary HTML element. Better than putting this all in the
+        DOM node class toJS function.
+
+        * bindings/js/JSXMLSerializer.cpp: Tweaked to make it build.
+        * bindings/js/kjs_dom.cpp: (KJS::toJS): Changed to call the
+        JSHTMLElementWrapperFactory function createJSWrapper, instead
+        of always creating a JSHTMLElement.
+
+        * bindings/js/kjs_html.h: Removed canvas-related stuff. Added HTMLElement
+        prototype.
+        * bindings/js/kjs_html.cpp:
+        (KJS::JSHTMLElement::classInfo): Removed canvas element.
+        (KJS::JSHTMLElement::accessors): Ditto.
+        (KJS::JSHTMLElementProtoFunc::callAsFunction): Added, to help the auto-binding
+        machiner cope with HTMLElement.
+        (KJS::HTMLElementFunction::callAsFunction): Removed canvas element.
+
+        * bindings/scripts/CodeGeneratorJS.pm: Added types needed for HTMLCanvasElement.
+
+        * bridge/mac/FrameMac.mm: (WebCore::FrameMac::setDisplaysWithFocusAttributes):
+        Changed to create a GraphicsContext with the new constructor that takes
+        a CGContextRef.
+        * bridge/mac/WebCoreFrameBridge.mm: (-[WebCoreFrameBridge drawRect:]):
+        Changed to create a GraphicsContext with the new constructor that takes
+        a NSGraphicsContext.
+        * page/Frame.cpp: (WebCore::Frame::adjustPageHeight): Changed to create a
+        GraphicsContext with the new constructor that takes a CGContextRef.
+
+        * editing/SelectionController.cpp: (WebCore::SelectionController::paintCaret):
+        Eliminated a use of obsolete class Brush.
+
+        * html/CanvasPattern.h:
+        * html/CanvasPattern.cpp:
+        (WebCore::CanvasPattern::parseRepetitionType): Added. Parses a repetition
+        type. Different from the old logic in that it is case-sensitive and rejects
+        anything other than null, empty string, or the four repeat types.
+        (WebCore::CanvasPattern::CanvasPattern): Added constructor that takes
+        a CGImageRef. Changed constructor to take two booleans instead of the repetition
+        type string. It's the caller's responsibility to parse the string.
+        (WebCore::CanvasPattern::~CanvasPattern): Release the CGImage.
+        (WebCore::patternCallback): Handle the CGImage case. Also changed the code
+        to create a GraphicsContext as needed and call the image drawing code with that.
+        (WebCore::CanvasPattern::createPattern): Handle both the image element case and
+        the canvas element case.
+        
+        * html/CanvasRenderingContext2D.h:
+        * html/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::State::State): Change line cap, line join,
+        and global composite to store enum values instead of strings.
+        (WebCore::CanvasRenderingContext2D::setLineWidth): Do nothing if width is NaN
+        or <= 0.
+        (WebCore::CanvasRenderingContext2D::lineCap): Return a string based on a
+        stored enum, rather than returning a stored string.
+        (WebCore::CanvasRenderingContext2D::setLineCap): Do nothing if the string is
+        not one of the standard line cap types. Also case sensitive and stores enum
+        rather than the string.
+        (WebCore::CanvasRenderingContext2D::lineJoin): Return a string based on a
+        stored enum, rather than returning a stored string.
+        (WebCore::CanvasRenderingContext2D::setLineJoin): Do nothing if the string is
+        not one of the standard line join types. Also case sensitive and stores enum
+        rather than the string.
+        (WebCore::CanvasRenderingContext2D::setMiterLimit): Do nothing if limit is NaN
+        or <= 0.
+        (WebCore::CanvasRenderingContext2D::setGlobalAlpha): Do nothing if alpha is NaN
+        or < 0 or > 1.
+        (WebCore::CanvasRenderingContext2D::globalCompositeOperation): Return a string
+        based on a stored enum, rather than returning a stored string.
+        (WebCore::CanvasRenderingContext2D::setGlobalCompositeOperation): Do nothing if
+        the string is not one of the standard compositing modes. Also case sensitive and
+        stores enum rather than the string.
+        (WebCore::CanvasRenderingContext2D::arcTo): Generate INDEX_SIZE_ERR exception
+        if radius is NaN or <= 0.
+        (WebCore::CanvasRenderingContext2D::arc): Ditto.
+        (WebCore::CanvasRenderingContext2D::rect): Generate INDEX_SIZE_ERR exception
+        if width or height is NaN or <= 0.
+        (WebCore::CanvasRenderingContext2D::clearRect): Ditto.
+        (WebCore::CanvasRenderingContext2D::fillRect): Ditto.
+        (WebCore::CanvasRenderingContext2D::strokeRect): Ditto, same for line width.
+        Changed the case where the line width is not specified to share code with the
+        case where it is.
+        (WebCore::size): Renamed from imageSize, since C++ overloads based on parameter
+        types anyway.
+        (WebCore::CanvasRenderingContext2D::drawImage): Generate INDEX_SIZE_ERR exception
+        if the source rect is not entirely inside the image rect, or if the width or height
+        of either the source or destination rect is NaN or <= 0. Changed image drawing
+        code to be platform-independent for the image element case, but not yet for the
+        canvas case.
+        (WebCore::CanvasRenderingContext2D::drawImageFromRect): Change code to parse the
+        composite operation to use the new code shared with Image.
+        (WebCore::CanvasRenderingContext2D::createPattern): Added code to parse the
+        repetition type separately before creating the pattern. Added an overload for
+        canvas elements.
+        (WebCore::CanvasRenderingContext2D::drawingContext): Changed to return a
+        GraphicsContext*.
+        (WebCore::CanvasRenderingContext2D::platformContext): Added. Now does what
+        drawingContext used to do.
+
+        * html/CanvasRenderingContext2D.idl: Added exception declarations as needed
+        for changes above.
+
+        * html/HTMLCanvasElement.h:
+        * html/HTMLCanvasElement.cpp:
+        (WebCore::HTMLCanvasElement::HTMLCanvasElement): Changed m_drawingContext
+        to be a GraphicsContext instead of a CGContextRef.
+        (WebCore::HTMLCanvasElement::~HTMLCanvasElement): Ditto.
+        (WebCore::HTMLCanvasElement::getContext): Removed special cases for null
+        and empty string. Only give a 2D graphics context if the string is "2d".
+        (WebCore::HTMLCanvasElement::reset): Updated for change to GraphicsContext
+        from CGContextRef.
+        (WebCore::HTMLCanvasElement::paint): Ditto.
+        (WebCore::HTMLCanvasElement::createDrawingContext): Changed to create a
+        GraphicsContext* instead of a CGContextRef.
+        (WebCore::HTMLCanvasElement::drawingContext): Changed to return a
+        GraphicsContext* instead of a CGContextRef.
+        (WebCore::HTMLCanvasElement::createPlatformImage): Updated for changes above.
+
+        * html/HTMLCanvasElement.idl: Added.
+
+        * html/HTMLParser.h:
+        * html/HTMLParser.cpp:
+        (WebCore::HTMLParser::canvasCreateErrorCheck): Added. An attempt to implement the
+        fallback behavior for canvas elements when JavaScript is off.
+        (WebCore::HTMLParser::getNode): Sorted list of functions. Added case for canvas.
+
+        * html/html_imageimpl.h:
+        * html/html_imageimpl.cpp:
+        (WebCore::HTMLImageElement::HTMLImageElement): Changed m_compositeOperator to be
+        an enum instead of a string.
+        (WebCore::HTMLImageElement::parseMappedAttribute): Parse the enum here.
+
+        * kcanvas/KCanvasResources.h:
+        * kcanvas/KCanvasResources.cpp: (WebCore::KCanvasMarker::draw): Changed to take a
+        GraphicsContext parameter.
+
+        * kcanvas/RenderPath.h: Added GraphicsContext parameter to drawMarkersIfNeeded.
+
+        * kcanvas/RenderPath.cpp: (WebCore::RenderPath::paint):
+        * kcanvas/RenderSVGImage.cpp: (WebCore::RenderSVGImage::paint):
+        * kcanvas/RenderSVGText.cpp: (WebCore::RenderSVGText::paint):
+        Changed to generate and use an appropriate GraphicsContext.
+
+        * kcanvas/device/quartz/KCanvasItemQuartz.h: Added GraphicsContext parameter to
+        drawMarkersIfNeeded.
+        * kcanvas/device/quartz/KCanvasItemQuartz.mm:
+        (WebCore::DrawMarkersData::DrawMarkersData): Added GraphicsContext*.
+        (WebCore::drawMarkerWithData): Pass along a GraphicsContext*.
+        (WebCore::drawStartAndMidMarkers): Ditto.
+        (WebCore::KCanvasItemQuartz::drawMarkersIfNeeded): Pass a long a GraphicsContext*.
+
+        * kcanvas/device/KRenderingDevice.h: Added a pure virtual createGraphicsContext
+        to bridge back to a GraphicsContext. Long term that class will replace this one.
+        * kcanvas/device/quartz/KRenderingDeviceQuartz.h:
+        * kcanvas/device/quartz/KRenderingDeviceQuartz.mm:
+        (WebCore::KRenderingDeviceContextQuartz::createGraphicsContext): Added.
+
+        * ksvg2/svg/SVGMaskElement.cpp: (WebCore::SVGMaskElement::drawMaskerContent):
+        Create and pass a GraphicsContext -- old code used the default constructor for
+        GraphicsContext which meant "current context", and that no longer exists.
+        * ksvg2/svg/SVGPatternElement.cpp:
+        (WebCore::SVGPatternElement::drawPatternContentIntoTile): Ditto.
+
+        * platform/Brush.h: Removed.
+        * platform/CompositeOperator.h: Added.
+        * platform/CompositeOperator.cpp: Added.
+
+        * platform/Font.h: Changed calls to use IntPoint instead of pairs of ints.
+        Also removed the const from all the uses of GraphicsContext*.
+
+        * platform/GraphicsContext.h: Eliminated default constructor and constructor
+        that takes only a boolean. Replaced with constructors that take platform
+        graphics contexts only. Replaced brush-related calls with fill color calls.
+        Replaced use of Brush with use of Color. Changed Image::CompositeOperator to
+        just plain CompositeOperator. Changed tuples of ints into IntRect and IntPoint.
+        Moved setFocusRingClip and clearFocusRingClip out of ifdefs. Removed unused
+        getCompositeOperation and string-based setCompositeOperation. Moved
+        currentCGContext and the other setCompositeOperation out of the GraphicsContext
+        class and made them global functions. Fixed platformContext so it won't always
+        return the CGContextRef of the current NSGraphicsContext. Instead, it will
+        return the appropriate CGContextRef for the GraphicsContext. This eliminates
+        the need to use void* for the image-drawing functions.
+
+        * platform/GraphicsContext.cpp:
+        (WebCore::GraphicsContextState::GraphicsContextState): Replaced Brush with
+        an RGBA fill color.
+        (WebCore::GraphicsContext::setFillColor): Renamed from setBrush.
+        (WebCore::GraphicsContext::fillColor): Renamed from brush.
+        (WebCore::GraphicsContext::drawImage): Changed to use IntRect.
+        (WebCore::GraphicsContext::drawTiledImage): Moved here from GraphicsContextMac.mm.
+        (WebCore::GraphicsContext::drawText): Changed to use IntPoint.
+        (WebCore::GraphicsContext::drawHighlightForText): Ditto.
+        (WebCore::GraphicsContext::drawLineForText): Ditto.
+        (WebCore::GraphicsContext::drawLineForMisspelling): Ditto.
+
+        * platform/Image.h: Removed CompositeOperator and related functions.
+        Removed void* context parameters from draw functions.
+
+        * platform/Image.cpp: Removed compositeOperatorFromString.
+
+        * platform/Widget.h: Added a GraphicsContext* return value from lockDrawingFocus
+        that you pass back to unlockDrawingFocus (for deletion).
+
+        * platform/mac/FontMac.mm:
+        (WebCore::Font::selectionRectForText): Changed parameter to point and removed
+        const on GraphicsContext* parameter.
+        (WebCore::Font::drawText): Ditto.
+        (WebCore::Font::drawHighlightForText): Ditto.
+        (WebCore::Font::drawLineForText): Ditto.
+        (WebCore::Font::drawLineForMisspelling): Ditto.
+        (WebCore::Font::misspellingLineThickness): Removed const.
+
+        * platform/mac/GraphicsContextMac.mm:
+        (WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate):
+        Added fields to store a CGContextRef and an NSGraphicsContext.
+        (WebCore::GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate):
+        Release both the CGContextRef and the NSGraphicsContext.
+        (WebCore::GraphicsContext::GraphicsContext): Implement to set up both the
+        CGContextRef and the NSGraphicsContext in one case, and only the CGContextRef
+        in the other.
+        (WebCore::GraphicsContext::savePlatformState): Implement for the CGContext-only
+        case.
+        (WebCore::GraphicsContext::restorePlatformState): Ditto.
+        (WebCore::GraphicsContext::drawRect): Assert that the NS context is present
+        and 
+        (WebCore::GraphicsContext::setColorFromFillColor): Renamed from
+        setColorFromBrush.
+        (WebCore::GraphicsContext::setColorFromPen): Added assertion.
+        (WebCore::GraphicsContext::drawLine): Added assertion.
+        (WebCore::GraphicsContext::drawEllipse): Get CGContext from the platformContext
+        function instead of currentCGContext, and changed to use fillColor.
+        (WebCore::GraphicsContext::drawArc): Ditto.
+        (WebCore::GraphicsContext::drawConvexPolygon): Ditto.
+        (WebCore::setCompositeOperation): Changed to global function and also changed
+        to do the work here -- no need to use WebCoreImageRendererFactory.
+        (WebCore::GraphicsContext::drawImage): Move most of this into GraphicsContext.cpp.
+        Remove the void* context parameter. Changed to take rects instead of separate coordinates.
+        (WebCore::GraphicsContext::fillRect): Changed to take color instead of Brush.
+        (WebCore::GraphicsContext::addClip): Added assertion.
+        (WebCore::GraphicsContext::addRoundedRectClip): Get CGContextRef from the platformContext
+        function instead of currentCGContext.
+        (WebCore::GraphicsContext::createRenderingDeviceContext): Ditto.
+        (WebCore::GraphicsContext::beginTransparencyLayer): Ditto.
+        (WebCore::GraphicsContext::endTransparencyLayer): Ditto.
+        (WebCore::GraphicsContext::setShadow): Change to take size instead of x,y. Also get
+        CGCOntextRef from the platformContext function instead of currentCGContext.
+        (WebCore::GraphicsContext::clearShadow): Get CGContextRef from the platformContext
+        function instead of currentCGContext.
+        (WebCore::GraphicsContext::platformContext): Added. Returns m_data->m_cgContext.
+
+        * platform/mac/ImageMac.mm:
+        (WebCore::fillSolidColorInRect): Updated for change in CompositeOperator type.
+        (WebCore::Image::checkForSolidColor): Ditto.
+        (WebCore::Image::draw): Removed void* context parameter and replaced it with
+        a GraphicsContext* parameter. Renamed from drawInRect.
+        (WebCore::Image::drawTiled): Ditto. Renamed from tileInRect and scaleAndTileInRect.
+
+        * platform/mac/PDFDocumentImage.h: Updated for change in CompositeOperator type.
+        * platform/mac/PDFDocumentImage.mm: (WebCore::PDFDocumentImage::draw): Ditto.
+
+        * platform/mac/WidgetMac.mm:
+        (WebCore::Widget::lockDrawingFocus): Changed to return a GraphicsContext*.
+        (WebCore::Widget::unlockDrawingFocus): Changed to take a GraphicsContext*.
+
+        * rendering/InlineTextBox.cpp:
+        (WebCore::InlineTextBox::selectionRect): Changed to pass IntPoint.
+        (WebCore::InlineTextBox::paint): Changed to pass IntSize.
+        (WebCore::InlineTextBox::paintSelection): More of the same.
+        (WebCore::InlineTextBox::paintMarkedTextBackground): Ditto.
+        (WebCore::InlineTextBox::paintDecoration): Ditto.
+        (WebCore::InlineTextBox::paintSpellingMarker): Ditto.
+        (WebCore::InlineTextBox::paintTextMatchMarker): Ditto.
+        (WebCore::InlineTextBox::paintMarkedTextUnderline): Ditto.
+        (WebCore::InlineTextBox::positionForOffset): Ditto.
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::fillHorizontalSelectionGap): Ditto.
+        (WebCore::RenderBlock::fillVerticalSelectionGap): Ditto.
+        (WebCore::RenderBlock::fillLeftSelectionGap): Ditto.
+        (WebCore::RenderBlock::fillRightSelectionGap): Ditto.
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::paintBackgroundExtended): Ditto.
+        (WebCore::RenderBox::outlineBox): Ditto.
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::paint): Ditto.
+        * rendering/RenderLayer.cpp:
+        (WebCore::setClip): Take out ifdefs. We'll do that inside GraphicsContext instead.
+        (WebCore::restoreClip): Ditto.
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::drawBorder): More of the same.
+        (WebCore::RenderObject::paintBorderImage): Ditto.
+        * rendering/render_line.cpp:
+        (WebCore::InlineFlowBox::paintDecorations): Ditto.
+        (WebCore::EllipsisBox::paint): Ditto.
+        * rendering/render_list.cpp:
+        (WebCore::RenderListMarker::paint): Ditto.
+
+        * rendering/render_frames.cpp: (WebCore::RenderFrameSet::userResize): Set up a graphics
+        context by calling lockDrawingFocus. Also changed a color here to be a constant.
+
+        * platform/cairo/GraphicsContextCairo.cpp:
+        (WebCore::GraphicsContext::drawImage): Update for parameter type changes.
+        (WebCore::GraphicsContext::drawScaledAndTiledImage):
+        (WebCore::GraphicsContext::setFocusRingClip):
+        (WebCore::GraphicsContext::clearFocusRingClip):
+        * platform/cairo/ImageCairo.cpp:
+        (WebCore::setCompositingOperation):
+        (WebCore::Image::tileInRect):
+        (WebCore::Image::scaleAndTileInRect):
+
 2006-04-20  Mitz Pettel  <opendarwin.org@mitzpettel.com>
 
         Reviewed by Darin.
index 8d22f9a3b8b9eda5c66c01a21c5379005962396e..f156e6e0b45ebcd0deee83e90a9af7d9c6446820 100644 (file)
@@ -57,6 +57,7 @@ all : \
     JSDOMWindow.h \
     JSElement.h \
     JSEntity.h \
+    JSHTMLCanvasElement.h \
     JSKeyboardEvent.h \
     JSMouseEvent.h \
     JSMutationEvent.h \
index 40a99c209febe593765a4f464aacab6ddf72cbde..e0d0923e5d9e4b815768ac5fe559766655dce9c5 100644 (file)
                9380F47809A11ACC001FDB34 /* WidgetMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9380F47709A11ACC001FDB34 /* WidgetMac.mm */; };
                9380F68709A143B2001FDB34 /* FrameViewMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9380F68609A143B2001FDB34 /* FrameViewMac.mm */; };
                9385F762098D9C3100D90D24 /* Screen.h in Headers */ = {isa = PBXBuildFile; fileRef = 9385F761098D9C3100D90D24 /* Screen.h */; };
+               938E65F109F09840008A48EC /* JSHTMLElementWrapperFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 938E65F009F09840008A48EC /* JSHTMLElementWrapperFactory.h */; };
+               938E65F709F0985D008A48EC /* JSHTMLElementWrapperFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 938E65F609F0985D008A48EC /* JSHTMLElementWrapperFactory.cpp */; };
+               938E662609F09956008A48EC /* HTMLCanvasElement.idl in Resources */ = {isa = PBXBuildFile; fileRef = 938E662509F09956008A48EC /* HTMLCanvasElement.idl */; };
+               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 */; };
                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 */; };
                AB23A32809BBA7D00067CC53 /* BeforeTextInsertedEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = AB23A32609BBA7D00067CC53 /* BeforeTextInsertedEvent.h */; };
                AB67D1A8097F3AE300F9392E /* RenderTextField.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB67D1A6097F3AE300F9392E /* RenderTextField.cpp */; };
                AB67D1A9097F3AE300F9392E /* RenderTextField.h in Headers */ = {isa = PBXBuildFile; fileRef = AB67D1A7097F3AE300F9392E /* RenderTextField.h */; };
-               BC075986098861A400407B48 /* Brush.h in Headers */ = {isa = PBXBuildFile; fileRef = BC075985098861A400407B48 /* Brush.h */; };
                BC1A37AD097C715F0019F3D8 /* DOM.h in Headers */ = {isa = PBXBuildFile; fileRef = BC1A3797097C715F0019F3D8 /* DOM.h */; settings = {ATTRIBUTES = (Private, ); }; };
                BC1A37AE097C715F0019F3D8 /* DOM.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC1A3798097C715F0019F3D8 /* DOM.mm */; };
                BC1A37AF097C715F0019F3D8 /* DOMCore.h in Headers */ = {isa = PBXBuildFile; fileRef = BC1A3799097C715F0019F3D8 /* DOMCore.h */; settings = {ATTRIBUTES = (Private, ); }; };
                9380F47709A11ACC001FDB34 /* WidgetMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = WidgetMac.mm; sourceTree = "<group>"; };
                9380F68609A143B2001FDB34 /* FrameViewMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FrameViewMac.mm; sourceTree = "<group>"; };
                9385F761098D9C3100D90D24 /* Screen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Screen.h; sourceTree = "<group>"; };
+               938E65F009F09840008A48EC /* JSHTMLElementWrapperFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSHTMLElementWrapperFactory.h; sourceTree = "<group>"; };
+               938E65F609F0985D008A48EC /* JSHTMLElementWrapperFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLElementWrapperFactory.cpp; sourceTree = "<group>"; };
+               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; name = JSHTMLCanvasElement.cpp; path = /Volumes/Spoon/Users/darin/symroots/Debug/DerivedSources/WebCore/JSHTMLCanvasElement.cpp; sourceTree = "<absolute>"; };
+               938E666109F09B87008A48EC /* JSHTMLCanvasElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSHTMLCanvasElement.h; path = /Volumes/Spoon/Users/darin/symroots/Debug/DerivedSources/WebCore/JSHTMLCanvasElement.h; sourceTree = "<absolute>"; };
+               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>"; };
                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; };
                BC06F24A06D18A7E004A6FA3 /* XSLStyleSheet.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = XSLStyleSheet.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                BC06F24B06D18A7E004A6FA3 /* XSLTProcessor.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XSLTProcessor.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                BC06F24C06D18A7E004A6FA3 /* XSLTProcessor.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = XSLTProcessor.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
-               BC075985098861A400407B48 /* Brush.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Brush.h; sourceTree = "<group>"; };
                BC1A3797097C715F0019F3D8 /* DOM.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOM.h; sourceTree = "<group>"; };
                BC1A3798097C715F0019F3D8 /* DOM.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = DOM.mm; sourceTree = "<group>"; };
                BC1A3799097C715F0019F3D8 /* DOMCore.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOMCore.h; sourceTree = "<group>"; };
                                65DF31E609D1CC60000BE325 /* JSElement.h */,
                                65DF322D09D1DDBC000BE325 /* JSEntity.cpp */,
                                65DF322E09D1DDBC000BE325 /* JSEntity.h */,
+                               938E665F09F09B81008A48EC /* JSHTMLCanvasElement.cpp */,
+                               938E666109F09B87008A48EC /* JSHTMLCanvasElement.h */,
                                A86629CE09DA2B47009633A5 /* JSKeyboardEvent.cpp */,
                                A86629CD09DA2B47009633A5 /* JSKeyboardEvent.h */,
                                A86629CC09DA2B47009633A5 /* JSMouseEvent.cpp */,
                                A81369B6097374F500D74463 /* HTMLButtonElement.h */,
                                51F6A3D50663BF04004D2919 /* HTMLCanvasElement.cpp */,
                                51F6A3D60663BF04004D2919 /* HTMLCanvasElement.h */,
+                               938E662509F09956008A48EC /* HTMLCanvasElement.idl */,
                                A8DF3FC9097FA0FB0052981B /* HTMLCollection.cpp */,
                                A8DF3FC8097FA0FB0052981B /* HTMLCollection.h */,
                                F523D23B02DE4396018635CA /* HTMLDocument.cpp */,
                                930CAD1409C4F3C300229C04 /* JSCanvasRenderingContext2DBase.h */,
                                93B70D3F09EB0C7C009D8468 /* JSDOMParser.cpp */,
                                93B70D4009EB0C7C009D8468 /* JSDOMParser.h */,
+                               938E65F609F0985D008A48EC /* JSHTMLElementWrapperFactory.cpp */,
+                               938E65F009F09840008A48EC /* JSHTMLElementWrapperFactory.h */,
                                93B70D4109EB0C7C009D8468 /* JSXMLHttpRequest.cpp */,
                                93B70D4209EB0C7C009D8468 /* JSXMLHttpRequest.h */,
                                93B70D4309EB0C7C009D8468 /* JSXMLSerializer.cpp */,
                                93CD4FD70995F9EA007ECC97 /* AtomicString.cpp */,
                                93CD4FD80995F9EA007ECC97 /* AtomicString.h */,
                                93CD4FD90995F9EA007ECC97 /* AtomicStringImpl.h */,
-                               BC075985098861A400407B48 /* Brush.h */,
                                65F5382009B2B55700F3DC4A /* character-sets.txt */,
                                9326DC0A09DAD5BE00AFC847 /* CharsetData.h */,
                                65F5386A09B2C05E00F3DC4A /* CharsetNames.cpp */,
                                BCC8CFC80986CD2400140BF2 /* Color.cpp */,
                                BCC8CFC90986CD2400140BF2 /* Color.h */,
                                BCC8CFCA0986CD2400140BF2 /* ColorData.gperf */,
+                               938E685309F0BE04008A48EC /* CompositeOperator.cpp */,
+                               938E683B09F0BD7A008A48EC /* CompositeOperator.h */,
                                9352088109BD45E900F2038D /* CookieJar.h */,
                                F587868402DE3B8601EA4122 /* Cursor.h */,
                                BCB16B880979B01400467741 /* DeprecatedArray.h */,
                                93E62D9B0985F41600E1B5E3 /* SystemTime.h in Headers */,
                                BCC8CFCC0986CD2400140BF2 /* Color.h in Headers */,
                                BCC8D1740988301200140BF2 /* Pen.h in Headers */,
-                               BC075986098861A400407B48 /* Brush.h in Headers */,
                                BCD75ABC0989A446003E28DF /* Image.h in Headers */,
                                9385F762098D9C3100D90D24 /* Screen.h in Headers */,
                                9305B24D098F1B6B00C28855 /* Timer.h in Headers */,
                                93B70EB309EEE5B5009D8468 /* RenderEmptyApplet.h in Headers */,
                                1403B99709EB13AF00797C7F /* DOMWindow.h in Headers */,
                                1403BA0F09EB18F900797C7F /* JSDOMWindow.h in Headers */,
+                               938E65F109F09840008A48EC /* JSHTMLElementWrapperFactory.h in Headers */,
+                               938E666209F09B87008A48EC /* JSHTMLCanvasElement.h in Headers */,
+                               938E683C09F0BD7B008A48EC /* CompositeOperator.h in Headers */,
                                8116896009F2A4A000772CA0 /* SVGTRefElement.h in Headers */,
                                93EB169709F880C00091F8FF /* WebCoreSystemInterface.h in Headers */,
                        );
                                141B94E609EC4223000E9413 /* MouseEvent.idl in Resources */,
                                141B94EF09EC425A000E9413 /* UIEvent.idl in Resources */,
                                14813BF409EDF88E00F757E1 /* IDLParser.pm in Resources */,
+                               938E662609F09956008A48EC /* HTMLCanvasElement.idl in Resources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                93B70EB209EEE5B5009D8468 /* RenderEmptyApplet.cpp in Sources */,
                                1403B99809EB13AF00797C7F /* DOMWindow.cpp in Sources */,
                                1403BA0C09EB18C700797C7F /* JSDOMWindow.cpp in Sources */,
+                               938E65F709F0985D008A48EC /* JSHTMLElementWrapperFactory.cpp in Sources */,
+                               938E666009F09B81008A48EC /* JSHTMLCanvasElement.cpp in Sources */,
+                               938E685409F0BE04008A48EC /* CompositeOperator.cpp in Sources */,
                                8116895F09F2A4A000772CA0 /* SVGTRefElement.cpp in Sources */,
                                93EB169509F880B00091F8FF /* WebCoreSystemInterface.mm in Sources */,
                        );
index 8ac0b143dbf42c514fa2255b65d750e1bb2aafe0..9d4858bc391a7d1163be3f387b87b8fde58001f7 100644 (file)
 #include "CanvasPattern.h"
 #include "CanvasRenderingContext2D.h"
 #include "CanvasStyle.h"
+#include "ExceptionCode.h"
 #include "HTMLCanvasElement.h"
 #include "JSCanvasGradient.h"
 #include "JSCanvasPattern.h"
-#include "kjs_html.h"
+#include "JSCanvasRenderingContext2D.h"
+#include "JSHTMLCanvasElement.h"
 
 #include "JSCanvasRenderingContext2DBaseTable.cpp"
 
@@ -126,14 +128,17 @@ JSValue* JSCanvasRenderingContext2DBaseProtoFunc::callAsFunction(ExecState* exec
                     return throwError(exec, SyntaxError);
             }
             break;
-        case JSCanvasRenderingContext2DBase::StrokeRect:
+        case JSCanvasRenderingContext2DBase::StrokeRect: {
+            ExceptionCode ec;
             if (args.size() <= 4)
                 context->strokeRect(args[0]->toNumber(exec), args[1]->toNumber(exec),
-                    args[2]->toNumber(exec), args[3]->toNumber(exec));
+                    args[2]->toNumber(exec), args[3]->toNumber(exec), ec);
             else
                 context->strokeRect(args[0]->toNumber(exec), args[1]->toNumber(exec),
-                    args[2]->toNumber(exec), args[3]->toNumber(exec), args[4]->toNumber(exec));
+                    args[2]->toNumber(exec), args[3]->toNumber(exec), args[4]->toNumber(exec), ec);
+            setDOMException(exec, ec);
             break;
+        }
         case JSCanvasRenderingContext2DBase::SetShadow:
             switch (args.size()) {
                 case 3:
@@ -184,6 +189,7 @@ JSValue* JSCanvasRenderingContext2DBaseProtoFunc::callAsFunction(ExecState* exec
             JSObject* o = static_cast<JSObject*>(args[0]);
             if (!o->isObject())
                 return throwError(exec, TypeError);
+            ExceptionCode ec;
             if (o->inherits(&JSHTMLElement::img_info)) {
                 HTMLImageElement* imgElt = static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(args[0])->impl());
                 switch (args.size()) {
@@ -192,20 +198,22 @@ JSValue* JSCanvasRenderingContext2DBaseProtoFunc::callAsFunction(ExecState* exec
                         break;
                     case 5:
                         context->drawImage(imgElt, args[1]->toNumber(exec), args[2]->toNumber(exec),
-                            args[3]->toNumber(exec), args[4]->toNumber(exec));
+                            args[3]->toNumber(exec), args[4]->toNumber(exec), ec);
+                        setDOMException(exec, ec);
                         break;
                     case 9:
                         context->drawImage(imgElt, args[1]->toNumber(exec), args[2]->toNumber(exec),
                             args[3]->toNumber(exec), args[4]->toNumber(exec),
                             args[5]->toNumber(exec), args[6]->toNumber(exec),
-                            args[7]->toNumber(exec), args[8]->toNumber(exec));
+                            args[7]->toNumber(exec), args[8]->toNumber(exec), ec);
+                        setDOMException(exec, ec);
                         break;
                     default:
                         return throwError(exec, SyntaxError);
                 }
                 break;
             }
-            if (o->inherits(&JSHTMLElement::canvas_info)) {
+            if (o->inherits(&JSHTMLCanvasElement::info)) {
                 HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(static_cast<JSHTMLElement*>(args[0])->impl());
                 switch (args.size()) {
                     case 3:
@@ -213,20 +221,23 @@ JSValue* JSCanvasRenderingContext2DBaseProtoFunc::callAsFunction(ExecState* exec
                         break;
                     case 5:
                         context->drawImage(canvas, args[1]->toNumber(exec), args[2]->toNumber(exec),
-                            args[3]->toNumber(exec), args[4]->toNumber(exec));
+                            args[3]->toNumber(exec), args[4]->toNumber(exec), ec);
+                        setDOMException(exec, ec);
                         break;
                     case 9:
                         context->drawImage(canvas, args[1]->toNumber(exec), args[2]->toNumber(exec),
                             args[3]->toNumber(exec), args[4]->toNumber(exec),
                             args[5]->toNumber(exec), args[6]->toNumber(exec),
-                            args[7]->toNumber(exec), args[8]->toNumber(exec));
+                            args[7]->toNumber(exec), args[8]->toNumber(exec), ec);
+                        setDOMException(exec, ec);
                         break;
                     default:
                         return throwError(exec, SyntaxError);
                 }
                 break;
             }
-            return throwError(exec, TypeError);
+            setDOMException(exec, TYPE_MISMATCH_ERR);
+            return 0;
         }
         case JSCanvasRenderingContext2DBase::DrawImageFromRect: {
             JSObject* o = static_cast<JSObject*>(args[0]);
@@ -246,11 +257,24 @@ JSValue* JSCanvasRenderingContext2DBaseProtoFunc::callAsFunction(ExecState* exec
             JSObject* o = static_cast<JSObject*>(args[0]);
             if (!o->isObject())
                 return throwError(exec, TypeError);
-            if (!o->inherits(&JSHTMLElement::img_info))
-                return throwError(exec, TypeError);
-            return toJS(exec,
-                context->createPattern(static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(args[0])->impl()),
-                args[1]->toString(exec)).get());
+            if (o->inherits(&JSHTMLElement::img_info)) {
+                ExceptionCode ec;
+                JSValue* pattern = toJS(exec,
+                    context->createPattern(static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(args[0])->impl()),
+                        args[1]->toString(exec), ec).get());
+                setDOMException(exec, ec);
+                return pattern;
+            }
+            if (o->inherits(&JSHTMLCanvasElement::info)) {
+                ExceptionCode ec;
+                JSValue* pattern = toJS(exec,
+                    context->createPattern(static_cast<HTMLCanvasElement*>(static_cast<JSHTMLElement*>(args[0])->impl()),
+                        args[1]->toString(exec), ec).get());
+                setDOMException(exec, ec);
+                return pattern;
+            }
+            setDOMException(exec, TYPE_MISMATCH_ERR);
+            return 0;
     }
 
     return jsUndefined();
@@ -315,7 +339,7 @@ void JSCanvasRenderingContext2DBase::putValueProperty(ExecState* exec, int token
     }
 }
 
-JSCanvasRenderingContext2DBase::JSCanvasRenderingContext2DBase(ExecState*, PassRefPtr<WebCore::CanvasRenderingContext2D> impl)
+JSCanvasRenderingContext2DBase::JSCanvasRenderingContext2DBase(ExecState*, PassRefPtr<CanvasRenderingContext2D> impl)
     : m_impl(impl)
 {
 }
@@ -325,4 +349,9 @@ JSCanvasRenderingContext2DBase::~JSCanvasRenderingContext2DBase()
     ScriptInterpreter::forgetDOMObject(m_impl.get());
 }
 
+JSValue* toJS(ExecState* exec, CanvasRenderingContext2D* context)
+{
+    return cacheDOMObject<CanvasRenderingContext2D, JSCanvasRenderingContext2D>(exec, context);
+}
+
 }
index 7c86277e1cf03f2e0f8879d081d6a96dffbf7989..4da17ea5bfd363191fe17e39229183a039edee15 100644 (file)
@@ -17,6 +17,9 @@
  * Boston, MA 02111-1307, USA.
  */
 
+#ifndef JSCanvasRenderingContext2DBase_h
+#define JSCanvasRenderingContext2DBase_h
+
 #include "kjs_binding.h"
 
 namespace WebCore {
@@ -42,4 +45,8 @@ namespace WebCore {
         RefPtr<CanvasRenderingContext2D> m_impl;
     };
 
+    KJS::JSValue* toJS(KJS::ExecState*, CanvasRenderingContext2D*);
+
 }
+
+#endif
diff --git a/WebCore/bindings/js/JSHTMLElementWrapperFactory.cpp b/WebCore/bindings/js/JSHTMLElementWrapperFactory.cpp
new file mode 100644 (file)
index 0000000..7f33ecb
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ *  Copyright (C) 2006 Apple Computer, Inc.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "config.h"
+#include "JSHTMLElementWrapperFactory.h"
+
+#include "HTMLCanvasElement.h"
+#include "HTMLNames.h"
+#include "JSHTMLCanvasElement.h"
+#include "kjs_html.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+typedef DOMNode* (*CreateHTMLElementWrapperFunction)(ExecState*, PassRefPtr<HTMLElement>);
+
+static DOMNode* createCanvasWrapper(ExecState* exec, PassRefPtr<HTMLElement> element)
+{
+    return new JSHTMLCanvasElement(exec, static_cast<HTMLCanvasElement*>(element.get()));
+}
+
+DOMNode* createJSWrapper(ExecState* exec, PassRefPtr<HTMLElement> element)
+{
+    static HashMap<WebCore::AtomicStringImpl*, CreateHTMLElementWrapperFunction> map;
+    if (map.isEmpty()) {
+        map.set(canvasTag.localName().impl(), createCanvasWrapper);
+    }
+    CreateHTMLElementWrapperFunction f = map.get(element->localName().impl());
+    if (f)
+        return f(exec, element);
+    return new JSHTMLElement(exec, element.get());
+}
+
+}
diff --git a/WebCore/bindings/js/JSHTMLElementWrapperFactory.h b/WebCore/bindings/js/JSHTMLElementWrapperFactory.h
new file mode 100644 (file)
index 0000000..d876c91
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ *  Copyright (C) 2006 Apple Computer, Inc.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef JSHTMLELEMENTWRAPPERFACTORY_H
+#define JSHTMLELEMENTWRAPPERFACTORY_H
+
+#include <kxmlcore/Forward.h>
+
+namespace KJS {
+    class DOMNode;
+    class ExecState;
+}
+
+namespace WebCore {
+
+    class HTMLElement;
+    KJS::DOMNode* createJSWrapper(KJS::ExecState*, PassRefPtr<HTMLElement>);
+
+}
+
+#endif
index 0d8392f5848d7dda8e1a29ac7a25620807287786..7d60b277f3319e9c566efa888dbe9e14b41ac571 100644 (file)
@@ -26,7 +26,7 @@
 #include "kjs_dom.h"
 #include "markup.h"
 
-using WebCore::Node;
+using namespace WebCore;
 
 namespace KJS {
 
index 66fa013592334ae98e683f53932b14eedf2a9208..c684ade40e16ebf712c699e3c6fda3ff3f102038 100644 (file)
@@ -45,6 +45,7 @@
 #include "dom_xmlimpl.h"
 #include "HTMLDocument.h"
 #include "html_objectimpl.h"
+#include "JSHTMLElementWrapperFactory.h"
 #include "HTMLNames.h"
 #include "KWQKHTMLSettings.h"
 #include "kjs_css.h"
@@ -1033,7 +1034,7 @@ bool checkNodeSecurity(ExecState* exec, WebCore::Node* n)
   return win && win->isSafeScript(exec);
 }
 
-JSValue *toJS(ExecState *exec, PassRefPtr<WebCore::Node> node)
+JSValuetoJS(ExecState *exec, PassRefPtr<WebCore::Node> node)
 {
   WebCore::Node* n = node.get();
   DOMNode *ret = 0;
@@ -1048,7 +1049,7 @@ JSValue *toJS(ExecState *exec, PassRefPtr<WebCore::Node> node)
   switch (n->nodeType()) {
     case WebCore::Node::ELEMENT_NODE:
       if (n->isHTMLElement())
-        ret = new JSHTMLElement(exec, static_cast<HTMLElement *>(n));
+        ret = createJSWrapper(exec, static_pointer_cast<WebCore::HTMLElement>(node));
       else
         ret = new JSElement(exec, static_cast<Element *>(n));
       break;
index c394c02af646933e7a05860c0a7733026af9b878..013414c8a394b4e9a63a744e8e49d98d2a72d93a 100644 (file)
@@ -27,6 +27,7 @@
 #include "Frame.h"
 #include "HTMLBaseFontElement.h"
 #include "HTMLButtonElement.h"
+#include "HTMLDocument.h"
 #include "HTMLFieldSetElement.h"
 #include "HTMLFormElement.h"
 #include "HTMLIsIndexElement.h"
 #include "HTMLOptionsCollection.h"
 #include "HTMLSelectElement.h"
 #include "HTMLTextAreaElement.h"
-#include "JSCanvasRenderingContext2D.h"
 #include "NameNodeList.h"
+#include "RenderLayer.h"
 #include "Text.h"
 #include "css_ruleimpl.h"
 #include "dom2_eventsimpl.h"
 #include "html_baseimpl.h"
 #include "html_blockimpl.h"
-#include "HTMLCanvasElement.h"
-#include "HTMLDocument.h"
 #include "html_headimpl.h"
+#include "html_imageimpl.h"
+#include "html_inlineimpl.h"
 #include "html_listimpl.h"
 #include "html_objectimpl.h"
 #include "html_tableimpl.h"
@@ -54,7 +55,6 @@
 #include "kjs_events.h"
 #include "kjs_proxy.h"
 #include "kjs_window.h"
-#include "RenderLayer.h"
 
 #include "kjs_html.lut.h"
 
@@ -429,7 +429,6 @@ const ClassInfo JSHTMLElement::blockQuote_info = { "HTMLBlockQuoteElement", &JSH
 const ClassInfo JSHTMLElement::body_info = { "HTMLBodyElement", &JSHTMLElement::info, &HTMLBodyElementTable, 0 };
 const ClassInfo JSHTMLElement::br_info = { "HTMLBRElement", &JSHTMLElement::info, &HTMLBRElementTable, 0 };
 const ClassInfo JSHTMLElement::button_info = { "HTMLButtonElement", &JSHTMLElement::info, &HTMLButtonElementTable, 0 };
-const ClassInfo JSHTMLElement::canvas_info = { "HTMLCanvasElement", &JSHTMLElement::info, &HTMLCanvasElementTable, 0 };
 const ClassInfo JSHTMLElement::caption_info = { "HTMLTableCaptionElement", &JSHTMLElement::info, &HTMLTableCaptionElementTable, 0 };
 const ClassInfo JSHTMLElement::col_info = { "HTMLTableColElement", &JSHTMLElement::info, &HTMLTableColElementTable, 0 };
 const ClassInfo JSHTMLElement::dir_info = { "HTMLDirectoryElement", &JSHTMLElement::info, &HTMLDirectoryElementTable, 0 };
@@ -489,7 +488,6 @@ const ClassInfo* JSHTMLElement::classInfo() const
         classInfoMap.set(bodyTag.localName().impl(), &body_info);
         classInfoMap.set(brTag.localName().impl(), &br_info);
         classInfoMap.set(buttonTag.localName().impl(), &button_info);
-        classInfoMap.set(canvasTag.localName().impl(), &canvas_info);
         classInfoMap.set(captionTag.localName().impl(), &caption_info);
         classInfoMap.set(colTag.localName().impl(), &col_info);
         classInfoMap.set(colgroupTag.localName().impl(), &col_info);
@@ -593,7 +591,6 @@ const JSHTMLElement::Accessors JSHTMLElement::font_accessors = { &JSHTMLElement:
 const JSHTMLElement::Accessors JSHTMLElement::hr_accessors = { &JSHTMLElement::hrGetter, &JSHTMLElement::hrSetter };
 const JSHTMLElement::Accessors JSHTMLElement::mod_accessors = { &JSHTMLElement::modGetter, &JSHTMLElement::modSetter };
 const JSHTMLElement::Accessors JSHTMLElement::a_accessors = { &JSHTMLElement::anchorGetter, &JSHTMLElement::anchorSetter };
-const JSHTMLElement::Accessors JSHTMLElement::canvas_accessors = { &JSHTMLElement::imageGetter, &JSHTMLElement::imageSetter };
 const JSHTMLElement::Accessors JSHTMLElement::img_accessors = { &JSHTMLElement::imageGetter, &JSHTMLElement::imageSetter };
 const JSHTMLElement::Accessors JSHTMLElement::object_accessors = { &JSHTMLElement::objectGetter, &JSHTMLElement::objectSetter };
 const JSHTMLElement::Accessors JSHTMLElement::param_accessors = { &JSHTMLElement::paramGetter, &JSHTMLElement::paramSetter };
@@ -625,7 +622,6 @@ const JSHTMLElement::Accessors* JSHTMLElement::accessors() const
         accessorMap.add(bodyTag.localName().impl(), &body_accessors);
         accessorMap.add(brTag.localName().impl(), &br_accessors);
         accessorMap.add(buttonTag.localName().impl(), &button_accessors);
-        accessorMap.add(canvasTag.localName().impl(), &canvas_accessors);
         accessorMap.add(captionTag.localName().impl(), &caption_accessors);
         accessorMap.add(colTag.localName().impl(), &col_accessors);
         accessorMap.add(colgroupTag.localName().impl(), &col_accessors);
@@ -689,6 +685,10 @@ const JSHTMLElement::Accessors* JSHTMLElement::accessors() const
 }
 
 /*
+
+@begin JSHTMLElementProtoTable 0
+@end
+
 @begin HTMLElementTable 14
   id            KJS::JSHTMLElement::ElementId     DontDelete
   title         KJS::JSHTMLElement::ElementTitle  DontDelete
@@ -1164,12 +1164,16 @@ const JSHTMLElement::Accessors* JSHTMLElement::accessors() const
   start           KJS::JSHTMLElement::MarqueeStart                DontDelete|Function 0
   stop            KJS::JSHTMLElement::MarqueeStop                 DontDelete|Function 0
 @end
-
-@begin HTMLCanvasElementTable 1
-  getContext      KJS::JSHTMLElement::GetContext                  DontDelete|Function 1
-@end
 */
 
+KJS_IMPLEMENT_PROTOFUNC(JSHTMLElementProtoFunc)
+KJS_IMPLEMENT_PROTOTYPE("HTMLElement", JSHTMLElementProto, JSHTMLElementProtoFunc)
+
+JSValue* JSHTMLElementProtoFunc::callAsFunction(ExecState*, JSObject*, const List&)
+{
+    return 0;
+}
+
 JSHTMLElement::JSHTMLElement(ExecState *exec, HTMLElement *e)
     : JSElement(exec, e)
 {
@@ -2218,11 +2222,6 @@ HTMLElementFunction::HTMLElementFunction(ExecState *exec, int i, int len, const
   put(exec,lengthPropertyName,jsNumber(len),DontDelete|ReadOnly|DontEnum);
 }
 
-static JSValue* toJS(ExecState* exec, CanvasRenderingContext2D* context)
-{
-    return cacheDOMObject<CanvasRenderingContext2D, JSCanvasRenderingContext2D>(exec, context);
-}
-
 JSValue *HTMLElementFunction::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args)
 {
     if (!thisObj->inherits(&JSHTMLElement::info))
@@ -2401,10 +2400,6 @@ JSValue *HTMLElementFunction::callAsFunction(ExecState *exec, JSObject *thisObj,
             return jsUndefined();
         }
     }
-    else if (element.hasLocalName(canvasTag)) {
-        if (id == JSHTMLElement::GetContext)
-            return toJS(exec, static_cast<HTMLCanvasElement*>(&element)->getContext(args[0]->toString(exec)));
-    }
 
     return jsUndefined();
 }
index a7dc18c80162e961825a5f36eae19daace27e6bb..182796b86164f7f1659195dc11f7e4461827baa4 100644 (file)
 #include "JSElement.h"
 
 namespace WebCore {
-    class CanvasRenderingContext2D;
     class HTMLCollection;
     class HTMLDocument;
     class HTMLElement;
-    class CanvasGradient;
-    class CanvasPattern;
     class HTMLSelectElement;
     class HTMLTableCaptionElement;
     class HTMLTableSectionElement;
@@ -58,6 +55,8 @@ namespace KJS {
     static JSValue *namedItemGetter(ExecState *, JSObject *, const Identifier&, const PropertySlot&);
   };
 
+  KJS_DEFINE_PROTOTYPE_WITH_PROTOTYPE(JSHTMLElementProto, WebCore::JSElementProto)
+
   class JSHTMLElement : public WebCore::JSElement {
   public:
     JSHTMLElement(ExecState *exec, WebCore::HTMLElement *e);
@@ -78,7 +77,7 @@ namespace KJS {
       button_info, label_info, fieldSet_info, legend_info, ul_info, ol_info,
       dl_info, dir_info, menu_info, li_info, div_info, p_info, heading_info,
       blockQuote_info, q_info, pre_info, br_info, baseFont_info, font_info,
-      hr_info, mod_info, a_info, canvas_info, img_info, object_info, param_info,
+      hr_info, mod_info, a_info, img_info, object_info, param_info,
       applet_info, map_info, area_info, script_info, table_info,
       caption_info, col_info, tablesection_info, tr_info,
       tablecell_info, frameSet_info, frame_info, iFrame_info, marquee_info;
@@ -94,7 +93,7 @@ namespace KJS {
       button_accessors, label_accessors, fieldSet_accessors, legend_accessors, ul_accessors, ol_accessors,
       dl_accessors, dir_accessors, menu_accessors, li_accessors, div_accessors, p_accessors, heading_accessors,
       blockQuote_accessors, q_accessors, pre_accessors, br_accessors, baseFont_accessors, font_accessors,
-      hr_accessors, mod_accessors, a_accessors, canvas_accessors, img_accessors, object_accessors, param_accessors,
+      hr_accessors, mod_accessors, a_accessors, img_accessors, object_accessors, param_accessors,
       applet_accessors, map_accessors, area_accessors, script_accessors, table_accessors,
       caption_accessors, col_accessors, tablesection_accessors, tr_accessors,
       tablecell_accessors, frameSet_accessors, frame_accessors, iFrame_accessors, marquee_accessors;
index 9b553723f38f96d5b5bbe5c21aab3ade0b80def7..de300032d9c6ba6ff695db7ff3a24cc220c35848 100644 (file)
@@ -142,21 +142,22 @@ sub AddIncludesForType
   # When we're finished with the one-file-per-class 
   # reorganization, we don't need these special cases.
   
-  if ($type eq "DocumentType" or 
-      $type eq "Document" or
-      $type eq "DOMWindow" or
-      $type eq "DOMImplementation" or
-      $type eq "NodeList" or 
-      $type eq "Text" or 
-      $type eq "CharacterData" or
+  if ($type eq "Attr" or
       $type eq "CDATASection" or
       $type eq "CanvasPattern" or
-      $type eq "Range" or
+      $type eq "CharacterData" or
+      $type eq "Comment" or
+      $type eq "DOMImplementation" or
+      $type eq "DOMWindow" or
+      $type eq "Document" or
       $type eq "DocumentFragment" or
+      $type eq "DocumentType" or 
+      $type eq "Element" or
+      $type eq "HTMLCanvasElement" or
       $type eq "Node" or
-      $type eq "Attr" or
-      $type eq "Comment" or
-      $type eq "Element") {
+      $type eq "NodeList" or 
+      $type eq "Range" or 
+      $type eq "Text") {
     $implIncludes{"${type}.h"} = 1;
   } elsif ($type eq "CSSStyleSheet" or $type eq "StyleSheet") {
     $implIncludes{"css_stylesheetimpl.h"} = 1;
@@ -192,7 +193,7 @@ sub AddIncludesForType
     $implIncludes{"CanvasGradient.h"} = 1;
     $implIncludes{"PlatformString.h"} = 1;
   } elsif ($codeGenerator->IsPrimitiveType($type) or
-           $type eq "DOMString") {
+           $type eq "DOMString" or $type eq "DOMObject") {
     # Do nothing
   } else {
     die "Don't know what to include for interface $type";
@@ -933,18 +934,18 @@ sub NativeToJSValue
     $implIncludes{"kjs_dom.h"} = 1;
     $implIncludes{"JSDOMImplementation.h"} = 1;
     return "toJS(exec, $value)";
-  } elsif ($type eq "Node" or
-           $type eq "Text" or
-           $type eq "Comment" or
+  } elsif ($type eq "Attr" or
            $type eq "CDATASection" or
-           $type eq "DocumentType" or
+           $type eq "Comment" or
            $type eq "Document" or
+           $type eq "DocumentFragment" or
+           $type eq "DocumentType" or
+           $type eq "Element" or
            $type eq "EntityReference" or
-           $type eq "ProcessingInstruction" or
            $type eq "HTMLDocument" or
-           $type eq "Element" or
-           $type eq "Attr" or
-           $type eq "DocumentFragment") {
+           $type eq "Node" or
+           $type eq "ProcessingInstruction" or
+           $type eq "Text") {
     $implIncludes{"kjs_dom.h"} = 1;
     $implIncludes{"Comment.h"} = 1;
     $implIncludes{"CDATASection.h"} = 1;
@@ -996,6 +997,9 @@ sub NativeToJSValue
   } elsif ($type eq "DOMWindow") {
     $implIncludes{"kjs_window.h"} = 1;
     return "toJS(exec, $value)";
+  } elsif ($type eq "DOMObject") {
+    $implIncludes{"JSCanvasRenderingContext2DBase.h"} = 1;
+    return "toJS(exec, $value)";
   } else {
     die "Don't know how to convert a value of type $type to a JS Value";
   }
index e3457491a7af25e1f03ad08dbab8d48008130711..605d771e7e5acf4c5fcadd00a69575f1fe5b1bdf 100644 (file)
@@ -2875,9 +2875,9 @@ 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 p;
-        p.setUpdatingControlTints(true);
-        paint(&p, visibleRect);
+        GraphicsContext context(0, false, false);
+        context.setUpdatingControlTints(true);
+        paint(&context, visibleRect);
     }
 }
 
index 1873dcbe50e29eccf0222ca4a66ad5639ff801b7..babe2d6de2597105df9280b9c63f8d397388db12 100644 (file)
@@ -900,7 +900,7 @@ static BOOL nowPrinting(WebCoreFrameBridge *self)
 
 - (void)drawRect:(NSRect)rect
 {
-    GraphicsContext context(nowPrinting(self));
+    GraphicsContext context([NSGraphicsContext currentContext]);
     context.setUsesInactiveTextBackgroundColor(!m_frame->displaysWithFocusAttributes());
     [self _setupRootForPrinting:YES];
     m_frame->paint(&context, enclosingIntRect(rect));
index c64b20efc72a77c413d76f8b770a67f14b9da2cd..92fbe08d1a0d4ed2bdd81a2cf19e2002d3a21f6d 100644 (file)
@@ -811,7 +811,7 @@ void SelectionController::paintCaret(GraphicsContext *p, const IntRect &rect)
         
     IntRect caret = intersection(caretRect(), rect);
     if (!caret.isEmpty())
-        p->fillRect(caret, Brush());
+        p->fillRect(caret, Color::black);
 }
 
 void SelectionController::debugRenderer(RenderObject *r, bool selected) const
index 2a4fd345726183d14b87a45d6e27b0d27de957c9..4e42ea57b7fcc410973e1e0d126620be752b312b 100644 (file)
 #include "CanvasPattern.h"
 
 #include "CachedImage.h"
+#include "ExceptionCode.h"
 #include "FloatRect.h"
+#include "GraphicsContext.h"
 #include "Image.h"
 
 namespace WebCore {
 
-CanvasPattern::CanvasPattern(CachedImage* cachedImage, const String& repetitionType)
-    : m_cachedImage(cachedImage)
-    , m_repeatX(!(equalIgnoringCase(repetitionType, "repeat-y") || equalIgnoringCase(repetitionType, "no-repeat")))
-    , m_repeatY(!(equalIgnoringCase(repetitionType, "repeat-x") || equalIgnoringCase(repetitionType, "no-repeat")))
+void CanvasPattern::parseRepetitionType(const String& type, bool& repeatX, bool& repeatY, ExceptionCode& ec)
+{
+    if (type.isEmpty() || type == "repeat") {
+        repeatX = true;
+        repeatY = true;
+        ec = 0;
+        return;
+    }
+    if (type == "no-repeat") {
+        repeatX = false;
+        repeatY = false;
+        ec = 0;
+        return;
+    }
+    if (type == "repeat-x") {
+        repeatX = true;
+        repeatY = false;
+        ec = 0;
+        return;
+    }
+    if (type == "repeat-y") {
+        repeatX = false;
+        repeatY = true;
+        ec = 0;
+        return;
+    }
+    ec = SYNTAX_ERR;
+}
+
+#if __APPLE__
+
+CanvasPattern::CanvasPattern(CGImageRef image, bool repeatX, bool repeatY)
+    : m_platformImage(image)
+    , m_cachedImage(0)
+    , m_repeatX(repeatX)
+    , m_repeatY(repeatY)
+{
+}
+
+#endif
+
+CanvasPattern::CanvasPattern(CachedImage* cachedImage, bool repeatX, bool repeatY)
+    : m_platformImage(0)
+    , m_cachedImage(cachedImage)
+    , m_repeatX(repeatX)
+    , m_repeatY(repeatY)
 {
     if (cachedImage)
         cachedImage->ref(this);
@@ -43,6 +87,9 @@ CanvasPattern::CanvasPattern(CachedImage* cachedImage, const String& repetitionT
 
 CanvasPattern::~CanvasPattern()
 {
+#if __APPLE__
+    CGImageRelease(m_platformImage);
+#endif
     if (m_cachedImage)
         m_cachedImage->deref(this);
 }
@@ -51,6 +98,13 @@ CanvasPattern::~CanvasPattern()
 
 static void patternCallback(void* info, CGContextRef context)
 {
+    CGImageRef platformImage = static_cast<CanvasPattern*>(info)->platformImage();
+    if (platformImage) {
+        CGRect rect = CGRectMake(0, 0, CGImageGetWidth(platformImage), CGImageGetHeight(platformImage));
+        CGContextDrawImage(context, rect, platformImage);
+        return;
+    }
+
     CachedImage* cachedImage = static_cast<CanvasPattern*>(info)->cachedImage();
     if (!cachedImage)
         return;
@@ -59,14 +113,15 @@ static void patternCallback(void* info, CGContextRef context)
         return;
 
     FloatRect rect = image->rect();
-    
-    // FIXME: Is using CGImageRef directly really superior to asking the image to draw?
+
     if (image->getCGImageRef()) {
         CGContextDrawImage(context, rect, image->getCGImageRef());
         return;
     }
 
-    image->drawInRect(rect, rect, Image::CompositeSourceOver, context);
+    // 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);
 }
 
 static void patternReleaseCallback(void* info)
@@ -76,26 +131,36 @@ static void patternReleaseCallback(void* info)
 
 CGPatternRef CanvasPattern::createPattern(const CGAffineTransform& transform)
 {
-    if (!m_cachedImage)
-        return 0;
-    Image* image = m_cachedImage->image();
-    if (!image)
-        return 0;
+    CGRect rect;
+    rect.origin.x = 0;
+    rect.origin.y = 0;
+    if (m_platformImage) {
+        rect.size.width = CGImageGetWidth(m_platformImage);
+        rect.size.height = CGImageGetHeight(m_platformImage);
+    } else {
+        if (!m_cachedImage)
+            return 0;
+        Image* image = m_cachedImage->image();
+        if (!image)
+            return 0;
+        rect.size.width = image->width();
+        rect.size.height = image->height();
+    }
 
     CGAffineTransform patternTransform =
-        CGAffineTransformTranslate(CGAffineTransformScale(transform, 1, -1), 0, -image->height());
+        CGAffineTransformTranslate(CGAffineTransformScale(transform, 1, -1), 0, -rect.size.height);
 
-    float xStep = m_repeatX ? image->width() : FLT_MAX;
+    float xStep = m_repeatX ? rect.size.width : FLT_MAX;
     // If FLT_MAX should also be used for yStep, nothing is rendered. Using fractions of FLT_MAX also
     // result in nothing being rendered. This is not a problem with xStep.
     // INT_MAX is almost correct, but there seems to be some number wrapping occuring making the fill
     // pattern is not filled correctly. 
     // So, just pick a really large number that works. 
-    float yStep = m_repeatY ? image->height() : (100000000.0);
+    float yStep = m_repeatY ? rect.size.height : (100000000.0);
 
     const CGPatternCallbacks patternCallbacks = { 0, patternCallback, patternReleaseCallback };
     ref();
-    return CGPatternCreate(this, image->rect(), patternTransform, xStep, yStep,
+    return CGPatternCreate(this, rect, patternTransform, xStep, yStep,
         kCGPatternTilingConstantSpacing, TRUE, &patternCallbacks);
 }
 
index 1e30229612f760ab1d9a9adee9519484ad0b560a..0a7bbc03d0aac0c57b21d3c8b0ce6c74c87a2036 100644 (file)
@@ -38,11 +38,21 @@ namespace WebCore {
     class CachedImage;
     class String;
 
+    typedef int ExceptionCode;
+
     class CanvasPattern : public Shared<CanvasPattern>, CachedObjectClient {
     public:
-        CanvasPattern(CachedImage*, const String& repetitionType);
+        static void parseRepetitionType(const String&, bool& repeatX, bool& repeatY, ExceptionCode&);
+
+#if __APPLE__
+        CanvasPattern(CGImageRef, bool repeatX, bool repeatY);
+#endif
+        CanvasPattern(CachedImage*, bool repeatX, bool repeatY);
         ~CanvasPattern();
 
+#if __APPLE__
+        CGImageRef platformImage() const { return m_platformImage; }
+#endif
         CachedImage* cachedImage() const { return m_cachedImage; }
 
 #if __APPLE__
@@ -50,6 +60,9 @@ namespace WebCore {
 #endif
 
     private:
+#if __APPLE__
+        const CGImageRef m_platformImage;
+#endif
         CachedImage* const m_cachedImage;
         const bool m_repeatX;
         const bool m_repeatY;
index bd045b6224deea1bb5bded171c0116b1b5560c7e..99dc69d2b81d8f01ebcdfd702d8633487858fed2 100644 (file)
 #include "config.h"
 #include "CanvasRenderingContext2D.h"
 
-#include "GraphicsContext.h"
-#include "CanvasStyle.h"
 #include "CanvasGradient.h"
 #include "CanvasPattern.h"
-#include "cssparser.h"
+#include "CanvasStyle.h"
+#include "ExceptionCode.h"
+#include "GraphicsContext.h"
 #include "HTMLCanvasElement.h"
 #include "HTMLNames.h"
 #include "RenderHTMLCanvas.h"
+#include "cssparser.h"
 
 namespace WebCore {
 
@@ -55,13 +56,13 @@ CanvasRenderingContext2D::State::State()
     : m_strokeStyle(new CanvasStyle("black"))
     , m_fillStyle(new CanvasStyle("black"))
     , m_lineWidth(1)
-    , m_lineCap("butt")
-    , m_lineJoin("miter")
+    , m_lineCap(ButtCap)
+    , m_lineJoin(MiterJoin)
     , m_miterLimit(10)
     , m_shadowBlur(0)
     , m_shadowColor("black")
     , m_globalAlpha(1)
-    , m_globalComposite("source-over")
+    , m_globalComposite(CompositeSourceOver)
 #if __APPLE__
     , m_platformContextStrokeStyleIsPattern(false)
     , m_platformContextFillStyleIsPattern(false)
@@ -76,7 +77,7 @@ void CanvasRenderingContext2D::save()
 
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
     CGContextSaveGState(c);
@@ -92,7 +93,7 @@ void CanvasRenderingContext2D::restore()
 
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
     CGContextRestoreGState(c);
@@ -112,7 +113,7 @@ void CanvasRenderingContext2D::setStrokeStyle(PassRefPtr<CanvasStyle> style)
 
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    state().m_strokeStyle->applyStrokeColor(drawingContext());
+    state().m_strokeStyle->applyStrokeColor(platformContext());
     state().m_platformContextStrokeStyleIsPattern = false;
 #endif
 }
@@ -130,7 +131,7 @@ void CanvasRenderingContext2D::setFillStyle(PassRefPtr<CanvasStyle> style)
 
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    state().m_fillStyle->applyFillColor(drawingContext());
+    state().m_fillStyle->applyFillColor(platformContext());
     state().m_platformContextFillStyleIsPattern = false;
 #endif
 }
@@ -142,55 +143,86 @@ float CanvasRenderingContext2D::lineWidth() const
 
 void CanvasRenderingContext2D::setLineWidth(float width)
 {
+    if (!(width > 0))
+        return;
+
     state().m_lineWidth = width;
 
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextSetLineWidth(drawingContext(), width);
+    CGContextSetLineWidth(platformContext(), width);
 #endif
 }
 
 String CanvasRenderingContext2D::lineCap() const
 {
-    return state().m_lineCap;
+    const char* const names[3] = { "butt", "round", "square" };
+    return names[state().m_lineCap];
 }
 
-void CanvasRenderingContext2D::setLineCap(const String& cap)
+void CanvasRenderingContext2D::setLineCap(const String& s)
 {
-    // FIXME: Should we store the actual string passed, or should we
-    // convert it to "round", "square", or "butt"?
+    Cap cap;
+    if (s == "butt")
+        cap = ButtCap;
+    else if (s == "round")
+        cap = RoundCap;
+    else if (s == "square")
+        cap = SquareCap;
+    else
+        return;
+
     state().m_lineCap = cap;
 
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    if (equalIgnoringCase(cap, "round"))
-        CGContextSetLineCap(drawingContext(), kCGLineCapRound);
-    else if (equalIgnoringCase(cap, "square"))
-        CGContextSetLineCap(drawingContext(), kCGLineCapSquare);
-    else
-        CGContextSetLineCap(drawingContext(), kCGLineCapButt);
+    switch (cap) {
+        case ButtCap:
+            CGContextSetLineCap(platformContext(), kCGLineCapButt);
+            break;
+        case RoundCap:
+            CGContextSetLineCap(platformContext(), kCGLineCapRound);
+            break;
+        case SquareCap:
+            CGContextSetLineCap(platformContext(), kCGLineCapSquare);
+            break;
+    }
 #endif
 }
 
 String CanvasRenderingContext2D::lineJoin() const
 {
-    return state().m_lineJoin;
+    const char* const names[3] = { "miter", "round", "bevel" };
+    return names[state().m_lineJoin];
 }
 
-void CanvasRenderingContext2D::setLineJoin(const String& join)
+void CanvasRenderingContext2D::setLineJoin(const String& s)
 {
-    // FIXME: Should we store the actual string passed, or should we
-    // convert it to "round", "bevel", or "miter"?
+    Join join;
+    if (s == "miter")
+        join = MiterJoin;
+    else if (s == "round")
+        join = RoundJoin;
+    else if (s == "bevel")
+        join = BevelJoin;
+    else
+        return;
+
     state().m_lineJoin = join;
 
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    if (equalIgnoringCase(join, "round"))
-        CGContextSetLineJoin(drawingContext(), kCGLineJoinRound);
-    else if (equalIgnoringCase(join, "bevel"))
-        CGContextSetLineJoin(drawingContext(), kCGLineJoinBevel);
-    else
-        CGContextSetLineJoin(drawingContext(), kCGLineJoinMiter);
+    switch (join) {
+        case MiterJoin:
+            CGContextSetLineJoin(platformContext(), kCGLineJoinMiter);
+            break;
+        case RoundJoin:
+            CGContextSetLineJoin(platformContext(), kCGLineJoinRound);
+            break;
+        case BevelJoin:
+            CGContextSetLineJoin(platformContext(), kCGLineJoinBevel);
+            break;
+    }
 #endif
 }
 
@@ -201,11 +233,14 @@ float CanvasRenderingContext2D::miterLimit() const
 
 void CanvasRenderingContext2D::setMiterLimit(float limit)
 {
+    if (!(limit > 0))
+        return;
+
     state().m_miterLimit = limit;
 
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextSetMiterLimit(drawingContext(), limit);
+    CGContextSetMiterLimit(platformContext(), limit);
 #endif
 }
 
@@ -261,26 +296,33 @@ float CanvasRenderingContext2D::globalAlpha() const
 
 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(drawingContext(), alpha);
+    CGContextSetAlpha(platformContext(), alpha);
 #endif
 }
 
 String CanvasRenderingContext2D::globalCompositeOperation() const
 {
-    return state().m_globalComposite;
+    return compositeOperatorName(state().m_globalComposite);
 }
 
 void CanvasRenderingContext2D::setGlobalCompositeOperation(const String& operation)
 {
-    state().m_globalComposite = operation;
+    CompositeOperator op;
+    if (!parseCompositeOperator(operation, op))
+        return;
+
+    state().m_globalComposite = op;
 
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    GraphicsContext::setCompositeOperation(drawingContext(), operation);
+    WebCore::setCompositeOperation(platformContext(), op);
 #endif
 }
 
@@ -288,7 +330,7 @@ void CanvasRenderingContext2D::scale(float sx, float sy)
 {
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextScaleCTM(drawingContext(), sx, sy);
+    CGContextScaleCTM(platformContext(), sx, sy);
 #endif
 }
 
@@ -296,7 +338,7 @@ void CanvasRenderingContext2D::rotate(float angleInRadians)
 {
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRotateCTM(drawingContext(), angleInRadians);
+    CGContextRotateCTM(platformContext(), angleInRadians);
 #endif
 }
 
@@ -304,7 +346,7 @@ void CanvasRenderingContext2D::translate(float tx, float ty)
 {
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextTranslateCTM(drawingContext(), tx, ty);
+    CGContextTranslateCTM(platformContext(), tx, ty);
 #endif
 }
 
@@ -372,7 +414,7 @@ void CanvasRenderingContext2D::beginPath()
 {
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
     CGContextBeginPath(c);
@@ -383,7 +425,7 @@ void CanvasRenderingContext2D::closePath()
 {
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
     CGContextClosePath(c);
@@ -394,7 +436,7 @@ void CanvasRenderingContext2D::moveTo(float x, float y)
 {
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
     CGContextMoveToPoint(c, x, y);
@@ -405,7 +447,7 @@ void CanvasRenderingContext2D::lineTo(float x, float y)
 {
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
     CGContextAddLineToPoint(c, x, y);
@@ -416,7 +458,7 @@ void CanvasRenderingContext2D::quadraticCurveTo(float cpx, float cpy, float x, f
 {
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
     CGContextAddQuadCurveToPoint(c, cpx, cpy, x, y);
@@ -427,43 +469,64 @@ void CanvasRenderingContext2D::bezierCurveTo(float cp1x, float cp1y, float cp2x,
 {
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
-    CGContextAddCurveToPoint(drawingContext(), cp1x, cp1y, cp2x, cp2y, x, y);
+    CGContextAddCurveToPoint(c, cp1x, cp1y, cp2x, cp2y, x, y);
 #endif
 }
 
-void CanvasRenderingContext2D::arcTo(float x0, float y0, float x1, float y1, float radius)
+void CanvasRenderingContext2D::arcTo(float x0, float y0, float x1, float y1, float radius, ExceptionCode& ec)
 {
+    ec = 0;
+
+    if (!(radius > 0)) {
+        ec = INDEX_SIZE_ERR;
+        return;
+    }
+
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
-    CGContextAddArcToPoint(drawingContext(), x0, y0, x1, y1, radius);
+    CGContextAddArcToPoint(c, x0, y0, x1, y1, radius);
 #endif
 }
 
-void CanvasRenderingContext2D::arc(float x, float y, float r, float sa, float ea, bool clockwise)
+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 = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
-    CGContextAddArc(drawingContext(), x, y, r, sa, ea, clockwise);
+    CGContextAddArc(c, x, y, r, sa, ea, clockwise);
 #endif
 }
 
-void CanvasRenderingContext2D::rect(float x, float y, float width, float height)
+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 = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
-    CGContextAddRect(drawingContext(), CGRectMake(x, y, width, height));
+    CGContextAddRect(c, CGRectMake(x, y, width, height));
 #endif
 }
 
@@ -471,7 +534,7 @@ void CanvasRenderingContext2D::fill()
 {
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
 
@@ -495,7 +558,7 @@ void CanvasRenderingContext2D::stroke()
 {
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
 
@@ -525,18 +588,25 @@ void CanvasRenderingContext2D::clip()
 {
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
     CGContextClip(c);
 #endif
 }
 
-void CanvasRenderingContext2D::clearRect(float x, float y, float width, float height)
+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 = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
     CGRect rect = CGRectMake(x, y, width, height);
@@ -547,11 +617,18 @@ void CanvasRenderingContext2D::clearRect(float x, float y, float width, float he
 #endif
 }
 
-void CanvasRenderingContext2D::fillRect(float x, float y, float width, float height)
+void CanvasRenderingContext2D::fillRect(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 = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
     CGRect rect = CGRectMake(x, y, width, height);
@@ -572,34 +649,23 @@ void CanvasRenderingContext2D::fillRect(float x, float y, float width, float hei
 #endif
 }
 
-void CanvasRenderingContext2D::strokeRect(float x, float y, float width, float height)
+void CanvasRenderingContext2D::strokeRect(float x, float y, float width, float height, ExceptionCode& ec)
 {
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = drawingContext();
-    if (!c)
-        return;
-
-    // FIXME: Is this right for negative widths?
-    float lineWidth = state().m_lineWidth;
-    float inset = -lineWidth / 2;
-    CGRect rect = CGRectMake(x, y, width, height);
-    CGRect boundingRect = CGRectInset(rect, inset, inset);
-
-    willDraw(boundingRect);
-
-    // FIXME: No support for gradients!
-    if (state().m_strokeStyle->pattern())
-        applyStrokePattern();
-    CGContextStrokeRect(c, rect);
-#endif
+    strokeRect(x, y, width, height, state().m_lineWidth, ec);
 }
 
-void CanvasRenderingContext2D::strokeRect(float x, float y, float width, float height, float lineWidth)
+void CanvasRenderingContext2D::strokeRect(float x, float y, float width, float height, float lineWidth, ExceptionCode& ec)
 {
+    ec = 0;
+
+    if (!(width > 0 && height > 0 && lineWidth > 0)) {
+        ec = INDEX_SIZE_ERR;
+        return;
+    }
+
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
 
@@ -641,7 +707,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
 
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
     const CGFloat components[2] = { grayLevel, 1 };
@@ -661,7 +727,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
 
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
     RGBA32 rgba = CSSParser::parseColor(color);
@@ -687,7 +753,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
 
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
     const CGFloat components[2] = { grayLevel, alpha };
@@ -707,7 +773,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
 
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
     const CGFloat components[4] = { r, g, b, a };
@@ -727,7 +793,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
 
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef dc = drawingContext();
+    CGContextRef dc = platformContext();
     if (!dc)
         return;
     const CGFloat components[5] = { c, m, y, k, a };
@@ -751,7 +817,7 @@ void CanvasRenderingContext2D::applyShadow()
 {
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
     RGBA32 rgba = state().m_shadowColor.isEmpty() ? 0 : CSSParser::parseColor(state().m_shadowColor);
@@ -769,8 +835,7 @@ void CanvasRenderingContext2D::applyShadow()
 #endif
 }
 
-// FIXME: This only exists because canvas is a subclass of image.
-static IntSize imageSize(HTMLImageElement* image)
+static IntSize size(HTMLImageElement* image)
 {
     if (CachedImage* cachedImage = image->cachedImage())
         return cachedImage->imageSize();
@@ -779,30 +844,37 @@ static IntSize imageSize(HTMLImageElement* image)
 
 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float y)
 {
-    if (!image)
-        return;
-    IntSize size = imageSize(image);
-    drawImage(image, 0, 0, size.width(), size.height(), x, y, size.width(), size.height());
+    ASSERT(image);
+    IntSize s = size(image);
+    ExceptionCode ec;
+    drawImage(image, x, y, s.width(), s.height(), ec);
 }
 
-void CanvasRenderingContext2D::drawImage(HTMLImageElement* image, float x, float y, float width, float height)
+void CanvasRenderingContext2D::drawImage(HTMLImageElement* image,
+    float x, float y, float width, float height, ExceptionCode& ec)
 {
-    if (!image)
-        return;
-    IntSize size = imageSize(image);
-    drawImage(image, 0, 0, size.width(), size.height(), x, y, width, height);
+    ASSERT(image);
+    IntSize s = size(image);
+    drawImage(image, 0, 0, s.width(), s.height(), x, y, width, height, ec);
 }
 
 void CanvasRenderingContext2D::drawImage(HTMLImageElement* image,
     float sx, float sy, float sw, float sh,
-    float dx, float dy, float dw, float dh)
+    float dx, float dy, float dw, float dh, ExceptionCode& ec)
 {
-    if (!image)
+    ASSERT(image);
+
+    ec = 0;
+
+    FloatRect imageRect = FloatRect(FloatPoint(), size(image));
+    FloatRect sourceRect = FloatRect(sx, sy, sw, sh);
+
+    if (!(imageRect.contains(sourceRect) && sw > 0 && sh > 0 && dw > 0 && dh > 0)) {
+        ec = INDEX_SIZE_ERR;
         return;
+    }
 
-    // FIXME: Do this through platform-independent GraphicsContext API.
-#if __APPLE__
-    CGContextRef c = drawingContext();
+    GraphicsContext* c = drawingContext();
     if (!c)
         return;
 
@@ -812,35 +884,42 @@ void CanvasRenderingContext2D::drawImage(HTMLImageElement* image,
 
     FloatRect destRect = FloatRect(dx, dy, dw, dh);
     willDraw(destRect);
-    cachedImage->image()->drawInRect(destRect, FloatRect(sx, sy, sw, sh),
-        Image::compositeOperatorFromString(state().m_globalComposite), c);
-#endif
+    c->drawImage(cachedImage->image(), destRect, sourceRect, state().m_globalComposite);
 }
 
 void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas, float x, float y)
 {
-    if (!canvas)
-        return;
-    drawImage(canvas, 0, 0, canvas->width(), canvas->height(), x, y, canvas->width(), canvas->height());
+    ASSERT(canvas);
+    ExceptionCode ec;
+    drawImage(canvas, x, y, canvas->width(), canvas->height(), ec);
 }
 
-void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas, float x, float y, float width, float height)
+void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas,
+    float x, float y, float width, float height, ExceptionCode& ec)
 {
-    if (!canvas)
-        return;
-    drawImage(canvas, 0, 0, canvas->width(), canvas->height(), x, y, width, height);
+    ASSERT(canvas);
+    drawImage(canvas, 0, 0, canvas->width(), canvas->height(), x, y, width, height, ec);
 }
 
 void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas,
     float sx, float sy, float sw, float sh,
-    float dx, float dy, float dw, float dh)
+    float dx, float dy, float dw, float dh, ExceptionCode& ec)
 {
+    ASSERT(canvas);
+
+    ec = 0;
+
+    if (!(sw > 0 && sh > 0 && dw > 0 && dh > 0)) {
+        ec = INDEX_SIZE_ERR;
+        return;
+    }
+
     if (!canvas)
         return;
 
     // FIXME: Do this through platform-independent GraphicsContext API.
 #if __APPLE__
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
 
@@ -899,16 +978,18 @@ void CanvasRenderingContext2D::drawImageFromRect(HTMLImageElement* image,
     if (!cachedImage)
         return;
 
+    GraphicsContext* c = drawingContext();
+    if (!c)
+        return;
+
+    CompositeOperator op;
+    if (!parseCompositeOperator(compositeOperation, op))
+        op = CompositeSourceOver;
+
     // FIXME: Do this through platform-independent GraphicsContext API.
     FloatRect destRect = FloatRect(dx, dy, dw, dh);
     willDraw(destRect);
-#if __APPLE__
-    CGContextRef c = drawingContext();
-    if (!c)
-        return;
-    cachedImage->image()->drawInRect(destRect, FloatRect(sx, sy, sw, sh),
-        Image::compositeOperatorFromString(compositeOperation), c);
-#endif
+    c->drawImage(cachedImage->image(), destRect, FloatRect(sx, sy, sw, sh), op);
 }
 
 void CanvasRenderingContext2D::setAlpha(float alpha)
@@ -931,9 +1012,33 @@ PassRefPtr<CanvasGradient> CanvasRenderingContext2D::createRadialGradient(float
     return new CanvasGradient(FloatPoint(x0, y0), r0, FloatPoint(x1, y1), r1);
 }
 
-PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLImageElement* image, const String& repetitionType)
+PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLImageElement* image,
+    const String& repetitionType, ExceptionCode& ec)
+{
+    bool repeatX, repeatY;
+    CanvasPattern::parseRepetitionType(repetitionType, repeatX, repeatY, ec);
+    if (ec)
+        return 0;
+    return new CanvasPattern(image ? image->cachedImage() : 0, repeatX, repeatY);
+}
+
+PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLCanvasElement* canvas,
+    const String& repetitionType, ExceptionCode& ec)
 {
-    return new CanvasPattern(image ? image->cachedImage() : 0, repetitionType);
+    bool repeatX, repeatY;
+    CanvasPattern::parseRepetitionType(repetitionType, repeatX, repeatY, ec);
+    if (ec)
+        return 0;
+#if __APPLE__
+    CGImageRef image = canvas->createPlatformImage();
+    if (!image)
+        return 0;
+    PassRefPtr<CanvasPattern> pattern = new CanvasPattern(image, repeatX, repeatY);
+    CGImageRelease(image);
+    return pattern;
+#else
+    return 0;
+#endif
 }
 
 void CanvasRenderingContext2D::willDraw(const FloatRect& r)
@@ -943,18 +1048,26 @@ void CanvasRenderingContext2D::willDraw(const FloatRect& r)
     m_canvas->willDraw(r);
 }
 
-#if __APPLE__
-
-CGContextRef CanvasRenderingContext2D::drawingContext() const
+GraphicsContext* CanvasRenderingContext2D::drawingContext() const
 {
     if (!m_canvas)
         return 0;
     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 = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
 
@@ -986,7 +1099,7 @@ void CanvasRenderingContext2D::applyStrokePattern()
 
 void CanvasRenderingContext2D::applyFillPattern()
 {
-    CGContextRef c = drawingContext();
+    CGContextRef c = platformContext();
     if (!c)
         return;
 
index 5c126209b469a12042fa3a33f1ca645d92763271..202e2131b2d15db29805238aa0b1497168546277 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef HTMLCanvas2DContext_h
 #define HTMLCanvas2DContext_h
 
+#include "CompositeOperator.h"
 #include "FloatRect.h"
 #include "PlatformString.h"
 #include <kxmlcore/Vector.h>
 
 namespace WebCore {
 
-    class HTMLCanvasElement;
-    class CanvasStyle;
-    class HTMLImageElement;
     class CanvasGradient;
     class CanvasPattern;
+    class CanvasStyle;
+    class GraphicsContext;
+    class HTMLCanvasElement;
+    class HTMLImageElement;
+
+    typedef int ExceptionCode;
 
     class CanvasRenderingContext2D : public Shared<CanvasRenderingContext2D> {
     public:
@@ -112,18 +116,18 @@ namespace WebCore {
         void lineTo(float x, float y);
         void quadraticCurveTo(float cpx, float cpy, float x, float y);
         void bezierCurveTo(float cp1x, float cp1y, float cp2x, float cp2y, float x, float y);
-        void arcTo(float x0, float y0, float x1, float y1, float radius);
-        void arc(float x, float y, float r, float sa, float ea, bool clockwise);
-        void rect(float x, float y, float width, float height);
+        void arcTo(float x0, float y0, float x1, float y1, float radius, ExceptionCode&);
+        void arc(float x, float y, float r, float sa, float ea, bool clockwise, ExceptionCode&);
+        void rect(float x, float y, float width, float height, ExceptionCode&);
 
         void fill();
         void stroke();
         void clip();
 
-        void clearRect(float x, float y, float width, float height);
-        void fillRect(float x, float y, float width, float height);
-        void strokeRect(float x, float y, float width, float height);
-        void strokeRect(float x, float y, float width, float height, float lineWidth);
+        void clearRect(float x, float y, float width, float height, ExceptionCode&);
+        void fillRect(float x, float y, float width, float height, ExceptionCode&);
+        void strokeRect(float x, float y, float width, float height, ExceptionCode&);
+        void strokeRect(float x, float y, float width, float height, float lineWidth, ExceptionCode&);
 
         void setShadow(float width, float height, float blur);
         void setShadow(float width, float height, float blur, const String& color);
@@ -136,13 +140,13 @@ namespace WebCore {
         void clearShadow();
 
         void drawImage(HTMLImageElement*, float x, float y);
-        void drawImage(HTMLImageElement*, float x, float y, float width, float height);
+        void drawImage(HTMLImageElement*, float x, float y, float width, float height, ExceptionCode&);
         void drawImage(HTMLImageElement*, float sx, float sy, float sw, float sh,
-            float dx, float dy, float dw, float dh);
+            float dx, float dy, float dw, float dh, ExceptionCode&);
         void drawImage(HTMLCanvasElement*, float x, float y);
-        void drawImage(HTMLCanvasElement*, float x, float y, float width, float height);
+        void drawImage(HTMLCanvasElement*, float x, float y, float width, float height, ExceptionCode&);
         void drawImage(HTMLCanvasElement*, float sx, float sy, float sw, float sh,
-            float dx, float dy, float dw, float dh);
+            float dx, float dy, float dw, float dh, ExceptionCode&);
 
         void drawImageFromRect(HTMLImageElement*, float sx, float sy, float sw, float sh,
             float dx, float dy, float dw, float dh, const String& compositeOperation);
@@ -153,26 +157,30 @@ namespace WebCore {
 
         PassRefPtr<CanvasGradient> createLinearGradient(float x0, float y0, float x1, float y1);
         PassRefPtr<CanvasGradient> createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1);
-        PassRefPtr<CanvasPattern> createPattern(HTMLImageElement*, const String& repetitionType);
+        PassRefPtr<CanvasPattern> createPattern(HTMLImageElement*, const String& repetitionType, ExceptionCode&);
+        PassRefPtr<CanvasPattern> createPattern(HTMLCanvasElement*, const String& repetitionType, ExceptionCode&);
 
         void reset();
         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;
             float m_lineWidth;
-            String m_lineCap;
-            String m_lineJoin;
+            Cap m_lineCap;
+            Join m_lineJoin;
             float m_miterLimit;
             FloatSize m_shadowOffset;
             float m_shadowBlur;
             String m_shadowColor;
             float m_globalAlpha;
-            String m_globalComposite;
+            CompositeOperator m_globalComposite;
 #if __APPLE__
             bool m_platformContextStrokeStyleIsPattern;
             CGAffineTransform m_strokeStylePatternTransform;
@@ -188,12 +196,13 @@ namespace WebCore {
 
         void willDraw(const FloatRect&);
 
+        GraphicsContext* drawingContext() const;
+
 #if __APPLE__
         void applyStrokePattern();
         void applyFillPattern();
 
-        // FIXME: Use GraphicsContext instead.
-        CGContextRef drawingContext() const;
+        CGContextRef platformContext() const;
 #endif
 
         HTMLCanvasElement* m_canvas;
index 7cf8e2861dd146c18787f1552eb96ee50d025a2e..eb7949ee050024e14aa0714bb0c0d980d4743561 100644 (file)
@@ -48,8 +48,10 @@ module html {
         attribute float shadowBlur;
         attribute DOMString shadowColor;
 
-        void clearRect(in float x, in float y, in float width, in float height);
-        void fillRect(in float x, in float y, in float width, in float height);
+        void clearRect(in float x, in float y, in float width, in float height)
+            raises (dom::DOMException);
+        void fillRect(in float x, in float y, in float width, in float height)
+            raises (dom::DOMException);
 
         void beginPath();
         void closePath();
@@ -57,9 +59,12 @@ module html {
         void lineTo(in float x, in float y);
         void quadraticCurveTo(in float cpx, in float cpy, in float x, in float y);
         void bezierCurveTo(in float cp1x, in float cp1y, in float cp2x, in float cp2y, in float x, in float y);
-        void arcTo(in float x1, in float y1, in float x2, in float y2, in float radius);
-        void rect(in float x, in float y, in float width, in float height);
-        void arc(in float x, in float y, in float radius, in float startAngle, in float endAngle, in boolean clockwise);
+        void arcTo(in float x1, in float y1, in float x2, in float y2, in float radius)
+            raises (dom::DOMException);
+        void rect(in float x, in float y, in float width, in float height)
+            raises (dom::DOMException);
+        void arc(in float x, in float y, in float radius, in float startAngle, in float endAngle, in boolean clockwise)
+            raises (dom::DOMException);
         void fill();
         void stroke();
         void clip();
index 3e2dd510e53c5e71021d2ae44954a44beb5e6e34..33689b951a00c3b252f2b607d969c5d816993ecf 100644 (file)
@@ -43,11 +43,11 @@ const int defaultWidth = 300;
 const int defaultHeight = 150;
 
 HTMLCanvasElement::HTMLCanvasElement(Document* doc)
-    : HTMLElement(canvasTag, doc), m_size(defaultWidth, defaultHeight)
-    , m_createdDrawingContext(false), m_data(0)
-#if __APPLE__
+    : HTMLElement(canvasTag, doc)
+    , m_size(defaultWidth, defaultHeight)
+    , m_createdDrawingContext(false)
+    , m_data(0)
     , m_drawingContext(0)
-#endif
 {
 }
 
@@ -56,9 +56,7 @@ HTMLCanvasElement::~HTMLCanvasElement()
     if (m_2DContext)
         m_2DContext->detachCanvas();
     fastFree(m_data);
-#if __APPLE__
-    CGContextRelease(m_drawingContext);
-#endif
+    delete m_drawingContext;
 }
 
 void HTMLCanvasElement::parseMappedAttribute(MappedAttribute* attr)
@@ -89,8 +87,7 @@ void HTMLCanvasElement::setWidth(int value)
 
 CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type)
 {
-    // FIXME: Web Applications 1.0 says "2d" only, but the code here matches historical behavior of WebKit.
-    if (type.isNull() || type == "2d" || type == "2D") {
+    if (type == "2d") {
         if (!m_2DContext)
             m_2DContext = new CanvasRenderingContext2D(this);
         return m_2DContext.get();
@@ -129,10 +126,8 @@ void HTMLCanvasElement::reset()
     m_createdDrawingContext = false;
     fastFree(m_data);
     m_data = 0;
-#if __APPLE__
-    CGContextRelease(m_drawingContext);
+    delete m_drawingContext;
     m_drawingContext = 0;
-#endif
 }
 
 void HTMLCanvasElement::paint(GraphicsContext* p, const IntRect& r)
@@ -141,7 +136,7 @@ void HTMLCanvasElement::paint(GraphicsContext* p, const IntRect& r)
         return;
 #if __APPLE__
     if (CGImageRef image = createPlatformImage()) {
-        CGContextDrawImage(p->currentCGContext(), r, image);
+        CGContextDrawImage(p->platformContext(), r, image);
         CGImageRelease(image);
     }
 #endif
@@ -165,27 +160,29 @@ void HTMLCanvasElement::createDrawingContext() const
         return;
 #if __APPLE__
     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
-    m_drawingContext = CGBitmapContextCreate(m_data, w, height(), 8, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);
+    CGContextRef bitmapContext = CGBitmapContextCreate(m_data, w, height(), 8, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);
     CGColorSpaceRelease(colorSpace);
+    m_drawingContext = new GraphicsContext(bitmapContext, false, false);
+    CGContextRelease(bitmapContext);
 #endif
 }
 
-#if __APPLE__
-
-CGContextRef HTMLCanvasElement::drawingContext() const
+GraphicsContext* HTMLCanvasElement::drawingContext() const
 {
     if (!m_createdDrawingContext)
         createDrawingContext();
     return m_drawingContext;
 }
 
+#if __APPLE__
+
 CGImageRef HTMLCanvasElement::createPlatformImage() const
 {
-    CGContextRef context = drawingContext();
+    GraphicsContext* context = drawingContext();
     if (!context)
         return 0;
-    CGContextFlush(context);
-    return CGBitmapContextCreateImage(context);
+    CGContextFlush(context->platformContext());
+    return CGBitmapContextCreateImage(context->platformContext());
 }
 
 #endif
index bce4ea7757df4e8bf478d2be123b3bdf4b363755..00376362b841fd87bea7928044dd013fa1871ab6 100644 (file)
@@ -60,9 +60,10 @@ public:
 
     void paint(GraphicsContext*, const IntRect&);
 
+    GraphicsContext* drawingContext() const;
+
 #if __APPLE__
     CGImageRef createPlatformImage() const;
-    CGContextRef drawingContext() const;
 #endif
 
 private:
@@ -77,10 +78,7 @@ private:
 
     mutable bool m_createdDrawingContext;
     mutable void* m_data;
-
-#if __APPLE__
-    mutable CGContextRef m_drawingContext;
-#endif
+    mutable GraphicsContext* m_drawingContext;
 };
 
 } //namespace
diff --git a/WebCore/html/HTMLCanvasElement.idl b/WebCore/html/HTMLCanvasElement.idl
new file mode 100644 (file)
index 0000000..6eec4d8
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+module html {
+
+    interface [LegacyParent=KJS::JSHTMLElement] HTMLCanvasElement : HTMLElement {
+
+        attribute long width;
+        attribute long height;
+
+        DOMObject getContext(in DOMString contextID);
+
+    };
+
+}
index b074135dd03e45fb0dcdc9b1b4fa2272ce1842cb..b0aaab58a591b48005b7053c18f4329c91c306e2 100644 (file)
@@ -730,45 +730,53 @@ bool HTMLParser::mapCreateErrorCheck(Token* t, RefPtr<Node>& result)
     return false;
 }
 
+bool HTMLParser::canvasCreateErrorCheck(Token* t, RefPtr<Node>& result)
+{
+    if (!m_fragment && document->frame()->jScriptEnabled())
+        setSkipMode(canvasTag);
+    return true;
+}
+
 PassRefPtr<Node> HTMLParser::getNode(Token* t)
 {
     // Init our error handling table.
     static FunctionMap gFunctionMap;
     if (gFunctionMap.isEmpty()) {
-        gFunctionMap.set(textAtom.impl(), &HTMLParser::textCreateErrorCheck);
-        gFunctionMap.set(commentAtom.impl(), &HTMLParser::commentCreateErrorCheck);
-        gFunctionMap.set(headTag.localName().impl(), &HTMLParser::headCreateErrorCheck);
+        gFunctionMap.set(aTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck);
+        gFunctionMap.set(bTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck);
+        gFunctionMap.set(bigTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck);
         gFunctionMap.set(bodyTag.localName().impl(), &HTMLParser::bodyCreateErrorCheck);
+        gFunctionMap.set(buttonTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck);
+        gFunctionMap.set(canvasTag.localName().impl(), &HTMLParser::canvasCreateErrorCheck);
+        gFunctionMap.set(commentAtom.impl(), &HTMLParser::commentCreateErrorCheck);
+        gFunctionMap.set(ddTag.localName().impl(), &HTMLParser::ddCreateErrorCheck);
+        gFunctionMap.set(dtTag.localName().impl(), &HTMLParser::dtCreateErrorCheck);
+        gFunctionMap.set(formTag.localName().impl(), &HTMLParser::formCreateErrorCheck);
         gFunctionMap.set(framesetTag.localName().impl(), &HTMLParser::framesetCreateErrorCheck);
+        gFunctionMap.set(headTag.localName().impl(), &HTMLParser::headCreateErrorCheck);
+        gFunctionMap.set(iTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck);
         gFunctionMap.set(iframeTag.localName().impl(), &HTMLParser::iframeCreateErrorCheck);
-        gFunctionMap.set(formTag.localName().impl(), &HTMLParser::formCreateErrorCheck);
         gFunctionMap.set(isindexTag.localName().impl(), &HTMLParser::isindexCreateErrorCheck);
-        gFunctionMap.set(selectTag.localName().impl(), &HTMLParser::selectCreateErrorCheck);
-        gFunctionMap.set(ddTag.localName().impl(), &HTMLParser::ddCreateErrorCheck);
-        gFunctionMap.set(dtTag.localName().impl(), &HTMLParser::dtCreateErrorCheck);
         gFunctionMap.set(liTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck);
-        gFunctionMap.set(aTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck);
-        gFunctionMap.set(buttonTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck);
+        gFunctionMap.set(mapTag.localName().impl(), &HTMLParser::mapCreateErrorCheck);
         gFunctionMap.set(nobrTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck);
-        gFunctionMap.set(wbrTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck);
-        gFunctionMap.set(trTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck);
+        gFunctionMap.set(noembedTag.localName().impl(), &HTMLParser::noembedCreateErrorCheck);
+        gFunctionMap.set(noframesTag.localName().impl(), &HTMLParser::noframesCreateErrorCheck);
+        gFunctionMap.set(noscriptTag.localName().impl(), &HTMLParser::noscriptCreateErrorCheck);
+        gFunctionMap.set(sTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck);
+        gFunctionMap.set(selectTag.localName().impl(), &HTMLParser::selectCreateErrorCheck);
+        gFunctionMap.set(smallTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck);
+        gFunctionMap.set(strikeTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck);
+        gFunctionMap.set(tbodyTag.localName().impl(), &HTMLParser::tableSectionCreateErrorCheck);
         gFunctionMap.set(tdTag.localName().impl(), &HTMLParser::tableCellCreateErrorCheck);
+        gFunctionMap.set(textAtom.impl(), &HTMLParser::textCreateErrorCheck);
+        gFunctionMap.set(tfootTag.localName().impl(), &HTMLParser::tableSectionCreateErrorCheck);
         gFunctionMap.set(thTag.localName().impl(), &HTMLParser::tableCellCreateErrorCheck);
-        gFunctionMap.set(tbodyTag.localName().impl(), &HTMLParser::tableSectionCreateErrorCheck);
         gFunctionMap.set(theadTag.localName().impl(), &HTMLParser::tableSectionCreateErrorCheck);
-        gFunctionMap.set(tfootTag.localName().impl(), &HTMLParser::tableSectionCreateErrorCheck);
+        gFunctionMap.set(trTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck);
         gFunctionMap.set(ttTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck);
         gFunctionMap.set(uTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck);
-        gFunctionMap.set(bTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck);
-        gFunctionMap.set(iTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck);
-        gFunctionMap.set(sTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck);
-        gFunctionMap.set(strikeTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck);
-        gFunctionMap.set(bigTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck);
-        gFunctionMap.set(smallTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck);
-        gFunctionMap.set(noembedTag.localName().impl(), &HTMLParser::noembedCreateErrorCheck);
-        gFunctionMap.set(noframesTag.localName().impl(), &HTMLParser::noframesCreateErrorCheck);
-        gFunctionMap.set(noscriptTag.localName().impl(), &HTMLParser::noscriptCreateErrorCheck);
-        gFunctionMap.set(mapTag.localName().impl(), &HTMLParser::mapCreateErrorCheck);
+        gFunctionMap.set(wbrTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck);
     }
 
     bool proceed = true;
index e19fbfc9802324142b67cff0148796465eb7344b..2c83ed1c6e7f0ecfad9b046d26be8def249b348d 100644 (file)
@@ -80,30 +80,28 @@ private:
 
     Document* document;
 
-    /*
-     * generate a node from the token
-     */
     PassRefPtr<Node> getNode(Token*);
-    bool textCreateErrorCheck(Token*, RefPtr<Node>&);
-    bool commentCreateErrorCheck(Token*, RefPtr<Node>&);
-    bool headCreateErrorCheck(Token*, RefPtr<Node>&);
     bool bodyCreateErrorCheck(Token*, RefPtr<Node>&);
+    bool canvasCreateErrorCheck(Token*, RefPtr<Node>&);
+    bool commentCreateErrorCheck(Token*, RefPtr<Node>&);
+    bool ddCreateErrorCheck(Token*, RefPtr<Node>&);
+    bool dtCreateErrorCheck(Token*, RefPtr<Node>&);
+    bool formCreateErrorCheck(Token*, RefPtr<Node>&);
     bool framesetCreateErrorCheck(Token*, RefPtr<Node>&);
+    bool headCreateErrorCheck(Token*, RefPtr<Node>&);
     bool iframeCreateErrorCheck(Token*, RefPtr<Node>&);
-    bool formCreateErrorCheck(Token*, RefPtr<Node>&);
     bool isindexCreateErrorCheck(Token*, RefPtr<Node>&);
-    bool selectCreateErrorCheck(Token*, RefPtr<Node>&);
-    bool ddCreateErrorCheck(Token*, RefPtr<Node>&);
-    bool dtCreateErrorCheck(Token*, RefPtr<Node>&);
+    bool mapCreateErrorCheck(Token*, RefPtr<Node>&);
     bool nestedCreateErrorCheck(Token*, RefPtr<Node>&);
     bool nestedStyleCreateErrorCheck(Token*, RefPtr<Node>&);
-    bool tableCellCreateErrorCheck(Token*, RefPtr<Node>&);
-    bool tableSectionCreateErrorCheck(Token*, RefPtr<Node>&);
     bool noembedCreateErrorCheck(Token*, RefPtr<Node>&);
-    bool noscriptCreateErrorCheck(Token*, RefPtr<Node>&);
     bool noframesCreateErrorCheck(Token*, RefPtr<Node>&);
     bool nolayerCreateErrorCheck(Token*, RefPtr<Node>&);
-    bool mapCreateErrorCheck(Token*, RefPtr<Node>&);
+    bool noscriptCreateErrorCheck(Token*, RefPtr<Node>&);
+    bool selectCreateErrorCheck(Token*, RefPtr<Node>&);
+    bool tableCellCreateErrorCheck(Token*, RefPtr<Node>&);
+    bool tableSectionCreateErrorCheck(Token*, RefPtr<Node>&);
+    bool textCreateErrorCheck(Token*, RefPtr<Node>&);
 
     void processCloseTag(Token *);
 
index 7598b407d7600f4db4991a9bd3ef379e80c5c2bd..aabce4edad5eec73eeaa368ca9eb6abfbc1cfc51 100644 (file)
@@ -120,6 +120,7 @@ void HTMLImageLoader::notifyFinished(CachedObject *image)
 
 HTMLImageElement::HTMLImageElement(Document *doc, HTMLFormElement *f)
     : HTMLElement(imgTag, doc), m_imageLoader(this), ismap(false), m_form(f)
+    , m_compositeOperator(CompositeSourceOver)
 {
     if (f)
         f->registerImgElement(this);
@@ -127,6 +128,7 @@ HTMLImageElement::HTMLImageElement(Document *doc, HTMLFormElement *f)
 
 HTMLImageElement::HTMLImageElement(const QualifiedName& tagName, Document *doc)
     : HTMLElement(tagName, doc), m_imageLoader(this), ismap(false), m_form(0)
+    , m_compositeOperator(CompositeSourceOver)
 {
 }
 
@@ -200,9 +202,10 @@ void HTMLImageElement::parseMappedAttribute(MappedAttribute *attr)
         setHTMLEventListener(errorEvent, attr);
     else if (attrName == onloadAttr)
         setHTMLEventListener(loadEvent, attr);
-    else if (attrName == compositeAttr)
-        _compositeOperator = attr->value().domString();
-    else if (attrName == nameAttr) {
+    else if (attrName == compositeAttr) {
+        if (!parseCompositeOperator(attr->value(), m_compositeOperator))
+            m_compositeOperator = CompositeSourceOver;
+    } else if (attrName == nameAttr) {
         String newNameAttr = attr->value();
         if (inDocument() && document()->isHTMLDocument()) {
             HTMLDocument* doc = static_cast<HTMLDocument*>(document());
index a0ec83ccace0f525b680ce819a8ac571fd96d100..beade8a2abb0c800dd4139fb4f318d9d1384ceca 100644 (file)
@@ -95,7 +95,7 @@ public:
     
     virtual bool isURLAttribute(Attribute*) const;
 
-    Image::CompositeOperator compositeOperator() const { return Image::compositeOperatorFromString(_compositeOperator); }
+    CompositeOperator compositeOperator() const { return m_compositeOperator; }
 
     CachedImage* cachedImage() const { return m_imageLoader.image(); }
     
@@ -144,7 +144,7 @@ protected:
     bool ismap;
     HTMLFormElement* m_form;
     String oldNameAttr;
-    String _compositeOperator;
+    CompositeOperator m_compositeOperator;
 };
 
 //------------------------------------------------------------------
index 93e8a95d50f2a1a3951b953de20b4ac796494aa5..1f3f2540bcffd793ef9002d91b08ba8209115ef0 100644 (file)
@@ -220,7 +220,7 @@ float KCanvasMarker::scaleY() const
     return m_scaleY;
 }
 
-void KCanvasMarker::draw(const FloatRect &rect, double x, double y, double strokeWidth, double angle)
+void KCanvasMarker::draw(GraphicsContext* context, const FloatRect& rect, double x, double y, double strokeWidth, double angle)
 {
     if(m_marker)
     {
@@ -239,8 +239,7 @@ void KCanvasMarker::draw(const FloatRect &rect, double x, double y, double strok
 
         // FIXME: PaintInfo should be passed into this method instead.
         // FIXME: bounding box fractions lost
-        GraphicsContext p;
-        RenderObject::PaintInfo info(&p, enclosingIntRect(rect), PaintPhaseForeground, 0, 0);
+        RenderObject::PaintInfo info(context, enclosingIntRect(rect), PaintPhaseForeground, 0, 0);
         m_marker->setLocalTransform(rotation.multiply(translation).qmatrix());
         static_cast<KCanvasContainer *>(m_marker)->setDrawsContents(true);
         m_marker->paint(info, 0, 0);
index 3a0bac272bb3cd264bda293469462cfa1479c414..ec5049874c49d4adfc37fbb46578748a6af748c0 100644 (file)
@@ -136,10 +136,10 @@ public:
     float scaleX() const;
     float scaleY() const;
 
-     // Draw onto the canvas
-    void draw(const FloatRect &rect, double x, double y, double strokeWidth = 1., double angle = 0.0);
+    void draw(GraphicsContext*, const FloatRect&, double x, double y, double strokeWidth = 1, double angle = 0);
 
     QTextStream& externalRepresentation(QTextStream &) const; 
+
 private:
     double m_refX, m_refY;
     float m_angle, m_scaleX, m_scaleY;
index bb07df5b3a6f64bb1da2b11d4ec618d3e40f6f7a..800cf3b03918419e4ac989b6ef3c04d9254f92b0 100644 (file)
 #include "KRenderingFillPainter.h"
 #include "KRenderingStrokePainter.h"
 #include "SVGStyledElement.h"
+#include <kxmlcore/OwnPtr.h>
 
 namespace WebCore {
 
-class RenderPath::Private
-{
+class RenderPath::Private {
 public:
     RefPtr<KCanvasPath> path;
 
@@ -44,7 +44,8 @@ public:
 };        
 
 // RenderPath
-RenderPath::RenderPath(RenderStyle *style, SVGStyledElement *node) : RenderObject((WebCore::Node *)node), d(new Private())
+RenderPath::RenderPath(RenderStyle* style, SVGStyledElement* node)
+    : RenderObject(node), d(new Private)
 {
     ASSERT(style != 0);
 }
@@ -188,23 +189,24 @@ void RenderPath::paint(PaintInfo &paintInfo, int parentX, int parentY)
         return;
     
     KRenderingDevice* device = renderingDevice();
-    KRenderingDeviceContext *deviceContext = device->currentContext();
+    KRenderingDeviceContext *context = device->currentContext();
     bool shouldPopContext = false;
-    if (!deviceContext) {
-        // I only need to setup for KCanvas rendering if it hasn't already been done.
-        deviceContext = paintInfo.p->createRenderingDeviceContext();
-        device->pushContext(deviceContext);
-        shouldPopContext = true;
-    } else
+    if (context)
         paintInfo.p->save();
+    else {
+        // Need to set up KCanvas rendering if it hasn't already been done.
+        context = paintInfo.p->createRenderingDeviceContext();
+        device->pushContext(context);
+        shouldPopContext = true;
+    }
 
-    deviceContext->concatCTM(localTransform());
+    context->concatCTM(localTransform());
 
     // setup to apply filters
     KCanvasFilter *filter = getFilterById(document(), style()->svgStyle()->filter().mid(1));
     if (filter) {
         filter->prepareFilter(relativeBBox(true));
-        deviceContext = device->currentContext();
+        context = device->currentContext();
     }
 
     if (KCanvasClipper *clipper = getClipperById(document(), style()->svgStyle()->clipPath().mid(1)))
@@ -213,33 +215,35 @@ void RenderPath::paint(PaintInfo &paintInfo, int parentX, int parentY)
     if (KCanvasMasker *masker = getMaskerById(document(), style()->svgStyle()->maskElement().mid(1)))
         masker->applyMask(relativeBBox(true));
 
-    deviceContext->clearPath();
+    context->clearPath();
     
     KRenderingPaintServer *fillPaintServer = KSVGPainterFactory::fillPaintServer(style(), this);
     if (fillPaintServer) {
-        deviceContext->addPath(path());
+        context->addPath(path());
         fillPaintServer->setActiveClient(this);
-        fillPaintServer->draw(deviceContext, this, APPLY_TO_FILL);
+        fillPaintServer->draw(context, this, APPLY_TO_FILL);
     }
     KRenderingPaintServer *strokePaintServer = KSVGPainterFactory::strokePaintServer(style(), this);
     if (strokePaintServer) {
-        deviceContext->addPath(path()); // path is cleared when filled.
+        context->addPath(path()); // path is cleared when filled.
         strokePaintServer->setActiveClient(this);
-        strokePaintServer->draw(deviceContext, this, APPLY_TO_STROKE);
+        strokePaintServer->draw(context, this, APPLY_TO_STROKE);
     }
 
-    drawMarkersIfNeeded(paintInfo.r, path());
+    OwnPtr<GraphicsContext> c(context->createGraphicsContext());
+    drawMarkersIfNeeded(c.get(), paintInfo.r, path());
 
     // actually apply the filter
     if (filter)
         filter->applyFilter(relativeBBox(true));
 
     // restore drawing state
-    if (shouldPopContext) {
-        device->popContext();
-        delete deviceContext;
-    } else
+    if (!shouldPopContext)
         paintInfo.p->restore();
+    else {
+        device->popContext();
+        delete context;
+    }
 }
 
 void RenderPath::absoluteRects(DeprecatedValueList<IntRect>& rects, int _tx, int _ty)
index 2e14205e0a7895ac49f8f815e0aa808e395e584f..329be7e60b031c7309931284ffdb14c4be83d724 100644 (file)
@@ -74,7 +74,7 @@ public:
     virtual bool nodeAtPoint(NodeInfo&, int x, int y, int tx, int ty, HitTestAction);
 
 protected:
-    virtual void drawMarkersIfNeeded(const FloatRect&, const KCanvasPath*) const = 0;
+    virtual void drawMarkersIfNeeded(GraphicsContext*, const FloatRect&, const KCanvasPath*) const = 0;
 
 private:
     FloatRect strokeBBox() const;
index e40238ed316d50d32333b718eaff6087bdb046c8..a768db15a6bae334f35a2cc77e45c5532652c72c 100644 (file)
 #if SVG_SUPPORT
 #include "RenderSVGImage.h"
 
+#include "Attr.h"
 #include "GraphicsContext.h"
 #include "KCanvasMaskerQuartz.h"
-#include "SVGAnimatedPreserveAspectRatio.h"
 #include "KCanvasRenderingStyle.h"
 #include "KCanvasResourcesQuartz.h"
 #include "KRenderingDevice.h"
 #include "SVGAnimatedLength.h"
+#include "SVGAnimatedPreserveAspectRatio.h"
 #include "SVGImageElement.h"
-#include "Attr.h"
-
 #include "SVGImageElement.h"
-
 #include "ksvg.h"
+#include <kxmlcore/OwnPtr.h>
 
 namespace WebCore {
 
@@ -132,13 +131,14 @@ void RenderSVGImage::paint(PaintInfo& paintInfo, int parentX, int parentY)
     KRenderingDevice* device = renderingDevice();
     KRenderingDeviceContext* context = device->currentContext();
     bool shouldPopContext = false;
-    if (!context) {
+    if (context)
+        paintInfo.p->save();
+    else {
         // Need to push a device context on the stack if empty.
         context = paintInfo.p->createRenderingDeviceContext();
         device->pushContext(context);
         shouldPopContext = true;
-    } else
-        paintInfo.p->save();
+    }
 
     context->concatCTM(QMatrix().translate(parentX, parentY));
     context->concatCTM(localTransform());
@@ -157,32 +157,35 @@ void RenderSVGImage::paint(PaintInfo& paintInfo, int parentX, int parentY)
     if (filter)
         filter->prepareFilter(boundingBox);
     
+    OwnPtr<GraphicsContext> c(device->currentContext()->createGraphicsContext());
+    PaintInfo pi = paintInfo;
+    pi.p = c.get();
+
     int x = 0, y = 0;
-    if (!shouldPaint(paintInfo, x, y))
+    if (!shouldPaint(pi, x, y))
         return;
         
     SVGImageElement *imageElt = static_cast<SVGImageElement *>(node());
         
     if (imageElt->preserveAspectRatio()->baseVal()->align() == SVG_PRESERVEASPECTRATIO_NONE)
-        RenderImage::paint(paintInfo, 0, 0);
+        RenderImage::paint(pi, 0, 0);
     else {
         FloatRect destRect(m_x, m_y, contentWidth(), contentHeight());
         FloatRect srcRect(0, 0, image()->width(), image()->height());
         adjustRectsForAspectRatio(destRect, srcRect, imageElt->preserveAspectRatio()->baseVal());
-        paintInfo.p->drawImage(image(), destRect,
-                                    srcRect.x(), srcRect.y(), srcRect.width(), srcRect.height(), 
-                                    Image::CompositeSourceOver);
+        c->drawImage(image(), destRect, srcRect);
     }
 
     if (filter)
         filter->applyFilter(boundingBox);
     
     // restore drawing state
-    if (shouldPopContext) {
+    if (!shouldPopContext)
+        paintInfo.p->restore();
+    else {
         device->popContext();
         delete context;
-    } else
-        paintInfo.p->restore();
+    }
 }
 
 FloatRect RenderSVGImage::relativeBBox(bool includeStroke) const
index 517a657c61f2f18c23acde68384f4ae1c3b10341..a73a40f9f50e490fe46c702700dced88de3447a5 100644 (file)
@@ -31,7 +31,7 @@
 #include "KRenderingDevice.h"
 #include "SVGAnimatedLengthList.h"
 #include "SVGTextElement.h"
-#include "RenderObject.h"
+#include <kxmlcore/OwnPtr.h>
 
 namespace WebCore {
 
@@ -64,13 +64,14 @@ void RenderSVGText::paint(PaintInfo& paintInfo, int parentX, int parentY)
     KRenderingDevice* device = renderingDevice();
     KRenderingDeviceContext* context = device->currentContext();
     bool shouldPopContext = false;
-    if (!context) {
-        // Need to push a device context on the stack if empty.
+    if (context)
+        paintInfo.p->save();
+    else {
+        // Need to set up KCanvas rendering if it hasn't already been done.
         context = paintInfo.p->createRenderingDeviceContext();
         device->pushContext(context);
         shouldPopContext = true;
-    } else
-        paintInfo.p->save();
+    }
     
     context->concatCTM(localTransform());
     context->concatCTM(QMatrix().translate(parentX, parentY));
@@ -90,12 +91,16 @@ void RenderSVGText::paint(PaintInfo& paintInfo, int parentX, int parentY)
     if (filter)
         filter->prepareFilter(boundingBox);
         
+    OwnPtr<GraphicsContext> c(device->currentContext()->createGraphicsContext());
+    PaintInfo pi = paintInfo;
+    pi.p = c.get();
+
     KRenderingPaintServer *fillPaintServer = KSVGPainterFactory::fillPaintServer(style(), this);
     if (fillPaintServer) {
         fillPaintServer->setPaintingText(true);
         // fillPaintServer->setActiveClient(this);
         if (fillPaintServer->setup(context, this, APPLY_TO_FILL)) {
-            RenderBlock::paint(paintInfo, 0, 0);
+            RenderBlock::paint(pi, 0, 0);
             fillPaintServer->teardown(context, this, APPLY_TO_FILL);
         }
         fillPaintServer->setPaintingText(false);
@@ -106,7 +111,7 @@ void RenderSVGText::paint(PaintInfo& paintInfo, int parentX, int parentY)
         strokePaintServer->setPaintingText(true);
         // strokePaintServer->setActiveClient(this);
         if (strokePaintServer->setup(context, this, APPLY_TO_STROKE)) {
-            RenderBlock::paint(paintInfo, 0, 0);
+            RenderBlock::paint(pi, 0, 0);
             strokePaintServer->teardown(context, this, APPLY_TO_STROKE);
         }
         strokePaintServer->setPaintingText(false);
@@ -116,11 +121,12 @@ void RenderSVGText::paint(PaintInfo& paintInfo, int parentX, int parentY)
         filter->applyFilter(boundingBox);
 
     // restore drawing state
-    if (shouldPopContext) {
+    if (!shouldPopContext)
+        paintInfo.p->restore();
+    else {
         device->popContext();
         delete context;
-    } else
-        paintInfo.p->restore();
+    }
 }
 
 bool RenderSVGText::nodeAtPoint(NodeInfo& info, int _x, int _y, int _tx, int _ty, HitTestAction hitTestAction)
index 81f380f2cc067ea2d2fd09eb59ac792561560cd3..eca7ac588211eee686d56cc2891116c5b4ba8f00 100644 (file)
@@ -45,6 +45,8 @@ public:
     
     virtual void clearPath() = 0;
     virtual void addPath(const KCanvasPath*) = 0;
+
+    virtual GraphicsContext* createGraphicsContext() = 0;
 };
 
 class KCanvasImage;
index dc171854d3209e30ff986860add0f31365aa2b97..ae8f5ee1cbbf872b7d3562dad02f36f923c1b55e 100644 (file)
@@ -37,7 +37,7 @@ public:
     KCanvasItemQuartz(RenderStyle*, SVGStyledElement*);
     virtual ~KCanvasItemQuartz() { }
     
-    virtual void drawMarkersIfNeeded(const FloatRect&, const KCanvasPath*) const;
+    virtual void drawMarkersIfNeeded(GraphicsContext*, const FloatRect&, const KCanvasPath*) const;
 };
 
 }
index d92a29b2a5203884c25271de0476dae7236da721..1b310b909db3140ee4014116746c190a0fd28e9d 100644 (file)
@@ -70,14 +70,15 @@ struct MarkerData {
 };
 
 struct DrawMarkersData {
-    DrawMarkersData(KCanvasMarker *startMarker, KCanvasMarker *midMarker, double strokeWidth);
-    
+    DrawMarkersData(GraphicsContext*, KCanvasMarker* startMarker, KCanvasMarker* midMarker, double strokeWidth);
+    GraphicsContext* context;
     int elementIndex;
     MarkerData previousMarkerData;
-    KCanvasMarker *midMarker;
+    KCanvasMarkermidMarker;
 };
 
-DrawMarkersData::DrawMarkersData(KCanvasMarker *start, KCanvasMarker *mid, double strokeWidth)
+DrawMarkersData::DrawMarkersData(GraphicsContext* c, KCanvasMarker *start, KCanvasMarker *mid, double strokeWidth)
+    : context(c)
 {
     elementIndex = 0;
     midMarker = mid;
@@ -88,7 +89,7 @@ DrawMarkersData::DrawMarkersData(KCanvasMarker *start, KCanvasMarker *mid, doubl
     previousMarkerData.type = Start;
 }
 
-void drawMarkerWithData(MarkerData &data)
+static void drawMarkerWithData(GraphicsContext* context, MarkerData &data)
 {
     if (!data.marker)
         return;
@@ -108,7 +109,7 @@ void drawMarkerWithData(MarkerData &data)
     else // (data.type == End)
         angle = inslope;
     
-    data.marker->draw(FloatRect(), data.origin.x, data.origin.y, data.strokeWidth, angle);
+    data.marker->draw(context, FloatRect(), data.origin.x, data.origin.y, data.strokeWidth, angle);
 }
 
 static inline void updateMarkerDataForElement(MarkerData &previousMarkerData, const CGPathElement *element)
@@ -133,7 +134,7 @@ static inline void updateMarkerDataForElement(MarkerData &previousMarkerData, co
     }
 }
 
-void DrawStartAndMidMarkers(void *info, const CGPathElement *element)
+static void drawStartAndMidMarkers(void *info, const CGPathElement *element)
 {
     DrawMarkersData &data = *(DrawMarkersData *)info;
 
@@ -148,7 +149,7 @@ void DrawStartAndMidMarkers(void *info, const CGPathElement *element)
 
     // Draw the marker for the previous element
     if (elementIndex != 0)
-        drawMarkerWithData(previousMarkerData);
+        drawMarkerWithData(data.context, previousMarkerData);
 
     // Update our marker data for this element
     updateMarkerDataForElement(previousMarkerData, element);
@@ -162,7 +163,7 @@ void DrawStartAndMidMarkers(void *info, const CGPathElement *element)
     data.elementIndex++;
 }
 
-void KCanvasItemQuartz::drawMarkersIfNeeded(const FloatRect& rect, const KCanvasPath *path) const
+void KCanvasItemQuartz::drawMarkersIfNeeded(GraphicsContext* context, const FloatRect& rect, const KCanvasPath *path) const
 {
     Document *doc = document();
     const SVGRenderStyle *svgStyle = style()->svgStyle();
@@ -176,14 +177,14 @@ void KCanvasItemQuartz::drawMarkersIfNeeded(const FloatRect& rect, const KCanvas
 
     double strokeWidth = KSVGPainterFactory::cssPrimitiveToLength(this, style()->svgStyle()->strokeWidth(), 1.0);
 
-    DrawMarkersData data(startMarker, midMarker, strokeWidth);
+    DrawMarkersData data(context, startMarker, midMarker, strokeWidth);
 
     CGPathRef cgPath = static_cast<const KCanvasPathQuartz*>(path)->cgPath();
-    CGPathApply(cgPath, &data, DrawStartAndMidMarkers);
+    CGPathApply(cgPath, &data, drawStartAndMidMarkers);
 
     data.previousMarkerData.marker = endMarker;
     data.previousMarkerData.type = End;
-    drawMarkerWithData(data.previousMarkerData);
+    drawMarkerWithData(context, data.previousMarkerData);
 }
 
 }
index 3c99c2d184116d2e0b5cf0a913b4d7322ce859b7..3a3660f547913ad06e53b60be45c5b1ec456d359 100644 (file)
@@ -55,6 +55,8 @@ public:
     
     virtual void clearPath();
     virtual void addPath(const KCanvasPath*);
+
+    virtual GraphicsContext* createGraphicsContext();
     
     CGContextRef cgContext() const { return m_cgContext; };
     NSGraphicsContext *nsGraphicsContext();
index 4a655a59c20cdae586f674cd0ae51177fb16b912..e42a6a102212af5e2131519b3217f0190b60c7e7 100644 (file)
@@ -28,6 +28,7 @@
 #import "KRenderingDeviceQuartz.h"
 
 #import "FoundationExtras.h"
+#import "GraphicsContext.h"
 #import "KCanvasFilterQuartz.h"
 #import "KCanvasItemQuartz.h"
 #import "KCanvasMaskerQuartz.h"
@@ -97,6 +98,11 @@ NSGraphicsContext *KRenderingDeviceContextQuartz::nsGraphicsContext()
     return m_nsGraphicsContext;
 }
 
+GraphicsContext* KRenderingDeviceContextQuartz::createGraphicsContext()
+{
+    return new GraphicsContext(m_cgContext, false, false);
+}
+
 static bool __useFilters = true;
 
 bool KRenderingDeviceQuartz::filtersEnabled()
index fc14b43590d363107abd9b50415b9755193609bd..e5ae5cb45b8d9eafa15e5dcb89237729d4ea4981 100644 (file)
@@ -37,6 +37,7 @@
 #include "cssstyleselector.h"
 #include "ksvg.h"
 #include "Attr.h"
+#include <kxmlcore/OwnPtr.h>
 
 namespace WebCore {
 
@@ -122,9 +123,10 @@ KCanvasImage *SVGMaskElement::drawMaskerContent()
     KRenderingDeviceContext *patternContext = device->contextForImage(maskImage);
     device->pushContext(patternContext);
 
+    OwnPtr<GraphicsContext> context(patternContext->createGraphicsContext());
+
     KCanvasContainer *maskContainer = static_cast<KCanvasContainer *>(renderer());
-    GraphicsContext p;
-    RenderObject::PaintInfo info(&p, IntRect(), PaintPhaseForeground, 0, 0);
+    RenderObject::PaintInfo info(context.get(), IntRect(), PaintPhaseForeground, 0, 0);
     maskContainer->setDrawsContents(true);
     maskContainer->paint(info, 0, 0);
     maskContainer->setDrawsContents(false);
index efcdda17b81ba647c068fbe976379481501a6b30..cb33b14bfac06ee9cf14c4a58e9b18f0e61da6c8 100644 (file)
@@ -24,8 +24,9 @@
 #if SVG_SUPPORT
 #include "SVGPatternElement.h"
 
-#include "GraphicsContext.h"
+#include "Attr.h"
 #include "Document.h"
+#include "GraphicsContext.h"
 #include "KCanvasContainer.h"
 #include "KCanvasCreator.h"
 #include "KCanvasImage.h"
@@ -45,7 +46,6 @@
 #include "SVGTransformList.h"
 #include "SVGTransformable.h"
 #include "ksvg.h"
-#include "Attr.h"
 
 namespace WebCore {
 
@@ -227,6 +227,8 @@ void SVGPatternElement::drawPatternContentIntoTile(const SVGPatternElement *targ
     m_paintServer->setPatternTransform(patternTransformMatrix);
     m_paintServer->setTile(m_tile);
 
+    OwnPtr<GraphicsContext> context(patternContext->createGraphicsContext());
+
     for(Node *n = target->firstChild(); n != 0; n = n->nextSibling())
     {
         SVGElement *elem = svg_dynamic_cast(n);
@@ -268,9 +270,9 @@ void SVGPatternElement::drawPatternContentIntoTile(const SVGPatternElement *targ
         }
 #endif
 
-        GraphicsContext p;
-        RenderObject::PaintInfo info(&p, IntRect(), PaintPhaseForeground, 0, 0);
+        RenderObject::PaintInfo info(context.get(), IntRect(), PaintPhaseForeground, 0, 0);
         item->paint(info, 0, 0);
+
 #if 0
         if(savedContext)
             e->pushAttributeContext(savedContext);
index b49b5be8704f2d89a0ff90abe5be193f296b916d..0014a8151c4e8c27830a68debe8ea017c1a9597e 100644 (file)
@@ -2721,14 +2721,11 @@ void Frame::adjustPageHeight(float *newBottom, float oldTop, float oldBottom, fl
 {
     RenderCanvas *root = static_cast<RenderCanvas *>(document()->renderer());
     if (root) {
-        // Use a printer device, with painting disabled for the pagination phase
-        GraphicsContext painter(true);
-        painter.setPaintingDisabled(true);
-        
+        // Use a context with painting disabled but with "for printer" set to true.
+        GraphicsContext context(0, false, true);
         root->setTruncatedAt((int)floorf(oldBottom));
-        IntRect dirtyRect(0, (int)floorf(oldTop),
-                        root->docWidth(), (int)ceilf(oldBottom-oldTop));
-        root->layer()->paint(&painter, dirtyRect);
+        IntRect dirtyRect(0, (int)floorf(oldTop), root->docWidth(), (int)ceilf(oldBottom - oldTop));
+        root->layer()->paint(&context, dirtyRect);
         *newBottom = root->bestTruncatedAt();
         if (*newBottom == 0)
             *newBottom = oldBottom;
similarity index 60%
rename from WebCore/platform/Brush.h
rename to WebCore/platform/CompositeOperator.cpp
index 612a9f2dd04adc9d0d6c4edcf506d9730ae3f7a5..eacc071a10f6489dcb860d395739b8c2f5085a7c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2003 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef BRUSH_H_
-#define BRUSH_H_
+#include "config.h"
+#include "CompositeOperator.h"
 
-#include "Color.h"
+#include "PlatformString.h"
 
 namespace WebCore {
 
-class Brush {
-public:    
-    enum BrushStyle {
-        NoBrush,
-        SolidPattern,
-    };
-
-    Brush(const Color &c = Color::black, BrushStyle style = SolidPattern)
-        : brushColor(c), brushStyle(style) { }
-
-    const Color &color() const { return brushColor; }
-    void setColor(const Color &c) { brushColor = c; }
-    BrushStyle style() const { return brushStyle; }
-    void setStyle(BrushStyle s) { brushStyle = s; }
-    
-    bool operator==(const Brush &b) const { return brushColor == b.brushColor && brushStyle == b.brushStyle; }
-    bool operator!=(const Brush &b) const { return !(*this == b); }
-
-private:
-    Color brushColor;
-    BrushStyle brushStyle;
+static const char* const compositeOperatorNames[] = {
+    "clear",
+    "copy",
+    "source-over",
+    "source-in",
+    "source-out",
+    "source-atop",
+    "destination-over",
+    "destination-in",
+    "destination-out",
+    "destination-atop",
+    "xor",
+    "darker",
+    "highlight",
+    "lighter"
 };
 
+bool parseCompositeOperator(const String& s, CompositeOperator& op)
+{
+    const int num = sizeof(compositeOperatorNames) / sizeof(compositeOperatorNames[0]);
+    for (int i = 0; i < num; i++)
+        if (s == compositeOperatorNames[i]) {
+            op = static_cast<CompositeOperator>(i);
+            return true;
+        }
+    return false;
 }
 
-#endif
+String compositeOperatorName(CompositeOperator op)
+{
+    return compositeOperatorNames[op];
+}
+
+}
diff --git a/WebCore/platform/CompositeOperator.h b/WebCore/platform/CompositeOperator.h
new file mode 100644 (file)
index 0000000..7625647
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef CompositeOperator_h
+#define CompositeOperator_h
+
+namespace WebCore {
+
+    class String;
+
+    // Note: These constants exactly match the NSCompositeOperator constants of
+    // AppKit on Mac OS X. If that's ever changed, we'll need to change the Mac
+    // platform code to map one to the other.
+    enum CompositeOperator {
+        CompositeClear,
+        CompositeCopy,
+        CompositeSourceOver,
+        CompositeSourceIn,
+        CompositeSourceOut,
+        CompositeSourceAtop,
+        CompositeDestinationOver,
+        CompositeDestinationIn,
+        CompositeDestinationOut,
+        CompositeDestinationAtop,
+        CompositeXOR,
+        CompositePlusDarker,
+        CompositeHighlight,
+        CompositePlusLighter
+    };
+
+    String compositeOperatorName(CompositeOperator);
+    bool parseCompositeOperator(const String&, CompositeOperator&);
+
+}
+
+#endif
index 2576cb04a5459de2d58be8565cfa4da224517874..1804bf290f0bec62b41934c0fc81d5b270c5cfec 100644 (file)
@@ -38,6 +38,7 @@ namespace WebCore {
 
 class FontDataSet;
 class GraphicsContext;
+class IntPoint;
 class IntRect;
 
 enum Pitch { UnknownPitch, FixedPitch, VariablePitch };
@@ -70,21 +71,21 @@ public:
     
     void update() const;
 
-    void drawText(const GraphicsContext*, int x, int y, int tabWidth, int xpos,
+    void drawText(GraphicsContext*, const IntPoint&, int tabWidth, int xpos,
                   const QChar*, int len, int from, int to, int toAdd, 
                   TextDirection, bool visuallyOrdered) const;
-    void drawHighlightForText(const GraphicsContext*, int x, int y, int h, int tabWidth, int xpos,
+    void drawHighlightForText(GraphicsContext*, const IntPoint&, int h, int tabWidth, int xpos,
                               const QChar*, int len, int from, int to, int toAdd, 
                               TextDirection d, bool visuallyOrdered, const Color& backgroundColor) const;
-    void drawLineForText(const GraphicsContext*, int x, int y, int yOffset, int width) const;
-    void drawLineForMisspelling(const GraphicsContext*, int x, int y, int width) const;
-    int misspellingLineThickness(const GraphicsContext*) const;
+    void drawLineForText(GraphicsContext*, const IntPoint&, int yOffset, int width) const;
+    void drawLineForMisspelling(GraphicsContext*, const IntPoint&, int width) const;
+    int misspellingLineThickness(GraphicsContext*) const;
 
     float floatWidth(const QChar*, int slen, int pos, int len, int tabWidth, int xpos, bool runRounding = true) const;
     
     int checkSelectionPoint(const QChar*, int slen, int pos, int len, int toAdd, int tabWidth, int xpos,
         int x, TextDirection, bool visuallyOrdered, bool includePartialGlyphs) const;
-    IntRect selectionRectForText(int x, int y, int h, int tabWidth, int xpos, 
+    IntRect selectionRectForText(const IntPoint&, int h, int tabWidth, int xpos, 
         const QChar*, int slen, int pos, int len, int width,
         bool rtl, bool visuallyOrdered = false, int from = -1, int to = -1) const;
     
index 22e2bfa6cfa468175383240417ed1f4480c95321..255181638cc55a0c746abf33e839e84246fd28b5 100644 (file)
 #include "IntRect.h"
 #include "Widget.h"
 
+using namespace std;
+
 namespace WebCore {
 
 struct GraphicsContextState {
-    GraphicsContextState() : paintingDisabled(false) { }
+    GraphicsContextState() : fillColor(Color::black), paintingDisabled(false) { }
     Font font;
     Pen pen;
-    Brush brush;
+    RGBA32 fillColor;
     bool paintingDisabled;
 };
         
@@ -133,26 +135,14 @@ void GraphicsContext::setPen(RGBA32 rgb)
     m_common->state.pen.setWidth(0);
 }
 
-void GraphicsContext::setBrush(const Brush& brush)
-{
-    m_common->state.brush = brush;
-}
-
-void GraphicsContext::setBrush(Brush::BrushStyle style)
+void GraphicsContext::setFillColor(RGBA32 color)
 {
-    m_common->state.brush.setStyle(style);
-    m_common->state.brush.setColor(Color::black);
+    m_common->state.fillColor = color;
 }
 
-void GraphicsContext::setBrush(RGBA32 rgb)
+const RGBA32 GraphicsContext::fillColor() const
 {
-    m_common->state.brush.setStyle(Brush::SolidPattern);
-    m_common->state.brush.setColor(rgb);
-}
-
-const Brush& GraphicsContext::brush() const
-{
-    return m_common->state.brush;
+    return m_common->state.fillColor;
 }
 
 void GraphicsContext::setUsesInactiveTextBackgroundColor(bool u)
@@ -191,87 +181,86 @@ bool GraphicsContext::printing() const
     return m_common->m_isForPrinting;
 }
 
-void GraphicsContext::drawImageAtPoint(Image* image, const IntPoint& p, Image::CompositeOperator compositeOperator)
+void GraphicsContext::drawImage(Image* image, const IntPoint& p, CompositeOperator op)
 {        
-    drawImage(image, p, 0, 0, -1, -1, compositeOperator);
+    drawImage(image, p, IntRect(0, 0, -1, -1), op);
 }
 
-void GraphicsContext::drawImageInRect(Image* image, const IntRect& r, Image::CompositeOperator compositeOperator)
+void GraphicsContext::drawImage(Image* image, const IntRect& r, CompositeOperator op)
 {
-    drawImage(image, r, 0, 0, -1, -1, compositeOperator);
+    drawImage(image, r, IntRect(0, 0, -1, -1), op);
 }
 
-void GraphicsContext::drawImage(Image* image, const IntPoint& dest,
-                         int sx, int sy, int sw, int sh, Image::CompositeOperator compositeOperator, void* context)
+void GraphicsContext::drawImage(Image* image, const IntPoint& dest, const IntRect& srcRect, CompositeOperator op)
 {
-    drawImage(image, IntRect(dest, IntSize(sw, sh)), sx, sy, sw, sh, compositeOperator, context);
+    drawImage(image, IntRect(dest, srcRect.size()), srcRect, op);
 }
 
-void GraphicsContext::drawImage(Image* image, const IntRect& dest,
-                         int sx, int sy, int sw, int sh, Image::CompositeOperator compositeOperator, void* context)
+void GraphicsContext::drawImage(Image* image, const IntRect& dest, const IntRect& srcRect, CompositeOperator op)
 {
-    drawImage(image, FloatRect(dest), (float)sx, (float)sy, (float)sw, (float)sh, compositeOperator, context);
+    drawImage(image, FloatRect(dest), srcRect, op);
 }
 
 // FIXME: We should consider removing this function and having callers just call the lower-level drawText directly.
 // FIXME: The int parameter should change to a HorizontalAlignment parameter.
 // FIXME: HorizontalAlignment should be moved into a separate header so it's not in Widget.h.
 // FIXME: We should consider changing this function to take a character pointer and length instead of a DeprecatedString.
-void GraphicsContext::drawText(int x, int y, int horizontalAlignment, const DeprecatedString& deprecatedString)
+void GraphicsContext::drawText(const IntPoint& point, int horizontalAlignment, const DeprecatedString& str)
 {
     if (paintingDisabled())
         return;
 
+    IntPoint p = point;
     if (horizontalAlignment == AlignRight)
-        x -= font().width(deprecatedString.unicode(), deprecatedString.length(), 0, 0);
-    drawText(x, y, 0, 0, deprecatedString.unicode(), deprecatedString.length(), 0, deprecatedString.length(), 0);
+        p.setX(p.x() - font().width(str.unicode(), str.length(), 0, 0));
+    drawText(p, 0, 0, str.unicode(), str.length(), 0, str.length(), 0);
 }
 
-void GraphicsContext::drawText(int x, int y, int tabWidth, int xpos, const QChar *str, int slen, int pos, int len, int toAdd,
+void GraphicsContext::drawText(const IntPoint& point, int tabWidth, int xpos, const QChar *str, int slen, int pos, int len, int toAdd,
                                TextDirection d, bool visuallyOrdered, int from, int to)
 {
     if (paintingDisabled())
         return;
 
-    int length = std::min(slen - pos, len);
+    int length = min(slen - pos, len);
     if (length <= 0)
         return;
     
-    font().drawText(this, x, y, tabWidth, xpos, str + pos, length, from, to, toAdd, d, visuallyOrdered);
+    font().drawText(this, point, tabWidth, xpos, str + pos, length, from, to, toAdd, d, visuallyOrdered);
 }
 
-void GraphicsContext::drawHighlightForText(int x, int y, int h, int tabWidth, int xpos, const QChar *str, int slen, int pos, int len, int toAdd,
+void GraphicsContext::drawHighlightForText(const IntPoint& point, int h, int tabWidth, int xpos, const QChar *str, int slen, int pos, int len, int toAdd,
                                            TextDirection d, bool visuallyOrdered, int from, int to, const Color& backgroundColor)
 {
     if (paintingDisabled())
         return;
         
-    int length = std::min(slen - pos, len);
+    int length = min(slen - pos, len);
     if (length <= 0)
         return;
 
-    return font().drawHighlightForText(this, x, y, h, tabWidth, xpos, str + pos, length, from, to,
+    return font().drawHighlightForText(this, point, h, tabWidth, xpos, str + pos, length, from, to,
                                        toAdd, d, visuallyOrdered, backgroundColor);
 }
 
-void GraphicsContext::drawLineForText(int x, int y, int yOffset, int width)
+void GraphicsContext::drawLineForText(const IntPoint& point, int yOffset, int width)
 {
     if (paintingDisabled())
         return;
 
-    return font().drawLineForText(this, x, y, yOffset, width);
+    return font().drawLineForText(this, point, yOffset, width);
 }
 
 
-void GraphicsContext::drawLineForMisspelling(int x, int y, int width)
+void GraphicsContext::drawLineForMisspelling(const IntPoint& point, int width)
 {
     if (paintingDisabled())
         return;
 
-    return font().drawLineForMisspelling(this, x, y, width);
+    return font().drawLineForMisspelling(this, point, width);
 }
 
-int GraphicsContext::misspellingLineThickness() const
+int GraphicsContext::misspellingLineThickness()
 {
     return font().misspellingLineThickness(this);
 }
@@ -313,4 +302,47 @@ const Vector<IntRect>& GraphicsContext::focusRingRects() const
     return m_common->m_focusRingRects;
 }
 
+void GraphicsContext::drawImage(Image* image, const FloatRect& dest, const FloatRect& src, CompositeOperator op)
+{
+    if (paintingDisabled())
+        return;
+
+    float tsw = src.width();
+    float tsh = src.height();
+    float tw = dest.width();
+    float th = dest.height();
+        
+    if (tsw == -1)
+        tsw = image->width();
+    if (tsh == -1)
+        tsh = image->height();
+
+    if (tw == -1)
+        tw = image->width();
+    if (th == -1)
+        th = image->height();
+
+    image->draw(this, FloatRect(dest.location(), FloatSize(tw, th)), FloatRect(src.location(), FloatSize(tsw, tsh)), op);
+}
+
+void GraphicsContext::drawTiledImage(Image* image, const IntRect& rect, const IntPoint& srcPoint, const IntSize& tileSize)
+{
+    if (paintingDisabled())
+        return;
+
+    image->drawTiled(this, rect, srcPoint, tileSize);
+}
+
+void GraphicsContext::drawTiledImage(Image* image, const IntRect& dest, const IntRect& srcRect, Image::TileRule hRule, Image::TileRule vRule)
+{
+    if (paintingDisabled())
+        return;
+
+    if (hRule == Image::StretchTile && vRule == Image::StretchTile)
+        // Just do a scale.
+        return drawImage(image, dest, srcRect);
+
+    image->drawTiled(this, dest, srcRect, hRule, vRule);
+}
+
 }
index 432ed090dc52eaa02825435a706a05d82980a2ab..9da7ecf5e4afc4d830c655e9bf81bbd3ff64baff 100644 (file)
 #ifndef GraphicsContext_h
 #define GraphicsContext_h
 
-#include "Brush.h"
+#include "FloatRect.h"
 #include "Image.h"
+#include "IntRect.h"
 #include "Pen.h"
 #include "TextDirection.h"
 #include <kxmlcore/Noncopyable.h>
 
 #if __APPLE__
+#if __OBJC__
+@class NSGraphicsContext;
+#else
+class NSGraphicsContext;
+#endif
 typedef struct CGContext* CGContextRef;
 #endif
 
 #if WIN32
-typedef struct HDC__ *HDC;
+typedef struct HDC__HDC;
 typedef struct _cairo cairo_t;
 #endif
 
@@ -53,27 +59,16 @@ namespace WebCore {
     class IntPointArray;
 
 #if SVG_SUPPORT
-    class KRenderingDevice;
     class KRenderingDeviceContext;
 #endif
 
+#if __APPLE__
+    CGContextRef currentCGContext();
+    void setCompositeOperation(CGContextRef, CompositeOperator);
+#endif
+
     class GraphicsContext : Noncopyable {
     public:
-        GraphicsContext();
-#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);
-#endif
-        GraphicsContext(bool forPrinting);
         ~GraphicsContext();
        
         const Font& font() const;
@@ -84,10 +79,8 @@ namespace WebCore {
         void setPen(Pen::PenStyle);
         void setPen(RGBA32);
         
-        const Brush& brush() const;
-        void setBrush(const Brush&);
-        void setBrush(Brush::BrushStyle);
-        void setBrush(RGBA32);
+        const RGBA32 fillColor() const;
+        void setFillColor(RGBA32);
 
         void save();
         void restore();
@@ -98,47 +91,36 @@ namespace WebCore {
         void drawArc(int, int, int, int, int, int);
         void drawConvexPolygon(const IntPointArray&);
 
-        void fillRect(const IntRect&, const Brush&);
-
-        void drawImageAtPoint(Image*, const IntPoint&, Image::CompositeOperator = Image::CompositeSourceOver);
-        void drawImageInRect(Image*, const IntRect&, Image::CompositeOperator = Image::CompositeSourceOver);
-
-        void drawImage(Image*, const IntPoint&, 
-            int sx = 0, int sy = 0, int sw = -1, int sh = -1,
-            Image::CompositeOperator = Image::CompositeSourceOver, 
-            void* nativeData = 0);
-        void drawImage(Image*, const IntRect&,
-            int sx = 0, int sy = 0, int sw = -1, int sh = -1,
-            Image::CompositeOperator = Image::CompositeSourceOver, 
-            void* nativeData = 0);
-        void drawImage(Image*, const FloatRect&,
-            float sx = 0, float sy = 0, float sw = -1, float sh = -1,
-            Image::CompositeOperator = Image::CompositeSourceOver, 
-            void* nativeData = 0);
-        void drawTiledImage(Image*, const IntRect& destRect, const IntPoint& srcPoint, const IntSize& tileSize, void* nativeData = 0);
-        void drawScaledAndTiledImage(Image*, const IntRect&, int, int, int, int, 
-            Image::TileRule hRule = Image::StretchTile, Image::TileRule vRule = Image::StretchTile,
-            void* nativeData = 0);
+        void fillRect(const IntRect&, const Color&);
+
+        void drawImage(Image*, const IntPoint&, CompositeOperator = CompositeSourceOver);
+        void drawImage(Image*, const IntRect&, CompositeOperator = CompositeSourceOver);
+        void drawImage(Image*, const IntPoint& destPoint, const IntRect& srcRect, CompositeOperator = CompositeSourceOver);
+        void drawImage(Image*, const IntRect& destRect, const IntRect& srcRect, CompositeOperator = CompositeSourceOver);
+        void drawImage(Image*, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1),
+            CompositeOperator = CompositeSourceOver);
+        void drawTiledImage(Image*, const IntRect& destRect, const IntPoint& srcPoint, const IntSize& tileSize);
+        void drawTiledImage(Image*, const IntRect& destRect, const IntRect& srcRect, 
+            Image::TileRule hRule = Image::StretchTile, Image::TileRule vRule = Image::StretchTile);
 
         void addClip(const IntRect&);
         void addRoundedRectClip(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight);
 
-#if __APPLE__
+        // Functions to work around bugs in focus ring clipping on Mac.
         void setFocusRingClip(const IntRect&);
         void clearFocusRingClip();
-#endif
 
-        void drawText(int x, int y, int alignmentFlags, const DeprecatedString&);
-        void drawHighlightForText(int x, int y, int h, int tabWidth, int xpos,
+        void drawText(const IntPoint&, int alignmentFlags, const DeprecatedString&);
+        void drawHighlightForText(const IntPoint&, int h, int tabWidth, int xpos,
             const QChar*, int slen, int pos, int len, int toAdd,
-            TextDirection d, bool visuallyOrdered,
+            TextDirection, bool visuallyOrdered,
             int from, int to, const Color& backgroundColor);
-        void drawText(int x, int y, int tabWidth, int xpos,
+        void drawText(const IntPoint&, int tabWidth, int xpos,
             const QChar*, int slen, int pos, int len, int toAdd,
-            TextDirection = LTR, bool visuallyOrdered = false, int from = -1, int to = -1);
-        void drawLineForText(int x, int y, int yOffset, int width);
-        void drawLineForMisspelling(int x, int y, int width);
-        int misspellingLineThickness() const;
+            TextDirection = LTR, bool visuallyOrdered = false, int from = -1, int to = -1);
+        void drawLineForText(const IntPoint&, int yOffset, int width);
+        void drawLineForMisspelling(const IntPoint&, int width);
+        int misspellingLineThickness();
 
         Color selectedTextBackgroundColor() const;
         void setUsesInactiveTextBackgroundColor(bool);
@@ -153,36 +135,44 @@ namespace WebCore {
         void beginTransparencyLayer(float opacity);
         void endTransparencyLayer();
 
-        void setShadow(int x, int y, int blur, const Color&);
+        void setShadow(const IntSize&, int blur, const Color&);
         void clearShadow();
 
         void initFocusRing(int width, int offset);
         void addFocusRingRect(const IntRect&);
         void drawFocusRing(const Color&);
         void clearFocusRing();
-    
-#if __APPLE__
-        static CGContextRef currentCGContext();
-        static int getCompositeOperation(CGContextRef);
-        static void setCompositeOperation(CGContextRef, const String& operation);
-        static void setCompositeOperation(CGContextRef, int operation);
+
+        bool printing() const;
+
+#if SVG_SUPPORT
+        KRenderingDeviceContext* createRenderingDeviceContext();
 #endif
 
 #if __APPLE__
-        CGContextRef platformContext() const { return currentCGContext(); }
+        GraphicsContext(NSGraphicsContext*);
+        GraphicsContext(CGContextRef, bool flipText, bool forPrinting);
+        CGContextRef platformContext() const;
 #endif
+
 #if WIN32
-        cairo_t* platformContext() const;
-#endif
+        // 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);
 
-#if SVG_SUPPORT
-        KRenderingDeviceContext* createRenderingDeviceContext();
-#endif
+        // 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);
 
-        bool printing() const;
+        cairo_t* platformContext() const;
+#endif
 
-private:
-        void setColorFromBrush();
+    private:
+        void setColorFromFillColor();
         void setColorFromPen();
         
         void savePlatformState();
index bbe5b82a629f71e2a7db28a4586b8c2039e86aad..2225bfda47171421a006059d9de885adb4701663 100644 (file)
@@ -302,39 +302,4 @@ int Image::height() const
     return size().height();
 }
 
-const int NUM_COMPOSITE_OPERATORS = 14;
-
-struct CompositeOperatorEntry
-{
-    const char *name;
-    Image::CompositeOperator value;
-};
-
-struct CompositeOperatorEntry compositeOperators[NUM_COMPOSITE_OPERATORS] = {
-    { "clear", Image::CompositeClear },
-    { "copy", Image::CompositeCopy },
-    { "source-over", Image::CompositeSourceOver },
-    { "source-in", Image::CompositeSourceIn },
-    { "source-out", Image::CompositeSourceOut },
-    { "source-atop", Image::CompositeSourceAtop },
-    { "destination-over", Image::CompositeDestinationOver },
-    { "destination-in", Image::CompositeDestinationIn },
-    { "destination-out", Image::CompositeDestinationOut },
-    { "destination-atop", Image::CompositeDestinationAtop },
-    { "xor", Image::CompositeXOR },
-    { "darker", Image::CompositePlusDarker },
-    { "highlight", Image::CompositeHighlight },
-    { "lighter", Image::CompositePlusLighter }
-};
-
-Image::CompositeOperator Image::compositeOperatorFromString(const String& s)
-{
-    CompositeOperator op = CompositeSourceOver;
-    if (!s.isEmpty())
-        for (int i = 0; i < NUM_COMPOSITE_OPERATORS; i++)
-            if (equalIgnoringCase(s, compositeOperators[i].name))
-                return compositeOperators[i].value;
-    return op;
-}
-
 }
index 4d5e848f0e4d466daf5240191c0d337253240bf8..32e385720a072d1da97eecefe6ae0cc5f8caef28 100644 (file)
 #ifndef IMAGE_H_
 #define IMAGE_H_
 
+#include "CompositeOperator.h"
 #include "DeprecatedArray.h"
 #include "ImageSource.h"
 #include "IntSize.h"
 #include "FloatSize.h"
+#include <kxmlcore/Noncopyable.h>
 #include <kxmlcore/Vector.h>
 
 #if __APPLE__
@@ -55,6 +57,7 @@ namespace WebCore {
 
 class FloatPoint;
 class FloatRect;
+class GraphicsContext;
 class IntRect;
 class IntSize;
 class String;
@@ -102,7 +105,8 @@ struct FrameData {
 // Image Class
 // =================================================
 
-class Image {
+class Image : Noncopyable {
+    friend class GraphicsContext;
 public:
     Image();
     Image(ImageAnimationObserver* observer, bool isPDF = false);
@@ -137,53 +141,25 @@ public:
     // Typically the CachedImage that owns us.
     ImageAnimationObserver* animationObserver() const { return m_animationObserver; }
 
-    // Note: These constants exactly match the NSCompositeOperator constants of AppKit.
-    enum CompositeOperator {
-        CompositeClear,
-        CompositeCopy,
-        CompositeSourceOver,
-        CompositeSourceIn,
-        CompositeSourceOut,
-        CompositeSourceAtop,
-        CompositeDestinationOver,
-        CompositeDestinationIn,
-        CompositeDestinationOut,
-        CompositeDestinationAtop,
-        CompositeXOR,
-        CompositePlusDarker,
-        CompositeHighlight,
-        CompositePlusLighter
-    };
-
     enum TileRule { StretchTile, RoundTile, RepeatTile };
 
-    static CompositeOperator compositeOperatorFromString(const String&);
-
-    // Drawing routines.
-    void drawInRect(const FloatRect& dstRect, const FloatRect& srcRect,
-                    CompositeOperator compositeOp, void* context);
-    void tileInRect(const FloatRect& destRect, const FloatPoint& point,
-                    const FloatSize& tileSize, void* context);
-    void scaleAndTileInRect(const FloatRect& dstRect, const FloatRect& srcRect,
-                            TileRule hRule, TileRule vRule, void* context);
-
 #if __APPLE__
-    // Apple Image accessors for native formats.
+    // Accessors for native image formats.
     CGImageRef getCGImageRef();
     NSImage* getNSImage();
     CFDataRef getTIFFRepresentation();
-    
+
     // PDF
     void setIsPDF() { m_isPDF = true; }
-    
+
 private:
-    void checkForSolidColor(CGImageRef image);
+    void checkForSolidColor(CGImageRef);
 #endif
 
 private:
-    // We do not allow images to be assigned to or copied.
-    Image(const Image&);
-    Image &operator=(const Image&);
+    void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator);
+    void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatPoint& srcPoint, const FloatSize& tileSize);
+    void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, TileRule hRule, TileRule vRule);
 
     // Decodes and caches a frame. Never accessed except internally.
     void cacheFrame(size_t index);
index cb3f64dc6d9bccc4e98cc18826b0e2b8a85e6000..8fc94bee60997db1805a7ec8dc658ac9f6fa73a6 100644 (file)
@@ -114,8 +114,8 @@ namespace WebCore {
 
         virtual void populate() {}
 
-        void lockDrawingFocus();
-        void unlockDrawingFocus();
+        GraphicsContext* lockDrawingFocus();
+        void unlockDrawingFocus(GraphicsContext*);
         void enableFlushDrawing();
         void disableFlushDrawing();
 
index 6b41be2e72608ac3910e08f3a023bb8671aeda18..611d8205b33f641c19cad6221900e9dbe555d943 100644 (file)
@@ -121,8 +121,8 @@ void GraphicsContext::drawRect(const IntRect& rect)
         return;
     
     cairo_t* context = m_data->context;
-    if (brush().style() != Brush::NoBrush)
-        fillRectSourceOver(context, rect, brush().color());
+    if (fillColor() & 0xFF000000)
+        fillRectSourceOver(context, rect, fillColor());
 
     if (pen().style() != Pen::NoPen) {
         setColorFromPen();
@@ -134,9 +134,9 @@ void GraphicsContext::drawRect(const IntRect& rect)
     }
 }
 
-void GraphicsContext::setColorFromBrush()
+void GraphicsContext::setColorFromFillColor()
 {
-    setColor(m_data->context, brush().color());
+    setColor(m_data->context, fillColor());
 }
   
 void GraphicsContext::setColorFromPen()
@@ -283,8 +283,8 @@ void GraphicsContext::drawEllipse(const IntRect& rect)
     cairo_arc(context, 0., 0., 1., 0., 2 * M_PI);
     cairo_restore(context);
 
-    if (brush().style() != Brush::NoBrush) {
-        setColorFromBrush();
+    if (fillColor() & 0xFF000000) {
+        setColorFromFillColor();
         cairo_fill(context);
     }
     if (pen().style() != Pen::NoPen) {
@@ -298,7 +298,7 @@ void GraphicsContext::drawEllipse(const IntRect& rect)
 }
 
 void GraphicsContext::drawArc(int x, int y, int w, int h, int a, int alen)
-{ 
+{
     // Only supports arc on circles.  That's all khtml needs.
     ASSERT(w == h);
 
@@ -336,8 +336,8 @@ void GraphicsContext::drawConvexPolygon(const IntPointArray& points)
         cairo_line_to(context, points[i].x(), points[i].y());
     cairo_close_path(context);
 
-    if (brush().style() != Brush::NoBrush) {
-        setColorFromBrush();
+    if (fillColor() & 0xFF000000) {
+        setColorFromFillColor();
         cairo_set_fill_rule(context, CAIRO_FILL_RULE_EVEN_ODD);
         cairo_fill(context);
     }
@@ -350,59 +350,6 @@ void GraphicsContext::drawConvexPolygon(const IntPointArray& points)
     cairo_restore(context);
 }
 
-void GraphicsContext::drawImage(Image* image, const FloatRect& destRect, 
-                              float sx, float sy, float sw, float sh, Image::CompositeOperator compositeOperator, void* context)
-{
-    if (!context)
-        context = m_data->context;
-
-    if (paintingDisabled())
-        return;
-
-    float tsw = sw;
-    float tsh = sh;
-    FloatRect dest = destRect;
-            
-    if (tsw == -1)
-        tsw = image->width();
-    if (tsh == -1)
-        tsh = image->height();
-
-    if (dest.width() == -1)
-        dest.setWidth(image->width());
-    if (dest.height() == -1)
-        dest.setHeight(image->height());
-
-    image->drawInRect(dest, FloatRect(sx, sy, tsw, tsh), compositeOperator, context);
-}
-
-void GraphicsContext::drawTiledImage(Image* image, const IntRect& dest, const IntPoint& srcPoint, const IntSize& tileSize, void* context)
-{
-    if (!context)
-        context = m_data->context;
-
-    if (paintingDisabled())
-        return;
-    
-    image->tileInRect(dest, srcPoint, tileSize, context);
-}
-
-void GraphicsContext::drawScaledAndTiledImage(Image* image, const IntRect& dest, int sx, int sy, int sw, int sh, 
-    Image::TileRule hRule, Image::TileRule vRule, void* context)
-{
-    if (!context)
-        context = m_data->context;
-
-    if (paintingDisabled())
-        return;
-
-    if (hRule == Image::StretchTile && vRule == Image::StretchTile)
-        // Just do a scale.
-        return drawImage(image, dest, sx, sy, sw, sh, Image::CompositeSourceOver, context);
-
-    image->scaleAndTileInRect(dest, FloatRect(sx, sy, sw, sh), hRule, vRule, context);
-}
-
 void GraphicsContext::fillRect(const IntRect& rect, const Brush& brush)
 {
     if (paintingDisabled())
@@ -446,4 +393,12 @@ void GraphicsContext::drawFocusRing(const Color& color)
     cairo_stroke(m_data->context);
 }
 
+void GraphicsContext::setFocusRingClip(const IntRect&)
+{
+}
+
+void GraphicsContext::clearFocusRingClip()
+{
+}
+
 }
index 9fd69877ebbf02800a071e021da9e161c8afd407..21baf990f5b06fb5c5b3c9635b126b2b174732fe 100644 (file)
@@ -71,30 +71,24 @@ bool Image::supportsType(const String& type)
 }
 
 // Drawing Routines
-static cairo_t* graphicsContext(void* context)
-{
-    // FIXME: If there is no context do we have some way of getting the current one?
-    return (cairo_t*)context;
-}
 
-static void setCompositingOperation(cairo_t* context, Image::CompositeOperator op, bool hasAlpha)
+static void setCompositingOperation(cairo_t* context, CompositeOperator op, bool hasAlpha)
 {
     // FIXME: Add support for more operators.
     // FIXME: This should really move to be a graphics context function once we have
     // a C++ abstraction for GraphicsContext.
-    if (op == Image::CompositeSourceOver && !hasAlpha)
-        op = Image::CompositeCopy;
+    if (op == CompositeSourceOver && !hasAlpha)
+        op = CompositeCopy;
 
-    if (op == Image::CompositeCopy)
+    if (op == CompositeCopy)
         cairo_set_operator(context, CAIRO_OPERATOR_SOURCE);
     else
         cairo_set_operator(context, CAIRO_OPERATOR_OVER);
 }
 
-void Image::drawInRect(const FloatRect& dst, const FloatRect& src,
-                       CompositeOperator compositeOp, void* ctxt)
+void Image::draw(GraphicsContext* ctxt, const FloatRect& dst, const FloatRect& src, CompositeOperator op)
 {
-    cairo_t* context = graphicsContext(ctxt);
+    cairo_t* context = ctxt->platformContext();
 
     if (!m_source.initialized())
         return;
@@ -110,7 +104,7 @@ void Image::drawInRect(const FloatRect& dst, const FloatRect& src,
     cairo_save(context);
 
     // Set the compositing operation.
-    setCompositingOperation(context, compositeOp, frameHasAlphaAtIndex(m_currentFrame));
+    setCompositingOperation(context, op, frameHasAlphaAtIndex(m_currentFrame));
     
     // If we're drawing a sub portion of the image or scaling then create
     // a pattern transformation on the image and draw the transformed pattern.
@@ -133,7 +127,7 @@ void Image::drawInRect(const FloatRect& dst, const FloatRect& src,
 
 }
 
-void Image::tileInRect(const FloatRect& dstRect, const FloatPoint& srcPoint, const FloatSize& tileSize, void* ctxt)
+void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatPoint& srcPoint, const FloatSize& tileSize)
 {
     if (!m_source.initialized())
         return;
@@ -180,20 +174,19 @@ void Image::tileInRect(const FloatRect& dstRect, const FloatPoint& srcPoint, con
 
     // If the single image draw covers the whole area, then just draw once.
     if (dstTileRect.contains(dstRect)) {
-        drawInRect(dstRect,
-                   FloatRect(srcX * scaleX, srcY * scaleY, dstRect.width() * scaleX, dstRect.height() * scaleY),
-                   Image::CompositeSourceOver,
-                   ctxt);
+        draw(ctxt, dstRect,
+             FloatRect(srcX * scaleX, srcY * scaleY, dstRect.width() * scaleX, dstRect.height() * scaleY),
+             CompositeSourceOver);
         return;
     }
 
     // We have to tile.
-    cairo_t* context = graphicsContext(ctxt);
+    cairo_t* context = ctxt->platformContext();
 
     cairo_save(context);
 
     // Set the compositing operation.
-    // FIXME: This should be part of the tileInRect API.
+    // FIXME: This should be part of the drawTiled API.
     setCompositingOperation(context, CompositeSourceOver, frameHasAlphaAtIndex(m_currentFrame));
 
     cairo_translate(context, dstTileRect.x(), dstTileRect.y());
@@ -210,8 +203,7 @@ void Image::tileInRect(const FloatRect& dstRect, const FloatPoint& srcPoint, con
     startAnimation();
 }
 
-void Image::scaleAndTileInRect(const FloatRect& dstRect, const FloatRect& srcRect,
-                               TileRule hRule, TileRule vRule, void* ctxt)
+void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRect& srcRect, TileRule hRule, TileRule vRule)
 {
     /* FIXME: IMPLEMENT
     if (!m_data)
@@ -224,7 +216,7 @@ void Image::scaleAndTileInRect(const FloatRect& dstRect, const FloatRect& srcRec
     CGContextRef context = graphicsContext(ctxt);
     
     if (m_currentFrame == 0 && m_isSolidColor)
-        return fillSolidColorInRect(m_solidColor, dstRect, Image::CompositeSourceOver, context);
+        return fillSolidColorInRect(m_solidColor, dstRect, CompositeSourceOver, context);
 
     CGContextSaveGState(context);
     CGSize tileSize = srcRect.size();
@@ -285,7 +277,7 @@ void Image::scaleAndTileInRect(const FloatRect& dstRect, const FloatRect& srcRec
         float patternAlpha = 1;
         CGContextSetFillPattern(context, pattern, &patternAlpha);
 
-        setCompositingOperation(context, Image::CompositeSourceOver);
+        setCompositingOperation(context, CompositeSourceOver);
         
         CGContextFillRect(context, ir);
 
index 4f252661c2221258eba8f1bb79b6bae4a8b315ac..541208826367ad5a7247084ce5920dcbee62df5e 100644 (file)
@@ -129,7 +129,7 @@ bool Font::isFixedPitch() const
     return m_dataSet->isFixedPitch(fontDescription());
 }
 
-IntRect Font::selectionRectForText(int x, int y, int h, int tabWidth, int xpos, 
+IntRect Font::selectionRectForText(const IntPoint& point, int h, int tabWidth, int xpos, 
     const QChar* str, int slen, int pos, int l, int toAdd,
     bool rtl, bool visuallyOrdered, int from, int to) const
 {
@@ -158,14 +158,14 @@ IntRect Font::selectionRectForText(int x, int y, int h, int tabWidth, int xpos,
     style.xpos = xpos;
     WebCoreTextGeometry geometry;
     WebCoreInitializeEmptyTextGeometry(&geometry);
-    geometry.point = NSMakePoint(x, y);
-    geometry.selectionY = y;
+    geometry.point = point;
+    geometry.selectionY = point.y();
     geometry.selectionHeight = h;
     geometry.useFontMetricsForSelectionYAndHeight = false;
     return enclosingIntRect([m_dataSet->getRenderer(fontDescription()) selectionRectForRun:&run style:&style geometry:&geometry]);
 }
                      
-void Font::drawText(const GraphicsContext* context, int x, int y, int tabWidth, int xpos, const QChar* str, int len, int from, int to,
+void Font::drawText(GraphicsContext* context, const IntPoint& point, int tabWidth, int xpos, const QChar* str, int len, int from, int to,
                     int toAdd, TextDirection d, bool visuallyOrdered) const
 {
     // Avoid allocations, use stack array to pass font families.  Normally these
@@ -194,11 +194,11 @@ void Font::drawText(const GraphicsContext* context, int x, int y, int tabWidth,
     style.xpos = xpos;
     WebCoreTextGeometry geometry;
     WebCoreInitializeEmptyTextGeometry(&geometry);
-    geometry.point = NSMakePoint(x, y);
+    geometry.point = point;
     [m_dataSet->getRenderer(fontDescription()) drawRun:&run style:&style geometry:&geometry];
 }
 
-void Font::drawHighlightForText(const GraphicsContext* context, int x, int y, int h, int tabWidth, int xpos, const QChar* str,
+void Font::drawHighlightForText(GraphicsContext* context, const IntPoint& point, int h, int tabWidth, int xpos, const QChar* str,
                                 int len, int from, int to, int toAdd,
                                 TextDirection d, bool visuallyOrdered, const Color& backgroundColor) const
 {
@@ -228,29 +228,29 @@ void Font::drawHighlightForText(const GraphicsContext* context, int x, int y, in
     style.xpos = xpos;
     WebCoreTextGeometry geometry;
     WebCoreInitializeEmptyTextGeometry(&geometry);
-    geometry.point = NSMakePoint(x, y);
-    geometry.selectionY = y;
+    geometry.point = point;
+    geometry.selectionY = point.y();
     geometry.selectionHeight = h;
     geometry.useFontMetricsForSelectionYAndHeight = false;
     [m_dataSet->getRenderer(fontDescription()) drawHighlightForRun:&run style:&style geometry:&geometry];
 }
 
-void Font::drawLineForText(const GraphicsContext* context, int x, int y, int yOffset, int width) const
+void Font::drawLineForText(GraphicsContext* context, const IntPoint& point, int yOffset, int width) const
 {
     [m_dataSet->getRenderer(fontDescription())
-        drawLineForCharacters:NSMakePoint(x, y)
+        drawLineForCharacters:point
                       yOffset:(float)yOffset
                         width:width
                         color:nsColor(context->pen().color())
                     thickness:context->pen().width()];
 }
 
-void Font::drawLineForMisspelling(const GraphicsContext* context, int x, int y, int width) const
+void Font::drawLineForMisspelling(GraphicsContext* context, const IntPoint& point, int width) const
 {
-    [m_dataSet->getRenderer(fontDescription()) drawLineForMisspelling:NSMakePoint(x, y) withWidth:width];
+    [m_dataSet->getRenderer(fontDescription()) drawLineForMisspelling:point withWidth:width];
 }
 
-int Font::misspellingLineThickness(const GraphicsContext* context) const
+int Font::misspellingLineThickness(GraphicsContext* context) const
 {
     return [m_dataSet->getRenderer(fontDescription()) misspellingLineThickness];
 }
index 22d4053538844a0d96c9c5914a74300e8320c59d..bcc1b4068bfc3dc98ca6888f270dc3dd5405f86d 100644 (file)
 #import "Font.h"
 #import "FoundationExtras.h"
 #import "IntPointArray.h"
-#import "IntRect.h"
 #import "KRenderingDeviceQuartz.h"
-#import "WebCoreImageRendererFactory.h"
 #import "WebCoreSystemInterface.h"
-#import "WebCoreTextRenderer.h"
-#import "WebCoreTextRendererFactory.h"
-#import "Widget.h"
 
 // FIXME: A lot more of this should use CoreGraphics instead of AppKit.
 // FIXME: A lot more of this should move into GraphicsContextCG.cpp.
@@ -46,16 +41,17 @@ using namespace std;
 
 namespace WebCore {
 
-// NSColor, NSBezierPath, NSGraphicsContext and WebCoreTextRenderer
+// NSColor, NSBezierPath, and NSGraphicsContext
 // calls in this file are all exception-safe, so we don't block
 // exceptions for those.
 
-
 class GraphicsContextPlatformPrivate {
 public:
-    GraphicsContextPlatformPrivate();
+    GraphicsContextPlatformPrivate(CGContextRef, NSGraphicsContext*);
     ~GraphicsContextPlatformPrivate();
-    
+
+    CGContextRef m_cgContext;
+    NSGraphicsContext* m_nsContext;
     IntRect m_focusRingClip; // Work around CG bug in focus ring clipping.
 };
 
@@ -66,24 +62,39 @@ static inline void fillRectSourceOver(const FloatRect& rect, const Color& col)
     NSRectFillUsingOperation(rect, NSCompositeSourceOver);
 }
 
-GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate()
+GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate(CGContextRef cgContext, NSGraphicsContext* nsContext)
 {
+    if (cgContext)
+        m_cgContext = cgContext;
+    else if (nsContext)
+        m_cgContext = static_cast<CGContextRef>([nsContext graphicsPort]);
+    else
+        m_cgContext = 0;
+
+    m_nsContext = nsContext;
+
+    CGContextRetain(m_cgContext);
+    KWQRetain(m_nsContext);
 }
 
 GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate()
 {
+    CGContextRelease(m_cgContext);
+    KWQRelease(m_nsContext);
 }
 
-GraphicsContext::GraphicsContext()
-    : m_common(createGraphicsContextPrivate())
-    , m_data(new GraphicsContextPlatformPrivate)
+GraphicsContext::GraphicsContext(NSGraphicsContext* nsContext)
+    : m_common(createGraphicsContextPrivate(nsContext && ![nsContext isDrawingToScreen]))
+    , m_data(new GraphicsContextPlatformPrivate(0, nsContext))
 {
+    setPaintingDisabled(!nsContext);
 }
 
-GraphicsContext::GraphicsContext(bool forPrinting)
+GraphicsContext::GraphicsContext(CGContextRef cgContext, bool /*flipText*/, bool forPrinting)
     : m_common(createGraphicsContextPrivate(forPrinting))
-    , m_data(new GraphicsContextPlatformPrivate)
+    , m_data(new GraphicsContextPlatformPrivate(cgContext, 0))
 {
+    setPaintingDisabled(!cgContext);
 }
 
 GraphicsContext::~GraphicsContext()
@@ -94,12 +105,22 @@ GraphicsContext::~GraphicsContext()
 
 void GraphicsContext::savePlatformState()
 {
-    [NSGraphicsContext saveGraphicsState];
+    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();
 }
 
 void GraphicsContext::restorePlatformState()
 {
-    [NSGraphicsContext restoreGraphicsState];
+    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();
 }
 
 // Draws a filled rectangle with a stroked border.
@@ -107,9 +128,13 @@ void GraphicsContext::drawRect(const IntRect& rect)
 {
     if (paintingDisabled())
         return;
-         
-    if (brush().style() != Brush::NoBrush)
-        fillRectSourceOver(rect, brush().color());
+
+    // This function currently works only with NSGraphicsContext.
+    ASSERT(m_data->m_nsContext);
+    ASSERT(m_data->m_nsContext == [NSGraphicsContext currentContext]);
+
+    if (fillColor() & 0xFF000000)
+        fillRectSourceOver(rect, fillColor());
 
     if (pen().style() != Pen::Pen::NoPen) {
         setColorFromPen();
@@ -117,13 +142,21 @@ void GraphicsContext::drawRect(const IntRect& rect)
     }
 }
 
-void GraphicsContext::setColorFromBrush()
+void GraphicsContext::setColorFromFillColor()
 {
-    [nsColor(brush().color()) set];
+    // This function currently works only with NSGraphicsContext.
+    ASSERT(m_data->m_nsContext);
+    ASSERT(m_data->m_nsContext == [NSGraphicsContext currentContext]);
+
+    [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]);
+
     [nsColor(pen().color()) set];
 }
   
@@ -133,6 +166,10 @@ 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]);
+
     Pen::PenStyle penStyle = pen().style();
     if (penStyle == Pen::Pen::NoPen)
         return;
@@ -260,14 +297,14 @@ void GraphicsContext::drawEllipse(const IntRect& rect)
     if (paintingDisabled())
         return;
         
-    CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
+    CGContextRef context = platformContext();
     CGContextBeginPath(context);
     float r = (float)rect.width() / 2;
     CGContextAddArc(context, rect.x() + r, rect.y() + r, r, 0, 2*M_PI, true);
     CGContextClosePath(context);
 
-    if (brush().style() != Brush::NoBrush) {
-        setColorFromBrush();
+    if (fillColor() & 0xFF000000) {
+        setColorFromFillColor();
         if (pen().style() != Pen::NoPen) {
             // stroke and fill
             setColorFromPen();
@@ -299,7 +336,7 @@ void GraphicsContext::drawArc(int x, int y, int w, int h, int a, int alen)
         return;
     
     if (pen().style() != Pen::NoPen) {
-        CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
+        CGContextRef context = platformContext();
         CGContextBeginPath(context);
         
         float r = (float)w / 2;
@@ -322,7 +359,7 @@ void GraphicsContext::drawConvexPolygon(const IntPointArray& points)
     if (npoints <= 1)
         return;
 
-    CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
+    CGContextRef context = platformContext();
 
     CGContextSaveGState(context);
 
@@ -334,8 +371,8 @@ void GraphicsContext::drawConvexPolygon(const IntPointArray& points)
         CGContextAddLineToPoint(context, points[i].x(), points[i].y());
     CGContextClosePath(context);
 
-    if (brush().style() != Brush::NoBrush) {
-        setColorFromBrush();
+    if (fillColor() & 0xFF000000) {
+        setColorFromFillColor();
         CGContextEOFillPath(context);
     }
 
@@ -348,64 +385,11 @@ void GraphicsContext::drawConvexPolygon(const IntPointArray& points)
     CGContextRestoreGState(context);
 }
 
-int GraphicsContext::getCompositeOperation(CGContextRef context)
-{
-    return (int)[[WebCoreImageRendererFactory sharedFactory] CGCompositeOperationInContext:context];
-}
-
-void GraphicsContext::setCompositeOperation (CGContextRef context, const String& op)
-{
-    [[WebCoreImageRendererFactory sharedFactory] setCGCompositeOperationFromString:op inContext:context];
-}
-
-void GraphicsContext::setCompositeOperation (CGContextRef context, int op)
-{
-    [[WebCoreImageRendererFactory sharedFactory] setCGCompositeOperation:op inContext:context];
-}
-
-void GraphicsContext::drawImage(Image* image, const FloatRect& dest, 
-                              float sx, float sy, float sw, float sh, Image::CompositeOperator compositeOperator, void* context)
-{
-    if (paintingDisabled())
-        return;
-
-    float tsw = sw;
-    float tsh = sh;
-    float tw = dest.width();
-    float th = dest.height();
-        
-    if (tsw == -1)
-        tsw = image->width();
-    if (tsh == -1)
-        tsh = image->height();
-
-    if (tw == -1)
-        tw = image->width();
-    if (th == -1)
-        th = image->height();
-
-    image->drawInRect(FloatRect(dest.location(), FloatSize(tw, th)), FloatRect(sx, sy, tsw, tsh), compositeOperator, context);
-}
-
-void GraphicsContext::drawTiledImage(Image* image, const IntRect& destRect, const IntPoint& srcPoint, const IntSize& tileSize, void* context)
+void setCompositeOperation(CGContextRef context, CompositeOperator op)
 {
-    if (paintingDisabled())
-        return;
-    
-    image->tileInRect(destRect, srcPoint, tileSize, context);
-}
-
-void GraphicsContext::drawScaledAndTiledImage(Image* image, const IntRect& dest, int sx, int sy, int sw, int sh, 
-    Image::TileRule hRule, Image::TileRule vRule, void* context)
-{
-    if (paintingDisabled())
-        return;
-
-    if (hRule == Image::StretchTile && vRule == Image::StretchTile)
-        // Just do a scale.
-        return drawImage(image, dest, sx, sy, sw, sh, Image::CompositeSourceOver, context);
-
-    image->scaleAndTileInRect(dest, FloatRect(sx, sy, sw, sh), hRule, vRule, context);
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    [[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO] setCompositingOperation:(NSCompositingOperation)op];
+    [pool release];
 }
 
 static int getBlendedColorComponent(int c, int a)
@@ -437,13 +421,17 @@ Color GraphicsContext::selectedTextBackgroundColor() const
     return col;
 }
 
-void GraphicsContext::fillRect(const IntRect& rect, const Brush& brush)
+void GraphicsContext::fillRect(const IntRect& rect, const Color& color)
 {
     if (paintingDisabled())
         return;
 
-    if (brush.style() == Brush::SolidPattern)
-        fillRectSourceOver(rect, brush.color());
+    // This function currently works only with NSGraphicsContext.
+    ASSERT(m_data->m_nsContext);
+    ASSERT(m_data->m_nsContext == [NSGraphicsContext currentContext]);
+
+    if (color.alpha())
+        fillRectSourceOver(rect, color.rgb());
 }
 
 void GraphicsContext::addClip(const IntRect& rect)
@@ -451,11 +439,11 @@ void GraphicsContext::addClip(const IntRect& rect)
     if (paintingDisabled())
         return;
 
-    [NSBezierPath clipRect:rect];
+    CGContextClipToRect(platformContext(), rect);
 }
 
 void GraphicsContext::addRoundedRectClip(const IntRect& rect, const IntSize& topLeft, const IntSize& topRight,
-                                  const IntSize& bottomLeft, const IntSize& bottomRight)
+    const IntSize& bottomLeft, const IntSize& bottomRight)
 {
     if (paintingDisabled())
         return;
@@ -472,8 +460,8 @@ void GraphicsContext::addRoundedRectClip(const IntRect& rect, const IntSize& top
     // Clip to our rect.
     addClip(rect);
 
-    // Ok, the curves can fit.
-    CGContextRef context = currentCGContext();
+    // OK, the curves can fit.
+    CGContextRef context = platformContext();
     
     // Add the four ellipses to the path.  Technically this really isn't good enough, since we could end up
     // not clipping the other 3/4 of the ellipse we don't care about.  We're relying on the fact that for
@@ -520,15 +508,10 @@ void GraphicsContext::clearFocusRingClip()
     m_data->m_focusRingClip = IntRect();
 }
 
-CGContextRef GraphicsContext::currentCGContext()
-{
-    return (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
-}
-
 #if SVG_SUPPORT
 KRenderingDeviceContext* GraphicsContext::createRenderingDeviceContext()
 {
-    return new KRenderingDeviceContextQuartz(currentCGContext());
+    return new KRenderingDeviceContextQuartz(platformContext());
 }
 #endif
 
@@ -536,7 +519,7 @@ void GraphicsContext::beginTransparencyLayer(float opacity)
 {
     if (paintingDisabled())
         return;
-    CGContextRef context = currentCGContext();
+    CGContextRef context = platformContext();
     CGContextSaveGState(context);
     CGContextSetAlpha(context, opacity);
     CGContextBeginTransparencyLayer(context, 0);
@@ -546,24 +529,24 @@ void GraphicsContext::endTransparencyLayer()
 {
     if (paintingDisabled())
         return;
-    CGContextRef context = currentCGContext();
+    CGContextRef context = platformContext();
     CGContextEndTransparencyLayer(context);
     CGContextRestoreGState(context);
 }
 
-void GraphicsContext::setShadow(int x, int y, int blur, const Color& color)
+void GraphicsContext::setShadow(const IntSize& size, int blur, const Color& color)
 {
     if (paintingDisabled())
         return;
     // Check for an invalid color, as this means that the color was not set for the shadow
     // and we should therefore just use the default shadow color.
-    CGContextRef context = currentCGContext();
+    CGContextRef context = platformContext();
     if (!color.isValid())
-        CGContextSetShadow(context, CGSizeMake(x,-y), blur); // y is flipped.
+        CGContextSetShadow(context, CGSizeMake(size.width(), -size.height()), blur); // y is flipped.
     else {
         CGColorRef colorCG = cgColor(color);
         CGContextSetShadowWithColor(context,
-                                    CGSizeMake(x,-y), // y is flipped.
+                                    CGSizeMake(size.width(), -size.height()), // y is flipped.
                                     blur, 
                                     colorCG);
         CGColorRelease(colorCG);
@@ -574,7 +557,7 @@ void GraphicsContext::clearShadow()
 {
     if (paintingDisabled())
         return;
-    CGContextRef context = currentCGContext();
+    CGContextRef context = platformContext();
     CGContextSetShadowWithColor(context, CGSizeZero, 0, NULL);
 }
 
@@ -622,4 +605,11 @@ void GraphicsContext::drawFocusRing(const Color& color)
     CGPathRelease(focusRingPath);
 }
 
+CGContextRef GraphicsContext::platformContext() const
+{
+    ASSERT(!paintingDisabled());
+    ASSERT(m_data->m_cgContext);
+    return m_data->m_cgContext;
+}
+
 }
index b212ab306ecd6abd1127f45c7ef7a793f1fe6b7d..1f2fa4fb3e58022c779b6e1e4bf0791476f285fa 100644 (file)
@@ -28,6 +28,7 @@
 
 #import "FloatRect.h"
 #import "FoundationExtras.h"
+#import "GraphicsContext.h"
 #import "PDFDocumentImage.h"
 #import "PlatformString.h"
 #import "WebCoreImageRendererFactory.h"
@@ -102,26 +103,13 @@ bool Image::supportsType(const String& type)
 }
 
 // Drawing Routines
-static CGContextRef graphicsContext(void* context)
-{
-    if (!context)
-        return (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
-    return (CGContextRef)context;
-}
-
-static void setCompositingOperation(CGContextRef context, Image::CompositeOperator op)
-{
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-    [[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO] setCompositingOperation:(NSCompositingOperation)op];
-    [pool release];
-}
 
-static void fillSolidColorInRect(CGColorRef color, CGRect rect, Image::CompositeOperator op, CGContextRef context)
+static void fillSolidColorInRect(CGColorRef color, CGRect rect, CompositeOperator op, CGContextRef context)
 {
     if (color) {
         CGContextSaveGState(context);
         CGContextSetFillColorWithColor(context, color);
-        setCompositingOperation(context, op);
+        setCompositeOperation(context, op);
         CGContextFillRect(context, rect);
         CGContextRestoreGState(context);
     }
@@ -148,8 +136,7 @@ void Image::checkForSolidColor(CGImageRef image)
             kCGImageAlphaPremultipliedLast | kCGBitmapFloatComponents | kCGBitmapByteOrder32Host);
 #endif
         if (bmap) {
-            setCompositingOperation(bmap, Image::CompositeCopy);
-            
+            setCompositeOperation(bmap, CompositeCopy);
             CGRect dst = { {0, 0}, {1, 1} };
             CGContextDrawImage(bmap, dst, image);
             if (pixel[3] > 0)
@@ -201,10 +188,9 @@ CGImageRef Image::getCGImageRef()
     return frameAtIndex(0);
 }
 
-void Image::drawInRect(const FloatRect& dstRect, const FloatRect& srcRect,
-                       CompositeOperator compositeOp, void* ctxt)
+void Image::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator compositeOp)
 {
-    CGContextRef context = graphicsContext(ctxt);
+    CGContextRef context = ctxt->platformContext();
     if (m_isPDF) {
         if (m_PDFDoc)
             m_PDFDoc->draw(srcRect, dstRect, compositeOp, 1.0, true, context);
@@ -247,7 +233,7 @@ void Image::drawInRect(const FloatRect& dstRect, const FloatRect& srcRect,
     }
 
     // Flip the coords.
-    setCompositingOperation(context, compositeOp);
+    setCompositeOperation(context, compositeOp);
     CGContextTranslateCTM(context, ir.origin.x, ir.origin.y);
     CGContextScaleCTM(context, 1, -1);
     CGContextTranslateCTM(context, 0, -ir.size.height);
@@ -292,19 +278,20 @@ static void drawPattern(void* info, CGContextRef context)
 
 static const CGPatternCallbacks patternCallbacks = { 0, drawPattern, NULL };
 
-void Image::tileInRect(const FloatRect& destRect, const FloatPoint& srcPoint, const FloatSize& tileSize, void* ctxt)
+void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const FloatPoint& srcPoint, const FloatSize& tileSize)
 {    
     CGImageRef image = frameAtIndex(m_currentFrame);
     if (!image)
         return;
 
-    CGContextRef context = graphicsContext(ctxt);
+    CGContextRef context = ctxt->platformContext();
 
-    if (m_currentFrame == 0 && m_isSolidColor)
-        return fillSolidColorInRect(m_solidColor, destRect, Image::CompositeSourceOver, context);
+    if (m_currentFrame == 0 && m_isSolidColor) {
+        fillSolidColorInRect(m_solidColor, destRect, CompositeSourceOver, context);
+        return;
+    }
 
     CGPoint scaledPoint = srcPoint;
-    CGRect destination = destRect;
     CGSize intrinsicTileSize = size();
     CGSize scaledTileSize = intrinsicTileSize;
 
@@ -325,23 +312,22 @@ void Image::tileInRect(const FloatRect& destRect, const FloatPoint& srcPoint, co
 
     // Check and see if a single draw of the image can cover the entire area we are supposed to tile.
     NSRect oneTileRect;
-    oneTileRect.origin.x = destination.origin.x + fmodf(fmodf(-scaledPoint.x, scaledTileSize.width) - 
+    oneTileRect.origin.x = destRect.x() + fmodf(fmodf(-scaledPoint.x, scaledTileSize.width) - 
                             scaledTileSize.width, scaledTileSize.width);
-    oneTileRect.origin.y = destination.origin.y + fmodf(fmodf(-scaledPoint.y, scaledTileSize.height) - 
+    oneTileRect.origin.y = destRect.y() + fmodf(fmodf(-scaledPoint.y, scaledTileSize.height) - 
                             scaledTileSize.height, scaledTileSize.height);
     oneTileRect.size.width = scaledTileSize.width;
     oneTileRect.size.height = scaledTileSize.height;
 
     // If the single image draw covers the whole area, then just draw once.
-    if (NSContainsRect(oneTileRect, NSMakeRect(destination.origin.x, destination.origin.y, 
-                                        destination.size.width, destination.size.height))) {
+    if (NSContainsRect(oneTileRect, destRect)) {
         CGRect fromRect;
-        fromRect.origin.x = (destination.origin.x - oneTileRect.origin.x) / scaleX;
-        fromRect.origin.y = (destination.origin.y - oneTileRect.origin.y) / scaleY;
+        fromRect.origin.x = (destRect.x() - oneTileRect.origin.x) / scaleX;
+        fromRect.origin.y = (destRect.y() - oneTileRect.origin.y) / scaleY;
         fromRect.size.width = oneTileRect.size.width / scaleX;
         fromRect.size.height = oneTileRect.size.height / scaleY;
 
-        drawInRect(destRect, FloatRect(fromRect), Image::CompositeSourceOver, context);
+        draw(ctxt, destRect, fromRect, CompositeSourceOver);
         return;
     }
 
@@ -362,9 +348,9 @@ void Image::tileInRect(const FloatRect& destRect, const FloatPoint& srcPoint, co
         CGFloat patternAlpha = 1;
         CGContextSetFillPattern(context, pattern, &patternAlpha);
 
-        setCompositingOperation(context, Image::CompositeSourceOver);
+        setCompositeOperation(context, CompositeSourceOver);
 
-        CGContextFillRect(context, destination);
+        CGContextFillRect(context, destRect);
 
         CGContextRestoreGState(context);
 
@@ -374,17 +360,17 @@ void Image::tileInRect(const FloatRect& destRect, const FloatPoint& srcPoint, co
     startAnimation();
 }
 
-void Image::scaleAndTileInRect(const FloatRect& dstRect, const FloatRect& srcRect,
-                               TileRule hRule, TileRule vRule, void* ctxt)
+// FIXME: Merge with the other drawTiled eventually, since we need a combination of both for some things.
+void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRect& srcRect, TileRule hRule, TileRule vRule)
 {    
     CGImageRef image = frameAtIndex(m_currentFrame);
     if (!image)
         return;
 
-    CGContextRef context = graphicsContext(ctxt);
+    CGContextRef context = ctxt->platformContext();
     
     if (m_currentFrame == 0 && m_isSolidColor)
-        return fillSolidColorInRect(m_solidColor, dstRect, Image::CompositeSourceOver, context);
+        return fillSolidColorInRect(m_solidColor, dstRect, CompositeSourceOver, context);
 
     CGContextSaveGState(context);
     CGSize tileSize = srcRect.size();
@@ -445,7 +431,7 @@ void Image::scaleAndTileInRect(const FloatRect& dstRect, const FloatRect& srcRec
         CGFloat patternAlpha = 1;
         CGContextSetFillPattern(context, pattern, &patternAlpha);
 
-        setCompositingOperation(context, Image::CompositeSourceOver);
+        setCompositeOperation(context, CompositeSourceOver);
         
         CGContextFillRect(context, ir);
 
index c00b033ff29fe83f731de0c28fdc9894d1f9c63f..3bc0f921960df0453e90f978973a19292214479a 100644 (file)
@@ -51,7 +51,7 @@ public:
     int pageCount();
     void adjustCTM(CGContextRef context);
 
-    void draw(NSRect fromRect, NSRect toRect, Image::CompositeOperator op, float alpha, bool flipped, CGContextRef context);
+    void draw(NSRect fromRect, NSRect toRect, CompositeOperator, float alpha, bool flipped, CGContextRef);
 
 private:
     CGPDFDocumentRef m_document;
index 872d7528d4e6dbd394f4c3710ad87fb131ff1b29..b424e0618971953a99c272c19a6be4b73ba2ef5e 100644 (file)
@@ -139,7 +139,7 @@ int PDFDocumentImage::pageCount()
     return CGPDFDocumentGetNumberOfPages(m_document);
 }
 
-void PDFDocumentImage::draw(NSRect srcRect, NSRect dstRect, Image::CompositeOperator op, 
+void PDFDocumentImage::draw(NSRect srcRect, NSRect dstRect, CompositeOperator op, 
                             float alpha, bool flipped, CGContextRef context)
 {
     CGContextSaveGState(context);
index 1c215da2bfdd8c2d94fcbb138badb434f38e2ed4..6250ca129638390c92da698c838946e669e32bf5 100644 (file)
@@ -315,18 +315,20 @@ NSView* Widget::getOuterView() const
     return view;
 }
 
-void Widget::lockDrawingFocus()
+GraphicsContext* Widget::lockDrawingFocus()
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
     [getView() lockFocus];
     END_BLOCK_OBJC_EXCEPTIONS;
+    return new GraphicsContext([NSGraphicsContext currentContext]);
 }
 
-void Widget::unlockDrawingFocus()
+void Widget::unlockDrawingFocus(GraphicsContext* context)
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
     [getView() unlockFocus];
     END_BLOCK_OBJC_EXCEPTIONS;
+    delete context;
 }
 
 void Widget::disableFlushDrawing()
index 55363a57b9ff56447b08376dc51c3a6d2c63ff12..3e2147b023787bf77a65230d355abbc977f56d4a 100644 (file)
@@ -237,7 +237,8 @@ static void convertRange(int from, int to, int len, int& offset, int& length)
         length = to - from;
 }
 
-void Font::drawText(const GraphicsContext* context, int x, int y, int tabWidth, int xpos, const QChar* str, int len, int from, int to,
+void Font::drawText(GraphicsContext* context, const IntPoint& point, int tabWidth, int xpos,
+                    const QChar* str, int len, int from, int to,
                     int toAdd, TextDirection d, bool visuallyOrdered) const
 {
     FontData* font = m_dataSet->primaryFont(fontDescription());
@@ -253,6 +254,8 @@ void Font::drawText(const GraphicsContext* context, int x, int y, int tabWidth,
     int offset, length;
     convertRange(from, to, len, offset, length);
 
+    int x = point.x();
+    int y = point.y();
     y -= font->ascent();
 
     SetBkMode(dc, TRANSPARENT);
@@ -264,8 +267,8 @@ void Font::drawText(const GraphicsContext* context, int x, int y, int tabWidth,
     // No need to ReleaseDC the HDC borrowed from cairo
 }
 
-void Font::drawHighlightForText(const GraphicsContext* context, int x, int y, int h, int tabWidth, int xpos, const QChar* str,
-                                int len, int from, int to, int toAdd,
+void Font::drawHighlightForText(GraphicsContext* context, const IntPoint& point, int h, int tabWidth, int xpos,
+                                const QChar* str, int len, int from, int to, int toAdd,
                                 TextDirection d, bool visuallyOrdered, const Color& backgroundColor) const
 {
     if (!backgroundColor.isValid())
@@ -283,10 +286,10 @@ void Font::drawHighlightForText(const GraphicsContext* context, int x, int y, in
     IntSize runSize = hackishExtentForString(dc, font, str, len, offset, length, tabWidth, xpos);
 
     // FIXME: this const_cast should be removed when this code is made real.
-    const_cast<GraphicsContext*>(context)->fillRect(IntRect(IntPoint(x, y), runSize), backgroundColor);
+    const_cast<GraphicsContext*>(context)->fillRect(IntRect(point, runSize), backgroundColor);
 }
 
-IntRect Font::selectionRectForText(int x, int y, int h, int tabWidth, int xpos, const QChar* str, int slen,
+IntRect Font::selectionRectForText(const IntPoint& point, int h, int tabWidth, int xpos, const QChar* str, int slen,
                                    int pos, int len, int toAdd, bool rtl, bool visuallyOrdered, int from, int to) const
 {
     FontData* font = m_dataSet->primaryFont(fontDescription());
@@ -299,11 +302,11 @@ IntRect Font::selectionRectForText(int x, int y, int h, int tabWidth, int xpos,
     HDC dc = GetDC((HWND)0); // FIXME: Need a way to get to the real HDC.
     IntSize runSize = hackishExtentForString(dc, font, str, slen, offset, length, tabWidth, xpos);
     ReleaseDC(0, dc);
-    return IntRect(x, y, runSize.width(), runSize.height());
+    return IntRect(point, runSize);
 }
 
 int Font::checkSelectionPoint(const QChar* str, int slen, int offset, int len, int toAdd, int tabWidth, int xpos, int x,
-                              WebCore::TextDirection, bool visuallyOrdered, bool includePartialGlyphs) const
+                              TextDirection, bool visuallyOrdered, bool includePartialGlyphs) const
 {
     FontData* font = m_dataSet->primaryFont(fontDescription());
     if (!font)
@@ -334,18 +337,18 @@ int Font::checkSelectionPoint(const QChar* str, int slen, int offset, int len, i
     return selectionOffset;
 }
 
-void Font::drawLineForText(const GraphicsContext* context, int x, int y, int yOffset, int width) const
+void Font::drawLineForText(GraphicsContext* context, const IntPoint& point, int yOffset, int width) const
 {
-    IntPoint origin(x, y + yOffset + 1);
+    IntPoint origin = point + IntSize(0, yOffset + 1);
     IntPoint endPoint = origin + IntSize(width, 0);
     const_cast<GraphicsContext*>(context)->drawLine(origin, endPoint);
 }
 
-void Font::drawLineForMisspelling(const GraphicsContext* context, int x, int y, int width) const
+void Font::drawLineForMisspelling(GraphicsContext* context, const IntPoint& point, int width) const
 {
 }
 
-int Font::misspellingLineThickness(const GraphicsContext* context) const
+int Font::misspellingLineThickness(GraphicsContext* context) const
 {
     return 1;
 }
index 0a49e44a09a4474e5c8615559cc74a23795a90b8..14c6dd1647fdd3bf67e2e46fe6b253b999000c48 100644 (file)
@@ -101,8 +101,8 @@ void Widget::enableFlushDrawing() { notImplemented(); }
 bool Widget::isEnabled() const { notImplemented(); return 0; }
 Widget::FocusPolicy Widget::focusPolicy() const { notImplemented(); return NoFocus; }
 void Widget::disableFlushDrawing() { notImplemented(); }
-void Widget::lockDrawingFocus() { notImplemented(); }
-void Widget::unlockDrawingFocus() { notImplemented(); }
+GraphicsContext* Widget::lockDrawingFocus() { notImplemented(); return 0; }
+void Widget::unlockDrawingFocus(GraphicsContext*) { notImplemented(); }
 
 JavaAppletWidget::JavaAppletWidget(IntSize const&,Frame*,KXMLCore::HashMap<String,String> const&) { notImplemented(); }
 
index 0df92cf1d22659cee771a79d582e41c8a286e132..2501bdbea724a9d8cf34a01325aff98006b52d18 100644 (file)
@@ -117,7 +117,7 @@ IntRect InlineTextBox::selectionRect(int tx, int ty, int startPos, int endPos)
     int selHeight = rootBox->selectionHeight();
     const Font *f = textObj->font(m_firstLine);
 
-    IntRect r = f->selectionRectForText(tx + m_x, ty + selTop, selHeight, textObj->tabWidth(), textPos(), 
+    IntRect r = f->selectionRectForText(IntPoint(tx + m_x, ty + selTop), selHeight, textObj->tabWidth(), textPos(), 
                                         textObj->str->unicode(), textObj->str->length(), m_start, m_len,
                                         m_toAdd, m_reversed, m_dirOverride, sPos, ePos);
     if (r.x() > tx + m_x + m_width)
@@ -301,8 +301,8 @@ void InlineTextBox::paint(RenderObject::PaintInfo& i, int tx, int ty)
     // we can do this.
     bool setShadow = false;
     if (styleToUse->textShadow()) {
-        i.p->setShadow(styleToUse->textShadow()->x, styleToUse->textShadow()->y,
-                        styleToUse->textShadow()->blur, styleToUse->textShadow()->color);
+        i.p->setShadow(IntSize(styleToUse->textShadow()->x, styleToUse->textShadow()->y),
+            styleToUse->textShadow()->blur, styleToUse->textShadow()->color);
         setShadow = true;
     }
 
@@ -332,7 +332,7 @@ void InlineTextBox::paint(RenderObject::PaintInfo& i, int tx, int ty)
         int endPoint = m_len;
         if (m_truncation != cNoTruncation)
             endPoint = m_truncation - m_start;
-        i.p->drawText(m_x + tx, m_y + ty + m_baseline, textObject()->tabWidth(), textPos(),
+        i.p->drawText(IntPoint(m_x + tx, m_y + ty + m_baseline), textObject()->tabWidth(), textPos(),
                       textObject()->string()->unicode(), textObject()->string()->length(), m_start, endPoint,
                       m_toAdd, m_reversed ? RTL : LTR, m_dirOverride || styleToUse->visuallyOrdered());
     } else {
@@ -340,21 +340,19 @@ void InlineTextBox::paint(RenderObject::PaintInfo& i, int tx, int ty)
         selectionStartEnd(sPos, ePos);
         if (paintSelectedTextSeparately) {
             // paint only the text that is not selected
-            if (sPos >= ePos) {
-                i.p->drawText(m_x + tx, m_y + ty + m_baseline, textObject()->tabWidth(), textPos(),
+            if (sPos >= ePos)
+                i.p->drawText(IntPoint(m_x + tx, m_y + ty + m_baseline), textObject()->tabWidth(), textPos(),
                               textObject()->string()->unicode(), textObject()->string()->length(), m_start, m_len,
                               m_toAdd, m_reversed ? RTL : LTR, m_dirOverride || styleToUse->visuallyOrdered());
-            else {
-                if (sPos - 1 >= 0) {
-                    i.p->drawText(m_x + tx, m_y + ty + m_baseline, textObject()->tabWidth(), textPos(),
+            else {
+                if (sPos - 1 >= 0)
+                    i.p->drawText(IntPoint(m_x + tx, m_y + ty + m_baseline), textObject()->tabWidth(), textPos(),
                                   textObject()->string()->unicode(), textObject()->string()->length(), m_start, m_len,
                                   m_toAdd, m_reversed ? RTL : LTR, m_dirOverride || styleToUse->visuallyOrdered(), 0, sPos);
-                }
-                if (ePos < m_start + m_len) {
-                    i.p->drawText(m_x + tx, m_y + ty + m_baseline, textObject()->tabWidth(), textPos(),
+                if (ePos < m_start + m_len)
+                    i.p->drawText(IntPoint(m_x + tx, m_y + ty + m_baseline), textObject()->tabWidth(), textPos(),
                                   textObject()->string()->unicode(), textObject()->string()->length(), m_start, m_len,
                                   m_toAdd, m_reversed ? RTL : LTR, m_dirOverride || styleToUse->visuallyOrdered(), ePos, -1);
-                }
             }
         }
             
@@ -364,11 +362,10 @@ void InlineTextBox::paint(RenderObject::PaintInfo& i, int tx, int ty)
                 i.p->setPen(selectionColor);
             
             if (selectionTextShadow)
-                i.p->setShadow(selectionTextShadow->x,
-                               selectionTextShadow->y,
+                i.p->setShadow(IntSize(selectionTextShadow->x, selectionTextShadow->y),
                                selectionTextShadow->blur,
                                selectionTextShadow->color);
-            i.p->drawText(m_x + tx, m_y + ty + m_baseline, textObject()->tabWidth(), textPos(),
+            i.p->drawText(IntPoint(m_x + tx, m_y + ty + m_baseline), textObject()->tabWidth(), textPos(),
                           textObject()->string()->unicode(), textObject()->string()->length(), m_start, m_len,
                           m_toAdd, m_reversed ? RTL : LTR, m_dirOverride || styleToUse->visuallyOrdered(), sPos, ePos);
             if (selectionTextShadow)
@@ -453,7 +450,7 @@ void InlineTextBox::paintSelection(GraphicsContext* p, int tx, int ty, RenderSty
     int y = r->selectionTop();
     int h = r->selectionHeight();
     p->addClip(IntRect(m_x + tx, y + ty, m_width, h));
-    p->drawHighlightForText(m_x + tx, y + ty, h, textObject()->tabWidth(), textPos(), 
+    p->drawHighlightForText(IntPoint(m_x + tx, y + ty), h, textObject()->tabWidth(), textPos(), 
                             textObject()->str->unicode(), textObject()->str->length(), m_start, m_len,
                             m_toAdd, m_reversed ? RTL : LTR, m_dirOverride || style->visuallyOrdered(), sPos, ePos, c);
     p->restore();
@@ -477,7 +474,8 @@ void InlineTextBox::paintMarkedTextBackground(GraphicsContext* p, int tx, int ty
     RootInlineBox* r = root();
     int y = r->selectionTop();
     int h = r->selectionHeight();
-    p->drawHighlightForText(m_x + tx, y + ty, h, textObject()->tabWidth(), textPos(), textObject()->str->unicode(), textObject()->str->length(), m_start, m_len,
+    p->drawHighlightForText(IntPoint(m_x + tx, y + ty), h, textObject()->tabWidth(), textPos(),
+                            textObject()->str->unicode(), textObject()->str->length(), m_start, m_len,
                             m_toAdd, m_reversed ? RTL : LTR, m_dirOverride || style->visuallyOrdered(), sPos, ePos, c);
     p->restore();
 }
@@ -500,15 +498,15 @@ void InlineTextBox::paintDecoration(GraphicsContext *pt, int _tx, int _ty, int d
     // Use a special function for underlines to get the positioning exactly right.
     if (deco & UNDERLINE) {
         pt->setPen(underline);
-        pt->drawLineForText(_tx, _ty, m_baseline, width);
+        pt->drawLineForText(IntPoint(_tx, _ty), m_baseline, width);
     }
     if (deco & OVERLINE) {
         pt->setPen(overline);
-        pt->drawLineForText(_tx, _ty, 0, width);
+        pt->drawLineForText(IntPoint(_tx, _ty), 0, width);
     }
     if (deco & LINE_THROUGH) {
         pt->setPen(linethrough);
-        pt->drawLineForText(_tx, _ty, 2*m_baseline/3, width);
+        pt->drawLineForText(IntPoint(_tx, _ty), 2*m_baseline/3, width);
     }
 }
 
@@ -558,7 +556,7 @@ void InlineTextBox::paintSpellingMarker(GraphicsContext* pt, int _tx, int _ty, D
         // in larger fonts, tho, place the underline up near the baseline to prevent big gap
         underlineOffset = m_baseline + 2;
     }
-    pt->drawLineForMisspelling(_tx + start, _ty + underlineOffset, width);
+    pt->drawLineForMisspelling(IntPoint(_tx + start, _ty + underlineOffset), width);
 }
 
 void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, int _tx, int _ty, DocumentMarker marker, RenderStyle* style, const Font* f)
@@ -575,7 +573,7 @@ void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, int _tx, int _ty,
     int sPos = max(marker.startOffset - m_start, (unsigned)0);
     int ePos = min(marker.endOffset - m_start, (unsigned)m_len);
     
-    pt->drawHighlightForText(m_x + _tx, y + _ty, h, textObject()->tabWidth(), textPos(), 
+    pt->drawHighlightForText(IntPoint(m_x + _tx, y + _ty), h, textObject()->tabWidth(), textPos(), 
                              textObject()->str->unicode(), textObject()->str->length(), m_start, m_len,
                              m_toAdd, m_reversed ? RTL : LTR, m_dirOverride || style->visuallyOrdered(), sPos, ePos, yellow);
     pt->restore();
@@ -654,7 +652,7 @@ void InlineTextBox::paintMarkedTextUnderline(GraphicsContext* pt, int _tx, int _
 
     int underlineOffset = m_height - 3;
     pt->setPen(Pen(underline.color, underline.thick ? 2 : 0));
-    pt->drawLineForText(_tx + start, _ty, underlineOffset, width);
+    pt->drawLineForText(IntPoint(_tx + start, _ty), underlineOffset, width);
 }
 
 int InlineTextBox::caretMinOffset() const
@@ -705,7 +703,7 @@ int InlineTextBox::positionForOffset(int offset) const
     int from = m_reversed ? offset - m_start : 0;
     int to = m_reversed ? m_len : offset - m_start;
     // FIXME: Do we need to add rightBearing here?
-    return f->selectionRectForText(m_x, 0, 0, text->tabWidth(), textPos(), text->str->unicode(), text->str->length(), m_start, m_len,
+    return f->selectionRectForText(IntPoint(m_x, 0), 0, text->tabWidth(), textPos(), text->str->unicode(), text->str->length(), m_start, m_len,
         m_toAdd, m_reversed, m_dirOverride, from, to).right();
 }
 
index 89b9565c550a740416ab5defae5e9009d26261b9..77c5a44dcd43b3e9b6eff01b01ad8e9f7775984b 100644 (file)
@@ -1635,13 +1635,9 @@ IntRect RenderBlock::fillHorizontalSelectionGap(RenderObject* selObj, int xPos,
 {
     if (width <= 0 || height <= 0)
         return IntRect();
-
     IntRect gapRect(xPos, yPos, width, height);
-    if (i) {
-        // Paint the rect.
-        Brush selBrush(selObj->selectionColor(i->p));
-        i->p->fillRect(gapRect, selBrush);
-    }
+    if (i)
+        i->p->fillRect(gapRect, selObj->selectionColor(i->p));
     return gapRect;
 }
 
@@ -1662,11 +1658,8 @@ IntRect RenderBlock::fillVerticalSelectionGap(int lastTop, int lastLeft, int las
         return IntRect();
 
     IntRect gapRect(left, top, width, height);
-    if (i) {
-        // Paint the rect.
-        Brush selBrush(selectionColor(i->p));
-        i->p->fillRect(gapRect, selBrush);
-    }
+    if (i)
+        i->p->fillRect(gapRect, selectionColor(i->p));
     return gapRect;
 }
 
@@ -1679,11 +1672,8 @@ IntRect RenderBlock::fillLeftSelectionGap(RenderObject* selObj, int xPos, int yP
         return IntRect();
 
     IntRect gapRect(left, top, width, height);
-    if (i) {
-        // Paint the rect.
-        Brush selBrush(selObj->selectionColor(i->p));
-        i->p->fillRect(gapRect, selBrush);
-    }
+    if (i)
+        i->p->fillRect(gapRect, selObj->selectionColor(i->p));
     return gapRect;
 }
 
@@ -1697,11 +1687,8 @@ IntRect RenderBlock::fillRightSelectionGap(RenderObject* selObj, int xPos, int y
         return IntRect();
 
     IntRect gapRect(left, top, width, height);
-    if (i) {
-        // Paint the rect.
-        Brush selBrush(selObj->selectionColor(i->p));
-        i->p->fillRect(gapRect, selBrush);
-    }
+    if (i)
+        i->p->fillRect(gapRect, selObj->selectionColor(i->p));
     return gapRect;
 }
 
index 5815030e797299af93906faaa0edd6b560163331..747ecf4f2b1b193fa527a256b8e545392408eff2 100644 (file)
@@ -626,11 +626,10 @@ void RenderBox::paintBackgroundExtended(GraphicsContext* p, const Color& c, cons
 
         if (cw > 0 && ch > 0) {
             if (bgLayer->backgroundRepeat() == NO_REPEAT) {
-                int imageSizeX = bg->imageSize().width();
-                int imageSizeY = bg->imageSize().height();
-                int originX = cx + int(fmodf(fmodf(-sx, imageSizeX) - imageSizeX, imageSizeX));
-                int originY = cy + int(fmodf(fmodf(-sy, imageSizeY) - imageSizeY, imageSizeY));
-                p->drawImage(bg->image(), IntRect(cx, cy, cw, ch), originX, originY, imageSizeX, imageSizeY);
+                IntSize imageSize = bg->imageSize();
+                int originX = cx + int(fmodf(fmodf(-sx, imageSize.width()) - imageSize.width(), imageSize.width()));
+                int originY = cy + int(fmodf(fmodf(-sy, imageSize.height()) - imageSize.height(), imageSize.height()));
+                p->drawImage(bg->image(), IntRect(cx, cy, cw, ch), IntRect(IntPoint(originX, originY), imageSize));
             } else
                 p->drawTiledImage(bg->image(), IntRect(cx, cy, cw, ch), IntPoint(sx, sy), IntSize(scaledWidth, scaledHeight));
         }
@@ -646,7 +645,7 @@ void RenderBox::paintBackgroundExtended(GraphicsContext* p, const Color& c, cons
 void RenderBox::outlineBox(GraphicsContext* p, int _tx, int _ty, const char* color)
 {
     p->setPen(Pen(Color(color), 1, Pen::DotLine));
-    p->setBrush(WebCore::Brush::NoBrush);
+    p->setFillColor(Color::transparent);
     p->drawRect(IntRect(_tx, _ty, m_width, m_height));
 }
 
index 9a3efdb1d248edc9ace67ecff8488380a70fda1a..7beb84a1edd3076795d80e30f9b5bc639e550e29 100644 (file)
@@ -211,9 +211,9 @@ void RenderImage::paint(PaintInfo& i, int _tx, int _ty)
 
         if (cWidth > 2 && cHeight > 2) {
             if (!errorOccurred()) {
-                p->setPen (Color::lightGray);
-                p->setBrush (WebCore::Brush::NoBrush);
-                p->drawRect (IntRect(_tx + leftBorder + leftPad, _ty + topBorder + topPad, cWidth, cHeight));
+                p->setPen(Color::lightGray);
+                p->setFillColor(Color::transparent);
+                p->drawRect(IntRect(_tx + leftBorder + leftPad, _ty + topBorder + topPad, cWidth, cHeight));
             }
             
             bool errorPictureDrawn = false;
@@ -231,7 +231,7 @@ void RenderImage::paint(PaintInfo& i, int _tx, int _ty)
                     centerY = 0;
                 imageX = leftBorder + leftPad + centerX;
                 imageY = topBorder + topPad + centerY;
-                p->drawImageAtPoint(image(), IntPoint(_tx + imageX, _ty + imageY));
+                p->drawImage(image(), IntPoint(_tx + imageX, _ty + imageY));
                 errorPictureDrawn = true;
             }
             
@@ -250,9 +250,9 @@ void RenderImage::paint(PaintInfo& i, int _tx, int _ty)
                 int textWidth = font.width(text);
                 if (errorPictureDrawn) {
                     if (usableWidth >= textWidth && font.height() <= imageY)
-                        p->drawText(ax, ay+ascent, 0, text);
+                        p->drawText(IntPoint(ax, ay + ascent), 0, text);
                 } else if (usableWidth >= textWidth && cHeight >= font.height())
-                    p->drawText(ax, ay+ascent, 0, text);
+                    p->drawText(IntPoint(ax, ay + ascent), 0, text);
             }
         }
     }
@@ -260,8 +260,8 @@ void RenderImage::paint(PaintInfo& i, int _tx, int _ty)
         IntRect rect(IntPoint(_tx + leftBorder + leftPad, _ty + topBorder + topPad), IntSize(cWidth, cHeight));
         
         HTMLImageElement* imageElt = (element() && element()->hasTagName(imgTag)) ? static_cast<HTMLImageElement*>(element()) : 0;
-        Image::CompositeOperator compositeOperator = imageElt ? imageElt->compositeOperator() : Image::CompositeSourceOver;
-        p->drawImageInRect(image(), rect, compositeOperator);
+        CompositeOperator compositeOperator = imageElt ? imageElt->compositeOperator() : CompositeSourceOver;
+        p->drawImage(image(), rect, compositeOperator);
 
         if (drawSelectionTint)
             p->fillRect(selectionRect(), selectionColor(p));
index 7315b6325156f226303abb726a417948e7d52305..8871113aeec392a1e70e55bb664a6c3c2a1e7f4b 100644 (file)
@@ -1069,10 +1069,8 @@ RenderLayer::paint(GraphicsContext* p, const IntRect& damageRect, bool selection
 
 static void setClip(GraphicsContext* p, const IntRect& paintDirtyRect, const IntRect& clipRect)
 {
-#if __APPLE__
     // Work around bugs in focus ring clipping on Mac.
     p->setFocusRingClip(clipRect);
-#endif
     if (paintDirtyRect == clipRect)
         return;
     p->save();
@@ -1081,10 +1079,8 @@ static void setClip(GraphicsContext* p, const IntRect& paintDirtyRect, const Int
 
 static void restoreClip(GraphicsContext* p, const IntRect& paintDirtyRect, const IntRect& clipRect)
 {
-#if __APPLE__
     // Work around bugs in focus ring clipping on Mac.
     p->clearFocusRingClip();
-#endif
     if (paintDirtyRect == clipRect)
         return;
     p->restore();
index f0964bd9ebce24d611ef65f45f0d28c09ae685c8..168dabbc1625fb4e393a24feec435f9d0d7628bd 100644 (file)
@@ -854,7 +854,7 @@ void RenderObject::drawBorder(GraphicsContext* p, int x1, int y1, int x2, int y2
         if (adjbw1 == 0 && adjbw2 == 0)
         {
             p->setPen(Pen::NoPen);
-            p->setBrush(c);
+            p->setFillColor(c.rgb());
             switch(s)
             {
             case BSTop:
@@ -971,7 +971,7 @@ void RenderObject::drawBorder(GraphicsContext* p, int x1, int y1, int x2, int y2
     case SOLID:
         IntPointArray quad(4);
         p->setPen(Pen::NoPen);
-        p->setBrush(c);
+        p->setFillColor(c.rgb());
         ASSERT(x2 >= x1);
         ASSERT(y2 >= y1);
         if (adjbw1==0 && adjbw2 == 0) {
@@ -1055,19 +1055,19 @@ bool RenderObject::paintBorderImage(GraphicsContext* p, int _tx, int _ty, int w,
         // The rect to use from within the image is obtained from our slice, and is (0, 0, leftSlice, topSlice)
         if (drawTop)
             p->drawImage(borderImage->image(), IntRect(_tx, _ty, style->borderLeftWidth(), style->borderTopWidth()),
-                         0, 0, leftSlice, topSlice);
+                         IntRect(0, 0, leftSlice, topSlice));
         
         // The bottom left corner rect is (_tx, _ty + h - bottomWidth, leftWidth, bottomWidth)
         // The rect to use from within the image is (0, imageHeight - bottomSlice, leftSlice, botomSlice)
         if (drawBottom)
             p->drawImage(borderImage->image(), IntRect(_tx, _ty + h - style->borderBottomWidth(), style->borderLeftWidth(), style->borderBottomWidth()),
-                         0, imageHeight - bottomSlice, leftSlice, bottomSlice);
+                         IntRect(0, imageHeight - bottomSlice, leftSlice, bottomSlice));
                       
         // Paint the left edge.
         // Have to scale and tile into the border rect.
-        p->drawScaledAndTiledImage(borderImage->image(), IntRect(_tx, _ty + style->borderTopWidth(), style->borderLeftWidth(),
+        p->drawTiledImage(borderImage->image(), IntRect(_tx, _ty + style->borderTopWidth(), style->borderLeftWidth(),
                                     h - style->borderTopWidth() - style->borderBottomWidth()),
-                                    0, topSlice, leftSlice, imageHeight - topSlice - bottomSlice, 
+                                    IntRect(0, topSlice, leftSlice, imageHeight - topSlice - bottomSlice),
                                     Image::StretchTile, (Image::TileRule)vRule);
     }
     
@@ -1077,39 +1077,39 @@ bool RenderObject::paintBorderImage(GraphicsContext* p, int _tx, int _ty, int w,
         // The rect to use from within the image is obtained from our slice, and is (imageWidth - rightSlice, 0, rightSlice, topSlice)
         if (drawTop)
             p->drawImage(borderImage->image(), IntRect(_tx + w - style->borderRightWidth(), _ty, style->borderRightWidth(), style->borderTopWidth()),
-                         imageWidth - rightSlice, 0, rightSlice, topSlice);
+                         IntRect(imageWidth - rightSlice, 0, rightSlice, topSlice));
         
         // The bottom right corner rect is (_tx + w - rightWidth, _ty + h - bottomWidth, rightWidth, bottomWidth)
         // The rect to use from within the image is (imageWidth - rightSlice, imageHeight - bottomSlice, rightSlice, botomSlice)
         if (drawBottom)
             p->drawImage(borderImage->image(), IntRect(_tx + w - style->borderRightWidth(), _ty + h - style->borderBottomWidth(), style->borderRightWidth(), style->borderBottomWidth()),
-                         imageWidth - rightSlice, imageHeight - bottomSlice, rightSlice, bottomSlice);
+                         IntRect(imageWidth - rightSlice, imageHeight - bottomSlice, rightSlice, bottomSlice));
                       
         // Paint the right edge.
-        p->drawScaledAndTiledImage(borderImage->image(), IntRect(_tx + w - style->borderRightWidth(), _ty + style->borderTopWidth(), style->borderRightWidth(),
+        p->drawTiledImage(borderImage->image(), IntRect(_tx + w - style->borderRightWidth(), _ty + style->borderTopWidth(), style->borderRightWidth(),
                           h - style->borderTopWidth() - style->borderBottomWidth()),
-                          imageWidth - rightSlice, topSlice, rightSlice, imageHeight - topSlice - bottomSlice,
+                          IntRect(imageWidth - rightSlice, topSlice, rightSlice, imageHeight - topSlice - bottomSlice),
                           Image::StretchTile, (Image::TileRule)vRule);
     }
 
     // Paint the top edge.
     if (drawTop)
-        p->drawScaledAndTiledImage(borderImage->image(), IntRect(_tx + style->borderLeftWidth(), _ty, w - style->borderLeftWidth() - style->borderRightWidth(), style->borderTopWidth()),
-                          leftSlice, 0, imageWidth - rightSlice - leftSlice, topSlice,
+        p->drawTiledImage(borderImage->image(), IntRect(_tx + style->borderLeftWidth(), _ty, w - style->borderLeftWidth() - style->borderRightWidth(), style->borderTopWidth()),
+                          IntRect(leftSlice, 0, imageWidth - rightSlice - leftSlice, topSlice),
                           (Image::TileRule)hRule, Image::StretchTile);
     
     // Paint the bottom edge.
     if (drawBottom)
-        p->drawScaledAndTiledImage(borderImage->image(), IntRect(_tx + style->borderLeftWidth(), _ty + h - style->borderBottomWidth(), 
+        p->drawTiledImage(borderImage->image(), IntRect(_tx + style->borderLeftWidth(), _ty + h - style->borderBottomWidth(), 
                           w - style->borderLeftWidth() - style->borderRightWidth(), style->borderBottomWidth()),
-                          leftSlice, imageHeight - bottomSlice, imageWidth - rightSlice - leftSlice, bottomSlice,
+                          IntRect(leftSlice, imageHeight - bottomSlice, imageWidth - rightSlice - leftSlice, bottomSlice),
                           (Image::TileRule)hRule, Image::StretchTile);
     
     // Paint the middle.
     if (drawMiddle)
-        p->drawScaledAndTiledImage(borderImage->image(), IntRect(_tx + style->borderLeftWidth(), _ty + style->borderTopWidth(), w - style->borderLeftWidth() - style->borderRightWidth(),
+        p->drawTiledImage(borderImage->image(), IntRect(_tx + style->borderLeftWidth(), _ty + style->borderTopWidth(), w - style->borderLeftWidth() - style->borderRightWidth(),
                           h - style->borderTopWidth() - style->borderBottomWidth()),
-                          leftSlice, topSlice, imageWidth - rightSlice - leftSlice, imageHeight - topSlice - bottomSlice,
+                          IntRect(leftSlice, topSlice, imageWidth - rightSlice - leftSlice, imageHeight - topSlice - bottomSlice),
                           (Image::TileRule)hRule, (Image::TileRule)vRule);
 
     // Clear the clip for the border radius.
index 0618eba26b10d4e5f62985a2fd4557b66ca90129..135d447d09086b24525de115b4fb12a10be0c6a7 100644 (file)
@@ -496,39 +496,35 @@ bool RenderFrameSet::userResize( MouseEvent *evt )
     }
     
     else if (m_resizing || evt->type() == mouseupEvent) {
-        FrameView *v = canvas()->view();
-        GraphicsContext paint;
-        
+        FrameView *v = canvas()->view();        
         v->disableFlushDrawing();
-        v->lockDrawingFocus();
-        paint.setPen( Color::gray );
-        paint.setBrush( Color::gray );
+        GraphicsContext* context = v->lockDrawingFocus();
         
         IntRect r(xPos(), yPos(), width(), height());
         const int rBord = 3;
         int sw = element()->border();
         int p = m_resizing ? (m_vSplit > -1 ? _x : _y) : -1;
-        static unsigned greyQuarterOpacity = 0x40A0A0A0;
+        const RGBA32 greyQuarterOpacity = 0x40A0A0A0;
         if (m_vSplit > -1) {
             if (m_oldpos >= 0)
                 v->updateContents(IntRect(m_oldpos + sw/2 - rBord, r.y(), 2 * rBord, r.height()), true);
             if (p >= 0) {
-                paint.setPen(Pen::NoPen);
-                paint.setBrush(greyQuarterOpacity);
-                paint.drawRect(IntRect(p + sw/2 - rBord, r.y(), 2 * rBord, r.height()));
+                context->setPen(Pen::NoPen);
+                context->setFillColor(greyQuarterOpacity);
+                context->drawRect(IntRect(p + sw/2 - rBord, r.y(), 2 * rBord, r.height()));
             }
         } else {
             if (m_oldpos >= 0)
                 v->updateContents(IntRect(r.x(), m_oldpos + sw/2 - rBord, r.width(), 2 * rBord), true);
             if (p >= 0) {
-                paint.setPen(Pen::NoPen);
-                paint.setBrush(greyQuarterOpacity);
-                paint.drawRect(IntRect(r.x(), p + sw/2 - rBord, r.width(), 2 * rBord));
+                context->setPen(Pen::NoPen);
+                context->setFillColor(greyQuarterOpacity);
+                context->drawRect(IntRect(r.x(), p + sw/2 - rBord, r.width(), 2 * rBord));
             }
         }
         m_oldpos = p;
 
-        v->unlockDrawingFocus();
+        v->unlockDrawingFocus(context);
         v->enableFlushDrawing();
     }
     
index be401ace802510e9a43b5eaf66bdda2d2717dc24..fd8c07b6781f547d5fe57b57772a683d54a2558c 100644 (file)
@@ -972,7 +972,7 @@ void InlineFlowBox::paintDecorations(RenderObject::PaintInfo& i, int _tx, int _t
         // FIXME: Support multiple shadow effects.  Need more from the CG API before we can do this.
         bool setShadow = false;
         if (styleToUse->textShadow()) {
-            p->setShadow(styleToUse->textShadow()->x, styleToUse->textShadow()->y,
+            p->setShadow(IntSize(styleToUse->textShadow()->x, styleToUse->textShadow()->y),
                          styleToUse->textShadow()->blur, styleToUse->textShadow()->color);
             setShadow = true;
         }
@@ -990,15 +990,15 @@ void InlineFlowBox::paintDecorations(RenderObject::PaintInfo& i, int _tx, int _t
 
         if (deco & UNDERLINE && !paintedChildren) {
             p->setPen(underline);
-            p->drawLineForText(_tx, _ty, m_baseline, w);
+            p->drawLineForText(IntPoint(_tx, _ty), m_baseline, w);
         }
         if (deco & OVERLINE && !paintedChildren) {
             p->setPen(overline);
-            p->drawLineForText(_tx, _ty, 0, w);
+            p->drawLineForText(IntPoint(_tx, _ty), 0, w);
         }
         if (deco & LINE_THROUGH && paintedChildren) {
             p->setPen(linethrough);
-            p->drawLineForText(_tx, _ty, 2*m_baseline/3, w);
+            p->drawLineForText(IntPoint(_tx, _ty), 2*m_baseline/3, w);
         }
 
         if (setShadow)
@@ -1079,13 +1079,13 @@ void EllipsisBox::paint(RenderObject::PaintInfo& i, int _tx, int _ty)
         p->setPen(textColor);
     bool setShadow = false;
     if (_style->textShadow()) {
-        p->setShadow(_style->textShadow()->x, _style->textShadow()->y,
+        p->setShadow(IntSize(_style->textShadow()->x, _style->textShadow()->y),
                      _style->textShadow()->blur, _style->textShadow()->color);
         setShadow = true;
     }
 
     const String& str = m_str;
-    p->drawText(m_x + _tx, m_y + _ty + m_baseline, 0, 0, str.unicode(), str.length(),
+    p->drawText(IntPoint(m_x + _tx, m_y + _ty + m_baseline), 0, 0, str.unicode(), str.length(),
         0, str.length(), 0, LTR, _style->visuallyOrdered(), 0, str.length());
 
     if (setShadow)
index 702533d2355892b8fd9ec18af4757629a8ba3025..ab3367d13ab54feb27a4cb697b0c14ee546f2153 100644 (file)
@@ -414,7 +414,7 @@ void RenderListMarker::paint(PaintInfo& i, int _tx, int _ty)
     }
 
     if (m_listImage && !m_listImage->isErrorImage()) {
-        p->drawImageAtPoint(m_listImage->image(), marker.location());
+        p->drawImage(m_listImage->image(), marker.location());
         if (selectionState() != SelectionNone)
             p->fillRect(selectionRect(), selectionColor(p));
         return;
@@ -433,15 +433,15 @@ void RenderListMarker::paint(PaintInfo& i, int _tx, int _ty)
 
     switch(style()->listStyleType()) {
     case DISC:
-        p->setBrush(color);
+        p->setFillColor(color.rgb());
         p->drawEllipse(marker);
         return;
     case CIRCLE:
-        p->setBrush(WebCore::Brush::NoBrush);
+        p->setFillColor(Color::transparent);
         p->drawEllipse(marker);
         return;
     case SQUARE:
-        p->setBrush(color);
+        p->setFillColor(color.rgb());
         p->drawRect(marker);
         return;
     case LNONE:
@@ -450,11 +450,11 @@ void RenderListMarker::paint(PaintInfo& i, int _tx, int _ty)
         if (!m_item.isEmpty()) {
             const Font& font = style()->font();
             if( style()->direction() == LTR) {
-                p->drawText(marker.x(), marker.y(), AlignLeft, m_item);
-                p->drawText(marker.x() + font.width(m_item), marker.y(), AlignLeft, ". ");
+                p->drawText(marker.location(), AlignLeft, m_item);
+                p->drawText(marker.location() + IntSize(font.width(m_item), 0), AlignLeft, ". ");
             } else {
-                p->drawText(marker.x(), marker.y(), AlignLeft, " .");
-                p->drawText(marker.x() + font.width(" ."), marker.y(), AlignLeft, m_item);
+                p->drawText(marker.location(), AlignLeft, " .");
+                p->drawText(marker.location() + IntSize(font.width(" ."), 0), AlignLeft, m_item);
             }
         }
     }