1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is the Mozilla SVG project.
17 * The Initial Developer of the Original Code is
18 * Crocodile Clips Ltd..
19 * Portions created by the Initial Developer are Copyright (C) 2002
20 * the Initial Developer. All Rights Reserved.
23 * Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef __NS_SVGGLYPHFRAME_H__
40 #define __NS_SVGGLYPHFRAME_H__
42 #include "nsSVGGeometryFrame.h"
43 #include "nsISVGGlyphFragmentLeaf.h"
44 #include "nsISVGChildFrame.h"
45 #include "gfxContext.h"
49 class nsSVGGlyphFrame
;
50 class CharacterIterator
;
51 struct CharacterPosition
;
53 typedef nsSVGGeometryFrame nsSVGGlyphFrameBase
;
55 class nsSVGGlyphFrame
: public nsSVGGlyphFrameBase
,
56 public nsISVGGlyphFragmentLeaf
, // : nsISVGGlyphFragmentNode
57 public nsISVGChildFrame
60 NS_NewSVGGlyphFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
,
61 nsIFrame
* parentFrame
, nsStyleContext
* aContext
);
63 nsSVGGlyphFrame(nsStyleContext
* aContext
)
64 : nsSVGGlyphFrameBase(aContext
),
66 mWhitespaceHandling(COMPRESS_WHITESPACE
)
74 // nsISupports interface:
75 NS_IMETHOD
QueryInterface(const nsIID
& aIID
, void** aInstancePtr
);
76 NS_IMETHOD_(nsrefcnt
) AddRef() { return 1; }
77 NS_IMETHOD_(nsrefcnt
) Release() { return 1; }
79 // nsIFrame interface:
80 NS_IMETHOD
CharacterDataChanged(nsPresContext
* aPresContext
,
84 virtual void DidSetStyleContext(nsStyleContext
* aOldStyleContext
);
86 NS_IMETHOD
SetSelected(nsPresContext
* aPresContext
,
91 NS_IMETHOD
GetSelected(PRBool
*aSelected
) const;
92 NS_IMETHOD
IsSelectable(PRBool
* aIsSelectable
, PRUint8
* aSelectStyle
) const;
95 * Get the "type" of the frame
97 * @see nsGkAtoms::svgGlyphFrame
99 virtual nsIAtom
* GetType() const;
101 virtual PRBool
IsFrameOfType(PRUint32 aFlags
) const
103 // Set the frame state bit for text frames to mark them as replaced.
104 // XXX kipp: temporary
106 return nsSVGGlyphFrameBase::IsFrameOfType(aFlags
& ~(nsIFrame::eReplaced
));
110 NS_IMETHOD
GetFrameName(nsAString
& aResult
) const
112 return MakeFrameName(NS_LITERAL_STRING("SVGGlyph"), aResult
);
116 // nsISVGChildFrame interface:
117 // These four always use the global transform, even if NS_STATE_NONDISPLAY_CHILD
118 NS_IMETHOD
PaintSVG(nsSVGRenderState
*aContext
,
119 const nsIntRect
*aDirtyRect
);
120 NS_IMETHOD_(nsIFrame
*) GetFrameForPoint(const nsPoint
&aPoint
);
121 NS_IMETHOD
UpdateCoveredRegion();
122 NS_IMETHOD
GetBBox(nsIDOMSVGRect
**_retval
);
124 NS_IMETHOD_(nsRect
) GetCoveredRegion();
125 NS_IMETHOD
InitialUpdate();
126 virtual void NotifySVGChanged(PRUint32 aFlags
);
127 NS_IMETHOD
NotifyRedrawSuspended();
128 NS_IMETHOD
NotifyRedrawUnsuspended();
129 NS_IMETHOD
SetMatrixPropagation(PRBool aPropagate
);
130 virtual PRBool
GetMatrixPropagation();
131 NS_IMETHOD_(PRBool
) IsDisplayContainer() { return PR_FALSE
; }
132 NS_IMETHOD_(PRBool
) HasValidCoveredRect() { return PR_TRUE
; }
134 // nsSVGGeometryFrame methods
135 NS_IMETHOD
GetCanvasTM(nsIDOMSVGMatrix
* *aCTM
);
137 // nsISVGGlyphFragmentLeaf interface:
138 // These do not use the global transform if NS_STATE_NONDISPLAY_CHILD
139 NS_IMETHOD
GetStartPositionOfChar(PRUint32 charnum
, nsIDOMSVGPoint
**_retval
);
140 NS_IMETHOD
GetEndPositionOfChar(PRUint32 charnum
, nsIDOMSVGPoint
**_retval
);
141 NS_IMETHOD
GetExtentOfChar(PRUint32 charnum
, nsIDOMSVGRect
**_retval
);
142 NS_IMETHOD
GetRotationOfChar(PRUint32 charnum
, float *_retval
);
144 * @param aForceGlobalTransform controls whether to use the
145 * global transform even when NS_STATE_NONDISPLAY_CHILD
147 NS_IMETHOD_(float) GetBaselineOffset(PRUint16 baselineIdentifier
,
148 PRBool aForceGlobalTransform
);
150 * @param aForceGlobalTransform controls whether to use the
151 * global transform even when NS_STATE_NONDISPLAY_CHILD
153 NS_IMETHOD_(float) GetAdvance(PRBool aForceGlobalTransform
);
155 NS_IMETHOD_(void) SetGlyphPosition(float x
, float y
);
156 NS_IMETHOD_(nsSVGTextPathFrame
*) FindTextPathParent();
157 NS_IMETHOD_(PRBool
) IsStartOfChunk(); // == is new absolutely positioned chunk.
158 NS_IMETHOD_(void) GetAdjustedPosition(/* inout */ float &x
, /* inout */ float &y
);
160 NS_IMETHOD_(already_AddRefed
<nsIDOMSVGLengthList
>) GetX();
161 NS_IMETHOD_(already_AddRefed
<nsIDOMSVGLengthList
>) GetY();
162 NS_IMETHOD_(already_AddRefed
<nsIDOMSVGLengthList
>) GetDx();
163 NS_IMETHOD_(already_AddRefed
<nsIDOMSVGLengthList
>) GetDy();
164 NS_IMETHOD_(PRUint16
) GetTextAnchor();
165 NS_IMETHOD_(PRBool
) IsAbsolutelyPositioned();
167 // nsISVGGlyphFragmentNode interface:
168 // These do not use the global transform if NS_STATE_NONDISPLAY_CHILD
169 NS_IMETHOD_(PRUint32
) GetNumberOfChars();
170 NS_IMETHOD_(float) GetComputedTextLength();
171 NS_IMETHOD_(float) GetSubStringLength(PRUint32 charnum
, PRUint32 fragmentChars
);
172 NS_IMETHOD_(PRInt32
) GetCharNumAtPosition(nsIDOMSVGPoint
*point
);
173 NS_IMETHOD_(nsISVGGlyphFragmentLeaf
*) GetFirstGlyphFragment();
174 NS_IMETHOD_(nsISVGGlyphFragmentLeaf
*) GetNextGlyphFragment();
175 NS_IMETHOD_(void) SetWhitespaceHandling(PRUint8 aWhitespaceHandling
);
178 friend class CharacterIterator
;
180 // Use a power of 2 here. It's not so important to match
181 // nsIDeviceContext::AppUnitsPerDevPixel, but since we do a lot of
182 // multiplying by 1/GetTextRunUnitsFactor, it's good for it to be a
183 // power of 2 to avoid accuracy loss.
184 static PRUint32
GetTextRunUnitsFactor() { return 64; }
187 * @aParam aDrawScale font drawing must be scaled into user units
189 * @param aMetricsScale font metrics must be scaled into user units
191 * @param aForceGlobalTransform set to true if we should force use of
192 * the global transform; otherwise we won't use the global transform
193 * if we're a NONDISPLAY_CHILD
195 PRBool
EnsureTextRun(float *aDrawScale
, float *aMetricsScale
,
196 PRBool aForceGlobalTransform
);
199 PRBool
GetCharacterData(nsAString
& aCharacterData
);
200 PRBool
GetCharacterPositions(nsTArray
<CharacterPosition
>* aCharacterPositions
,
201 float aMetricsScale
);
203 void AddCharactersToPath(CharacterIterator
*aIter
,
204 gfxContext
*aContext
);
205 void AddBoundingBoxesToPath(CharacterIterator
*aIter
,
206 gfxContext
*aContext
);
207 void FillCharacters(CharacterIterator
*aIter
,
208 gfxContext
*aContext
);
210 void NotifyGlyphMetricsChange();
211 PRBool
ContainsPoint(const nsPoint
&aPoint
);
212 PRBool
GetGlobalTransform(gfxMatrix
*aMatrix
);
213 void SetupGlobalTransform(gfxContext
*aContext
);
214 nsresult
GetHighlight(PRUint32
*charnum
, PRUint32
*nchars
,
215 nscolor
*foreground
, nscolor
*background
);
217 // Owning pointer, must call gfxTextRunWordCache::RemoveTextRun before deleting
218 gfxTextRun
*mTextRun
;
220 PRUint8 mWhitespaceHandling
;