Bug 663375 - When text color is darkened, darken text-decoration color too. r=dbaron
authorMats Palmgren <matspal@gmail.com>
Tue, 09 Aug 2011 17:14:36 +0200
changeset 74892 e9f6607a3990d027d09dcdc3395fe76be4ef9e6b
parent 74891 3015d5cb3a9c493d3d53f828a2a42e1ea7d86419
child 74893 2c7e0e31fc0cb3e298d005cdef9139dfc91e20db
push idunknown
push userunknown
push dateunknown
reviewersdbaron
bugs663375
milestone8.0a1
Bug 663375 - When text color is darkened, darken text-decoration color too. r=dbaron
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
layout/generic/TextOverflow.cpp
layout/generic/nsBulletFrame.cpp
layout/generic/nsTextFrameThebes.cpp
layout/xul/base/src/nsTextBoxFrame.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -2872,30 +2872,30 @@ DarkenColor(nscolor aColor)
   if (value > sat) {
     value = sat;
     // convert this color back into the RGB color space.
     NS_HSV2RGB(aColor, hue, sat, value, alpha);
   }
   return aColor;
 }
 
-// Check whether we should darken text colors. We need to do this if
+// Check whether we should darken text/decoration colors. We need to do this if
 // background images and colors are being suppressed, because that means
 // light text will not be visible against the (presumed light-colored) background.
 static PRBool
 ShouldDarkenColors(nsPresContext* aPresContext)
 {
   return !aPresContext->GetBackgroundColorDraw() &&
-    !aPresContext->GetBackgroundImageDraw();
+         !aPresContext->GetBackgroundImageDraw();
 }
 
 nscolor
-nsLayoutUtils::GetTextColor(nsIFrame* aFrame)
+nsLayoutUtils::GetColor(nsIFrame* aFrame, nsCSSProperty aProperty)
 {
-  nscolor color = aFrame->GetVisitedDependentColor(eCSSProperty_color);
+  nscolor color = aFrame->GetVisitedDependentColor(aProperty);
   if (ShouldDarkenColors(aFrame->PresContext())) {
     color = DarkenColor(color);
   }
   return color;
 }
 
 gfxFloat
 nsLayoutUtils::GetSnappedBaselineY(nsIFrame* aFrame, gfxContext* aContext,
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -929,18 +929,18 @@ public:
   // Implement nsIFrame::GetPrefWidth in terms of nsIFrame::AddInlinePrefWidth
   static nscoord PrefWidthFromInline(nsIFrame* aFrame,
                                      nsRenderingContext* aRenderingContext);
 
   // Implement nsIFrame::GetMinWidth in terms of nsIFrame::AddInlineMinWidth
   static nscoord MinWidthFromInline(nsIFrame* aFrame,
                                     nsRenderingContext* aRenderingContext);
 
-  // Get a suitable foreground color for painting text for the frame.
-  static nscolor GetTextColor(nsIFrame* aFrame);
+  // Get a suitable foreground color for painting aProperty for aFrame.
+  static nscolor GetColor(nsIFrame* aFrame, nsCSSProperty aProperty);
 
   // 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);
 
   static void DrawString(const nsIFrame*      aFrame,
                          nsRenderingContext* aContext,
                          const PRUnichar*     aString,
--- a/layout/generic/TextOverflow.cpp
+++ b/layout/generic/TextOverflow.cpp
@@ -225,17 +225,18 @@ PaintTextShadowCallback(nsRenderingConte
   reinterpret_cast<nsDisplayTextOverflowMarker*>(aData)->
            PaintTextToContext(aCtx, aShadowOffset);
 }
 
 void
 nsDisplayTextOverflowMarker::Paint(nsDisplayListBuilder* aBuilder,
                                    nsRenderingContext*   aCtx)
 {
-  nscolor foregroundColor = nsLayoutUtils::GetTextColor(mFrame);
+  nscolor foregroundColor =
+    nsLayoutUtils::GetColor(mFrame, eCSSProperty_color);
 
   // Paint the text-shadows for the overflow marker
   nsLayoutUtils::PaintTextShadow(mFrame, aCtx, mRect, mVisibleRect,
                                  foregroundColor, PaintTextShadowCallback,
                                  (void*)this);
   aCtx->SetColor(foregroundColor);
   PaintTextToContext(aCtx, nsPoint(0, 0));
 }
--- a/layout/generic/nsBulletFrame.cpp
+++ b/layout/generic/nsBulletFrame.cpp
@@ -285,17 +285,17 @@ nsBulletFrame::PaintBullet(nsRenderingCo
              imageCon, nsLayoutUtils::GetGraphicsFilterForFrame(this),
              dest + aPt, aDirtyRect, imgIContainer::FLAG_NONE);
         return;
       }
     }
   }
 
   nsRefPtr<nsFontMetrics> fm;
