Bug 266236 part 2: Merge nsIRenderingContext with nsThebesRenderingContext (the sole implementation) and remove XPCOM vestiges. Non-mechanical fixups. DOES NOT COMPILE without part 3.
authorJan Küchler <jan@kuechler-wuppertal.de>
Thu, 07 Apr 2011 18:04:39 -0700
changeset 68122 1c1bfa98f6005c20776388a6814950aa531d5893
parent 68121 faeb9fecfc94ed619fed6758b4dbea1b8ed1fee6
child 68123 f54747d3a9087414d41d7c8894b8c67fa52c4474
push id19517
push userzackw@panix.com
push dateThu, 14 Apr 2011 15:49:12 +0000
treeherdermozilla-central@3a3109b0d39d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs266236
milestone6.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 266236 part 2: Merge nsIRenderingContext with nsThebesRenderingContext (the sole implementation) and remove XPCOM vestiges. Non-mechanical fixups. DOES NOT COMPILE without part 3.
gfx/src/Makefile.in
gfx/src/nsGfxCIID.h
gfx/src/nsIDeviceContext.h
gfx/src/nsIRenderingContext.h
gfx/src/nsIThebesFontMetrics.h
gfx/src/nsRenderingContext.cpp
gfx/src/nsRenderingContext.h
gfx/src/nsSystemFontsAndroid.cpp
gfx/src/nsSystemFontsAndroid.h
gfx/src/nsSystemFontsGTK2.cpp
gfx/src/nsSystemFontsGTK2.h
gfx/src/nsSystemFontsMac.mm
gfx/src/nsSystemFontsOS2.cpp
gfx/src/nsSystemFontsOS2.h
gfx/src/nsSystemFontsQt.cpp
gfx/src/nsSystemFontsQt.h
gfx/src/nsSystemFontsWin.cpp
gfx/src/nsSystemFontsWin.h
gfx/src/nsThebesGfxFactory.cpp
gfx/src/nsThebesRenderingContext.cpp
gfx/src/nsThebesRenderingContext.h
widget/src/cocoa/nsChildView.mm
widget/src/windows/nsWindow.cpp
widget/src/windows/nsWindowGfx.cpp
--- a/gfx/src/Makefile.in
+++ b/gfx/src/Makefile.in
@@ -67,17 +67,17 @@ EXPORTS	= \
 	nsCoord.h \
 	nsFont.h \
 	nsRect.h \
 	nsRegion.h \
 	nsPoint.h \
 	nsSize.h \
 	nsMargin.h \
 	nsTransform2D.h \
-	nsIRenderingContext.h \
+	nsRenderingContext.h \
 	nsIFontMetrics.h \
 	nsIDeviceContext.h \
 	nsGfxCIID.h \
 	nsIRegion.h \
 	nsITheme.h \
 	nsThemeConstants.h \
 	gfxCrashReporterUtils.h \
 	nsIThebesFontMetrics.h \
@@ -94,17 +94,17 @@ CPPSRCS = \
         nsRect.cpp \
         nsRegion.cpp \
         nsTransform2D.cpp \
         nsScriptableRegion.cpp \
         gfxCrashReporterUtils.cpp \
         nsThebesDeviceContext.cpp \
         nsThebesRegion.cpp \
         nsThebesGfxFactory.cpp \
-        nsThebesRenderingContext.cpp \
+        nsRenderingContext.cpp \
         nsThebesFontMetrics.cpp \
         nsThebesFontEnumerator.cpp \
        $(NULL)
 
 ifdef MOZ_X11
 CPPSRCS += X11Util.cpp
 endif
 
--- a/gfx/src/nsGfxCIID.h
+++ b/gfx/src/nsGfxCIID.h
@@ -41,20 +41,16 @@
 #include "nsISupports.h"
 #include "nsIFactory.h"
 #include "nsIComponentManager.h"
 
 #define NS_IMAGE_CID \
 { 0x6049b260, 0xc1e6, 0x11d1, \
 { 0xa8, 0x27, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } }
 
-#define NS_RENDERING_CONTEXT_CID \
-{ 0x6049b261, 0xc1e6, 0x11d1, \
-{ 0xa8, 0x27, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } }
-
 #define NS_DEVICE_CONTEXT_CID \
 { 0x6049b262, 0xc1e6, 0x11d1, \
 { 0xa8, 0x27, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } }
 
 #define NS_FONT_METRICS_CID \
 { 0x6049b263, 0xc1e6, 0x11d1, \
 { 0xa8, 0x27, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } }
 
--- a/gfx/src/nsIDeviceContext.h
+++ b/gfx/src/nsIDeviceContext.h
@@ -37,26 +37,26 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsIDeviceContext_h___
 #define nsIDeviceContext_h___
 
 #include "nsISupports.h"
 #include "nsCoord.h"
 #include "nsRect.h"
-#include "nsIRenderingContext.h"
-// XXX we need only gfxTypes.h, but we cannot include it directly.
-#include "gfxPoint.h"
+#include "gfxTypes.h"
+#include "nsStringFwd.h"
 
 class nsIView;
 class nsIFontMetrics;
 class nsIWidget;
 class nsIDeviceContextSpec;
 class nsIAtom;
 class gfxUserFontSet;
+class nsRenderingContext;
 
 struct nsFont;
 
 //a cross platform way of specifying a native device context
 typedef void * nsNativeDeviceContext;
 
 /* error codes for printer device contexts */
 #define NS_ERROR_GFX_PRINTER_BASE (1) /* adjustable :-) */
