[gtk+/wip/otte/rendernode: 90/100] menu: Implement snapshot() for the menu code



commit 150474c67cbfdca973ec7b3a17bdb93f38efa503
Author: Benjamin Otte <otte redhat com>
Date:   Sat Dec 17 20:46:25 2016 +0100

    menu: Implement snapshot() for the menu code

 gtk/gtkcheckmenuitem.c |   34 ++++++++++++++++------------------
 gtk/gtkcheckmenuitem.h |    6 +++---
 gtk/gtkmenu.c          |   40 +++++++++++++++++++++-------------------
 gtk/gtkmenubar.c       |   24 +++++++++++-------------
 gtk/gtkmenuitem.c      |   20 +++++++++-----------
 gtk/gtkmodelmenuitem.c |    8 ++++----
 6 files changed, 64 insertions(+), 68 deletions(-)
---
diff --git a/gtk/gtkcheckmenuitem.c b/gtk/gtkcheckmenuitem.c
index c45084e..ae5938f 100644
--- a/gtk/gtkcheckmenuitem.c
+++ b/gtk/gtkcheckmenuitem.c
@@ -84,13 +84,13 @@ enum {
   PROP_DRAW_AS_RADIO
 };
 
-static gint gtk_check_menu_item_draw                 (GtkWidget             *widget,
-                                                      cairo_t               *cr);
+static void gtk_check_menu_item_snapshot             (GtkWidget             *widget,
+                                                      GtkSnapshot           *snapshot);
 static void gtk_check_menu_item_activate             (GtkMenuItem           *menu_item);
 static void gtk_check_menu_item_toggle_size_request  (GtkMenuItem           *menu_item,
                                                       gint                  *requisition);
