[gtk/wip/ebassi/a11y-2: 1058/1060] a11y: Split GtkSearchEntryAccessible from GtkEntryAccessible



commit fe3ed6a320a2acbf77dac4e04c5256fac1ef453c
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Wed May 27 17:54:23 2020 +0100

    a11y: Split GtkSearchEntryAccessible from GtkEntryAccessible
    
    Use a separate accessible object for the GtkSearchEntry, just like we
    did for GtkPasswordEntry.

 gtk/a11y/gtkentryaccessible.c       |  7 +++-
 gtk/a11y/gtksearchentryaccessible.c | 76 +++++++++++++++++++++++++++++++++++++
 gtk/a11y/gtksearchentryaccessible.h | 48 +++++++++++++++++++++++
 gtk/a11y/meson.build                |  2 +
 gtk/gtk-a11y.h                      |  1 +
 gtk/gtksearchentry.c                | 16 +-------
 6 files changed, 134 insertions(+), 16 deletions(-)
---
diff --git a/gtk/a11y/gtkentryaccessible.c b/gtk/a11y/gtkentryaccessible.c
index 74a72f68f3..fc33f5b6f3 100644
--- a/gtk/a11y/gtkentryaccessible.c
+++ b/gtk/a11y/gtkentryaccessible.c
@@ -425,7 +425,10 @@ gtk_entry_accessible_get_attributes (AtkObject *accessible)
   if (widget == NULL)
     return attributes;
 
-  if (GTK_IS_ENTRY (widget) || GTK_IS_SEARCH_ENTRY (widget))
+  /* Subclasses of GtkEntryAccessible will chain up, so we need to protect
+   * the placeholder-text property access
+   */
+  if (GTK_IS_ENTRY (widget))
     g_object_get (widget, "placeholder-text", &text, NULL);
 
   if (text == NULL)
