/* Copyright (c) 2009 Yahoo! Inc. All rights reserved. The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license */ package com.yahoo.astra.fl.accessibility { import com.yahoo.astra.accessibility.EventTypes; import com.yahoo.astra.accessibility.ObjectRoles; import com.yahoo.astra.accessibility.ObjectStates; import com.yahoo.astra.fl.controls.mediaPlayerClasses.VolumeSlider; import fl.accessibility.AccImpl; import fl.core.UIComponent; import flash.accessibility.Accessibility; import flash.events.Event; /** * The VolumeSliderAccImpl class is the accessibility class for VolumeSlider, used in AudioPlayback. * * @author Alaric Cole */ public class VolumeSliderAccImpl extends AccImpl { //-------------------------------------------------------------------------- // // Class initialization // //-------------------------------------------------------------------------- /** * @private * Static variable triggering the hookAccessibility() method. * This is used for initializing VolumeSliderAccImpl class to hook its * createAccessibilityImplementation() method to VolumeSlider class * before it gets called from UIComponent. */ private static var accessibilityHooked:Boolean = hookAccessibility(); /** * @private * Static method for swapping the createAccessibilityImplementation() * method of VolumeSlider withthe VolumeSliderAccImpl class. */ private static function hookAccessibility():Boolean { VolumeSlider.createAccessibilityImplementation = createAccessibilityImplementation; return true; } override public function getChildIDArray():Array { var childIDs:Array = [0]; return childIDs; } /** * @private * Method for creating the Accessibility class. * This method is called from UIComponent. * @review */ public static function createAccessibilityImplementation(component:UIComponent):void { component.accessibilityImplementation = new VolumeSliderAccImpl(component); } /** * Method call for enabling accessibility for a component. * This method is required for the compiler to activate * the accessibility classes for a component. */ public static function enableAccessibility():void { } //-------------------------------------------------------------------------- // // Constructor // //-------------------------------------------------------------------------- /** * Constructor. * * @param master The UIComponent instance that this AccImpl instance * is making accessible. */ public function VolumeSliderAccImpl(master:UIComponent) { super(master); role = ObjectRoles.ROLE_SYSTEM_SLIDER; } /** * @private * Array of events that we should listen for from the master component. */ override protected function get eventsToHandle():Array { return super.eventsToHandle.concat([ "change" ]); } /** * @inheritDoc */ override public function get_accRole(childID:uint):uint { return role; } /** * @inheritDoc */ override public function get_accValue(childID:uint):String { var val:Number = Math.round(VolumeSlider(master).volume * 100); return val.toString() + " percent"; } /** * @inheritDoc */ override protected function getName(childID:uint):String { return "Volume"; } /** * @inheritDoc */ override public function get_accState(childID:uint):uint { var accState:uint = getState(childID); var master:VolumeSlider = VolumeSlider(master); accState = ObjectStates.STATE_SYSTEM_SELECTABLE | ObjectStates.STATE_SYSTEM_FOCUSABLE; accState |= ObjectStates.STATE_SYSTEM_FOCUSED; return accState; } /** * @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 { if (event.type == "change") { if(Accessibility.active) { Accessibility.sendEvent(master, 0, EventTypes.EVENT_OBJECT_VALUECHANGE, true) } } } } }