Merge lp:~apinheiro/unity/a11y-emit-children-changed into lp:unity

Proposed by Alejandro Piñeiro on 2011-03-14
Status: Merged
Merged at revision: 948
Proposed branch: lp:~apinheiro/unity/a11y-emit-children-changed
Merge into: lp:unity
Diff against target: 269 lines (+157/-0)
4 files modified
src/unity-launcher-accessible.cpp (+123/-0)
src/unity-launcher-icon-accessible.cpp (+25/-0)
src/unity-launcher-icon-accessible.h (+3/-0)
src/unity-root-accessible.cpp (+6/-0)
To merge this branch: bzr merge lp:~apinheiro/unity/a11y-emit-children-changed
Reviewer Review Type Date Requested Status
Rodrigo Moya (community) 2011-03-14 Approve on 2011-03-14
Review via email: mp+53228@code.launchpad.net

Description of the change

Some comments:

It doesn't emit that signal for all the accessibility object, specifically:

  * NuxViewAccessible
  * NuxLayoutAccessible

But this is because nux::View and nux::Layout lacks signals reporting that a child was added.

Anyway, this branch emit "children-changed" for the most important object, the root, and I found that no manual request of the object was required (so no accessible objects are missing).

So I suggest to close the bug related once this branch gets merged, and managed those objects in a different bug.

