Bug 876129 - Part 2: Prefer to look at <body> instead of <html> 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
This commit is contained in:
Ehsan Akhgari 2013-05-30 22:23:49 -04:00
Родитель a0b40933ce
Коммит d0eb61c94b
1 изменённых файлов: 27 добавлений и 0 удалений

Просмотреть файл

@ -25,6 +25,8 @@
#include "nsRangeFrame.h"
#include "nsCSSRendering.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/HTMLBodyElement.h"
#include "nsIDocumentInlines.h"
#include <algorithm>
nsNativeTheme::nsNativeTheme()
@ -679,6 +681,21 @@ nsNativeTheme::IsRangeHorizontal(nsIFrame* aFrame)
return static_cast<nsRangeFrame*>(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()) {