Ticket #7920: 7920-native-appearance.patch

File 7920-native-appearance.patch, 8.7 KB (added by mcs, 8 years ago)

Here is the proposed fix. The patch is for an ESR17 Firefox tree to which 0024-Do-not-expose-system-colors-to-CSS-or-canvas.patch has already been applied. If this looks good, we will produce a new, combined 0024- patch..

  • layout/base/nsLayoutUtils.cpp

    diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp
    index 87b0d34..65515d9 100644
    a b  
    7171#include "nsTextFrame.h"
    7272#include "nsFontFaceList.h"
    7373#include "nsFontInflationData.h"
    7474#include "nsSVGUtils.h"
    7575#include "nsSVGIntegrationUtils.h"
    7676#include "nsSVGForeignObjectFrame.h"
    7777#include "nsSVGOuterSVGFrame.h"
    7878#include "nsStyleStructInlines.h"
     79#include "mozilla/LookAndFeel.h"
    7980
    8081#include "mozilla/Preferences.h"
    8182
    8283#ifdef MOZ_XUL
    8384#include "nsXULPopupManager.h"
    8485#endif
    8586
    8687#include "sampler.h"
    ShouldDarkenColors(nsPresContext* aPresContext) 
    31293130{
    31303131  return !aPresContext->GetBackgroundColorDraw() &&
    31313132         !aPresContext->GetBackgroundImageDraw();
    31323133}
    31333134
    31343135nscolor
    31353136nsLayoutUtils::GetColor(nsIFrame* aFrame, nsCSSProperty aProperty)
    31363137{
     3138  if (aProperty == eCSSProperty_color)
     3139  {
     3140    nscolor nativeColor = NS_RGB(0, 0, 0);
     3141    if (GetNativeTextColor(aFrame, nativeColor))
     3142      return nativeColor;
     3143  }
     3144
    31373145  nscolor color = aFrame->GetVisitedDependentColor(aProperty);
    31383146  if (ShouldDarkenColors(aFrame->PresContext())) {
    31393147    color = DarkenColor(color);
    31403148  }
     3149
    31413150  return color;
    31423151}
    31433152
     3153bool
     3154nsLayoutUtils::GetNativeTextColor(nsIFrame* aFrame, nscolor& aColor)
     3155{
     3156  nsPresContext *presContext = aFrame->PresContext();
     3157  if (!presContext->IsChrome()) {
     3158    // If native appearance was used to draw the background of the containing
     3159    // frame, return a contrasting native foreground color instead of the
     3160    // color from the element's style.  This avoids a problem where black
     3161    // text was displayed on a black background when a Windows theme such as
     3162    // "High Contrast Black" was used.  The background is drawn inside
     3163    // nsNativeThemeWin::ClassicDrawWidgetBackground().
     3164    //
     3165    // Because both the background color and this foreground color are used
     3166    // directly without exposing the colors via CSS computed styles, the
     3167    // native colors are not leaked to content.
     3168    nsIFrame* bgFrame =
     3169                    nsCSSRendering::FindNonTransparentBackgroundFrame(aFrame);
     3170    if (bgFrame) {
     3171      const nsStyleDisplay* displayData = bgFrame->GetStyleDisplay();
     3172      uint8_t widgetType = displayData->mAppearance;
     3173      nsITheme *theme = presContext->GetTheme();
     3174      if (widgetType && theme->ThemeSupportsWidget(presContext, bgFrame,
     3175                                                   widgetType)) {
     3176        bool isDisabled = false;
     3177        nsIContent* frameContent = bgFrame->GetContent();
     3178        if (frameContent && frameContent->IsElement()) {
     3179          nsEventStates es = frameContent->AsElement()->State();
     3180          isDisabled = es.HasState(NS_EVENT_STATE_DISABLED);
     3181        }
     3182
     3183        if (NS_SUCCEEDED(LookAndFeel::GetColorForNativeAppearance(widgetType,
     3184                                                       isDisabled, &aColor))) {
     3185            return true;
     3186        }
     3187      }
     3188    }
     3189  }
     3190
     3191  return false;
     3192}
     3193
    31443194gfxFloat
    31453195nsLayoutUtils::GetSnappedBaselineY(nsIFrame* aFrame, gfxContext* aContext,
    31463196                                   nscoord aY, nscoord aAscent)
    31473197{
    31483198  gfxFloat appUnitsPerDevUnit = aFrame->PresContext()->AppUnitsPerDevPixel();
    31493199  gfxFloat baseline = gfxFloat(aY) + aAscent;
    31503200  gfxRect putativeRect(0, baseline/appUnitsPerDevUnit, 1, 1);
    31513201  if (!aContext->UserToDevicePixelSnapped(putativeRect, true))
  • layout/base/nsLayoutUtils.h

    diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h
    index 4fb1f93..6552f04 100644
    a b public: 
    984984
    985985  // Implement nsIFrame::GetMinWidth in terms of nsIFrame::AddInlineMinWidth
    986986  static nscoord MinWidthFromInline(nsIFrame* aFrame,
    987987                                    nsRenderingContext* aRenderingContext);
    988988
    989989  // Get a suitable foreground color for painting aProperty for aFrame.
    990990  static nscolor GetColor(nsIFrame* aFrame, nsCSSProperty aProperty);
    991991
     992  // Get the native text color if appropriate.  If false is returned, callers
     993  // should fallback to the CSS color.
     994  static bool GetNativeTextColor(nsIFrame* aFrame, nscolor& aColor);
     995
    992996  // Get a baseline y position in app units that is snapped to device pixels.
    993997  static gfxFloat GetSnappedBaselineY(nsIFrame* aFrame, gfxContext* aContext,
    994998                                      nscoord aY, nscoord aAscent);
    995999
    9961000  static void DrawString(const nsIFrame*      aFrame,
    9971001                         nsRenderingContext* aContext,
    9981002                         const PRUnichar*     aString,
    9991003                         int32_t              aLength,
  • layout/generic/nsFrame.cpp

    diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp
    index 75a2bb9..d684a62 100644
    a b nsIFrame::DisplayCaret(nsDisplayListBuilder* aBuilder, 
    14411441
    14421442  return aList->AppendNewToTop(
    14431443      new (aBuilder) nsDisplayCaret(aBuilder, this, aBuilder->GetCaret()));
    14441444}
    14451445
    14461446nscolor
    14471447nsIFrame::GetCaretColorAt(int32_t aOffset)
    14481448{
    1449   // Use text color.
     1449  nscolor color = NS_RGB(0, 0, 0);
     1450  if (nsLayoutUtils::GetNativeTextColor(this, color))
     1451    return color;
     1452
     1453  // Use CSS text color.
    14501454  return GetStyleColor()->mColor;
    14511455}
    14521456
    14531457nsresult
    14541458nsFrame::DisplayBackgroundUnconditional(nsDisplayListBuilder*   aBuilder,
    14551459                                        const nsDisplayListSet& aLists,
    14561460                                        bool                    aForceBackground,
    14571461                                        nsDisplayBackground**   aBackground)
  • widget/LookAndFeel.h

    diff --git a/widget/LookAndFeel.h b/widget/LookAndFeel.h
    index 59f00f5..f947084 100644
    a b public: 
    449449   * This variant of GetColor() take an extra Boolean parameter that allows
    450450   * the caller to ask that hard-coded color values be substituted for
    451451   * native colors (used when it is desireable to hide system colors to
    452452   * avoid system fingerprinting).
    453453   */
    454454  static nsresult GetColor(ColorID aID, bool aUseStandinsForNativeColors,
    455455                           nscolor* aResult);
    456456
     457  static nsresult GetColorForNativeAppearance(uint8_t aWidgetType,
     458                                          bool aIsDisabled, nscolor* aResult);
     459
    457460  /**
    458461   * GetInt() and GetFloat() return a int or float value for aID.  The result
    459462   * might be distance, time, some flags or a int value which has particular
    460463   * meaning.  See each document at definition of each ID for the detail.
    461464   * The result is always 0 when they return error.  Therefore, if you want to
    462465   * use a value for the default value, you should use the other method which
    463466   * returns int or float directly.
    464467   */
  • widget/xpwidgets/nsXPLookAndFeel.cpp

    diff --git a/widget/xpwidgets/nsXPLookAndFeel.cpp b/widget/xpwidgets/nsXPLookAndFeel.cpp
    index 20ccfef..704963a 100644
    a b  
    66#include "mozilla/Util.h"
    77
    88#include "nscore.h"
    99
    1010#include "nsXPLookAndFeel.h"
    1111#include "nsLookAndFeel.h"
    1212#include "nsCRT.h"
    1313#include "nsFont.h"
     14#include "nsThemeConstants.h"
    1415#include "mozilla/Preferences.h"
    1516
    1617#include "gfxPlatform.h"
    1718#include "qcms.h"
    1819
    1920#ifdef DEBUG
    2021#include "nsSize.h"
    2122#endif
    LookAndFeel::GetColor(ColorID aID, bool aUseStandinsForNativeColors, 
    860861                      nscolor* aResult)
    861862{
    862863  return nsLookAndFeel::GetInstance()->GetColorImpl(aID,
    863864                                       aUseStandinsForNativeColors, *aResult);
    864865}
    865866
    866867// static
    867868nsresult
     869LookAndFeel::GetColorForNativeAppearance(uint8_t aWidgetType, bool aIsDisabled,
     870                                         nscolor* aResult)
     871{
     872  NS_ENSURE_ARG_POINTER(aResult);
     873
     874  ColorID colorID = eColorID_LAST_COLOR;
     875  switch (aWidgetType) {
     876    case NS_THEME_TEXTFIELD:
     877    case NS_THEME_TEXTFIELD_MULTILINE:
     878    case NS_THEME_LISTBOX:
     879    case NS_THEME_DROPDOWN:
     880    case NS_THEME_DROPDOWN_TEXTFIELD:
     881    case NS_THEME_TREEVIEW:
     882      colorID = (aIsDisabled) ? eColorID_graytext : eColorID__moz_fieldtext;
     883      break;
     884
     885    case NS_THEME_TOOLTIP:
     886      colorID = eColorID_infotext;
     887      break;
     888
     889    case NS_THEME_BUTTON:
     890    case NS_THEME_GROUPBOX:
     891    case NS_THEME_PROGRESSBAR:
     892    case NS_THEME_PROGRESSBAR_VERTICAL:
     893    case NS_THEME_TAB_PANEL:
     894    case NS_THEME_STATUSBAR:
     895    case NS_THEME_STATUSBAR_RESIZER_PANEL:
     896      colorID = (aIsDisabled) ? eColorID_graytext : eColorID_buttontext;
     897      break;
     898  }
     899
     900  if (LookAndFeel::eColorID_LAST_COLOR == colorID)
     901    return NS_ERROR_FAILURE;
     902
     903  *aResult = NS_RGB(0, 0, 0);
     904  return nsLookAndFeel::GetInstance()->NativeGetColor(colorID, *aResult);
     905}
     906
     907// static
     908nsresult
    868909LookAndFeel::GetInt(IntID aID, int32_t* aResult)
    869910{
    870911  return nsLookAndFeel::GetInstance()->GetIntImpl(aID, *aResult);
    871912}
    872913
    873914// static
    874915nsresult
    875916LookAndFeel::GetFloat(FloatID aID, float* aResult)