Bug 1289763 - Move gImageMenuItemWidget/gCheckMenuItemWidget to WidgetCache, r=acomminos

This commit is contained in:
Martin Stransky 2016-07-28 03:54:00 +02:00
parent d055a30b27
commit 0bbcee935c
4 changed files with 75 additions and 56 deletions

View File

@ -303,6 +303,33 @@ CreateVPanedWidget()
return widget;
}
static GtkWidget*
CreateImageMenuItemWidget()
{
GtkWidget* widget = gtk_image_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(GetWidget(MOZ_GTK_MENUPOPUP)), widget);
gtk_widget_realize(widget);
return widget;
}
static GtkWidget*
CreateCheckMenuItemWidget()
{
GtkWidget* widget = gtk_check_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(GetWidget(MOZ_GTK_MENUPOPUP)), widget);
gtk_widget_realize(widget);
return widget;
}
static GtkWidget*
CreateRadioMenuItemWidget()
{
GtkWidget* widget = gtk_radio_menu_item_new(nullptr);
gtk_menu_shell_append(GTK_MENU_SHELL(GetWidget(MOZ_GTK_MENUPOPUP)), widget);
gtk_widget_realize(widget);
return widget;
}
static GtkWidget*
CreateWidget(WidgetNodeType aWidgetType)
{
@ -369,6 +396,12 @@ CreateWidget(WidgetNodeType aWidgetType)
return CreateHPanedWidget();
case MOZ_GTK_SPLITTER_VERTICAL:
return CreateVPanedWidget();
case MOZ_GTK_IMAGEMENUITEM:
return CreateImageMenuItemWidget();
case MOZ_GTK_CHECKMENUITEM_CONTAINER:
return CreateCheckMenuItemWidget();
case MOZ_GTK_RADIOMENUITEM_CONTAINER:
return CreateRadioMenuItemWidget();
default:
/* Not implemented */
return nullptr;
@ -491,6 +524,14 @@ GetCssNodeStyleInternal(WidgetNodeType aNodeType)
style = CreateChildCSSNode(GTK_STYLE_CLASS_CHECK,
MOZ_GTK_CHECKBUTTON_CONTAINER);
break;
case MOZ_GTK_RADIOMENUITEM:
style = CreateChildCSSNode(GTK_STYLE_CLASS_RADIO,
MOZ_GTK_RADIOMENUITEM_CONTAINER);
break;
case MOZ_GTK_CHECKMENUITEM:
style = CreateChildCSSNode(GTK_STYLE_CLASS_CHECK,
MOZ_GTK_CHECKMENUITEM_CONTAINER);
break;
case MOZ_GTK_PROGRESS_TROUGH:
/* Progress bar background (trough) */
style = CreateChildCSSNode(GTK_STYLE_CLASS_TROUGH,
@ -577,6 +618,12 @@ GetWidgetStyleInternal(WidgetNodeType aNodeType)
case MOZ_GTK_CHECKBUTTON:
return GetWidgetStyleWithClass(MOZ_GTK_CHECKBUTTON_CONTAINER,
GTK_STYLE_CLASS_CHECK);
case MOZ_GTK_RADIOMENUITEM:
return GetWidgetStyleWithClass(MOZ_GTK_RADIOMENUITEM_CONTAINER,
GTK_STYLE_CLASS_RADIO);
case MOZ_GTK_CHECKMENUITEM:
return GetWidgetStyleWithClass(MOZ_GTK_CHECKMENUITEM_CONTAINER,
GTK_STYLE_CLASS_CHECK);
case MOZ_GTK_PROGRESS_TROUGH:
return GetWidgetStyleWithClass(MOZ_GTK_PROGRESSBAR,
GTK_STYLE_CLASS_TROUGH);

View File

@ -30,8 +30,6 @@ static GtkWidget* gComboBoxEntryTextareaWidget;
static GtkWidget* gComboBoxEntryButtonWidget;
static GtkWidget* gComboBoxEntryArrowWidget;
static GtkWidget* gTabWidget;
static GtkWidget* gImageMenuItemWidget;
static GtkWidget* gCheckMenuItemWidget;
static style_prop_t style_prop_func;
static gboolean have_arrow_scaling;
@ -304,30 +302,6 @@ ensure_tab_widget()
return MOZ_GTK_SUCCESS;
}
static gint
ensure_image_menu_item_widget()
{
if (!gImageMenuItemWidget) {
gImageMenuItemWidget = gtk_image_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(GetWidget(MOZ_GTK_MENUPOPUP)),
gImageMenuItemWidget);
gtk_widget_realize(gImageMenuItemWidget);
}
return MOZ_GTK_SUCCESS;
}
static gint
ensure_check_menu_item_widget()
{
if (!gCheckMenuItemWidget) {
gCheckMenuItemWidget = gtk_check_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(GetWidget(MOZ_GTK_MENUPOPUP)),
gCheckMenuItemWidget);
gtk_widget_realize(gCheckMenuItemWidget);
}
return MOZ_GTK_SUCCESS;
}
gint
moz_gtk_init()
{
@ -402,12 +376,11 @@ moz_gtk_menuitem_get_horizontal_padding(gint* horizontal_padding)
gint
moz_gtk_checkmenuitem_get_horizontal_padding(gint* horizontal_padding)
{
ensure_check_menu_item_widget();
gtk_style_context_get_style(gtk_widget_get_style_context(gCheckMenuItemWidget),
GtkStyleContext *style = ClaimStyleContext(MOZ_GTK_CHECKMENUITEM_CONTAINER);
gtk_style_context_get_style(style,
"horizontal-padding", horizontal_padding,
NULL);
ReleaseStyleContext(style);
return MOZ_GTK_SUCCESS;
}
@ -2101,32 +2074,26 @@ moz_gtk_check_menu_item_paint(cairo_t *cr, GdkRectangle* rect,
moz_gtk_menu_item_paint(MOZ_GTK_MENUITEM, cr, rect, state, direction);
ensure_check_menu_item_widget();
gtk_widget_set_direction(gCheckMenuItemWidget, direction);
style = gtk_widget_get_style_context(gCheckMenuItemWidget);
gtk_style_context_save(style);
if (checked) {
state_flags = static_cast<GtkStateFlags>(state_flags|checkbox_check_state);
}
style = ClaimStyleContext(isradio ? MOZ_GTK_RADIOMENUITEM_CONTAINER :
MOZ_GTK_CHECKMENUITEM_CONTAINER,
direction);
gtk_style_context_get_style(style,
"indicator-size", &indicator_size,
"horizontal-padding", &horizontal_padding,
NULL);
ReleaseStyleContext(style);
if (isradio) {
gtk_style_context_add_class(style, GTK_STYLE_CLASS_RADIO);
} else {
gtk_style_context_add_class(style, GTK_STYLE_CLASS_CHECK);
}
if (checked) {
state_flags = static_cast<GtkStateFlags>(state_flags|checkbox_check_state);
}
gtk_style_context_set_state(style, state_flags);
style = ClaimStyleContext(isradio ? MOZ_GTK_RADIOMENUITEM :
MOZ_GTK_CHECKMENUITEM,
direction, state_flags);
gtk_style_context_get_padding(style, state_flags, &padding);
offset = gtk_container_get_border_width(GTK_CONTAINER(gCheckMenuItemWidget)) +
padding.left + 2;
offset = gtk_container_get_border_width(GTK_CONTAINER(
GetWidget(MOZ_GTK_CHECKMENUITEM_CONTAINER)));
offset += padding.left + 2;
if (direction == GTK_TEXT_DIR_RTL) {
x = rect->width - indicator_size - offset - horizontal_padding;
@ -2136,12 +2103,17 @@ moz_gtk_check_menu_item_paint(cairo_t *cr, GdkRectangle* rect,
}
y = rect->y + (rect->height - indicator_size) / 2;
if (gtk_check_version(3, 20, 0) == nullptr) {
gtk_render_background(style, cr, x, y, indicator_size, indicator_size);
gtk_render_frame(style, cr, x, y, indicator_size, indicator_size);
}
if (isradio) {
gtk_render_option(style, cr, x, y, indicator_size, indicator_size);
} else {
gtk_render_check(style, cr, x, y, indicator_size, indicator_size);
}
gtk_style_context_restore(style);
ReleaseStyleContext(style);
return MOZ_GTK_SUCCESS;
}
@ -2366,8 +2338,7 @@ moz_gtk_get_widget_border(WidgetNodeType widget, gint* left, gint* top,
// Bug 1274143 for MOZ_GTK_MENUBARITEM
w = GetWidget(MOZ_GTK_MENUITEM);
} else {
ensure_check_menu_item_widget();
w = gCheckMenuItemWidget;
w = GetWidget(MOZ_GTK_CHECKMENUITEM_CONTAINER);
}
*left = *top = *right = *bottom = gtk_container_get_border_width(GTK_CONTAINER(w));
@ -2676,8 +2647,7 @@ moz_gtk_images_in_menus()
gboolean result;
GtkSettings* settings;
ensure_image_menu_item_widget();
settings = gtk_widget_get_settings(gImageMenuItemWidget);
settings = gtk_widget_get_settings(GetWidget(MOZ_GTK_IMAGEMENUITEM));
g_object_get(settings, "gtk-menu-images", &result, NULL);
return result;
@ -2944,8 +2914,6 @@ moz_gtk_shutdown()
gComboBoxEntryArrowWidget = NULL;
gComboBoxEntryTextareaWidget = NULL;
gTabWidget = NULL;
gImageMenuItemWidget = NULL;
gCheckMenuItemWidget = NULL;
is_initialized = FALSE;

View File

@ -201,6 +201,9 @@ typedef enum {
MOZ_GTK_MENUBARITEM,
/* Paints items of popup menus. */
MOZ_GTK_MENUITEM,
MOZ_GTK_IMAGEMENUITEM,
MOZ_GTK_CHECKMENUITEM_CONTAINER,
MOZ_GTK_RADIOMENUITEM_CONTAINER,
MOZ_GTK_CHECKMENUITEM,
MOZ_GTK_RADIOMENUITEM,
MOZ_GTK_MENUSEPARATOR,

View File

@ -530,6 +530,7 @@ STUB(gtk_get_minor_version)
STUB(gtk_menu_button_new)
STUB(gtk_offscreen_window_new)
STUB(gtk_paned_new)
STUB(gtk_radio_menu_item_new)
STUB(gtk_render_activity)
STUB(gtk_render_arrow)
STUB(gtk_render_background)