Bug 1271523 - Construct tooltip style from path for Gtk >= 3.20. r=karlt, a=lizzard
authorMartin Stransky <stransky@redhat.com>
Tue, 07 Jun 2016 06:22:00 +0200
changeset 341759 e729f06b361f8f5a1c953edb151f0f6ef5418200
parent 341758 2e16cca367c04506b5cf3015c1cac662ceb33fad
child 341760 a720069003b6eabfe0d347ad4c14e9649d21e017
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt, lizzard
bugs1271523, 1277818
milestone49.0a2
Bug 1271523 - Construct tooltip style from path for Gtk >= 3.20. r=karlt, a=lizzard To apply it needs a patch from Bug 1277818. MozReview-Commit-ID: 3xhYDliL4iw
widget/gtk/WidgetStyleCache.cpp
widget/gtk/gtk3drawing.cpp
widget/gtk/mozgtk/mozgtk.c
--- a/widget/gtk/WidgetStyleCache.cpp
+++ b/widget/gtk/WidgetStyleCache.cpp
@@ -101,16 +101,27 @@ static GtkWidget*
 CreateProgressWidget()
 {
   GtkWidget* widget = gtk_progress_bar_new();
   AddToWindowContainer(widget);
   return widget;
 }
 
 static GtkWidget*
+CreateTooltipWidget()
+{
+  MOZ_ASSERT(gtk_check_version(3, 20, 0) != nullptr,
+             "CreateTooltipWidget should be used for Gtk < 3.20 only.");
+  GtkWidget* widget = CreateWindowWidget();
+  GtkStyleContext* style = gtk_widget_get_style_context(widget);
+  gtk_style_context_add_class(style, GTK_STYLE_CLASS_TOOLTIP);
+  return widget;
+}
+
+static GtkWidget*
 CreateWidget(WidgetNodeType aWidgetType)
 {
   switch (aWidgetType) {
     case MOZ_GTK_WINDOW:
       return CreateWindowWidget();
     case MOZ_GTK_WINDOW_CONTAINER:
       return CreateWindowContainerWidget();
     case MOZ_GTK_CHECKBUTTON_CONTAINER:
@@ -128,16 +139,18 @@ CreateWidget(WidgetNodeType aWidgetType)
     case MOZ_GTK_MENUBAR:
       return CreateMenuBarWidget();
     case MOZ_GTK_MENUPOPUP:
       return CreateMenuPopupWidget();
     case MOZ_GTK_MENUBARITEM:
       return CreateMenuItemWidget(MOZ_GTK_MENUBAR);
     case MOZ_GTK_MENUITEM:
       return CreateMenuItemWidget(MOZ_GTK_MENUPOPUP);
+    case MOZ_GTK_TOOLTIP:
+      return CreateTooltipWidget();
     default:
       /* Not implemented */
       return nullptr;
   }
 }
 
 GtkWidget*
 GetWidget(WidgetNodeType aWidgetType)
@@ -216,16 +229,21 @@ GetCssNodeStyleInternal(WidgetNodeType a
       /* Progress bar background (trough) */
       style = CreateChildCSSNode(GTK_STYLE_CLASS_TROUGH,
                                  MOZ_GTK_PROGRESSBAR);
       break;
     case MOZ_GTK_PROGRESS_CHUNK:
       style = CreateChildCSSNode("progress",
                                  MOZ_GTK_PROGRESS_TROUGH);
       break;
+    case MOZ_GTK_TOOLTIP:
+      // We create this from the path because GtkTooltipWindow is not public.
+      style = CreateCSSNode("tooltip", nullptr, GTK_TYPE_TOOLTIP);
+      gtk_style_context_add_class(style, GTK_STYLE_CLASS_BACKGROUND);
+      break; 
     default:
       // TODO - create style from style path
       GtkWidget* widget = GetWidget(aNodeType);
       return gtk_widget_get_style_context(widget);
   }
 
   if (style) {
     sStyleStorage[aNodeType] = style;
--- a/widget/gtk/gtk3drawing.cpp
+++ b/widget/gtk/gtk3drawing.cpp
@@ -34,17 +34,16 @@ static GtkWidget* gComboBoxEntryWidget;
 static GtkWidget* gComboBoxEntryTextareaWidget;
 static GtkWidget* gComboBoxEntryButtonWidget;
 static GtkWidget* gComboBoxEntryArrowWidget;
 static GtkWidget* gHandleBoxWidget;
 static GtkWidget* gToolbarWidget;
 static GtkWidget* gFrameWidget;
 static GtkWidget* gTabWidget;
 static GtkWidget* gTextViewWidget;
-static GtkWidget* gTooltipWidget;
 static GtkWidget* gImageMenuItemWidget;
 static GtkWidget* gCheckMenuItemWidget;
 static GtkWidget* gTreeViewWidget;
 static GtkTreeViewColumn* gMiddleTreeViewColumn;
 static GtkWidget* gTreeHeaderCellWidget;
 static GtkWidget* gTreeHeaderSortArrowWidget;
 static GtkWidget* gExpanderWidget;
 static GtkWidget* gToolbarSeparatorWidget;
@@ -83,25 +82,16 @@ GetStateFlagsFromGtkWidgetState(GtkWidge
             stateFlags = static_cast<GtkStateFlags>(stateFlags|GTK_STATE_FLAG_PRELIGHT);
         if (state->focused)
             stateFlags = static_cast<GtkStateFlags>(stateFlags|GTK_STATE_FLAG_FOCUSED);
     }
   
     return stateFlags;
 }
 
