summaryrefslogtreecommitdiffstats
path: root/widget/gtk
diff options
context:
space:
mode:
authortrav90 <travawine@protonmail.ch>2018-04-06 07:41:32 -0500
committertrav90 <travawine@protonmail.ch>2018-04-06 07:52:43 -0500
commit3203c21a801b034e7d8c8ce2e4cd802adc37b1fc (patch)
tree6cafee2a1b745bf2e6224f7db2b389b5d8f388bd /widget/gtk
parent0f83951b6b67e9c1a1e4c30b107639671a02d567 (diff)
downloadUXP-3203c21a801b034e7d8c8ce2e4cd802adc37b1fc.tar
UXP-3203c21a801b034e7d8c8ce2e4cd802adc37b1fc.tar.gz
UXP-3203c21a801b034e7d8c8ce2e4cd802adc37b1fc.tar.lz
UXP-3203c21a801b034e7d8c8ce2e4cd802adc37b1fc.tar.xz
UXP-3203c21a801b034e7d8c8ce2e4cd802adc37b1fc.zip
[GTK3] Use WidgetCache to get colors at nsLookAndFeel
Diffstat (limited to 'widget/gtk')
-rw-r--r--widget/gtk/WidgetStyleCache.cpp40
-rw-r--r--widget/gtk/gtk3drawing.cpp26
-rw-r--r--widget/gtk/gtkdrawing.h4
-rw-r--r--widget/gtk/nsLookAndFeel.cpp14
4 files changed, 38 insertions, 46 deletions
diff --git a/widget/gtk/WidgetStyleCache.cpp b/widget/gtk/WidgetStyleCache.cpp
index 6e5fc669b..bfb96653f 100644
--- a/widget/gtk/WidgetStyleCache.cpp
+++ b/widget/gtk/WidgetStyleCache.cpp
@@ -754,6 +754,27 @@ GetWidgetRootStyle(WidgetNodeType aNodeType)
style = CreateStyleForWidget(gtk_radio_menu_item_new(nullptr),
MOZ_GTK_MENUPOPUP);
break;
+ case MOZ_GTK_TOOLTIP:
+ if (gtk_check_version(3, 20, 0) != nullptr) {
+ // The tooltip style class is added first in CreateTooltipWidget()
+ // and transfered to style in CreateStyleForWidget().
+ GtkWidget* tooltipWindow = CreateTooltipWidget();
+ style = CreateStyleForWidget(tooltipWindow, nullptr);
+ gtk_widget_destroy(tooltipWindow); // Release GtkWindow self-reference.
+ } else {
+ // 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;
+ 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;
default:
GtkWidget* widget = GetWidget(aNodeType);
MOZ_ASSERT(widget);
@@ -844,11 +865,6 @@ GetCssNodeStyleInternal(WidgetNodeType aNodeType)
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;
case MOZ_GTK_GRIPPER:
// TODO - create from CSS node
return GetWidgetStyleWithClass(MOZ_GTK_GRIPPER,
@@ -980,20 +996,6 @@ GetWidgetStyleInternal(WidgetNodeType aNodeType)
case MOZ_GTK_PROGRESS_TROUGH:
return GetWidgetStyleWithClass(MOZ_GTK_PROGRESSBAR,
GTK_STYLE_CLASS_TROUGH);
- case MOZ_GTK_TOOLTIP: {
- GtkStyleContext* style = sStyleStorage[aNodeType];
- if (style)
- return style;
-
- // The tooltip style class is added first in CreateTooltipWidget() so
- // that gtk_widget_path_append_for_widget() in CreateStyleForWidget()
- // will find it.
- GtkWidget* tooltipWindow = CreateTooltipWidget();
- style = CreateStyleForWidget(tooltipWindow, nullptr);
- gtk_widget_destroy(tooltipWindow); // Release GtkWindow self-reference.
- sStyleStorage[aNodeType] = style;
- return style;
- }
case MOZ_GTK_GRIPPER:
return GetWidgetStyleWithClass(MOZ_GTK_GRIPPER,
GTK_STYLE_CLASS_GRIP);
diff --git a/widget/gtk/gtk3drawing.cpp b/widget/gtk/gtk3drawing.cpp
index 48d76a9ee..062a5c006 100644
--- a/widget/gtk/gtk3drawing.cpp
+++ b/widget/gtk/gtk3drawing.cpp
@@ -1299,6 +1299,7 @@ moz_gtk_tooltip_paint(cairo_t *cr, const GdkRectangle* aRect,
GdkRectangle rect = *aRect;
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);
// Horizontal Box drawing
//
@@ -1308,8 +1309,7 @@ moz_gtk_tooltip_paint(cairo_t *cr, const GdkRectangle* aRect,
// 6px margin.
// For drawing Horizontal Box we have to inset drawing area by that 6px
// plus its CSS margin.
- GtkStyleContext* boxStyle =
- CreateStyleForWidget(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0), style);
+ GtkStyleContext* boxStyle = ClaimStyleContext(MOZ_GTK_TOOLTIP_BOX, direction);
rect.x += 6;
rect.y += 6;
@@ -1322,15 +1322,13 @@ moz_gtk_tooltip_paint(cairo_t *cr, const GdkRectangle* aRect,
// Label drawing
InsetByBorderPadding(&rect, boxStyle);
+ ReleaseStyleContext(boxStyle);
GtkStyleContext* labelStyle =
- CreateStyleForWidget(gtk_label_new(nullptr), boxStyle);
+ ClaimStyleContext(MOZ_GTK_TOOLTIP_BOX_LABEL, direction);
moz_gtk_draw_styled_frame(labelStyle, cr, &rect, false);
- g_object_unref(labelStyle);
-
- g_object_unref(boxStyle);
+ ReleaseStyleContext(labelStyle);
- ReleaseStyleContext(style);
return MOZ_GTK_SUCCESS;
}
@@ -2207,7 +2205,6 @@ moz_gtk_get_widget_border(WidgetNodeType widget, gint* left, gint* top,
break;
case MOZ_GTK_TOOLTIP:
{
- style = ClaimStyleContext(MOZ_GTK_TOOLTIP);
// In GTK 3 there are 6 pixels of additional margin around the box.
// See details there:
// https://github.com/GNOME/gtk/blob/5ea69a136bd7e4970b3a800390e20314665aaed2/gtk/ui/gtktooltipwindow.ui#L11
@@ -2216,21 +2213,16 @@ moz_gtk_get_widget_border(WidgetNodeType widget, gint* left, gint* top,
// We also need to add margin/padding/borders from Tooltip content.
// Tooltip contains horizontal box, where icon and label is put.
// We ignore icon as long as we don't have support for it.
- GtkStyleContext* boxStyle =
- CreateStyleForWidget(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0),
- style);
+ GtkStyleContext* boxStyle = ClaimStyleContext(MOZ_GTK_TOOLTIP_BOX);
moz_gtk_add_margin_border_padding(boxStyle,
left, top, right, bottom);
+ ReleaseStyleContext(boxStyle);
- GtkStyleContext* labelStyle =
- CreateStyleForWidget(gtk_label_new(nullptr), boxStyle);
+ GtkStyleContext* labelStyle = ClaimStyleContext(MOZ_GTK_TOOLTIP_BOX_LABEL);
moz_gtk_add_margin_border_padding(labelStyle,
left, top, right, bottom);
+ ReleaseStyleContext(labelStyle);
- g_object_unref(labelStyle);
- g_object_unref(boxStyle);
-
- ReleaseStyleContext(style);
return MOZ_GTK_SUCCESS;
}
case MOZ_GTK_SCROLLBAR_VERTICAL:
diff --git a/widget/gtk/gtkdrawing.h b/widget/gtk/gtkdrawing.h
index 1df8a10ff..540e38184 100644
--- a/widget/gtk/gtkdrawing.h
+++ b/widget/gtk/gtkdrawing.h
@@ -160,6 +160,10 @@ typedef enum {
MOZ_GTK_TOOLBAR_SEPARATOR,
/* Paints a GtkToolTip */
MOZ_GTK_TOOLTIP,
+ /* Paints a GtkBox from GtkToolTip */
+ MOZ_GTK_TOOLTIP_BOX,
+ /* Paints a GtkLabel of GtkToolTip */
+ MOZ_GTK_TOOLTIP_BOX_LABEL,
/* Paints a GtkFrame (e.g. a status bar panel). */
MOZ_GTK_FRAME,
/* Paints the border of a GtkFrame */
diff --git a/widget/gtk/nsLookAndFeel.cpp b/widget/gtk/nsLookAndFeel.cpp
index 53430dfbb..775b52924 100644
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -1161,16 +1161,10 @@ nsLookAndFeel::Init()
style = ClaimStyleContext(MOZ_GTK_TOOLTIP);
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
sInfoBackground = GDK_RGBA_TO_NS_RGBA(color);
- {
- GtkStyleContext* boxStyle =
- CreateStyleForWidget(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0),
- style);
- GtkStyleContext* labelStyle =
- CreateStyleForWidget(gtk_label_new(nullptr), boxStyle);
- gtk_style_context_get_color(labelStyle, GTK_STATE_FLAG_NORMAL, &color);
- g_object_unref(labelStyle);
- g_object_unref(boxStyle);
- }
+ ReleaseStyleContext(style);
+
+ style = ClaimStyleContext(MOZ_GTK_TOOLTIP_BOX_LABEL);
+ gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
sInfoText = GDK_RGBA_TO_NS_RGBA(color);
ReleaseStyleContext(style);