Compare commits

...

3 Commits

Author SHA1 Message Date
Jasper St. Pierre
cbf6545ef2 wip state changes 2014-11-24 19:40:25 -08:00
Jasper St. Pierre
8c17c90a82 gtkentry: Pass the correct set of state flags to gtk_style_context_get*
This eliminates a lot of overhead in the CSS engine recalculating
cached CSS rules, and is overall the correct thing to do.
2014-11-24 17:10:53 -08:00
Jasper St. Pierre
8d2671d00e gtkwidget: Remove unnecessary code in get_state_flags
Any time has_focus is called, we will call gtk_widget_update_state_flags
which will assign the state flags properly.
2014-11-24 17:10:52 -08:00
7 changed files with 71 additions and 62 deletions

View File

@@ -616,11 +616,13 @@ static gboolean
set_color_from_context (GtkStyle *style, set_color_from_context (GtkStyle *style,
GtkStateType state, GtkStateType state,
GtkStyleContext *context, GtkStyleContext *context,
GtkStateFlags flags,
GtkRcFlags prop) GtkRcFlags prop)
{ {
GdkRGBA *color = NULL; GdkRGBA *color = NULL;
GdkColor *dest = { 0 }; /* Shut up gcc */ GdkColor *dest = { 0 }; /* Shut up gcc */
GtkStateFlags flags;
flags = gtk_style_context_get_state (context);
switch (prop) switch (prop)
{ {
@@ -674,26 +676,6 @@ set_color (GtkStyle *style,
GtkStateType state, GtkStateType state,
GtkRcFlags prop) GtkRcFlags prop)
{ {
GtkStateFlags flags;
switch (state)
{
case GTK_STATE_ACTIVE:
flags = GTK_STATE_FLAG_ACTIVE;
break;
case GTK_STATE_PRELIGHT:
flags = GTK_STATE_FLAG_PRELIGHT;
break;
case GTK_STATE_SELECTED:
flags = GTK_STATE_FLAG_SELECTED;
break;
case GTK_STATE_INSENSITIVE:
flags = GTK_STATE_FLAG_INSENSITIVE;
break;
default:
flags = 0;
}
/* Try to fill in the values from the associated GtkStyleContext. /* Try to fill in the values from the associated GtkStyleContext.
* Since fully-transparent black is a very common default (e.g. for * Since fully-transparent black is a very common default (e.g. for
* background-color properties), and we must store the result in a GdkColor * background-color properties), and we must store the result in a GdkColor
@@ -701,11 +683,11 @@ set_color (GtkStyle *style,
* we give themes a fallback style class they can style, before using the * we give themes a fallback style class they can style, before using the
* hardcoded default values. * hardcoded default values.
*/ */
if (!set_color_from_context (style, state, context, flags, prop)) if (!set_color_from_context (style, state, context, prop))
{ {
gtk_style_context_save (context); gtk_style_context_save (context);
gtk_style_context_add_class (context, "gtkstyle-fallback"); gtk_style_context_add_class (context, "gtkstyle-fallback");
set_color_from_context (style, state, context, flags, prop); set_color_from_context (style, state, context, prop);
gtk_style_context_restore (context); gtk_style_context_restore (context);
} }
} }
@@ -715,6 +697,7 @@ gtk_style_update_from_context (GtkStyle *style)
{ {
GtkStylePrivate *priv; GtkStylePrivate *priv;
GtkStateType state; GtkStateType state;
GtkStateFlags flags;
GtkBorder padding; GtkBorder padding;
gint i; gint i;
@@ -722,6 +705,27 @@ gtk_style_update_from_context (GtkStyle *style)
for (state = GTK_STATE_NORMAL; state <= GTK_STATE_INSENSITIVE; state++) for (state = GTK_STATE_NORMAL; state <= GTK_STATE_INSENSITIVE; state++)
{ {
switch (state)
{
case GTK_STATE_ACTIVE:
flags = GTK_STATE_FLAG_ACTIVE;
break;
case GTK_STATE_PRELIGHT:
flags = GTK_STATE_FLAG_PRELIGHT;
break;
case GTK_STATE_SELECTED:
flags = GTK_STATE_FLAG_SELECTED;
break;
case GTK_STATE_INSENSITIVE:
flags = GTK_STATE_FLAG_INSENSITIVE;
break;
default:
flags = 0;
}
gtk_style_context_save (priv->context);
gtk_style_context_set_state (priv->context, flags);
if (gtk_style_context_has_class (priv->context, "entry")) if (gtk_style_context_has_class (priv->context, "entry"))
{ {
gtk_style_context_save (priv->context); gtk_style_context_save (priv->context);
@@ -744,15 +748,18 @@ gtk_style_update_from_context (GtkStyle *style)
set_color (style, priv->context, state, GTK_RC_BG); set_color (style, priv->context, state, GTK_RC_BG);
set_color (style, priv->context, state, GTK_RC_FG); set_color (style, priv->context, state, GTK_RC_FG);
} }
gtk_style_context_restore (priv->context);
} }
if (style->font_desc) if (style->font_desc)
pango_font_description_free (style->font_desc); pango_font_description_free (style->font_desc);
gtk_style_context_get (priv->context, 0, flags = gtk_style_context_get_state (priv->context);
gtk_style_context_get (priv->context, flags,
"font", &style->font_desc, "font", &style->font_desc,
NULL); NULL);
gtk_style_context_get_padding (priv->context, 0, &padding); gtk_style_context_get_padding (priv->context, flags, &padding);
style->xthickness = padding.left; style->xthickness = padding.left;
style->ythickness = padding.top; style->ythickness = padding.top;

View File

@@ -3561,7 +3561,7 @@ gtk_cell_area_inner_cell_area (GtkCellArea *area,
g_return_if_fail (inner_area != NULL); g_return_if_fail (inner_area != NULL);
context = gtk_widget_get_style_context (widget); context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget); state = gtk_style_context_get_state (context);
gtk_style_context_get_padding (context, state, &border); gtk_style_context_get_padding (context, state, &border);
*inner_area = *cell_area; *inner_area = *cell_area;
@@ -3611,7 +3611,7 @@ gtk_cell_area_request_renderer (GtkCellArea *area,
g_return_if_fail (natural_size != NULL); g_return_if_fail (natural_size != NULL);
context = gtk_widget_get_style_context (widget); context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget); state = gtk_style_context_get_state (context);
gtk_style_context_get_padding (context, state, &border); gtk_style_context_get_padding (context, state, &border);
if (orientation == GTK_ORIENTATION_HORIZONTAL) if (orientation == GTK_ORIENTATION_HORIZONTAL)

View File

@@ -2834,13 +2834,15 @@ get_icon_width (GtkEntry *entry,
GtkStyleContext *context; GtkStyleContext *context;
GtkBorder padding; GtkBorder padding;
gint width; gint width;
GtkStateFlags state;
if (!icon_info) if (!icon_info)
return 0; return 0;
context = gtk_widget_get_style_context (GTK_WIDGET (entry)); context = gtk_widget_get_style_context (GTK_WIDGET (entry));
state = gtk_style_context_get_state (context);
gtk_entry_prepare_context_for_icon (entry, context, icon_pos); gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
gtk_style_context_get_padding (context, 0, &padding); gtk_style_context_get_padding (context, state, &padding);
_gtk_icon_helper_get_size (icon_info->icon_helper, context, _gtk_icon_helper_get_size (icon_info->icon_helper, context,
&width, NULL); &width, NULL);
@@ -3406,19 +3408,17 @@ _gtk_entry_get_borders (GtkEntry *entry,
GtkWidget *widget = GTK_WIDGET (entry); GtkWidget *widget = GTK_WIDGET (entry);
GtkBorder padding, border; GtkBorder padding, border;
GtkStyleContext *context; GtkStyleContext *context;
GtkStateFlags state;
context = gtk_widget_get_style_context (widget); context = gtk_widget_get_style_context (widget);
state = gtk_style_context_get_state (context);
gtk_style_context_get_padding (context, state, &padding);
gtk_style_context_get_border (context, state, &border);
gtk_style_context_get_padding (context, 0, &padding); border_out->top = padding.top + border.top;
gtk_style_context_get_border (context, 0, &border); border_out->bottom = padding.bottom + border.bottom;
border_out->left = padding.left + border.left;
if (border_out != NULL) border_out->right = padding.right + border.right;
{
border_out->top = padding.top + border.top;
border_out->bottom = padding.bottom + border.bottom;
border_out->left = padding.left + border.left;
border_out->right = padding.right + border.right;
}
} }
static void static void
@@ -3770,6 +3770,7 @@ draw_icon (GtkWidget *widget,
gint x, y, width, height, pix_width, pix_height; gint x, y, width, height, pix_width, pix_height;
GtkStyleContext *context; GtkStyleContext *context;
GtkBorder padding; GtkBorder padding;
GtkStateFlags state;
if (!icon_info) if (!icon_info)
return; return;
@@ -3789,7 +3790,8 @@ draw_icon (GtkWidget *widget,
gtk_entry_prepare_context_for_icon (entry, context, icon_pos); gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
_gtk_icon_helper_get_size (icon_info->icon_helper, context, _gtk_icon_helper_get_size (icon_info->icon_helper, context,
&pix_width, &pix_height); &pix_width, &pix_height);
gtk_style_context_get_padding (context, 0, &padding); state = gtk_style_context_get_state (context);
gtk_style_context_get_padding (context, state, &padding);
x = MAX (0, padding.left); x = MAX (0, padding.left);
y = MAX (0, (height - pix_height) / 2); y = MAX (0, (height - pix_height) / 2);
@@ -3866,6 +3868,7 @@ get_progress_area (GtkWidget *widget,
GtkStyleContext *context; GtkStyleContext *context;
GtkBorder margin, border, entry_borders; GtkBorder margin, border, entry_borders;
gint frame_width, text_area_width, text_area_height; gint frame_width, text_area_width, text_area_height;
GtkStateFlags state;
context = gtk_widget_get_style_context (widget); context = gtk_widget_get_style_context (widget);
_gtk_entry_get_borders (entry, &entry_borders); _gtk_entry_get_borders (entry, &entry_borders);
@@ -3881,13 +3884,15 @@ get_progress_area (GtkWidget *widget,
*width = text_area_width + entry_borders.left + entry_borders.right; *width = text_area_width + entry_borders.left + entry_borders.right;
*height = text_area_height + entry_borders.top + entry_borders.bottom; *height = text_area_height + entry_borders.top + entry_borders.bottom;
state = gtk_style_context_get_state (context);
/* if the text area got resized by a subclass, subtract the left/right /* if the text area got resized by a subclass, subtract the left/right
* border width, so that the progress bar won't extend over the resized * border width, so that the progress bar won't extend over the resized
* text area. * text area.
*/ */
if (frame_width > *width) if (frame_width > *width)
{ {
gtk_style_context_get_border (context, 0, &border); gtk_style_context_get_border (context, state, &border);
if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL) if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
{ {
*x = (frame_width - *width) + border.left; *x = (frame_width - *width) + border.left;
@@ -3900,7 +3905,7 @@ get_progress_area (GtkWidget *widget,
} }
gtk_entry_prepare_context_for_progress (entry, context); gtk_entry_prepare_context_for_progress (entry, context);
gtk_style_context_get_margin (context, 0, &margin); gtk_style_context_get_margin (context, state, &margin);
gtk_style_context_restore (context); gtk_style_context_restore (context);
@@ -9932,9 +9937,11 @@ gtk_entry_drag_motion (GtkWidget *widget,
gint new_position, old_position; gint new_position, old_position;
gint sel1, sel2; gint sel1, sel2;
GtkBorder padding; GtkBorder padding;
GtkStateFlags state;
style_context = gtk_widget_get_style_context (widget); style_context = gtk_widget_get_style_context (widget);
gtk_style_context_get_padding (style_context, 0, &padding); state = gtk_style_context_get_state (style_context);
gtk_style_context_get_padding (style_context, state, &padding);
x -= padding.left; x -= padding.left;
y -= padding.top; y -= padding.top;
@@ -10007,11 +10014,13 @@ gtk_entry_drag_data_received (GtkWidget *widget,
GtkStyleContext *style_context; GtkStyleContext *style_context;
GtkBorder padding; GtkBorder padding;
gchar *str; gchar *str;
GtkStateFlags state;
str = (gchar *) gtk_selection_data_get_text (selection_data); str = (gchar *) gtk_selection_data_get_text (selection_data);
style_context = gtk_widget_get_style_context (widget); style_context = gtk_widget_get_style_context (widget);
gtk_style_context_get_padding (style_context, 0, &padding); state = gtk_style_context_get_state (style_context);
gtk_style_context_get_padding (style_context, state, &padding);
x -= padding.left; x -= padding.left;
y -= padding.top; y -= padding.top;

View File

@@ -2240,15 +2240,17 @@ get_padding_and_border (GtkNotebook *notebook,
GtkBorder *border) GtkBorder *border)
{ {
GtkStyleContext *context; GtkStyleContext *context;
GtkStateFlags state;
context = gtk_widget_get_style_context (GTK_WIDGET (notebook)); context = gtk_widget_get_style_context (GTK_WIDGET (notebook));
gtk_style_context_get_padding (context, 0, border); state = gtk_style_context_get_state (context);
gtk_style_context_get_padding (context, state, border);
if (notebook->priv->show_border || notebook->priv->show_tabs) if (notebook->priv->show_border || notebook->priv->show_tabs)
{ {
GtkBorder tmp; GtkBorder tmp;
gtk_style_context_get_border (context, 0, &tmp); gtk_style_context_get_border (context, state, &tmp);
border->top += tmp.top; border->top += tmp.top;
border->right += tmp.right; border->right += tmp.right;
border->bottom += tmp.bottom; border->bottom += tmp.bottom;
@@ -6247,7 +6249,7 @@ gtk_notebook_calculate_tabs_allocation (GtkNotebook *notebook,
if (page != priv->cur_page) if (page != priv->cur_page)
{ {
GtkBorder active_padding, normal_padding, padding; GtkBorder padding = {};
/* The active tab is by definition at least the same height as the inactive one. /* The active tab is by definition at least the same height as the inactive one.
* The padding we're building is the offset between the two tab states, * The padding we're building is the offset between the two tab states,
@@ -6259,16 +6261,11 @@ gtk_notebook_calculate_tabs_allocation (GtkNotebook *notebook,
gtk_style_context_save (context); gtk_style_context_save (context);
notebook_tab_prepare_style_context (notebook, page, context, TRUE); notebook_tab_prepare_style_context (notebook, page, context, TRUE);
gtk_style_context_get_padding (context, GTK_STATE_FLAG_ACTIVE, &active_padding); /* gtk_style_context_get_padding (context, GTK_STATE_FLAG_ACTIVE, &active_padding); */
gtk_style_context_get_padding (context, GTK_STATE_FLAG_NORMAL, &normal_padding); /* gtk_style_context_get_padding (context, GTK_STATE_FLAG_NORMAL, &normal_padding); */
gtk_style_context_restore (context); gtk_style_context_restore (context);
padding.top = MAX (0, active_padding.top - normal_padding.top);
padding.right = MAX (0, active_padding.right - normal_padding.right);
padding.bottom = MAX (0, active_padding.bottom - normal_padding.bottom);
padding.left = MAX (0, active_padding.left - normal_padding.left);
switch (tab_pos) switch (tab_pos)
{ {
case GTK_POS_TOP: case GTK_POS_TOP:

View File

@@ -745,6 +745,8 @@ style_values_lookup_for_state (GtkStyleContext *context,
if (gtk_css_node_declaration_get_state (context->priv->info->decl) == state) if (gtk_css_node_declaration_get_state (context->priv->info->decl) == state)
return g_object_ref (style_values_lookup (context)); return g_object_ref (style_values_lookup (context));
g_warning ("State does not match current state");
decl = gtk_css_node_declaration_ref (context->priv->info->decl); decl = gtk_css_node_declaration_ref (context->priv->info->decl);
gtk_css_node_declaration_set_state (&decl, state); gtk_css_node_declaration_set_state (&decl, state);
values = _gtk_css_computed_values_new (); values = _gtk_css_computed_values_new ();

View File

@@ -8857,16 +8857,9 @@ gtk_widget_unset_state_flags (GtkWidget *widget,
GtkStateFlags GtkStateFlags
gtk_widget_get_state_flags (GtkWidget *widget) gtk_widget_get_state_flags (GtkWidget *widget)
{ {
GtkStateFlags flags;
g_return_val_if_fail (GTK_IS_WIDGET (widget), 0); g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
flags = widget->priv->state_flags; return widget->priv->state_flags;
if (gtk_widget_has_focus (widget))
flags |= GTK_STATE_FLAG_FOCUSED;
return flags;
} }
/** /**

View File

@@ -6431,13 +6431,14 @@ get_shadow_width (GtkWidget *widget,
else else
s = state | GTK_STATE_FLAG_BACKDROP; s = state | GTK_STATE_FLAG_BACKDROP;
gtk_style_context_set_state (context, s);
/* Always sum border + padding */ /* Always sum border + padding */
gtk_style_context_get_border (context, s, &border); gtk_style_context_get_border (context, s, &border);
gtk_style_context_get_padding (context, s, &d); gtk_style_context_get_padding (context, s, &d);
sum_borders (&d, &border); sum_borders (&d, &border);
/* Calculate the size of the drop shadows ... */ /* Calculate the size of the drop shadows ... */
gtk_style_context_set_state (context, s);
shadows = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BOX_SHADOW); shadows = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BOX_SHADOW);
_gtk_css_shadows_value_get_extents (shadows, &border); _gtk_css_shadows_value_get_extents (shadows, &border);