@@ -738,7 +741,7 @@ gtk_entry_accessible_finalize (GObject *object)
 static void
 gtk_entry_accessible_class_init (GtkEntryAccessibleClass *klass)
 {
-  AtkObjectClass  *class = ATK_OBJECT_CLASS (klass);
+  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
   GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
diff --git a/gtk/a11y/gtksearchentryaccessible.c b/gtk/a11y/gtksearchentryaccessible.c
new file mode 100644
index 0000000000..92c68c424f
--- /dev/null
+++ b/gtk/a11y/gtksearchentryaccessible.c
@@ -0,0 +1,76 @@
+/* gtksearchentryaccessible.c: GtkWidgetAccessible for GtkSearchEntry
+ *
+ * Copyright 2020  GNOME Foundation
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gtksearchentryaccessible.h"
+
+#include "gtkintl.h"
+
+struct _GtkSearchEntryAccessible
+{
+  GtkEntryAccessible parent_instance;
+};
+
+G_DEFINE_TYPE (GtkSearchEntryAccessible, gtk_search_entry_accessible, GTK_TYPE_ENTRY_ACCESSIBLE)
+
+static AtkAttributeSet *
+gtk_search_entry_accessible_get_attributes (AtkObject *accessible)
+{
+  GtkWidget *widget;
+  AtkAttributeSet *attributes;
+  AtkAttribute *placeholder_text;
+  char *text = NULL;
+
+  attributes = ATK_OBJECT_CLASS (gtk_search_entry_accessible_parent_class)->get_attributes (accessible);
+
+  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
+  if (widget == NULL)
+    return attributes;
+
+  g_object_get (widget, "placeholder-text", &text, NULL);
+  if (text == NULL)
+    return attributes;
+
+  placeholder_text = g_malloc (sizeof (AtkAttribute));
+  placeholder_text->name = g_strdup ("placeholder-text");
+  placeholder_text->value = text;
+
+  attributes = g_slist_append (attributes, placeholder_text);
+
+  return attributes;
+}
+
+static void
+gtk_search_entry_accessible_class_init (GtkSearchEntryAccessibleClass *klass)
+{
+  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
+
+  class->get_attributes = gtk_search_entry_accessible_get_attributes;
+}
+
+static void
+gtk_search_entry_accessible_init (GtkSearchEntryAccessible *self)
+{
+  AtkObject *atk_obj = ATK_OBJECT (self);
+
+  atk_obj->role = ATK_ROLE_TEXT;
+  atk_object_set_name (atk_obj, _("Search"));
+}
diff --git a/gtk/a11y/gtksearchentryaccessible.h b/gtk/a11y/gtksearchentryaccessible.h
new file mode 100644
index 0000000000..49012918e7
--- /dev/null
+++ b/gtk/a11y/gtksearchentryaccessible.h
@@ -0,0 +1,48 @@
+/* gtksearchentryaccessible.h: A GtkWidgetAccessible for GtkSearchEntry
+ *
+ * Copyright 2020  GNOME Foundation
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#if !defined (__GTK_A11Y_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk-a11y.h> can be included directly."
+#endif
+
+#include <gtk/a11y/gtkentryaccessible.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_SEARCH_ENTRY_ACCESSIBLE        (gtk_search_entry_accessible_get_type())
+#define GTK_SEARCH_ENTRY_ACCESSIBLE(obj)        (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_TYPE_SEARCH_ENTRY_ACCESSIBLE, GtkSearchEntryAccessible))
+#define GTK_IS_SEARCH_ENTRY_ACCESSIBLE(obj)     (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_TYPE_SEARCH_ENTRY_ACCESSIBLE))
+
+typedef struct _GtkSearchEntryAccessible        GtkSearchEntryAccessible;
+typedef struct _GtkSearchEntryAccessibleClass   GtkSearchEntryAccessibleClass;
+
+struct _GtkSearchEntryAccessibleClass
+{
+  GtkEntryAccessibleClass parent_class;
+};
+
+GDK_AVAILABLE_IN_ALL
+GType gtk_search_entry_accessible_get_type (void) G_GNUC_CONST;
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GtkSearchEntryAccessible, g_object_unref)
+
+G_END_DECLS
diff --git a/gtk/a11y/meson.build b/gtk/a11y/meson.build
index 680c598b64..10d74907f9 100644
--- a/gtk/a11y/meson.build
+++ b/gtk/a11y/meson.build
@@ -38,6 +38,7 @@ a11y_sources = files([
   'gtkscalebuttonaccessible.c',
   'gtkscrollbaraccessible.c',
   'gtkscrolledwindowaccessible.c',
+  'gtksearchentryaccessible.c',
   'gtkspinbuttonaccessible.c',
   'gtkspinneraccessible.c',
   'gtkstackaccessible.c',
@@ -90,6 +91,7 @@ a11y_headers = files([
   'gtkscalebuttonaccessible.h',
   'gtkscrollbaraccessible.h',
   'gtkscrolledwindowaccessible.h',
+  'gtksearchentryaccessible.h',
   'gtkspinbuttonaccessible.h',
   'gtkspinneraccessible.h',
   'gtkstackaccessible.h',
diff --git a/gtk/gtk-a11y.h b/gtk/gtk-a11y.h
index 1e253ec5f3..3199b23156 100644
--- a/gtk/gtk-a11y.h
+++ b/gtk/gtk-a11y.h
@@ -63,6 +63,7 @@
 #include <gtk/a11y/gtkscalebuttonaccessible.h>
 #include <gtk/a11y/gtkscrolledwindowaccessible.h>
 #include <gtk/a11y/gtkscrollbaraccessible.h>
+#include <gtk/a11y/gtksearchentryaccessible.h>
 #include <gtk/a11y/gtkspinbuttonaccessible.h>
 #include <gtk/a11y/gtkspinneraccessible.h>
 #include <gtk/a11y/gtkstackaccessible.h>
diff --git a/gtk/gtksearchentry.c b/gtk/gtksearchentry.c
index b8c224dd84..0ccf639e87 100644
--- a/gtk/gtksearchentry.c
+++ b/gtk/gtksearchentry.c
@@ -40,7 +40,7 @@
 #include "gtkmarshalers.h"
 #include "gtkstylecontext.h"
 #include "gtkeventcontrollerkey.h"
-#include "a11y/gtkentryaccessible.h"
+#include "a11y/gtksearchentryaccessible.h"
 
 
 /**
@@ -219,17 +219,6 @@ gtk_search_entry_get_property (GObject    *object,
     }
 }
 
-static AtkObject *
-gtk_search_entry_get_accessible (GtkWidget *widget)
-{
-  AtkObject *atk_obj;
-
-  atk_obj = GTK_WIDGET_CLASS (gtk_search_entry_parent_class)->get_accessible (widget);
-  atk_object_set_name (atk_obj, _("Search"));
-
-  return atk_obj;
-}
-
 static gboolean
 gtk_search_entry_grab_focus (GtkWidget *widget)
 {
@@ -259,7 +248,6 @@ gtk_search_entry_class_init (GtkSearchEntryClass *klass)
   object_class->get_property = gtk_search_entry_get_property;
   object_class->set_property = gtk_search_entry_set_property;
 
-  widget_class->get_accessible = gtk_search_entry_get_accessible;
   widget_class->grab_focus = gtk_search_entry_grab_focus;
   widget_class->mnemonic_activate = gtk_search_entry_mnemonic_activate;
 
@@ -400,7 +388,7 @@ gtk_search_entry_class_init (GtkSearchEntryClass *klass)
                                        "stop-search",
                                        NULL);
 
-  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
+  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_SEARCH_ENTRY_ACCESSIBLE);
   gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
   gtk_widget_class_set_css_name (widget_class, I_("entry"));
 }


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