GtkLabel: Rely on the new pango support for context change tracking

Now that Pango tracks changes to the context automatically there is
no need to do it manually in e.g. style-updated or direction-changed,
in fact the only case we have to care about is when we re-create
the PangoContext due to a screen change, so we only have to clear
the layouts in GtkLabel in screen-changed.

This means we're not clearing all the layouts whenever the state changes,
which happens to every widget when the window is unfocused, which helps
performance a lot.

https://bugzilla.gnome.org/show_bug.cgi?id=340066
This commit is contained in:
Alexander Larsson 2012-12-05 14:51:23 +01:00
parent 53e08b58aa
commit bf35c2f044
2 changed files with 9 additions and 43 deletions

View File

@ -384,9 +384,6 @@ static void gtk_label_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gtk_label_state_flags_changed (GtkWidget *widget,
GtkStateFlags prev_state);
static void gtk_label_style_updated (GtkWidget *widget);
static void gtk_label_direction_changed (GtkWidget *widget,
GtkTextDirection previous_dir);
static gint gtk_label_draw (GtkWidget *widget,
cairo_t *cr);
static gboolean gtk_label_focus (GtkWidget *widget,
@ -566,9 +563,7 @@ gtk_label_class_init (GtkLabelClass *class)
widget_class->destroy = gtk_label_destroy;
widget_class->size_allocate = gtk_label_size_allocate;
widget_class->state_flags_changed = gtk_label_state_flags_changed;
widget_class->style_updated = gtk_label_style_updated;
widget_class->query_tooltip = gtk_label_query_tooltip;
widget_class->direction_changed = gtk_label_direction_changed;
widget_class->draw = gtk_label_draw;
widget_class->realize = gtk_label_realize;
widget_class->unrealize = gtk_label_unrealize;
@ -1852,6 +1847,9 @@ gtk_label_screen_changed (GtkWidget *widget,
GtkSettings *settings;
gboolean shortcuts_connected;
/* The PangoContext is replaced when the screen changes, so clear the layouts */
gtk_label_clear_layout (GTK_LABEL (widget));
if (!gtk_widget_has_screen (widget))
return;
@ -3811,37 +3809,10 @@ gtk_label_state_flags_changed (GtkWidget *widget,
gtk_label_update_cursor (label);
}
/* We have to clear the layout, fonts etc. may have changed */
gtk_label_clear_layout (label);
if (GTK_WIDGET_CLASS (gtk_label_parent_class)->state_flags_changed)
GTK_WIDGET_CLASS (gtk_label_parent_class)->state_flags_changed (widget, prev_state);
}
static void
gtk_label_style_updated (GtkWidget *widget)
{
GtkLabel *label = GTK_LABEL (widget);
GTK_WIDGET_CLASS (gtk_label_parent_class)->style_updated (widget);
/* We have to clear the layout, fonts etc. may have changed */
gtk_label_clear_layout (label);
}
static void
gtk_label_direction_changed (GtkWidget *widget,
GtkTextDirection previous_dir)
{
GtkLabel *label = GTK_LABEL (widget);
GtkLabelPrivate *priv = label->priv;
if (priv->layout)
pango_layout_context_changed (priv->layout);
GTK_WIDGET_CLASS (gtk_label_parent_class)->direction_changed (widget, previous_dir);
}
static void
get_layout_location (GtkLabel *label,
gint *xp,

View File

@ -8705,12 +8705,8 @@ gtk_widget_peek_pango_context (GtkWidget *widget)
* by gtk_widget_create_pango_context(), this context is owned by
* the widget (it can be used until the screen for the widget changes
* or the widget is removed from its toplevel), and will be updated to
* match any changes to the widget's attributes.
*
* If you create and keep a #PangoLayout using this context, you must
* deal with changes to the context by calling pango_layout_context_changed()
* on the layout in response to the #GtkWidget::style-updated and
* #GtkWidget::direction-changed signals for the widget.
* match any changes to the widget's attributes. This can be tracked
* by using the #GtkWidget::screen-changed signal on the widget.
*
* Return value: (transfer none): the #PangoContext for the widget.
**/
@ -8821,11 +8817,10 @@ gtk_widget_create_pango_context (GtkWidget *widget)
* font description, and base direction for drawing text for
* this widget.
*
* If you keep a #PangoLayout created in this way around, in order to
* notify the layout of changes to the base direction or font of this
* widget, you must call pango_layout_context_changed() in response to
* the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
* for the widget.
* If you keep a #PangoLayout created in this way around, you need
* to re-create it when the widget #PangoContext is replaced.
* This can be tracked by using the #GtkWidget::screen-changed signal
* on the widget.
*
* Return value: (transfer full): the new #PangoLayout
**/