diff --git a/layout/generic/nsHTMLContainerFrame.cpp b/layout/generic/nsHTMLContainerFrame.cpp
index 014e390f3be8..ae8d4185e2c7 100644
--- a/layout/generic/nsHTMLContainerFrame.cpp
+++ b/layout/generic/nsHTMLContainerFrame.cpp
@@ -145,9 +145,13 @@ nsHTMLContainerFrame::PaintDecorationsAndChildren(
nsCOMPtr fm;
nsCompatibility mode;
aPresContext->GetCompatibilityMode(&mode);
+ PRBool isVisible;
if (eCompatibility_NavQuirks != mode &&
- NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
+ NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer &&
+ NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext,
+ PR_TRUE, &isVisible)) &&
+ isVisible) {
GetTextDecorations(aPresContext, aIsBlock, decorations, underColor,
overColor, strikeColor);
if (decorations & (NS_STYLE_TEXT_DECORATION_UNDERLINE |
diff --git a/layout/html/base/src/nsHTMLContainerFrame.cpp b/layout/html/base/src/nsHTMLContainerFrame.cpp
index 014e390f3be8..ae8d4185e2c7 100644
--- a/layout/html/base/src/nsHTMLContainerFrame.cpp
+++ b/layout/html/base/src/nsHTMLContainerFrame.cpp
@@ -145,9 +145,13 @@ nsHTMLContainerFrame::PaintDecorationsAndChildren(
nsCOMPtr fm;
nsCompatibility mode;
aPresContext->GetCompatibilityMode(&mode);
+ PRBool isVisible;
if (eCompatibility_NavQuirks != mode &&
- NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
+ NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer &&
+ NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext,
+ PR_TRUE, &isVisible)) &&
+ isVisible) {
GetTextDecorations(aPresContext, aIsBlock, decorations, underColor,
overColor, strikeColor);
if (decorations & (NS_STYLE_TEXT_DECORATION_UNDERLINE |