deleted file mode 100644
--- a/gfx/src/nsIRenderingContext.h
+++ /dev/null
@@ -1,830 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
- *   Leon Sha <leon.sha@sun.com>
- *   Boris Zbarsky <bzbarsky@mit.edu>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef nsIRenderingContext_h___
-#define nsIRenderingContext_h___
-
-#include "nscore.h"
-#include "nsCOMPtr.h"
-#include "nsISupports.h"
-#include "nsColor.h"
-#include "nsCoord.h"
-#include "nsRect.h"
-#include "nsPoint.h"
-#include "nsSize.h"
-#include <stdio.h>
-
-class nsIWidget;
-class nsIFontMetrics;
-class nsTransform2D;
-class nsString;
-class nsIDeviceContext;
-class nsIntRegion;
-class nsIAtom;
-
-struct nsFont;
-struct nsTextDimensions;
-class gfxUserFontSet;
-#ifdef MOZ_MATHML
-struct nsBoundingMetrics;
-#endif
-
-class gfxASurface;
-class gfxContext;
-
-/* gfx2 */
-class imgIContainer;
-
-//cliprect/region combination methods
-
-typedef enum
-{
-  nsClipCombine_kIntersect = 0,
-  nsClipCombine_kUnion = 1,
-  nsClipCombine_kSubtract = 2,
-  nsClipCombine_kReplace = 3
-} nsClipCombine;
-
-//linestyles
-typedef enum
-{
-  nsLineStyle_kNone   = 0,
-  nsLineStyle_kSolid  = 1,
-  nsLineStyle_kDashed = 2,
-  nsLineStyle_kDotted = 3
-} nsLineStyle;
-
-typedef enum
-{
-  nsPenMode_kNone   = 0,
-  nsPenMode_kInvert = 1
-} nsPenMode;
-
-
-// IID for the nsIRenderingContext interface
-#define NS_IRENDERING_CONTEXT_IID \
-{ 0xefbfeb6c, 0x937e, 0x4889, \
-  { 0x92, 0x46, 0x16, 0xc0, 0xe8, 0x4b, 0xfa, 0xae } }
-
-//----------------------------------------------------------------------
-
-// RenderingContext interface
-class nsIRenderingContext : public nsISupports
-{
-public:
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_IRENDERING_CONTEXT_IID)
-
-  //TBD: bind/unbind, transformation of scalars (hacky), 
-  //potential drawmode for selection, polygons. MMP
-
-  /**
-   * Initialize the RenderingContext
-   * @param aContext the device context to use.
-   * @param aWidget the widget to hook up to
-   * @result The result of the initialization, NS_Ok if no errors
-   */
-  NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWidget) = 0;
-
-  /**
-   * Initialize the RenderingContext
-   * @param aContext the device context to use for the drawing.
-   * @param aThebesSurface the Thebes gfxASurface to which to draw
-   * @result The result of the initialization, NS_Ok if no errors
-   */
-  NS_IMETHOD Init(nsIDeviceContext* aContext, gfxASurface* aThebesSurface) = 0;
-
-  /**
-   * Initialize the RenderingContext
-   * @param aContext the device context to use for the drawing.
-   * @param aThebesContext an existing thebes context to use for the drawing
-   * @result The result of the initialization, NS_Ok if no errors
-   */
-  NS_IMETHOD Init(nsIDeviceContext* aContext, gfxContext* aThebesContext) = 0;
-
-  /**
-   * Get the DeviceContext that this RenderingContext was initialized
-   * with.
-   * @result the device context
-   */
-  virtual already_AddRefed<nsIDeviceContext> GetDeviceContext() = 0;
-
-  /**
-   * Save a graphical state onto a stack.
-   */
-  NS_IMETHOD PushState(void) = 0;
-
-  /**
-   * Get and and set RenderingContext to this graphical state
-   */
-  NS_IMETHOD PopState(void) = 0;
-
-  // XXX temporary
-  NS_IMETHOD PushFilter(const nsRect& aRect, PRBool aAreaIsOpaque, float aOpacity)
-  { return NS_ERROR_NOT_IMPLEMENTED; }
-  NS_IMETHOD PopFilter()
-  { return NS_ERROR_NOT_IMPLEMENTED; }
-
-  /**
-   * Sets the clipping for the RenderingContext to the passed in rectangle.
-   * The rectangle is in app units!
-   * @param aRect The rectangle to set the clipping rectangle to
-   * @param aCombine how to combine this rect with the current clip region.
-   *        see the bottom of nsIRenderingContext.h
-   */
-  NS_IMETHOD SetClipRect(const nsRect& aRect, nsClipCombine aCombine) = 0;
-
-  /**
-   * Sets the line style for the RenderingContext 
-   * @param aLineStyle The line style
-   * @return NS_OK if the line style is correctly set
-   */
-  NS_IMETHOD SetLineStyle(nsLineStyle aLineStyle) = 0;
-
-  /**
-   * Sets the clipping for the RenderingContext to the passed in region.
-   * The region is in device coordinates!
-   * @param aRegion The region to set the clipping area to, IN DEVICE COORDINATES
-   * @param aCombine how to combine this region with the current clip region.
-   *        see the bottom of nsIRenderingContext.h
-   */
-  NS_IMETHOD SetClipRegion(const nsIntRegion& aRegion, nsClipCombine aCombine) = 0;
-
-  /**
-   * Sets the forground color for the RenderingContext
-   * @param aColor The color to set the RenderingContext to
-   */
-  NS_IMETHOD SetColor(nscolor aColor) = 0;
-
-  /**
-   * Get the forground color for the RenderingContext
-   * @return The current forground color of the RenderingContext
-   */
-  NS_IMETHOD GetColor(nscolor &aColor) const = 0;
-
-  /**
-   * Sets the font for the RenderingContext
-   * @param aFont The font to use in the RenderingContext
-   */
-  NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLanguage,
-                     gfxUserFontSet *aUserFontSet) = 0;
-
-  /**
-   * Sets the font for the RenderingContext, without language info
-   * @param aFont The font to use in the RenderingContext
-   */
-  NS_IMETHOD SetFont(const nsFont& aFont,
-                     gfxUserFontSet *aUserFontSet) = 0;
-
-  /**
-   * Sets the font for the RenderingContext
-   * @param aFontMetric The font metrics representing the
-   *        font to use in the RenderingContext
-   */
-  NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics) = 0;
-
-  /**
-   * Get the current fontmetrics for the RenderingContext
-   * @return The current font of the RenderingContext
-   */
-  virtual already_AddRefed<nsIFontMetrics> GetFontMetrics() = 0;
-
-  /**
-   * Add in a translate to the RenderingContext's transformation matrix
-   * @param aPt The point to translate to
-   */
-  NS_IMETHOD Translate(const nsPoint& aPt) = 0;
-
-  /**
-   * Set the translation compoennt of the current transformation matrix.
-   * Useful to set it to a known pixel value without incurring roundoff
-   * errors.
-   */
-  NS_IMETHOD SetTranslation(const nsPoint& aPt) = 0;
-
-  /**
-   *  Add in a scale to the RenderingContext's transformation matrix
-   * @param aX The horizontal scale
-   * @param aY The vertical scale
-   */
-  NS_IMETHOD Scale(float aSx, float aSy) = 0;
-
-  struct PushedTranslation {
-    float mSavedX, mSavedY;
-  };
-
-  class AutoPushTranslation {
-    nsIRenderingContext* mCtx;
-    PushedTranslation mPushed;
-  public:
-    AutoPushTranslation(nsIRenderingContext* aCtx, const nsPoint& aPt)
-      : mCtx(aCtx) {
-      mCtx->PushTranslation(&mPushed);
-      mCtx->Translate(aPt);
-    }
-    ~AutoPushTranslation() {
-      mCtx->PopTranslation(&mPushed);
-    }
-  };
-
-  NS_IMETHOD PushTranslation(PushedTranslation* aState) = 0;
-
-  NS_IMETHOD PopTranslation(PushedTranslation* aState) = 0;
-
-  /**
-   * Get the current transformation matrix for the RenderingContext
-   * @return The transformation matrix for the RenderingContext
-   */
-  virtual nsTransform2D* GetCurrentTransform() = 0;
-
-  /**
-   * Draw a line
-   * @param aStartPt starting point
-   * @param aEndPt ending point
-   */
-  NS_IMETHOD DrawLine(const nsPoint& aStartPt, const nsPoint& aEndPt) = 0;
-
-  /**
-   * Draw a line
-   * @param aX0 starting horizontal coord in twips
-   * @param aY0 starting vertical coord in twips
-   * @param aX1 end horiztonal coord in twips
-   * @param aY1 end vertical coord in twips
-   */
-  NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1) = 0;
-
-  /**
-   * Draw a rectangle
-   * @param aRect The rectangle to draw
-   */
-  NS_IMETHOD DrawRect(const nsRect& aRect) = 0;
-
-  /**
-   * Draw a rectangle
-   * @param aX Horizontal left Coordinate in twips
-   * @param aY Vertical top Coordinate in twips
-   * @param aWidth Width of rectangle in twips
-   * @param aHeight Height of rectangle in twips
-   */
-  NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) = 0;
-
-  /**
-   * Fill a rectangle in the current foreground color
-   * @param aRect The rectangle to draw
-   */
-  NS_IMETHOD FillRect(const nsRect& aRect) = 0;
-
-  /**
-   * Fill a rectangle in the current foreground color
-   * @param aX Horizontal left Coordinate in twips
-   * @param aY Vertical top Coordinate in twips
-   * @param aWidth Width of rectangle in twips
-   * @param aHeight Height of rectangle in twips
-   */
-  NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) = 0;
-
-  /**
-   * XOR Invert a rectangle in the current foreground color
-   * @param aRect The rectangle to draw
-   */
-  NS_IMETHOD InvertRect(const nsRect& aRect) = 0;
-
-  /**
-   * XOR Invert a rectangle in the current foreground color
-   * @param aX Horizontal left Coordinate in twips
-   * @param aY Vertical top Coordinate in twips
-   * @param aWidth Width of rectangle in twips
-   * @param aHeight Height of rectangle in twips
-   */
-  NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) = 0;
-
-  /**
-   * Fill a poly in the current foreground color
-   * @param aPoints points to use for the drawing, last must equal first
-   * @param aNumPonts number of points in the polygon
-   */
-  NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints) = 0;
-
-  /**
-   * Draw an ellipse in the current foreground color
-   * @param aRect The rectangle define bounds of ellipse to draw
-   */
-  NS_IMETHOD DrawEllipse(const nsRect& aRect) = 0;
-
-  /**
-   * Draw an ellipse in the current foreground color
-   * @param aX Horizontal left Coordinate in twips
-   * @param aY Vertical top Coordinate in twips
-   * @param aWidth Width of horizontal axis in twips
-   * @param aHeight Height of vertical axis in twips
-   */
-  NS_IMETHOD DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) = 0;
-
-  /**
-   * Fill an ellipse in the current foreground color
-   * @param aRect The rectangle define bounds of ellipse to draw
-   */
-  NS_IMETHOD FillEllipse(const nsRect& aRect) = 0;
-
-  /**
-   * Fill an ellipse in the current foreground color
-   * @param aX Horizontal left Coordinate in twips
-   * @param aY Vertical top Coordinate in twips
-   * @param aWidth Width of horizontal axis in twips
-   * @param aHeight Height of vertical axis in twips
-   */
-  NS_IMETHOD FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) = 0;
-
-  /**
-   * Returns the width (in app units) of an 8-bit character
-   * If no font has been Set, the results are undefined.
-   * @param aC character to measure
-   * @param aWidth out parameter for width
-   * @return error status
-   */
-  NS_IMETHOD GetWidth(char aC, nscoord &aWidth) = 0;
-
-  /**
-   * Returns the width (in app units) of a unicode character
-   * If no font has been Set, the results are undefined.
-   * @param aC character to measure
-   * @param aWidth out parameter for width
-   * @param aFontID an optional out parameter used to store a
-   *        font identifier that can be passed into the DrawString()
-   *        methods to speed rendering
-   * @return error status
-   */
-  NS_IMETHOD GetWidth(PRUnichar aC, nscoord &aWidth,
-                      PRInt32 *aFontID = nsnull) = 0;
-
-  /**
-   * Returns the width (in app units) of an nsString
-   * If no font has been Set, the results are undefined.
-   * @param aString string to measure
-   * @param aWidth out parameter for width
-   * @param aFontID an optional out parameter used to store a
-   *        font identifier that can be passed into the DrawString()
-   *        methods to speed rendering
-   * @return error status
-   */
-  NS_IMETHOD GetWidth(const nsString& aString, nscoord &aWidth,
-                      PRInt32 *aFontID = nsnull) = 0;
-
-  /**
-   * Returns the width (in app units) of an 8-bit character string
-   * If no font has been Set, the results are undefined.
-   * @param aString string to measure
-   * @param aWidth out parameter for width
-   * @return error status
-   */
-  NS_IMETHOD GetWidth(const char* aString, nscoord& aWidth) = 0;
-
-  /**
-   * Returns the width (in app units) of an 8-bit character string
-   * If no font has been Set, the results are undefined.
-   * @param aString string to measure
-   * @param aLength number of characters in string
-   * @param aWidth out parameter for width
-   * @return error status
-   */
-  NS_IMETHOD GetWidth(const char* aString, PRUint32 aLength,
-                      nscoord& aWidth) = 0;
-
-  /**
-   * Returns the width (in app units) of a Unicode character string
-   * If no font has been Set, the results are undefined.
-   * @param aString string to measure
-   * @param aLength number of characters in string
-   * @param aWidth out parameter for width
-   * @param aFontID an optional out parameter used to store a
-   *        font identifier that can be passed into the DrawString()
-   *        methods to speed rendering
-   * @return error status
-   */
-  NS_IMETHOD GetWidth(const PRUnichar *aString, PRUint32 aLength,
-                      nscoord &aWidth, PRInt32 *aFontID = nsnull) = 0;
-
-  /**
-   * Returns the dimensions of a string, i.e., the overall extent of a string
-   * whose rendering may involve switching between different fonts that have
-   * different metrics.
-   * @param aString string to measure
-   * @param aLength number of characters in string
-   * @param aFontID an optional out parameter used to store a
-   *        font identifier that can be passed into the DrawString()
-   *        methods to speed measurements
-   * @return aDimensions struct that contains the extent of the string (see below)
-   */
-  NS_IMETHOD GetTextDimensions(const char* aString, PRUint32 aLength,
-                               nsTextDimensions& aDimensions) = 0;
-  NS_IMETHOD GetTextDimensions(const PRUnichar* aString, PRUint32 aLength,
-                               nsTextDimensions& aDimensions, PRInt32* aFontID = nsnull) = 0;
-
-#if defined(_WIN32) || defined(XP_OS2) || defined(MOZ_X11)
-  /**
-   * Given an available width and an array of break points,
-   * returns the dimensions (in app units) of the text that fit and
-   * the number of characters that fit. The number of characters
-   * corresponds to an entry in the break array.
-   * If no font has been set, the results are undefined.
-   * @param aString, string to measure
-   * @param aLength, number of characters in string
-   * @param aAvailWidth, the available space in which the text must fit
-   * @param aBreaks, array of places to break. Specified as offsets from the
-   *          start of the string
-   * @param aNumBreaks, the number of entries in the break array. The last
-   *          entry in the break array must equal the length of the string
-   * @param aDimensions, out parameter for the dimensions, the ascent and descent
-   *           of the last word are left out to allow possible line-breaking before
-   *           the last word. However, the width of the last word is included.
-   * @param aNumCharsFit, the number of characters that fit in the available space
-   * @param aLastWordDimensions, dimensions of the last word, the width field,
-   *             dimensions.width, should be -1 for an unknown width. But the 
-   *             ascent and descent are expected to be known.
-   * @param aFontID, an optional out parameter used to store a
-   *        font identifier that can be passed into the DrawString()
-   *        methods to speed rendering
-   * @return error status
-   */
-  NS_IMETHOD GetTextDimensions(const char*       aString,
-                               PRInt32           aLength,
-                               PRInt32           aAvailWidth,
-                               PRInt32*          aBreaks,
-                               PRInt32           aNumBreaks,
-                               nsTextDimensions& aDimensions,
-                               PRInt32&          aNumCharsFit,
-                               nsTextDimensions& aLastWordDimensions,
-                               PRInt32*          aFontID = nsnull) = 0;
-
-  NS_IMETHOD GetTextDimensions(const PRUnichar*  aString,
-                               PRInt32           aLength,
-                               PRInt32           aAvailWidth,
-                               PRInt32*          aBreaks,
-                               PRInt32           aNumBreaks,
-                               nsTextDimensions& aDimensions,
-                               PRInt32&          aNumCharsFit,
-                               nsTextDimensions& aLastWordDimensions,
-                               PRInt32*          aFontID = nsnull) = 0;
-#endif
-
-  /**
-   * Draw a string in the RenderingContext
-   * @param aString The string to draw
-   * @param aLength The length of the aString
-   * @param aX Horizontal starting point of baseline
-   * @param aY Vertical starting point of baseline.
-   * @param aSpacing inter-character spacing to apply
-   */
-  NS_IMETHOD DrawString(const char *aString, PRUint32 aLength,
-                        nscoord aX, nscoord aY,
-                        const nscoord* aSpacing = nsnull) = 0;
-
-  /**
-   * Draw a string in the RenderingContext
-   * @param aString A PRUnichar of the string
-   * @param aLength The length of the aString
-   * @param aX Horizontal starting point of baseline
-   * @param aY Vertical starting point of baseline.
-   * @param aFontID an optional parameter used to speed font
-   *        selection for complex unicode strings. the value
-   *        passed is returned by the DrawString() methods.
-   * @param aSpacing inter-character spacing to apply
-   */
-  NS_IMETHOD DrawString(const PRUnichar *aString, PRUint32 aLength,
-                        nscoord aX, nscoord aY,
-                        PRInt32 aFontID = -1,
-                        const nscoord* aSpacing = nsnull) = 0;
-
-  /**
-   * Draw a string in the RenderingContext
-   * @param aString A nsString of the string
-   * @param aX Horizontal starting point of baseline
-   * @param aY Vertical starting point of baseline.
-   * @param aFontID an optional parameter used to speed font
-   *        selection for complex unicode strings. the value
-   *        passed is returned by the DrawString() methods.
-   * @param aSpacing inter-character spacing to apply
-   */
-  NS_IMETHOD DrawString(const nsString& aString, nscoord aX, nscoord aY,
-                        PRInt32 aFontID = -1,
-                        const nscoord* aSpacing = nsnull) = 0;
-
-  enum GraphicDataType {
-    NATIVE_CAIRO_CONTEXT = 1,
-    NATIVE_GDK_DRAWABLE = 2,
-    NATIVE_WINDOWS_DC = 3,
-    NATIVE_MAC_THING = 4,
-    NATIVE_THEBES_CONTEXT = 5,
-    NATIVE_OS2_PS = 6
-  };
-  /**
-   * Retrieve the native graphic data given by aType. Return
-   * nsnull if not available.
-   */
-  virtual void* GetNativeGraphicData(GraphicDataType aType) = 0;
-
-#ifdef MOZ_MATHML
-  /**
-   * Returns bounding metrics (in app units) of an 8-bit character string
-   * @param aString string to measure
-   * @param aLength number of characters in string
-   * @return aBoundingMetrics struct that contains various metrics (see below)
-   * @return error status
-   */
-  NS_IMETHOD
-  GetBoundingMetrics(const char*        aString,
-                     PRUint32           aLength,
-                     nsBoundingMetrics& aBoundingMetrics) = 0;
-  /**
-   * Returns bounding metrics (in app units) of an Unicode character string
-   * @param aString string to measure
-   * @param aLength number of characters in string
-   * @param aFontID an optional out parameter used to store a
-   *        font identifier that can be passed into the GetBoundingMetrics()
-   *        methods to speed measurements
-   * @return aBoundingMetrics struct that contains various metrics (see below)
-   * @return error status
-   */
-  NS_IMETHOD
-  GetBoundingMetrics(const PRUnichar*   aString,
-                     PRUint32           aLength,
-                     nsBoundingMetrics& aBoundingMetrics,
-                     PRInt32*           aFontID = nsnull) = 0;
-#endif
-
-
-  /**
-   * Let the device context know whether we want text reordered with
-   * right-to-left base direction
-   */
-  NS_IMETHOD SetRightToLeftText(PRBool aIsRTL) = 0;
-
-  /**
-   * This sets the direction of the text; all characters should be
-   * overridden to have this direction.
-   */
-  virtual void SetTextRunRTL(PRBool aIsRTL) = 0;
-
-  /**
-   * Find the closest cursor position for a given x coordinate.
-   *
-   * This will find the closest byte index for a given x coordinate.
-   * This takes into account grapheme clusters and bidi text.
-   *
-   * @param aText Text on which to operate.
-   * @param aLength Length of the text.
-   * @param aPt the x/y position in the string to check.
-   *
-   * @return Index where the cursor falls.  If the return is zero,
-   *   it's before the first character, if it falls off the end of
-   *   the string it's the length of the string + 1.
-   *
-   */
-  virtual PRInt32 GetPosition(const PRUnichar *aText,
-                              PRUint32 aLength,
-                              nsPoint aPt) = 0;
-
-  /**
-   * Get the width for the specific range of a given string.
-   *
-   * This function is similar to other GetWidth functions, except that
-   * it gets the width for a part of the string instead of the entire
-   * string.  This is useful when you're interested in finding out the
-   * length of a chunk in the middle of the string.  Lots of languages
-   * require you to include surrounding information to accurately
-   * determine the length of a substring.
-   *
-   * @param aText Text on which to operate
-   * @param aLength Length of the text
-   * @param aStart Start index into the string
-   * @param aEnd End index into the string (inclusive)
-   * @param aWidth Returned with in app coordinates
-   *
-   */
-  NS_IMETHOD GetRangeWidth(const PRUnichar *aText,
-                           PRUint32 aLength,
-                           PRUint32 aStart,
-                           PRUint32 aEnd,
-                           PRUint32 &aWidth) = 0;
-
-  /**
-   * Get the width for the specific range of a given string.
-   *
-   * Same as GetRangeWidth for PRUnichar, but takes a char * as the
-   * text argument.
-   *
-   */
-  NS_IMETHOD GetRangeWidth(const char *aText,
-                           PRUint32 aLength,
-                           PRUint32 aStart,
-                           PRUint32 aEnd,
-                           PRUint32 &aWidth) = 0;
-
-  /**
-   * Render an encapsulated postscript object onto the current rendering
-   * surface.
-   *
-   * The EPS object must conform to the EPSF standard. See Adobe
-   * specification #5002, "Encapsulated PostScript File Format Specification"
-   * at <http://partners.adobe.com/asn/developer/pdfs/tn/5002.EPSF_Spec.pdf>.
-   * In particular, the EPS object must contain a BoundingBox comment.
-   *
-   * @param aRect  Rectangle in which to render the EPSF.
-   * @param aDataFile - plugin data stored in a file
-   * @return NS_OK for success, or a suitable error value.
-   *         NS_ERROR_NOT_IMPLEMENTED is returned if the rendering context
-   *         doesn't support rendering EPSF, 
-   */
-  NS_IMETHOD RenderEPS(const nsRect& aRect, FILE *aDataFile) = 0;
-
-  /**
-   * Return the Thebes gfxContext associated with this nsIRenderingContext.
-   */
-  virtual gfxContext *ThebesContext() = 0;
-};
-
-NS_DEFINE_STATIC_IID_ACCESSOR(nsIRenderingContext, NS_IRENDERING_CONTEXT_IID)
-
-//flags for copy CopyOffScreenBits
-
-//when performing the blit, use the region, if any,
-//that exists in the source drawingsurface as a
-//blit mask.
-#define NS_COPYBITS_USE_SOURCE_CLIP_REGION  0x0001
-
-//transform the source offsets by the xform in the
-//rendering context
-#define NS_COPYBITS_XFORM_SOURCE_VALUES     0x0002
-
-//transform the destination rect by the xform in the
-//rendering context
-#define NS_COPYBITS_XFORM_DEST_VALUES       0x0004
-
-//this is basically a hack and is used by callers
-//who have selected an alternate drawing surface and
-//wish the copy to happen to that buffer rather than
-//the "front" buffer. i'm not proud of this. MMP
-//XXX: This is no longer needed by the XPCODE. It will
-//be removed once all of the platform specific nsRenderingContext's
-//stop using it.
-#define NS_COPYBITS_TO_BACK_BUFFER          0x0008
-
-/* Struct used to represent the overall extent of a string
-   whose rendering may involve switching between different
-   fonts that have different metrics.
-*/
-struct nsTextDimensions {
-  // max ascent amongst all the fonts needed to represent the string
-  nscoord ascent;
-
-  // max descent amongst all the fonts needed to represent the string
-  nscoord descent;
-
-  // width of the string
-  nscoord width;
-
-
-  nsTextDimensions()
-  {
-    Clear();
-  }
-
-  /* Set all member data to zero */
-  void 
-  Clear() {
-    ascent = descent = width = 0;
-  }
-
-  /* Sum with another dimension */
-  void 
-  Combine(const nsTextDimensions& aOther) {
-    if (ascent < aOther.ascent) ascent = aOther.ascent;
-    if (descent < aOther.descent) descent = aOther.descent;   
-    width += aOther.width;
-  }
-};
-
-#ifdef MOZ_MATHML
-/* Struct used for accurate measurements of a string in order
-   to allow precise positioning when processing MathML.
-*/
-struct nsBoundingMetrics {
-
-  ///////////
-  // Metrics that _exactly_ enclose the text:
-
-  // The character coordinate system is the one used on X Windows:
-  // 1. The origin is located at the intersection of the baseline
-  //    with the left of the character's cell.
-  // 2. All horizontal bearings are oriented from left to right.
-  // 3. The ascent is oriented from bottom to top (being 0 at the orgin).
-  // 4. The descent is oriented from top to bottom (being 0 at the origin).
-
-  // Note that Win32/Mac/PostScript use a different convention for
-  // the descent (all vertical measurements are oriented from bottom
-  // to top on these palatforms). Make sure to flip the sign of the
-  // descent on these platforms for cross-platform compatibility.
-
-  // Any of the following member variables listed here can have 
-  // positive or negative value.
-
-  nscoord leftBearing;
-       /* The horizontal distance from the origin of the drawing
-          operation to the left-most part of the drawn string. */
-
-  nscoord rightBearing;
-       /* The horizontal distance from the origin of the drawing
-          operation to the right-most part of the drawn string.
-          The _exact_ width of the string is therefore:
-          rightBearing - leftBearing */
-  
-  nscoord ascent;
-       /* The vertical distance from the origin of the drawing 
-          operation to the top-most part of the drawn string. */
-
-  nscoord descent;
-       /* The vertical distance from the origin of the drawing 
-          operation to the bottom-most part of the drawn string.
-          The _exact_ height of the string is therefore:
-          ascent + descent */
-
-  //////////
-  // Metrics for placing other surrounding text:
-
-  nscoord width;
-       /* The horizontal distance from the origin of the drawing
-          operation to the correct origin for drawing another string
-          to follow the current one. Depending on the font, this
-          could be greater than or less than the right bearing. */
-
-  nsBoundingMetrics() {
-    Clear();
-  }
-
-  //////////
-  // Utility methods and operators:
-
-  /* Set all member data to zero */
-  void 
-  Clear() {
-    leftBearing = rightBearing = 0;
-    ascent = descent = width = 0;
-  }
-
-  /* Append another bounding metrics */
-  void 
-  operator += (const nsBoundingMetrics& bm) {
-    if (ascent + descent == 0 && rightBearing - leftBearing == 0) {
-      ascent = bm.ascent;
-      descent = bm.descent;
-      leftBearing = width + bm.leftBearing;
-      rightBearing = width + bm.rightBearing;
-    }
-    else {
-      if (ascent < bm.ascent) ascent = bm.ascent;
-      if (descent < bm.descent) descent = bm.descent;   
-      leftBearing = PR_MIN(leftBearing, width + bm.leftBearing);
-      rightBearing = PR_MAX(rightBearing, width + bm.rightBearing);
-    }
-    width += bm.width;
-  }
-};
-#endif // MOZ_MATHML
-
-#endif /* nsIRenderingContext_h___ */
--- a/gfx/src/nsIThebesFontMetrics.h
+++ b/gfx/src/nsIThebesFontMetrics.h
@@ -34,21 +34,21 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef __nsIThebesFontMetrics_h
 #define __nsIThebesFontMetrics_h
 
 #include "nsIFontMetrics.h"
