bug 1320860 consider textview root node background in addition to text node for -moz-field r?stransky draft
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 03 Jan 2017 13:08:07 +1300
changeset 455183 9ec8373f08373b8917799a7694768f1cd3321cb1
parent 454751 ec622c5ba9e8e9ba1131ed86d4e6439c32062dc4
child 455184 533194c7b0ea0fcbf94a18be503d4aee49b92577
push id40148
push userktomlinson@mozilla.com
push dateTue, 03 Jan 2017 00:13:34 +0000
reviewersstransky
bugs1320860, 1324262
milestone53.0a1
bug 1320860 consider textview root node background in addition to text node for -moz-field r?stransky This is necessary for GTK versions > 3.18 because windows no longer clear their backgrounds since https://git.gnome.org/browse/gtk+/commit/?id=580ea227a6bb19ad6c6d4766b3a36dbad24583f3 and Ambiance for 3.20 has a transparent background for the "text" window. See bug 1324262. MozReview-Commit-ID: FL16Gx1EQR
widget/gtk/nsLookAndFeel.cpp
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -57,16 +57,32 @@ nsLookAndFeel::nsLookAndFeel()
 nsLookAndFeel::~nsLookAndFeel()
 {
 #if (MOZ_WIDGET_GTK == 2)
     g_object_unref(mStyle);
 #endif
 }
 
 #if MOZ_WIDGET_GTK != 2
+// Modifies color |*aDest| as if a pattern of color |aSource| was painted with
+// CAIRO_OPERATOR_OVER to a surface with color |*aDest|.
+static void
+ApplyColorOver(const GdkRGBA& aSource, GdkRGBA* aDest) {
+    gdouble sourceCoef = aSource.alpha;
+    gdouble destCoef = aDest->alpha * (1.0 - sourceCoef);
+    gdouble resultAlpha = sourceCoef + destCoef;
+    if (resultAlpha != 0.0) { // don't divide by zero
+        destCoef /= resultAlpha;
+        sourceCoef /= resultAlpha;
+        aDest->red = sourceCoef * aSource.red + destCoef * aDest->red;
+        aDest->green = sourceCoef * aSource.green + destCoef * aDest->green;
+        aDest->blue = sourceCoef * aSource.blue + destCoef * aDest->blue;
+    }
+}
+
 static void
 GetLightAndDarkness(const GdkRGBA& aColor,
                     double* aLightness, double* aDarkness)
 {
     double sum = aColor.red + aColor.green + aColor.blue;
     *aLightness = sum * aColor.alpha;
     *aDarkness = (3.0 - sum) * aColor.alpha;
 }
@@ -1285,19 +1301,29 @@ nsLookAndFeel::Init()
         sButtonBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]);
         sFrameOuterLightBorder =
             GDK_COLOR_TO_NS_RGB(style->light[GTK_STATE_NORMAL]);
         sFrameInnerDarkBorder =
             GDK_COLOR_TO_NS_RGB(style->dark[GTK_STATE_NORMAL]);
     }
 #else
     // Text colors
+    GdkRGBA bgColor;
+    // If the text window background is translucent, then the background of
+    // the textview root node is visible.
+    style = ClaimStyleContext(MOZ_GTK_TEXT_VIEW);
+    gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL,
+                                           &bgColor);
+    ReleaseStyleContext(style);
+
     style = ClaimStyleContext(MOZ_GTK_TEXT_VIEW_TEXT);
-    gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
-    sMozFieldBackground = GDK_RGBA_TO_NS_RGBA(color);
+    gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL,
+                                           &color);
+    ApplyColorOver(color, &bgColor);
+    sMozFieldBackground = GDK_RGBA_TO_NS_RGBA(bgColor);
     gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
     sMozFieldText = GDK_RGBA_TO_NS_RGBA(color);
 
     // Selected text and background
     gtk_style_context_get_background_color(style,
         static_cast<GtkStateFlags>(GTK_STATE_FLAG_FOCUSED|GTK_STATE_FLAG_SELECTED),
         &color);
     sTextSelectedBackground = GDK_RGBA_TO_NS_RGBA(color);