~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/platform/graphics/GraphicsContext.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2003, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
 
3
 * Copyright (C) 2008-2009 Torch Mobile, Inc.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
8
 * 1. Redistributions of source code must retain the above copyright
 
9
 *    notice, this list of conditions and the following disclaimer.
 
10
 * 2. Redistributions in binary form must reproduce the above copyright
 
11
 *    notice, this list of conditions and the following disclaimer in the
 
12
 *    documentation and/or other materials provided with the distribution.
 
13
 *
 
14
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 
15
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
17
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 
18
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
19
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
20
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 
21
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
22
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
23
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
24
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
25
 */
 
26
 
 
27
#ifndef GraphicsContext_h
 
28
#define GraphicsContext_h
 
29
 
 
30
#include "ColorSpace.h"
 
31
#include "DashArray.h"
 
32
#include "FloatRect.h"
 
33
#include "Font.h"
 
34
#include "Gradient.h"
 
35
#include "Image.h"
 
36
#include "ImageOrientation.h"
 
37
#include "Path.h"
 
38
#include "Pattern.h"
 
39
#include <wtf/Noncopyable.h>
 
40
#include <wtf/PassOwnPtr.h>
 
41
 
 
42
#if USE(CG)
 
43
typedef struct CGContext PlatformGraphicsContext;
 
44
#elif USE(CAIRO)
 
45
namespace WebCore {
 
46
class PlatformContextCairo;
 
47
}
 
48
typedef WebCore::PlatformContextCairo PlatformGraphicsContext;
 
49
#elif PLATFORM(OPENVG)
 
50
namespace WebCore {
 
51
class SurfaceOpenVG;
 
52
}
 
53
typedef class WebCore::SurfaceOpenVG PlatformGraphicsContext;
 
54
#elif PLATFORM(QT)
 
55
#include <QPainter>
 
56
namespace WebCore {
 
57
class ShadowBlur;
 
58
}
 
59
typedef QPainter PlatformGraphicsContext;
 
60
#elif PLATFORM(WX)
 
61
class wxGCDC;
 
62
class wxWindowDC;
 
63
 
 
64
// wxGraphicsContext allows us to support Path, etc.
 
65
// but on some platforms, e.g. Linux, it requires fairly
 
66
// new software.
 
67
#if USE(WXGC)
 
68
// On OS X, wxGCDC is just a typedef for wxDC, so use wxDC explicitly to make
 
69
// the linker happy.
 
70
#ifdef __APPLE__
 
71
    class wxDC;
 
72
    typedef wxDC PlatformGraphicsContext;
 
73
#else
 
74
    typedef wxGCDC PlatformGraphicsContext;
 
75
#endif
 
76
#else
 
77
    typedef wxWindowDC PlatformGraphicsContext;
 
78
#endif
 
79
#elif USE(SKIA)
 
80
namespace WebCore {
 
81
class PlatformContextSkia;
 
82
typedef PlatformContextSkia GraphicsContextPlatformPrivate;
 
83
}
 
84
typedef WebCore::PlatformContextSkia PlatformGraphicsContext;
 
85
#elif OS(WINCE)
 
86
typedef struct HDC__ PlatformGraphicsContext;
 
87
#else
 
88
typedef void PlatformGraphicsContext;
 
89
#endif
 
90
 
 
91
#if PLATFORM(WIN)
 
92
#include "DIBPixelData.h"
 
93
typedef struct HDC__* HDC;
 
94
#if !USE(CG)
 
95
// UInt8 is defined in CoreFoundation/CFBase.h
 
96
typedef unsigned char UInt8;
 
97
#endif
 
98
#endif
 
99
 
 
100
#if PLATFORM(QT) && OS(WINDOWS)
 
101
#include <windows.h>
 
102
#endif
 
