[gtk/wip/ebassi/a11y-2: 24/28] a11y: Split password entry accessible from GtkEntryAccessible



commit 2729a3886ea45f897fe65559ecede23c0ad6cbdf
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Wed May 27 16:24:31 2020 +0100

    a11y: Split password entry accessible from GtkEntryAccessible
    
    Use a separate accessible object.

 gtk/a11y/gtkentryaccessible.c         | 27 ++++++++++----------
 gtk/a11y/gtkpasswordentryaccessible.c | 46 +++++++++++++++++++++++++++++++++
 gtk/a11y/gtkpasswordentryaccessible.h | 48 +++++++++++++++++++++++++++++++++++
 gtk/a11y/meson.build                  |  2 ++
 gtk/gtk-a11y.h                        |  1 +
 gtk/gtkpasswordentry.c                | 16 ++----------
 po/POTFILES.in                        |  1 +
 7 files changed, 113 insertions(+), 28 deletions(-)
---
diff --git a/gtk/a11y/gtkentryaccessible.c b/gtk/a11y/gtkentryaccessible.c
index 324a79f31c..74a72f68f3 100644
--- a/gtk/a11y/gtkentryaccessible.c
+++ b/gtk/a11y/gtkentryaccessible.c
@@ -17,21 +17,23 @@
 
 #include "config.h"
 
-#include "gdk/gdkeventsprivate.h"
-
-#include <glib/gi18n-lib.h>
-#include <string.h>
-#include <gtk/gtk.h>
-#include "gtkpango.h"
 #include "gtkentryaccessible.h"
+
+#include "gtkcomboboxaccessible.h"
+
 #include "gtkentryprivate.h"
+#include "gtklabel.h"
+#include "gtkpango.h"
 #include "gtksearchentryprivate.h"
-#include "gtkpasswordentry.h"
-#include "gtktextprivate.h"
-#include "gtkcomboboxaccessible.h"
 #include "gtkstylecontextprivate.h"
+#include "gtktextprivate.h"
 #include "gtkwidgetprivate.h"
 
+#include "gdk/gdkeventsprivate.h"
+
+#include <glib/gi18n-lib.h>
+#include <string.h>
+
 #define GTK_TYPE_ENTRY_ICON_ACCESSIBLE      (gtk_entry_icon_accessible_get_type ())
 #define GTK_ENTRY_ICON_ACCESSIBLE(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_TYPE_ENTRY_ICON_ACCESSIBLE, GtkEntryIconAccessible))
 #define GTK_IS_ENTRY_ICON_ACCESSIBLE(obj)   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_TYPE_ENTRY_ICON_ACCESSIBLE))
@@ -458,11 +460,6 @@ gtk_entry_accessible_initialize (AtkObject *obj,
   /* Set up signal callbacks */
   g_signal_connect_after (widget, "insert-text", G_CALLBACK (insert_text_cb), NULL);
   g_signal_connect (widget, "delete-text", G_CALLBACK (delete_text_cb), NULL);
-
-  if (GTK_IS_PASSWORD_ENTRY (widget))
-    obj->role = ATK_ROLE_PASSWORD_TEXT;
-  else
-    obj->role = ATK_ROLE_TEXT;
 }
 
 static void
@@ -763,6 +760,8 @@ gtk_entry_accessible_init (GtkEntryAccessible *entry)
   entry->priv = gtk_entry_accessible_get_instance_private (entry);
   entry->priv->cursor_position = 0;
   entry->priv->selection_bound = 0;
+
+  ATK_OBJECT (entry)->role = ATK_ROLE_TEXT;
 }
 
 static GtkText *
