bug 1323656 use CreateCSSNode for MOZ_GTK_SCROLLED_WINDOW instead of using the widget's context r?stransky draft
authorKarl Tomlinson <karlt+@karlt.net>
Thu, 15 Dec 2016 16:42:48 +1300
changeset 645152 620ae8e576261f50ad052f7330cdc68c4e48a310
parent 645151 571aa087923903179536a5ebaff8577e5141e534
child 645153 2f56b8f07012cae840d31d7fb9a05c7a7005b608
push id73684
push userktomlinson@mozilla.com
push dateFri, 11 Aug 2017 22:29:12 +0000
reviewersstransky
bugs1323656
milestone57.0a1
bug 1323656 use CreateCSSNode for MOZ_GTK_SCROLLED_WINDOW instead of using the widget's context r?stransky This means there is no need to cache the widget, nor deal with widget invalidation and animations. The style context is no longer saved in versions >= 3.20 to match changes in GTK drawing and layout. MozReview-Commit-ID: JeQMWn2nSa9
widget/gtk/WidgetStyleCache.cpp
--- a/widget/gtk/WidgetStyleCache.cpp
+++ b/widget/gtk/WidgetStyleCache.cpp
@@ -417,24 +417,16 @@ CreateComboBoxEntryArrowWidget()
                               reinterpret_cast<gpointer *>(sWidgetStorage) +
                               MOZ_GTK_COMBOBOX_ENTRY_ARROW);
   }
 
   return comboBoxArrow;
 }
 
 static GtkWidget*
-CreateScrolledWindowWidget()
-{
-  GtkWidget* widget = gtk_scrolled_window_new(nullptr, nullptr);
-  AddToWindowContainer(widget);
-  return widget;
-}
-
-static GtkWidget*
 CreateMenuSeparatorWidget()
 {
   GtkWidget* widget = gtk_separator_menu_item_new();
   gtk_menu_shell_append(GTK_MENU_SHELL(GetWidget(MOZ_GTK_MENUPOPUP)),
                         widget);
   return widget;
 }
 
@@ -571,18 +563,16 @@ CreateWidget(WidgetNodeType aWidgetType)
     case MOZ_GTK_BUTTON:
       return CreateButtonWidget();
     case MOZ_GTK_TOGGLE_BUTTON:
       return CreateToggleButtonWidget();
     case MOZ_GTK_BUTTON_ARROW:
       return CreateButtonArrowWidget();
     case MOZ_GTK_ENTRY:
       return CreateEntryWidget();
-    case MOZ_GTK_SCROLLED_WINDOW: 
-      return CreateScrolledWindowWidget();
     case MOZ_GTK_TREEVIEW:
       return CreateTreeViewWidget();
     case MOZ_GTK_TREE_HEADER_CELL:
       return CreateTreeHeaderCellWidget();
     case MOZ_GTK_TREE_HEADER_SORTARROW:
       return CreateTreeHeaderSortArrowWidget();
     case MOZ_GTK_SPLITTER_HORIZONTAL:
       return CreateHPanedWidget();
@@ -791,16 +781,27 @@ GetWidgetRootStyle(WidgetNodeType aNodeT
     case MOZ_GTK_TOOLTIP_BOX:
       style = CreateStyleForWidget(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0),
                                    MOZ_GTK_TOOLTIP);
       break;
     case MOZ_GTK_TOOLTIP_BOX_LABEL:
       style = CreateStyleForWidget(gtk_label_new(nullptr),
                                    MOZ_GTK_TOOLTIP_BOX);
       break;
+    case MOZ_GTK_SCROLLED_WINDOW:
+      style = CreateStyleForWidget(gtk_scrolled_window_new(nullptr, nullptr),
+                                   MOZ_GTK_WINDOW_CONTAINER);
+      // GTK versions newer than 3.14 add the "frame" class when
+      // gtk_scrolled_window_set_shadow_type() is called with a non-none
+      // type.  The actual type is irrelevant, but the frame provides the
+      // visible border around textareas.
+      if (gtk_get_minor_version() > 14) {
+        gtk_style_context_add_class(style, GTK_STYLE_CLASS_FRAME);
+      }
+      break;
     default:
       GtkWidget* widget = GetWidget(aNodeType);
       MOZ_ASSERT(widget);
       return gtk_widget_get_style_context(widget);
   }
 
   MOZ_ASSERT(style);
   sStyleStorage[aNodeType] = style;
@@ -941,21 +942,16 @@ GetCssNodeStyleInternal(WidgetNodeType a
       style = CreateSubStyleWithClass(MOZ_GTK_INFO_BAR,
                                       GTK_STYLE_CLASS_INFO);
       break;
     case MOZ_GTK_SPINBUTTON_ENTRY:
       // TODO - create from CSS node
       style = CreateSubStyleWithClass(MOZ_GTK_SPINBUTTON,
                                       GTK_STYLE_CLASS_ENTRY);
       break;
-    case MOZ_GTK_SCROLLED_WINDOW:
-      // TODO - create from CSS node
-      style = CreateSubStyleWithClass(MOZ_GTK_SCROLLED_WINDOW,
-                                      GTK_STYLE_CLASS_FRAME);
-      break;
     case MOZ_GTK_TEXT_VIEW_TEXT:
     case MOZ_GTK_RESIZER:
       style = CreateChildCSSNode("text", MOZ_GTK_TEXT_VIEW);
       if (aNodeType == MOZ_GTK_RESIZER) {
         // The "grip" class provides the correct builtin icon from
         // gtk_render_handle().  The icon is drawn with shaded variants of
         // the background color, and so a transparent background would lead to
         // a transparent resizer.  gtk_render_handle() also uses the
@@ -1112,16 +1108,20 @@ GetWidgetStyleInternal(WidgetNodeType aN
       style = CreateSubStyleWithClass(MOZ_GTK_INFO_BAR,
                                       GTK_STYLE_CLASS_INFO);
       break;
     case MOZ_GTK_SPINBUTTON_ENTRY:
       style = CreateSubStyleWithClass(MOZ_GTK_SPINBUTTON,
                                       GTK_STYLE_CLASS_ENTRY);
       break;
     case MOZ_GTK_SCROLLED_WINDOW:
+      // All GTK versions < 3.20 save the style context when getting border
+      // and padding.  Only versions < 3.14 do this when drawing, but no
+      // distinction is made here for versions 3.14 to 3.18 because the CSS
+      // node is similar enough to match selectors from themes.
       style = CreateSubStyleWithClass(MOZ_GTK_SCROLLED_WINDOW,
                                       GTK_STYLE_CLASS_FRAME);
       break;
     case MOZ_GTK_TEXT_VIEW_TEXT:
     case MOZ_GTK_RESIZER:
       // GTK versions prior to 3.20 do not have the view class on the root
       // node, but add this to determine the background for the text window.
       style = CreateSubStyleWithClass(MOZ_GTK_TEXT_VIEW, GTK_STYLE_CLASS_VIEW);