From d0eb61c94be12dabee511278dea38c2319620b60 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 30 May 2013 22:23:49 -0400 Subject: [PATCH] Bug 876129 - Part 2: Prefer to look at instead of when determining whether the background color of a page is dark or not; r=roc This seems to be a slightly better heuristic to follow the CSS Rendering code in all cases, since the background color for the body element often overrides that of the html element. --HG-- extra : rebase_source : ef4ac31003d75fb0fe17b493d7267ba3306e77bf --- widget/xpwidgets/nsNativeTheme.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/widget/xpwidgets/nsNativeTheme.cpp b/widget/xpwidgets/nsNativeTheme.cpp index 3e57f0e8b621..ad272f8e4fca 100644 --- a/widget/xpwidgets/nsNativeTheme.cpp +++ b/widget/xpwidgets/nsNativeTheme.cpp @@ -25,6 +25,8 @@ #include "nsRangeFrame.h" #include "nsCSSRendering.h" #include "mozilla/dom/Element.h" +#include "mozilla/dom/HTMLBodyElement.h" +#include "nsIDocumentInlines.h" #include nsNativeTheme::nsNativeTheme() @@ -679,6 +681,21 @@ nsNativeTheme::IsRangeHorizontal(nsIFrame* aFrame) return static_cast(rangeFrame)->IsHorizontal(); } +static nsIFrame* +GetBodyFrame(nsIFrame* aCanvasFrame) +{ + nsIContent* content = aCanvasFrame->GetContent(); + if (!content) { + return nullptr; + } + nsIDocument* document = content->OwnerDoc(); + nsIContent* body = document->GetBodyElement(); + if (!body) { + return nullptr; + } + return body->GetPrimaryFrame(); +} + bool nsNativeTheme::IsDarkBackground(nsIFrame* aFrame) { @@ -691,6 +708,16 @@ nsNativeTheme::IsDarkBackground(nsIFrame* aFrame) return false; nsIFrame* frame = scrollFrame->GetScrolledFrame(); + if (nsCSSRendering::IsCanvasFrame(frame)) { + // For canvas frames, prefer to look at the body first, because the body + // background color is most likely what will be visible as the background + // color of the page, even if the html element has a different background + // color which prevents that of the body frame to propagate to the viewport. + nsIFrame* bodyFrame = GetBodyFrame(frame); + if (bodyFrame) { + frame = bodyFrame; + } + } nsStyleContext* bgSC = nullptr; if (!nsCSSRendering::FindBackground(frame, &bgSC) || bgSC->StyleBackground()->IsTransparent()) {