diff --git a/gtk/a11y/gtkpasswordentryaccessible.c b/gtk/a11y/gtkpasswordentryaccessible.c
new file mode 100644
index 0000000000..5cdce35512
--- /dev/null
+++ b/gtk/a11y/gtkpasswordentryaccessible.c
@@ -0,0 +1,46 @@
+/* gtkpasswordentryaccessible.c: A GtkWidgetAccessible for GtkPasswordEntry
+ *
+ * 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 "gtkpasswordentryaccessible.h"
+
+#include "gtkintl.h"
+
+struct _GtkPasswordEntryAccessible
+{
+  GtkEntryAccessible parent_instance;
+};
+
+G_DEFINE_TYPE (GtkPasswordEntryAccessible, gtk_password_entry_accessible, GTK_TYPE_ENTRY_ACCESSIBLE)
+
+static void
+gtk_password_entry_accessible_class_init (GtkPasswordEntryAccessibleClass *klass)
+{
+}
+
+static void
+gtk_password_entry_accessible_init (GtkPasswordEntryAccessible *self)
+{
+  AtkObject *atk_obj = ATK_OBJECT (self);
+
+  atk_obj->role = ATK_ROLE_PASSWORD_TEXT;
+  atk_object_set_name (atk_obj, _("Password"));
+}
diff --git a/gtk/a11y/gtkpasswordentryaccessible.h b/gtk/a11y/gtkpasswordentryaccessible.h
new file mode 100644
index 0000000000..1fe210feb8
--- /dev/null
+++ b/gtk/a11y/gtkpasswordentryaccessible.h
@@ -0,0 +1,48 @@
+/* gtkpasswordentryaccessible.h: A GtkWidgetAccessible for GtkPasswordEntry
+ *
+ * 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_PASSWORD_ENTRY_ACCESSIBLE      (gtk_password_entry_accessible_get_type())
+#define GTK_PASSWORD_ENTRY_ACCESSIBLE(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_TYPE_PASSWORD_ENTRY_ACCESSIBLE, GtkPasswordEntryAccessible))
+#define GTK_IS_PASSWORD_ENTRY_ACCESSIBLE(obj)   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_TYPE_PASSWORD_ENTRY_ACCESSIBLE))
+
+typedef struct _GtkPasswordEntryAccessible      GtkPasswordEntryAccessible;
+typedef struct _GtkPasswordEntryAccessibleClass GtkPasswordEntryAccessibleClass;
+
+struct _GtkPasswordEntryAccessibleClass
+{
+  GtkEntryAccessibleClass parent_class;
+};
+
+GDK_AVAILABLE_IN_ALL
+GType gtk_password_entry_accessible_get_type (void) G_GNUC_CONST;
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GtkPasswordEntryAccessible, g_object_unref)
+
+G_END_DECLS
diff --git a/gtk/a11y/meson.build b/gtk/a11y/meson.build
index f47ca0a2bf..680c598b64 100644
--- a/gtk/a11y/meson.build
+++ b/gtk/a11y/meson.build
@@ -27,6 +27,7 @@ a11y_sources = files([
   'gtknotebookaccessible.c',
   'gtknotebookpageaccessible.c',
   'gtkpanedaccessible.c',
+  'gtkpasswordentryaccessible.c',
   'gtkpictureaccessible.c',
   'gtkpopoveraccessible.c',
   'gtkprogressbaraccessible.c',
@@ -79,6 +80,7 @@ a11y_headers = files([
   'gtknotebookaccessible.h',
   'gtknotebookpageaccessible.h',
   'gtkpanedaccessible.h',
+  'gtkpasswordentryaccessible.h',
   'gtkpopoveraccessible.h',
   'gtkprogressbaraccessible.h',
   'gtkradiobuttonaccessible.h',
diff --git a/gtk/gtk-a11y.h b/gtk/gtk-a11y.h
index e097eed58e..1e253ec5f3 100644
--- a/gtk/gtk-a11y.h
+++ b/gtk/gtk-a11y.h
@@ -53,6 +53,7 @@
 #include <gtk/a11y/gtknotebookaccessible.h>
 #include <gtk/a11y/gtknotebookpageaccessible.h>
 #include <gtk/a11y/gtkpanedaccessible.h>
+#include <gtk/a11y/gtkpasswordentryaccessible.h>
 #include <gtk/a11y/gtkpopoveraccessible.h>
 #include <gtk/a11y/gtkprogressbaraccessible.h>
 #include <gtk/a11y/gtkradiobuttonaccessible.h>
diff --git a/gtk/gtkpasswordentry.c b/gtk/gtkpasswordentry.c
index ab68a7dbd8..99eaf0b39b 100644
--- a/gtk/gtkpasswordentry.c
+++ b/gtk/gtkpasswordentry.c
@@ -35,7 +35,7 @@
 #include "gtkstylecontext.h"
 #include "gtkeventcontrollerkey.h"
 
-#include "a11y/gtkentryaccessible.h"
+#include "a11y/gtkpasswordentryaccessible.h"
 
 /**
  * SECTION:gtkpasswordentry
@@ -346,17 +346,6 @@ gtk_password_entry_size_allocate (GtkWidget *widget,
                               baseline);
 }
 
-static AtkObject *
-gtk_password_entry_get_accessible (GtkWidget *widget)
-{
-  AtkObject *atk_obj;
-
-  atk_obj = GTK_WIDGET_CLASS (gtk_password_entry_parent_class)->get_accessible (widget);
-  atk_object_set_name (atk_obj, _("Password"));
-
-  return atk_obj;
-}
-
 static gboolean
 gtk_password_entry_mnemonic_activate (GtkWidget *widget,
                                       gboolean   group_cycling)
@@ -382,7 +371,6 @@ gtk_password_entry_class_init (GtkPasswordEntryClass *klass)
   widget_class->realize = gtk_password_entry_realize;
   widget_class->measure = gtk_password_entry_measure;
   widget_class->size_allocate = gtk_password_entry_size_allocate;
-  widget_class->get_accessible = gtk_password_entry_get_accessible;
   widget_class->mnemonic_activate = gtk_password_entry_mnemonic_activate;
   widget_class->grab_focus = gtk_widget_grab_focus_child;
 
@@ -423,7 +411,7 @@ gtk_password_entry_class_init (GtkPasswordEntryClass *klass)
   g_object_class_install_properties (object_class, NUM_PROPERTIES, props);
   gtk_editable_install_properties (object_class, NUM_PROPERTIES);
 
-  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
+  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_PASSWORD_ENTRY_ACCESSIBLE);
   gtk_widget_class_set_css_name (widget_class, I_("entry"));
 }
 
diff --git a/po/POTFILES.in b/po/POTFILES.in
index df6c85d0a6..77233fc7b9 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -53,6 +53,7 @@ gtk/a11y/gtkentryaccessible.c
 gtk/a11y/gtkexpanderaccessible.c
 gtk/a11y/gtkimageaccessible.c
 gtk/a11y/gtkmenubuttonaccessible.c
+gtk/a11y/gtkpasswordentryaccessible.c
 gtk/a11y/gtkrenderercellaccessible.c
 gtk/a11y/gtkscalebuttonaccessible.c
 gtk/a11y/gtkspinneraccessible.c


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