Bug 865806 - Part 1: Continue walking up the frame tree when hitting a transparent frame as we're trying to determine whether a given element's background is dark or not; r=roc
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 30 May 2013 14:27:57 -0400
changeset 133517 d921692be88fb0f5876b216956c7c814917347f1
parent 133516 fe6ca42a5b6e72d7229fa0ceeb873bcb1a8467cf
child 133518 a6de622f95744e724e08f448a6489ee272ad5463
push id24757
push userryanvm@gmail.com
push dateFri, 31 May 2013 20:11:58 +0000
treeherdermozilla-central@2222b07ab207 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs865806
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 865806 - Part 1: Continue walking up the frame tree when hitting a transparent frame as we're trying to determine whether a given element's background is dark or not; r=roc This heuristic improvement gives us correct dark background detection in pdf.js, among other cases.
widget/xpwidgets/nsNativeTheme.cpp
--- a/widget/xpwidgets/nsNativeTheme.cpp
+++ b/widget/xpwidgets/nsNativeTheme.cpp
@@ -686,18 +686,23 @@ nsNativeTheme::IsDarkBackground(nsIFrame
   while (!scrollFrame && aFrame) {
     scrollFrame = aFrame->GetScrollTargetFrame();
     aFrame = aFrame->GetParent();
   }
   if (!scrollFrame)
     return false;
 
   nsIFrame* frame = scrollFrame->GetScrolledFrame();
-  nsStyleContext* bgSC;
-  if (nsCSSRendering::FindBackground(frame, &bgSC)) {
+  nsStyleContext* bgSC = nullptr;
+  if (!nsCSSRendering::FindBackground(frame, &bgSC) ||
+      bgSC->StyleBackground()->IsTransparent()) {
+    nsIFrame* backgroundFrame = nsCSSRendering::FindNonTransparentBackgroundFrame(frame, true);
+    nsCSSRendering::FindBackground(backgroundFrame, &bgSC);
+  }
+  if (bgSC) {
     nscolor bgColor = bgSC->StyleBackground()->mBackgroundColor;
     // Consider the background color dark if the sum of the r, g and b values is
     // less than 384 in a semi-transparent document.  This heuristic matches what
     // WebKit does, and we can improve it later if needed.
     return NS_GET_A(bgColor) > 127 &&
            NS_GET_R(bgColor) + NS_GET_G(bgColor) + NS_GET_B(bgColor) < 384;
   }
   return false;