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
1=== modified file 'src/unity-launcher-accessible.cpp'
2--- src/unity-launcher-accessible.cpp 2011-03-09 09:44:28 +0000
3+++ src/unity-launcher-accessible.cpp 2011-03-14 12:04:17 +0000
4@@ -31,6 +31,7 @@
5 #include <glib/gi18n.h>
6
7 #include "unity-launcher-accessible.h"
8+#include "unity-launcher-icon-accessible.h"
9
10 #include "unitya11y.h"
11 #include "Launcher.h"
12@@ -58,6 +59,10 @@
13
14 /* private */
15 static void on_selection_change_cb (UnityLauncherAccessible *launcher_accessible);
16+static void on_icon_added_cb (LauncherIcon *icon, UnityLauncherAccessible *self);
17+static void on_icon_removed_cb (LauncherIcon *icon, UnityLauncherAccessible *self);
18+static void on_order_change_cb (UnityLauncherAccessible *self);
19+static void update_children_index (UnityLauncherAccessible *self);
20
21
22 G_DEFINE_TYPE_WITH_CODE (UnityLauncherAccessible, unity_launcher_accessible, NUX_TYPE_VIEW_ACCESSIBLE,
23@@ -70,6 +75,9 @@
24 struct _UnityLauncherAccessiblePrivate
25 {
26 sigc::connection on_selection_change_connection;
27+ sigc::connection on_icon_added_connection;
28+ sigc::connection on_icon_removed_connection;
29+ sigc::connection on_order_changed_connection;
30 };
31
32
33@@ -104,6 +112,9 @@
34 UnityLauncherAccessible *self = UNITY_LAUNCHER_ACCESSIBLE (object);
35
36 self->priv->on_selection_change_connection.disconnect ();
37+ self->priv->on_icon_added_connection.disconnect ();
38+ self->priv->on_icon_removed_connection.disconnect ();
39+ self->priv->on_order_changed_connection.disconnect ();
40
41 G_OBJECT_CLASS (unity_launcher_accessible_parent_class)->finalize (object);
42 }
43@@ -131,6 +142,7 @@
44 Launcher *launcher = NULL;
45 nux::Object *nux_object = NULL;
46 UnityLauncherAccessible *self = NULL;
47+ LauncherModel *model = NULL;
48
49 ATK_OBJECT_CLASS (unity_launcher_accessible_parent_class)->initialize (accessible, data);
50
51@@ -143,6 +155,20 @@
52
53 self->priv->on_selection_change_connection =
54 launcher->selection_change.connect (sigc::bind (sigc::ptr_fun (on_selection_change_cb), self));
55+
56+ model = launcher->GetModel ();
57+
58+ if (model)
59+ {
60+ self->priv->on_icon_added_connection =
61+ model->icon_added.connect (sigc::bind (sigc::ptr_fun (on_icon_added_cb), self));
62+
63+ self->priv->on_icon_removed_connection =
64+ model->icon_removed.connect (sigc::bind (sigc::ptr_fun (on_icon_removed_cb), self));
65+
66+ self->priv->on_order_changed_connection =
67+ model->order_changed.connect (sigc::bind (sigc::ptr_fun (on_order_change_cb), self));
68+ }
69 }
70
71 static gint
72@@ -315,3 +341,100 @@
73 g_signal_emit_by_name (ATK_OBJECT (launcher_accessible), "selection-changed");
74 }
75
76+
77+static void
78+on_icon_added_cb (LauncherIcon *icon,
79+ UnityLauncherAccessible *self)
80+{
81+ AtkObject *icon_accessible = NULL;
82+ nux::Object *nux_object = NULL;
83+ gint index = 0;
84+
85+ g_return_if_fail (UNITY_IS_LAUNCHER_ACCESSIBLE (self));
86+
87+ nux_object = nux_object_accessible_get_object (NUX_OBJECT_ACCESSIBLE (self));
88+ if (nux_object == NULL) /* state is defunct */
89+ return;
90+
91+ icon_accessible = unity_a11y_get_accessible (icon);
92+
93+ update_children_index (self);
94+
95+ index = atk_object_get_index_in_parent (icon_accessible);
96+
97+ g_debug ("[a11y] icon (%p, %s) added on container (%p,%s) at index %i",
98+ icon_accessible, atk_object_get_name (icon_accessible),
99+ self, atk_object_get_name ( ATK_OBJECT (self)),
100+ index);
101+
102+ g_signal_emit_by_name (self, "children-changed::add",
103+ index, icon_accessible, NULL);
104+}
105+
106+static void
107+on_icon_removed_cb (LauncherIcon *icon,
108+ UnityLauncherAccessible *self)
109+{
110+ AtkObject *icon_accessible = NULL;
111+ nux::Object *nux_object = NULL;
112+ gint index = 0;
113+
114+ g_return_if_fail (UNITY_IS_LAUNCHER_ACCESSIBLE (self));
115+
116+ nux_object = nux_object_accessible_get_object (NUX_OBJECT_ACCESSIBLE (self));
117+ if (nux_object == NULL) /* state is defunct */
118+ return;
119+
120+ icon_accessible = unity_a11y_get_accessible (icon);
121+
122+ index = atk_object_get_index_in_parent (icon_accessible);
123+
124+ g_debug ("[a11y] icon (%p, %s) removed on container (%p,%s) at index %i",
125+ icon_accessible, atk_object_get_name (icon_accessible),
126+ self, atk_object_get_name (ATK_OBJECT (self)),
127+ index);
128+
129+ g_signal_emit_by_name (self, "children-changed::remove",
130+ index, icon_accessible, NULL);
131+
132+ update_children_index (self);
133+}
134+
135+static void
136+update_children_index (UnityLauncherAccessible *self)
137+{
138+ gint index = 0;
139+ nux::Object *nux_object = NULL;
140+ Launcher *launcher = NULL;
141+ LauncherModel *launcher_model = NULL;
142+ LauncherModel::iterator it;
143+ nux::Object *child = NULL;
144+ AtkObject *child_accessible = NULL;
145+
146+ nux_object = nux_object_accessible_get_object (NUX_OBJECT_ACCESSIBLE (self));
147+ if (!nux_object) /* state is defunct */
148+ return;
149+
150+ launcher = dynamic_cast<Launcher *>(nux_object);
151+ launcher_model = launcher->GetModel ();
152+
153+ if (launcher_model == NULL)
154+ return;
155+
156+ for (it = launcher_model->begin (); it != launcher_model->end (); it++)
157+ {
158+ child = dynamic_cast<nux::Object *>(*it);
159+ child_accessible = unity_a11y_get_accessible (child);
160+
161+ unity_launcher_icon_accessible_set_index (UNITY_LAUNCHER_ICON_ACCESSIBLE (child_accessible),
162+ index++);
163+ }
164+}
165+
166+static void
167+on_order_change_cb (UnityLauncherAccessible *self)
168+{
169+ g_return_if_fail (UNITY_IS_LAUNCHER_ACCESSIBLE (self));
170+
171+ update_children_index (self);
172+}
173
174=== modified file 'src/unity-launcher-icon-accessible.cpp'
175--- src/unity-launcher-icon-accessible.cpp 2011-03-09 09:44:28 +0000
176+++ src/unity-launcher-icon-accessible.cpp 2011-03-14 12:04:17 +0000
177@@ -46,6 +46,7 @@
178 static AtkStateSet* unity_launcher_icon_accessible_ref_state_set (AtkObject *obj);
179 static const gchar * unity_launcher_icon_accessible_get_name (AtkObject *obj);
180 static AtkObject * unity_launcher_icon_accessible_get_parent (AtkObject *obj);
181+static gint unity_launcher_icon_accessible_get_index_in_parent (AtkObject *obj);
182
183 /* AtkComponent.h */
184 static void atk_component_interface_init (AtkComponentIface *iface);
185@@ -79,6 +80,7 @@
186 /* Cached values (used to avoid extra notifications) */
187 gboolean selected;
188 gboolean parent_focused;
189+ gboolean index_in_parent;
190
191 guint on_parent_selection_change_id;
192 guint on_parent_focus_event_id;
193@@ -97,6 +99,7 @@
194 atk_class->get_name = unity_launcher_icon_accessible_get_name;
195 atk_class->ref_state_set = unity_launcher_icon_accessible_ref_state_set;
196 atk_class->get_parent = unity_launcher_icon_accessible_get_parent;
197+ atk_class->get_index_in_parent = unity_launcher_icon_accessible_get_index_in_parent;
198
199 g_type_class_add_private (gobject_class, sizeof (UnityLauncherIconAccessiblePrivate));
200 }
201@@ -281,6 +284,10 @@
202 gboolean found = FALSE;
203
204 nux_object = nux_object_accessible_get_object (NUX_OBJECT_ACCESSIBLE (self));
205+
206+ if (nux_object == NULL) /* state is defunct */
207+ return;
208+
209 icon = dynamic_cast<LauncherIcon *>(nux_object);
210 launcher = icon->GetLauncher ();
211
212@@ -412,3 +419,21 @@
213
214 atk_object_notify_state_change (accessible, ATK_STATE_FOCUSED, focus_in);
215 }
216+
217+/* Public */
218+static gint
219+unity_launcher_icon_accessible_get_index_in_parent (AtkObject *obj)
220+{
221+ g_return_val_if_fail (UNITY_IS_LAUNCHER_ICON_ACCESSIBLE (obj), -1);
222+
223+ return UNITY_LAUNCHER_ICON_ACCESSIBLE (obj)->priv->index_in_parent;
224+}
225+
226+void
227+unity_launcher_icon_accessible_set_index (UnityLauncherIconAccessible *self,
228+ gint index)
229+{
230+ g_return_if_fail (UNITY_IS_LAUNCHER_ICON_ACCESSIBLE (self));
231+
232+ self->priv->index_in_parent = index;
233+}
234
235=== modified file 'src/unity-launcher-icon-accessible.h'
236--- src/unity-launcher-icon-accessible.h 2011-02-27 00:17:03 +0000
237+++ src/unity-launcher-icon-accessible.h 2011-03-14 12:04:17 +0000
238@@ -52,6 +52,9 @@
239 GType unity_launcher_icon_accessible_get_type (void);
240 AtkObject *unity_launcher_icon_accessible_new (nux::Object *object);
241
242+void unity_launcher_icon_accessible_set_index (UnityLauncherIconAccessible *self,
243+ gint index);
244+
245 G_END_DECLS
246
247 #endif /* __UNITY_LAUNCHER_ICON_ACCESSIBLE_H__ */
248
249=== modified file 'src/unity-root-accessible.cpp'
250--- src/unity-root-accessible.cpp 2011-02-27 16:16:02 +0000
251+++ src/unity-root-accessible.cpp 2011-03-14 12:04:17 +0000
252@@ -175,6 +175,7 @@
253 nux::BaseWindow *window)
254 {
255 AtkObject *window_accessible = NULL;
256+ gint index = 0;
257
258 g_return_if_fail (UNITY_IS_ROOT_ACCESSIBLE (self));
259
260@@ -183,4 +184,9 @@
261
262 self->priv->window_list =
263 g_slist_append (self->priv->window_list, window_accessible);
264+
265+ index = g_slist_index (self->priv->window_list, window_accessible);
266+
267+ g_signal_emit_by_name (self, "children-changed::add",
268+ index, window_accessible, NULL);
269 }