[epiphany/gnome-3-30] action-bar: Adapt to window chrome changes



commit 2d3ce2ae18d5f82ac51a21c03cff08e906f9789f
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu Sep 27 08:50:43 2018 +0200

    action-bar: Adapt to window chrome changes
    
    This allows to correctly update visibility of the action bar elements in
    application mode.
    
    https://gitlab.gnome.org/GNOME/epiphany/issues/544

 src/ephy-action-bar.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/ephy-action-bar.h |  3 +-
 src/ephy-window.c     |  2 +-
 3 files changed, 90 insertions(+), 3 deletions(-)
---
diff --git a/src/ephy-action-bar.c b/src/ephy-action-bar.c
index 12ac1a788..9424ab962 100644
--- a/src/ephy-action-bar.c
+++ b/src/ephy-action-bar.c
@@ -21,20 +21,105 @@
 
 #include "ephy-action-bar.h"
 
+enum {
+  PROP_0,
+  PROP_WINDOW,
+  N_PROPERTIES
+};
+
+static GParamSpec *object_properties[N_PROPERTIES] = { NULL, };
+
 struct _EphyActionBar {
   GtkRevealer parent_instance;
 
+  EphyWindow *window;
   EphyActionBarStart *action_bar_start;
   EphyActionBarEnd *action_bar_end;
 };
 
 G_DEFINE_TYPE (EphyActionBar, ephy_action_bar, GTK_TYPE_REVEALER)
 
+static void
+sync_chromes_visibility (EphyActionBar *action_bar)
+{
+  EphyWindowChrome chrome;
+
+  chrome = ephy_window_get_chrome (action_bar->window);
+
+  gtk_widget_set_visible (ephy_action_bar_start_get_navigation_box (action_bar->action_bar_start),
+                          chrome & EPHY_WINDOW_CHROME_HEADER_BAR);
+  ephy_action_bar_end_set_show_bookmarks_button (action_bar->action_bar_end,
+                                                 chrome & EPHY_WINDOW_CHROME_BOOKMARKS);
+  ephy_action_bar_end_set_show_new_tab_button (action_bar->action_bar_end,
+                                               chrome & EPHY_WINDOW_CHROME_TABSBAR);
+}
+
+static void
+ephy_action_bar_set_property (GObject      *object,
+                              guint         property_id,
+                              const GValue *value,
+                              GParamSpec   *pspec)
+{
+  EphyActionBar *action_bar = EPHY_ACTION_BAR (object);
+
+  switch (property_id) {
+    case PROP_WINDOW:
+      action_bar->window = EPHY_WINDOW (g_value_get_object (value));
+      g_object_notify_by_pspec (object, object_properties[PROP_WINDOW]);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+  }
+}
+
+static void
+ephy_action_bar_get_property (GObject    *object,
+                              guint       property_id,
+                              GValue     *value,
+                              GParamSpec *pspec)
+{
+  EphyActionBar *action_bar = EPHY_ACTION_BAR (object);
+
+  switch (property_id) {
+    case PROP_WINDOW:
+      g_value_set_object (value, action_bar->window);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+  }
+}
+
+static void
+ephy_action_bar_constructed (GObject *object)
+{
+  EphyActionBar *action_bar = EPHY_ACTION_BAR (object);
+
+  g_signal_connect_object (action_bar->window, "notify::chrome",
+                           G_CALLBACK (sync_chromes_visibility), action_bar,
+                           G_CONNECT_SWAPPED);
+}
+
 static void
 ephy_action_bar_class_init (EphyActionBarClass *klass)
 {
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
+  gobject_class->set_property = ephy_action_bar_set_property;
+  gobject_class->get_property = ephy_action_bar_get_property;
+  gobject_class->constructed = ephy_action_bar_constructed;
+
+  object_properties[PROP_WINDOW] =
+    g_param_spec_object ("window",
+                         "Window",
+                         "The action_bar's EphyWindow",
+                         EPHY_TYPE_WINDOW,
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (gobject_class,
+                                     N_PROPERTIES,
+                                     object_properties);
+
   gtk_widget_class_set_template_from_resource (widget_class,
                                                "/org/gnome/epiphany/gtk/action-bar.ui");
 
@@ -57,9 +142,10 @@ ephy_action_bar_init (EphyActionBar *action_bar)
 }
 
 EphyActionBar *
-ephy_action_bar_new (void)
+ephy_action_bar_new (EphyWindow *window)
 {
   return g_object_new (EPHY_TYPE_ACTION_BAR,
+                       "window", window,
                        NULL);
 }
 
diff --git a/src/ephy-action-bar.h b/src/ephy-action-bar.h
index 312227a0b..390e92007 100644
--- a/src/ephy-action-bar.h
+++ b/src/ephy-action-bar.h
@@ -26,6 +26,7 @@
 #include "ephy-action-bar-end.h"
 #include "ephy-action-bar-start.h"
 #include "ephy-adaptive-mode.h"
+#include "ephy-window.h"
 
 G_BEGIN_DECLS
 
@@ -33,7 +34,7 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (EphyActionBar, ephy_action_bar, EPHY, ACTION_BAR, GtkRevealer);
 
-EphyActionBar      *ephy_action_bar_new                  (void);
+EphyActionBar      *ephy_action_bar_new                  (EphyWindow *window);
 EphyActionBarStart *ephy_action_bar_get_action_bar_start (EphyActionBar *action_bar);
 EphyActionBarEnd   *ephy_action_bar_get_action_bar_end   (EphyActionBar *action_bar);
 void                ephy_action_bar_set_adaptive_mode    (EphyActionBar    *action_bar,
diff --git a/src/ephy-window.c b/src/ephy-window.c
index e1a6402b8..d0c0f3d04 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -3105,7 +3105,7 @@ setup_action_bar (EphyWindow *window)
 {
   GtkWidget *action_bar;
 
-  action_bar = GTK_WIDGET (ephy_action_bar_new ());
+  action_bar = GTK_WIDGET (ephy_action_bar_new (window));
   gtk_revealer_set_transition_type (GTK_REVEALER (action_bar), GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP);
   gtk_widget_show (action_bar);
 


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