-#include "nsIRenderingContext.h"
 
-class nsThebesRenderingContext;
-
+struct nsTextDimensions;
+struct nsBoundingMetrics;
 class gfxFontGroup;
+class nsRenderingContext;
 
 class nsIThebesFontMetrics : public nsIFontMetrics {
 public:
     // Get the width for this string.  aWidth will be updated with the
     // width in points, not twips.  Callers must convert it if they
     // want it in another format.
     virtual nsresult GetWidth(const char* aString, PRUint32 aLength,
                               nscoord& aWidth, nsThebesRenderingContext *aContext) = 0;
rename from gfx/src/nsThebesRenderingContext.cpp
rename to gfx/src/nsRenderingContext.cpp
--- a/gfx/src/nsThebesRenderingContext.cpp
+++ b/gfx/src/nsRenderingContext.cpp
@@ -32,17 +32,17 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#include "nsThebesRenderingContext.h"
+#include "nsRenderingContext.h"
 #include "nsThebesDeviceContext.h"
 
 #include "nsString.h"
 #include "nsTransform2D.h"
 #include "nsIServiceManager.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsGfxCIID.h"
 
@@ -55,40 +55,32 @@
 
 #include "gfxPlatform.h"
 
 #ifdef XP_WIN
 #include "gfxWindowsSurface.h"
 #include "cairo-win32.h"
 #endif
 
-static NS_DEFINE_CID(kRegionCID, NS_REGION_CID);
-
-//////////////////////////////////////////////////////////////////////
-
 // XXXTodo: rename FORM_TWIPS to FROM_APPUNITS
 #define FROM_TWIPS(_x)  ((gfxFloat)((_x)/(mP2A)))
 #define FROM_TWIPS_INT(_x)  (NSToIntRound((gfxFloat)((_x)/(mP2A))))
 #define TO_TWIPS(_x)    ((nscoord)((_x)*(mP2A)))
 #define GFX_RECT_FROM_TWIPS_RECT(_r)   (gfxRect(FROM_TWIPS((_r).x), FROM_TWIPS((_r).y), FROM_TWIPS((_r).width), FROM_TWIPS((_r).height)))
 
-//////////////////////////////////////////////////////////////////////
-
-NS_IMPL_ISUPPORTS1(nsThebesRenderingContext, nsIRenderingContext)
-
 // Hard limit substring lengths to 8000 characters ... this lets us statically
 // size the cluster buffer array in FindSafeLength
 #define MAX_GFX_TEXT_BUF_SIZE 8000
-static PRInt32 GetMaxChunkLength(nsThebesRenderingContext* aContext)
+static PRInt32 GetMaxChunkLength(nsRenderingContext* aContext)
 {
     PRInt32 len = aContext->GetMaxStringLength();
     return PR_MIN(len, MAX_GFX_TEXT_BUF_SIZE);
 }
 
-static PRInt32 FindSafeLength(nsThebesRenderingContext* aContext,
+static PRInt32 FindSafeLength(nsRenderingContext* aContext,
                               const PRUnichar *aString, PRUint32 aLength,
                               PRUint32 aMaxChunkLength)
 {
     if (aLength <= aMaxChunkLength)
         return aLength;
 
     PRInt32 len = aMaxChunkLength;
 
@@ -102,65 +94,55 @@ static PRInt32 FindSafeLength(nsThebesRe
         // unless there are languages that allow clusters of arbitrary size.
         // If there are and someone feeds us a 500+ character cluster, too
         // bad.
         return aMaxChunkLength;
     }
     return len;
 }
 
-static PRInt32 FindSafeLength(nsThebesRenderingContext* aContext,
+static PRInt32 FindSafeLength(nsRenderingContext* aContext,
                               const char *aString, PRUint32 aLength,
                               PRUint32 aMaxChunkLength)
 {
     // Since it's ASCII, we don't need to worry about clusters or RTL
     return PR_MIN(aLength, aMaxChunkLength);
 }
 
-nsThebesRenderingContext::nsThebesRenderingContext()
-  : mLineStyle(nsLineStyle_kNone)
-  , mColor(NS_RGB(0,0,0))
-{
-}
-
-nsThebesRenderingContext::~nsThebesRenderingContext()
-{
-}
-
 //////////////////////////////////////////////////////////////////////
 //// nsIRenderingContext
 
-NS_IMETHODIMP
-nsThebesRenderingContext::Init(nsIDeviceContext* aContext, gfxASurface *aThebesSurface)
+nsresult
+nsRenderingContext::Init(nsIDeviceContext* aContext, gfxASurface *aThebesSurface)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::Init ctx %p thebesSurface %p\n", this, aContext, aThebesSurface));
 
     mDeviceContext = aContext;
     mWidget = nsnull;
 
     mThebes = new gfxContext(aThebesSurface);
 
     return (CommonInit());
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::Init(nsIDeviceContext* aContext, gfxContext *aThebesContext)
+nsresult
+nsRenderingContext::Init(nsIDeviceContext* aContext, gfxContext *aThebesContext)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::Init ctx %p thebesContext %p\n", this, aContext, aThebesContext));
 
     mDeviceContext = aContext;
     mWidget = nsnull;
 
     mThebes = aThebesContext;
 
     return (CommonInit());
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::Init(nsIDeviceContext* aContext, nsIWidget *aWidget)
+nsresult
+nsRenderingContext::Init(nsIDeviceContext* aContext, nsIWidget *aWidget)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::Init ctx %p widget %p\n", this, aContext, aWidget));
 
     mDeviceContext = aContext;
     mWidget = aWidget;
 
     mThebes = new gfxContext(aWidget->GetThebesSurface());
 
@@ -168,92 +150,91 @@ nsThebesRenderingContext::Init(nsIDevice
     //mThebes->Paint();
 
     //mThebes->Translate(gfxPoint(300,0));
     //mThebes->Rotate(M_PI/4);
 
     return (CommonInit());
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::CommonInit(void)
+nsresult
+nsRenderingContext::CommonInit(void)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::CommonInit\n", this));
 
     mThebes->SetLineWidth(1.0);
 
     mP2A = mDeviceContext->AppUnitsPerDevPixel();
 
     return NS_OK;
 }
 
 already_AddRefed<nsIDeviceContext>
-nsThebesRenderingContext::GetDeviceContext()
+nsRenderingContext::GetDeviceContext()
 {
     NS_IF_ADDREF(mDeviceContext);
     return mDeviceContext.get();
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::PushTranslation(PushedTranslation* aState)
+nsresult
+nsRenderingContext::PushTranslation(PushedTranslation* aState)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::PushTranslation\n", this));
 
     // XXX this is slow!
     PushState();
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::PopTranslation(PushedTranslation* aState)
+nsresult
+nsRenderingContext::PopTranslation(PushedTranslation* aState)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::PopTranslation\n", this));
 
     // XXX this is slow!
     PopState();
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::SetTranslation(const nsPoint& aPt)
+nsresult
+nsRenderingContext::SetTranslation(const nsPoint& aPt)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetTranslation %d %d\n", this, aPt.x, aPt.y));
 
     gfxMatrix newMat(mThebes->CurrentMatrix());
     newMat.x0 = aPt.x;
     newMat.y0 = aPt.y;
     mThebes->SetMatrix(newMat);
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::PushState()
+nsresult
+nsRenderingContext::PushState()
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::PushState\n", this));
 
     mThebes->Save();
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::PopState()
+nsresult
+nsRenderingContext::PopState()
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::PopState\n", this));
 
     mThebes->Restore();
     return NS_OK;
 }
 
 //
 // clipping
 //
 
-NS_IMETHODIMP
-nsThebesRenderingContext::SetClipRect(const nsRect& aRect,
-                                      nsClipCombine aCombine)
+nsresult
+nsRenderingContext::SetClipRect(const nsRect& aRect, nsClipCombine aCombine)
 {
     //return NS_OK;
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetClipRect [%d,%d,%d,%d] %d\n", this, aRect.x, aRect.y, aRect.width, aRect.height, aCombine));
 
     if (aCombine == nsClipCombine_kReplace) {
         mThebes->ResetClip();
     } else if (aCombine != nsClipCombine_kIntersect) {
         NS_WARNING("Unexpected usage of SetClipRect");
@@ -270,32 +251,32 @@ nsThebesRenderingContext::SetClipRect(co
         mThebes->Rectangle(clipRect);
     }
 
     mThebes->Clip();
 
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::SetClipRegion(const nsIntRegion& aRegion,
-                                        nsClipCombine aCombine)
+nsresult
+nsRenderingContext::SetClipRegion(const nsIntRegion& aRegion,
+                                  nsClipCombine aCombine)
 {
     // Region is in device coords, no transformation.
     // This should only be called when there is no transform in place, when we
     // we just start painting a widget. The region is set by the platform paint
     // routine.
     NS_ASSERTION(aCombine == nsClipCombine_kReplace,
                  "Unexpected usage of SetClipRegion");
 
     gfxMatrix mat = mThebes->CurrentMatrix();
     mThebes->IdentityMatrix();
 
     mThebes->ResetClip();
-    
+
     mThebes->NewPath();
     nsIntRegionRectIterator iter(aRegion);
     const nsIntRect* rect;
     while ((rect = iter.Next())) {
         mThebes->Rectangle(gfxRect(rect->x, rect->y, rect->width, rect->height),
                            PR_TRUE);
     }
     mThebes->Clip();
@@ -304,18 +285,18 @@ nsThebesRenderingContext::SetClipRegion(
 
     return NS_OK;
 }
 
 //
 // other junk
 //
 
-NS_IMETHODIMP
-nsThebesRenderingContext::SetLineStyle(nsLineStyle aLineStyle)
+nsresult
+nsRenderingContext::SetLineStyle(nsLineStyle aLineStyle)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetLineStyle %d\n", this, aLineStyle));
     switch (aLineStyle) {
         case nsLineStyle_kSolid:
             mThebes->SetDash(gfxContext::gfxLineSolid);
             break;
         case nsLineStyle_kDashed:
             mThebes->SetDash(gfxContext::gfxLineDashed);
@@ -330,55 +311,55 @@ nsThebesRenderingContext::SetLineStyle(n
             break;
     }
 
     mLineStyle = aLineStyle;
     return NS_OK;
 }
 
 
-NS_IMETHODIMP
-nsThebesRenderingContext::SetColor(nscolor aColor)
+nsresult
+nsRenderingContext::SetColor(nscolor aColor)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetColor 0x%08x\n", this, aColor));
     /* This sets the color assuming the sRGB color space, since that's what all
      * CSS colors are defined to be in by the spec.
      */
     mThebes->SetColor(gfxRGBA(aColor));
 
     mColor = aColor;
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::GetColor(nscolor &aColor) const
+nsresult
+nsRenderingContext::GetColor(nscolor &aColor) const
 {
     aColor = mColor;
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::Translate(const nsPoint& aPt)
+nsresult
+nsRenderingContext::Translate(const nsPoint& aPt)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::Translate %d %d\n", this, aPt.x, aPt.y));
     mThebes->Translate (gfxPoint(FROM_TWIPS(aPt.x), FROM_TWIPS(aPt.y)));
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::Scale(float aSx, float aSy)
+nsresult
+nsRenderingContext::Scale(float aSx, float aSy)
 {
     // as far as I can tell, noone actually calls this
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::Scale %f %f\n", this, aSx, aSy));
     mThebes->Scale (aSx, aSy);
     return NS_OK;
 }
 
 void
-nsThebesRenderingContext::UpdateTempTransformMatrix()
+nsRenderingContext::UpdateTempTransformMatrix()
 {
     //PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::UpdateTempTransformMatrix\n", this));
 
     /*****
      * Thebes matrix layout:   gfx matrix layout:
      * | xx yx 0 |            | m00 m01  0 |
      * | xy yy 0 |            | m10 m11  0 |
      * | x0 y0 1 |            | m20 m21  1 |
@@ -386,17 +367,17 @@ nsThebesRenderingContext::UpdateTempTran
 
     const gfxMatrix& ctm = mThebes->CurrentMatrix();
     NS_ASSERTION(ctm.yx == 0 && ctm.xy == 0, "Can't represent Thebes matrix to Gfx");
     mTempTransform.SetToTranslate(TO_TWIPS(ctm.x0), TO_TWIPS(ctm.y0));
     mTempTransform.AddScale(ctm.xx, ctm.yy);
 }
 
 nsTransform2D&
-nsThebesRenderingContext::CurrentTransform()
+nsRenderingContext::CurrentTransform()
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::CurrentTransform\n", this));
     UpdateTempTransformMatrix();
     return mTempTransform;
 }
 
 /****
  **** XXXXXX
@@ -405,47 +386,46 @@ nsThebesRenderingContext::CurrentTransfo
  **** has a built in twips to pixels ratio.  That is, you pass in
  **** twips to any nsTransform2D TransformCoord method, and you
  **** get back pixels.  This makes no sense.  We don't do this.
  **** This in turn breaks SVG and <object>; those should just be
  **** fixed to not use this!
  ****/
 
 nsTransform2D*
-nsThebesRenderingContext::GetCurrentTransform()
+nsRenderingContext::GetCurrentTransform()
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG,
            ("## %p nsTRC::GetCurrentTransform\n", this));
     UpdateTempTransformMatrix();
     return &mTempTransform;
 }
 
 void
-nsThebesRenderingContext::TransformCoord (nscoord *aX, nscoord *aY)
+nsRenderingContext::TransformCoord (nscoord *aX, nscoord *aY)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::TransformCoord\n", this));
 
     gfxPoint pt(FROM_TWIPS(*aX), FROM_TWIPS(*aY));
 
     pt = mThebes->UserToDevice (pt);
 
     *aX = TO_TWIPS(pt.x);
     *aY = TO_TWIPS(pt.y);
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::DrawLine(const nsPoint& aStartPt,
-                                   const nsPoint& aEndPt)
+nsresult
+nsRenderingContext::DrawLine(const nsPoint& aStartPt, const nsPoint& aEndPt)
 {
     return DrawLine(aStartPt.x, aStartPt.y, aEndPt.x, aEndPt.y);
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::DrawLine(nscoord aX0, nscoord aY0,
-                                   nscoord aX1, nscoord aY1)
+nsresult
+nsRenderingContext::DrawLine(nscoord aX0, nscoord aY0,
+                             nscoord aX1, nscoord aY1)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG,
            ("## %p nsTRC::DrawLine %d %d %d %d\n", this, aX0, aY0, aX1, aY1));
 
     gfxPoint p0 = gfxPoint(FROM_TWIPS(aX0), FROM_TWIPS(aY0));
     gfxPoint p1 = gfxPoint(FROM_TWIPS(aX1), FROM_TWIPS(aY1));
 
     // we can't draw thick lines with gfx, so we always assume we want
@@ -480,30 +460,31 @@ nsThebesRenderingContext::DrawLine(nscoo
         mThebes->NewPath();
         mThebes->Line(p0, p1);
         mThebes->Stroke();
     }
 
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::DrawRect(const nsRect& aRect)
+nsresult
+nsRenderingContext::DrawRect(const nsRect& aRect)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::DrawRect [%d,%d,%d,%d]\n", this, aRect.x, aRect.y, aRect.width, aRect.height));
 
     mThebes->NewPath();
     mThebes->Rectangle(GFX_RECT_FROM_TWIPS_RECT(aRect), PR_TRUE);
     mThebes->Stroke();
 
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
+nsresult
+nsRenderingContext::DrawRect(nscoord aX, nscoord aY,
+                             nscoord aWidth, nscoord aHeight)
 {
     DrawRect(nsRect(aX, aY, aWidth, aHeight));
     return NS_OK;
 }
 
 
 /* Clamp r to (0,0) (2^23,2^23)
  * these are to be device coordinates.
@@ -561,18 +542,18 @@ ConditionRect(gfxRect& r) {
     }
 
     if (r.pos.y + r.size.height > CAIRO_COORD_MAX) {
         r.size.height = CAIRO_COORD_MAX - r.pos.y;
     }
     return PR_TRUE;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::FillRect(const nsRect& aRect)
+nsresult
+nsRenderingContext::FillRect(const nsRect& aRect)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::FillRect [%d,%d,%d,%d]\n", this, aRect.x, aRect.y, aRect.width, aRect.height));
 
     gfxRect r(GFX_RECT_FROM_TWIPS_RECT(aRect));
 
     /* Clamp coordinates to work around a design bug in cairo */
     nscoord bigval = (nscoord)(CAIRO_COORD_MAX*mP2A);
     if (aRect.width > bigval ||
@@ -605,85 +586,89 @@ nsThebesRenderingContext::FillRect(const
 
     mThebes->NewPath();
     mThebes->Rectangle(r, PR_TRUE);
     mThebes->Fill();
 
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
+nsresult
+nsRenderingContext::FillRect(nscoord aX, nscoord aY,
+                             nscoord aWidth, nscoord aHeight)
 {
     FillRect(nsRect(aX, aY, aWidth, aHeight));
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::InvertRect(const nsRect& aRect)
+nsresult
+nsRenderingContext::InvertRect(const nsRect& aRect)
 {
     gfxContext::GraphicsOperator lastOp = mThebes->CurrentOperator();
 
     mThebes->SetOperator(gfxContext::OPERATOR_XOR);
     nsresult rv = FillRect(aRect);
     mThebes->SetOperator(lastOp);
 
     return rv;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
+nsresult
+nsRenderingContext::InvertRect(nscoord aX, nscoord aY,
+                               nscoord aWidth, nscoord aHeight)
 {
     return InvertRect(nsRect(aX, aY, aWidth, aHeight));
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::DrawEllipse(const nsRect& aRect)
+nsresult
+nsRenderingContext::DrawEllipse(const nsRect& aRect)
 {
     return DrawEllipse(aRect.x, aRect.y, aRect.width, aRect.height);
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
+nsresult
+nsRenderingContext::DrawEllipse(nscoord aX, nscoord aY,
+                                nscoord aWidth, nscoord aHeight)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::DrawEllipse [%d,%d,%d,%d]\n", this, aX, aY, aWidth, aHeight));
 
     mThebes->NewPath();
     mThebes->Ellipse(gfxPoint(FROM_TWIPS(aX) + FROM_TWIPS(aWidth)/2.0,
                               FROM_TWIPS(aY) + FROM_TWIPS(aHeight)/2.0),
                      gfxSize(FROM_TWIPS(aWidth),
                              FROM_TWIPS(aHeight)));
     mThebes->Stroke();
 
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::FillEllipse(const nsRect& aRect)
+nsresult
+nsRenderingContext::FillEllipse(const nsRect& aRect)
 {
     return FillEllipse(aRect.x, aRect.y, aRect.width, aRect.height);
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
+nsresult
+nsRenderingContext::FillEllipse(nscoord aX, nscoord aY,
+                                nscoord aWidth, nscoord aHeight)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::FillEllipse [%d,%d,%d,%d]\n", this, aX, aY, aWidth, aHeight));
 
     mThebes->NewPath();
     mThebes->Ellipse(gfxPoint(FROM_TWIPS(aX) + FROM_TWIPS(aWidth)/2.0,
                               FROM_TWIPS(aY) + FROM_TWIPS(aHeight)/2.0),
                      gfxSize(FROM_TWIPS(aWidth),
                              FROM_TWIPS(aHeight)));
     mThebes->Fill();
 
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::FillPolygon(const nsPoint twPoints[], PRInt32 aNumPoints)
+nsresult
+nsRenderingContext::FillPolygon(const nsPoint twPoints[], PRInt32 aNumPoints)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::FillPolygon %d\n", this, aNumPoints));
 
     if (aNumPoints == 0)
         return NS_OK;
 
     if (aNumPoints == 4) {
     }
@@ -698,17 +683,17 @@ nsThebesRenderingContext::FillPolygon(co
     mThebes->NewPath();
     mThebes->Polygon(pxPoints, aNumPoints);
     mThebes->Fill();
 
     return NS_OK;
 }
 
 void*
-nsThebesRenderingContext::GetNativeGraphicData(GraphicDataType aType)
+nsRenderingContext::GetNativeGraphicData(GraphicDataType aType)
 {
     if (aType == NATIVE_GDK_DRAWABLE)
     {
         if (mWidget)
             return mWidget->GetNativeData(NS_NATIVE_WIDGET);
     }
     if (aType == NATIVE_THEBES_CONTEXT)
         return mThebes;
@@ -729,35 +714,36 @@ nsThebesRenderingContext::GetNativeGraph
             return nsnull;
         return (void*)(static_cast<gfxOS2Surface*>(static_cast<gfxASurface*>(surf.get()))->GetPS());
     }
 #endif
 
     return nsnull;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::PushFilter(const nsRect& twRect, PRBool aAreaIsOpaque, float aOpacity)
+nsresult
+nsRenderingContext::PushFilter(const nsRect& twRect, PRBool aAreaIsOpaque,
+                               float aOpacity)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG,
            ("## %p nsTRC::PushFilter [%d,%d,%d,%d] isOpaque: %d opacity: %f\n",
             this, twRect.x, twRect.y, twRect.width, twRect.height,
             aAreaIsOpaque, aOpacity));
 
     mOpacityArray.AppendElement(aOpacity);
 
     mThebes->Save();
     mThebes->Clip(GFX_RECT_FROM_TWIPS_RECT(twRect));
     mThebes->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
 
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::PopFilter()
+nsresult
+nsRenderingContext::PopFilter()
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::PopFilter\n"));
 
     if (mOpacityArray.Length() > 0) {
         float f = mOpacityArray[mOpacityArray.Length()-1];
         mOpacityArray.RemoveElementAt(mOpacityArray.Length()-1);
 
         mThebes->PopGroupToSource();
@@ -775,145 +761,146 @@ nsThebesRenderingContext::PopFilter()
 
 
     return NS_OK;
 }
 
 //
 // text junk
 //
-NS_IMETHODIMP
-nsThebesRenderingContext::SetRightToLeftText(PRBool aIsRTL)
+nsresult
+nsRenderingContext::SetRightToLeftText(PRBool aIsRTL)
 {
     return mFontMetrics->SetRightToLeftText(aIsRTL);
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::GetRightToLeftText(PRBool* aIsRTL)
+nsresult
+nsRenderingContext::GetRightToLeftText(PRBool* aIsRTL)
 {
     *aIsRTL = mFontMetrics->GetRightToLeftText();
     return NS_OK;
 }
 
 void
-nsThebesRenderingContext::SetTextRunRTL(PRBool aIsRTL)
+nsRenderingContext::SetTextRunRTL(PRBool aIsRTL)
 {
     mFontMetrics->SetTextRunRTL(aIsRTL);
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::SetFont(const nsFont& aFont, nsIAtom* aLanguage,
-                                  gfxUserFontSet *aUserFontSet)
+nsresult
+nsRenderingContext::SetFont(const nsFont& aFont, nsIAtom* aLanguage,
+                            gfxUserFontSet *aUserFontSet)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetFont %p\n", this, &aFont));
 
     nsCOMPtr<nsIFontMetrics> newMetrics;
     mDeviceContext->GetMetricsFor(aFont, aLanguage, aUserFontSet,
                                   *getter_AddRefs(newMetrics));
     mFontMetrics = reinterpret_cast<nsIThebesFontMetrics*>(newMetrics.get());
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::SetFont(const nsFont& aFont,
-                                  gfxUserFontSet *aUserFontSet)
+nsresult
+nsRenderingContext::SetFont(const nsFont& aFont,
+                            gfxUserFontSet *aUserFontSet)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetFont %p\n", this, &aFont));
 
     nsCOMPtr<nsIFontMetrics> newMetrics;
     mDeviceContext->GetMetricsFor(aFont, nsnull, aUserFontSet,
                                   *getter_AddRefs(newMetrics));
     mFontMetrics = reinterpret_cast<nsIThebesFontMetrics*>(newMetrics.get());
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::SetFont(nsIFontMetrics *aFontMetrics)
+nsresult
+nsRenderingContext::SetFont(nsIFontMetrics *aFontMetrics)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetFont[Metrics] %p\n", this, aFontMetrics));
 
     mFontMetrics = static_cast<nsIThebesFontMetrics*>(aFontMetrics);
     return NS_OK;
 }
 
 already_AddRefed<nsIFontMetrics>
-nsThebesRenderingContext::GetFontMetrics()
+nsRenderingContext::GetFontMetrics()
 {
     NS_IF_ADDREF(mFontMetrics);
     return mFontMetrics.get();
 }
 
 PRInt32
-nsThebesRenderingContext::GetMaxStringLength()
+nsRenderingContext::GetMaxStringLength()
 {
     if (!mFontMetrics)
         return 1;
     return mFontMetrics->GetMaxStringLength();
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::GetWidth(char aC, nscoord &aWidth)
+nsresult
+nsRenderingContext::GetWidth(char aC, nscoord &aWidth)
 {
     if (aC == ' ' && mFontMetrics)
         return mFontMetrics->GetSpaceWidth(aWidth);
 
     return GetWidth(&aC, 1, aWidth);
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::GetWidth(PRUnichar aC, nscoord &aWidth, PRInt32 *aFontID)
+nsresult
+nsRenderingContext::GetWidth(PRUnichar aC, nscoord &aWidth, PRInt32 *aFontID)
 {
     return GetWidth(&aC, 1, aWidth, aFontID);
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::GetWidth(const nsString& aString, nscoord &aWidth,
+nsresult
+nsRenderingContext::GetWidth(const nsString& aString, nscoord &aWidth,
                                    PRInt32 *aFontID)
 {
     return GetWidth(aString.get(), aString.Length(), aWidth, aFontID);
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::GetWidth(const char* aString, nscoord& aWidth)
+nsresult
+nsRenderingContext::GetWidth(const char* aString, nscoord& aWidth)
 {
     return GetWidth(aString, strlen(aString), aWidth);
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::DrawString(const nsString& aString, nscoord aX, nscoord aY,
-                                     PRInt32 aFontID, const nscoord* aSpacing)
+nsresult
+nsRenderingContext::DrawString(const nsString& aString, nscoord aX, nscoord aY,
+                               PRInt32 aFontID, const nscoord* aSpacing)
 {
-    return DrawString(aString.get(), aString.Length(), aX, aY, aFontID, aSpacing);
+    return DrawString(aString.get(), aString.Length(), aX, aY,
+                      aFontID, aSpacing);
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::GetWidth(const char* aString,
-                                   PRUint32 aLength,
-                                   nscoord& aWidth)
+nsresult
+nsRenderingContext::GetWidth(const char* aString,
+                             PRUint32 aLength,
+                             nscoord& aWidth)
 {
     PRUint32 maxChunkLength = GetMaxChunkLength(this);
     aWidth = 0;
     while (aLength > 0) {
         PRInt32 len = FindSafeLength(this, aString, aLength, maxChunkLength);
         nscoord width;
         nsresult rv = GetWidthInternal(aString, len, width);
         if (NS_FAILED(rv))
             return rv;
         aWidth += width;
         aLength -= len;
         aString += len;
     }
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::GetWidth(const PRUnichar *aString,
-                                   PRUint32 aLength,
-                                   nscoord &aWidth,
-                                   PRInt32 *aFontID)
+nsresult
+nsRenderingContext::GetWidth(const PRUnichar *aString,
+                             PRUint32 aLength,
+                             nscoord &aWidth,
+                             PRInt32 *aFontID)
 {
     PRUint32 maxChunkLength = GetMaxChunkLength(this);
     aWidth = 0;
 
     if (aFontID) {
         *aFontID = 0;
     }
 
@@ -925,20 +912,20 @@ nsThebesRenderingContext::GetWidth(const
             return rv;
         aWidth += width;
         aLength -= len;
         aString += len;
     }
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::GetTextDimensions(const char* aString,
-                                            PRUint32 aLength,
-                                            nsTextDimensions& aDimensions)
+nsresult
+nsRenderingContext::GetTextDimensions(const char* aString,
+                                      PRUint32 aLength,
+                                      nsTextDimensions& aDimensions)
 {
     PRUint32 maxChunkLength = GetMaxChunkLength(this);
     if (aLength <= maxChunkLength)
         return GetTextDimensionsInternal(aString, aLength, aDimensions);
 
     PRBool firstIteration = PR_TRUE;
     while (aLength > 0) {
         PRInt32 len = FindSafeLength(this, aString, aLength, maxChunkLength);
@@ -956,21 +943,21 @@ nsThebesRenderingContext::GetTextDimensi
         }
         aLength -= len;
         aString += len;
         firstIteration = PR_FALSE;
     }
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::GetTextDimensions(const PRUnichar* aString,
-                                            PRUint32 aLength,
-                                            nsTextDimensions& aDimensions,
-                                            PRInt32* aFontID)
+nsresult
+nsRenderingContext::GetTextDimensions(const PRUnichar* aString,
+                                      PRUint32 aLength,
+                                      nsTextDimensions& aDimensions,
+                                      PRInt32* aFontID)
 {
     PRUint32 maxChunkLength = GetMaxChunkLength(this);
     if (aLength <= maxChunkLength)
         return GetTextDimensionsInternal(aString, aLength, aDimensions);
 
     if (aFontID) {
         *aFontID = nsnull;
     }
@@ -993,26 +980,26 @@ nsThebesRenderingContext::GetTextDimensi
         aLength -= len;
         aString += len;
         firstIteration = PR_FALSE;
     }
     return NS_OK;
 }
 
 #if defined(_WIN32) || defined(XP_OS2) || defined(MOZ_X11)
-NS_IMETHODIMP
-nsThebesRenderingContext::GetTextDimensions(const char*       aString,
-                                            PRInt32           aLength,
-                                            PRInt32           aAvailWidth,
-                                            PRInt32*          aBreaks,
-                                            PRInt32           aNumBreaks,
-                                            nsTextDimensions& aDimensions,
-                                            PRInt32&          aNumCharsFit,
-                                            nsTextDimensions& aLastWordDimensions,
-                                            PRInt32*          aFontID)
+nsresult
+nsRenderingContext::GetTextDimensions(const char*       aString,
+                                      PRInt32           aLength,
+                                      PRInt32           aAvailWidth,
+                                      PRInt32*          aBreaks,
+                                      PRInt32           aNumBreaks,
+                                      nsTextDimensions& aDimensions,
+                                      PRInt32&          aNumCharsFit,
+                                      nsTextDimensions& aLastWordDimensions,
+                                      PRInt32*          aFontID)
 {
     PRUint32 maxChunkLength = GetMaxChunkLength(this);
     if (aLength <= PRInt32(maxChunkLength))
         return GetTextDimensionsInternal(aString, aLength, aAvailWidth, aBreaks, aNumBreaks,
                                          aDimensions, aNumCharsFit, aLastWordDimensions, aFontID);
 
     if (aFontID) {
         *aFontID = 0;
@@ -1049,26 +1036,26 @@ nsThebesRenderingContext::GetTextDimensi
         aNumCharsFit = aBreaks[wordCount];
         aLastWordDimensions = dimensions;
     }
     // aDimensions width should include all the text
     aDimensions.width = x;
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::GetTextDimensions(const PRUnichar*  aString,
-                                            PRInt32           aLength,
-                                            PRInt32           aAvailWidth,
-                                            PRInt32*          aBreaks,
-                                            PRInt32           aNumBreaks,
-                                            nsTextDimensions& aDimensions,
-                                            PRInt32&          aNumCharsFit,
-                                            nsTextDimensions& aLastWordDimensions,
-                                            PRInt32*          aFontID)
+nsresult
+nsRenderingContext::GetTextDimensions(const PRUnichar*  aString,
+                                      PRInt32           aLength,
+                                      PRInt32           aAvailWidth,
+                                      PRInt32*          aBreaks,
+                                      PRInt32           aNumBreaks,
+                                      nsTextDimensions& aDimensions,
+                                      PRInt32&          aNumCharsFit,
+                                      nsTextDimensions& aLastWordDimensions,
+                                      PRInt32*          aFontID)
 {
     PRUint32 maxChunkLength = GetMaxChunkLength(this);
     if (aLength <= PRInt32(maxChunkLength))
         return GetTextDimensionsInternal(aString, aLength, aAvailWidth, aBreaks, aNumBreaks,
                                      aDimensions, aNumCharsFit, aLastWordDimensions, aFontID);
 
     if (aFontID) {
         *aFontID = 0;
@@ -1106,20 +1093,20 @@ nsThebesRenderingContext::GetTextDimensi
     }
     // aDimensions width should include all the text
     aDimensions.width = x;
     return NS_OK;
 }
 #endif
 
 #ifdef MOZ_MATHML
-NS_IMETHODIMP
-nsThebesRenderingContext::GetBoundingMetrics(const char*        aString,
-                                             PRUint32           aLength,
-                                             nsBoundingMetrics& aBoundingMetrics)
+nsresult
+nsRenderingContext::GetBoundingMetrics(const char*        aString,
+                                       PRUint32           aLength,
+                                       nsBoundingMetrics& aBoundingMetrics)
 {
     PRUint32 maxChunkLength = GetMaxChunkLength(this);
     if (aLength <= maxChunkLength)
         return GetBoundingMetricsInternal(aString, aLength, aBoundingMetrics);
 
     PRBool firstIteration = PR_TRUE;
     while (aLength > 0) {
         PRInt32 len = FindSafeLength(this, aString, aLength, maxChunkLength);
@@ -1138,21 +1125,21 @@ nsThebesRenderingContext::GetBoundingMet
         }
         aLength -= len;
         aString += len;
         firstIteration = PR_FALSE;
     }
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::GetBoundingMetrics(const PRUnichar*   aString,
-                                             PRUint32           aLength,
-                                             nsBoundingMetrics& aBoundingMetrics,
-                                             PRInt32*           aFontID)
+nsresult
+nsRenderingContext::GetBoundingMetrics(const PRUnichar*   aString,
+                                       PRUint32           aLength,
+                                       nsBoundingMetrics& aBoundingMetrics,
+                                       PRInt32*           aFontID)
 {
     PRUint32 maxChunkLength = GetMaxChunkLength(this);
     if (aLength <= maxChunkLength)
         return GetBoundingMetricsInternal(aString, aLength, aBoundingMetrics, aFontID);
 
     if (aFontID) {
         *aFontID = 0;
     }
@@ -1176,20 +1163,20 @@ nsThebesRenderingContext::GetBoundingMet
         aLength -= len;
         aString += len;
         firstIteration = PR_FALSE;
     }
     return NS_OK;
 }
 #endif
 
-NS_IMETHODIMP
-nsThebesRenderingContext::DrawString(const char *aString, PRUint32 aLength,
-                                   nscoord aX, nscoord aY,
-                                   const nscoord* aSpacing)
+nsresult
+nsRenderingContext::DrawString(const char *aString, PRUint32 aLength,
+                               nscoord aX, nscoord aY,
+                               const nscoord* aSpacing)
 {
     PRUint32 maxChunkLength = GetMaxChunkLength(this);
     while (aLength > 0) {
         PRInt32 len = FindSafeLength(this, aString, aLength, maxChunkLength);
         nsresult rv = DrawStringInternal(aString, len, aX, aY);
         if (NS_FAILED(rv))
             return rv;
         aLength -= len;
@@ -1201,21 +1188,21 @@ nsThebesRenderingContext::DrawString(con
                 return rv;
             aX += width;
             aString += len;
         }
     }
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::DrawString(const PRUnichar *aString, PRUint32 aLength,
-                                   nscoord aX, nscoord aY,
-                                   PRInt32 aFontID,
-                                   const nscoord* aSpacing)
+nsresult
+nsRenderingContext::DrawString(const PRUnichar *aString, PRUint32 aLength,
+                               nscoord aX, nscoord aY,
+                               PRInt32 aFontID,
+                               const nscoord* aSpacing)
 {
     PRUint32 maxChunkLength = GetMaxChunkLength(this);
     if (aLength <= maxChunkLength) {
         return DrawStringInternal(aString, aLength, aX, aY, aFontID, aSpacing);
     }
 
     PRBool isRTL = PR_FALSE;
     GetRightToLeftText(&isRTL);
@@ -1261,170 +1248,175 @@ nsThebesRenderingContext::DrawString(con
         if (aSpacing) {
             aSpacing += len;
         }
     }
     return NS_OK;
 }
 
 nsresult
-nsThebesRenderingContext::GetWidthInternal(const char* aString, PRUint32 aLength, nscoord& aWidth)
+nsRenderingContext::GetWidthInternal(const char* aString, PRUint32 aLength,
+                                     nscoord& aWidth)
 {
 #ifdef DISABLE_TEXT
     aWidth = (8 * aLength);
     return NS_OK;
 #endif
 
     if (aLength == 0) {
         aWidth = 0;
         return NS_OK;
     }
 
     return mFontMetrics->GetWidth(aString, aLength, aWidth, this);
 }
 
 nsresult
-nsThebesRenderingContext::GetWidthInternal(const PRUnichar *aString, PRUint32 aLength,
-                                           nscoord &aWidth, PRInt32 *aFontID)
+nsRenderingContext::GetWidthInternal(const PRUnichar *aString, PRUint32 aLength,
+                                     nscoord &aWidth, PRInt32 *aFontID)
 {
 #ifdef DISABLE_TEXT
     aWidth = (8 * aLength);
     return NS_OK;
 #endif
 
     if (aLength == 0) {
         aWidth = 0;
         return NS_OK;
     }
 
     return mFontMetrics->GetWidth(aString, aLength, aWidth, aFontID, this);
 }
 
 nsresult
-nsThebesRenderingContext::GetTextDimensionsInternal(const char* aString, PRUint32 aLength,
-                                                    nsTextDimensions& aDimensions)
+nsRenderingContext::GetTextDimensionsInternal(const char* aString,
+                                              PRUint32 aLength,
+                                              nsTextDimensions& aDimensions)
 {
     mFontMetrics->GetMaxAscent(aDimensions.ascent);
     mFontMetrics->GetMaxDescent(aDimensions.descent);
     return GetWidth(aString, aLength, aDimensions.width);
 }
 
 nsresult
-nsThebesRenderingContext::GetTextDimensionsInternal(const PRUnichar* aString,
-                                                    PRUint32 aLength,
-                                                    nsTextDimensions& aDimensions,
-                                                    PRInt32* aFontID)
+nsRenderingContext::GetTextDimensionsInternal(const PRUnichar* aString,
+                                              PRUint32 aLength,
+                                              nsTextDimensions& aDimensions,
+                                              PRInt32* aFontID)
 {
     mFontMetrics->GetMaxAscent(aDimensions.ascent);
     mFontMetrics->GetMaxDescent(aDimensions.descent);
     return GetWidth(aString, aLength, aDimensions.width, aFontID);
 }
 
 #if defined(_WIN32) || defined(XP_OS2) || defined(MOZ_X11) || defined(XP_MACOSX) || defined (MOZ_DFB)
 nsresult
-nsThebesRenderingContext::GetTextDimensionsInternal(const char*       aString,
-                                                    PRInt32           aLength,
-                                                    PRInt32           aAvailWidth,
-                                                    PRInt32*          aBreaks,
-                                                    PRInt32           aNumBreaks,
-                                                    nsTextDimensions& aDimensions,
-                                                    PRInt32&          aNumCharsFit,
-                                                    nsTextDimensions& aLastWordDimensions,
-                                                    PRInt32*          aFontID)
+nsRenderingContext::GetTextDimensionsInternal(const char*       aString,
+                                              PRInt32           aLength,
+                                              PRInt32           aAvailWidth,
+                                              PRInt32*          aBreaks,
+                                              PRInt32           aNumBreaks,
+                                              nsTextDimensions& aDimensions,
+                                              PRInt32&          aNumCharsFit,
+                                              nsTextDimensions& aLastWordDimensions,
+                                              PRInt32*          aFontID)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 nsresult
-nsThebesRenderingContext::GetTextDimensionsInternal(const PRUnichar*  aString,
-                                                    PRInt32           aLength,
-                                                    PRInt32           aAvailWidth,
-                                                    PRInt32*          aBreaks,
-                                                    PRInt32           aNumBreaks,
-                                                    nsTextDimensions& aDimensions,
-                                                    PRInt32&          aNumCharsFit,
-                                                    nsTextDimensions& aLastWordDimensions,
-                                                    PRInt32*          aFontID)
+nsRenderingContext::GetTextDimensionsInternal(const PRUnichar*  aString,
+                                              PRInt32           aLength,
+                                              PRInt32           aAvailWidth,
+                                              PRInt32*          aBreaks,
+                                              PRInt32           aNumBreaks,
+                                              nsTextDimensions& aDimensions,
+                                              PRInt32&          aNumCharsFit,
+                                              nsTextDimensions& aLastWordDimensions,
+                                              PRInt32*          aFontID)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 #endif
 
 #ifdef MOZ_MATHML
-nsresult 
-nsThebesRenderingContext::GetBoundingMetricsInternal(const char*        aString,
-                                                     PRUint32           aLength,
-                                                     nsBoundingMetrics& aBoundingMetrics)
+nsresult
+nsRenderingContext::GetBoundingMetricsInternal(const char*        aString,
+                                               PRUint32           aLength,
+                                               nsBoundingMetrics& aBoundingMetrics)
 {
-    return mFontMetrics->GetBoundingMetrics(aString, aLength, this, aBoundingMetrics);
+    return mFontMetrics->GetBoundingMetrics(aString, aLength, this,
+                                            aBoundingMetrics);
 }
 
 nsresult
-nsThebesRenderingContext::GetBoundingMetricsInternal(const PRUnichar*   aString,
-                                                     PRUint32           aLength,
-                                                     nsBoundingMetrics& aBoundingMetrics,
-                                                     PRInt32*           aFontID)
+nsRenderingContext::GetBoundingMetricsInternal(const PRUnichar*   aString,
+                                               PRUint32           aLength,
+                                               nsBoundingMetrics& aBoundingMetrics,
+                                               PRInt32*           aFontID)
 {
-    return mFontMetrics->GetBoundingMetrics(aString, aLength, this, aBoundingMetrics);
+    return mFontMetrics->GetBoundingMetrics(aString, aLength, this,
+                                            aBoundingMetrics);
 }
 #endif // MOZ_MATHML
 
 nsresult
-nsThebesRenderingContext::DrawStringInternal(const char *aString, PRUint32 aLength,
-                                             nscoord aX, nscoord aY,
-                                             const nscoord* aSpacing)
+nsRenderingContext::DrawStringInternal(const char *aString, PRUint32 aLength,
+                                       nscoord aX, nscoord aY,
+                                       const nscoord* aSpacing)
 {
 #ifdef DISABLE_TEXT
     return NS_OK;
 #endif
 
     return mFontMetrics->DrawString(aString, aLength, aX, aY, aSpacing,
                                     this);
 }
 
 nsresult
-nsThebesRenderingContext::DrawStringInternal(const PRUnichar *aString, PRUint32 aLength,
-                                             nscoord aX, nscoord aY,
-                                             PRInt32 aFontID,
-                                             const nscoord* aSpacing)
+nsRenderingContext::DrawStringInternal(const PRUnichar *aString,
+                                       PRUint32 aLength,
+                                       nscoord aX, nscoord aY,
+                                       PRInt32 aFontID,
+                                       const nscoord* aSpacing)
 {
 #ifdef DISABLE_TEXT
     return NS_OK;
 #endif
 
     return mFontMetrics->DrawString(aString, aLength, aX, aY, aFontID,
                                     aSpacing, this);
 }
 
 PRInt32
-nsThebesRenderingContext::GetPosition(const PRUnichar *aText,
-                                      PRUint32 aLength,
-                                      nsPoint aPt)
+nsRenderingContext::GetPosition(const PRUnichar *aText,
+                                PRUint32 aLength,
+                                nsPoint aPt)
 {
-  return -1;
+    return -1;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::GetRangeWidth(const PRUnichar *aText,
-                                        PRUint32 aLength,
-                                        PRUint32 aStart,
-                                        PRUint32 aEnd,
-                                        PRUint32 &aWidth)
-{
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-nsThebesRenderingContext::GetRangeWidth(const char *aText,
-                                        PRUint32 aLength,
-                                        PRUint32 aStart,
-                                        PRUint32 aEnd,
-                                        PRUint32 &aWidth)
-{
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-nsThebesRenderingContext::RenderEPS(const nsRect& aRect, FILE *aDataFile)
+nsresult
+nsRenderingContext::GetRangeWidth(const PRUnichar *aText,
+                                  PRUint32 aLength,
+                                  PRUint32 aStart,
+                                  PRUint32 aEnd,
+                                  PRUint32 &aWidth)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
+nsresult
+nsRenderingContext::GetRangeWidth(const char *aText,
+                                  PRUint32 aLength,
+                                  PRUint32 aStart,
+                                  PRUint32 aEnd,
+                                  PRUint32 &aWidth)
+{
+    return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+nsresult
+nsRenderingContext::RenderEPS(const nsRect& aRect, FILE *aDataFile)
+{
+    return NS_ERROR_NOT_IMPLEMENTED;
+}
+
rename from gfx/src/nsThebesRenderingContext.h
rename to gfx/src/nsRenderingContext.h
--- a/gfx/src/nsThebesRenderingContext.h
+++ b/gfx/src/nsRenderingContext.h
@@ -31,191 +31,360 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#ifndef NSTHEBESRENDERINGCONTEXT__H__
-#define NSTHEBESRENDERINGCONTEXT__H__
+#ifndef NSRENDERINGCONTEXT__H__
+#define NSRENDERINGCONTEXT__H__
 
 #include "nsCOMPtr.h"
 #include "nsTArray.h"
-#include "nsIRenderingContext.h"
 #include "nsIDeviceContext.h"
 #include "nsIFontMetrics.h"
 #include "nsIWidget.h"
 #include "nsPoint.h"
 #include "nsSize.h"
 #include "nsColor.h"
 #include "nsRect.h"
 #include "nsIRegion.h"
 #include "nsTransform2D.h"
 #include "nsIThebesFontMetrics.h"
 #include "gfxContext.h"
 
-class nsThebesRenderingContext : public nsIRenderingContext
+typedef enum {
+    nsClipCombine_kIntersect = 0,
+    nsClipCombine_kUnion = 1,
+    nsClipCombine_kSubtract = 2,
+    nsClipCombine_kReplace = 3
+} nsClipCombine;
+
+typedef enum {
+    nsLineStyle_kNone   = 0,
+    nsLineStyle_kSolid  = 1,
+    nsLineStyle_kDashed = 2,
+    nsLineStyle_kDotted = 3
+} nsLineStyle;
+
+/* Struct used to represent the overall extent of a string
+ * whose rendering may involve switching between different
+ * fonts that have different metrics.
+ */
+struct nsTextDimensions {
+    // max ascent amongst all the fonts needed to represent the string
+    nscoord ascent;
+
+    // max descent amongst all the fonts needed to represent the string
+    nscoord descent;
+
+    // width of the string
+    nscoord width;
+
+
+    nsTextDimensions()
+    {
+        Clear();
+    }
+
+    /* Set all member data to zero */
+    void
+    Clear() {
+        ascent = descent = width = 0;
+    }
+
+    /* Sum with another dimension */
+    void
+    Combine(const nsTextDimensions& aOther) {
+        if (ascent < aOther.ascent) ascent = aOther.ascent;
+        if (descent < aOther.descent) descent = aOther.descent;
+        width += aOther.width;
+    }
+};
+
+#ifdef MOZ_MATHML
+/* Struct used for accurate measurements of a string in order
+ * to allow precise positioning when processing MathML.
+ */
+struct nsBoundingMetrics {
+
+    ///////////
+    // Metrics that _exactly_ enclose the text:
+
+    // The character coordinate system is the one used on X Windows:
+    // 1. The origin is located at the intersection of the baseline
+    //    with the left of the character's cell.
+    // 2. All horizontal bearings are oriented from left to right.
+    // 2. All horizontal bearings are oriented from left to right.
+    // 3. The ascent is oriented from bottom to top (being 0 at the orgin).
+    // 4. The descent is oriented from top to bottom (being 0 at the origin).
+
+    // Note that Win32/Mac/PostScript use a different convention for
+    // the descent (all vertical measurements are oriented from bottom
+    // to top on these palatforms). Make sure to flip the sign of the
+    // descent on these platforms for cross-platform compatibility.
+
+    // Any of the following member variables listed here can have
+    // positive or negative value.
+
+    nscoord leftBearing;
+    /* The horizontal distance from the origin of the drawing
+       operation to the left-most part of the drawn string. */
+
+    nscoord rightBearing;
+    /* The horizontal distance from the origin of the drawing
+       operation to the right-most part of the drawn string.
+       The _exact_ width of the string is therefore:
+       rightBearing - leftBearing */
+
+    nscoord ascent;
+    /* The vertical distance from the origin of the drawing
+       operation to the top-most part of the drawn string. */
+
+    nscoord descent;
+    /* The vertical distance from the origin of the drawing
+       operation to the bottom-most part of the drawn string.
+       The _exact_ height of the string is therefore:
+       ascent + descent */
+
+    //////////
+    // Metrics for placing other surrounding text:
+
+    nscoord width;
+    /* The horizontal distance from the origin of the drawing
+       operation to the correct origin for drawing another string
+       to follow the current one. Depending on the font, this
+       could be greater than or less than the right bearing. */
+
+    nsBoundingMetrics() {
+        Clear();
+    }
+
+    //////////
+    // Utility methods and operators:
+
+    /* Set all member data to zero */
+    void
+    Clear() {
+        leftBearing = rightBearing = 0;
+        ascent = descent = width = 0;
+    }
+
+    /* Append another bounding metrics */
+    void
+    operator += (const nsBoundingMetrics& bm) {
+        if (ascent + descent == 0 && rightBearing - leftBearing == 0) {
+            ascent = bm.ascent;
+            descent = bm.descent;
+            leftBearing = width + bm.leftBearing;
+            rightBearing = width + bm.rightBearing;
+        }
+        else {
+            if (ascent < bm.ascent) ascent = bm.ascent;
+            if (descent < bm.descent) descent = bm.descent;
+            leftBearing = PR_MIN(leftBearing, width + bm.leftBearing);
+            rightBearing = PR_MAX(rightBearing, width + bm.rightBearing);
+        }
+        width += bm.width;
+    }
+};
+#endif // MOZ_MATHML
+
+
+class nsRenderingContext
 {
 public:
-    nsThebesRenderingContext();
-    virtual ~nsThebesRenderingContext();
+    nsRenderingContext()
+        : mP2A(0.), mLineStyle(nsLineStyle_kNone), mColor(NS_RGB(0,0,0))
+    {}
+    // ~nsRenderingContext() {}
 
-    NS_DECL_ISUPPORTS
-
+    NS_INLINE_DECL_REFCOUNTING(nsRenderingContext)
 
     /**
-     * Return the maximum length of a string that can be handled by the platform
-     * using the current font metrics.
+     * Return the maximum length of a string that can be handled by
+     * the platform using the current font metrics.
      */
-    virtual PRInt32 GetMaxStringLength();
+    PRInt32 GetMaxStringLength();
 
     // Safe string method variants: by default, these defer to the more
     // elaborate methods below
-    NS_IMETHOD GetWidth(const nsString& aString, nscoord &aWidth,
-                        PRInt32 *aFontID = nsnull);
-    NS_IMETHOD GetWidth(const char* aString, nscoord& aWidth);
-    NS_IMETHOD DrawString(const nsString& aString, nscoord aX, nscoord aY,
-                          PRInt32 aFontID = -1,
-                          const nscoord* aSpacing = nsnull);
+    nsresult GetWidth(const nsString& aString, nscoord &aWidth,
+                      PRInt32 *aFontID = nsnull);
+    nsresult GetWidth(const char* aString, nscoord& aWidth);
+    nsresult DrawString(const nsString& aString, nscoord aX, nscoord aY,
+                        PRInt32 aFontID = -1,
+                        const nscoord* aSpacing = nsnull);
 
     // Safe string methods
-    NS_IMETHOD GetWidth(const char* aString, PRUint32 aLength,
-                        nscoord& aWidth);
-    NS_IMETHOD GetWidth(const PRUnichar *aString, PRUint32 aLength,
-                        nscoord &aWidth, PRInt32 *aFontID = nsnull);
-    NS_IMETHOD GetWidth(char aC, nscoord &aWidth);
-    NS_IMETHOD GetWidth(PRUnichar aC, nscoord &aWidth,
-                        PRInt32 *aFontID);
+    nsresult GetWidth(const char* aString, PRUint32 aLength,
+                      nscoord& aWidth);
+    nsresult GetWidth(const PRUnichar *aString, PRUint32 aLength,
+                      nscoord &aWidth, PRInt32 *aFontID = nsnull);
+    nsresult GetWidth(char aC, nscoord &aWidth);
+    nsresult GetWidth(PRUnichar aC, nscoord &aWidth,
+                      PRInt32 *aFontID);
 
-    NS_IMETHOD GetTextDimensions(const char* aString, PRUint32 aLength,
-                                 nsTextDimensions& aDimensions);
-    NS_IMETHOD GetTextDimensions(const PRUnichar* aString, PRUint32 aLength,
-                                 nsTextDimensions& aDimensions, PRInt32* aFontID = nsnull);
+    nsresult GetTextDimensions(const char* aString, PRUint32 aLength,
+                               nsTextDimensions& aDimensions);
+    nsresult GetTextDimensions(const PRUnichar* aString, PRUint32 aLength,
+                               nsTextDimensions& aDimensions,
+                               PRInt32* aFontID = nsnull);
 
 #if defined(_WIN32) || defined(XP_OS2) || defined(MOZ_X11)
-    NS_IMETHOD GetTextDimensions(const char*       aString,
-                                 PRInt32           aLength,
-                                 PRInt32           aAvailWidth,
-                                 PRInt32*          aBreaks,
-                                 PRInt32           aNumBreaks,
-                                 nsTextDimensions& aDimensions,
-                                 PRInt32&          aNumCharsFit,
-                                 nsTextDimensions& aLastWordDimensions,
-                                 PRInt32*          aFontID = nsnull);
+    nsresult GetTextDimensions(const char*       aString,
+                               PRInt32           aLength,
+                               PRInt32           aAvailWidth,
+                               PRInt32*          aBreaks,
+                               PRInt32           aNumBreaks,
+                               nsTextDimensions& aDimensions,
+                               PRInt32&          aNumCharsFit,
+                               nsTextDimensions& aLastWordDimensions,
+                               PRInt32*          aFontID = nsnull);
 
-    NS_IMETHOD GetTextDimensions(const PRUnichar*  aString,
-                                 PRInt32           aLength,
-                                 PRInt32           aAvailWidth,
-                                 PRInt32*          aBreaks,
-                                 PRInt32           aNumBreaks,
-                                 nsTextDimensions& aDimensions,
-                                 PRInt32&          aNumCharsFit,
-                                 nsTextDimensions& aLastWordDimensions,
-                                 PRInt32*          aFontID = nsnull);
+    nsresult GetTextDimensions(const PRUnichar*  aString,
+                               PRInt32           aLength,
+                               PRInt32           aAvailWidth,
+                               PRInt32*          aBreaks,
+                               PRInt32           aNumBreaks,
+                               nsTextDimensions& aDimensions,
+                               PRInt32&          aNumCharsFit,
+                               nsTextDimensions& aLastWordDimensions,
+                               PRInt32*          aFontID = nsnull);
 #endif
 #ifdef MOZ_MATHML
-    NS_IMETHOD GetBoundingMetrics(const char*        aString,
-                                  PRUint32           aLength,
-                                  nsBoundingMetrics& aBoundingMetrics);
-    NS_IMETHOD GetBoundingMetrics(const PRUnichar*   aString,
-                                  PRUint32           aLength,
-                                  nsBoundingMetrics& aBoundingMetrics,
-                                  PRInt32*           aFontID = nsnull);
+    nsresult GetBoundingMetrics(const char*        aString,
+                                PRUint32           aLength,
+                                nsBoundingMetrics& aBoundingMetrics);
+    nsresult GetBoundingMetrics(const PRUnichar*   aString,
+                                PRUint32           aLength,
+                                nsBoundingMetrics& aBoundingMetrics,
+                                PRInt32*           aFontID = nsnull);
 #endif
-    NS_IMETHOD DrawString(const char *aString, PRUint32 aLength,
-                          nscoord aX, nscoord aY,
-                          const nscoord* aSpacing = nsnull);
-    NS_IMETHOD DrawString(const PRUnichar *aString, PRUint32 aLength,
-                          nscoord aX, nscoord aY,
-                          PRInt32 aFontID = -1,
-                          const nscoord* aSpacing = nsnull);
+    nsresult DrawString(const char *aString, PRUint32 aLength,
+                        nscoord aX, nscoord aY,
+                        const nscoord* aSpacing = nsnull);
+    nsresult DrawString(const PRUnichar *aString, PRUint32 aLength,
+                        nscoord aX, nscoord aY,
+                        PRInt32 aFontID = -1,
+                        const nscoord* aSpacing = nsnull);
+
+    nsresult Init(nsIDeviceContext* aContext, gfxASurface* aThebesSurface);
+    nsresult Init(nsIDeviceContext* aContext, gfxContext* aThebesContext);
+    nsresult Init(nsIDeviceContext* aContext, nsIWidget *aWidget);
+    nsresult CommonInit(void);
+    already_AddRefed<nsIDeviceContext> GetDeviceContext();
+    nsresult PushState(void);
+    nsresult PopState(void);
+    nsresult SetClipRect(const nsRect& aRect, nsClipCombine aCombine);
+    nsresult SetLineStyle(nsLineStyle aLineStyle);
+    nsresult SetClipRegion(const nsIntRegion& aRegion, nsClipCombine aCombine);
+    nsresult SetColor(nscolor aColor);
+    nsresult GetColor(nscolor &aColor) const;
+    nsresult SetFont(const nsFont& aFont, nsIAtom* aLanguage,
+                     gfxUserFontSet *aUserFontSet);
+    nsresult SetFont(const nsFont& aFont,
+                     gfxUserFontSet *aUserFontSet);
+    nsresult SetFont(nsIFontMetrics *aFontMetrics);
+    already_AddRefed<nsIFontMetrics> GetFontMetrics();
+    nsresult Translate(const nsPoint& aPt);
+    nsresult Scale(float aSx, float aSy);
+    nsTransform2D* GetCurrentTransform();
 
-    NS_IMETHOD Init(nsIDeviceContext* aContext, gfxASurface* aThebesSurface);
-    NS_IMETHOD Init(nsIDeviceContext* aContext, gfxContext* aThebesContext);
-    NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWidget);
-    NS_IMETHOD CommonInit(void);
-    virtual already_AddRefed<nsIDeviceContext> GetDeviceContext();
-    NS_IMETHOD PushState(void);
-    NS_IMETHOD PopState(void);
-    NS_IMETHOD SetClipRect(const nsRect& aRect, nsClipCombine aCombine);
-    NS_IMETHOD SetLineStyle(nsLineStyle aLineStyle);
-    NS_IMETHOD SetClipRegion(const nsIntRegion& aRegion, nsClipCombine aCombine);
-    NS_IMETHOD SetColor(nscolor aColor);
-    NS_IMETHOD GetColor(nscolor &aColor) const;
-    NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLanguage,
-                       gfxUserFontSet *aUserFontSet);
-    NS_IMETHOD SetFont(const nsFont& aFont,
-                       gfxUserFontSet *aUserFontSet);
-    NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
-    virtual already_AddRefed<nsIFontMetrics> GetFontMetrics();
-    NS_IMETHOD Translate(const nsPoint& aPt);
-    NS_IMETHOD Scale(float aSx, float aSy);
-    virtual nsTransform2D* GetCurrentTransform();
+    nsresult DrawLine(const nsPoint& aStartPt, const nsPoint& aEndPt);
+    nsresult DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
+    nsresult DrawRect(const nsRect& aRect);
+    nsresult DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
+    nsresult FillRect(const nsRect& aRect);
+    nsresult FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
+    nsresult InvertRect(const nsRect& aRect);
+    nsresult InvertRect(nscoord aX, nscoord aY,
+                        nscoord aWidth, nscoord aHeight);
+    nsresult FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
+    nsresult DrawEllipse(const nsRect& aRect);
+    nsresult DrawEllipse(nscoord aX, nscoord aY,
+                         nscoord aWidth, nscoord aHeight);
+    nsresult FillEllipse(const nsRect& aRect);
+    nsresult FillEllipse(nscoord aX, nscoord aY,
+                         nscoord aWidth, nscoord aHeight);
+
+    nsresult PushFilter(const nsRect& aRect,
+                        PRBool aAreaIsOpaque, float aOpacity);
+    nsresult PopFilter();
 
-    NS_IMETHOD DrawLine(const nsPoint& aStartPt, const nsPoint& aEndPt);
-    NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
-    NS_IMETHOD DrawRect(const nsRect& aRect);
-    NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
-    NS_IMETHOD FillRect(const nsRect& aRect);
-    NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
-    NS_IMETHOD InvertRect(const nsRect& aRect);
-    NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
-    NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
-    NS_IMETHOD DrawEllipse(const nsRect& aRect);
-    NS_IMETHOD DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
-    NS_IMETHOD FillEllipse(const nsRect& aRect);
-    NS_IMETHOD FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
+    enum GraphicDataType {
+        NATIVE_CAIRO_CONTEXT = 1,
+        NATIVE_GDK_DRAWABLE = 2,
+        NATIVE_WINDOWS_DC = 3,
+        NATIVE_MAC_THING = 4,
+        NATIVE_THEBES_CONTEXT = 5,
+        NATIVE_OS2_PS = 6
+    };
+    void* GetNativeGraphicData(GraphicDataType aType);
 
-    NS_IMETHOD PushFilter(const nsRect& aRect, PRBool aAreaIsOpaque, float aOpacity);
-    NS_IMETHOD PopFilter();
+    struct PushedTranslation {
+        float mSavedX, mSavedY;
+    };
+    class AutoPushTranslation {
+        nsRenderingContext* mCtx;
+        PushedTranslation mPushed;
+    public:
+        AutoPushTranslation(nsRenderingContext* aCtx, const nsPoint& aPt)
+            : mCtx(aCtx) {
+            mCtx->PushTranslation(&mPushed);
+            mCtx->Translate(aPt);
+        }
+        ~AutoPushTranslation() {
+            mCtx->PopTranslation(&mPushed);
+        }
+    };
 
-    virtual void* GetNativeGraphicData(GraphicDataType aType);
-
-    NS_IMETHOD PushTranslation(PushedTranslation* aState);
-    NS_IMETHOD PopTranslation(PushedTranslation* aState);
-    NS_IMETHOD SetTranslation(const nsPoint& aPoint);
+    nsresult PushTranslation(PushedTranslation* aState);
+    nsresult PopTranslation(PushedTranslation* aState);
+    nsresult SetTranslation(const nsPoint& aPoint);
 
     /**
      * Let the device context know whether we want text reordered with
      * right-to-left base direction
      */
-    NS_IMETHOD SetRightToLeftText(PRBool aIsRTL);
-    NS_IMETHOD GetRightToLeftText(PRBool* aIsRTL);
-    virtual void SetTextRunRTL(PRBool aIsRTL);
+    nsresult SetRightToLeftText(PRBool aIsRTL);
+    nsresult GetRightToLeftText(PRBool* aIsRTL);
+    void SetTextRunRTL(PRBool aIsRTL);
 
-    virtual PRInt32 GetPosition(const PRUnichar *aText,
-                                PRUint32 aLength,
-                                nsPoint aPt);
-    NS_IMETHOD GetRangeWidth(const PRUnichar *aText,
-                             PRUint32 aLength,
-                             PRUint32 aStart,
-                             PRUint32 aEnd,
-                             PRUint32 &aWidth);
-    NS_IMETHOD GetRangeWidth(const char *aText,
-                             PRUint32 aLength,
-                             PRUint32 aStart,
-                             PRUint32 aEnd,
-                             PRUint32 &aWidth);
+    PRInt32 GetPosition(const PRUnichar *aText,
+                        PRUint32 aLength,
+                        nsPoint aPt);
+    nsresult GetRangeWidth(const PRUnichar *aText,
+                           PRUint32 aLength,
+                           PRUint32 aStart,
+                           PRUint32 aEnd,
+                           PRUint32 &aWidth);
+    nsresult GetRangeWidth(const char *aText,
+                           PRUint32 aLength,
+                           PRUint32 aStart,
+                           PRUint32 aEnd,
+                           PRUint32 &aWidth);
 
-    NS_IMETHOD RenderEPS(const nsRect& aRect, FILE *aDataFile);
+    nsresult RenderEPS(const nsRect& aRect, FILE *aDataFile);
 
     // Thebes specific stuff
 
     gfxContext *ThebesContext() { return mThebes; }
 
     nsTransform2D& CurrentTransform();
 
     void TransformCoord (nscoord *aX, nscoord *aY);
 
 protected:
-    nsresult GetWidthInternal(const char *aString, PRUint32 aLength, nscoord &aWidth);
-    nsresult GetWidthInternal(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth,
-                              PRInt32 *aFontID = nsnull);
+    nsresult GetWidthInternal(const char *aString, PRUint32 aLength,
+                              nscoord &aWidth);
+    nsresult GetWidthInternal(const PRUnichar *aString, PRUint32 aLength,
+                              nscoord &aWidth, PRInt32 *aFontID = nsnull);
 
     nsresult DrawStringInternal(const char *aString, PRUint32 aLength,
                                 nscoord aX, nscoord aY,
                                 const nscoord* aSpacing = nsnull);
     nsresult DrawStringInternal(const PRUnichar *aString, PRUint32 aLength,
                                 nscoord aX, nscoord aY,
                                 PRInt32 aFontID = -1,
                                 const nscoord* aSpacing = nsnull);
@@ -241,16 +410,18 @@ protected:
                                        PRInt32           aAvailWidth,
                                        PRInt32*          aBreaks,
                                        PRInt32           aNumBreaks,
                                        nsTextDimensions& aDimensions,
                                        PRInt32&          aNumCharsFit,
                                        nsTextDimensions& aLastWordDimensions,
                                        PRInt32*          aFontID = nsnull);
 
+    void UpdateTempTransformMatrix();
+
 #ifdef MOZ_MATHML
     /**
      * Returns metrics (in app units) of an 8-bit character string
      */
     nsresult GetBoundingMetricsInternal(const char*        aString,
                                         PRUint32           aLength,
                                         nsBoundingMetrics& aBoundingMetrics);
 
@@ -259,33 +430,25 @@ protected:
      */
     nsresult GetBoundingMetricsInternal(const PRUnichar*   aString,
                                         PRUint32           aLength,
                                         nsBoundingMetrics& aBoundingMetrics,
                                         PRInt32*           aFontID = nsnull);
 
 #endif /* MOZ_MATHML */
 
+    nsRefPtr<gfxContext> mThebes;
     nsCOMPtr<nsIDeviceContext> mDeviceContext;
-    // cached app units per device pixel value
-    double mP2A;
-
     nsCOMPtr<nsIWidget> mWidget;
-
-    // we need to manage our own clip region (since we can't get at
-    // the old one from cairo)
     nsCOMPtr<nsIThebesFontMetrics> mFontMetrics;
 
+    double mP2A; // cached app units per device pixel value
     nsLineStyle mLineStyle;
     nscolor mColor;
 
-    // the rendering context
-    nsRefPtr<gfxContext> mThebes;
-
     // for handing out to people
-    void UpdateTempTransformMatrix();
     nsTransform2D mTempTransform;
 
     // keeping track of pushgroup/popgroup opacities
     nsTArray<float> mOpacityArray;
 };
 
-#endif  // NSCAIRORENDERINGCONTEXT__H__
+#endif  // NSRENDERINGCONTEXT__H__
--- a/gfx/src/nsSystemFontsAndroid.cpp
+++ b/gfx/src/nsSystemFontsAndroid.cpp
@@ -30,21 +30,17 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#include "nsIDeviceContext.h"
-#include "nsIRenderingContext.h"
-
 #include "nsSystemFontsAndroid.h"
-
 #include "gfxPlatform.h"
 
 #define DEFAULT_FONT  "Droid Sans"
 
 nsSystemFontsAndroid::nsSystemFontsAndroid()
   : mDefaultFontName(NS_LITERAL_STRING(DEFAULT_FONT))
   , mButtonFontName(NS_LITERAL_STRING(DEFAULT_FONT))
   , mFieldFontName(NS_LITERAL_STRING(DEFAULT_FONT))
--- a/gfx/src/nsSystemFontsAndroid.h
+++ b/gfx/src/nsSystemFontsAndroid.h
@@ -33,17 +33,18 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef _NS_SYSTEMFONTSANDROID_H_
 #define _NS_SYSTEMFONTSANDROID_H_
 
-#include <gfxFont.h>
+#include "gfxFont.h"
+#include "nsIDeviceContext.h"
 
 class nsSystemFontsAndroid
 {
 public:
     nsSystemFontsAndroid();
     ~nsSystemFontsAndroid();
 
     nsresult GetSystemFont(nsSystemFontID anID, nsString *aFontName,
--- a/gfx/src/nsSystemFontsGTK2.cpp
+++ b/gfx/src/nsSystemFontsGTK2.cpp
@@ -34,30 +34,29 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 // for strtod()
 #include <stdlib.h>
 
-#include "nsIDeviceContext.h"
-#include "nsIRenderingContext.h"
+#include "nsSystemFontsGTK2.h"
+#include "nsRenderingContext.h"
 #include "prlink.h"
 
 #include <gtk/gtk.h>
 #include <gdk/gdk.h>
 
 #ifdef MOZ_PANGO
 #include <pango/pango.h>
 #include <pango/pango-fontmap.h>
 #endif
 
 #include <fontconfig/fontconfig.h>
-#include "nsSystemFontsGTK2.h"
 #include "gfxPlatformGtk.h"
 
 // Glue to avoid build/runtime dependencies on Pango > 1.6
 #if defined(MOZ_PANGO) && !defined(THEBES_USE_PANGO_CAIRO)
 static gboolean
 (* PTR_pango_font_description_get_size_is_absolute)(PangoFontDescription*)
     = nsnull;
 
--- a/gfx/src/nsSystemFontsGTK2.h
+++ b/gfx/src/nsSystemFontsGTK2.h
@@ -35,16 +35,18 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef _NS_SYSTEMFONTSGTK2_H_
 #define _NS_SYSTEMFONTSGTK2_H_
 
 #include "gfxFont.h"
+#include "nsIDeviceContext.h"
+
 typedef struct _GtkWidget GtkWidget;
 
 class nsSystemFontsGTK2
 {
 public:
     nsSystemFontsGTK2();
     ~nsSystemFontsGTK2();
 
--- a/gfx/src/nsSystemFontsMac.mm
+++ b/gfx/src/nsSystemFontsMac.mm
@@ -31,21 +31,19 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "nsSystemFontsMac.h"
 #include <Cocoa/Cocoa.h>
 
-#include "nsSystemFontsMac.h"
-
-
 nsSystemFontsMac::nsSystemFontsMac()
 {
 }
 
 // copied from gfxQuartzFontCache.mm, maybe should go in a Cocoa utils file somewhere
 static void GetStringForNSString(const NSString *aSrc, nsAString& aDest)
 {
     aDest.SetLength([aSrc length]);
--- a/gfx/src/nsSystemFontsOS2.cpp
+++ b/gfx/src/nsSystemFontsOS2.cpp
@@ -34,18 +34,24 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#include "nsIDeviceContext.h"
 #include "nsSystemFontsOS2.h"
+
+#define INCL_WINWINDOWMGR
+#define INCL_WINSHELLDATA
+#define INCL_DOSNLS
+#define INCL_DOSERRORS
+#include <os2.h>
+
 #include <stdlib.h>
 
 /************************
  *   Helper functions   *
  ************************/
 static BOOL bIsDBCS;
 static BOOL bIsDBCSSet = FALSE;
 
--- a/gfx/src/nsSystemFontsOS2.h
+++ b/gfx/src/nsSystemFontsOS2.h
@@ -36,22 +36,18 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef _NS_SYSTEMFONTSOS2_H_
 #define _NS_SYSTEMFONTSOS2_H_
 
-#include <gfxFont.h>
-#define INCL_WINWINDOWMGR
-#define INCL_WINSHELLDATA
-#define INCL_DOSNLS
-#define INCL_DOSERRORS
-#include <os2.h>
+#include "gfxFont.h"
+#include "nsIDeviceContext.h"
 
 class nsSystemFontsOS2
 {
 public:
     nsSystemFontsOS2();
     nsresult GetSystemFont(nsSystemFontID aID, nsString* aFontName,
                            gfxFontStyle *aFontStyle) const;
 };
--- a/gfx/src/nsSystemFontsQt.cpp
+++ b/gfx/src/nsSystemFontsQt.cpp
@@ -31,38 +31,37 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+// Qt headers must be included before anything that might pull in our
+// malloc wrappers.
 #include <QApplication>
 #include <QFont>
 
-#include "nsIDeviceContext.h"
-#include "nsIRenderingContext.h"
-
 #include "nsSystemFontsQt.h"
 #include "gfxQtPlatform.h"
 
 nsSystemFontsQt::nsSystemFontsQt()
   : mDefaultFontName(NS_LITERAL_STRING("sans-serif"))
   , mButtonFontName(NS_LITERAL_STRING("sans-serif"))
   , mFieldFontName(NS_LITERAL_STRING("sans-serif"))
   , mMenuFontName(NS_LITERAL_STRING("sans-serif"))
 {
    // What about using QFontInfo? is it faster or what?
    GetSystemFontInfo("Qlabel", &mDefaultFontName, &mDefaultFontStyle);
 
    GetSystemFontInfo("QlineEdit", &mFieldFontName, &mFieldFontStyle);
 
    GetSystemFontInfo("QAction", &mMenuFontName, &mMenuFontStyle);
-  
+
    GetSystemFontInfo("QPushButton", &mButtonFontName, &mButtonFontStyle);
 }
 
 nsSystemFontsQt::~nsSystemFontsQt()
 {
     // No implementation needed
 }
 
--- a/gfx/src/nsSystemFontsQt.h
+++ b/gfx/src/nsSystemFontsQt.h
@@ -34,19 +34,18 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef _NS_SYSTEMFONTSQT_H_
 #define _NS_SYSTEMFONTSQT_H_
 
-#include <gfxFont.h>
-
-class QFont;
+#include "gfxFont.h"
+#include "nsIDeviceContext.h"
 
 class nsSystemFontsQt
 {
 public:
     nsSystemFontsQt();
     ~nsSystemFontsQt();
 
     nsresult GetSystemFont(nsSystemFontID anID, nsString *aFontName,
--- a/gfx/src/nsSystemFontsWin.cpp
+++ b/gfx/src/nsSystemFontsWin.cpp
@@ -31,23 +31,19 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#include "nsIRenderingContext.h"
-
+#include "nsSystemFontsWin.h"
 #include "gfxWindowsSurface.h"
 
-#include "nsSystemFontsWin.h"
-
-
 nsresult nsSystemFontsWin::CopyLogFontToNSFont(HDC* aHDC, const LOGFONTW* ptrLogFont,
                                                nsString *aFontName,
                                                gfxFontStyle *aFontStyle) const
 {
   PRUnichar name[LF_FACESIZE];
   name[0] = 0;
   memcpy(name, ptrLogFont->lfFaceName, LF_FACESIZE*sizeof(PRUnichar));
   *aFontName = name;
--- a/gfx/src/nsSystemFontsWin.h
+++ b/gfx/src/nsSystemFontsWin.h
@@ -36,16 +36,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef _NS_SYSTEMFONTSWIN_H_
 #define _NS_SYSTEMFONTSWIN_H_
 
 #include "gfxFont.h"
 #include "nsIDeviceContext.h"
+#include <windows.h> // need HDC and LOGFONTW
 
 class nsSystemFontsWin
 {
 public:
     nsSystemFontsWin();
 
     nsresult GetSystemFont(nsSystemFontID anID, nsString *aFontName,
                            gfxFontStyle *aFontStyle) const;
@@ -53,9 +54,8 @@ private:
     nsresult CopyLogFontToNSFont(HDC* aHDC, const LOGFONTW* ptrLogFont,
                                  nsString *aFontName, gfxFontStyle *aFontStyle) const;
     nsresult GetSysFontInfo(HDC aHDC, nsSystemFontID anID,
                             nsString *aFontName,
                             gfxFontStyle *aFontStyle) const;
 };
 
 #endif /* _NS_SYSTEMFONTSWIN_H_ */
-
--- a/gfx/src/nsThebesGfxFactory.cpp
+++ b/gfx/src/nsThebesGfxFactory.cpp
@@ -38,25 +38,23 @@
 
 #include "mozilla/ModuleUtils.h"
 #include "nsCOMPtr.h"
 #include "nsGfxCIID.h"
 
 #include "nsScriptableRegion.h"
 
 #include "nsThebesDeviceContext.h"
-#include "nsThebesRenderingContext.h"
 #include "nsThebesRegion.h"
 #include "nsThebesFontMetrics.h"
 #include "nsThebesFontEnumerator.h"
 #include "gfxPlatform.h"
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsThebesFontMetrics)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsThebesDeviceContext)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsThebesRenderingContext)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsThebesRegion)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsThebesFontEnumerator)
 
 static nsresult
 nsScriptableRegionConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
 {
   nsresult rv;
 
@@ -94,35 +92,32 @@ nsScriptableRegionConstructor(nsISupport
   NS_RELEASE(inst);
 
   return rv;
 }
 
 NS_DEFINE_NAMED_CID(NS_FONT_METRICS_CID);
 NS_DEFINE_NAMED_CID(NS_FONT_ENUMERATOR_CID);
 NS_DEFINE_NAMED_CID(NS_DEVICE_CONTEXT_CID);
-NS_DEFINE_NAMED_CID(NS_RENDERING_CONTEXT_CID);
 NS_DEFINE_NAMED_CID(NS_REGION_CID);
 NS_DEFINE_NAMED_CID(NS_SCRIPTABLE_REGION_CID);
 
 static const mozilla::Module::CIDEntry kThebesCIDs[] = {
     { &kNS_FONT_METRICS_CID, false, NULL, nsThebesFontMetricsConstructor },
     { &kNS_FONT_ENUMERATOR_CID, false, NULL, nsThebesFontEnumeratorConstructor },
     { &kNS_DEVICE_CONTEXT_CID, false, NULL, nsThebesDeviceContextConstructor },
-    { &kNS_RENDERING_CONTEXT_CID, false, NULL, nsThebesRenderingContextConstructor },
     { &kNS_REGION_CID, false, NULL, nsThebesRegionConstructor },
     { &kNS_SCRIPTABLE_REGION_CID, false, NULL, nsScriptableRegionConstructor },
     { NULL }
 };
 
 static const mozilla::Module::ContractIDEntry kThebesContracts[] = {
     { "@mozilla.org/gfx/fontmetrics;1", &kNS_FONT_METRICS_CID },
     { "@mozilla.org/gfx/fontenumerator;1", &kNS_FONT_ENUMERATOR_CID },
     { "@mozilla.org/gfx/devicecontext;1", &kNS_DEVICE_CONTEXT_CID },
-    { "@mozilla.org/gfx/renderingcontext;1", &kNS_RENDERING_CONTEXT_CID },
     { "@mozilla.org/gfx/region/nsThebes;1", &kNS_REGION_CID },
     { "@mozilla.org/gfx/region;1", &kNS_SCRIPTABLE_REGION_CID },
     { NULL }
 };
 
 static nsresult
 nsThebesGfxModuleCtor()
 {
--- a/widget/src/cocoa/nsChildView.mm
+++ b/widget/src/cocoa/nsChildView.mm
@@ -130,17 +130,16 @@ extern NSMenu* sApplicationMenu; // Appl
 extern PRBool gConsumeRollupEvent;
 
 PRBool gChildViewMethodsSwizzled = PR_FALSE;
 
 extern nsISupportsArray *gDraggedTransferables;
 
 ChildView* ChildViewMouseTracker::sLastMouseEventView = nil;
 
-static NS_DEFINE_CID(kRegionCID, NS_REGION_CID);
 #ifdef INVALIDATE_DEBUGGING
 static void blinkRect(Rect* r);
 static void blinkRgn(RgnHandle rgn);
 #endif
 
 nsIRollupListener * gRollupListener = nsnull;
 nsIMenuRollup     * gMenuRollup = nsnull;
 nsIWidget         * gRollupWidget   = nsnull;
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -350,19 +350,16 @@ static PRBool    gCheckForHTCApi = PR_FA
 // Global user preference for disabling native theme. Used
 // in NativeWindowTheme.
 PRBool          gDisableNativeTheme               = PR_FALSE;
 
 // Global used in Show window enumerations.
 static PRBool   gWindowsVisible                   = PR_FALSE;
 
 static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
-#ifdef WINCE_WINDOWS_MOBILE
-static NS_DEFINE_CID(kRegionCID, NS_REGION_CID);
-#endif
 
 // General purpose user32.dll hook object
 static WindowsDllInterceptor sUser32Intercept;
 
 // A glass window's opaque rectangle must be at least this height
 // before we use glass margins. Shorter opaque rectangles lead to
 // stupid-looking visual effects because Windows (foolishly) makes the
 // window edge rendering dependent on the opaque rect height.
--- a/widget/src/windows/nsWindowGfx.cpp
+++ b/widget/src/windows/nsWindowGfx.cpp
@@ -103,25 +103,16 @@ using namespace mozilla::layers;
  * SECTION: nsWindow statics
  * 
  **************************************************************/
 
 static nsAutoPtr<PRUint8>  sSharedSurfaceData;
 static gfxIntSize          sSharedSurfaceSize;
 
 /**************************************************************
- *
- * SECTION: global variables.
- *
- **************************************************************/
-
-static NS_DEFINE_CID(kRegionCID,                  NS_REGION_CID);
-static NS_DEFINE_IID(kRenderingContextCID,        NS_RENDERING_CONTEXT_CID);
-
-/**************************************************************
  **************************************************************
  **
  ** BLOCK: nsWindowGfx impl.
  **
  ** Misc. graphics related utilities.
  **
  **************************************************************
  **************************************************************/