From 20636c2fb4cda8caff08965613c0485bec24c83b Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Fri, 19 Sep 2008 19:06:46 +0200 Subject: [PATCH] Bug 455217 - Selection colors for plain text files is wrong (white background, blue text instead of blue background, white text); "code" part; r+sr=dbaron --- layout/base/nsCSSColorUtils.cpp | 7 +++++++ layout/base/nsCSSRendering.cpp | 9 +++------ layout/base/nsPresContext.cpp | 5 +++++ layout/generic/nsTextFrameThebes.cpp | 8 +++++++- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/layout/base/nsCSSColorUtils.cpp b/layout/base/nsCSSColorUtils.cpp index 3baca90cc0f..b0d9ad952b0 100644 --- a/layout/base/nsCSSColorUtils.cpp +++ b/layout/base/nsCSSColorUtils.cpp @@ -38,6 +38,7 @@ /* functions that manipulate colors */ #include "nsCSSColorUtils.h" +#include "nsDebug.h" #include // Weird color computing code stolen from winfe which was stolen @@ -189,6 +190,12 @@ int NS_GetBrightness(PRUint8 aRed, PRUint8 aGreen, PRUint8 aBlue) PRInt32 NS_GetLuminosity(nscolor aColor) { + // When aColor is not opaque, the perceived luminosity will depend + // on what color(s) aColor is ultimately drawn on top of, which we + // do not know. + NS_ASSERTION(NS_GET_A(aColor) == 255, + "impossible to compute luminosity of a non-opaque color"); + return (NS_GET_R(aColor) * RED_LUMINOSITY + NS_GET_G(aColor) * GREEN_LUMINOSITY + NS_GET_B(aColor) * BLUE_LUMINOSITY); diff --git a/layout/base/nsCSSRendering.cpp b/layout/base/nsCSSRendering.cpp index fc204b3f128..12e8c2dcf4d 100644 --- a/layout/base/nsCSSRendering.cpp +++ b/layout/base/nsCSSRendering.cpp @@ -1301,17 +1301,14 @@ nsCSSRendering::PaintBackground(nsPresContext* aPresContext, // If the window is intended to be opaque, ensure that we always // paint an opaque color for its root element, in case there's no // background at all or a partly transparent image. - // - // The default background color from the prescontext is under user - // control, so it might not be opaque either. nsIView* rView; vm->GetRootView(rView); if (!rView->GetParent() && (!rView->HasWidget() || rView->GetWidget()->GetTransparencyMode() == eTransparencyOpaque)) { - nscolor backColor = - NS_ComposeColors(NS_RGB(255,255,255), - aPresContext->DefaultBackgroundColor()); + nscolor backColor = aPresContext->DefaultBackgroundColor(); + NS_ASSERTION(NS_GET_A(backColor) == 255, + "default background color is not opaque"); canvasColor.mBackgroundColor = NS_ComposeColors(backColor, canvasColor.mBackgroundColor); diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index d0d9d0965d4..330a0fffdae 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -569,6 +569,11 @@ nsPresContext::GetDocumentColorPreferences() mBackgroundColor); } + // Wherever we got the default background color from, ensure it is + // opaque. + mBackgroundColor = NS_ComposeColors(NS_RGB(0xFF, 0xFF, 0xFF), + mBackgroundColor); + mUseDocumentColors = !useAccessibilityTheme && nsContentUtils::GetBoolPref("browser.display.use_document_colors", mUseDocumentColors); diff --git a/layout/generic/nsTextFrameThebes.cpp b/layout/generic/nsTextFrameThebes.cpp index bcdbbe98746..4f57a677c6d 100644 --- a/layout/generic/nsTextFrameThebes.cpp +++ b/layout/generic/nsTextFrameThebes.cpp @@ -2968,7 +2968,13 @@ nsTextPaintStyle::InitCommonColors() const nsStyleBackground* bg = nsCSSRendering::FindNonTransparentBackground(sc); NS_ASSERTION(bg, "Cannot find NonTransparentBackground."); - mFrameBackgroundColor = bg->mBackgroundColor; + + nscolor defaultBgColor = mPresContext->DefaultBackgroundColor(); + NS_ASSERTION(NS_GET_A(defaultBgColor) == 255, + "default background color is not opaque"); + + mFrameBackgroundColor = NS_ComposeColors(defaultBgColor, + bg->mBackgroundColor); nsILookAndFeel* look = mPresContext->LookAndFeel(); nscolor defaultWindowBackgroundColor, selectionTextColor, selectionBGColor;