Back to index

lightning-sunbird  0.9+nobinonly
nsSVGCairoRegion.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Mozilla SVG Cairo Renderer project.
00016  *
00017  * The Initial Developer of the Original Code is Crocodile Clips Ltd..
00018  * Portions created by the Initial Developer are Copyright (C) 2004
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either of the GNU General Public License Version 2 or later (the "GPL"),
00025  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 #include "nsCOMPtr.h"
00038 #include "nsISVGCairoRegion.h"
00039 #include "nsISVGRectangleSink.h"
00040 #include "nsSVGCairoRegion.h"
00041 
00042 class nsSVGCairoRectRegion : public nsISVGCairoRegion
00043 {
00044 protected:
00045   friend nsresult NS_NewSVGCairoRectRegion(nsISVGRendererRegion** result,
00046                                            float x, float y,
00047                                            float width, float height);
00048   nsSVGCairoRectRegion(float x, float y, float w, float h);
00049   
00050 public:
00051   // nsISupports interface:
00052   NS_DECL_ISUPPORTS
00053 
00054   // nsISVGCairoRegion interface:
00055   NS_IMETHOD_(PRBool) Contains(float x, float y);
00056 
00057   // nsISVGRendererRegion interface:
00058   NS_DECL_NSISVGRENDERERREGION
00059 
00060 private:
00061   float mX, mY, mWidth, mHeight;
00062 };
00063 
00064 //----------------------------------------------------------------------
00065 // implementation:
00066 
00067 nsresult
00068 NS_NewSVGCairoRectRegion(nsISVGRendererRegion** result, float x, float y,
00069                          float width, float height)
00070 {
00071   *result = new nsSVGCairoRectRegion(x, y, width, height);
00072   
00073   if (!*result) return NS_ERROR_OUT_OF_MEMORY;
00074   
00075   NS_ADDREF(*result);
00076   return NS_OK;
00077 }
00078 
00079 nsSVGCairoRectRegion::nsSVGCairoRectRegion(float x, float y, float w, float h) :
00080     mX(x), mY(y), mWidth(w), mHeight(h)
00081 {
00082 }
00083 
00084 //----------------------------------------------------------------------
00085 // nsISupports methods:
00086 
00087 NS_IMPL_ADDREF(nsSVGCairoRectRegion)
00088 NS_IMPL_RELEASE(nsSVGCairoRectRegion)
00089 
00090 NS_INTERFACE_MAP_BEGIN(nsSVGCairoRectRegion)
00091   NS_INTERFACE_MAP_ENTRY(nsISVGCairoRegion)
00092   NS_INTERFACE_MAP_ENTRY(nsISVGRendererRegion)
00093   NS_INTERFACE_MAP_ENTRY(nsISupports)
00094 NS_INTERFACE_MAP_END
00095 
00096 //----------------------------------------------------------------------
00097 // nsISVGCairoRegion methods:
00098 
00099 NS_IMETHODIMP_(PRBool)
00100 nsSVGCairoRectRegion::Contains(float x, float y)
00101 {
00102   if (x >= mX &&
00103       x <= mX + mWidth &&
00104       y >= mY &&
00105       y <= mY + mHeight)
00106     return PR_TRUE;
00107   return PR_FALSE;
00108 }
00109 
00110 //----------------------------------------------------------------------
00111 // nsISVGRendererRegion methods:
00112 
00114 NS_IMETHODIMP
00115 nsSVGCairoRectRegion::Combine(nsISVGRendererRegion *other,
00116                               nsISVGRendererRegion **_retval)
00117 {
00118   nsSVGCairoRectRegion *_other = static_cast<nsSVGCairoRectRegion*>(other); // ok, i know i'm being bad
00119 
00120   float x1 = PR_MIN(mX, _other->mX);
00121   float y1 = PR_MIN(mY, _other->mY);
00122   float x2 = PR_MAX(mX+mWidth, _other->mX+_other->mWidth);
00123   float y2 = PR_MAX(mY+mHeight, _other->mY+_other->mHeight);
00124   
00125   return NS_NewSVGCairoRectRegion(_retval, x1, y1, x2-x1, y2-y1);
00126 }
00127 
00129 NS_IMETHODIMP
00130 nsSVGCairoRectRegion::GetRectangleScans(nsISVGRectangleSink *sink)
00131 {
00132   sink->SinkRectangle(mX, mY, mWidth, mHeight);
00133   return NS_OK;
00134 }