[gtk/ebassi/for-master: 4/8] a11y: Notify callers when an attributes set changes




commit 32a1cd13c8abd3015af5923344d463eee6a6d3a5
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Wed Aug 5 18:04:34 2020 +0100

    a11y: Notify callers when an attributes set changes
    
    We can use that information inside the ATContext.

 gtk/gtkaccessibleattributeset.c        | 37 ++++++++++++++++++++++++++++++----
 gtk/gtkaccessibleattributesetprivate.h |  4 ++--
 2 files changed, 35 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkaccessibleattributeset.c b/gtk/gtkaccessibleattributeset.c
index abdc0950ed..f49a9cf911 100644
--- a/gtk/gtkaccessibleattributeset.c
+++ b/gtk/gtkaccessibleattributeset.c
@@ -114,13 +114,26 @@ gtk_accessible_attribute_set_unref (GtkAccessibleAttributeSet *self)
  *
  * If you want to remove @attribute from the set, use gtk_accessible_attribute_set_remove()
  * instead.
+ *
+ * Returns: %TRUE if the set was modified, and %FALSE otherwise
  */
-void
+gboolean
 gtk_accessible_attribute_set_add (GtkAccessibleAttributeSet *self,
                                   int                        attribute,
                                   GtkAccessibleValue        *value)
 {
-  g_return_if_fail (attribute >= 0 && attribute < self->n_attributes);
+  g_return_val_if_fail (attribute >= 0 && attribute < self->n_attributes, FALSE);
+
+  if (value != NULL)
+    {
+      if (gtk_accessible_value_equal (value, self->attribute_values[attribute]))
+        return FALSE;
+    }
+  else
+    {
+      if (!_gtk_bitmask_get (self->attributes_set, attribute))
+        return FALSE;
+    }
 
   g_clear_pointer (&(self->attribute_values[attribute]), gtk_accessible_value_unref);
 
@@ -130,18 +143,34 @@ gtk_accessible_attribute_set_add (GtkAccessibleAttributeSet *self,
     self->attribute_values[attribute] = (* self->default_func) (attribute);
 
   self->attributes_set = _gtk_bitmask_set (self->attributes_set, attribute, TRUE);
+
+  return TRUE;
 }
 
-void
+/*< private >
+ * gtk_accessible_attribute_set_remove:
+ * @self: a #GtkAccessibleAttributeSet
+ * @attribute: the attribute to be removed
+ *
+ * Resets the @attribute in the given #GtkAccessibleAttributeSet to its default value.
+ *
+ * Returns: %TRUE if the set was modified, and %FALSE otherwise
+ */
+gboolean
 gtk_accessible_attribute_set_remove (GtkAccessibleAttributeSet *self,
                                      int                        attribute)
 {
-  g_return_if_fail (attribute >= 0 && attribute < self->n_attributes);
+  g_return_val_if_fail (attribute >= 0 && attribute < self->n_attributes, FALSE);
+
+  if (!_gtk_bitmask_get (self->attributes_set, attribute))
+    return FALSE;
 
   g_clear_pointer (&(self->attribute_values[attribute]), gtk_accessible_value_unref);
 
   self->attribute_values[attribute] = (* self->default_func) (attribute);
   self->attributes_set = _gtk_bitmask_set (self->attributes_set, attribute, FALSE);
+
+  return TRUE;
 }
 
 gboolean
diff --git a/gtk/gtkaccessibleattributesetprivate.h b/gtk/gtkaccessibleattributesetprivate.h
index 57a1e63e35..83694c7ede 100644
--- a/gtk/gtkaccessibleattributesetprivate.h
+++ b/gtk/gtkaccessibleattributesetprivate.h
@@ -37,10 +37,10 @@ void                            gtk_accessible_attribute_set_unref
 
 gsize                           gtk_accessible_attribute_set_get_length         (GtkAccessibleAttributeSet  
*self);
 
-void                            gtk_accessible_attribute_set_add                (GtkAccessibleAttributeSet  
*self,
+gboolean                        gtk_accessible_attribute_set_add                (GtkAccessibleAttributeSet  
*self,
                                                                                  int                         
attribute,
                                                                                  GtkAccessibleValue         
*value);
-void                            gtk_accessible_attribute_set_remove             (GtkAccessibleAttributeSet  
*self,
+gboolean                        gtk_accessible_attribute_set_remove             (GtkAccessibleAttributeSet  
*self,
                                                                                  int                         
state);
 gboolean                        gtk_accessible_attribute_set_contains           (GtkAccessibleAttributeSet  
*self,
                                                                                  int                         
state);


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