[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [torbrowser/master] Bug 7920: Honor the Windows theme for inverse text colors
commit f6325cc47656445f729c4426246154733e4bf6df
Author: Mike Perry <mikeperry-git@xxxxxxxxxx>
Date: Tue Apr 2 16:03:44 2013 -0700
Bug 7920: Honor the Windows theme for inverse text colors
---
...not-expose-system-colors-to-CSS-or-canvas.patch | 195 ++++++++++++++++++--
1 files changed, 180 insertions(+), 15 deletions(-)
diff --git a/src/current-patches/firefox/0023-Do-not-expose-system-colors-to-CSS-or-canvas.patch b/src/current-patches/firefox/0023-Do-not-expose-system-colors-to-CSS-or-canvas.patch
index 1db7290..2bd9ffc 100644
--- a/src/current-patches/firefox/0023-Do-not-expose-system-colors-to-CSS-or-canvas.patch
+++ b/src/current-patches/firefox/0023-Do-not-expose-system-colors-to-CSS-or-canvas.patch
@@ -1,17 +1,24 @@
-From 6cf784929d122dd2b83536bdd742e9a718027376 Mon Sep 17 00:00:00 2001
+From 6f70c68258eb81dc898622f1f2629d71441fb1d3 Mon Sep 17 00:00:00 2001
From: Kathleen Brade <brade@xxxxxxxxxxxxxxxxx>
Date: Wed, 28 Nov 2012 15:08:40 -0500
-Subject: [PATCH 23/27] Do not expose system colors to CSS or canvas.
+Subject: [PATCH 23/28] Do not expose system colors to CSS or canvas.
+This patch also contains a hack to use properly contrasting colors if the
+desktop theme specifies white on black for text colors (see
+https://trac.torproject.org/projects/tor/ticket/7920). These color choices are
+also not exposed to content.
---
- content/canvas/src/nsCanvasRenderingContext2D.cpp | 28 +++-
+ content/canvas/src/nsCanvasRenderingContext2D.cpp | 28 ++-
.../canvas/src/nsCanvasRenderingContext2DAzure.cpp | 34 +++-
.../canvas/src/nsCanvasRenderingContext2DAzure.h | 5 +-
+ layout/base/nsLayoutUtils.cpp | 50 +++++
+ layout/base/nsLayoutUtils.h | 4 +
+ layout/generic/nsFrame.cpp | 6 +-
layout/style/nsRuleNode.cpp | 5 +-
- widget/LookAndFeel.h | 9 +
- widget/xpwidgets/nsXPLookAndFeel.cpp | 173 +++++++++++++++++++-
+ widget/LookAndFeel.h | 12 ++
+ widget/xpwidgets/nsXPLookAndFeel.cpp | 214 +++++++++++++++++++-
widget/xpwidgets/nsXPLookAndFeel.h | 5 +-
- 7 files changed, 239 insertions(+), 20 deletions(-)
+ 10 files changed, 342 insertions(+), 21 deletions(-)
diff --git a/content/canvas/src/nsCanvasRenderingContext2D.cpp b/content/canvas/src/nsCanvasRenderingContext2D.cpp
index 0dec654..7132e4f 100644
@@ -190,6 +197,113 @@ index 05ccf61..629d78a 100644
Type mType;
virtual ~nsCanvasGradientAzure() {}
};
+diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp
+index 87b0d34..65515d9 100644
+--- a/layout/base/nsLayoutUtils.cpp
++++ b/layout/base/nsLayoutUtils.cpp
+@@ -76,6 +76,7 @@
+ #include "nsSVGForeignObjectFrame.h"
+ #include "nsSVGOuterSVGFrame.h"
+ #include "nsStyleStructInlines.h"
++#include "mozilla/LookAndFeel.h"
+
+ #include "mozilla/Preferences.h"
+
+@@ -3134,13 +3135,62 @@ ShouldDarkenColors(nsPresContext* aPresContext)
+ nscolor
+ nsLayoutUtils::GetColor(nsIFrame* aFrame, nsCSSProperty aProperty)
+ {
++ if (aProperty == eCSSProperty_color)
++ {
++ nscolor nativeColor = NS_RGB(0, 0, 0);
++ if (GetNativeTextColor(aFrame, nativeColor))
++ return nativeColor;
++ }
++
+ nscolor color = aFrame->GetVisitedDependentColor(aProperty);
+ if (ShouldDarkenColors(aFrame->PresContext())) {
+ color = DarkenColor(color);
+ }
++
+ return color;
+ }
+
++bool
++nsLayoutUtils::GetNativeTextColor(nsIFrame* aFrame, nscolor& aColor)
++{
++ nsPresContext *presContext = aFrame->PresContext();
++ if (!presContext->IsChrome()) {
++ // If native appearance was used to draw the background of the containing
++ // frame, return a contrasting native foreground color instead of the
++ // color from the element's style. This avoids a problem where black
++ // text was displayed on a black background when a Windows theme such as
++ // "High Contrast Black" was used. The background is drawn inside
++ // nsNativeThemeWin::ClassicDrawWidgetBackground().
++ //
++ // Because both the background color and this foreground color are used
++ // directly without exposing the colors via CSS computed styles, the
++ // native colors are not leaked to content.
++ nsIFrame* bgFrame =
++ nsCSSRendering::FindNonTransparentBackgroundFrame(aFrame);
++ if (bgFrame) {
++ const nsStyleDisplay* displayData = bgFrame->GetStyleDisplay();
++ uint8_t widgetType = displayData->mAppearance;
++ nsITheme *theme = presContext->GetTheme();
++ if (widgetType && theme->ThemeSupportsWidget(presContext, bgFrame,
++ widgetType)) {
++ bool isDisabled = false;
++ nsIContent* frameContent = bgFrame->GetContent();
++ if (frameContent && frameContent->IsElement()) {
++ nsEventStates es = frameContent->AsElement()->State();
++ isDisabled = es.HasState(NS_EVENT_STATE_DISABLED);
++ }
++
++ if (NS_SUCCEEDED(LookAndFeel::GetColorForNativeAppearance(widgetType,
++ isDisabled, &aColor))) {
++ return true;
++ }
++ }
++ }
++ }
++
++ return false;
++}
++
+ gfxFloat
+ nsLayoutUtils::GetSnappedBaselineY(nsIFrame* aFrame, gfxContext* aContext,
+ nscoord aY, nscoord aAscent)
+diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h
+index 4fb1f93..6552f04 100644
+--- a/layout/base/nsLayoutUtils.h
++++ b/layout/base/nsLayoutUtils.h
+@@ -989,6 +989,10 @@ public:
+ // Get a suitable foreground color for painting aProperty for aFrame.
+ static nscolor GetColor(nsIFrame* aFrame, nsCSSProperty aProperty);
+
++ // Get the native text color if appropriate. If false is returned, callers
++ // should fallback to the CSS color.
++ static bool GetNativeTextColor(nsIFrame* aFrame, nscolor& aColor);
++
+ // Get a baseline y position in app units that is snapped to device pixels.
+ static gfxFloat GetSnappedBaselineY(nsIFrame* aFrame, gfxContext* aContext,
+ nscoord aY, nscoord aAscent);
+diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp
+index 75a2bb9..d684a62 100644
+--- a/layout/generic/nsFrame.cpp
++++ b/layout/generic/nsFrame.cpp
+@@ -1446,7 +1446,11 @@ nsIFrame::DisplayCaret(nsDisplayListBuilder* aBuilder,
+ nscolor
+ nsIFrame::GetCaretColorAt(int32_t aOffset)
+ {
+- // Use text color.
++ nscolor color = NS_RGB(0, 0, 0);
++ if (nsLayoutUtils::GetNativeTextColor(this, color))
++ return color;
++
++ // Use CSS text color.
+ return GetStyleColor()->mColor;
+ }
+
diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp
index 86eff1f..732b1fe 100644
--- a/layout/style/nsRuleNode.cpp
@@ -207,10 +321,10 @@ index 86eff1f..732b1fe 100644
}
}
diff --git a/widget/LookAndFeel.h b/widget/LookAndFeel.h
-index e46bb13..59f00f5 100644
+index e46bb13..f947084 100644
--- a/widget/LookAndFeel.h
+++ b/widget/LookAndFeel.h
-@@ -446,6 +446,15 @@ public:
+@@ -446,6 +446,18 @@ public:
static nsresult GetColor(ColorID aID, nscolor* aResult);
/**
@@ -222,15 +336,26 @@ index e46bb13..59f00f5 100644
+ static nsresult GetColor(ColorID aID, bool aUseStandinsForNativeColors,
+ nscolor* aResult);
+
++ static nsresult GetColorForNativeAppearance(uint8_t aWidgetType,
++ bool aIsDisabled, nscolor* aResult);
++
+ /**
* GetInt() and GetFloat() return a int or float value for aID. The result
* might be distance, time, some flags or a int value which has particular
* meaning. See each document at definition of each ID for the detail.
diff --git a/widget/xpwidgets/nsXPLookAndFeel.cpp b/widget/xpwidgets/nsXPLookAndFeel.cpp
-index 50c2c86..20ccfef 100644
+index 50c2c86..704963a 100644
--- a/widget/xpwidgets/nsXPLookAndFeel.cpp
+++ b/widget/xpwidgets/nsXPLookAndFeel.cpp
-@@ -476,6 +476,155 @@ nsXPLookAndFeel::IsSpecialColor(ColorID aID, nscolor &aColor)
+@@ -11,6 +11,7 @@
+ #include "nsLookAndFeel.h"
+ #include "nsCRT.h"
+ #include "nsFont.h"
++#include "nsThemeConstants.h"
+ #include "mozilla/Preferences.h"
+
+ #include "gfxPlatform.h"
+@@ -476,6 +477,155 @@ nsXPLookAndFeel::IsSpecialColor(ColorID aID, nscolor &aColor)
return false;
}
@@ -386,7 +511,7 @@ index 50c2c86..20ccfef 100644
//
// All these routines will return NS_OK if they have a value,
// in which case the nsLookAndFeel should use that value;
-@@ -483,7 +632,8 @@ nsXPLookAndFeel::IsSpecialColor(ColorID aID, nscolor &aColor)
+@@ -483,7 +633,8 @@ nsXPLookAndFeel::IsSpecialColor(ColorID aID, nscolor &aColor)
// platform-specific nsLookAndFeel should use its own values instead.
//
nsresult
@@ -396,7 +521,7 @@ index 50c2c86..20ccfef 100644
{
if (!sInitialized)
Init();
-@@ -569,7 +719,10 @@ nsXPLookAndFeel::GetColorImpl(ColorID aID, nscolor &aResult)
+@@ -569,7 +720,10 @@ nsXPLookAndFeel::GetColorImpl(ColorID aID, nscolor &aResult)
}
#endif // DEBUG_SYSTEM_COLOR_USE
@@ -408,7 +533,7 @@ index 50c2c86..20ccfef 100644
aResult = sCachedColors[aID];
return NS_OK;
}
-@@ -603,6 +756,12 @@ nsXPLookAndFeel::GetColorImpl(ColorID aID, nscolor &aResult)
+@@ -603,6 +757,12 @@ nsXPLookAndFeel::GetColorImpl(ColorID aID, nscolor &aResult)
return NS_OK;
}
@@ -421,7 +546,7 @@ index 50c2c86..20ccfef 100644
if (sUseNativeColors && NS_SUCCEEDED(NativeGetColor(aID, aResult))) {
if ((gfxPlatform::GetCMSMode() == eCMSMode_All) &&
!IsSpecialColor(aID, aResult)) {
-@@ -693,7 +852,15 @@ namespace mozilla {
+@@ -693,7 +853,55 @@ namespace mozilla {
nsresult
LookAndFeel::GetColor(ColorID aID, nscolor* aResult)
{
@@ -435,6 +560,46 @@ index 50c2c86..20ccfef 100644
+{
+ return nsLookAndFeel::GetInstance()->GetColorImpl(aID,
+ aUseStandinsForNativeColors, *aResult);
++}
++
++// static
++nsresult
++LookAndFeel::GetColorForNativeAppearance(uint8_t aWidgetType, bool aIsDisabled,
++ nscolor* aResult)
++{
++ NS_ENSURE_ARG_POINTER(aResult);
++
++ ColorID colorID = eColorID_LAST_COLOR;
++ switch (aWidgetType) {
++ case NS_THEME_TEXTFIELD:
++ case NS_THEME_TEXTFIELD_MULTILINE:
++ case NS_THEME_LISTBOX:
++ case NS_THEME_DROPDOWN:
++ case NS_THEME_DROPDOWN_TEXTFIELD:
++ case NS_THEME_TREEVIEW:
++ colorID = (aIsDisabled) ? eColorID_graytext : eColorID__moz_fieldtext;
++ break;
++
++ case NS_THEME_TOOLTIP:
++ colorID = eColorID_infotext;
++ break;
++
++ case NS_THEME_BUTTON:
++ case NS_THEME_GROUPBOX:
++ case NS_THEME_PROGRESSBAR:
++ case NS_THEME_PROGRESSBAR_VERTICAL:
++ case NS_THEME_TAB_PANEL:
++ case NS_THEME_STATUSBAR:
++ case NS_THEME_STATUSBAR_RESIZER_PANEL:
++ colorID = (aIsDisabled) ? eColorID_graytext : eColorID_buttontext;
++ break;
++ }
++
++ if (LookAndFeel::eColorID_LAST_COLOR == colorID)
++ return NS_ERROR_FAILURE;
++
++ *aResult = NS_RGB(0, 0, 0);
++ return nsLookAndFeel::GetInstance()->NativeGetColor(colorID, *aResult);
}
// static
@@ -462,5 +627,5 @@ index 69627d2..2729803 100644
static int OnPrefChanged(const char* aPref, void* aClosure);
--
-1.7.5.4
+1.7.9.5
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits