|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef NSSVGINTEGRATIONUTILS_H_ |
|
7 #define NSSVGINTEGRATIONUTILS_H_ |
|
8 |
|
9 #include "gfxMatrix.h" |
|
10 #include "GraphicsFilter.h" |
|
11 #include "gfxRect.h" |
|
12 #include "nsAutoPtr.h" |
|
13 |
|
14 class gfxDrawable; |
|
15 class nsDisplayList; |
|
16 class nsDisplayListBuilder; |
|
17 class nsIFrame; |
|
18 class nsRenderingContext; |
|
19 class nsIntRegion; |
|
20 |
|
21 struct nsRect; |
|
22 struct nsIntRect; |
|
23 |
|
24 namespace mozilla { |
|
25 namespace layers { |
|
26 class LayerManager; |
|
27 } |
|
28 } |
|
29 |
|
30 struct nsPoint; |
|
31 struct nsSize; |
|
32 |
|
33 /** |
|
34 * Integration of SVG effects (clipPath clipping, masking and filters) into |
|
35 * regular display list based painting and hit-testing. |
|
36 */ |
|
37 class nsSVGIntegrationUtils MOZ_FINAL |
|
38 { |
|
39 public: |
|
40 /** |
|
41 * Returns true if SVG effects are currently applied to this frame. |
|
42 */ |
|
43 static bool |
|
44 UsingEffectsForFrame(const nsIFrame* aFrame); |
|
45 |
|
46 /** |
|
47 * Returns the size of the union of the border-box rects of all of |
|
48 * aNonSVGFrame's continuations. |
|
49 */ |
|
50 static nsSize |
|
51 GetContinuationUnionSize(nsIFrame* aNonSVGFrame); |
|
52 |
|
53 /** |
|
54 * When SVG effects need to resolve percentage, userSpaceOnUse lengths, they |
|
55 * need a coordinate context to resolve them against. This method provides |
|
56 * that coordinate context for non-SVG frames with SVG effects applied to |
|
57 * them. The gfxSize returned is the size of the union of all of the given |
|
58 * frame's continuations' border boxes, converted to SVG user units (equal to |
|
59 * CSS px units), as required by the SVG code. |
|
60 */ |
|
61 static mozilla::gfx::Size |
|
62 GetSVGCoordContextForNonSVGFrame(nsIFrame* aNonSVGFrame); |
|
63 |
|
64 /** |
|
65 * SVG effects such as SVG filters, masking and clipPath may require an SVG |
|
66 * "bbox" for the element they're being applied to in order to make decisions |
|
67 * about positioning, and to resolve various lengths against. This method |
|
68 * provides the "bbox" for non-SVG frames. The bbox returned is in CSS px |
|
69 * units, and is the union of all aNonSVGFrame's continuations' overflow |
|
70 * areas, relative to the top-left of the union of all aNonSVGFrame's |
|
71 * continuations' border box rects. |
|
72 */ |
|
73 static gfxRect |
|
74 GetSVGBBoxForNonSVGFrame(nsIFrame* aNonSVGFrame); |
|
75 |
|
76 /** |
|
77 * Used to adjust a frame's pre-effects visual overflow rect to take account |
|
78 * of SVG effects. |
|
79 * |
|
80 * XXX This method will not do the right thing for frames with continuations. |
|
81 * It really needs all the continuations to have been reflowed before being |
|
82 * called, but we currently call it on each continuation as its overflow |
|
83 * rects are set during the reflow of each particular continuation. Gecko's |
|
84 * current reflow architecture does not allow us to set the overflow rects |
|
85 * for a whole chain of continuations for a given element at the point when |
|
86 * the last continuation is reflowed. See: |
|
87 * http://groups.google.com/group/mozilla.dev.tech.layout/msg/6b179066f3051f65 |
|
88 */ |
|
89 static nsRect |
|
90 ComputePostEffectsVisualOverflowRect(nsIFrame* aFrame, |
|
91 const nsRect& aPreEffectsOverflowRect); |
|
92 |
|
93 /** |
|
94 * Used to adjust the area of a frame that needs to be invalidated to take |
|
95 * account of SVG effects. |
|
96 * |
|
97 * @param aFrame The effects frame. |
|
98 * @param aToReferenceFrame The offset (in app units) from aFrame to its |
|
99 * reference display item. |
|
100 * @param aInvalidRegion The pre-effects invalid region in pixels relative to |
|
101 * the reference display item. |
|
102 * @return The post-effects invalid rect in pixels relative to the reference |
|
103 * display item. |
|
104 */ |
|
105 static nsIntRegion |
|
106 AdjustInvalidAreaForSVGEffects(nsIFrame* aFrame, const nsPoint& aToReferenceFrame, |
|
107 const nsIntRegion& aInvalidRegion); |
|
108 |
|
109 /** |
|
110 * Figure out which area of the source is needed given an area to |
|
111 * repaint |
|
112 */ |
|
113 static nsRect |
|
114 GetRequiredSourceForInvalidArea(nsIFrame* aFrame, const nsRect& aDamageRect); |
|
115 |
|
116 /** |
|
117 * Returns true if the given point is not clipped out by effects. |
|
118 * @param aPt in appunits relative to aFrame |
|
119 */ |
|
120 static bool |
|
121 HitTestFrameForEffects(nsIFrame* aFrame, const nsPoint& aPt); |
|
122 |
|
123 /** |
|
124 * Paint non-SVG frame with SVG effects. |
|
125 */ |
|
126 static void |
|
127 PaintFramesWithEffects(nsRenderingContext* aCtx, |
|
128 nsIFrame* aFrame, const nsRect& aDirtyRect, |
|
129 nsDisplayListBuilder* aBuilder, |
|
130 mozilla::layers::LayerManager* aManager); |
|
131 |
|
132 /** |
|
133 * SVG frames expect to paint in SVG user units, which are equal to CSS px |
|
134 * units. This method provides a transform matrix to multiply onto a |
|
135 * gfxContext's current transform to convert the context's current units from |
|
136 * its usual dev pixels to SVG user units/CSS px to keep the SVG code happy. |
|
137 */ |
|
138 static gfxMatrix |
|
139 GetCSSPxToDevPxMatrix(nsIFrame* aNonSVGFrame); |
|
140 |
|
141 /** |
|
142 * @param aRenderingContext the target rendering context in which the paint |
|
143 * server will be rendered |
|
144 * @param aTarget the target frame onto which the paint server will be |
|
145 * rendered |
|
146 * @param aPaintServer a first-continuation frame to use as the source |
|
147 * @param aFilter a filter to be applied when scaling |
|
148 * @param aDest the area the paint server image should be mapped to |
|
149 * @param aFill the area to be filled with copies of the paint server image |
|
150 * @param aAnchor a point in aFill which we will ensure is pixel-aligned in |
|
151 * the output |
|
152 * @param aDirty pixels outside this area may be skipped |
|
153 * @param aPaintServerSize the size that would be filled when using |
|
154 * background-repeat:no-repeat and background-size:auto. For normal background |
|
155 * images, this would be the intrinsic size of the image; for gradients and |
|
156 * patterns this would be the whole target frame fill area. |
|
157 * @param aFlags pass FLAG_SYNC_DECODE_IMAGES and any images in the paint |
|
158 * server will be decoding synchronously if they are not decoded already. |
|
159 */ |
|
160 enum { |
|
161 FLAG_SYNC_DECODE_IMAGES = 0x01, |
|
162 }; |
|
163 |
|
164 static already_AddRefed<gfxDrawable> |
|
165 DrawableFromPaintServer(nsIFrame* aFrame, |
|
166 nsIFrame* aTarget, |
|
167 const nsSize& aPaintServerSize, |
|
168 const gfxIntSize& aRenderSize, |
|
169 const gfxMatrix& aContextMatrix, |
|
170 uint32_t aFlags); |
|
171 }; |
|
172 |
|
173 #endif /*NSSVGINTEGRATIONUTILS_H_*/ |