//////////////////////////////////////////////////////////////////////////////// // // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to You under the Apache License, Version 2.0 // (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //////////////////////////////////////////////////////////////////////////////// package spark.accessibility { import flash.accessibility.Accessibility; import flash.events.Event; import flash.events.KeyboardEvent; import flash.ui.Keyboard; import mx.accessibility.AccImpl; import mx.accessibility.AccConst; import mx.core.UIComponent; import mx.core.mx_internal; import spark.components.supportClasses.ButtonBase; import spark.components.supportClasses.ToggleButtonBase; use namespace mx_internal; /** * ButtonBaseAccImpl is the accessibility implementation class * for spark.components.supportClasses.ButtonBase. * *

Although ToggleButton, CheckBox, and RadioButton have their own * accessibility implementation subclasses, * Button simply uses the one for ButtonBase. * Therefore, the rest of this description refers to * the commonly-used Button component rather than the ButtonBase base class.

* *

When a Spark Button is created, * its accessibilityImplementation property * is set to an instance of this class. * The Flash Player then uses this class to allow MSAA clients * such as screen readers to see and manipulate the Button. * See the mx.accessibility.AccImpl and * flash.accessibility.AccessibilityImplementation classes * for background information about accessibility implementation * classes and MSAA.

* *

Children

* *

A Button has no MSAA children.

* *

Role

* *

The MSAA Role of a Button is ROLE_SYSTEM_PUSHBUTTON.

* *

Name

* *

The MSAA Name of a Button is, by default, the label that it displays. * When wrapped in a FormItem element, * this label will be combined with the FormItem's label. * To override this behavior, * set the Button's accessibilityName property.

* *

When the Name changes, * a Button dispatches the MSAA event EVENT_OBJECT_NAMECHANGE.

* *

Description

* *

The MSAA Description of a Button is, by default, the empty string, * but you can set the Button's accessibilityDescription * property.

* *

State

* *

The MSAA State of a Button is a combination of: *

* *

When the State changes, * a Button dispatches the MSAA event EVENT_OBJECT_STATECHANGE.

* *

Value

* *

A Button does not have an MSAA Value.

* *

Location

* *

The MSAA Location of a Button is its bounding rectangle.

* *

Default Action

* *

The MSAA DefaultAction of a Button is "Press".

* *

When an MSAA client tells the Button to perform this action, * KEY_DOWN and KEY_UP MouseEvents for the SPACE key are generated, * to simulate pressing the ButtonBase via the keyboard, * if the Button is enabled.

* *

Focus

* *

A Button accepts focus. * When it does so, it dispatches the MSAA event EVENT_OBJECT_FOCUS.

* *

Selection

* *

A Button does not support selection in the MSAA sense.

* * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ public class ButtonBaseAccImpl extends AccImpl { include "../core/Version.as"; //-------------------------------------------------------------------------- // // Class methods // //-------------------------------------------------------------------------- /** * Enables accessibility in the Button class. * *

This method is called by application startup code * that is autogenerated by the MXML compiler. * Afterwards, when instances of Button are initialized, * their accessibilityImplementation property * will be set to an instance of this class.

* * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ public static function enableAccessibility():void { ButtonBase.createAccessibilityImplementation = createAccessibilityImplementation; } /** * @private * Creates a Button's AccessibilityImplementation object. * This method is called from UIComponent's * initializeAccessibility() method. */ mx_internal static function createAccessibilityImplementation( component:UIComponent):void { component.accessibilityImplementation = new ButtonBaseAccImpl(component); } //-------------------------------------------------------------------------- // // Constructor // //-------------------------------------------------------------------------- /** * Constructor. * * @param master The UIComponent instance that this AccImpl instance * is making accessible. * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ public function ButtonBaseAccImpl(master:UIComponent) { super(master); role = AccConst.ROLE_SYSTEM_PUSHBUTTON; } //-------------------------------------------------------------------------- // // Overridden properties: AccImpl // //-------------------------------------------------------------------------- //---------------------------------- // eventsToHandle //---------------------------------- /** * @private * Array of events that we should listen for from the master component. */ override protected function get eventsToHandle():Array { return super.eventsToHandle.concat([ "click", "labelChanged" ]); } //-------------------------------------------------------------------------- // // Overridden methods: AccessibilityImplementation // //-------------------------------------------------------------------------- /** * @private * IAccessible method for returning the state of the Button. * States are predefined for all the components in MSAA. * Values are assigned to each state. * * @param childID uint * * @return State uint */ override public function get_accState(childID:uint):uint { var accState:uint = getState(childID); return accState; } /** * @private * IAccessible method for returning the default action * of the Button, which is Press. * * @param childID uint * * @return DefaultAction String */ override public function get_accDefaultAction(childID:uint):String { return "Press"; } /** * @private * IAccessible method for performing the default action * associated with Button, which is Press. * * @param childID uint */ override public function accDoDefaultAction(childID:uint):void { if (master.enabled) { var event:KeyboardEvent = new KeyboardEvent(KeyboardEvent.KEY_DOWN); event.keyCode = Keyboard.SPACE; master.dispatchEvent(event); event = new KeyboardEvent(KeyboardEvent.KEY_UP); event.keyCode = Keyboard.SPACE; master.dispatchEvent(event); } } //-------------------------------------------------------------------------- // // Overridden methods: AccImpl // //-------------------------------------------------------------------------- /** * @private * method for returning the name of the Button * which is spoken out by the screen reader * The Button should return the label inside as the name of the Button. * The name returned here would take precedence over the name * specified in the accessibility panel. * * @param childID uint * * @return Name String */ override protected function getName(childID:uint):String { var label:String = ButtonBase(master).label; return label != null && label != "" ? label : ""; } //-------------------------------------------------------------------------- // // Overridden event handlers: AccImpl // //-------------------------------------------------------------------------- /** * @private * Override the generic event handler. * All AccImpl must implement this * to listen for events from its master component. */ override protected function eventHandler(event:Event):void { // Let AccImpl class handle the events // that all accessible UIComponents understand. $eventHandler(event); switch (event.type) { case "click": { Accessibility.sendEvent(master, 0, AccConst.EVENT_OBJECT_STATECHANGE); Accessibility.updateProperties(); break; } case "labelChanged": { Accessibility.sendEvent(master, 0, AccConst.EVENT_OBJECT_NAMECHANGE); Accessibility.updateProperties(); break; } } } } }