From a3ee1cccb316ae426b52103a315cb56aa075c2a7 Mon Sep 17 00:00:00 2001 From: "reed@reedloden.com" Date: Tue, 4 Dec 2007 17:09:29 -0800 Subject: [PATCH] Bug 404816 - "Visual bug in list view header" [p=twanno@lycos.nl (Teune van Steeg) r+sr=roc a1.9=damons] --- widget/src/gtk2/nsNativeThemeGTK.cpp | 48 ++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/widget/src/gtk2/nsNativeThemeGTK.cpp b/widget/src/gtk2/nsNativeThemeGTK.cpp index ab10092fff9..8435188019c 100644 --- a/widget/src/gtk2/nsNativeThemeGTK.cpp +++ b/widget/src/gtk2/nsNativeThemeGTK.cpp @@ -22,6 +22,7 @@ * Contributor(s): * Brian Ryner (Original Author) * Michael Ventnor + * Teune van Steeg * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -620,6 +621,27 @@ ConvertToGdkRect(const nsRect &aRect, PRInt32 aP2A) return gdk_rect; } +static GdkRectangle +ConvertGfxToGdkRect(const gfxRect &aRect, const gfxPoint &aTranslation) +{ + GdkRectangle gdk_rect; + gdk_rect.x = NSToIntRound(aRect.X()) - NSToIntRound(aTranslation.x); + gdk_rect.y = NSToIntRound(aRect.Y()) - NSToIntRound(aTranslation.y); + gdk_rect.width = NSToIntRound(aRect.Width()); + gdk_rect.height = NSToIntRound(aRect.Height()); + return gdk_rect; +} + +static gfxRect +ConvertToGfxRect(const nsRect &aRect, PRInt32 aP2A) +{ + gfxRect rect(NSAppUnitsToFloatPixels(aRect.x, aP2A), + NSAppUnitsToFloatPixels(aRect.y, aP2A), + NSAppUnitsToFloatPixels(aRect.width, aP2A), + NSAppUnitsToFloatPixels(aRect.height, aP2A)); + return rect; +} + NS_IMETHODIMP nsNativeThemeGTK::DrawWidgetBackground(nsIRenderingContext* aContext, nsIFrame* aFrame, @@ -663,26 +685,38 @@ nsNativeThemeGTK::DrawWidgetBackground(nsIRenderingContext* aContext, oldHandler = XSetErrorHandler(NativeThemeErrorHandler); } + gfxContext* ctx = + (gfxContext*)aContext->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT); + gfxMatrix current = ctx->CurrentMatrix(); + // We require the use of the default display and visual // because I'm afraid that otherwise the GTK theme may explode. // Some themes (e.g. Clearlooks) just don't clip properly to any // clip rect we provide, so we cannot advertise support for clipping within the // widget bounds. The gdk_clip is just advisory here, meanining "you don't // need to draw outside this rect if you don't feel like it!" - PRUint32 rendererFlags = gfxXlibNativeRenderer::DRAW_SUPPORTS_OFFSET; - GdkRectangle gdk_rect = ConvertToGdkRect(aRect - drawingRect.TopLeft(), p2a); - GdkRectangle gdk_clip = ConvertToGdkRect(aClipRect - drawingRect.TopLeft(), p2a); + GdkRectangle gdk_rect, gdk_clip; + gfxRect gfx_rect = ConvertToGfxRect(aRect - drawingRect.TopLeft(), p2a); + gfxRect gfx_clip = ConvertToGfxRect(aClipRect - drawingRect.TopLeft(), p2a); + if (ctx->UserToDevicePixelSnapped(gfx_rect) && + ctx->UserToDevicePixelSnapped(gfx_clip)) { + gfxPoint currentTranslation = current.GetTranslation(); + gdk_rect = ConvertGfxToGdkRect(gfx_rect, currentTranslation); + gdk_clip = ConvertGfxToGdkRect(gfx_clip, currentTranslation); + } + else { + gdk_rect = ConvertToGdkRect(aRect - drawingRect.TopLeft(), p2a); + gdk_clip = ConvertToGdkRect(aClipRect - drawingRect.TopLeft(), p2a); + } ThemeRenderer renderer(state, gtkWidgetType, flags, gdk_rect, gdk_clip); - gfxContext* ctx = - (gfxContext*)aContext->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT); - // XXXbz do we really want to round here, then snap, then round again? gfxRect rect(0, 0, NSAppUnitsToIntPixels(drawingRect.width, p2a), NSAppUnitsToIntPixels(drawingRect.height, p2a)); + + PRUint32 rendererFlags = gfxXlibNativeRenderer::DRAW_SUPPORTS_OFFSET; // Don't snap if it's a non-unit scale factor. We're going to have to take // slow paths then in any case. - gfxMatrix current = ctx->CurrentMatrix(); PRBool snapXY = ctx->UserToDevicePixelSnapped(rect) && !current.HasNonTranslation(); if (snapXY) {