103
 
 
104
namespace WebCore {
 
105
 
 
106
#if OS(WINCE) && !PLATFORM(QT)
 
107
    class SharedBitmap;
 
108
    class SimpleFontData;
 
109
    class GlyphBuffer;
 
110
#endif
 
111
 
 
112
    const int cMisspellingLineThickness = 3;
 
113
    const int cMisspellingLinePatternWidth = 4;
 
114
    const int cMisspellingLinePatternGapWidth = 1;
 
115
 
 
116
    class AffineTransform;
 
117
    class DrawingBuffer;
 
118
    class Generator;
 
119
#if !USE(SKIA)
 
120
    class GraphicsContextPlatformPrivate;
 
121
#endif
 
122
    class ImageBuffer;
 
123
    class IntRect;
 
124
    class RoundedRect;
 
125
    class KURL;
 
126
    class GraphicsContext3D;
 
127
    class TextRun;
 
128
    class TransformationMatrix;
 
129
 
 
130
    enum TextDrawingMode {
 
131
        TextModeFill      = 1 << 0,
 
132
        TextModeStroke    = 1 << 1,
 
133
    };
 
134
    typedef unsigned TextDrawingModeFlags;
 
135
 
 
136
    enum StrokeStyle {
 
137
        NoStroke,
 
138
        SolidStroke,
 
139
        DottedStroke,
 
140
        DashedStroke,
 
141
#if ENABLE(CSS3_TEXT)
 
142
        DoubleStroke,
 
143
        WavyStroke,
 
144
#endif // CSS3_TEXT
 
145
    };
 
146
 
 
147
    enum InterpolationQuality {
 
148
        InterpolationDefault,
 
149
        InterpolationNone,
 
150
        InterpolationLow,
 
151
        InterpolationMedium,
 
152
        InterpolationHigh
 
153
    };
 
154
 
 
155
    struct GraphicsContextState {
 
156
        GraphicsContextState()
 
157
            : strokeThickness(0)
 
158
            , shadowBlur(0)
 
159
            , textDrawingMode(TextModeFill)
 
160
            , strokeColor(Color::black)
 
161
            , fillColor(Color::black)
 
162
            , strokeStyle(SolidStroke)
 
163
            , fillRule(RULE_NONZERO)
 
164
            , strokeColorSpace(ColorSpaceDeviceRGB)
 
165
            , fillColorSpace(ColorSpaceDeviceRGB)
 
166
            , shadowColorSpace(ColorSpaceDeviceRGB)
 
167
            , compositeOperator(CompositeSourceOver)
 
168
            , shouldAntialias(true)
 
169
            , shouldSmoothFonts(true)
 
170
            , shouldSubpixelQuantizeFonts(true)
 
171
            , paintingDisabled(false)
 
172
            , shadowsIgnoreTransforms(false)
 
173
#if USE(CG)
 
174
            // Core Graphics incorrectly renders shadows with radius > 8px (<rdar://problem/8103442>),
 
175
            // but we need to preserve this buggy behavior for canvas and -webkit-box-shadow.
 
176
            , shadowsUseLegacyRadius(false)
 
177
#endif
 
178
        {
 
179
        }
 
180
 
 
181
        RefPtr<Gradient> strokeGradient;
 
182
        RefPtr<Pattern> strokePattern;
 
183
        
 
184
        RefPtr<Gradient> fillGradient;
 
185
        RefPtr<Pattern> fillPattern;
 
186
 
 
187
        FloatSize shadowOffset;
 
188
 
 
189
        float strokeThickness;
 
190
        float shadowBlur;
 
191
 
 
192
        TextDrawingModeFlags textDrawingMode;
 
193
 
 
194
        Color strokeColor;
 
195
        Color fillColor;
 
196
        Color shadowColor;
 
197
 
 
198
        StrokeStyle strokeStyle;
 
199
        WindRule fillRule;
 
200
 
 
201
        ColorSpace strokeColorSpace;
 
202
        ColorSpace fillColorSpace;
 
203
        ColorSpace shadowColorSpace;
 
204
 
 
205
        CompositeOperator compositeOperator;
 
206
 
 
207
        bool shouldAntialias : 1;
 
208
        bool shouldSmoothFonts : 1;
 
209
        bool shouldSubpixelQuantizeFonts : 1;
 
210
        bool paintingDisabled : 1;
 
211
        bool shadowsIgnoreTransforms : 1;
 
212
#if USE(CG)
 
213
        bool shadowsUseLegacyRadius : 1;
 
214
#endif
 
215
    };
 
216
 
 
217
    class GraphicsContext {
 
218
        WTF_MAKE_NONCOPYABLE(GraphicsContext); WTF_MAKE_FAST_ALLOCATED;
 
219
    public:
 
220
        GraphicsContext(PlatformGraphicsContext*);
 
221
        ~GraphicsContext();
 
222
 
 
223
#if !OS(WINCE) || PLATFORM(QT)
 
224
        PlatformGraphicsContext* platformContext() const;
 
225
#endif
 
226
 
 
227
        float strokeThickness() const;
 
228
        void setStrokeThickness(float);
 
229
        StrokeStyle strokeStyle() const;
 
230
        void setStrokeStyle(StrokeStyle);
 
231
        Color strokeColor() const;
 
232
        ColorSpace strokeColorSpace() const;
 
233
        void setStrokeColor(const Color&, ColorSpace);
 
234
 
 
235
        void setStrokePattern(PassRefPtr<Pattern>);
 
236
        Pattern* strokePattern() const;
 
237
 
 
238
        void setStrokeGradient(PassRefPtr<Gradient>);
 
239
        Gradient* strokeGradient() const;
 
240
 
 
241
        WindRule fillRule() const;
 
242
        void setFillRule(WindRule);
 
243
        Color fillColor() const;
 
244
        ColorSpace fillColorSpace() const;
 
245
        void setFillColor(const Color&, ColorSpace);
 
246
 
 
247
        void setFillPattern(PassRefPtr<Pattern>);
 
248
        Pattern* fillPattern() const;
 
249
 
 
250
        void setFillGradient(PassRefPtr<Gradient>);
 
251
        Gradient* fillGradient() const;
 
252
 
 
253
        void setShadowsIgnoreTransforms(bool);
 
254
        bool shadowsIgnoreTransforms() const;
 
255
 
 
256
        void setShouldAntialias(bool);
 
257
        bool shouldAntialias() const;
 
258
 
 
259
        void setShouldSmoothFonts(bool);
 
260
        bool shouldSmoothFonts() const;
 
261
 
 
262
        // Normally CG enables subpixel-quantization because it improves the performance of aligning glyphs.
 
263
        // In some cases we have to disable to to ensure a high-quality output of the glyphs.
 
264
        void setShouldSubpixelQuantizeFonts(bool);
 
265
        bool shouldSubpixelQuantizeFonts() const;
 
266
 
 
267
        const GraphicsContextState& state() const;
 
268
 
 
269
#if USE(CG)
 
270
        void applyStrokePattern();
 
271
        void applyFillPattern();
 
272
        void drawPath(const Path&);
 
273
 
 
274
        void drawNativeImage(NativeImagePtr, const FloatSize& selfSize, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator = CompositeSourceOver, ImageOrientation = DefaultImageOrientation);
 
275
 
 
276
        // Allow font smoothing (LCD antialiasing). Not part of the graphics state.
 
277
        void setAllowsFontSmoothing(bool);
 
278
        
 
279
        void setIsCALayerContext(bool);
 
280
        bool isCALayerContext() const;
 
281
 
 
282
        void setIsAcceleratedContext(bool);
 
283
#endif
 
284
        bool isAcceleratedContext() const;
 
285
 
 
286
        void save();
 
287
        void restore();
 
288
 
 
289
        // These draw methods will do both stroking and filling.
 
290
        // FIXME: ...except drawRect(), which fills properly but always strokes
 
291
        // using a 1-pixel stroke inset from the rect borders (of the correct
 
292
        // stroke color).
 
293
        void drawRect(const IntRect&);
 
294
        void drawLine(const IntPoint&, const IntPoint&);
 
295
        void drawEllipse(const IntRect&);
 
296
        void drawConvexPolygon(size_t numPoints, const FloatPoint*, bool shouldAntialias = false);
 
297
 
 
298
        void fillPath(const Path&);
 
299
        void strokePath(const Path&);
 
300
 
 
301
        void fillEllipse(const FloatRect&);
 
302
        void strokeEllipse(const FloatRect&);
 
303
 
 
304
        // Arc drawing (used by border-radius in CSS) just supports stroking at the moment.
 
305
        void strokeArc(const IntRect&, int startAngle, int angleSpan);
 
306
 
 
307
        void fillRect(const FloatRect&);
 
308
        void fillRect(const FloatRect&, const Color&, ColorSpace);
 
309
        void fillRect(const FloatRect&, Generator&);
 
310
        void fillRect(const FloatRect&, const Color&, ColorSpace, CompositeOperator);
 
311
        void fillRoundedRect(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color&, ColorSpace);
 
312
        void fillRoundedRect(const RoundedRect&, const Color&, ColorSpace);
 
313
        void fillRectWithRoundedHole(const IntRect&, const RoundedRect& roundedHoleRect, const Color&, ColorSpace);
 
314
 
 
315
        void clearRect(const FloatRect&);
 
316
 
 
317
        void strokeRect(const FloatRect&, float lineWidth);
 
318
 
 
319
        void drawImage(Image*, ColorSpace styleColorSpace, const IntPoint&, CompositeOperator = CompositeSourceOver, RespectImageOrientationEnum = DoNotRespectImageOrientation);
 
320
        void drawImage(Image*, ColorSpace styleColorSpace, const IntRect&, CompositeOperator = CompositeSourceOver, RespectImageOrientationEnum = DoNotRespectImageOrientation, bool useLowQualityScale = false);
 
321
        void drawImage(Image*, ColorSpace styleColorSpace, const IntPoint& destPoint, const IntRect& srcRect, CompositeOperator = CompositeSourceOver, RespectImageOrientationEnum = DoNotRespectImageOrientation);
 
322
        void drawImage(Image*, ColorSpace styleColorSpace, const IntRect& destRect, const IntRect& srcRect, CompositeOperator = CompositeSourceOver, RespectImageOrientationEnum = DoNotRespectImageOrientation, bool useLowQualityScale = false);
 
323
        void drawImage(Image*, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1),
 
324
                       CompositeOperator = CompositeSourceOver, RespectImageOrientationEnum = DoNotRespectImageOrientation, bool useLowQualityScale = false);
 
325
        void drawTiledImage(Image*, ColorSpace styleColorSpace, const IntRect& destRect, const IntPoint& srcPoint, const IntSize& tileSize,
 
326
                       CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
 
327
        void drawTiledImage(Image*, ColorSpace styleColorSpace, const IntRect& destRect, const IntRect& srcRect,
 
328
                            const FloatSize& tileScaleFactor, Image::TileRule hRule = Image::StretchTile, Image::TileRule vRule = Image::StretchTile,
 
329
                            CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
 
330
 
 
331
        void drawImageBuffer(ImageBuffer*, ColorSpace styleColorSpace, const IntPoint&, CompositeOperator = CompositeSourceOver);
 
332
        void drawImageBuffer(ImageBuffer*, ColorSpace styleColorSpace, const IntRect&, CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
 
333
        void drawImageBuffer(ImageBuffer*, ColorSpace styleColorSpace, const IntPoint& destPoint, const IntRect& srcRect, CompositeOperator = CompositeSourceOver);
 
334
        void drawImageBuffer(ImageBuffer*, ColorSpace styleColorSpace, const IntRect& destRect, const IntRect& srcRect, CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
 
335
        void drawImageBuffer(ImageBuffer*, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1),
 
336
                             CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
 
337
 
 
338
        void setImageInterpolationQuality(InterpolationQuality);
 
339
        InterpolationQuality imageInterpolationQuality() const;
 
340
 
 
341
        void clip(const IntRect&);
 
342
        void clip(const FloatRect&);
 
343
        void addRoundedRectClip(const RoundedRect&);
 
344
        void addInnerRoundedRectClip(const IntRect&, int thickness);
 
345
        void clipOut(const IntRect&);
 
346
        void clipOutRoundedRect(const RoundedRect&);
 
347
        void clipPath(const Path&, WindRule);
 
348
        void clipConvexPolygon(size_t numPoints, const FloatPoint*, bool antialias = true);
 
349
        void clipToImageBuffer(ImageBuffer*, const FloatRect&);
 
350
        
 
351
        IntRect clipBounds() const;
 
352
 
 
353
        TextDrawingModeFlags textDrawingMode() const;
 
354
        void setTextDrawingMode(TextDrawingModeFlags);
 
355
 
 
356
        void drawText(const Font&, const TextRun&, const FloatPoint&, int from = 0, int to = -1);
 
357
        void drawEmphasisMarks(const Font&, const TextRun& , const AtomicString& mark, const FloatPoint&, int from = 0, int to = -1);
 
358
        void drawBidiText(const Font&, const TextRun&, const FloatPoint&, Font::CustomFontNotReadyAction = Font::DoNotPaintIfFontNotReady);
 
359
        void drawHighlightForText(const Font&, const TextRun&, const FloatPoint&, int h, const Color& backgroundColor, ColorSpace, int from = 0, int to = -1);
 
360
 
 
361
        enum RoundingMode {
 
362
            RoundAllSides,
 
363
            RoundOriginAndDimensions
 
364
        };
 
365
        FloatRect roundToDevicePixels(const FloatRect&, RoundingMode = RoundAllSides);
 
366
 
 
367
        void drawLineForText(const FloatPoint&, float width, bool printing);
 
368
        enum DocumentMarkerLineStyle {
 
369
            DocumentMarkerSpellingLineStyle,
 
370
            DocumentMarkerGrammarLineStyle,
 
371
            DocumentMarkerAutocorrectionReplacementLineStyle,
 
372
            DocumentMarkerDictationAlternativesLineStyle
 
373
        };
 
374
        void drawLineForDocumentMarker(const FloatPoint&, float width, DocumentMarkerLineStyle);
 
375
 
 
376
        bool paintingDisabled() const;
 
377
        void setPaintingDisabled(bool);
 
378
 
 
379
        bool updatingControlTints() const;
 
380
        void setUpdatingControlTints(bool);
 
381
 
 
382
        void beginTransparencyLayer(float opacity);
 
383
        void endTransparencyLayer();
 
384
        bool isInTransparencyLayer() const;
 
385
 
 
386
        bool hasShadow() const;
 
387
        void setShadow(const FloatSize&, float blur, const Color&, ColorSpace);
 
388
        // Legacy shadow blur radius is used for canvas, and -webkit-box-shadow.
 
389
        // It has different treatment of radii > 8px.
 
390
        void setLegacyShadow(const FloatSize&, float blur, const Color&, ColorSpace);
 
391
 
 
392
        bool getShadow(FloatSize&, float&, Color&, ColorSpace&) const;
 
393
        void clearShadow();
 
394
 
 
395
        void drawFocusRing(const Vector<IntRect>&, int width, int offset, const Color&);
 
396
        void drawFocusRing(const Path&, int width, int offset, const Color&);
 
397
 
 
398
        void setLineCap(LineCap);
 
399
        void setLineDash(const DashArray&, float dashOffset);
 
400
        void setLineJoin(LineJoin);
 
401
        void setMiterLimit(float);
 
402
 
 
403
        void setAlpha(float);
 
404
 
 
405
        void setCompositeOperation(CompositeOperator);
 
406
        CompositeOperator compositeOperation() const;
 
407
 
 
408
        void clip(const Path&);
 
409
 
 
410
        // This clip function is used only by <canvas> code. It allows
 
411
        // implementations to handle clipping on the canvas differently since
 
412
        // the discipline is different.
 
413
        void canvasClip(const Path&);
 
414
        void clipOut(const Path&);
 
415
 
 
416
        void scale(const FloatSize&);
 
417
        void rotate(float angleInRadians);
 
418
        void translate(const FloatSize& size) { translate(size.width(), size.height()); }
 
419
        void translate(float x, float y);
 
420
 
 
421
        void setURLForRect(const KURL&, const IntRect&);
 
422
 
 
423
        void concatCTM(const AffineTransform&);
 
424
        void setCTM(const AffineTransform&);
 
425
 
 
426
        enum IncludeDeviceScale { DefinitelyIncludeDeviceScale, PossiblyIncludeDeviceScale };
 
427
        AffineTransform getCTM(IncludeDeviceScale includeScale = PossiblyIncludeDeviceScale) const;
 
428
 
 
429
#if ENABLE(3D_RENDERING) && USE(TEXTURE_MAPPER)
 
430
        // This is needed when using accelerated-compositing in software mode, like in TextureMapper.
 
431
        void concat3DTransform(const TransformationMatrix&);
 
432
        void set3DTransform(const TransformationMatrix&);
 
433
        TransformationMatrix get3DTransform() const;
 
434
#endif
 
435
        // Create an image buffer compatible with this context, with suitable resolution
 
436
        // for drawing into the buffer and then into this context.
 
437
        PassOwnPtr<ImageBuffer> createCompatibleBuffer(const IntSize&) const;
 
438
        bool isCompatibleWithBuffer(ImageBuffer*) const;
 
439
 
 
440
        // This function applies the device scale factor to the context, making the context capable of
 
441
        // acting as a base-level context for a HiDPI environment.
 
442
        void applyDeviceScaleFactor(float);
 
443
        void platformApplyDeviceScaleFactor(float);
 
444
 
 
445
#if OS(WINDOWS)
 
446
        HDC getWindowsContext(const IntRect&, bool supportAlphaBlend, bool mayCreateBitmap); // The passed in rect is used to create a bitmap for compositing inside transparency layers.
 
447
        void releaseWindowsContext(HDC, const IntRect&, bool supportAlphaBlend, bool mayCreateBitmap); // The passed in HDC should be the one handed back by getWindowsContext.
 
448
#if PLATFORM(WIN)
 
449
#if OS(WINCE)
 
450
        void setBitmap(PassRefPtr<SharedBitmap>);
 
451
        const AffineTransform& affineTransform() const;
 
452
        AffineTransform& affineTransform();
 
453
        void resetAffineTransform();
 
454
        void fillRect(const FloatRect&, const Gradient*);
 
455
        void drawText(const SimpleFontData* fontData, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point);
 
456
        void drawFrameControl(const IntRect& rect, unsigned type, unsigned state);
 
457
        void drawFocusRect(const IntRect& rect);
 
458
        void paintTextField(const IntRect& rect, unsigned state);
 
459
        void drawBitmap(SharedBitmap*, const IntRect& dstRect, const IntRect& srcRect, ColorSpace styleColorSpace, CompositeOperator compositeOp);
 
460
        void drawBitmapPattern(SharedBitmap*, const FloatRect& tileRectIn, const AffineTransform& patternTransform, const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect, const IntSize& origSourceSize);
 
461
        void drawIcon(HICON icon, const IntRect& dstRect, UINT flags);
 
462
        void drawRoundCorner(bool newClip, RECT clipRect, RECT rectWin, HDC dc, int width, int height);
 
463
#else
 
464
        GraphicsContext(HDC, bool hasAlpha = false); // FIXME: To be removed.
 
465
 
 
466
        // When set to true, child windows should be rendered into this context
 
467
        // rather than allowing them just to render to the screen. Defaults to
 
468
        // false.
 
469
        // FIXME: This is a layering violation. GraphicsContext shouldn't know
 
470
        // what a "window" is. It would be much more appropriate for this flag
 
471
        // to be passed as a parameter alongside the GraphicsContext, but doing
 
472
        // that would require lots of changes in cross-platform code that we
 
473
        // aren't sure we want to make.
 
474
        void setShouldIncludeChildWindows(bool);
 
475
        bool shouldIncludeChildWindows() const;
 
476
 
 
477
        class WindowsBitmap {
 
478
            WTF_MAKE_NONCOPYABLE(WindowsBitmap);
 
479
        public:
 
480
            WindowsBitmap(HDC, const IntSize&);
 
481
            ~WindowsBitmap();
 
482
 
 
483
            HDC hdc() const { return m_hdc; }
 
484
            UInt8* buffer() const { return m_pixelData.buffer(); }
 
485
            unsigned bufferLength() const { return m_pixelData.bufferLength(); }
 
486
            const IntSize& size() const { return m_pixelData.size(); }
 
487
            unsigned bytesPerRow() const { return m_pixelData.bytesPerRow(); }
 
488
            unsigned short bitsPerPixel() const { return m_pixelData.bitsPerPixel(); }
 
489
            const DIBPixelData& windowsDIB() const { return m_pixelData; }
 
490
 
 
491
        private:
 
492
            HDC m_hdc;
 
493
            HBITMAP m_bitmap;
 
494
            DIBPixelData m_pixelData;
 
495
        };
 
496
 
 
497
        PassOwnPtr<WindowsBitmap> createWindowsBitmap(const IntSize&);
 
498
        // The bitmap should be non-premultiplied.
 
499
        void drawWindowsBitmap(WindowsBitmap*, const IntPoint&);
 
500
#endif
 
501
#else // PLATFORM(WIN)
 
502
        bool shouldIncludeChildWindows() const { return false; }
 
503
#endif // PLATFORM(WIN)
 
504
#endif // OS(WINDOWS)
 
505
 
 
506
#if PLATFORM(WX)
 
507
        // This is needed because of a bug whereby getting an HDC from a GDI+ context
 
508
        // loses the scale operations applied to the context.
 
509
        FloatSize currentScale(); 
 
510
#endif
 
511
 
 
512
#if PLATFORM(QT)
 
513
        void pushTransparencyLayerInternal(const QRect&, qreal, QPixmap&);
 
514
        void takeOwnershipOfPlatformContext();
 
515
#endif
 
516
 
 
517
#if PLATFORM(QT)
 
518
        ShadowBlur* shadowBlur();
 
519
#endif
 
520
 
 
521
#if USE(CAIRO)
 
522
        GraphicsContext(cairo_t*);
 
523
#endif
 
524
 
 
525
#if PLATFORM(GTK)
 
526
        void setGdkExposeEvent(GdkEventExpose*);
 
527
        GdkWindow* gdkWindow() const;
 
528
        GdkEventExpose* gdkExposeEvent() const;
 
529
#endif
 
530
 
 
531
        static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, StrokeStyle);
 
532
 
 
533
    private:
 
534
        void platformInit(PlatformGraphicsContext*);
 
535
        void platformDestroy();
 
536
 
 
537
#if PLATFORM(WIN) && !OS(WINCE)
 
538
        void platformInit(HDC, bool hasAlpha = false);
 
539
#endif
 
540
 
 
541
        void savePlatformState();
 
542
        void restorePlatformState();
 
543
 
 
544
        void setPlatformTextDrawingMode(TextDrawingModeFlags);
 
545
        void setPlatformFont(const Font& font);
 
546
 
 
547
        void setPlatformStrokeColor(const Color&, ColorSpace);
 
548
        void setPlatformStrokeStyle(StrokeStyle);
 
549
        void setPlatformStrokeThickness(float);
 
550
 
 
551
        void setPlatformFillColor(const Color&, ColorSpace);
 
552
 
 
553
        void setPlatformShouldAntialias(bool);
 
554
        void setPlatformShouldSmoothFonts(bool);
 
555
 
 
556
        void setPlatformShadow(const FloatSize&, float blur, const Color&, ColorSpace);
 
557
        void clearPlatformShadow();
 
558
 
 
559
        void setPlatformCompositeOperation(CompositeOperator);
 
560
 
 
561
        void beginPlatformTransparencyLayer(float opacity);
 
562
        void endPlatformTransparencyLayer();
 
563
        static bool supportsTransparencyLayers();
 
564
 
 
565
        void fillEllipseAsPath(const FloatRect&);
 
566
        void strokeEllipseAsPath(const FloatRect&);
 
567
 
 
568
        void platformFillEllipse(const FloatRect&);
 
569
        void platformStrokeEllipse(const FloatRect&);
 
570
 
 
571
        GraphicsContextPlatformPrivate* m_data;
 
572
 
 
573
        GraphicsContextState m_state;
 
574
        Vector<GraphicsContextState> m_stack;
 
575
        bool m_updatingControlTints;
 
576
        unsigned m_transparencyCount;
 
577
    };
 
578
 
 
579
    class GraphicsContextStateSaver {
 
580
        WTF_MAKE_FAST_ALLOCATED;
 
581
    public:
 
582
        GraphicsContextStateSaver(GraphicsContext& context, bool saveAndRestore = true)
 
583
        : m_context(context)
 
584
        , m_saveAndRestore(saveAndRestore)
 
585
        {
 
586
            if (m_saveAndRestore)
 
587
                m_context.save();
 
588
        }
 
589
        
 
590
        ~GraphicsContextStateSaver()
 
591
        {
 
592
            if (m_saveAndRestore)
 
593
                m_context.restore();
 
594
        }
 
595
        
 
596
        void save()
 
597
        {
 
598
            ASSERT(!m_saveAndRestore);
 
599
            m_context.save();
 
600
            m_saveAndRestore = true;
 
601
        }
 
602
 
 
603
        void restore()
 
604
        {
 
605
            ASSERT(m_saveAndRestore);
 
606
            m_context.restore();
 
607
            m_saveAndRestore = false;
 
608
        }
 
609
        
 
610
        GraphicsContext* context() const { return &m_context; }
 
611
 
 
612
    private:
 
613
        GraphicsContext& m_context;
 
614
        bool m_saveAndRestore;
 
615
    };
 
616
 
 
617
} // namespace WebCore
 
618
 
 
619
#endif // GraphicsContext_h
 
620