frame: make sure to allocate the CSS border width

Similar to GtkNotebook, GtkFrame was only allocating space for the
padding width, and not the border.

This could be seen by just running tests/testframe. With a theme that
renders frame borders, setting xthickness = 0 in the test draws the
button border over the frame border, which is wrong.

https://bugzilla.gnome.org/show_bug.cgi?id=664342
This commit is contained in:
Cosimo Cecchi 2011-11-18 11:58:56 -05:00
parent b9b01f99b6
commit 4626edb889

View File

@ -643,6 +643,30 @@ gtk_frame_get_shadow_type (GtkFrame *frame)
return frame->priv->shadow_type; return frame->priv->shadow_type;
} }
static void
get_padding_and_border (GtkFrame *frame,
GtkBorder *border)
{
GtkStyleContext *context;
GtkStateFlags state;
context = gtk_widget_get_style_context (GTK_WIDGET (frame));
state = gtk_widget_get_state_flags (GTK_WIDGET (frame));
gtk_style_context_get_padding (context, state, border);
if (frame->priv->shadow_type != GTK_SHADOW_NONE)
{
GtkBorder tmp;
gtk_style_context_get_border (context, state, &tmp);
border->top += tmp.top;
border->right += tmp.right;
border->bottom += tmp.bottom;
border->left += tmp.left;
}
}
static gboolean static gboolean
gtk_frame_draw (GtkWidget *widget, gtk_frame_draw (GtkWidget *widget,
cairo_t *cr) cairo_t *cr)
@ -650,7 +674,6 @@ gtk_frame_draw (GtkWidget *widget,
GtkFrame *frame; GtkFrame *frame;
GtkFramePrivate *priv; GtkFramePrivate *priv;
GtkStyleContext *context; GtkStyleContext *context;
GtkStateFlags state;
gint x, y, width, height; gint x, y, width, height;
GtkAllocation allocation; GtkAllocation allocation;
GtkBorder padding; GtkBorder padding;
@ -658,11 +681,9 @@ gtk_frame_draw (GtkWidget *widget,
frame = GTK_FRAME (widget); frame = GTK_FRAME (widget);
priv = frame->priv; priv = frame->priv;
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_allocation (widget, &allocation);
get_padding_and_border (frame, &padding);
gtk_style_context_get_padding (context, state, &padding); context = gtk_widget_get_style_context (widget);
x = priv->child_allocation.x - allocation.x - padding.left; x = priv->child_allocation.x - allocation.x - padding.left;
y = priv->child_allocation.y - allocation.y - padding.top; y = priv->child_allocation.y - allocation.y - padding.top;
@ -736,16 +757,11 @@ gtk_frame_size_allocate (GtkWidget *widget,
if (priv->label_widget && gtk_widget_get_visible (priv->label_widget)) if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
{ {
GtkStyleContext *context;
GtkStateFlags state;
GtkBorder padding; GtkBorder padding;
gint nat_width, width, height; gint nat_width, width, height;
gfloat xalign; gfloat xalign;
context = gtk_widget_get_style_context (widget); get_padding_and_border (frame, &padding);
state = gtk_widget_get_state_flags (widget);
gtk_style_context_get_padding (context, state, &padding);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
xalign = priv->label_xalign; xalign = priv->label_xalign;
@ -789,18 +805,12 @@ gtk_frame_real_compute_child_allocation (GtkFrame *frame,
GtkFramePrivate *priv = frame->priv; GtkFramePrivate *priv = frame->priv;
GtkWidget *widget = GTK_WIDGET (frame); GtkWidget *widget = GTK_WIDGET (frame);
GtkAllocation allocation; GtkAllocation allocation;
GtkStyleContext *context;
GtkStateFlags state;
GtkBorder padding; GtkBorder padding;
gint top_margin; gint top_margin;
guint border_width; guint border_width;
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
gtk_style_context_get_padding (context, state, &padding);
gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_allocation (widget, &allocation);
get_padding_and_border (frame, &padding);
border_width = gtk_container_get_border_width (GTK_CONTAINER (frame)); border_width = gtk_container_get_border_width (GTK_CONTAINER (frame));
if (priv->label_widget) if (priv->label_widget)
@ -842,8 +852,6 @@ gtk_frame_get_preferred_size (GtkWidget *request,
{ {
GtkFrame *frame = GTK_FRAME (request); GtkFrame *frame = GTK_FRAME (request);
GtkFramePrivate *priv = frame->priv; GtkFramePrivate *priv = frame->priv;
GtkStyleContext *context;
GtkStateFlags state;
GtkBorder padding; GtkBorder padding;
GtkWidget *widget = GTK_WIDGET (request); GtkWidget *widget = GTK_WIDGET (request);
GtkWidget *child; GtkWidget *child;
@ -852,11 +860,6 @@ gtk_frame_get_preferred_size (GtkWidget *request,
gint minimum, natural; gint minimum, natural;
guint border_width; guint border_width;
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
gtk_style_context_get_padding (context, state, &padding);
if (priv->label_widget && gtk_widget_get_visible (priv->label_widget)) if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
{ {
if (orientation == GTK_ORIENTATION_HORIZONTAL) if (orientation == GTK_ORIENTATION_HORIZONTAL)
@ -899,6 +902,7 @@ gtk_frame_get_preferred_size (GtkWidget *request,
} }
} }
get_padding_and_border (frame, &padding);
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
if (orientation == GTK_ORIENTATION_HORIZONTAL) if (orientation == GTK_ORIENTATION_HORIZONTAL)
@ -947,19 +951,14 @@ gtk_frame_get_preferred_height_for_width (GtkWidget *request,
GtkFrame *frame = GTK_FRAME (widget); GtkFrame *frame = GTK_FRAME (widget);
GtkFramePrivate *priv = frame->priv; GtkFramePrivate *priv = frame->priv;
GtkBin *bin = GTK_BIN (widget); GtkBin *bin = GTK_BIN (widget);
GtkStyleContext *context;
GtkStateFlags state;
GtkBorder padding; GtkBorder padding;
gint child_min, child_nat, label_width; gint child_min, child_nat, label_width;
gint minimum, natural; gint minimum, natural;
guint border_width; guint border_width;
context = gtk_widget_get_style_context (widget); get_padding_and_border (frame, &padding);
state = gtk_widget_get_state_flags (widget);
gtk_style_context_get_padding (context, state, &padding);
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
minimum = (border_width * 2) + padding.top + padding.bottom; minimum = (border_width * 2) + padding.top + padding.bottom;
natural = (border_width * 2) + padding.top + padding.bottom; natural = (border_width * 2) + padding.top + padding.bottom;