Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / gfx / src / thebes / nsThebesRegion.cpp
blobd8bbb6081bd012e9834785ce70d53fc7e09ce9b5
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * mozilla.org.
19 * Portions created by the Initial Developer are Copyright (C) 2004
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Stuart Parmenter <pavlov@pavlov.net>
24 * Vladimir Vukicevic <vladimir@pobox.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #include "nsThebesRegion.h"
42 NS_IMPL_ISUPPORTS1(nsThebesRegion, nsIRegion)
44 nsThebesRegion::nsThebesRegion()
46 NS_INIT_ISUPPORTS();
49 nsresult nsThebesRegion::Init (void)
51 mRegion.SetEmpty();
52 return NS_OK;
55 void nsThebesRegion::SetTo (const nsIRegion &aRegion)
57 const nsThebesRegion* pRegion = static_cast<const nsThebesRegion*>(&aRegion);
58 mRegion = pRegion->mRegion;
61 void nsThebesRegion::SetTo (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
63 mRegion = nsRect (aX, aY, aWidth, aHeight);
66 void nsThebesRegion::Intersect (const nsIRegion &aRegion)
68 const nsThebesRegion* pRegion = static_cast<const nsThebesRegion*>(&aRegion);
69 mRegion.And (mRegion, pRegion->mRegion);
72 void nsThebesRegion::Intersect (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
74 mRegion.And (mRegion, nsRect (aX, aY, aWidth, aHeight));
77 void nsThebesRegion::Union (const nsIRegion &aRegion)
79 const nsThebesRegion* pRegion = static_cast<const nsThebesRegion*>(&aRegion);
80 mRegion.Or (mRegion, pRegion->mRegion);
83 void nsThebesRegion::Union (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
85 mRegion.Or (mRegion, nsRect (aX, aY, aWidth, aHeight));
88 void nsThebesRegion::Subtract (const nsIRegion &aRegion)
90 const nsThebesRegion* pRegion = static_cast<const nsThebesRegion*>(&aRegion);
91 mRegion.Sub (mRegion, pRegion->mRegion);
94 void nsThebesRegion::Subtract (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
96 mRegion.Sub (mRegion, nsRect (aX, aY, aWidth, aHeight));
99 PRBool nsThebesRegion::IsEmpty (void)
101 return mRegion.IsEmpty ();
104 PRBool nsThebesRegion::IsEqual (const nsIRegion &aRegion)
106 const nsThebesRegion* pRegion = static_cast<const nsThebesRegion*>(&aRegion);
107 return mRegion.IsEqual (pRegion->mRegion);
110 void nsThebesRegion::GetBoundingBox (PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight)
112 nsRect BoundRect;
113 BoundRect = mRegion.GetBounds();
114 *aX = BoundRect.x;
115 *aY = BoundRect.y;
116 *aWidth = BoundRect.width;
117 *aHeight = BoundRect.height;
120 void nsThebesRegion::Offset (PRInt32 aXOffset, PRInt32 aYOffset)
122 mRegion.MoveBy (aXOffset, aYOffset);
125 PRBool nsThebesRegion::ContainsRect (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
127 nsRegion TmpRegion;
128 TmpRegion.And (mRegion, nsRect (aX, aY, aWidth, aHeight));
129 return (!TmpRegion.IsEmpty ());
132 NS_IMETHODIMP
133 nsThebesRegion::GetRects (nsRegionRectSet **aRects)
135 if (!aRects)
136 return NS_ERROR_NULL_POINTER;
138 nsRegionRectSet* pRegionSet = *aRects;
139 PRUint32 NumRects = mRegion.GetNumRects ();
141 if (pRegionSet == nsnull) // Not yet allocated
143 PRUint8* pBuf = new PRUint8 [sizeof (nsRegionRectSet) + NumRects * sizeof (nsRegionRect)];
144 pRegionSet = reinterpret_cast<nsRegionRectSet*>(pBuf);
145 pRegionSet->mRectsLen = NumRects + 1;
146 } else // Already allocated in previous call
148 if (NumRects > pRegionSet->mRectsLen) // passed array is not big enough - reallocate it.
150 delete [] reinterpret_cast<PRUint8*>(pRegionSet);
151 PRUint8* pBuf = new PRUint8 [sizeof (nsRegionRectSet) + NumRects * sizeof (nsRegionRect)];
152 pRegionSet = reinterpret_cast<nsRegionRectSet*>(pBuf);
153 pRegionSet->mRectsLen = NumRects + 1;
156 pRegionSet->mNumRects = NumRects;
157 *aRects = pRegionSet;
160 nsRegionRectIterator ri (mRegion);
161 nsRegionRect* pDest = &pRegionSet->mRects [0];
162 const nsRect* pSrc;
164 while ((pSrc = ri.Next ()))
166 pDest->x = pSrc->x;
167 pDest->y = pSrc->y;
168 pDest->width = pSrc->width;
169 pDest->height = pSrc->height;
171 pDest++;
174 return NS_OK;
177 NS_IMETHODIMP
178 nsThebesRegion::FreeRects (nsRegionRectSet *aRects)
180 if (!aRects)
181 return NS_ERROR_NULL_POINTER;
183 delete [] reinterpret_cast<PRUint8*>(aRects);
184 return NS_OK;
187 NS_IMETHODIMP
188 nsThebesRegion::GetNativeRegion (void *&aRegion) const
190 aRegion = 0;
191 return NS_OK;
194 NS_IMETHODIMP
195 nsThebesRegion::GetRegionComplexity (nsRegionComplexity &aComplexity) const
197 switch (mRegion.GetNumRects ())
199 case 0: aComplexity = eRegionComplexity_empty; break;
200 case 1: aComplexity = eRegionComplexity_rect; break;
201 default: aComplexity = eRegionComplexity_complex; break;
204 return NS_OK;
207 NS_IMETHODIMP
208 nsThebesRegion::GetNumRects (PRUint32 *aRects) const
210 *aRects = mRegion.GetNumRects ();
211 return NS_OK;