From f0d1b74fac91a3e9db433134dd43e2f06e690442 Mon Sep 17 00:00:00 2001 From: "neil%parkwaycc.co.uk" Date: Wed, 16 Nov 2005 13:51:47 +0000 Subject: [PATCH] GDI resource leak fix b=243078 p=shutdown@flashmail.com r=ere sr=me --- widget/src/windows/nsNativeThemeWin.cpp | 46 ++++++++++--------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/widget/src/windows/nsNativeThemeWin.cpp b/widget/src/windows/nsNativeThemeWin.cpp index a435b95ad5ef..bfcf571d3119 100644 --- a/widget/src/windows/nsNativeThemeWin.cpp +++ b/widget/src/windows/nsNativeThemeWin.cpp @@ -1813,6 +1813,7 @@ nsresult nsNativeThemeWin::ClassicDrawWidgetBackground(nsIRenderingContext* aCon #endif #endif + rv = NS_OK; switch (aWidgetType) { // Draw button case NS_THEME_BUTTON: { @@ -1854,8 +1855,7 @@ nsresult nsNativeThemeWin::ClassicDrawWidgetBackground(nsIRenderingContext* aCon ::DrawFocusRect(hdc, &widgetRect); ::SetTextColor(hdc, oldColor); } - RestoreDC(hdc, -1); - return NS_OK; + break; } // Draw controls with 2px 3D inset border case NS_THEME_TEXTFIELD: @@ -1873,8 +1873,7 @@ nsresult nsNativeThemeWin::ClassicDrawWidgetBackground(nsIRenderingContext* aCon else ::FillRect(hdc, &widgetRect, (HBRUSH) (COLOR_WINDOW+1)); - RestoreDC(hdc, -1); - return NS_OK; + break; } case NS_THEME_TREEVIEW: { // Draw inset edge @@ -1883,8 +1882,7 @@ nsresult nsNativeThemeWin::ClassicDrawWidgetBackground(nsIRenderingContext* aCon // Fill in window color background ::FillRect(hdc, &widgetRect, (HBRUSH) (COLOR_WINDOW+1)); - RestoreDC(hdc, -1); - return NS_OK; + break; } // Draw ToolTip background case NS_THEME_TOOLTIP: @@ -1895,8 +1893,7 @@ nsresult nsNativeThemeWin::ClassicDrawWidgetBackground(nsIRenderingContext* aCon InflateRect(&widgetRect, -1, -1); ::FillRect(hdc, &widgetRect, (HBRUSH) (COLOR_INFOBK+1)); - RestoreDC(hdc, -1); - return NS_OK; + break; // Draw 3D face background controls case NS_THEME_PROGRESSBAR: case NS_THEME_PROGRESSBAR_VERTICAL: @@ -1909,8 +1906,7 @@ nsresult nsNativeThemeWin::ClassicDrawWidgetBackground(nsIRenderingContext* aCon case NS_THEME_STATUSBAR_RESIZER_PANEL: { ::FillRect(hdc, &widgetRect, (HBRUSH) (COLOR_BTNFACE+1)); - RestoreDC(hdc, -1); - return NS_OK; + break; } // Draw 3D inset statusbar panel case NS_THEME_STATUSBAR_PANEL: { @@ -1919,16 +1915,14 @@ nsresult nsNativeThemeWin::ClassicDrawWidgetBackground(nsIRenderingContext* aCon ::DrawEdge(hdc, &widgetRect, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE); - RestoreDC(hdc, -1); - return NS_OK; + break; } // Draw scrollbar thumb case NS_THEME_SCROLLBAR_THUMB_VERTICAL: case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL: ::DrawEdge(hdc, &widgetRect, EDGE_RAISED, BF_RECT | BF_MIDDLE); - RestoreDC(hdc, -1); - return NS_OK; + break; // Draw scrollbar track background case NS_THEME_SCROLLBAR_TRACK_VERTICAL: case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL: { @@ -1983,15 +1977,13 @@ nsresult nsNativeThemeWin::ClassicDrawWidgetBackground(nsIRenderingContext* aCon // XXX should invert the part of the track being clicked here // but the track is never :active - RestoreDC(hdc, -1); - return NS_OK; + break; } case NS_THEME_PROGRESSBAR_CHUNK: case NS_THEME_PROGRESSBAR_CHUNK_VERTICAL: ::FillRect(hdc, &widgetRect, (HBRUSH) (COLOR_HIGHLIGHT+1)); - RestoreDC(hdc, -1); - return NS_OK; + break; // Draw Tab case NS_THEME_TAB: case NS_THEME_TAB_LEFT_EDGE: @@ -2002,17 +1994,15 @@ nsresult nsNativeThemeWin::ClassicDrawWidgetBackground(nsIRenderingContext* aCon aWidgetType != NS_THEME_TAB_RIGHT_EDGE, aWidgetType != NS_THEME_TAB_LEFT_EDGE); - RestoreDC(hdc, -1); - return NS_OK; + break; } case NS_THEME_TAB_PANELS: ::DrawEdge(hdc, &widgetRect, EDGE_RAISED, BF_SOFT | BF_MIDDLE | BF_LEFT | BF_RIGHT | BF_BOTTOM); - RestoreDC(hdc, -1); - return NS_OK; + break; case NS_THEME_MENUBAR: - return NS_OK; + break; case NS_THEME_MENUPOPUP: if (mFlatMenus) { ::FillRect(hdc, &widgetRect, (HBRUSH) (COLOR_MENU+1)); @@ -2020,7 +2010,7 @@ nsresult nsNativeThemeWin::ClassicDrawWidgetBackground(nsIRenderingContext* aCon } else { ::DrawEdge(hdc, &widgetRect, EDGE_RAISED, BF_RECT | BF_MIDDLE); } - return NS_OK; + break; case NS_THEME_MENUITEM: case NS_THEME_CHECKMENUITEM: case NS_THEME_RADIOMENUITEM: { @@ -2085,12 +2075,14 @@ nsresult nsNativeThemeWin::ClassicDrawWidgetBackground(nsIRenderingContext* aCon } #endif } - return NS_OK; + break; } - + default: + rv = NS_ERROR_FAILURE; + break; } RestoreDC(hdc, -1); - return NS_ERROR_FAILURE; + return rv; }