Merge lp:~alanbell/compiz/texttracking into lp:compiz/0.9.8
- texttracking
- Merge into 0.9.8
Status: | Work in progress | ||||
---|---|---|---|---|---|
Proposed branch: | lp:~alanbell/compiz/texttracking | ||||
Merge into: | lp:compiz/0.9.8 | ||||
Diff against target: |
1249 lines (+1101/-2) 13 files modified
plugins/accessibility/AUTHORS (+1/-0) plugins/accessibility/CMakeLists.txt (+5/-0) plugins/accessibility/VERSION (+1/-0) plugins/accessibility/accessibility.xml.in (+17/-0) plugins/accessibility/compiz-accessibility.pc.in (+12/-0) plugins/accessibility/include/accessibility/accessibility.h (+217/-0) plugins/accessibility/src/accessibility.cpp (+651/-0) plugins/accessibility/src/private.h (+113/-0) plugins/ezoom/CMakeLists.txt (+1/-1) plugins/ezoom/ezoom.xml.in (+2/-0) plugins/ezoom/src/ezoom.cpp (+71/-0) plugins/ezoom/src/ezoom.h (+9/-0) plugins/mousepoll/mousepoll.xml.in (+1/-1) |
||||
To merge this branch: | bzr merge lp:~alanbell/compiz/texttracking | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel van Vugt | Needs Fixing | ||
Sam Spilsbury | Needs Fixing | ||
Review via email: mp+111710@code.launchpad.net |
Commit message
Description of the change
merges in code from
https:/
https:/
fixing lp:#727290
it compiles, might have an additional dependency on at-spi stuff, I don't know how to merge it with the debian packaging to make an installable package.
Sam Spilsbury (smspillaz) wrote : | # |
Oh yeah, totally forgot! Tests...
Generally speaking, I prefer all code going into compiz to come with unit tests. I don't think getting this particular code under test will be that difficult. The majority of the a11y code looks like its just wrappers for managing objects coming to us from AT-SPI.
Stuff that I think needs to be tested (or needs to be deleted, since it looks unused):
206 + virtual bool
207 + load (AtspiAccessible *);
208 +
209 + virtual bool
210 + contains (AccessibilityE
211 +
Actually they can be deleted completely as they are unused. But...
236 + CompRect
237 + getExtents () const;
238 +
239 + CompPoint
240 + getPosition () const;
241 +
242 + CompPoint
243 + getSize () const;
I am like 99% sure the second two are unused.
The relationship between getExtents and this:
1214 + if (optionGetZoomMode () == EzoomOptions:
1215 + {
1216 + ensureVisibilit
1217 + rect.y1(),
1218 + rect.x2(),
1219 + rect.y2(),
1220 + optionGetRestra
1221 + NORTHWEST);
1222 + }
Or, a potential getZoomCenterArea () needs to come under test
As well as:
267 + CompRect
268 + getCharacterExtents (int) const;
269 +
270 + CompRect
271 + getRangeExtents (int) const;
272 +
273 + int
274 + getCaretOffset ();
(getRangeExtents can be deleted)
But the relationship between the first and the third needs to be tested. That means breaking the dependency on
654 + AtspiRect *character_rect = atspi_text_
655 + (text, offset, ATSPI_COORD_
through an interface by which AtspiRect can be manipulated and atspi_text_
Then you can use Mock Objects to verify the behaviour of getCharacterExtents and the resulting zoom rect.
Feel free to poke with questions on IRC. I'm on planes for the next two days, but I can be found on freenode (nick: smspillaz)
Daniel van Vugt (vanvugt) wrote : | # |
Please review and fix the indentation and style again. For example:
135 + virtual IfaceType
136 + is ();
137 +
138 + virtual AccessibilityEntity *
139 + clone () const;
140 +
141 + AtspiAccessible *
142 + getObject ();
should be more like:
virtual IfaceType is ();
virtual AccessibilityEntity *clone () const;
AtspiAccessible *getObject ();
And the same applies elsewhere.
Daniel van Vugt (vanvugt) wrote : | # |
When done, please click Resubmit so we get notified.
Daniel van Vugt (vanvugt) wrote : | # |
Please also click "Set commit message" when done so the automerger doesn't reject it once approved by us.
Sam Spilsbury (smspillaz) wrote : | # |
(This will be looked at and I will propose a merge to fix some of the overarching design issues once the gles2 and gsettings work is done)
Alan Bell (alanbell) wrote : | # |
I will have a go at the indentation issues, but I am a bit out of my depth on the refactoring, this isn't my code, I am just trying to integrate it into the upstream tree, I will try and contact gloob https:/
Alejandro Leiva (gloob) wrote : | # |
Hi guys, thanks for working on this.
As Sam pointed out before there's some methods, classes and structures that I'm not using in the plugin. In fact I'm not happy with the global architecture. A refactor is needed. I'll do.
Alan if you can grant me write access to your branch I won't need to create a new branch and merge and so on.
Cheers.
Alan Bell (alanbell) wrote : | # |
thanks Alejandro,
I don't think I can give you write access to my branch, but you can probably do
bzr branch lp:~alanbell/compiz/texttracking
bzr push lp:~gloob/compiz/texttracking
and then do a merge request from there
Unmerged revisions
- 3256. By Alan Bell
-
indentation issue
- 3255. By Alan Bell
-
remove message
- 3254. By Alan Bell
-
remove README and fix indentation
- 3253. By Alan Bell
-
renamed the accessibility plugin folder and fixed an unused variable in ezoom
- 3252. By Alan Bell
-
merging in text tracking zoom work by Alejandro Leiva
https://github. com/gloob/ compiz- accessibility- plugin
https://github. com/gloob/ gloob-Ezoom- fork
Preview Diff
1 | === added directory 'plugins/accessibility' | |||
2 | === added file 'plugins/accessibility/AUTHORS' | |||
3 | --- plugins/accessibility/AUTHORS 1970-01-01 00:00:00 +0000 | |||
4 | +++ plugins/accessibility/AUTHORS 2012-06-23 15:04:23 +0000 | |||
5 | @@ -0,0 +1,1 @@ | |||
6 | 1 | Alejandro Leiva <aleiva@emergya.com> | ||
7 | 0 | 2 | ||
8 | === added file 'plugins/accessibility/CMakeLists.txt' | |||
9 | --- plugins/accessibility/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
10 | +++ plugins/accessibility/CMakeLists.txt 2012-06-23 15:04:23 +0000 | |||
11 | @@ -0,0 +1,5 @@ | |||
12 | 1 | find_package (Compiz REQUIRED) | ||
13 | 2 | |||
14 | 3 | include (CompizPlugin) | ||
15 | 4 | |||
16 | 5 | compiz_plugin (accessibility PKGDEPS atspi-2) | ||
17 | 0 | 6 | ||
18 | === added file 'plugins/accessibility/ChangeLog' | |||
19 | === added file 'plugins/accessibility/NEWS' | |||
20 | === added file 'plugins/accessibility/VERSION' | |||
21 | --- plugins/accessibility/VERSION 1970-01-01 00:00:00 +0000 | |||
22 | +++ plugins/accessibility/VERSION 2012-06-23 15:04:23 +0000 | |||
23 | @@ -0,0 +1,1 @@ | |||
24 | 1 | 0.9.5.0 | ||
25 | 0 | 2 | ||
26 | === added file 'plugins/accessibility/accessibility.xml.in' | |||
27 | --- plugins/accessibility/accessibility.xml.in 1970-01-01 00:00:00 +0000 | |||
28 | +++ plugins/accessibility/accessibility.xml.in 2012-06-23 15:04:23 +0000 | |||
29 | @@ -0,0 +1,17 @@ | |||
30 | 1 | <?xml version="1.0"?> | ||
31 | 2 | <compiz> | ||
32 | 3 | <plugin name="accessibility" useBcop="true"> | ||
33 | 4 | <_short>Accessibility</_short> | ||
34 | 5 | <_long>Activate compatibility with accessibility layer.</_long> | ||
35 | 6 | <category>Accessibility</category> | ||
36 | 7 | <deps> | ||
37 | 8 | <relation type="after"> | ||
38 | 9 | <plugin>opengl</plugin> | ||
39 | 10 | <plugin>composite</plugin> | ||
40 | 11 | <plugin>decor</plugin> | ||
41 | 12 | </relation> | ||
42 | 13 | </deps> | ||
43 | 14 | <options> | ||
44 | 15 | </options> | ||
45 | 16 | </plugin> | ||
46 | 17 | </compiz> | ||
47 | 0 | 18 | ||
48 | === added file 'plugins/accessibility/compiz-accessibility.pc.in' | |||
49 | --- plugins/accessibility/compiz-accessibility.pc.in 1970-01-01 00:00:00 +0000 | |||
50 | +++ plugins/accessibility/compiz-accessibility.pc.in 2012-06-23 15:04:23 +0000 | |||
51 | @@ -0,0 +1,12 @@ | |||
52 | 1 | prefix=@prefix@ | ||
53 | 2 | exec_prefix=@prefix@ | ||
54 | 3 | libdir=@libdir@ | ||
55 | 4 | includedir=@includedir@ | ||
56 | 5 | |||
57 | 6 | Name: compiz-accessibility | ||
58 | 7 | Description: Accessibility (based in AT-SPI2) plugin for compiz | ||
59 | 8 | Version: @VERSION@ | ||
60 | 9 | |||
61 | 10 | Requires: compiz | ||
62 | 11 | Libs: -L${libdir}/compiz -laccessibility | ||
63 | 12 | Cflags: @COMPIZ_CFLAGS@ -I${includedir}/compiz | ||
64 | 0 | 13 | ||
65 | === added directory 'plugins/accessibility/include' | |||
66 | === added directory 'plugins/accessibility/include/accessibility' | |||
67 | === added file 'plugins/accessibility/include/accessibility/accessibility.h' | |||
68 | --- plugins/accessibility/include/accessibility/accessibility.h 1970-01-01 00:00:00 +0000 | |||
69 | +++ plugins/accessibility/include/accessibility/accessibility.h 2012-06-23 15:04:23 +0000 | |||
70 | @@ -0,0 +1,217 @@ | |||
71 | 1 | /* | ||
72 | 2 | * Compiz Accessibility PLugin | ||
73 | 3 | * | ||
74 | 4 | * Copyright (c) 2011 F123 Consulting & Mais Diferenças | ||
75 | 5 | * | ||
76 | 6 | * This program is free software; you can redistribute it and/or | ||
77 | 7 | * modify it under the terms of the GNU General Public License | ||
78 | 8 | * as published by the Free Software Foundation; either version 2 | ||
79 | 9 | * of the License, or (at your option) any later version. | ||
80 | 10 | * | ||
81 | 11 | * This program is distributed in the hope that it will be useful, | ||
82 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
83 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
84 | 14 | * GNU General Public License for more details. | ||
85 | 15 | * | ||
86 | 16 | * Author: Alejandro Leiva <aleiva@emergya.com> | ||
87 | 17 | * | ||
88 | 18 | */ | ||
89 | 19 | |||
90 | 20 | #ifndef _ACCESSIBILITY_H | ||
91 | 21 | #define _ACCESSIBILITY_H | ||
92 | 22 | |||
93 | 23 | #ifdef __cplusplus | ||
94 | 24 | extern "C" { | ||
95 | 25 | #endif | ||
96 | 26 | #include <atspi/atspi.h> | ||
97 | 27 | #ifdef __cplusplus | ||
98 | 28 | } | ||
99 | 29 | #endif | ||
100 | 30 | |||
101 | 31 | /* | ||
102 | 32 | * Class hierarchy that hold and manage differents accessible objects. | ||
103 | 33 | */ | ||
104 | 34 | enum IfaceType | ||
105 | 35 | { | ||
106 | 36 | Accessible = 0, | ||
107 | 37 | Action, | ||
108 | 38 | Collection, | ||
109 | 39 | Component, | ||
110 | 40 | Document, | ||
111 | 41 | EditableText, | ||
112 | 42 | Hypertext, | ||
113 | 43 | Hyperlink, | ||
114 | 44 | Image, | ||
115 | 45 | Selection, | ||
116 | 46 | Table, | ||
117 | 47 | Text, | ||
118 | 48 | Value, | ||
119 | 49 | }; | ||
120 | 50 | |||
121 | 51 | class AccessibilityEntity | ||
122 | 52 | { | ||
123 | 53 | public: | ||
124 | 54 | typedef boost::shared_ptr<AccessibilityEntity> Ptr; | ||
125 | 55 | |||
126 | 56 | AccessibilityEntity (AtspiAccessible *); | ||
127 | 57 | virtual ~AccessibilityEntity (); | ||
128 | 58 | |||
129 | 59 | virtual bool | ||
130 | 60 | load (AtspiAccessible *); | ||
131 | 61 | |||
132 | 62 | virtual bool | ||
133 | 63 | contains (AccessibilityEntity *, int, int); | ||
134 | 64 | |||
135 | 65 | virtual IfaceType | ||
136 | 66 | is (); | ||
137 | 67 | |||
138 | 68 | virtual AccessibilityEntity * | ||
139 | 69 | clone () const; | ||
140 | 70 | |||
141 | 71 | AtspiAccessible * | ||
142 | 72 | getObject (); | ||
143 | 73 | |||
144 | 74 | protected: | ||
145 | 75 | AtspiAccessible * obj; | ||
146 | 76 | }; | ||
147 | 77 | |||
148 | 78 | class AccessibilityComponent : | ||
149 | 79 | public AccessibilityEntity | ||
150 | 80 | { | ||
151 | 81 | public: | ||
152 | 82 | typedef boost::shared_ptr<AccessibilityComponent> Ptr; | ||
153 | 83 | |||
154 | 84 | AccessibilityComponent (AtspiAccessible *); | ||
155 | 85 | |||
156 | 86 | virtual AccessibilityComponent * | ||
157 | 87 | clone () const; | ||
158 | 88 | |||
159 | 89 | CompRect | ||
160 | 90 | getExtents () const; | ||
161 | 91 | |||
162 | 92 | CompPoint | ||
163 | 93 | getPosition () const; | ||
164 | 94 | |||
165 | 95 | CompPoint | ||
166 | 96 | getSize () const; | ||
167 | 97 | |||
168 | 98 | virtual IfaceType | ||
169 | 99 | is (); | ||
170 | 100 | |||
171 | 101 | /* TODO: Implement based in a compiz layer type. | ||
172 | 102 | CompLayer | ||
173 | 103 | getLayer (); | ||
174 | 104 | */ | ||
175 | 105 | protected: | ||
176 | 106 | AtspiComponent *component; | ||
177 | 107 | }; | ||
178 | 108 | |||
179 | 109 | class AccessibilityText : | ||
180 | 110 | public AccessibilityEntity | ||
181 | 111 | { | ||
182 | 112 | public: | ||
183 | 113 | typedef boost::shared_ptr<AccessibilityText> Ptr; | ||
184 | 114 | |||
185 | 115 | AccessibilityText (AtspiAccessible *); | ||
186 | 116 | |||
187 | 117 | virtual AccessibilityText * | ||
188 | 118 | clone () const; | ||
189 | 119 | |||
190 | 120 | CompRect | ||
191 | 121 | getCharacterExtents (int) const; | ||
192 | 122 | |||
193 | 123 | CompRect | ||
194 | 124 | getRangeExtents (int) const; | ||
195 | 125 | |||
196 | 126 | int | ||
197 | 127 | getCaretOffset (); | ||
198 | 128 | |||
199 | 129 | virtual IfaceType | ||
200 | 130 | is (); | ||
201 | 131 | |||
202 | 132 | protected: | ||
203 | 133 | AtspiText *text; | ||
204 | 134 | }; | ||
205 | 135 | |||
206 | 136 | class AccessibleObject | ||
207 | 137 | { | ||
208 | 138 | public: | ||
209 | 139 | typedef std::vector <AccessibilityEntity::Ptr> Entities; | ||
210 | 140 | typedef std::vector <IfaceType> Interfaces; | ||
211 | 141 | |||
212 | 142 | AccessibleObject (AtspiAccessible *); | ||
213 | 143 | |||
214 | 144 | AccessibleObject::Entities | ||
215 | 145 | create (AtspiAccessible *); | ||
216 | 146 | |||
217 | 147 | AccessibilityEntity::Ptr | ||
218 | 148 | get (IfaceType); | ||
219 | 149 | |||
220 | 150 | bool | ||
221 | 151 | is (IfaceType); | ||
222 | 152 | |||
223 | 153 | AccessibilityEntity::Ptr | ||
224 | 154 | getEntity (IfaceType); | ||
225 | 155 | |||
226 | 156 | private: | ||
227 | 157 | AccessibilityEntity::Ptr | ||
228 | 158 | instantiate (AtspiAccessible *, IfaceType); | ||
229 | 159 | |||
230 | 160 | static IfaceType | ||
231 | 161 | enumFromStr (const char *); | ||
232 | 162 | |||
233 | 163 | int | ||
234 | 164 | getIfaceIndex (IfaceType); | ||
235 | 165 | |||
236 | 166 | private: | ||
237 | 167 | Entities ents; | ||
238 | 168 | Interfaces interfaces; | ||
239 | 169 | AtspiAccessible * obj; | ||
240 | 170 | }; | ||
241 | 171 | |||
242 | 172 | class AccessibilityEvent | ||
243 | 173 | { | ||
244 | 174 | public: | ||
245 | 175 | AccessibilityEvent (const AtspiEvent *); | ||
246 | 176 | ~AccessibilityEvent (); | ||
247 | 177 | |||
248 | 178 | const char * | ||
249 | 179 | getType (); | ||
250 | 180 | |||
251 | 181 | AccessibleObject * | ||
252 | 182 | getAccessibleObject (); | ||
253 | 183 | |||
254 | 184 | private: | ||
255 | 185 | const AtspiEvent *event; | ||
256 | 186 | AccessibleObject *object; | ||
257 | 187 | |||
258 | 188 | }; | ||
259 | 189 | |||
260 | 190 | typedef boost::function<void (AccessibilityEvent *)> AccessibilityEventCallback; | ||
261 | 191 | |||
262 | 192 | class Accessibility | ||
263 | 193 | { | ||
264 | 194 | public: | ||
265 | 195 | |||
266 | 196 | Accessibility (); | ||
267 | 197 | ~Accessibility (); | ||
268 | 198 | |||
269 | 199 | bool | ||
270 | 200 | start (); | ||
271 | 201 | |||
272 | 202 | bool | ||
273 | 203 | stop (); | ||
274 | 204 | |||
275 | 205 | bool | ||
276 | 206 | active (); | ||
277 | 207 | |||
278 | 208 | bool | ||
279 | 209 | registerEventHandler (const char *, AccessibilityEventCallback); | ||
280 | 210 | |||
281 | 211 | void | ||
282 | 212 | unregisterAll (); | ||
283 | 213 | |||
284 | 214 | friend class AccessibilityScreen; | ||
285 | 215 | }; | ||
286 | 216 | |||
287 | 217 | #endif // _ACCESSIBILITY_H | ||
288 | 0 | 218 | ||
289 | === added directory 'plugins/accessibility/src' | |||
290 | === added file 'plugins/accessibility/src/accessibility.cpp' | |||
291 | --- plugins/accessibility/src/accessibility.cpp 1970-01-01 00:00:00 +0000 | |||
292 | +++ plugins/accessibility/src/accessibility.cpp 2012-06-23 15:04:23 +0000 | |||
293 | @@ -0,0 +1,651 @@ | |||
294 | 1 | /* | ||
295 | 2 | * Compiz Accessibility PLugin | ||
296 | 3 | * | ||
297 | 4 | * Copyright (c) 2011 F123 Consulting & Mais Diferenças | ||
298 | 5 | * | ||
299 | 6 | * This program is free software; you can redistribute it and/or | ||
300 | 7 | * modify it under the terms of the GNU General Public License | ||
301 | 8 | * as published by the Free Software Foundation; either version 2 | ||
302 | 9 | * of the License, or (at your option) any later version. | ||
303 | 10 | * | ||
304 | 11 | * This program is distributed in the hope that it will be useful, | ||
305 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
306 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
307 | 14 | * GNU General Public License for more details. | ||
308 | 15 | * | ||
309 | 16 | * Author: Alejandro Leiva <aleiva@emergya.com> | ||
310 | 17 | * | ||
311 | 18 | */ | ||
312 | 19 | |||
313 | 20 | #include "private.h" | ||
314 | 21 | |||
315 | 22 | COMPIZ_PLUGIN_20090315 (accessibility, AccessibilityPluginVTable); | ||
316 | 23 | |||
317 | 24 | AccessibleObject::AccessibleObject (AtspiAccessible *object) | ||
318 | 25 | { | ||
319 | 26 | compLogMessage ("Accessibility", CompLogLevelInfo, | ||
320 | 27 | "AccessibleObject::AccessibleObject (%s)\n", object->name); | ||
321 | 28 | |||
322 | 29 | obj = object; | ||
323 | 30 | |||
324 | 31 | create (object); | ||
325 | 32 | } | ||
326 | 33 | |||
327 | 34 | AccessibleObject::Entities | ||
328 | 35 | AccessibleObject::create (AtspiAccessible *object) | ||
329 | 36 | { | ||
330 | 37 | GArray * ifaces = atspi_accessible_get_interfaces (object); | ||
331 | 38 | |||
332 | 39 | int len = (int) ifaces->len; | ||
333 | 40 | |||
334 | 41 | for (int i = 0; i < len; i++) | ||
335 | 42 | { | ||
336 | 43 | |||
337 | 44 | char *iface = (char *) g_array_index (ifaces, gchar *, i); | ||
338 | 45 | |||
339 | 46 | interfaces.push_back (enumFromStr (iface)); | ||
340 | 47 | // Defer the creation of the AccessibilityEntity structure. | ||
341 | 48 | // TODO: Create a new method to create it from AccessibleObject. | ||
342 | 49 | //ents.push_back (instantiate (object, iface)); | ||
343 | 50 | } | ||
344 | 51 | |||
345 | 52 | g_array_free (ifaces, TRUE); | ||
346 | 53 | |||
347 | 54 | return ents; | ||
348 | 55 | } | ||
349 | 56 | |||
350 | 57 | AccessibilityEntity::Ptr | ||
351 | 58 | AccessibleObject::instantiate (AtspiAccessible *object, IfaceType iface) | ||
352 | 59 | { | ||
353 | 60 | AccessibilityEntity::Ptr entity; | ||
354 | 61 | |||
355 | 62 | switch (iface) | ||
356 | 63 | { | ||
357 | 64 | |||
358 | 65 | case Component: | ||
359 | 66 | entity = AccessibilityEntity::Ptr (new AccessibilityComponent (object)); | ||
360 | 67 | break; | ||
361 | 68 | |||
362 | 69 | case Text: | ||
363 | 70 | entity = AccessibilityEntity::Ptr (new AccessibilityText (object)); | ||
364 | 71 | break; | ||
365 | 72 | |||
366 | 73 | case Accessible: | ||
367 | 74 | case Action: | ||
368 | 75 | case Collection: | ||
369 | 76 | case Document: | ||
370 | 77 | case EditableText: | ||
371 | 78 | case Hypertext: | ||
372 | 79 | case Hyperlink: | ||
373 | 80 | case Image: | ||
374 | 81 | case Selection: | ||
375 | 82 | case Table: | ||
376 | 83 | case Value: | ||
377 | 84 | break; | ||
378 | 85 | |||
379 | 86 | default: | ||
380 | 87 | entity = AccessibilityEntity::Ptr (new AccessibilityEntity (object)); | ||
381 | 88 | } | ||
382 | 89 | |||
383 | 90 | return entity; | ||
384 | 91 | } | ||
385 | 92 | |||
386 | 93 | IfaceType | ||
387 | 94 | AccessibleObject::enumFromStr (const char *str) | ||
388 | 95 | { | ||
389 | 96 | |||
390 | 97 | for (int i = 0; i < NUM_IFACES_SUPPORTED; i++) | ||
391 | 98 | if (!strcmp (IfaceTypeStr[i], str)) | ||
392 | 99 | return (IfaceType) i; | ||
393 | 100 | |||
394 | 101 | return Accessible; | ||
395 | 102 | } | ||
396 | 103 | |||
397 | 104 | AccessibilityEntity::Ptr | ||
398 | 105 | AccessibleObject::get (IfaceType type) | ||
399 | 106 | { | ||
400 | 107 | int index = getIfaceIndex (type); | ||
401 | 108 | compLogMessage ("Accessibility", CompLogLevelInfo, "AccessibleObject::get(%s) = %d\n", | ||
402 | 109 | type, index); | ||
403 | 110 | |||
404 | 111 | if (index < 0) | ||
405 | 112 | return AccessibilityEntity::Ptr (); | ||
406 | 113 | |||
407 | 114 | return ents[index]; | ||
408 | 115 | } | ||
409 | 116 | |||
410 | 117 | bool | ||
411 | 118 | AccessibleObject::is (IfaceType type) | ||
412 | 119 | { | ||
413 | 120 | int index = getIfaceIndex (type); | ||
414 | 121 | |||
415 | 122 | if (index < 0) | ||
416 | 123 | return false; | ||
417 | 124 | |||
418 | 125 | return true; | ||
419 | 126 | } | ||
420 | 127 | |||
421 | 128 | int | ||
422 | 129 | AccessibleObject::getIfaceIndex (IfaceType type) | ||
423 | 130 | { | ||
424 | 131 | for (int i = 0; i < (int) interfaces.size(); i++) | ||
425 | 132 | { | ||
426 | 133 | if (type == interfaces[i]) | ||
427 | 134 | return i; | ||
428 | 135 | } | ||
429 | 136 | |||
430 | 137 | return -1; | ||
431 | 138 | } | ||
432 | 139 | |||
433 | 140 | AccessibilityEntity::Ptr | ||
434 | 141 | AccessibleObject::getEntity (IfaceType type) | ||
435 | 142 | { | ||
436 | 143 | return instantiate (obj, type); | ||
437 | 144 | } | ||
438 | 145 | |||
439 | 146 | |||
440 | 147 | AccessibilityEntity::AccessibilityEntity (AtspiAccessible *object) | ||
441 | 148 | { | ||
442 | 149 | obj = object; | ||
443 | 150 | } | ||
444 | 151 | |||
445 | 152 | AccessibilityEntity::~AccessibilityEntity () { | ||
446 | 153 | |||
447 | 154 | } | ||
448 | 155 | |||
449 | 156 | bool | ||
450 | 157 | AccessibilityEntity::load (AtspiAccessible *object) | ||
451 | 158 | { | ||
452 | 159 | return true; | ||
453 | 160 | } | ||
454 | 161 | |||
455 | 162 | bool | ||
456 | 163 | AccessibilityEntity::contains (AccessibilityEntity *entity, int x, int y) | ||
457 | 164 | { | ||
458 | 165 | return true; | ||
459 | 166 | } | ||
460 | 167 | |||
461 | 168 | IfaceType | ||
462 | 169 | AccessibilityEntity::is () | ||
463 | 170 | { | ||
464 | 171 | return Accessible; | ||
465 | 172 | } | ||
466 | 173 | |||
467 | 174 | AccessibilityEntity * | ||
468 | 175 | AccessibilityEntity::clone () const | ||
469 | 176 | { | ||
470 | 177 | return new AccessibilityEntity (obj); | ||
471 | 178 | } | ||
472 | 179 | |||
473 | 180 | AtspiAccessible * | ||
474 | 181 | AccessibilityEntity::getObject () { | ||
475 | 182 | return obj; | ||
476 | 183 | } | ||
477 | 184 | |||
478 | 185 | |||
479 | 186 | AccessibilityComponent::AccessibilityComponent (AtspiAccessible *obj) : | ||
480 | 187 | AccessibilityEntity (obj) | ||
481 | 188 | { | ||
482 | 189 | compLogMessage ("Accessibility", CompLogLevelInfo, | ||
483 | 190 | "AccessibilityComponent::AccessibilityComponent (%s)\n", obj->name); | ||
484 | 191 | |||
485 | 192 | component = atspi_accessible_get_component (obj); | ||
486 | 193 | } | ||
487 | 194 | |||
488 | 195 | AccessibilityComponent * | ||
489 | 196 | AccessibilityComponent::clone () const | ||
490 | 197 | { | ||
491 | 198 | return new AccessibilityComponent (obj); | ||
492 | 199 | } | ||
493 | 200 | |||
494 | 201 | CompRect | ||
495 | 202 | AccessibilityComponent::getExtents () const | ||
496 | 203 | { | ||
497 | 204 | CompRect rect; | ||
498 | 205 | GError *error = NULL; | ||
499 | 206 | |||
500 | 207 | AtspiRect *component_rect = | ||
501 | 208 | atspi_component_get_extents (component, ATSPI_COORD_TYPE_SCREEN, &error); | ||
502 | 209 | |||
503 | 210 | if (!component_rect) | ||
504 | 211 | g_error_free (error); | ||
505 | 212 | else | ||
506 | 213 | rect = CompRect (component_rect->x, | ||
507 | 214 | component_rect->y, | ||
508 | 215 | component_rect->width, | ||
509 | 216 | component_rect->height); | ||
510 | 217 | |||
511 | 218 | return rect; | ||
512 | 219 | } | ||
513 | 220 | |||
514 | 221 | CompPoint | ||
515 | 222 | AccessibilityComponent::getPosition () const | ||
516 | 223 | { | ||
517 | 224 | CompPoint position; | ||
518 | 225 | GError *error = NULL; | ||
519 | 226 | |||
520 | 227 | AtspiPoint *component_position = | ||
521 | 228 | atspi_component_get_position (component, ATSPI_COORD_TYPE_SCREEN, &error); | ||
522 | 229 | |||
523 | 230 | if (!component_position) | ||
524 | 231 | g_error_free (error); | ||
525 | 232 | else | ||
526 | 233 | position = CompPoint (component_position->x, component_position->y); | ||
527 | 234 | |||
528 | 235 | return position; | ||
529 | 236 | } | ||
530 | 237 | |||
531 | 238 | CompPoint | ||
532 | 239 | AccessibilityComponent::getSize () const | ||
533 | 240 | { | ||
534 | 241 | CompPoint size; | ||
535 | 242 | GError *error = NULL; | ||
536 | 243 | |||
537 | 244 | AtspiPoint *component_size = atspi_component_get_size (component, &error); | ||
538 | 245 | |||
539 | 246 | if (!component_size) | ||
540 | 247 | g_error_free (error); | ||
541 | 248 | else | ||
542 | 249 | size = CompPoint (component_size->x, component_size->y); | ||
543 | 250 | |||
544 | 251 | return size; | ||
545 | 252 | } | ||
546 | 253 | |||
547 | 254 | IfaceType | ||
548 | 255 | AccessibilityComponent::is () | ||
549 | 256 | { | ||
550 | 257 | return Component; | ||
551 | 258 | } | ||
552 | 259 | |||
553 | 260 | |||
554 | 261 | AccessibilityText::AccessibilityText (AtspiAccessible *obj) : | ||
555 | 262 | AccessibilityEntity (obj) | ||
556 | 263 | { | ||
557 | 264 | compLogMessage ("Accessibility", CompLogLevelInfo, | ||
558 | 265 | "AccessibilityText::AccessibilityText (%s)\n", obj->name); | ||
559 | 266 | |||
560 | 267 | text = atspi_accessible_get_text (obj); | ||
561 | 268 | } | ||
562 | 269 | |||
563 | 270 | AccessibilityText * | ||
564 | 271 | AccessibilityText::clone () const | ||
565 | 272 | { | ||
566 | 273 | return new AccessibilityText (obj); | ||
567 | 274 | } | ||
568 | 275 | |||
569 | 276 | CompRect | ||
570 | 277 | AccessibilityText::getCharacterExtents (int offset) const | ||
571 | 278 | { | ||
572 | 279 | CompRect rect; | ||
573 | 280 | GError *error = NULL; | ||
574 | 281 | |||
575 | 282 | AtspiRect *character_rect = atspi_text_get_character_extents | ||
576 | 283 | (text, offset, ATSPI_COORD_TYPE_SCREEN, &error); | ||
577 | 284 | |||
578 | 285 | if (!character_rect) | ||
579 | 286 | g_error_free (error); | ||
580 | 287 | else | ||
581 | 288 | rect = CompRect (character_rect->x, | ||
582 | 289 | character_rect->y, | ||
583 | 290 | character_rect->width, | ||
584 | 291 | character_rect->height); | ||
585 | 292 | |||
586 | 293 | return rect; | ||
587 | 294 | } | ||
588 | 295 | |||
589 | 296 | CompRect | ||
590 | 297 | AccessibilityText::getRangeExtents (int offset) const | ||
591 | 298 | { | ||
592 | 299 | CompRect rect; | ||
593 | 300 | GError *error = NULL; | ||
594 | 301 | |||
595 | 302 | AtspiRect *range_rect = atspi_text_get_range_extents | ||
596 | 303 | (text, 0, 0, ATSPI_COORD_TYPE_SCREEN, &error); | ||
597 | 304 | |||
598 | 305 | if (!range_rect) | ||
599 | 306 | g_error_free (error); | ||
600 | 307 | else | ||
601 | 308 | rect = CompRect (range_rect->x, | ||
602 | 309 | range_rect->y, | ||
603 | 310 | range_rect->width, | ||
604 | 311 | range_rect->height); | ||
605 | 312 | |||
606 | 313 | return rect; | ||
607 | 314 | } | ||
608 | 315 | |||
609 | 316 | int | ||
610 | 317 | AccessibilityText::getCaretOffset () | ||
611 | 318 | { | ||
612 | 319 | GError *error = NULL; | ||
613 | 320 | |||
614 | 321 | int caret_offset = atspi_text_get_caret_offset (text, &error); | ||
615 | 322 | |||
616 | 323 | if (!caret_offset) | ||
617 | 324 | g_error_free (error); | ||
618 | 325 | |||
619 | 326 | return caret_offset; | ||
620 | 327 | } | ||
621 | 328 | |||
622 | 329 | IfaceType | ||
623 | 330 | AccessibilityText::is () | ||
624 | 331 | { | ||
625 | 332 | return Text; | ||
626 | 333 | } | ||
627 | 334 | |||
628 | 335 | |||
629 | 336 | Accessibility::Accessibility () | ||
630 | 337 | { | ||
631 | 338 | compLogMessage ("Accessibility", CompLogLevelInfo, | ||
632 | 339 | "Accessibility constructor called.\n"); | ||
633 | 340 | |||
634 | 341 | } | ||
635 | 342 | |||
636 | 343 | Accessibility::~Accessibility () | ||
637 | 344 | { | ||
638 | 345 | compLogMessage ("Accessibility", CompLogLevelInfo, | ||
639 | 346 | "Accessibility destructor called.\n"); | ||
640 | 347 | |||
641 | 348 | } | ||
642 | 349 | |||
643 | 350 | bool | ||
644 | 351 | Accessibility::start () | ||
645 | 352 | { | ||
646 | 353 | return true; | ||
647 | 354 | } | ||
648 | 355 | |||
649 | 356 | bool | ||
650 | 357 | Accessibility::stop () | ||
651 | 358 | { | ||
652 | 359 | return true; | ||
653 | 360 | } | ||
654 | 361 | |||
655 | 362 | bool | ||
656 | 363 | Accessibility::active () | ||
657 | 364 | { | ||
658 | 365 | return true; | ||
659 | 366 | } | ||
660 | 367 | |||
661 | 368 | bool | ||
662 | 369 | Accessibility::registerEventHandler (const char *event_type, AccessibilityEventCallback cb) | ||
663 | 370 | { | ||
664 | 371 | ACCESSIBILITY_SCREEN (screen); | ||
665 | 372 | |||
666 | 373 | as->registerEventHandler (event_type, cb); | ||
667 | 374 | |||
668 | 375 | return true; | ||
669 | 376 | } | ||
670 | 377 | |||
671 | 378 | void | ||
672 | 379 | Accessibility::unregisterAll () | ||
673 | 380 | { | ||
674 | 381 | ACCESSIBILITY_SCREEN (screen); | ||
675 | 382 | |||
676 | 383 | as->unregisterAll (); | ||
677 | 384 | } | ||
678 | 385 | |||
679 | 386 | void | ||
680 | 387 | staticAccessibilityEventCallback (const AtspiEvent *event) | ||
681 | 388 | { | ||
682 | 389 | if (!event) | ||
683 | 390 | return; | ||
684 | 391 | |||
685 | 392 | ACCESSIBILITY_SCREEN (screen); | ||
686 | 393 | |||
687 | 394 | AccessibilityHandlerList list = as->list; | ||
688 | 395 | |||
689 | 396 | std::list<AccessibilityHandler *>::iterator it; | ||
690 | 397 | |||
691 | 398 | AccessibilityEvent *e = new AccessibilityEvent (event); | ||
692 | 399 | |||
693 | 400 | for (it = list.begin (); it != list.end (); it++) | ||
694 | 401 | { | ||
695 | 402 | const char * target_type = (*it)->event_type; | ||
696 | 403 | |||
697 | 404 | if (strncmp (target_type, event->type, strlen(target_type)) == 0) | ||
698 | 405 | { | ||
699 | 406 | compLogMessage ("Accessibility", CompLogLevelInfo, | ||
700 | 407 | "Delegating (%s) to -> functor [%d][%s]\n", | ||
701 | 408 | event->type, | ||
702 | 409 | (*it)->id, (*it)->event_type); | ||
703 | 410 | |||
704 | 411 | (*it)->cb (e); | ||
705 | 412 | } | ||
706 | 413 | } | ||
707 | 414 | |||
708 | 415 | delete (e); | ||
709 | 416 | } | ||
710 | 417 | |||
711 | 418 | void | ||
712 | 419 | staticAccessibilityEventDestroyCallback (void *data) | ||
713 | 420 | { | ||
714 | 421 | ACCESSIBILITY_SCREEN (screen); | ||
715 | 422 | |||
716 | 423 | AccessibilityHandlerList list = as->list; | ||
717 | 424 | |||
718 | 425 | std::list<AccessibilityHandler *>::iterator it; | ||
719 | 426 | |||
720 | 427 | for (it = list.begin (); it != list.end (); it++) | ||
721 | 428 | { | ||
722 | 429 | compLogMessage ("Accessibility", CompLogLevelInfo, | ||
723 | 430 | "Delegating destroy to -> functor [%d][%s]\n", | ||
724 | 431 | (*it)->id); | ||
725 | 432 | // TODO: Implement callback mechanism for handles destroy. | ||
726 | 433 | } | ||
727 | 434 | } | ||
728 | 435 | |||
729 | 436 | AccessibilityEvent::AccessibilityEvent (const AtspiEvent *event) | ||
730 | 437 | { | ||
731 | 438 | this->event = event; | ||
732 | 439 | this->object = new AccessibleObject (event->source); | ||
733 | 440 | } | ||
734 | 441 | |||
735 | 442 | AccessibilityEvent::~AccessibilityEvent () | ||
736 | 443 | { | ||
737 | 444 | delete (event); | ||
738 | 445 | delete (object); | ||
739 | 446 | } | ||
740 | 447 | |||
741 | 448 | const char * | ||
742 | 449 | AccessibilityEvent::getType () | ||
743 | 450 | { | ||
744 | 451 | return event->type; | ||
745 | 452 | } | ||
746 | 453 | |||
747 | 454 | AccessibleObject * | ||
748 | 455 | AccessibilityEvent::getAccessibleObject () | ||
749 | 456 | { | ||
750 | 457 | return object; | ||
751 | 458 | } | ||
752 | 459 | |||
753 | 460 | AccessibilityEventHandler | ||
754 | 461 | AccessibilityScreen::registerEventHandler (const char *event_type, | ||
755 | 462 | AccessibilityEventCallback cb) | ||
756 | 463 | { | ||
757 | 464 | |||
758 | 465 | AccessibilityHandler *hnd = new AccessibilityHandler (); | ||
759 | 466 | |||
760 | 467 | if (!hnd) | ||
761 | 468 | return 0; | ||
762 | 469 | |||
763 | 470 | if (!event_type || !cb) | ||
764 | 471 | return 0; | ||
765 | 472 | |||
766 | 473 | // Create event listeners | ||
767 | 474 | GError *error = NULL; | ||
768 | 475 | |||
769 | 476 | AtspiEventListener *event_listener = | ||
770 | 477 | atspi_event_listener_new_simple (staticAccessibilityEventCallback, | ||
771 | 478 | staticAccessibilityEventDestroyCallback); | ||
772 | 479 | |||
773 | 480 | if (!atspi_event_listener_register (event_listener, event_type, &error)) | ||
774 | 481 | { | ||
775 | 482 | compLogMessage ("Accessibility", CompLogLevelInfo, | ||
776 | 483 | "Cannot create event listener (%s). [%s]\n", | ||
777 | 484 | event_type, | ||
778 | 485 | error->message); | ||
779 | 486 | |||
780 | 487 | g_error_free (error); | ||
781 | 488 | error = NULL; | ||
782 | 489 | } | ||
783 | 490 | |||
784 | 491 | hnd->event_type = event_type; | ||
785 | 492 | hnd->event_listener = event_listener; | ||
786 | 493 | hnd->cb = cb; | ||
787 | 494 | hnd->id = lastEventHandler++; | ||
788 | 495 | |||
789 | 496 | list.push_front (hnd); | ||
790 | 497 | |||
791 | 498 | compLogMessage ("Accessibility", CompLogLevelInfo, "Registered new listener (%d): (%s))\n", hnd->id, hnd->event_type); | ||
792 | 499 | |||
793 | 500 | return hnd->id; | ||
794 | 501 | } | ||
795 | 502 | |||
796 | 503 | void | ||
797 | 504 | AccessibilityScreen::unregisterEventHandler (AccessibilityEventHandler handler) | ||
798 | 505 | { | ||
799 | 506 | |||
800 | 507 | std::list<AccessibilityHandler *>::iterator it; | ||
801 | 508 | AccessibilityHandler *h; | ||
802 | 509 | |||
803 | 510 | if (list.size() < 0) | ||
804 | 511 | return; | ||
805 | 512 | |||
806 | 513 | for (it = list.begin (); it != list.end (); it++) | ||
807 | 514 | if ((*it)->id == handler) | ||
808 | 515 | break; | ||
809 | 516 | |||
810 | 517 | if (it == list.end ()) | ||
811 | 518 | return; | ||
812 | 519 | |||
813 | 520 | // Unregister event. | ||
814 | 521 | GError *error = NULL; | ||
815 | 522 | |||
816 | 523 | if (!atspi_event_listener_deregister ((*it)->event_listener, (*it)->event_type, &error)) | ||
817 | 524 | { | ||
818 | 525 | compLogMessage ("Accessibility", CompLogLevelInfo, | ||
819 | 526 | "Cannot unregister event listener (%s). [%s]\n", | ||
820 | 527 | (*it)->event_type, | ||
821 | 528 | error->message); | ||
822 | 529 | |||
823 | 530 | g_error_free (error); | ||
824 | 531 | error = NULL; | ||
825 | 532 | } | ||
826 | 533 | |||
827 | 534 | // Free and erase from the list. | ||
828 | 535 | h = (*it); | ||
829 | 536 | delete (h); | ||
830 | 537 | |||
831 | 538 | list.erase (it); | ||
832 | 539 | } | ||
833 | 540 | |||
834 | 541 | |||
835 | 542 | bool | ||
836 | 543 | AccessibilityScreen::unregisterByType (const char * event_type) | ||
837 | 544 | { | ||
838 | 545 | //TODO | ||
839 | 546 | return true; | ||
840 | 547 | } | ||
841 | 548 | |||
842 | 549 | void | ||
843 | 550 | AccessibilityScreen::unregisterAll () | ||
844 | 551 | { | ||
845 | 552 | std::list<AccessibilityHandler *>::iterator it; | ||
846 | 553 | |||
847 | 554 | if (list.size () < 0) | ||
848 | 555 | return; | ||
849 | 556 | |||
850 | 557 | for (it = list.begin (); it != list.end (); it++) | ||
851 | 558 | { | ||
852 | 559 | unregisterEventHandler ((*it)->id); | ||
853 | 560 | } | ||
854 | 561 | } | ||
855 | 562 | |||
856 | 563 | void | ||
857 | 564 | AccessibilityScreen::handleAccessibilityEvent (AccessibilityEvent *event) | ||
858 | 565 | { | ||
859 | 566 | |||
860 | 567 | AccessibleObject *object = event->getAccessibleObject (); | ||
861 | 568 | |||
862 | 569 | if (object->is (Component)) | ||
863 | 570 | { | ||
864 | 571 | |||
865 | 572 | AccessibilityComponent::Ptr ac = | ||
866 | 573 | boost::static_pointer_cast<AccessibilityComponent> | ||
867 | 574 | (object->getEntity (Component)); | ||
868 | 575 | |||
869 | 576 | CompRect rect = ac->getExtents (); | ||
870 | 577 | |||
871 | 578 | compLogMessage ("Accessibility", CompLogLevelInfo, "Object is Component\n"); | ||
872 | 579 | |||
873 | 580 | compLogMessage ("Accessibility", CompLogLevelInfo, | ||
874 | 581 | "Component Area [%d, %d] [%d, %d]\n", | ||
875 | 582 | rect.x1(), rect.y1(), rect.x2(), rect.y2()); | ||
876 | 583 | } | ||
877 | 584 | else | ||
878 | 585 | { | ||
879 | 586 | |||
880 | 587 | compLogMessage ("Accessibility", CompLogLevelInfo, "Object is NOT Component\n"); | ||
881 | 588 | } | ||
882 | 589 | } | ||
883 | 590 | |||
884 | 591 | AccessibilityScreen::AccessibilityScreen (CompScreen *screen) : | ||
885 | 592 | PluginClassHandler <AccessibilityScreen, CompScreen> (screen), | ||
886 | 593 | screen (screen), | ||
887 | 594 | lastEventHandler (0) | ||
888 | 595 | { | ||
889 | 596 | compLogMessage ("Accessibility", CompLogLevelInfo, | ||
890 | 597 | "AccessibilityScreen called.\n"); | ||
891 | 598 | |||
892 | 599 | /* TODO: Check atspi_init() code. There's a memory leak when registryd | ||
893 | 600 | * isn't running. | ||
894 | 601 | */ | ||
895 | 602 | int atspi_status = atspi_init (); | ||
896 | 603 | |||
897 | 604 | compLogMessage ("Accessibility", CompLogLevelInfo, | ||
898 | 605 | "AccessibilityScreen: AT-SPI init() %d.\n", atspi_status); | ||
899 | 606 | |||
900 | 607 | /* | ||
901 | 608 | registerEventHandler ("object:state-changed:", boost::bind ( | ||
902 | 609 | &AccessibilityScreen::handleAccessibilityEvent, this, _1)); | ||
903 | 610 | */ | ||
904 | 611 | |||
905 | 612 | compLogMessage ("Accessibility", CompLogLevelInfo, "Running!\n"); | ||
906 | 613 | |||
907 | 614 | /* | ||
908 | 615 | // Launch main event atspi loop | ||
909 | 616 | // This is not needed because compiz private screen launches its own | ||
910 | 617 | // Glib MainLoop | ||
911 | 618 | */ | ||
912 | 619 | /* | ||
913 | 620 | |||
914 | 621 | atspi_event_main(); | ||
915 | 622 | */ | ||
916 | 623 | } | ||
917 | 624 | |||
918 | 625 | AccessibilityScreen::~AccessibilityScreen () | ||
919 | 626 | { | ||
920 | 627 | |||
921 | 628 | unregisterAll (); | ||
922 | 629 | |||
923 | 630 | //atspi_event_quit(); | ||
924 | 631 | int atspi_status = atspi_exit (); | ||
925 | 632 | |||
926 | 633 | compLogMessage ("Accessibility", CompLogLevelInfo, | ||
927 | 634 | "~AccessibilityScreen called. Exit value: %d\n", atspi_status); | ||
928 | 635 | } | ||
929 | 636 | |||
930 | 637 | bool | ||
931 | 638 | AccessibilityPluginVTable::init () | ||
932 | 639 | { | ||
933 | 640 | if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION)) | ||
934 | 641 | { | ||
935 | 642 | compLogMessage ("Accessibility", CompLogLevelInfo, | ||
936 | 643 | "compiz core not in sync.\n"); | ||
937 | 644 | return false; | ||
938 | 645 | } | ||
939 | 646 | |||
940 | 647 | compLogMessage ("Accessibility", CompLogLevelInfo, | ||
941 | 648 | "Running Accessibility plugin.\n"); | ||
942 | 649 | |||
943 | 650 | return true; | ||
944 | 651 | } | ||
945 | 0 | 652 | ||
946 | === added file 'plugins/accessibility/src/private.h' | |||
947 | --- plugins/accessibility/src/private.h 1970-01-01 00:00:00 +0000 | |||
948 | +++ plugins/accessibility/src/private.h 2012-06-23 15:04:23 +0000 | |||
949 | @@ -0,0 +1,113 @@ | |||
950 | 1 | /* | ||
951 | 2 | * Compiz Accessibility PLugin | ||
952 | 3 | * | ||
953 | 4 | * Copyright (c) 2011 F123 Consulting & Mais Diferenças | ||
954 | 5 | * | ||
955 | 6 | * This program is free software; you can redistribute it and/or | ||
956 | 7 | * modify it under the terms of the GNU General Public License | ||
957 | 8 | * as published by the Free Software Foundation; either version 2 | ||
958 | 9 | * of the License, or (at your option) any later version. | ||
959 | 10 | * | ||
960 | 11 | * This program is distributed in the hope that it will be useful, | ||
961 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
962 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
963 | 14 | * GNU General Public License for more details. | ||
964 | 15 | * | ||
965 | 16 | * Author: Alejandro Leiva <aleiva@emergya.com> | ||
966 | 17 | * | ||
967 | 18 | */ | ||
968 | 19 | |||
969 | 20 | #include <vector> | ||
970 | 21 | #include <cstring> | ||
971 | 22 | |||
972 | 23 | #include <boost/shared_ptr.hpp> | ||
973 | 24 | |||
974 | 25 | #include <core/core.h> | ||
975 | 26 | #include <core/pluginclasshandler.h> | ||
976 | 27 | |||
977 | 28 | #include <glibmm/main.h> | ||
978 | 29 | |||
979 | 30 | #include <accessibility/accessibility.h> | ||
980 | 31 | #include "accessibility_options.h" | ||
981 | 32 | |||
982 | 33 | static const char *IfaceTypeStr[] = | ||
983 | 34 | { | ||
984 | 35 | "Accessible", | ||
985 | 36 | "Action", | ||
986 | 37 | "Collection", | ||
987 | 38 | "Component", | ||
988 | 39 | "Document", | ||
989 | 40 | "EditableText", | ||
990 | 41 | "Hypertext", | ||
991 | 42 | "Hyperlink", | ||
992 | 43 | "Image", | ||
993 | 44 | "Selection", | ||
994 | 45 | "Table", | ||
995 | 46 | "Text", | ||
996 | 47 | "Value", | ||
997 | 48 | }; | ||
998 | 49 | |||
999 | 50 | #define NUM_IFACES_SUPPORTED 13 | ||
1000 | 51 | |||
1001 | 52 | typedef int AccessibilityEventHandler; | ||
1002 | 53 | |||
1003 | 54 | /* Struct of a handler and list of handlers */ | ||
1004 | 55 | struct AccessibilityHandler { | ||
1005 | 56 | const char * event_type; | ||
1006 | 57 | AtspiEventListener * event_listener; | ||
1007 | 58 | AccessibilityEventCallback cb; | ||
1008 | 59 | AccessibilityEventHandler id; | ||
1009 | 60 | }; | ||
1010 | 61 | |||
1011 | 62 | typedef std::list<AccessibilityHandler *> AccessibilityHandlerList; | ||
1012 | 63 | |||
1013 | 64 | class AccessibilityScreen : | ||
1014 | 65 | public PluginClassHandler <AccessibilityScreen, CompScreen>, | ||
1015 | 66 | public ScreenInterface, | ||
1016 | 67 | public AccessibilityOptions | ||
1017 | 68 | { | ||
1018 | 69 | public: | ||
1019 | 70 | |||
1020 | 71 | AccessibilityScreen (CompScreen *); | ||
1021 | 72 | ~AccessibilityScreen (); | ||
1022 | 73 | |||
1023 | 74 | CompScreen *screen; | ||
1024 | 75 | |||
1025 | 76 | AccessibilityEventHandler | ||
1026 | 77 | registerEventHandler (const char * event_type, | ||
1027 | 78 | AccessibilityEventCallback cb); | ||
1028 | 79 | |||
1029 | 80 | void | ||
1030 | 81 | unregisterEventHandler (AccessibilityEventHandler handler); | ||
1031 | 82 | |||
1032 | 83 | bool | ||
1033 | 84 | unregisterByType (const char * event_type); | ||
1034 | 85 | |||
1035 | 86 | void | ||
1036 | 87 | unregisterAll (); | ||
1037 | 88 | |||
1038 | 89 | void | ||
1039 | 90 | handleAccessibilityEvent (AccessibilityEvent *); | ||
1040 | 91 | |||
1041 | 92 | public: | ||
1042 | 93 | |||
1043 | 94 | AccessibilityHandlerList list; | ||
1044 | 95 | int lastEventHandler; | ||
1045 | 96 | |||
1046 | 97 | protected: | ||
1047 | 98 | |||
1048 | 99 | AtspiEventListener *listener; | ||
1049 | 100 | |||
1050 | 101 | }; | ||
1051 | 102 | |||
1052 | 103 | #define ACCESSIBILITY_SCREEN(s) \ | ||
1053 | 104 | AccessibilityScreen *as = AccessibilityScreen::get (s) | ||
1054 | 105 | |||
1055 | 106 | class AccessibilityPluginVTable : | ||
1056 | 107 | public CompPlugin::VTableForScreen <AccessibilityScreen> | ||
1057 | 108 | { | ||
1058 | 109 | public: | ||
1059 | 110 | |||
1060 | 111 | bool init(); | ||
1061 | 112 | |||
1062 | 113 | }; | ||
1063 | 0 | 114 | ||
1064 | === modified file 'plugins/ezoom/CMakeLists.txt' | |||
1065 | --- plugins/ezoom/CMakeLists.txt 2012-05-16 17:40:27 +0000 | |||
1066 | +++ plugins/ezoom/CMakeLists.txt 2012-06-23 15:04:23 +0000 | |||
1067 | @@ -2,4 +2,4 @@ | |||
1068 | 2 | 2 | ||
1069 | 3 | include (CompizPlugin) | 3 | include (CompizPlugin) |
1070 | 4 | 4 | ||
1072 | 5 | compiz_plugin (ezoom PLUGINDEPS composite opengl mousepoll) | 5 | compiz_plugin (ezoom PLUGINDEPS composite opengl mousepoll accessibility PKGDEPS atspi-2) |
1073 | 6 | 6 | ||
1074 | === modified file 'plugins/ezoom/ezoom.xml.in' | |||
1075 | --- plugins/ezoom/ezoom.xml.in 2012-05-16 17:40:27 +0000 | |||
1076 | +++ plugins/ezoom/ezoom.xml.in 2012-06-23 15:04:23 +0000 | |||
1077 | @@ -6,6 +6,7 @@ | |||
1078 | 6 | <plugin>opengl</plugin> | 6 | <plugin>opengl</plugin> |
1079 | 7 | <plugin>expo</plugin> | 7 | <plugin>expo</plugin> |
1080 | 8 | <plugin>decor</plugin> | 8 | <plugin>decor</plugin> |
1081 | 9 | <plugin>accessibility</plugin> | ||
1082 | 9 | </relation> | 10 | </relation> |
1083 | 10 | <relation type="before"> | 11 | <relation type="before"> |
1084 | 11 | <plugin>staticswitcher</plugin> | 12 | <plugin>staticswitcher</plugin> |
1085 | @@ -14,6 +15,7 @@ | |||
1086 | 14 | <requirement> | 15 | <requirement> |
1087 | 15 | <plugin>opengl</plugin> | 16 | <plugin>opengl</plugin> |
1088 | 16 | <plugin>mousepoll</plugin> | 17 | <plugin>mousepoll</plugin> |
1089 | 18 | <plugin>accessibility</plugin> | ||
1090 | 17 | </requirement> | 19 | </requirement> |
1091 | 18 | </deps> | 20 | </deps> |
1092 | 19 | <_short>Enhanced Zoom Desktop</_short> | 21 | <_short>Enhanced Zoom Desktop</_short> |
1093 | 20 | 22 | ||
1094 | === modified file 'plugins/ezoom/src/ezoom.cpp' | |||
1095 | --- plugins/ezoom/src/ezoom.cpp 2012-05-18 06:52:20 +0000 | |||
1096 | +++ plugins/ezoom/src/ezoom.cpp 2012-06-23 15:04:23 +0000 | |||
1097 | @@ -604,6 +604,12 @@ | |||
1098 | 604 | mouse = MousePoller::getCurrentPosition (); | 604 | mouse = MousePoller::getCurrentPosition (); |
1099 | 605 | } | 605 | } |
1100 | 606 | 606 | ||
1101 | 607 | void | ||
1102 | 608 | EZoomScreen::enableAccessibility () | ||
1103 | 609 | { | ||
1104 | 610 | ; | ||
1105 | 611 | } | ||
1106 | 612 | |||
1107 | 607 | /* Sets the zoom (or scale) level. | 613 | /* Sets the zoom (or scale) level. |
1108 | 608 | * Cleans up if we are suddenly zoomed out. | 614 | * Cleans up if we are suddenly zoomed out. |
1109 | 609 | */ | 615 | */ |
1110 | @@ -1790,6 +1796,62 @@ | |||
1111 | 1790 | screen->handleEvent (event); | 1796 | screen->handleEvent (event); |
1112 | 1791 | } | 1797 | } |
1113 | 1792 | 1798 | ||
1114 | 1799 | void | ||
1115 | 1800 | EZoomScreen::handleAccessibilityEvent (AccessibilityEvent *event) | ||
1116 | 1801 | { | ||
1117 | 1802 | AccessibleObject *object = event->getAccessibleObject (); | ||
1118 | 1803 | |||
1119 | 1804 | compLogMessage ("EZoom", CompLogLevelInfo, | ||
1120 | 1805 | "event->type: %s\n", event->getType()); | ||
1121 | 1806 | |||
1122 | 1807 | if (object->is (Component)) | ||
1123 | 1808 | { | ||
1124 | 1809 | |||
1125 | 1810 | AccessibilityComponent::Ptr ac = | ||
1126 | 1811 | boost::static_pointer_cast<AccessibilityComponent> | ||
1127 | 1812 | (object->getEntity (Component)); | ||
1128 | 1813 | |||
1129 | 1814 | CompRect rect = ac->getExtents (); | ||
1130 | 1815 | |||
1131 | 1816 | compLogMessage ("Ezoom", CompLogLevelInfo, | ||
1132 | 1817 | "ensureVisibilityArea [%d, %d] [%d, %d]\n", | ||
1133 | 1818 | rect.x1(), rect.y1(), rect.x2(), rect.y2()); | ||
1134 | 1819 | |||
1135 | 1820 | if (optionGetZoomMode () == EzoomOptions::ZoomModePanArea) | ||
1136 | 1821 | { | ||
1137 | 1822 | ensureVisibilityArea (rect.x1(), | ||
1138 | 1823 | rect.y1(), | ||
1139 | 1824 | rect.x2(), | ||
1140 | 1825 | rect.y2(), | ||
1141 | 1826 | optionGetRestrainMargin (), | ||
1142 | 1827 | NORTHWEST); | ||
1143 | 1828 | } | ||
1144 | 1829 | } | ||
1145 | 1830 | |||
1146 | 1831 | if (object->is (Text)) | ||
1147 | 1832 | { | ||
1148 | 1833 | AccessibilityText::Ptr at = | ||
1149 | 1834 | boost::static_pointer_cast<AccessibilityText> | ||
1150 | 1835 | (object->getEntity (Text)); | ||
1151 | 1836 | |||
1152 | 1837 | CompRect rect = at->getCharacterExtents (at->getCaretOffset ()); | ||
1153 | 1838 | |||
1154 | 1839 | compLogMessage ("Ezoom", CompLogLevelInfo, | ||
1155 | 1840 | "TEXT - [%d, %d] [%d, %d]\n", | ||
1156 | 1841 | rect.x1(), rect.y1(), rect.x2(), rect.y2()); | ||
1157 | 1842 | |||
1158 | 1843 | if (optionGetZoomMode () == EzoomOptions::ZoomModePanArea) | ||
1159 | 1844 | { | ||
1160 | 1845 | ensureVisibilityArea (rect.x1(), | ||
1161 | 1846 | rect.y1(), | ||
1162 | 1847 | rect.x2(), | ||
1163 | 1848 | rect.y2(), | ||
1164 | 1849 | optionGetRestrainMargin (), | ||
1165 | 1850 | NORTHWEST); | ||
1166 | 1851 | } | ||
1167 | 1852 | } | ||
1168 | 1853 | } | ||
1169 | 1854 | |||
1170 | 1793 | /* TODO: Use this ctor carefully */ | 1855 | /* TODO: Use this ctor carefully */ |
1171 | 1794 | 1856 | ||
1172 | 1795 | EZoomScreen::CursorTexture::CursorTexture () : | 1857 | EZoomScreen::CursorTexture::CursorTexture () : |
1173 | @@ -1866,6 +1928,12 @@ | |||
1174 | 1866 | pollHandle.setCallback (boost::bind ( | 1928 | pollHandle.setCallback (boost::bind ( |
1175 | 1867 | &EZoomScreen::updateMouseInterval, this, _1)); | 1929 | &EZoomScreen::updateMouseInterval, this, _1)); |
1176 | 1868 | 1930 | ||
1177 | 1931 | a11yHandle = new Accessibility(); | ||
1178 | 1932 | a11yHandle->registerEventHandler ("object:state-changed", boost::bind ( | ||
1179 | 1933 | &EZoomScreen::handleAccessibilityEvent, this, _1)); | ||
1180 | 1934 | a11yHandle->registerEventHandler ("object:text-changed", boost::bind ( | ||
1181 | 1935 | &EZoomScreen::handleAccessibilityEvent, this, _1)); | ||
1182 | 1936 | |||
1183 | 1869 | optionSetZoomInButtonInitiate (boost::bind (&EZoomScreen::zoomIn, this, _1, | 1937 | optionSetZoomInButtonInitiate (boost::bind (&EZoomScreen::zoomIn, this, _1, |
1184 | 1870 | _2, _3)); | 1938 | _2, _3)); |
1185 | 1871 | optionSetZoomOutButtonInitiate (boost::bind (&EZoomScreen::zoomOut, this, _1, | 1939 | optionSetZoomOutButtonInitiate (boost::bind (&EZoomScreen::zoomOut, this, _1, |
1186 | @@ -1926,6 +1994,9 @@ | |||
1187 | 1926 | if (pollHandle.active ()) | 1994 | if (pollHandle.active ()) |
1188 | 1927 | pollHandle.stop (); | 1995 | pollHandle.stop (); |
1189 | 1928 | 1996 | ||
1190 | 1997 | if (a11yHandle->active ()) | ||
1191 | 1998 | a11yHandle->unregisterAll (); | ||
1192 | 1999 | |||
1193 | 1929 | if (zooms.size ()) | 2000 | if (zooms.size ()) |
1194 | 1930 | zooms.clear (); | 2001 | zooms.clear (); |
1195 | 1931 | 2002 | ||
1196 | 1932 | 2003 | ||
1197 | === modified file 'plugins/ezoom/src/ezoom.h' | |||
1198 | --- plugins/ezoom/src/ezoom.h 2010-10-25 02:23:36 +0000 | |||
1199 | +++ plugins/ezoom/src/ezoom.h 2012-06-23 15:04:23 +0000 | |||
1200 | @@ -44,6 +44,7 @@ | |||
1201 | 44 | #include <composite/composite.h> | 44 | #include <composite/composite.h> |
1202 | 45 | #include <opengl/opengl.h> | 45 | #include <opengl/opengl.h> |
1203 | 46 | #include <mousepoll/mousepoll.h> | 46 | #include <mousepoll/mousepoll.h> |
1204 | 47 | #include <accessibility/accessibility.h> | ||
1205 | 47 | 48 | ||
1206 | 48 | 49 | ||
1207 | 49 | #include "ezoom_options.h" | 50 | #include "ezoom_options.h" |
1208 | @@ -184,6 +185,8 @@ | |||
1209 | 184 | 185 | ||
1210 | 185 | MousePoller pollHandle; // mouse poller object | 186 | MousePoller pollHandle; // mouse poller object |
1211 | 186 | 187 | ||
1212 | 188 | Accessibility *a11yHandle; // Accessibility object | ||
1213 | 189 | |||
1214 | 187 | private: | 190 | private: |
1215 | 188 | 191 | ||
1216 | 189 | bool fixesSupported; | 192 | bool fixesSupported; |
1217 | @@ -212,6 +215,9 @@ | |||
1218 | 212 | void | 215 | void |
1219 | 213 | handleEvent (XEvent *); | 216 | handleEvent (XEvent *); |
1220 | 214 | 217 | ||
1221 | 218 | void | ||
1222 | 219 | handleAccessibilityEvent (AccessibilityEvent *event); | ||
1223 | 220 | |||
1224 | 215 | public: | 221 | public: |
1225 | 216 | 222 | ||
1226 | 217 | int | 223 | int |
1227 | @@ -250,6 +256,9 @@ | |||
1228 | 250 | void | 256 | void |
1229 | 251 | enableMousePolling (); | 257 | enableMousePolling (); |
1230 | 252 | 258 | ||
1231 | 259 | void | ||
1232 | 260 | enableAccessibility (); | ||
1233 | 261 | |||
1234 | 253 | void | 262 | void |
1235 | 254 | setScale (int out, float value); | 263 | setScale (int out, float value); |
1236 | 255 | 264 | ||
1237 | 256 | 265 | ||
1238 | === modified file 'plugins/mousepoll/mousepoll.xml.in' | |||
1239 | --- plugins/mousepoll/mousepoll.xml.in 2012-05-16 17:43:36 +0000 | |||
1240 | +++ plugins/mousepoll/mousepoll.xml.in 2012-06-23 15:04:23 +0000 | |||
1241 | @@ -16,7 +16,7 @@ | |||
1242 | 16 | <option type="int" name="mouse_poll_interval"> | 16 | <option type="int" name="mouse_poll_interval"> |
1243 | 17 | <_short>Mouse Poll Interval</_short> | 17 | <_short>Mouse Poll Interval</_short> |
1244 | 18 | <_long>How often to poll the mouse position, in miliseconds. Reduce this to reduce choppy behavior.</_long> | 18 | <_long>How often to poll the mouse position, in miliseconds. Reduce this to reduce choppy behavior.</_long> |
1246 | 19 | <default>40</default> | 19 | <default>10</default> |
1247 | 20 | <min>1</min> | 20 | <min>1</min> |
1248 | 21 | <max>500</max> | 21 | <max>500</max> |
1249 | 22 | </option> | 22 | </option> |
Looks good, and definitely on the right track, needs some work before we can merge it in, but definitely something we can have for 12.10
The README can probably be cut down or go entirely, it seems to be mostly about how to enable AT-SPI and how to build and install the plugin, which is mostly redundant anyways as the buildsystem will build it for us.
There are a few indentation problems that need to be fixed. Indentation in compiz is a little weird (X11 style). It goes:
4 spaces
8-wide tab
8-wide tab + 4 spaces
8-wide tab + 8 wide tab
8-wide tab + 8-wide tab + 4 spaces
etc
So some areas where this needs to be fixed are:
215 + virtual AccessibilityEntity *
216 + clone () const;
217 +
218 + AtspiAccessible *
219 + getObject ();
215 + virtual AccessibilityEntity *
216 + clone () const;
217 +
218 + AtspiAccessible *
219 + getObject ();
412 + for (int i = 0; i < len; i++) {
413 +
The brace goes on the next line, eg
for (int i = 0; i < len; i++)
{
+ switch (iface) {
ditto
518 + compLogMessage ("Accessibility", CompLogLevelInfo, ntity:: AccessibilityEn tity (%s)\n", object->name);
519 + "AccessibilityE
520 +
I don't think these messages are necessary. Program function can be verified through unit tests (which I'll get on to in a minute)
1269 + if (a11yHandle->active ()) >unregisterAll ();
1270 + a11yHandle-
That needs to be a tab and not four spaces.
The second big thing I have about this code is that the design feels a little weird.
The inheritance hierarchy looks a bit like this:
AccessibilityEntity mponent
- AccessibilityCo
- AccessibilityText
AccessibleObject (which appears to be a wrapper around AtspiAccessible *)
Accessibility (which appears to be a manager class)
The real gripe I have here are things like this:
434 + case Component: tity::Ptr (new AccessibilityCo mponent (object)); tity::Ptr (new AccessibilityText (object)); tity::Ptr (new AccessibilityEntity (object));
435 + entity = AccessibilityEn
436 + break;
437 +
438 + case Text:
439 + entity = AccessibilityEn
440 + break;
441 +
442 + case Accessible:
443 + case Action:
444 + case Collection:
445 + case Document:
446 + case EditableText:
447 + case Hypertext:
448 + case Hyperlink:
449 + case Image:
450 + case Selection:
451 + case Table:
452 + case Value:
453 + break;
454 +
455 + default:
456 + entity = AccessibilityEn
This code feels fragile, because our fallback case is "silently do nothing", and we just waste memory by tracking objects we don't really care about. Moreover, that behaviour is different from cases that we know we don't care about where we return a shared_ptr to NULL and then the client code just assumes that the pointer is valid.
There are other examples like this:
941 + if (object->is (Component)) mponent: :Ptr ac = static_ pointer_ cast<Accessibil ityComponent>
942 + {
943 +
944 + AccessibilityCo
945 + boost::
946 + (object->getEntity (Component));
Generally speaking, code where you need to go from some "placeholder" down to something that you think the object is feels to me like reintepret_casting through void * with a note that everything will be okay.
I understand that Atspi is based on GObject and as such, you have to handle the type system at run...