-  aRenderingContext.SetColor(GetVisitedDependentColor(eCSSProperty_color));
+  aRenderingContext.SetColor(nsLayoutUtils::GetColor(this, eCSSProperty_color));
 
   mTextIsRTL = PR_FALSE;
 
   nsAutoString text;
   switch (listStyleType) {
   case NS_STYLE_LIST_STYLE_NONE:
     break;
 
--- a/layout/generic/nsTextFrameThebes.cpp
+++ b/layout/generic/nsTextFrameThebes.cpp
@@ -3234,17 +3234,17 @@ nsTextPaintStyle::EnsureSufficientContra
     return PR_TRUE;
   }
   return PR_FALSE;
 }
 
 nscolor
 nsTextPaintStyle::GetTextColor()
 {
-  return nsLayoutUtils::GetTextColor(mFrame);
+  return nsLayoutUtils::GetColor(mFrame, eCSSProperty_color);
 }
 
 PRBool
 nsTextPaintStyle::GetSelectionColors(nscolor* aForeColor,
                                      nscolor* aBackColor)
 {
   NS_ASSERTION(aForeColor, "aForeColor is null");
   NS_ASSERTION(aBackColor, "aBackColor is null");
@@ -4284,23 +4284,22 @@ nsTextFrame::GetTextDecorations(nsPresCo
     if (!context->HasTextDecorationLines()) {
       break;
     }
 
     const nsStyleTextReset *const styleText = context->GetStyleTextReset();
     const PRUint8 textDecorations = styleText->mTextDecorationLine;
 
     if (!useOverride &&
-        (NS_STYLE_TEXT_DECORATION_LINE_OVERRIDE_ALL & textDecorations))
-    {
+        (NS_STYLE_TEXT_DECORATION_LINE_OVERRIDE_ALL & textDecorations)) {
       // This handles the <a href="blah.html"><font color="green">La 
       // la la</font></a> case. The link underline should be green.
       useOverride = PR_TRUE;
-      overrideColor = context->GetVisitedDependentColor(
-                                 eCSSProperty_text_decoration_color);
+      overrideColor =
+        nsLayoutUtils::GetColor(f, eCSSProperty_text_decoration_color);
     }
 
     fParent = nsLayoutUtils::GetParentOrPlaceholderFor(
                 aPresContext->FrameManager(), f);
     const bool firstBlock = !nearestBlockFound &&
                             nsLayoutUtils::GetAsBlock(fParent);
 
     // Not updating positions once we hit a parent block is equivalent to
@@ -4322,32 +4321,29 @@ nsTextFrame::GetTextDecorations(nsPresCo
 
     nearestBlockFound = nearestBlockFound || firstBlock;
     frameTopOffset += f->GetRect().Y() - f->GetRelativeOffset().y;
 
     const PRUint8 style = styleText->GetDecorationStyle();
     // Accumulate only elements that have decorations with a genuine style
     if (textDecorations && style != NS_STYLE_TEXT_DECORATION_STYLE_NONE) {
       const nscolor color = useOverride ? overrideColor
-        : context->GetVisitedDependentColor(eCSSProperty_text_decoration_color);
+        : nsLayoutUtils::GetColor(f, eCSSProperty_text_decoration_color);
 
       if (textDecorations & NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE) {
         aDecorations.mUnderlines.AppendElement(
-          nsTextFrame::LineDecoration(f, baselineOffset, color,
-                                      style));
+          nsTextFrame::LineDecoration(f, baselineOffset, color, style));
       }
       if (textDecorations & NS_STYLE_TEXT_DECORATION_LINE_OVERLINE) {
         aDecorations.mOverlines.AppendElement(
-          nsTextFrame::LineDecoration(f, baselineOffset, color,
-                                      style));
+          nsTextFrame::LineDecoration(f, baselineOffset, color, style));
       }
       if (textDecorations & NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH) {
         aDecorations.mStrikes.AppendElement(
-          nsTextFrame::LineDecoration(f, baselineOffset, color,
-                                      style));
+          nsTextFrame::LineDecoration(f, baselineOffset, color, style));
       }
     }
 
     // In all modes, if we're on an inline-block or inline-table (or
     // inline-stack, inline-box, inline-grid), we're done.
     const nsStyleDisplay *disp = context->GetStyleDisplay();
     if (disp->mDisplay != NS_STYLE_DISPLAY_INLINE &&
         disp->IsInlineOutside()) {
--- a/layout/xul/base/src/nsTextBoxFrame.cpp
+++ b/layout/xul/base/src/nsTextBoxFrame.cpp
@@ -15,16 +15,17 @@
  * The Original Code is Mozilla Communicator client code.
  *
  * The Initial Developer of the Original Code is
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 1998
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
+ *   Eric Vaughan, Netscape Communications
  *   Peter Annema <disttsc@bart.nl>
  *   Dean Tessman <dean_tessman@hotmail.com>
  *   Masayuki Nakano <masayuki@d-toybox.com>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of the GNU General Public License Version 2 or later (the "GPL"),
  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
@@ -33,25 +34,19 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-//
-// Eric Vaughan
-// Netscape Communications
-//
-// See documentation in associated header file
-//
+#include "nsTextBoxFrame.h"
 
 #include "nsReadableUtils.h"
-#include "nsTextBoxFrame.h"
 #include "nsCOMPtr.h"
 #include "nsGkAtoms.h"
 #include "nsPresContext.h"
 #include "nsRenderingContext.h"
 #include "nsStyleContext.h"
 #include "nsIContent.h"
 #include "nsINameSpaceManager.h"
 #include "nsBoxLayoutState.h"
@@ -66,48 +61,38 @@
 #include "nsITheme.h"
 #include "nsUnicharUtils.h"
 #include "nsContentUtils.h"
 #include "nsDisplayList.h"
 #include "nsCSSRendering.h"
 #include "nsIReflowCallback.h"
 #include "nsBoxFrame.h"
 #include "mozilla/Preferences.h"
+#include "nsLayoutUtils.h"
 
 #ifdef IBMBIDI
 #include "nsBidiUtils.h"
 #include "nsBidiPresUtils.h"
 #endif // IBMBIDI
 
 using namespace mozilla;
 
-#define CROP_LEFT   "left"
-#define CROP_RIGHT  "right"
-#define CROP_CENTER "center"
-#define CROP_START  "start"
-#define CROP_END    "end"
-
 class nsAccessKeyInfo
 {
 public:
     PRInt32 mAccesskeyIndex;
     nscoord mBeforeWidth, mAccessWidth, mAccessUnderlineSize, mAccessOffset;
 };
 
 
 PRBool nsTextBoxFrame::gAlwaysAppendAccessKey          = PR_FALSE;
 PRBool nsTextBoxFrame::gAccessKeyPrefInitialized       = PR_FALSE;
 PRBool nsTextBoxFrame::gInsertSeparatorBeforeAccessKey = PR_FALSE;
 PRBool nsTextBoxFrame::gInsertSeparatorPrefInitialized = PR_FALSE;
 
-//
-// NS_NewToolbarFrame
-//
-// Creates a new Toolbar frame and returns it
-//
 nsIFrame*
 NS_NewTextBoxFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
     return new (aPresShell) nsTextBoxFrame (aPresShell, aContext);
 }
 
 NS_IMPL_FRAMEARENA_HELPERS(nsTextBoxFrame)
 
