2 * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef GraphicsContext_h
27 #define GraphicsContext_h
29 #include "FloatRect.h"
33 #include "TextDirection.h"
34 #include <wtf/Noncopyable.h>
35 #include <unicode/umachine.h>
38 typedef struct CGContext PlatformGraphicsContext;
40 typedef struct HDC__* HDC;
41 typedef struct _cairo PlatformGraphicsContext;
43 typedef void PlatformGraphicsContext;
46 class DeprecatedString;
51 class GraphicsContextPrivate;
52 class GraphicsContextPlatformPrivate;
59 class KRenderingDeviceContext;
62 class GraphicsContext : Noncopyable {
64 GraphicsContext(PlatformGraphicsContext*);
67 PlatformGraphicsContext* platformContext() const;
69 const Font& font() const;
70 void setFont(const Font&);
72 const Pen& pen() const;
73 void setPen(const Pen&);
74 void setPen(Pen::PenStyle);
77 Color fillColor() const;
78 void setFillColor(const Color&);
83 void drawRect(const IntRect&);
84 void drawLine(const IntPoint&, const IntPoint&);
85 void drawEllipse(const IntRect&);
86 void drawArc(int, int, int, int, int, int);
87 void drawConvexPolygon(const IntPointArray&);
89 void fillRect(const IntRect&, const Color&);
90 void clearRect(const FloatRect&);
91 void strokeRect(const FloatRect&, float lineWidth);
93 void drawImage(Image*, const IntPoint&, CompositeOperator = CompositeSourceOver);
94 void drawImage(Image*, const IntRect&, CompositeOperator = CompositeSourceOver);
95 void drawImage(Image*, const IntPoint& destPoint, const IntRect& srcRect, CompositeOperator = CompositeSourceOver);
96 void drawImage(Image*, const IntRect& destRect, const IntRect& srcRect, CompositeOperator = CompositeSourceOver);
97 void drawImage(Image*, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1),
98 CompositeOperator = CompositeSourceOver);
99 void drawTiledImage(Image*, const IntRect& destRect, const IntPoint& srcPoint, const IntSize& tileSize);
100 void drawTiledImage(Image*, const IntRect& destRect, const IntRect& srcRect,
101 Image::TileRule hRule = Image::StretchTile, Image::TileRule vRule = Image::StretchTile);
103 void addClip(const IntRect&);
104 void addRoundedRectClip(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight);
106 // Functions to work around bugs in focus ring clipping on Mac.
107 void setFocusRingClip(const IntRect&);
108 void clearFocusRingClip();
110 void drawText(const TextRun&, const IntPoint&, int tabWidth = 0, int xpos = 0, int toAdd = 0,
111 TextDirection = LTR, bool visuallyOrdered = false);
112 void drawHighlightForText(const TextRun&, const IntPoint&, int h,
113 int tabWidth, int xpos, int toAdd, TextDirection, bool visuallyOrdered, const Color& backgroundColor);
116 void drawLineForText(const IntPoint&, int yOffset, int width);
117 void drawLineForMisspelling(const IntPoint&, int width);
118 int misspellingLineThickness();
120 Color selectedTextBackgroundColor() const;
121 void setUsesInactiveTextBackgroundColor(bool);
122 bool usesInactiveTextBackgroundColor() const;
124 bool paintingDisabled() const;
125 void setPaintingDisabled(bool);
127 bool updatingControlTints() const;
128 void setUpdatingControlTints(bool);
130 void beginTransparencyLayer(float opacity);
131 void endTransparencyLayer();
133 void setShadow(const IntSize&, int blur, const Color&);
136 void initFocusRing(int width, int offset);
137 void addFocusRingRect(const IntRect&);
138 void drawFocusRing(const Color&);
139 void clearFocusRing();
141 void setLineWidth(float);
142 void setLineCap(LineCap);
143 void setLineJoin(LineJoin);
144 void setMiterLimit(float);
146 void setAlpha(float);
148 void setCompositeOperation(CompositeOperator);
150 void clip(const Path&);
152 void scale(const FloatSize&);
153 void rotate(float angleInRadians);
154 void translate(const FloatSize&);
157 KRenderingDeviceContext* createRenderingDeviceContext();
161 GraphicsContext(HDC); // FIXME: To be removed.
165 void savePlatformState();
166 void restorePlatformState();
168 int focusRingWidth() const;
169 int focusRingOffset() const;
170 const Vector<IntRect>& focusRingRects() const;
172 static GraphicsContextPrivate* createGraphicsContextPrivate();
173 static void destroyGraphicsContextPrivate(GraphicsContextPrivate*);
175 GraphicsContextPrivate* m_common;
176 GraphicsContextPlatformPrivate* m_data;