Back to index

lightning-sunbird  0.9+nobinonly
nsCairoGfxFactory.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * mozilla.org.
00019  * Portions created by the Initial Developer are Copyright (C) 2004
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Stuart Parmenter <pavlov@pavlov.net>
00024  *   Joe Hewitt <hewitt@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "nsIGenericFactory.h"
00041 #include "nsIModule.h"
00042 #include "nsCOMPtr.h"
00043 #include "nsGfxCIID.h"
00044 
00045 #include "nsScriptableRegion.h"
00046 #include "gfxImageFrame.h"
00047 #include "nsCairoFontMetrics.h"
00048 #include "nsCairoDeviceContext.h"
00049 #include "nsCairoRenderingContext.h"
00050 #include "nsCairoImage.h"
00051 #include "nsCairoRegion.h"
00052 #include "nsCairoScreen.h"
00053 #include "nsCairoScreenManager.h"
00054 #include "nsCairoBlender.h"
00055 #ifdef MOZ_ENABLE_XFT
00056 #include "nsFontMetricsXft.h"
00057 #endif
00058 
00059 NS_GENERIC_FACTORY_CONSTRUCTOR(nsCairoBlender)
00060 NS_GENERIC_FACTORY_CONSTRUCTOR(gfxImageFrame)
00061 NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontMetricsXft)
00062     //NS_GENERIC_FACTORY_CONSTRUCTOR(nsCairoFontMetrics)
00063 NS_GENERIC_FACTORY_CONSTRUCTOR(nsCairoDeviceContext)
00064 NS_GENERIC_FACTORY_CONSTRUCTOR(nsCairoRenderingContext)
00065 NS_GENERIC_FACTORY_CONSTRUCTOR(nsCairoImage)
00066 NS_GENERIC_FACTORY_CONSTRUCTOR(nsCairoRegion)
00067 NS_GENERIC_FACTORY_CONSTRUCTOR(nsCairoScreenManager)
00068 
00069 static NS_IMETHODIMP nsScriptableRegionConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
00070 {
00071   nsresult rv;
00072 
00073   nsIScriptableRegion *inst = nsnull;
00074 
00075   if ( !aResult )
00076   {
00077     rv = NS_ERROR_NULL_POINTER;
00078     return rv;
00079   }
00080   *aResult = nsnull;
00081   if (aOuter)
00082   {
00083     rv = NS_ERROR_NO_AGGREGATION;
00084     return rv;
00085   }
00086   // create an nsRegionGtk and get the scriptable region from it
00087   nsCOMPtr <nsIRegion> rgn;
00088   NS_NEWXPCOM(rgn, nsCairoRegion);
00089   nsCOMPtr<nsIScriptableRegion> scriptableRgn;
00090   if (rgn != nsnull)
00091   {
00092     scriptableRgn = new nsScriptableRegion(rgn);
00093     inst = scriptableRgn;
00094   }
00095   if (!inst)
00096   {
00097     rv = NS_ERROR_OUT_OF_MEMORY;
00098     return rv;
00099   }
00100   NS_ADDREF(inst);
00101   // release our variable above now that we have created our owning
00102   // reference - we don't want this to go out of scope early!
00103   scriptableRgn = nsnull;
00104   rv = inst->QueryInterface(aIID, aResult);
00105   NS_RELEASE(inst);
00106 
00107   return rv;
00108 }
00109 
00110 static const nsModuleComponentInfo components[] =
00111 {
00112   { "Cairo nsFontMetrics",
00113     NS_FONT_METRICS_CID,
00114     "@mozilla.org/gfx/fontmetrics;1",
00115     nsFontMetricsXftConstructor },
00116   { "Cairo Device Context",
00117     NS_DEVICE_CONTEXT_CID,
00118     "@mozilla.org/gfx/devicecontext;1",
00119     nsCairoDeviceContextConstructor },
00120   { "Cairo Rendering Context",
00121     NS_RENDERING_CONTEXT_CID,
00122     "@mozilla.org/gfx/renderingcontext;1",
00123     nsCairoRenderingContextConstructor },
00124   { "Cairo nsImage",
00125     NS_IMAGE_CID,
00126     "@mozilla.org/gfx/image;1",
00127     nsCairoImageConstructor },
00128   { "Cairo Region",
00129     NS_REGION_CID,
00130     "@mozilla.org/gfx/region/nsCairo;1",
00131     nsCairoRegionConstructor },
00132   { "Cairo Screen Manager",
00133     NS_SCREENMANAGER_CID,
00134     "@mozilla.org/gfx/screenmanager;1",
00135     nsCairoScreenManagerConstructor },
00136   { "Scriptable Region",
00137     NS_SCRIPTABLE_REGION_CID,
00138     "@mozilla.org/gfx/region;1",
00139     nsScriptableRegionConstructor },
00140   { "Cairo Blender",
00141     NS_BLENDER_CID,
00142     "@mozilla.org/gfx/blender;1",
00143     nsCairoBlenderConstructor },
00144   { "image frame",
00145     GFX_IMAGEFRAME_CID,
00146     "@mozilla.org/gfx/image/frame;2",
00147     gfxImageFrameConstructor, }
00148 };
00149 
00150 PR_STATIC_CALLBACK(void)
00151 nsCairoGfxModuleDtor(nsIModule *self)
00152 {
00153 }
00154 
00155 NS_IMPL_NSGETMODULE_WITH_DTOR(nsCairoGfxModule, components, nsCairoGfxModuleDtor)
00156