@@ -440,36 +425,39 @@ nsTextBoxFrame::DrawText(nsRenderingCont
 
     // paint the title
     nscolor overColor;
     nscolor underColor;
     nscolor strikeColor;
     PRUint8 overStyle;
     PRUint8 underStyle;
     PRUint8 strikeStyle;
-    nsStyleContext* context = mStyleContext;
 
     // Begin with no decorations
     PRUint8 decorations = NS_STYLE_TEXT_DECORATION_LINE_NONE;
     // A mask of all possible decorations.
     PRUint8 decorMask = NS_STYLE_TEXT_DECORATION_LINE_LINES_MASK;
-    PRBool hasDecorationLines = context->HasTextDecorationLines();
 
+    nsIFrame* f = this;
     do {  // find decoration colors
+      nsStyleContext* context = f->GetStyleContext();
+      if (!context->HasTextDecorationLines()) {
+        break;
+      }
       const nsStyleTextReset* styleText = context->GetStyleTextReset();
       
       if (decorMask & styleText->mTextDecorationLine) {  // a decoration defined here
         nscolor color;
         if (aOverrideColor) {
           color = *aOverrideColor;
         } else {
           PRBool isForeground;
           styleText->GetDecorationColor(color, isForeground);
           if (isForeground) {
-            color = context->GetVisitedDependentColor(eCSSProperty_color);
+            color = nsLayoutUtils::GetColor(f, eCSSProperty_color);
           }
         }
         PRUint8 style = styleText->GetDecorationStyle();
 
         if (NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE & decorMask &
               styleText->mTextDecorationLine) {
           underColor = color;
           underStyle = style;
@@ -486,23 +474,19 @@ nsTextBoxFrame::DrawText(nsRenderingCont
         if (NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH & decorMask &
               styleText->mTextDecorationLine) {
           strikeColor = color;
           strikeStyle = style;
           decorMask &= ~NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH;
           decorations |= NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH;
         }
       }
-      if (0 != decorMask) {
-        context = context->GetParent();
-        if (context) {
-          hasDecorationLines = context->HasTextDecorationLines();
-        }
-      }
-    } while (context && hasDecorationLines && (0 != decorMask));
+    } while (0 != decorMask &&
+             (f = nsLayoutUtils::GetParentOrPlaceholderFor(
+                                   presContext->FrameManager(), f)));
 
     nsRefPtr<nsFontMetrics> fontMet;
     nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
 
     nscoord offset;
     nscoord size;
     nscoord ascent = fontMet->MaxAscent();