-/* Because we have such an unconventional way of drawing widgets, signal to the GTK theme engine
-   that they are drawing for Mozilla instead of a conventional GTK app so they can do any specific
-   things they may want to do. */
-static void
-moz_gtk_set_widget_name(GtkWidget* widget)
-{
-    gtk_widget_set_name(widget, "MozillaGtkWidget");
-}
-
 gint
 moz_gtk_enable_style_props(style_prop_t styleGetProp)
 {
     style_prop_func = styleGetProp;
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
@@ -442,29 +432,16 @@ ensure_toolbar_separator_widget()
         ensure_toolbar_widget();
         gToolbarSeparatorWidget = GTK_WIDGET(gtk_separator_tool_item_new());
         setup_widget_prototype(gToolbarSeparatorWidget);
     }
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
-ensure_tooltip_widget()
-{
-    if (!gTooltipWidget) {
-        gTooltipWidget = gtk_window_new(GTK_WINDOW_POPUP);
-        GtkStyleContext* style = gtk_widget_get_style_context(gTooltipWidget);
-        gtk_style_context_add_class(style, GTK_STYLE_CLASS_TOOLTIP);
-        gtk_widget_realize(gTooltipWidget);
-        moz_gtk_set_widget_name(gTooltipWidget);
-    }
-    return MOZ_GTK_SUCCESS;
-}
-
-static gint
 ensure_tab_widget()
 {
     if (!gTabWidget) {
         gTabWidget = gtk_notebook_new();
         setup_widget_prototype(gTabWidget);
     }
     return MOZ_GTK_SUCCESS;
 }
