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 mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsIRegion_h___
39 #define nsIRegion_h___
42 #include "nsISupports.h"
46 enum nsRegionComplexity
48 eRegionComplexity_empty
= 0,
49 eRegionComplexity_rect
= 1,
50 eRegionComplexity_complex
= 2
63 PRUint32 mNumRects
; //number of actual rects in the mRects array
64 PRUint32 mRectsLen
; //length, in rects, of the mRects array
65 PRUint32 mArea
; //area of the covered portion of the region
66 nsRegionRect mRects
[1];
69 // An implementation of a region primitive that can be used to
70 // represent arbitrary pixel areas. Probably implemented on top
71 // of the native region primitive. The assumption is that, at worst,
72 // it is a rectangle list.
74 #define NS_IREGION_IID \
75 { 0x8ef366e0, 0xee94, 0x11d1, \
76 { 0xa8, 0x2a, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } }
78 class nsIRegion
: public nsISupports
81 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IREGION_IID
)
83 virtual nsresult
Init(void) = 0;
86 * copy operator equivalent that takes another region
88 * @param region to copy
93 virtual void SetTo(const nsIRegion
&aRegion
) = 0;
96 * copy operator equivalent that takes a rect
98 * @param aX xoffset of rect to set region to
99 * @param aY yoffset of rect to set region to
100 * @param aWidth width of rect to set region to
101 * @param aHeight height of rect to set region to
106 virtual void SetTo(PRInt32 aX
, PRInt32 aY
, PRInt32 aWidth
, PRInt32 aHeight
) = 0;
109 * destructively intersect another region with this one
111 * @param region to intersect
116 virtual void Intersect(const nsIRegion
&aRegion
) = 0;
119 * destructively intersect a rect with this region
121 * @param aX xoffset of rect to intersect with region
122 * @param aY yoffset of rect to intersect with region
123 * @param aWidth width of rect to intersect with region
124 * @param aHeight height of rect to intersect with region
129 virtual void Intersect(PRInt32 aX
, PRInt32 aY
, PRInt32 aWidth
, PRInt32 aHeight
) = 0;
132 * destructively union another region with this one
134 * @param region to union
139 virtual void Union(const nsIRegion
&aRegion
) = 0;
142 * destructively union a rect with this region
144 * @param aX xoffset of rect to union with region
145 * @param aY yoffset of rect to union with region
146 * @param aWidth width of rect to union with region
147 * @param aHeight height of rect to union with region
152 virtual void Union(PRInt32 aX
, PRInt32 aY
, PRInt32 aWidth
, PRInt32 aHeight
) = 0;
155 * destructively subtract another region with this one
157 * @param region to subtract
162 virtual void Subtract(const nsIRegion
&aRegion
) = 0;
165 * destructively subtract a rect from this region
167 * @param aX xoffset of rect to subtract with region
168 * @param aY yoffset of rect to subtract with region
169 * @param aWidth width of rect to subtract with region
170 * @param aHeight height of rect to subtract with region
175 virtual void Subtract(PRInt32 aX
, PRInt32 aY
, PRInt32 aWidth
, PRInt32 aHeight
) = 0;
178 * is this region empty? i.e. does it contain any pixels
181 * @return returns whether the region is empty
185 virtual PRBool
IsEmpty(void) = 0;
188 * == operator equivalent i.e. do the regions contain exactly
191 * @param region to compare
192 * @return whether the regions are identical
196 virtual PRBool
IsEqual(const nsIRegion
&aRegion
) = 0;
199 * returns the bounding box of the region i.e. the smallest
200 * rectangle that completely contains the region.
202 * @param aX out parameter for xoffset of bounding rect for region
203 * @param aY out parameter for yoffset of bounding rect for region
204 * @param aWidth out parameter for width of bounding rect for region
205 * @param aHeight out parameter for height of bounding rect for region
209 virtual void GetBoundingBox(PRInt32
*aX
, PRInt32
*aY
, PRInt32
*aWidth
, PRInt32
*aHeight
) = 0;
212 * offsets the region in x and y
214 * @param xoffset pixel offset in x
215 * @param yoffset pixel offset in y
219 virtual void Offset(PRInt32 aXOffset
, PRInt32 aYOffset
) = 0;
222 * does the region intersect the rectangle?
224 * @param rect to check for containment
225 * @return true if the region intersects the rect
229 virtual PRBool
ContainsRect(PRInt32 aX
, PRInt32 aY
, PRInt32 aWidth
, PRInt32 aHeight
) = 0;
232 * get the set of rects which make up this region. the aRects
233 * parameter must be freed by calling FreeRects before the region
234 * is deleted. aRects may be passed in again when requesting
235 * the rect list as a recycling method.
237 * @param aRects out parameter containing set of rects
238 * comprising the region
239 * @return error status
242 NS_IMETHOD
GetRects(nsRegionRectSet
**aRects
) = 0;
245 * Free a rect set returned by GetRects.
247 * @param aRects rects to free
248 * @return error status
251 NS_IMETHOD
FreeRects(nsRegionRectSet
*aRects
) = 0;
254 * Get the underlying nsIntRegion that this nsIRegion represents.
256 virtual nsIntRegion
GetUnderlyingRegion() const = 0;
259 * Get the native region that this nsIRegion represents.
260 * @param aRegion out parameter for native region handle
261 * @return error status
263 NS_IMETHOD
GetNativeRegion(void *&aRegion
) const = 0;
266 * Get the complexity of the region as defined by the
267 * nsRegionComplexity enum.
268 * @param aComplexity out parameter for region complexity
269 * @return error status
271 NS_IMETHOD
GetRegionComplexity(nsRegionComplexity
&aComplexity
) const = 0;
274 * get the number of rects which make up this region.
276 * @param aRects out parameter containing the number of rects
277 * comprising the region
278 * @return error status
281 NS_IMETHOD
GetNumRects(PRUint32
*aRects
) const = 0;
284 NS_DEFINE_STATIC_IID_ACCESSOR(nsIRegion
, NS_IREGION_IID
)
286 #endif // nsIRegion_h___