[gtk+] notebook: Implement rtl flipping for CSS nodes



commit bb92428112b1b6ee4fae639e5190608c437c24b5
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jan 19 21:38:30 2016 -0500

    notebook: Implement rtl flipping for CSS nodes
    
    Use gtk_box_gadget_reverse_children and gtk_css_node_reverse_children
    to flip the children of the header_gadget and the tabs_gadget when
    appropriate.
    
    Add new CSS node tests to verify that the node order is updated
    as expected in all cases.

 gtk/gtknotebook.c                                  |   75 ++++++++------------
 testsuite/css/nodes/Makefile.am                    |   38 ++++++-----
 ...book.bottom.nodes => notebook.bottom.ltr.nodes} |    0
 .../{notebook.bottom.ui => notebook.bottom.ltr.ui} |    0
 ...book.bottom.nodes => notebook.bottom.rtl.nodes} |   16 ++--
 .../{notebook.bottom.ui => notebook.bottom.rtl.ui} |    0
 ...notebook.left.nodes => notebook.left.ltr.nodes} |    0
 .../{notebook.left.ui => notebook.left.ltr.ui}     |    0
 ...otebook.right.nodes => notebook.left.rtl.nodes} |   12 ++--
 .../{notebook.left.ui => notebook.left.rtl.ui}     |    0
 ...tebook.right.nodes => notebook.right.ltr.nodes} |    0
 .../{notebook.right.ui => notebook.right.ltr.ui}   |    0
 ...otebook.left.nodes => notebook.right.rtl.nodes} |   12 ++--
 .../{notebook.right.ui => notebook.right.rtl.ui}   |    0
 .../{notebook.top.nodes => notebook.top.ltr.nodes} |    0
 .../nodes/{notebook.top.ui => notebook.top.ltr.ui} |    0
 .../{notebook.top.nodes => notebook.top.rtl.nodes} |   16 ++--
 .../nodes/{notebook.top.ui => notebook.top.rtl.ui} |    0
 18 files changed, 80 insertions(+), 89 deletions(-)
---
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 8481d45..f175815 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -219,6 +219,7 @@ struct _GtkNotebookPrivate
   guint          show_tabs          : 1;
   guint          scrollable         : 1;
   guint          tab_pos            : 2;
