[gtk+/wip/csd] window: Fix get_preferred_{width, height} to apply border correctly



commit b18569d261c4c68d04f008af5323eab91d59435f
Author: Rob Bradford <rob linux intel com>
Date:   Thu Jan 31 16:33:57 2013 +0000

    window: Fix get_preferred_{width,height} to apply border correctly
    
    This change tidies the code a bit to clarify what is happening and through
    inspection fixes a bug where the border width was sometimes being incorrectly
    applied.

 gtk/gtkwindow.c |  109 ++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 64 insertions(+), 45 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 9205247..b6ae702 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -6752,10 +6752,11 @@ gtk_window_get_preferred_width (GtkWidget *widget,
   priv = window->priv;
   child  = gtk_bin_get_child (GTK_BIN (window));
 
-  border_width =
-    2 * gtk_container_get_border_width (GTK_CONTAINER (window));
+  border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
 
-  if (priv->client_decorated && priv->type == GTK_WINDOW_TOPLEVEL)
+  if (priv->client_decorated &&
+      priv->decorated &&
+      priv->type == GTK_WINDOW_TOPLEVEL)
     {
       context = gtk_widget_get_style_context (widget);
       state = gtk_style_context_get_state (context);
@@ -6776,21 +6777,24 @@ gtk_window_get_preferred_width (GtkWidget *widget,
       gtk_style_context_get_border (context, state, &priv->window_border);
       gtk_style_context_restore (context);
 
-      border_width +=
-        priv->title_border.left + priv->title_border.right +
-        priv->window_border.left + priv->window_border.right;
+      title_min += border_width * 2 +
+                   priv->title_border.left + priv->title_border.right +
+                   priv->window_border.left + priv->window_border.right;
+      title_nat += border_width * 2 +
+                   priv->title_border.left + priv->title_border.right +
+                   priv->window_border.left + priv->window_border.right;
 
-      title_min += border_width;
-      title_nat += border_width;
     }
 
   if (child && gtk_widget_get_visible (child))
     {
       gtk_widget_get_preferred_width (child, &child_min, &child_nat);
-      child_min += border_width;
-      child_nat += border_width;
+      child_min += border_width * 2 +
+                   priv->window_border.left + priv->window_border.right;
+      child_nat += border_width * 2 +
+                   priv->window_border.left + priv->window_border.right;
     }
-  
+
   *minimum_size = MAX (title_min, child_min);
   *natural_size = MAX (title_nat, child_nat);
 }
@@ -6815,19 +6819,20 @@ gtk_window_get_preferred_width_for_height (GtkWidget *widget,
   priv = window->priv;
   child  = gtk_bin_get_child (GTK_BIN (window));
 
-  border_width =
-    2 * gtk_container_get_border_width (GTK_CONTAINER (window));
+  border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
 
-  if (priv->client_decorated && priv->type == GTK_WINDOW_TOPLEVEL)
+  if (priv->client_decorated &&
+      priv->decorated &&
+      priv->type == GTK_WINDOW_TOPLEVEL)
     {
       context = gtk_widget_get_style_context (widget);
       state = gtk_style_context_get_state (context);
 
       if (priv->title_box)
         {
-          gtk_widget_get_preferred_width_for_height (priv->title_box, height,
+          gtk_widget_get_preferred_width_for_height (priv->title_box,
+                                                     height,
                                                      &title_min, &title_nat);
-
           gtk_style_context_save (context);
           gtk_style_context_add_class (context, "titlebar");
           gtk_style_context_get_border (context, state, &priv->title_border);
@@ -6839,21 +6844,25 @@ gtk_window_get_preferred_width_for_height (GtkWidget *widget,
       gtk_style_context_get_border (context, state, &priv->window_border);
       gtk_style_context_restore (context);
 
-      border_width +=
-        priv->title_border.left + priv->title_border.right +
-        priv->window_border.left + priv->window_border.right;
+      title_min += border_width * 2 +
+                   priv->title_border.left + priv->title_border.right +
+                   priv->window_border.left + priv->window_border.right;
+      title_nat += border_width * 2 +
+                   priv->title_border.left + priv->title_border.right +
+                   priv->window_border.left + priv->window_border.right;
 
-      title_min += border_width;
-      title_nat += border_width;
     }
 
   if (child && gtk_widget_get_visible (child))
     {
-      gtk_widget_get_preferred_width_for_height (child, height, &child_min, &child_nat);
-      child_min += border_width;
-      child_nat += border_width;
+      gtk_widget_get_preferred_width_for_height (child, height,
+                                                 &child_min, &child_nat);
+      child_min += border_width * 2 +
+                   priv->window_border.left + priv->window_border.right;
+      child_nat += border_width * 2 +
+                   priv->window_border.left + priv->window_border.right;
     }
-  
+
   *minimum_size = MAX (title_min, child_min);
   *natural_size = MAX (title_nat, child_nat);
 }
@@ -6878,7 +6887,11 @@ gtk_window_get_preferred_height (GtkWidget *widget,
   *minimum_size = 0;
   *natural_size = 0;
 
-  if (priv->client_decorated && priv->type == GTK_WINDOW_TOPLEVEL)
+  border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
+
+  if (priv->client_decorated &&
+      priv->decorated &&
+      priv->type == GTK_WINDOW_TOPLEVEL)
     {
       context = gtk_widget_get_style_context (widget);
       state = gtk_style_context_get_state (context);
@@ -6899,13 +6912,13 @@ gtk_window_get_preferred_height (GtkWidget *widget,
       gtk_style_context_get_border (context, state, &priv->window_border);
       gtk_style_context_restore (context);
 
-      border_width =
-        2 * gtk_container_get_border_width (GTK_CONTAINER (window)) +
-        priv->title_border.top + priv->title_border.bottom +
-        priv->window_border.top + priv->window_border.bottom;
+      *minimum_size = title_min +
+                      priv->title_border.top + priv->title_border.bottom +
+                      priv->window_border.top + priv->window_border.bottom;
 
-      *minimum_size = border_width + title_min;
-      *natural_size = border_width + priv->title_height;
+      *natural_size = priv->title_height +
+                      priv->title_border.top + priv->title_border.bottom +
+                      priv->window_border.top + priv->window_border.bottom;
     }
 
   if (child && gtk_widget_get_visible (child))
@@ -6913,8 +6926,8 @@ gtk_window_get_preferred_height (GtkWidget *widget,
       gint child_min, child_nat;
       gtk_widget_get_preferred_height (child, &child_min, &child_nat);
 
-      *minimum_size += child_min;
-      *natural_size += child_nat;
+      *minimum_size += child_min + 2 * border_width;
+      *natural_size += child_nat + 2 * border_width;
     }
 }
 
@@ -6940,14 +6953,19 @@ gtk_window_get_preferred_height_for_width (GtkWidget *widget,
   *minimum_size = 0;
   *natural_size = 0;
 
-  if (priv->client_decorated && priv->type == GTK_WINDOW_TOPLEVEL)
+  border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
+
+  if (priv->client_decorated &&
+      priv->decorated &&
+      priv->type == GTK_WINDOW_TOPLEVEL)
     {
       context = gtk_widget_get_style_context (widget);
       state = gtk_style_context_get_state (context);
 
       if (priv->title_box)
         {
-          gtk_widget_get_preferred_height_for_width (priv->title_box, width,
+          gtk_widget_get_preferred_height_for_width (priv->title_box,
+                                                     width,
                                                      &title_min, &priv->title_height);
 
           gtk_style_context_save (context);
@@ -6961,22 +6979,23 @@ gtk_window_get_preferred_height_for_width (GtkWidget *widget,
       gtk_style_context_get_border (context, state, &priv->window_border);
       gtk_style_context_restore (context);
 
-      border_width =
-        2 * gtk_container_get_border_width (GTK_CONTAINER (window)) +
-        priv->title_border.top + priv->title_border.bottom +
-        priv->window_border.top + priv->window_border.bottom;
+      *minimum_size = title_min +
+                      priv->title_border.top + priv->title_border.bottom +
+                      priv->window_border.top + priv->window_border.bottom;
 
-      *minimum_size = border_width + title_min;
-      *natural_size = border_width + priv->title_height;
+      *natural_size = priv->title_height +
+                      priv->title_border.top + priv->title_border.bottom +
+                      priv->window_border.top + priv->window_border.bottom;
     }
 
   if (child && gtk_widget_get_visible (child))
     {
       gint child_min, child_nat;
-      gtk_widget_get_preferred_height_for_width (child, width, &child_min, &child_nat);
+      gtk_widget_get_preferred_height_for_width (child, width,
+                                                 &child_min, &child_nat);
 
-      *minimum_size += child_min;
-      *natural_size += child_nat;
+      *minimum_size += child_min + 2 * border_width;
+      *natural_size += child_nat + 2 * border_width;
     }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]