@@ -1804,24 +1781,20 @@ moz_gtk_toolbar_separator_paint(cairo_t 
 
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_tooltip_paint(cairo_t *cr, GdkRectangle* rect,
                       GtkTextDirection direction)
 {
-    GtkStyleContext* style;
-
-    ensure_tooltip_widget();
-    gtk_widget_set_direction(gTooltipWidget, direction);
-
-    style = gtk_widget_get_style_context(gTooltipWidget);
+    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_TOOLTIP, direction);
     gtk_render_background(style, cr, rect->x, rect->y, rect->width, rect->height);
     gtk_render_frame(style, cr, rect->x, rect->y, rect->width, rect->height);
+    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_resizer_paint(cairo_t *cr, GdkRectangle* rect,
                       GtkWidgetState* state,
                       GtkTextDirection direction)
 {
@@ -2733,16 +2706,24 @@ moz_gtk_get_widget_border(WidgetNodeType
             moz_gtk_add_style_padding(gtk_widget_get_style_context(w),
                                       left, top, right, bottom);
             return MOZ_GTK_SUCCESS;
         }
     case MOZ_GTK_INFO_BAR:
         ensure_info_bar();
         w = gInfoBar;
         break;
+    case MOZ_GTK_TOOLTIP:
+        {
+            style = ClaimStyleContext(MOZ_GTK_TOOLTIP);
+            moz_gtk_add_style_border(style, left, top, right, bottom);
+            moz_gtk_add_style_padding(style, left, top, right, bottom);
+            ReleaseStyleContext(style);
+            return MOZ_GTK_SUCCESS;
+        }
     /* These widgets have no borders, since they are not containers. */
     case MOZ_GTK_CHECKBUTTON_LABEL:
     case MOZ_GTK_RADIOBUTTON_LABEL:
     case MOZ_GTK_SPLITTER_HORIZONTAL:
     case MOZ_GTK_SPLITTER_VERTICAL:
     case MOZ_GTK_CHECKBUTTON:
     case MOZ_GTK_RADIOBUTTON:
     case MOZ_GTK_SCROLLBAR_BUTTON:
@@ -2756,17 +2737,16 @@ moz_gtk_get_widget_border(WidgetNodeType
     case MOZ_GTK_PROGRESS_CHUNK:
     case MOZ_GTK_PROGRESS_CHUNK_INDETERMINATE:
     case MOZ_GTK_PROGRESS_CHUNK_VERTICAL_INDETERMINATE:
     case MOZ_GTK_TREEVIEW_EXPANDER:
     case MOZ_GTK_TOOLBAR_SEPARATOR:
     case MOZ_GTK_MENUSEPARATOR:
     /* These widgets have no borders.*/
     case MOZ_GTK_SPINBUTTON:
-    case MOZ_GTK_TOOLTIP:
     case MOZ_GTK_WINDOW:
     case MOZ_GTK_RESIZER:
     case MOZ_GTK_MENUARROW:
     case MOZ_GTK_TOOLBARBUTTON_ARROW:
     case MOZ_GTK_TOOLBAR:
     case MOZ_GTK_MENUBAR:
     case MOZ_GTK_TAB_SCROLLARROW:
         return MOZ_GTK_SUCCESS;
@@ -3282,20 +3262,17 @@ gboolean moz_gtk_has_scrollbar_buttons(v
     ReleaseStyleContext(style);
 
     return backward | forward | secondary_forward | secondary_forward;
 }
 
 gint
 moz_gtk_shutdown()
 {
-    if (gTooltipWidget)
-        gtk_widget_destroy(gTooltipWidget);
     /* This will destroy all of our widgets */
-
     ResetWidgetCache();
 
     /* TODO - replace it with appropriate widget */
     if (gTreeHeaderSortArrowWidget)
         gtk_widget_destroy(gTreeHeaderSortArrowWidget);
 
     gProtoLayout = NULL;
     gButtonWidget = NULL;
@@ -3313,17 +3290,16 @@ moz_gtk_shutdown()
     gComboBoxEntryButtonWidget = NULL;
     gComboBoxEntryArrowWidget = NULL;
     gComboBoxEntryTextareaWidget = NULL;
     gHandleBoxWidget = NULL;
     gToolbarWidget = NULL;
     gFrameWidget = NULL;
     gTabWidget = NULL;
     gTextViewWidget = nullptr;
-    gTooltipWidget = NULL;
     gImageMenuItemWidget = NULL;
     gCheckMenuItemWidget = NULL;
     gTreeViewWidget = NULL;
     gMiddleTreeViewColumn = NULL;
     gTreeHeaderCellWidget = NULL;
     gTreeHeaderSortArrowWidget = NULL;
     gExpanderWidget = NULL;
     gToolbarSeparatorWidget = NULL;
--- a/widget/gtk/mozgtk/mozgtk.c
+++ b/widget/gtk/mozgtk/mozgtk.c
@@ -406,16 +406,17 @@ STUB(gtk_target_table_free)
 STUB(gtk_target_table_new_from_list)
 STUB(gtk_text_view_new)
 STUB(gtk_toggle_button_get_active)
 STUB(gtk_toggle_button_get_type)
 STUB(gtk_toggle_button_new)
 STUB(gtk_toggle_button_set_active)
 STUB(gtk_toggle_button_set_inconsistent)
 STUB(gtk_toolbar_new)
+STUB(gtk_tooltip_get_type)
 STUB(gtk_tree_view_append_column)
 STUB(gtk_tree_view_column_new)
 STUB(gtk_tree_view_column_set_title)
 STUB(gtk_tree_view_get_type)
 STUB(gtk_tree_view_new)
 STUB(gtk_vbox_new)
 STUB(gtk_widget_add_events)
 STUB(gtk_widget_class_find_style_property)