+  guint          tabs_reversed      : 1;
 };
 
 enum {
@@ -1290,6 +1291,11 @@ gtk_notebook_init (GtkNotebook *notebook)
   priv->during_detach = FALSE;
   priv->has_scrolled = FALSE;
 
+  if (gtk_widget_get_direction (GTK_WIDGET (notebook)) == GTK_TEXT_DIR_RTL)
+    priv->tabs_reversed = TRUE;
+  else
+    priv->tabs_reversed = FALSE;
+
   gtk_drag_dest_set (GTK_WIDGET (notebook), 0,
                      notebook_targets, G_N_ELEMENTS (notebook_targets),
                      GDK_ACTION_MOVE);
@@ -1825,49 +1831,17 @@ static void
 update_node_ordering (GtkNotebook *notebook)
 {
   GtkNotebookPrivate *priv = notebook->priv;
-  GtkPositionType tab_pos;
-  gboolean is_rtl;
-  GtkCssNode *node, *header_node, *tabs_node;
+  gboolean reverse_tabs;
 
-  tab_pos = get_effective_tab_pos (notebook);
-  is_rtl = gtk_widget_get_direction (GTK_WIDGET (notebook)) == GTK_TEXT_DIR_RTL;
-  header_node = gtk_css_gadget_get_node (priv->header_gadget);
-  tabs_node = gtk_css_gadget_get_node (priv->tabs_gadget);
+  reverse_tabs = (priv->tab_pos == GTK_POS_TOP || priv->tab_pos == GTK_POS_BOTTOM) &&
+                 gtk_widget_get_direction (GTK_WIDGET (notebook)) == GTK_TEXT_DIR_RTL;
 
-  switch (tab_pos)
+  if ((reverse_tabs && !priv->tabs_reversed) ||
+      (!reverse_tabs && priv->tabs_reversed))
     {
-    case GTK_POS_TOP:
-    case GTK_POS_BOTTOM:
-      if (priv->action_widget[ACTION_WIDGET_START])
-        {
-          node = gtk_widget_get_css_node (priv->action_widget[ACTION_WIDGET_START]);
-          if (is_rtl)
-            gtk_css_node_insert_after (header_node, node, tabs_node);
-          else
-            gtk_css_node_insert_before (header_node, node, tabs_node);
-        }
-      if (priv->action_widget[ACTION_WIDGET_END])
-        {
-          node = gtk_widget_get_css_node (priv->action_widget[ACTION_WIDGET_END]);
-          if (is_rtl)
-            gtk_css_node_insert_before (header_node, node, tabs_node);
-          else
-            gtk_css_node_insert_after (header_node, node, tabs_node);
-        }
-      break;
-    case GTK_POS_LEFT:
-    case GTK_POS_RIGHT:
-      if (priv->action_widget[ACTION_WIDGET_START])
-        {
-          node = gtk_widget_get_css_node (priv->action_widget[ACTION_WIDGET_START]);
-          gtk_css_node_insert_before (header_node, node, tabs_node);
-        }
-      if (priv->action_widget[ACTION_WIDGET_END])
-        {
-          node = gtk_widget_get_css_node (priv->action_widget[ACTION_WIDGET_END]);
-          gtk_css_node_insert_after (header_node, node, tabs_node);
-        }
-      break;
+      gtk_box_gadget_reverse_children (GTK_BOX_GADGET (priv->header_gadget));
+      gtk_css_node_reverse_children (gtk_css_gadget_get_node (priv->tabs_gadget));
+      priv->tabs_reversed = reverse_tabs;
     }
 }
 
@@ -4767,6 +4741,9 @@ gtk_notebook_real_insert_page (GtkNotebook *notebook,
   else
     sibling = priv->arrow_gadget[ARROW_RIGHT_AFTER];
 
+  if (priv->tabs_reversed)
+    gtk_css_node_reverse_children (gtk_css_gadget_get_node (priv->tabs_gadget));
+
   page->gadget = gtk_css_custom_gadget_new ("tab",
                                             GTK_WIDGET (notebook),
                                             priv->tabs_gadget,
@@ -4776,6 +4753,9 @@ gtk_notebook_real_insert_page (GtkNotebook *notebook,
                                             draw_tab,
                                             page,
                                             NULL);
+  if (priv->tabs_reversed)
+    gtk_css_node_reverse_children (gtk_css_gadget_get_node (priv->tabs_gadget));
+
   gtk_css_gadget_set_state (page->gadget, gtk_css_node_get_state (gtk_css_gadget_get_node 
(priv->tabs_gadget)));
 
   if (!tab_label)
@@ -7050,6 +7030,8 @@ gtk_notebook_update_tab_pos (GtkNotebook *notebook)
       gtk_box_gadget_set_orientation (GTK_BOX_GADGET (priv->header_gadget), GTK_ORIENTATION_VERTICAL);
       break;
     }
+
+  update_node_ordering (notebook);
 }
 
 /**
@@ -8017,14 +7999,19 @@ gtk_notebook_set_action_widget (GtkNotebook *notebook,
 
   if (widget)
     {
+      int pos;
+
       gtk_css_node_set_parent (gtk_widget_get_css_node (widget),
                                gtk_css_gadget_get_node (priv->header_gadget));
-      gtk_box_gadget_insert_widget (GTK_BOX_GADGET (priv->header_gadget),
-                                    pack_type == GTK_PACK_START ? 0 : -1,
-                                    widget);
+
+      if (priv->tabs_reversed)
+        pos = pack_type == GTK_PACK_START ? -1 : 0;
+      else
+        pos = pack_type == GTK_PACK_START ? 0 : -1;
+
+      gtk_box_gadget_insert_widget (GTK_BOX_GADGET (priv->header_gadget), pos, widget);
       gtk_widget_set_child_visible (widget, priv->show_tabs);
       gtk_widget_set_parent (widget, GTK_WIDGET (notebook));
-      update_node_ordering (notebook);
     }
 
   gtk_widget_queue_resize (GTK_WIDGET (notebook));
diff --git a/testsuite/css/nodes/Makefile.am b/testsuite/css/nodes/Makefile.am
index c00eaef..10dcc27 100644
--- a/testsuite/css/nodes/Makefile.am
+++ b/testsuite/css/nodes/Makefile.am
@@ -28,23 +28,27 @@ test_css_nodes_SOURCES = \
        $(NULL)
 
 test_data = \
-       box.ltr.ui              box.ltr.nodes           \
-       box.rtl.ui              box.rtl.nodes           \
-       buttons.ui              buttons.nodes           \
-       checkbutton.ltr.ui      checkbutton.ltr.nodes   \
-       checkbutton.rtl.ui      checkbutton.rtl.nodes   \
-       entries.ui              entries.nodes           \
-       expander.ltr.ui         expander.ltr.nodes      \
-       expander.rtl.ui         expander.rtl.nodes      \
-       levelbar.ltr.ui         levelbar.ltr.nodes      \
-       levelbar.rtl.ui         levelbar.rtl.nodes      \
-       notebook.top.ui         notebook.top.nodes      \
-       notebook.left.ui        notebook.left.nodes     \
-       notebook.right.ui       notebook.right.nodes    \
-       notebook.bottom.ui      notebook.bottom.nodes   \
-       paned.ltr.ui            paned.ltr.nodes         \
-       paned.rtl.ui            paned.rtl.nodes         \
-       progressbar.ui          progressbar.nodes       \
+       box.ltr.ui              box.ltr.nodes                   \
+       box.rtl.ui              box.rtl.nodes                   \
+       buttons.ui              buttons.nodes                   \
+       checkbutton.ltr.ui      checkbutton.ltr.nodes           \
+       checkbutton.rtl.ui      checkbutton.rtl.nodes           \
+       entries.ui              entries.nodes                   \
+       expander.ltr.ui         expander.ltr.nodes              \
+       expander.rtl.ui         expander.rtl.nodes              \
+       levelbar.ltr.ui         levelbar.ltr.nodes              \
+       levelbar.rtl.ui         levelbar.rtl.nodes              \
+       notebook.top.ltr.ui     notebook.top.ltr.nodes          \
+       notebook.top.rtl.ui     notebook.top.rtl.nodes          \
+       notebook.left.ltr.ui    notebook.left.ltr.nodes         \
+       notebook.left.rtl.ui    notebook.left.rtl.nodes         \
+       notebook.right.ltr.ui   notebook.right.ltr.nodes        \
+       notebook.right.rtl.ui   notebook.right.rtl.nodes        \
+       notebook.bottom.ltr.ui  notebook.bottom.ltr.nodes       \
+       notebook.bottom.rtl.ui  notebook.bottom.rtl.nodes       \
+       paned.ltr.ui            paned.ltr.nodes                 \
+       paned.rtl.ui            paned.rtl.nodes                 \
+       progressbar.ui          progressbar.nodes               \
        $(NULL)
 
 EXTRA_DIST += $(test_in_files) $(test_data)
diff --git a/testsuite/css/nodes/notebook.bottom.nodes b/testsuite/css/nodes/notebook.bottom.ltr.nodes
similarity index 100%
copy from testsuite/css/nodes/notebook.bottom.nodes
copy to testsuite/css/nodes/notebook.bottom.ltr.nodes
diff --git a/testsuite/css/nodes/notebook.bottom.ui b/testsuite/css/nodes/notebook.bottom.ltr.ui
similarity index 100%
copy from testsuite/css/nodes/notebook.bottom.ui
copy to testsuite/css/nodes/notebook.bottom.ltr.ui
diff --git a/testsuite/css/nodes/notebook.bottom.nodes b/testsuite/css/nodes/notebook.bottom.rtl.nodes
similarity index 57%
rename from testsuite/css/nodes/notebook.bottom.nodes
rename to testsuite/css/nodes/notebook.bottom.rtl.nodes
index 0177d13..fdf8204 100644
--- a/testsuite/css/nodes/notebook.bottom.nodes
+++ b/testsuite/css/nodes/notebook.bottom.rtl.nodes
@@ -1,18 +1,18 @@
-[window.background:dir(ltr)]
+[window.background:dir(rtl)]
   decoration:dir(ltr)
-  notebook.frame:dir(ltr)
+  notebook.frame:dir(rtl)
     stack:dir(ltr)
-      button#page1.text-button:dir(ltr)
+      button#page1.text-button:dir(rtl)
         label:dir(ltr)
-      button#page2.text-button:dir(ltr)
+      button#page2.text-button:dir(rtl)
         label:dir(ltr)
     header.bottom:dir(ltr)
-      button#start.text-button:dir(ltr)
+      button#end.text-button:dir(rtl)
         label:dir(ltr)
       tabs:dir(ltr)
-        tab:active:dir(ltr)
-          label#tab1:dir(ltr)
         tab:dir(ltr)
           label#tab2:dir(ltr)
-      button#end.text-button:dir(ltr)
+        tab:active:dir(ltr)
+          label#tab1:dir(ltr)
+      button#start.text-button:dir(rtl)
         label:dir(ltr)
diff --git a/testsuite/css/nodes/notebook.bottom.ui b/testsuite/css/nodes/notebook.bottom.rtl.ui
similarity index 100%
rename from testsuite/css/nodes/notebook.bottom.ui
rename to testsuite/css/nodes/notebook.bottom.rtl.ui
diff --git a/testsuite/css/nodes/notebook.left.nodes b/testsuite/css/nodes/notebook.left.ltr.nodes
similarity index 100%
copy from testsuite/css/nodes/notebook.left.nodes
copy to testsuite/css/nodes/notebook.left.ltr.nodes
diff --git a/testsuite/css/nodes/notebook.left.ui b/testsuite/css/nodes/notebook.left.ltr.ui
similarity index 100%
copy from testsuite/css/nodes/notebook.left.ui
copy to testsuite/css/nodes/notebook.left.ltr.ui
diff --git a/testsuite/css/nodes/notebook.right.nodes b/testsuite/css/nodes/notebook.left.rtl.nodes
similarity index 57%
copy from testsuite/css/nodes/notebook.right.nodes
copy to testsuite/css/nodes/notebook.left.rtl.nodes
index 500331c..b1d4e2f 100644
--- a/testsuite/css/nodes/notebook.right.nodes
+++ b/testsuite/css/nodes/notebook.left.rtl.nodes
@@ -1,18 +1,18 @@
-[window.background:dir(ltr)]
+[window.background:dir(rtl)]
   decoration:dir(ltr)
-  notebook.frame:dir(ltr)
+  notebook.frame:dir(rtl)
     stack:dir(ltr)
-      button#page1.text-button:dir(ltr)
+      button#page1.text-button:dir(rtl)
         label:dir(ltr)
-      button#page2.text-button:dir(ltr)
+      button#page2.text-button:dir(rtl)
         label:dir(ltr)
     header.right:dir(ltr)
-      button#start.text-button:dir(ltr)
+      button#start.text-button:dir(rtl)
         label:dir(ltr)
       tabs:dir(ltr)
         tab:active:dir(ltr)
           label#tab1:dir(ltr)
         tab:dir(ltr)
           label#tab2:dir(ltr)
-      button#end.text-button:dir(ltr)
+      button#end.text-button:dir(rtl)
         label:dir(ltr)
diff --git a/testsuite/css/nodes/notebook.left.ui b/testsuite/css/nodes/notebook.left.rtl.ui
similarity index 100%
rename from testsuite/css/nodes/notebook.left.ui
rename to testsuite/css/nodes/notebook.left.rtl.ui
diff --git a/testsuite/css/nodes/notebook.right.nodes b/testsuite/css/nodes/notebook.right.ltr.nodes
similarity index 100%
rename from testsuite/css/nodes/notebook.right.nodes
rename to testsuite/css/nodes/notebook.right.ltr.nodes
diff --git a/testsuite/css/nodes/notebook.right.ui b/testsuite/css/nodes/notebook.right.ltr.ui
similarity index 100%
copy from testsuite/css/nodes/notebook.right.ui
copy to testsuite/css/nodes/notebook.right.ltr.ui
diff --git a/testsuite/css/nodes/notebook.left.nodes b/testsuite/css/nodes/notebook.right.rtl.nodes
similarity index 57%
rename from testsuite/css/nodes/notebook.left.nodes
rename to testsuite/css/nodes/notebook.right.rtl.nodes
index ad04ef9..fe9dd83 100644
--- a/testsuite/css/nodes/notebook.left.nodes
+++ b/testsuite/css/nodes/notebook.right.rtl.nodes
@@ -1,18 +1,18 @@
-[window.background:dir(ltr)]
+[window.background:dir(rtl)]
   decoration:dir(ltr)
-  notebook.frame:dir(ltr)
+  notebook.frame:dir(rtl)
     header.left:dir(ltr)
-      button#start.text-button:dir(ltr)
+      button#start.text-button:dir(rtl)
         label:dir(ltr)
       tabs:dir(ltr)
         tab:active:dir(ltr)
           label#tab1:dir(ltr)
         tab:dir(ltr)
           label#tab2:dir(ltr)
-      button#end.text-button:dir(ltr)
+      button#end.text-button:dir(rtl)
         label:dir(ltr)
     stack:dir(ltr)
-      button#page1.text-button:dir(ltr)
+      button#page1.text-button:dir(rtl)
         label:dir(ltr)
-      button#page2.text-button:dir(ltr)
+      button#page2.text-button:dir(rtl)
         label:dir(ltr)
diff --git a/testsuite/css/nodes/notebook.right.ui b/testsuite/css/nodes/notebook.right.rtl.ui
similarity index 100%
rename from testsuite/css/nodes/notebook.right.ui
rename to testsuite/css/nodes/notebook.right.rtl.ui
diff --git a/testsuite/css/nodes/notebook.top.nodes b/testsuite/css/nodes/notebook.top.ltr.nodes
similarity index 100%
copy from testsuite/css/nodes/notebook.top.nodes
copy to testsuite/css/nodes/notebook.top.ltr.nodes
diff --git a/testsuite/css/nodes/notebook.top.ui b/testsuite/css/nodes/notebook.top.ltr.ui
similarity index 100%
copy from testsuite/css/nodes/notebook.top.ui
copy to testsuite/css/nodes/notebook.top.ltr.ui
diff --git a/testsuite/css/nodes/notebook.top.nodes b/testsuite/css/nodes/notebook.top.rtl.nodes
similarity index 57%
rename from testsuite/css/nodes/notebook.top.nodes
rename to testsuite/css/nodes/notebook.top.rtl.nodes
index 6009264..4d46049 100644
--- a/testsuite/css/nodes/notebook.top.nodes
+++ b/testsuite/css/nodes/notebook.top.rtl.nodes
@@ -1,18 +1,18 @@
-[window.background:dir(ltr)]
+[window.background:dir(rtl)]
   decoration:dir(ltr)
-  notebook.frame:dir(ltr)
+  notebook.frame:dir(rtl)
     header.top:dir(ltr)
-      button#start.text-button:dir(ltr)
+      button#end.text-button:dir(rtl)
         label:dir(ltr)
       tabs:dir(ltr)
-        tab:active:dir(ltr)
-          label#tab1:dir(ltr)
         tab:dir(ltr)
           label#tab2:dir(ltr)
-      button#end.text-button:dir(ltr)
+        tab:active:dir(ltr)
+          label#tab1:dir(ltr)
+      button#start.text-button:dir(rtl)
         label:dir(ltr)
     stack:dir(ltr)
-      button#page1.text-button:dir(ltr)
+      button#page1.text-button:dir(rtl)
         label:dir(ltr)
-      button#page2.text-button:dir(ltr)
+      button#page2.text-button:dir(rtl)
         label:dir(ltr)
diff --git a/testsuite/css/nodes/notebook.top.ui b/testsuite/css/nodes/notebook.top.rtl.ui
similarity index 100%
rename from testsuite/css/nodes/notebook.top.ui
rename to testsuite/css/nodes/notebook.top.rtl.ui


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