(Programming Guide) Initial chapter on creating a custom control
[platform/core/uifw/dali-toolkit.git] / docs / content / shared-javascript-and-cpp-documentation / accessibility.md
1 <!--
2 /**-->
3
4 [TOC]
5
6 # Accessibility{#accessibility}
7
8
9 ## Introduction - What is Accessibility? {#accessibilityintroduction}
10
11 Accessibility describes functionality designed to aid usage by the visually impaired.
12   
13 This includes:
14 - Reading out selections or other on-screen items via text-to-speach.
15 - Item selection being controlled with gestures to aid selecting other small hard to select entities.
16   
17
18 ## Accessibility within DALi {#accessibilitydali}
19
20 DALi will pick up the system's current accessibility state (and subsequent changes to it) and enable its internal accessibility mode based on this.
21   
22 DALi includes an Accessibility Manager which prodives public API control of the order of object selection by gesture, and text to be read out per actor or control.
23   
24 It further provides many signals that represent accessibility gestures. These gestures can range from a simple actor selection through to a more control-specific concept like "page-up", which an application developer may want to provide an implementation for.
25   
26 Furthermore, these APIs can be used not only with existing actors and controls, but also when creating a custom control.
27   
28 The AccessibilityManager lives within DALi Toolkit. Please see accessibility-manager.h for the full API.
29
30
31 ## Accessibility Focus {#accessibilityfocus}
32
33 <!-- Float image to the right of the text -->
34 <div style="float: right">
35     ![ ](../assets/img/accessibility/accessibility-focus.png) ![ ](./accessibility-focus.png)
36 </div>
37
38 Visibily, when enabled, accessibility will typically show an actor (or actors) as focused. This is represented by default with yellow rectangular frame around the actor. See this section for [modifying the appearance of the accessibility focus](#accessibilityfocusappearance).
39   
40 Once in accessibility mode, normal control is disabled and accessibility gestures must be used to access content.
41 DALi actors and controls will no longer receive tap gestures or click events when they are touched once (as they normally would).
42   
43 Note: The accessibility focus is also refered to as the Focus Indicator.
44
45
46 ### Moving the focus with gestures {#accessibilitygestures}
47
48 Accessibility recognises many gesture types to move the accessibility focus from actor to actor.
49   
50 Note:
51   
52 - Some of these gestures have pre-defined, automatic behaviour.
53 - Some gestures require an specific implementation to be added to use.
54 - All can be caught as signals if extra control is needed.
55   
56 To test (and understand) this behaviour, you can use the Tizen adaptor which uses the following gestures to perform basic operation:
57   
58 Note: The gestures that perform these actions are platform specific. These are the gestures implemented in the Tizen adaptor for example only.
59   
60 - Swiping right and left will move the focus forward and backward one item.
61 - Doing a left or right swipe-return (where a direction is swiped forwards and backwards quickly) will move to the previous or next page - DALi cannot know what a page is within your application so these gestures can only work if implemented manually.
62   
63
64 ![ ](../assets/img/accessibility/accessibility-focus-order.png) ![ ](./accessibility-focus-order.png)
65
66 ### Activation {#accessibilityactivation}
67
68 Activation describes an operation performed on a selected actor, typically an on-tap or on-click event.
69   
70 Activating an actor in accessibility mode will call a virtual function, as well as signal, for that actor.
71 Depending on the platform this can br triggered in different ways.
72 When activated, the built in actor types (like PushButton) will do the equivalent of a tap.
73   
74 Custom-built actor types will need to implement activation in order to perform a specific behaviour. See the [Custom Controls](#accessibilitycustomcontrol) section.
75   
76 Therefore, to tap an actor (EG. Click a button) in accessibility mode, the following must be done:
77   
78 - The actor needs to be selected first (using gestures specific to the platform).
79 - Then activated, by using the activation gesture.
80   
81 ## Scrolling {#accessibilityscrolling}
82
83 Scrolling around a view outside of accessibility is normally performed by simply holding one finger and dragging (in the appropriate direction).
84 Within accessibility this can be overridden and performed with a different gesture type to achieve the same effect.
85   
86 Example: For the Tizen platform scrolling is performed with a two-finger drag.
87
88
89 ## Basic functionality {#accessibilitybasicfunctionality}
90
91 ### Using the Accessibility Manager functionality {#accessibilityfunctionality}
92
93 Accessibility information is stored within the accessibility manager itself rather than within actors.
94 This allows the manager to have a global view of focusable actors and their order.
95   
96 The Accessibility Manager is a singleton (owned by the singleton service) and can be accessed via its static Get() method:
97   
98 ~~~{.cpp}
99 // Get the accessibility manager singleton.
100 accessibilityManager accessibilityManager = AccessibilityManager::Get();
101 ~~~
102
103
104 ### Controlling where the focus will move {#accessibilitymovingfocus}
105
106 In order to provide automatic focus movement, the accessibility manager must be told the focus order of any actors to be selected.
107 This order is a linear order. It can move forwards or backwards only (there is no concept of "up" or "down").
108   
109 The order of a particular actor can be set with a call to the accessibility manager like so:
110   
111 ~~~{.cpp}
112 // 6 is an int representing this actor's position in the focus chain.
113 accessibilityManager.SetFocusOrder( actor, 6 );
114 ~~~
115   
116 The focus order of each actor in the focus chain is unique. If there is another actor assigned with the same focus order already, the new actor will be inserted to the focus chain with that focus order, and the focus order of the original actor and all the actors followed in the focus chain will be increased accordingly.
117   
118 If the focus order assigned to the actor is 0, it means that actor's focus order is undefined (e.g. the actor has a description but with no focus order being set yet) and therefore that actor is not focusable.
119   
120 Moving focus to a particular actor directly can be done with SetCurrentFocusActor like so:
121   
122 ~~~{.cpp}
123 // Move focus to the first item on our applications page.
124 AccessibilityManager accessibilityManager = AccessibilityManager::Get();
125   
126 accessibilityManager.SetCurrentFocusActor( table.GetChildAt( 0 ) );
127 ~~~
128
129 ### Modifying the appearance of the accessibility focus {#accessibilityfocusappearance}
130
131 The focus graphic itself can be customised.
132 It can be an image (EG. A nine-patch border) or any other type of actor.
133   
134 It can be set using this method within C++:
135   
136 ~~~{.cpp}
137 accessibilityManager.SetFocusIndicatorActor( myCustomIndicatorActor );
138 ~~~
139
140
141 ### Using activation {#accessibilityusingactivation}
142
143 If the application would like to perform specific behaviour when an entity is activated, it can catch the activation by connecting to a signal like this:
144   
145 ~~~{.cpp}
146 AccessibilityManager::Get().FocusedActorActivatedSignal().Connect( this, &MyClass::OnFocusedActorActivated );
147 ~~~
148   
149 Controlling the activation behaviour within a custom control is covered in the [custom control section](#accessibilitycustomcontrol)
150
151
152 ## Focus groups {#accessibilityfocusgroups}
153
154 <!-- Float image to the right of the text -->
155 <div style="float: right">
156     ![ ](../assets/img/accessibility/accessibility-focus-group.png) ![ ](./accessibility-focus-group.png)
157 </div>
158
159 Group mode allows the limiting of focusable actors.
160   
161 Example: If a popup appears, you may want the focus to be limited to only the OK and Cancel buttons. You can do this by setting the popup as a focus group and turning on group mode, the focus will be limited.
162   
163 ~~~{.cpp}
164 // Create a parent actor and add two children to it.
165 Actor groupActor = Actor::New();
166
167 Actor child1 = Actor::New();
168 groupActor.Add( child1 );
169
170 Actor child2 = Actor::New();
171 groupActor.Add( child2 );
172
173 AccessibilityManager accessibilityManager = AccessibilityManager::Get();
174
175 // Mark the parent as a focus group. Now focus movement *can* be limited to the children of this actor.
176 // Note: That this is not enabled until specified.
177 accessibilityManager.SetFocusGroup( groupActor, true );
178
179 // Enable the focus group mode.
180 accessibilityManager.SetGroupMode( true );
181 ~~~
182
183
184 ### Wrap mode {#accessibilitywrapmode}
185
186 Wrap mode allows the focus to wrap back to the beginning once the end is reached.
187   
188 In group mode this will move to the beggining of the current focus group.
189   
190 ~~~{.cpp}
191 AccessibilityManager accessibilityManager = AccessibilityManager::Get();
192
193 // Enable wrap mode.
194 accessibilityManager.SetWrapMode( true );
195 ~~~
196
197
198 ## Using Accessibility {#accessibilityusage}
199
200 ### Using accessibility with existing actors {#accessibilityactors}
201
202 This example sets up a 3 by 3 grid of actors with the following accessibility functionality:
203   
204   - They have a focus order that moves from top left to bottom right (when using the accessibility next and previous gestures).
205   - They contain text that will be spoken out loud (via text-to-speach) when the focus changes.
206   
207 Note that all the above is set via the AccessibilityManager and not as properties within the actors.
208   
209 The text spoken per tile will be the LABEL, TRAIT and HINT (in that order).
210   
211 ~~~{.cpp}
212 Toolkit::TableView table = Toolkit::TableView::New( 3, 3 );
213 int tileNumber = 0;
214 for( int row = 0; row < 3; ++row )
215 {
216   for( int column = 0; column < 3; ++column )
217   {
218     // Create a solid color actor, with some text.
219     Actor tile = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
220     Toolkit::TextLabel text = Toolkit::TextLabel::New( tileNames[tileNumber] );
221     tile.Add( text );
222
223     // Get the accessibility manager singleton.
224     accessibilityManager accessibilityManager = AccessibilityManager::Get();
225
226     // Set the focus order of this actor.
227     accessibilityManager.SetFocusOrder( tile, tileNumber );
228
229     // Set up the accessibility information for this actor (this will be read out with text-to-speach).
230     accessibilityManager.SetAccessibilityAttribute( tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_LABEL, tileNames[tileNumber] );
231     accessibilityManager.SetAccessibilityAttribute( tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_TRAIT, "Tile" );
232     accessibilityManager.SetAccessibilityAttribute( tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_HINT, "You can run this example");
233
234     // Lay out our actor within the table view.
235     table.AddChild( tile, Toolkit::TableView::CellPosition( row, column ) );
236
237     tileNumber++;
238   }
239 }
240 Stage::GetCurrent().Add( table );
241 ~~~
242
243 ### Using accessibility within a custom control (C++) {#accessibilitycustomcontrol}
244
245 Accessibility behaviour can be customized in a custom UI control by overriding all or some of the following methods.
246
247 | Method                     | Description                                                                                                                                                                |
248 |----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
249 | OnAccessibilityActivated   | When the control is *activated* or selected, in accessibility mode.                                                                                                        |
250 | OnAccessibilityPan         | When an accessibility pan gesture occurs while this control is focussed.                                                                                                   |
251 | OnAccessibilityTouch       | Touch events are delivered differently in Accessibility mode. This method should be overridden if some special behaviour is required when these touch events are received. |
252 | OnAccessibilityValueChange | When a value is changed while this control is focussed (e.g. value change of a slider control).                                                                            |
253 | OnAccessibilityZoom        | Should be overridden if behaviour is required when the magnification level changes when this control is focussed.                                                          |
254  
255 If these events are consumed, then the method should return true.
256 The default behaviour in the control base classes returns false, i.e. not consumed.
257  
258 ### Using accessibility signals for extra control {#accessibilitysignals}
259
260 For more specific control of functionality when accessibility is enabled, there are several signals within the accessibility manager's public API that can be connected to.
261   
262 The main catagories of signals are:
263   
264 - The signal when the accessibility status is detected as being toggled on or off: StatusChangedSignal()
265 - Focus changes can cause FocusChangedSignal() and FocusOvershotSignal(). These can be connected to in order to provide custom actions when the focus is moved around the screen.
266 - The activated signal when an actor has been activated (typically by a focus, then double tap): ActionActivateSignal()
267 - Gesture received signals: There are many of these. They are each linked to the many accessibility gestures that can be received by the system.
268   
269 Please see accessibility-manager.h within DALi Toolkit for the full API.
270
271
272 @class _Guide_Accessibility
273 */