1////////////////////////////////////////////////////////////////////////////////
2//
3//  ADOBE SYSTEMS INCORPORATED
4//  Copyright 2009 Adobe Systems Incorporated
5//  All Rights Reserved.
6//
7//  NOTICE: Adobe permits you to use, modify, and distribute this file
8//  in accordance with the terms of the license agreement accompanying it.
9//
10////////////////////////////////////////////////////////////////////////////////
11
12package spark.accessibility
13{
14
15import mx.accessibility.AccConst;
16import mx.accessibility.AccImpl
17import mx.core.UIComponent;
18import mx.core.mx_internal;
19
20import spark.components.supportClasses.ToggleButtonBase;
21
22use namespace mx_internal;
23
24/**
25 *  ToggleButtonAccImpl is the accessibility implementation class
26 *  for spark.components.ToggleButton.
27 *
28 *  <p>When a Spark ToggleButton is created,
29 *  its <code>accessibilityImplementation</code> property
30 *  is set to an instance of this class.
31 *  The Flash Player then uses this class to allow MSAA clients
32 *  such as screen readers to see and manipulate the ToggleButton.
33 *  See the mx.accessibility.AccImpl and
34 *  flash.accessibility.AccessibilityImplementation classes
35 *  for background information about accessibility implementation
36 *  classes and MSAA.</p>
37 *
38 *  <p><b>Children</b></p>
39 *
40 *  <p>A ToggleButton has no MSAA children.</p>
41 *
42 *  <p><b>Role</b></p>
43 *
44 *  <p>The MSAA Role of a ToggleButton is ROLE_SYSTEM_PUSHBUTTON.</p>
45 *
46 *  <p><b>Name</b></p>
47 *
48 *  <p>The MSAA Name of a ToggleButton is, by default,
49 *  the label that it displays.
50 *  When wrapped in a FormItem element,
51 *  this label will be combined with the FormItem's label.
52 *  To override this behavior,
53 *  set the ToggleButton's <code>accessibilityName</code> property.</p>
54 *
55 *  <p>To provide two separate names for the different states
56 *  of an icon-based ToggleButton (such as "Mute" and "Unmute",
57 *  or "Play" and "Pause"), both names can be separated by a comma
58 *  in the <code>accessibilityName</code> property, as in
59 *  <code>accessibilityProperty="Mute,Unmute"</code>.
60 *  When using state specific names like this
61 *  the button will not exposed the "pressed" state when pressed.</p>
62 *
63 *  <p>When the Name changes,
64 *  a ToggleButton dispatches the MSAA event EVENT_OBJECT_NAMECHANGE.</p>
65 *
66 *  <p><b>Description</b></p>
67 *
68 *  <p>The MSAA Description of a ToggleButton is, by default, the empty string,
69 *  but you can set the ToggleButton's <code>accessibilityDescription</code>
70 *  property.</p>
71 *
72 *  <p><b>State</b></p>
73 *
74 *  <p>The MSAA State of a ToggleButton is a combination of:
75 *  <ul>
76 *    <li>STATE_SYSTEM_UNAVAILABLE (when enabled is false)</li>
77 *    <li>STATE_SYSTEM_FOCUSABLE (when enabled is true)</li>
78 *    <li>STATE_SYSTEM_FOCUSED (when enabled is true
79 *    and the CheckBox has focus)</li>
80 *    <li>STATE_SYSTEM_PRESSED (when selected is true;
81 *    not used when state specific names are provided)</li>
82 *  </ul></p>
83 *
84 *  <p>When the State changes,
85 *  a ToggleButton dispatches the MSAA event EVENT_OBJECT_STATECHANGE.</p>
86 *
87 *  <p><b>Value</b></p>
88 *
89 *  <p>A ToggleButton does not have an MSAA Value.</p>
90 *
91 *  <p><b>Location</b></p>
92 *
93 *  <p>The MSAA Location of a ToggleButton is its bounding rectangle.</p>
94 *
95 *  <p><b>Default Action</b></p>
96 *
97 *  <p>The MSAA DefaultAction of a ToggleButton is "Toggle".</p>
98 *
99 *  <p>When an MSAA client tells the Button to perform this action,
100 *  KEY_DOWN and KEY_UP MouseEvents for the SPACE key are generated,
101 *  to simulate pressing the ToggleButton via the keyboard,
102 *  if the ToggleButton is enabled.</p>
103 *
104 *  <p><b>Focus</b></p>
105 *
106 *  <p>A ToggleButton accepts focus.
107 *  When it does so, it dispatches the MSAA event EVENT_OBJECT_FOCUS.</p>
108 *
109 *  <p><b>Selection</b></p>
110 *
111 *  <p>A ToggleButton does not support selection in the MSAA sense.</p>
112 *
113 *  @langversion 3.0
114 *  @playerversion Flash 10
115 *  @playerversion AIR 1.5
116 *  @productversion Flex 4
117 */
118public class ToggleButtonAccImpl extends ButtonBaseAccImpl
119{
120    include "../core/Version.as";
121
122    //--------------------------------------------------------------------------
123    //
124    //  Class methods
125    //
126    //--------------------------------------------------------------------------
127
128    /**
129     *  Enables accessibility in the ToggleButton class.
130     *
131     *  <p>This method is called by application startup code
132     *  that is autogenerated by the MXML compiler.
133     *  Afterwards, when instances of ToggleButton are initialized,
134     *  their <code>accessibilityImplementation</code> property
135     *  will be set to an instance of this class.</p>
136     *
137     *  @langversion 3.0
138     *  @playerversion Flash 10
139     *  @playerversion AIR 1.5
140     *  @productversion Flex 4
141     */
142    public static function enableAccessibility():void
143    {
144        ToggleButtonBase.createAccessibilityImplementation =
145            createAccessibilityImplementation;
146    }
147
148    /**
149     *  @private
150     *  Creates a ToggleButton's AccessibilityImplementation object.
151     *  This method is called from UIComponent's
152     *  initializeAccessibility() method.
153     */
154    mx_internal static function createAccessibilityImplementation(
155        component:UIComponent):void
156    {
157        component.accessibilityImplementation =
158            new ToggleButtonAccImpl(component);
159    }
160
161    //--------------------------------------------------------------------------
162    //
163    //  Constructor
164    //
165    //--------------------------------------------------------------------------
166
167    /**
168     *  Constructor.
169     *
170     *  @param master The UIComponent instance that this AccImpl instance
171     *  is making accessible.
172     *
173     *  @langversion 3.0
174     *  @playerversion Flash 10
175     *  @playerversion AIR 1.5
176     *  @productversion Flex 4
177     */
178    public function ToggleButtonAccImpl(master:UIComponent)
179    {
180        super(master);
181    }
182
183    //--------------------------------------------------------------------------
184    //
185    //  Overridden methods: AccessibilityImplementation
186    //
187    //--------------------------------------------------------------------------
188
189    /**
190     *  @private
191     *  Returns the name of the component.
192	 *  If accessibilityName is set and divided by a comma, the first part
193     *  will be exposed as the default name, and the second part as the name
194     *  when the button is pressed.
195     *
196     *  @param childID uint.
197     *
198     *  @return Name of the component.
199     *
200     */
201    override public function get_accName(childID:uint):String
202    {
203        var accName:String;
204        if (master.accessibilityName && master.accessibilityName.indexOf(",") != -1)
205        {
206            accName = AccImpl.getFormName(master);
207            var stateNames:Array = master.accessibilityName.split(",");
208            accName += " " + (ToggleButtonBase(master).selected ?
209                stateNames[1] : stateNames[0]);
210        }
211        else
212            accName = super.get_accName(0);
213
214        return accName;
215    }
216
217    /**
218     *  @private
219     *  IAccessible method for returning the state of the ToggleButton.
220     *  States are predefined for all the components in MSAA.
221     *  Values are assigned to each state.
222     *  Depending upon the Togglebutton being pressed or released,
223     *  a value is returned.
224     *
225     *  @param childID uint
226     *
227     *  @return State uint
228     */
229    override public function get_accState(childID:uint):uint
230    {
231        var accState:uint = getState(childID);
232        if (ToggleButtonBase(master).selected && (!master.accessibilityName ||
233            master.accessibilityName.indexOf(",") == -1))
234            accState |= AccConst.STATE_SYSTEM_PRESSED;
235
236        return accState;
237    }
238
239}
240
241}
242