To post a comment you must log in.
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/unity-launcher-accessible.cpp'
--- src/unity-launcher-accessible.cpp 2011-03-09 09:44:28 +0000
+++ src/unity-launcher-accessible.cpp 2011-03-14 12:04:17 +0000
@@ -31,6 +31,7 @@
31#include <glib/gi18n.h>31#include <glib/gi18n.h>
3232
33#include "unity-launcher-accessible.h"33#include "unity-launcher-accessible.h"
34#include "unity-launcher-icon-accessible.h"
3435
35#include "unitya11y.h"36#include "unitya11y.h"
36#include "Launcher.h"37#include "Launcher.h"
@@ -58,6 +59,10 @@
5859
59/* private */60/* private */
60static void on_selection_change_cb (UnityLauncherAccessible *launcher_accessible);61static void on_selection_change_cb (UnityLauncherAccessible *launcher_accessible);
62static void on_icon_added_cb (LauncherIcon *icon, UnityLauncherAccessible *self);
63static void on_icon_removed_cb (LauncherIcon *icon, UnityLauncherAccessible *self);
64static void on_order_change_cb (UnityLauncherAccessible *self);
65static void update_children_index (UnityLauncherAccessible *self);
6166
6267
63G_DEFINE_TYPE_WITH_CODE (UnityLauncherAccessible, unity_launcher_accessible, NUX_TYPE_VIEW_ACCESSIBLE,68G_DEFINE_TYPE_WITH_CODE (UnityLauncherAccessible, unity_launcher_accessible, NUX_TYPE_VIEW_ACCESSIBLE,
@@ -70,6 +75,9 @@
70struct _UnityLauncherAccessiblePrivate75struct _UnityLauncherAccessiblePrivate
71{76{
72 sigc::connection on_selection_change_connection;77 sigc::connection on_selection_change_connection;
78 sigc::connection on_icon_added_connection;
79 sigc::connection on_icon_removed_connection;
80 sigc::connection on_order_changed_connection;
73};81};
7482
7583
@@ -104,6 +112,9 @@
104 UnityLauncherAccessible *self = UNITY_LAUNCHER_ACCESSIBLE (object);112 UnityLauncherAccessible *self = UNITY_LAUNCHER_ACCESSIBLE (object);
105113
106 self->priv->on_selection_change_connection.disconnect ();114 self->priv->on_selection_change_connection.disconnect ();
115 self->priv->on_icon_added_connection.disconnect ();
116 self->priv->on_icon_removed_connection.disconnect ();
117 self->priv->on_order_changed_connection.disconnect ();
107118
108 G_OBJECT_CLASS (unity_launcher_accessible_parent_class)->finalize (object);119 G_OBJECT_CLASS (unity_launcher_accessible_parent_class)->finalize (object);
109}120}
@@ -131,6 +142,7 @@
131 Launcher *launcher = NULL;142 Launcher *launcher = NULL;
132 nux::Object *nux_object = NULL;143 nux::Object *nux_object = NULL;
133 UnityLauncherAccessible *self = NULL;144 UnityLauncherAccessible *self = NULL;
145 LauncherModel *model = NULL;
134146
135 ATK_OBJECT_CLASS (unity_launcher_accessible_parent_class)->initialize (accessible, data);147 ATK_OBJECT_CLASS (unity_launcher_accessible_parent_class)->initialize (accessible, data);
136148
@@ -143,6 +155,20 @@
143155
144 self->priv->on_selection_change_connection =156 self->priv->on_selection_change_connection =
145 launcher->selection_change.connect (sigc::bind (sigc::ptr_fun (on_selection_change_cb), self));157 launcher->selection_change.connect (sigc::bind (sigc::ptr_fun (on_selection_change_cb), self));
158
159 model = launcher->GetModel ();
160
161 if (model)
162 {
163 self->priv->on_icon_added_connection =
164 model->icon_added.connect (sigc::bind (sigc::ptr_fun (on_icon_added_cb), self));
165
166 self->priv->on_icon_removed_connection =
167 model->icon_removed.connect (sigc::bind (sigc::ptr_fun (on_icon_removed_cb), self));
168
169 self->priv->on_order_changed_connection =
170 model->order_changed.connect (sigc::bind (sigc::ptr_fun (on_order_change_cb), self));
171 }
146}172}
147173
148static gint174static gint
@@ -315,3 +341,100 @@
315 g_signal_emit_by_name (ATK_OBJECT (launcher_accessible), "selection-changed");341 g_signal_emit_by_name (ATK_OBJECT (launcher_accessible), "selection-changed");
316}342}
317343
344
345static void
346on_icon_added_cb (LauncherIcon *icon,
347 UnityLauncherAccessible *self)
348{
349 AtkObject *icon_accessible = NULL;
350 nux::Object *nux_object = NULL;
351 gint index = 0;
352
353 g_return_if_fail (UNITY_IS_LAUNCHER_ACCESSIBLE (self));
354
355 nux_object = nux_object_accessible_get_object (NUX_OBJECT_ACCESSIBLE (self));
356 if (nux_object == NULL) /* state is defunct */
357 return;
358
359 icon_accessible = unity_a11y_get_accessible (icon);
360
361 update_children_index (self);
362
363 index = atk_object_get_index_in_parent (icon_accessible);
364
365 g_debug ("[a11y] icon (%p, %s) added on container (%p,%s) at index %i",
366 icon_accessible, atk_object_get_name (icon_accessible),
367 self, atk_object_get_name ( ATK_OBJECT (self)),
368 index);
369
370 g_signal_emit_by_name (self, "children-changed::add",
371 index, icon_accessible, NULL);
372}
373
374static void
375on_icon_removed_cb (LauncherIcon *icon,
376 UnityLauncherAccessible *self)
377{
378 AtkObject *icon_accessible = NULL;
379 nux::Object *nux_object = NULL;
380 gint index = 0;
381
382 g_return_if_fail (UNITY_IS_LAUNCHER_ACCESSIBLE (self));
383
384 nux_object = nux_object_accessible_get_object (NUX_OBJECT_ACCESSIBLE (self));
385 if (nux_object == NULL) /* state is defunct */
386 return;
387
388 icon_accessible = unity_a11y_get_accessible (icon);
389
390 index = atk_object_get_index_in_parent (icon_accessible);
391
392 g_debug ("[a11y] icon (%p, %s) removed on container (%p,%s) at index %i",
393 icon_accessible, atk_object_get_name (icon_accessible),
394 self, atk_object_get_name (ATK_OBJECT (self)),
395 index);
396
397 g_signal_emit_by_name (self, "children-changed::remove",
398 index, icon_accessible, NULL);
399
400 update_children_index (self);
401}
402
403static void
404update_children_index (UnityLauncherAccessible *self)
405{
406 gint index = 0;
407 nux::Object *nux_object = NULL;
408 Launcher *launcher = NULL;
409 LauncherModel *launcher_model = NULL;
410 LauncherModel::iterator it;
411 nux::Object *child = NULL;
412 AtkObject *child_accessible = NULL;
413
414 nux_object = nux_object_accessible_get_object (NUX_OBJECT_ACCESSIBLE (self));
415 if (!nux_object) /* state is defunct */
416 return;
417
418 launcher = dynamic_cast<Launcher *>(nux_object);
419 launcher_model = launcher->GetModel ();
420
421 if (launcher_model == NULL)
422 return;
423
424 for (it = launcher_model->begin (); it != launcher_model->end (); it++)
425 {
426 child = dynamic_cast<nux::Object *>(*it);
427 child_accessible = unity_a11y_get_accessible (child);
428
429 unity_launcher_icon_accessible_set_index (UNITY_LAUNCHER_ICON_ACCESSIBLE (child_accessible),
430 index++);
431 }
432}
433
434static void
435on_order_change_cb (UnityLauncherAccessible *self)
436{
437 g_return_if_fail (UNITY_IS_LAUNCHER_ACCESSIBLE (self));
438
439 update_children_index (self);
440}
318441
=== modified file 'src/unity-launcher-icon-accessible.cpp'
--- src/unity-launcher-icon-accessible.cpp 2011-03-09 09:44:28 +0000
+++ src/unity-launcher-icon-accessible.cpp 2011-03-14 12:04:17 +0000
@@ -46,6 +46,7 @@
46static AtkStateSet* unity_launcher_icon_accessible_ref_state_set (AtkObject *obj);46static AtkStateSet* unity_launcher_icon_accessible_ref_state_set (AtkObject *obj);
47static const gchar * unity_launcher_icon_accessible_get_name (AtkObject *obj);47static const gchar * unity_launcher_icon_accessible_get_name (AtkObject *obj);
48static AtkObject * unity_launcher_icon_accessible_get_parent (AtkObject *obj);48static AtkObject * unity_launcher_icon_accessible_get_parent (AtkObject *obj);
49static gint unity_launcher_icon_accessible_get_index_in_parent (AtkObject *obj);
4950
50/* AtkComponent.h */51/* AtkComponent.h */
51static void atk_component_interface_init (AtkComponentIface *iface);52static void atk_component_interface_init (AtkComponentIface *iface);
@@ -79,6 +80,7 @@
79 /* Cached values (used to avoid extra notifications) */80 /* Cached values (used to avoid extra notifications) */
80 gboolean selected;81 gboolean selected;
81 gboolean parent_focused;82 gboolean parent_focused;
83 gboolean index_in_parent;
8284
83 guint on_parent_selection_change_id;85 guint on_parent_selection_change_id;
84 guint on_parent_focus_event_id;86 guint on_parent_focus_event_id;
@@ -97,6 +99,7 @@
97 atk_class->get_name = unity_launcher_icon_accessible_get_name;99 atk_class->get_name = unity_launcher_icon_accessible_get_name;
98 atk_class->ref_state_set = unity_launcher_icon_accessible_ref_state_set;100 atk_class->ref_state_set = unity_launcher_icon_accessible_ref_state_set;
99 atk_class->get_parent = unity_launcher_icon_accessible_get_parent;101 atk_class->get_parent = unity_launcher_icon_accessible_get_parent;
102 atk_class->get_index_in_parent = unity_launcher_icon_accessible_get_index_in_parent;
100103
101 g_type_class_add_private (gobject_class, sizeof (UnityLauncherIconAccessiblePrivate));104 g_type_class_add_private (gobject_class, sizeof (UnityLauncherIconAccessiblePrivate));
102}105}
@@ -281,6 +284,10 @@
281 gboolean found = FALSE;284 gboolean found = FALSE;
282285
283 nux_object = nux_object_accessible_get_object (NUX_OBJECT_ACCESSIBLE (self));286 nux_object = nux_object_accessible_get_object (NUX_OBJECT_ACCESSIBLE (self));
287
288 if (nux_object == NULL) /* state is defunct */
289 return;
290
284 icon = dynamic_cast<LauncherIcon *>(nux_object);291 icon = dynamic_cast<LauncherIcon *>(nux_object);
285 launcher = icon->GetLauncher ();292 launcher = icon->GetLauncher ();
286293
@@ -412,3 +419,21 @@
412419
413 atk_object_notify_state_change (accessible, ATK_STATE_FOCUSED, focus_in);420 atk_object_notify_state_change (accessible, ATK_STATE_FOCUSED, focus_in);
414}421}
422
423/* Public */
424static gint
425unity_launcher_icon_accessible_get_index_in_parent (AtkObject *obj)
426{
427 g_return_val_if_fail (UNITY_IS_LAUNCHER_ICON_ACCESSIBLE (obj), -1);
428
429 return UNITY_LAUNCHER_ICON_ACCESSIBLE (obj)->priv->index_in_parent;
430}
431
432void
433unity_launcher_icon_accessible_set_index (UnityLauncherIconAccessible *self,
434 gint index)
435{
436 g_return_if_fail (UNITY_IS_LAUNCHER_ICON_ACCESSIBLE (self));
437
438 self->priv->index_in_parent = index;
439}
415440
=== modified file 'src/unity-launcher-icon-accessible.h'
--- src/unity-launcher-icon-accessible.h 2011-02-27 00:17:03 +0000
+++ src/unity-launcher-icon-accessible.h 2011-03-14 12:04:17 +0000
@@ -52,6 +52,9 @@
52GType unity_launcher_icon_accessible_get_type (void);52GType unity_launcher_icon_accessible_get_type (void);
53AtkObject *unity_launcher_icon_accessible_new (nux::Object *object);53AtkObject *unity_launcher_icon_accessible_new (nux::Object *object);
5454
55void unity_launcher_icon_accessible_set_index (UnityLauncherIconAccessible *self,
56 gint index);
57
55G_END_DECLS58G_END_DECLS
5659
57#endif /* __UNITY_LAUNCHER_ICON_ACCESSIBLE_H__ */60#endif /* __UNITY_LAUNCHER_ICON_ACCESSIBLE_H__ */
5861
=== modified file 'src/unity-root-accessible.cpp'
--- src/unity-root-accessible.cpp 2011-02-27 16:16:02 +0000
+++ src/unity-root-accessible.cpp 2011-03-14 12:04:17 +0000
@@ -175,6 +175,7 @@
175 nux::BaseWindow *window)175 nux::BaseWindow *window)
176{176{
177 AtkObject *window_accessible = NULL;177 AtkObject *window_accessible = NULL;
178 gint index = 0;
178179
179 g_return_if_fail (UNITY_IS_ROOT_ACCESSIBLE (self));180 g_return_if_fail (UNITY_IS_ROOT_ACCESSIBLE (self));
180181
@@ -183,4 +184,9 @@
183184
184 self->priv->window_list =185 self->priv->window_list =
185 g_slist_append (self->priv->window_list, window_accessible);186 g_slist_append (self->priv->window_list, window_accessible);
187
188 index = g_slist_index (self->priv->window_list, window_accessible);
189
190 g_signal_emit_by_name (self, "children-changed::add",
191 index, window_accessible, NULL);
186}192}