-static void gtk_real_check_menu_item_draw_indicator  (GtkCheckMenuItem      *check_menu_item,
-                                                      cairo_t               *cr);
+static void gtk_real_check_menu_item_snapshot_indicator (GtkCheckMenuItem   *check_menu_item,
+                                                      GtkSnapshot           *snapshot);
 static void gtk_check_menu_item_set_property         (GObject               *object,
                                                       guint                  prop_id,
                                                       const GValue          *value,
@@ -213,14 +213,14 @@ gtk_check_menu_item_class_init (GtkCheckMenuItemClass *klass)
                                                          FALSE,
                                                          GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
 
-  widget_class->draw = gtk_check_menu_item_draw;
+  widget_class->snapshot = gtk_check_menu_item_snapshot;
 
   menu_item_class->activate = gtk_check_menu_item_activate;
   menu_item_class->hide_on_activate = FALSE;
   menu_item_class->toggle_size_request = gtk_check_menu_item_toggle_size_request;
   
   klass->toggled = NULL;
-  klass->draw_indicator = gtk_real_check_menu_item_draw_indicator;
+  klass->snapshot_indicator = gtk_real_check_menu_item_snapshot_indicator;
 
   /**
    * GtkCheckMenuItem::toggled:
@@ -501,19 +501,17 @@ gtk_check_menu_item_init (GtkCheckMenuItem *check_menu_item)
   update_node_state (check_menu_item);
 }
 
-static gint
-gtk_check_menu_item_draw (GtkWidget *widget,
-                          cairo_t   *cr)
+static void
+gtk_check_menu_item_snapshot (GtkWidget   *widget,
+                              GtkSnapshot *snapshot)
 {
   GtkCheckMenuItem *check_menu_item = GTK_CHECK_MENU_ITEM (widget);
 
-  if (GTK_WIDGET_CLASS (gtk_check_menu_item_parent_class)->draw)
-    GTK_WIDGET_CLASS (gtk_check_menu_item_parent_class)->draw (widget, cr);
-
-  if (GTK_CHECK_MENU_ITEM_GET_CLASS (check_menu_item)->draw_indicator)
-    GTK_CHECK_MENU_ITEM_GET_CLASS (check_menu_item)->draw_indicator (check_menu_item, cr);
+  if (GTK_WIDGET_CLASS (gtk_check_menu_item_parent_class)->snapshot)
+    GTK_WIDGET_CLASS (gtk_check_menu_item_parent_class)->snapshot (widget, snapshot);
 
-  return FALSE;
+  if (GTK_CHECK_MENU_ITEM_GET_CLASS (check_menu_item)->snapshot_indicator)
+    GTK_CHECK_MENU_ITEM_GET_CLASS (check_menu_item)->snapshot_indicator (check_menu_item, snapshot);
 }
 
 static void
@@ -581,10 +579,10 @@ gtk_check_menu_item_direction_changed (GtkWidget        *widget,
 }
 
 static void
-gtk_real_check_menu_item_draw_indicator (GtkCheckMenuItem *check_menu_item,
-                                         cairo_t          *cr)
+gtk_real_check_menu_item_snapshot_indicator (GtkCheckMenuItem *check_menu_item,
+                                             GtkSnapshot      *snapshot)
 {
-  gtk_css_gadget_draw (check_menu_item->priv->indicator_gadget, cr);
+  gtk_css_gadget_snapshot (check_menu_item->priv->indicator_gadget, snapshot);
 }
 
 static void
diff --git a/gtk/gtkcheckmenuitem.h b/gtk/gtkcheckmenuitem.h
index be1af00..8e21004 100644
--- a/gtk/gtkcheckmenuitem.h
+++ b/gtk/gtkcheckmenuitem.h
@@ -67,9 +67,9 @@ struct _GtkCheckMenuItemClass
 
   /*< public >*/
 
-  void (* toggled)       (GtkCheckMenuItem *check_menu_item);
-  void (* draw_indicator) (GtkCheckMenuItem *check_menu_item,
-                          cairo_t          *cr);
+  void (* toggled)             (GtkCheckMenuItem *check_menu_item);
+  void (* snapshot_indicator)   (GtkCheckMenuItem *check_menu_item,
+                                GtkSnapshot      *snapshot);
 
   /*< private >*/
 
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index 256f5b7..e1b3ec1 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -234,8 +234,8 @@ static void     gtk_menu_unrealize         (GtkWidget        *widget);
 static void     gtk_menu_size_allocate     (GtkWidget        *widget,
                                             GtkAllocation    *allocation);
 static void     gtk_menu_show              (GtkWidget        *widget);
-static gboolean gtk_menu_draw              (GtkWidget        *widget,
-                                            cairo_t          *cr);
+static void     gtk_menu_snapshot          (GtkWidget        *widget,
+                                            GtkSnapshot      *snapshot);
 static gboolean gtk_menu_key_press         (GtkWidget        *widget,
                                             GdkEventKey      *event);
 static gboolean gtk_menu_scroll            (GtkWidget        *widget,
@@ -515,7 +515,7 @@ gtk_menu_class_init (GtkMenuClass *class)
   widget_class->unrealize = gtk_menu_unrealize;
   widget_class->size_allocate = gtk_menu_size_allocate;
   widget_class->show = gtk_menu_show;
-  widget_class->draw = gtk_menu_draw;
+  widget_class->snapshot = gtk_menu_snapshot;
   widget_class->scroll_event = gtk_menu_scroll;
   widget_class->key_press_event = gtk_menu_key_press;
   widget_class->motion_notify_event = gtk_menu_motion_notify;
@@ -2931,9 +2931,9 @@ gtk_menu_size_allocate (GtkWidget     *widget,
     }
 }
 
-static gboolean
-gtk_menu_draw (GtkWidget *widget,
-               cairo_t   *cr)
+static void
+gtk_menu_snapshot (GtkWidget   *widget,
+                   GtkSnapshot *snapshot)
 {
   GtkMenu *menu;
   GtkMenuPrivate *priv;
@@ -2947,28 +2947,30 @@ gtk_menu_draw (GtkWidget *widget,
 
   gtk_widget_get_allocation (widget, &allocation);
 
-  gtk_render_background (context, cr, 0, 0,
-                         allocation.width, allocation.height);
-  gtk_render_frame (context, cr, 0, 0,
-                    allocation.width, allocation.height);
+  gtk_snapshot_render_background (snapshot, context, 0, 0,
+                                  allocation.width, allocation.height);
+  gtk_snapshot_render_frame (snapshot, context, 0, 0,
+                             allocation.width, allocation.height);
 
   if (priv->upper_arrow_visible)
-    gtk_css_gadget_draw (priv->top_arrow_gadget, cr);
+    gtk_css_gadget_snapshot (priv->top_arrow_gadget, snapshot);
 
   if (priv->lower_arrow_visible)
-    gtk_css_gadget_draw (priv->bottom_arrow_gadget, cr);
+    gtk_css_gadget_snapshot (priv->bottom_arrow_gadget, snapshot);
 
   gdk_window_get_position (priv->view_window, &x, &y);
 
-  cairo_rectangle (cr,
-                   x - allocation.x, y - allocation.y,
-                   gdk_window_get_width (priv->view_window),
-                   gdk_window_get_height (priv->view_window));
-  cairo_clip (cr);
+  gtk_snapshot_push_clip (snapshot,
+                          &GRAPHENE_RECT_INIT(
+                              x - allocation.x, y - allocation.y,
+                              gdk_window_get_width (priv->view_window),
+                              gdk_window_get_height (priv->view_window)
+                          ),
+                          "MenuClip");
 
-  GTK_WIDGET_CLASS (gtk_menu_parent_class)->draw (widget, cr);
+  GTK_WIDGET_CLASS (gtk_menu_parent_class)->snapshot (widget, snapshot);
 
-  return FALSE;
+  gtk_snapshot_pop_and_append (snapshot);
 }
 
 static void
diff --git a/gtk/gtkmenubar.c b/gtk/gtkmenubar.c
index fa56e09..8f2cc6d 100644
--- a/gtk/gtkmenubar.c
+++ b/gtk/gtkmenubar.c
@@ -94,8 +94,8 @@ static void gtk_menu_bar_measure_ (GtkWidget     *widget,
                                   int            *natural_baseline);
 static void gtk_menu_bar_size_allocate     (GtkWidget       *widget,
                                            GtkAllocation   *allocation);
-static gint gtk_menu_bar_draw              (GtkWidget       *widget,
-                                            cairo_t         *cr);
+static void gtk_menu_bar_snapshot          (GtkWidget       *widget,
+                                            GtkSnapshot     *snapshot);
 static void gtk_menu_bar_hierarchy_changed (GtkWidget       *widget,
                                            GtkWidget       *old_toplevel);
 static gint gtk_menu_bar_get_popup_delay   (GtkMenuShell    *menu_shell);
@@ -116,7 +116,7 @@ static void gtk_menu_bar_allocate (GtkCssGadget        *gadget,
                                    GtkAllocation       *out_clip,
                                    gpointer             data);
 static gboolean gtk_menu_bar_render (GtkCssGadget *gadget,
-                                     cairo_t      *cr,
+                                     GtkSnapshot  *snapshot,
                                      int           x,
                                      int           y,
                                      int           width,
@@ -144,7 +144,7 @@ gtk_menu_bar_class_init (GtkMenuBarClass *class)
 
   widget_class->measure = gtk_menu_bar_measure_;
   widget_class->size_allocate = gtk_menu_bar_size_allocate;
-  widget_class->draw = gtk_menu_bar_draw;
+  widget_class->snapshot = gtk_menu_bar_snapshot;
   widget_class->hierarchy_changed = gtk_menu_bar_hierarchy_changed;
 
   menu_shell_class->submenu_placement = GTK_TOP_BOTTOM;
@@ -246,8 +246,8 @@ gtk_menu_bar_init (GtkMenuBar *menu_bar)
                                                      widget,
                                                      gtk_menu_bar_measure,
                                                      gtk_menu_bar_allocate,
-                                                     gtk_menu_bar_render,
                                                      NULL,
+                                                     gtk_menu_bar_render,
                                                      NULL, NULL);
 }
 
@@ -573,7 +573,7 @@ gtk_menu_bar_size_allocate (GtkWidget     *widget,
 
 static gboolean
 gtk_menu_bar_render (GtkCssGadget *gadget,
-                     cairo_t      *cr,
+                     GtkSnapshot  *snapshot,
                      int           x,
                      int           y,
                      int           width,
@@ -582,18 +582,16 @@ gtk_menu_bar_render (GtkCssGadget *gadget,
 {
   GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
 
-  GTK_WIDGET_CLASS (gtk_menu_bar_parent_class)->draw (widget, cr);
+  GTK_WIDGET_CLASS (gtk_menu_bar_parent_class)->snapshot (widget, snapshot);
 
   return FALSE;
 }
 
-static gboolean
-gtk_menu_bar_draw (GtkWidget *widget,
-                  cairo_t   *cr)
+static void
+gtk_menu_bar_snapshot (GtkWidget   *widget,
+                       GtkSnapshot *snapshot)
 {
-  gtk_css_gadget_draw (GTK_MENU_BAR (widget)->priv->gadget, cr);
-
-  return FALSE;
+  gtk_css_gadget_snapshot (GTK_MENU_BAR (widget)->priv->gadget, snapshot);
 }
 
 static GList *
diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c
index fd8ce98..64a7e53 100644
--- a/gtk/gtkmenuitem.c
+++ b/gtk/gtkmenuitem.c
@@ -254,7 +254,7 @@ gtk_menu_item_actionable_interface_init (GtkActionableInterface *iface)
 
 static gboolean
 gtk_menu_item_render (GtkCssGadget *gadget,
-                      cairo_t      *cr,
+                      GtkSnapshot  *snapshot,
                       int           x,
                       int           y,
                       int           width,
@@ -269,20 +269,18 @@ gtk_menu_item_render (GtkCssGadget *gadget,
   parent = gtk_widget_get_parent (widget);
 
   if (priv->submenu && !GTK_IS_MENU_BAR (parent))
-    gtk_css_gadget_draw (priv->arrow_gadget, cr);
+    gtk_css_gadget_snapshot (priv->arrow_gadget, snapshot);
 
-  GTK_WIDGET_CLASS (gtk_menu_item_parent_class)->draw (widget, cr);
+  GTK_WIDGET_CLASS (gtk_menu_item_parent_class)->snapshot (widget, snapshot);
 
   return FALSE;
 }
 
-static gboolean
-gtk_menu_item_draw (GtkWidget *widget,
-                    cairo_t   *cr)
+static void
+gtk_menu_item_snapshot (GtkWidget   *widget,
+                        GtkSnapshot *snapshot)
 {
-  gtk_css_gadget_draw (GTK_MENU_ITEM (widget)->priv->gadget, cr);
-
-  return FALSE;
+  gtk_css_gadget_snapshot (GTK_MENU_ITEM (widget)->priv->gadget, snapshot);
 }
 
 static void
@@ -590,7 +588,7 @@ gtk_menu_item_class_init (GtkMenuItemClass *klass)
 
   widget_class->destroy = gtk_menu_item_destroy;
   widget_class->size_allocate = gtk_menu_item_size_allocate;
-  widget_class->draw = gtk_menu_item_draw;
+  widget_class->snapshot = gtk_menu_item_snapshot;
   widget_class->realize = gtk_menu_item_realize;
   widget_class->unrealize = gtk_menu_item_unrealize;
   widget_class->map = gtk_menu_item_map;
@@ -783,8 +781,8 @@ gtk_menu_item_init (GtkMenuItem *menu_item)
                                                      GTK_WIDGET (menu_item),
                                                      gtk_menu_item_measure,
                                                      gtk_menu_item_allocate,
-                                                     gtk_menu_item_render,
                                                      NULL,
+                                                     gtk_menu_item_render,
                                                      NULL, NULL);
 }
 
diff --git a/gtk/gtkmodelmenuitem.c b/gtk/gtkmodelmenuitem.c
index c1f4aca..7c5264c 100644
--- a/gtk/gtkmodelmenuitem.c
+++ b/gtk/gtkmodelmenuitem.c
@@ -68,14 +68,14 @@ gtk_model_menu_item_activate (GtkMenuItem *item)
 }
 
 static void
-gtk_model_menu_item_draw_indicator (GtkCheckMenuItem *check_item,
-                                    cairo_t          *cr)
+gtk_model_menu_item_snapshot_indicator (GtkCheckMenuItem *check_item,
+                                        GtkSnapshot      *snapshot)
 {
   GtkModelMenuItem *item = GTK_MODEL_MENU_ITEM (check_item);
 
   if (item->has_indicator)
     GTK_CHECK_MENU_ITEM_CLASS (gtk_model_menu_item_parent_class)
-      ->draw_indicator (check_item, cr);
+      ->snapshot_indicator (check_item, snapshot);
 }
 
 static void
@@ -474,7 +474,7 @@ gtk_model_menu_item_class_init (GtkModelMenuItemClass *class)
   GtkMenuItemClass *item_class = GTK_MENU_ITEM_CLASS (class);
   GObjectClass *object_class = G_OBJECT_CLASS (class);
 
-  check_class->draw_indicator = gtk_model_menu_item_draw_indicator;
+  check_class->snapshot_indicator = gtk_model_menu_item_snapshot_indicator;
 
   item_class->toggle_size_request = gtk_model_menu_item_toggle_size_request;
   item_class->activate = gtk_model_menu_item_activate;


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