//////////////////////////////////////////////////////////////////////////////// // // 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.automation.delegates.components.supportClasses { import flash.display.DisplayObject; import flash.events.Event; import flash.events.KeyboardEvent; import flash.events.MouseEvent; import mx.automation.Automation; import mx.automation.IAutomationObject; import mx.automation.IAutomationObjectHelper; import mx.automation.events.AutomationDragEvent; import mx.automation.events.AutomationRecordEvent; import mx.core.EventPriority; import mx.core.UIComponent; import mx.core.mx_internal; import spark.automation.delegates.SparkRichEditableTextAutomationHelper; import spark.automation.tabularData.RichEditableTextTabularData; import spark.components.RichEditableText; import spark.components.Scroller; import spark.components.supportClasses.SkinnableTextBase; use namespace mx_internal; [Mixin] /** * * Defines methods and properties required to perform instrumentation for the * SkinnableTextBase control. * * @see spark.components.supportClasses.SkinnableTextBase * * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ public class SparkSkinnableTextBaseAutomationImpl extends SparkSkinnableComponentAutomationImpl { include "../../../../core/Version.as"; //-------------------------------------------------------------------------- // // Class methods // //-------------------------------------------------------------------------- /** * Registers the delegate class for a component class with automation manager. * * @param root The SystemManger of the application. * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ public static function init(root:DisplayObject):void { Automation.registerDelegateClass(spark.components.supportClasses.SkinnableTextBase, SparkSkinnableTextBaseAutomationImpl); } //-------------------------------------------------------------------------- // // Constructor // //-------------------------------------------------------------------------- /** * Constructor. * @param obj SkinnableTextBase object to be automated. * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ public function SparkSkinnableTextBaseAutomationImpl(obj:spark.components.supportClasses.SkinnableTextBase) { super(obj); obj.addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelHandler, false, EventPriority.DEFAULT+1, true ); } //-------------------------------------------------------------------------- // // Variables // //-------------------------------------------------------------------------- /** * @private * storage for the owner component */ protected function get skinnableTextBase():spark.components.supportClasses.SkinnableTextBase { return uiComponent as spark.components.supportClasses.SkinnableTextBase; } /** * @private * Generic record/replay logic for textfields. */ private var automationHelper:SparkRichEditableTextAutomationHelper; //-------------------------------------------------------------------------- // // Overridden properties // //-------------------------------------------------------------------------- //---------------------------------- // automationValue //---------------------------------- /** * @private */ override public function get automationValue():Array { return [ skinnableTextBase.text ]; } //-------------------------------------------------------------------------- // // Overridden methods // //-------------------------------------------------------------------------- /** * @private */ override public function replayAutomatableEvent(interaction:Event):Boolean { // For drag events, this needs to be handled by this object itself // instead of delegating it to its textDisplay // This is needed for AIR as we need to dispatch native drag events on // current object to handle drag drop events in AIR // This is working in Flex even without this special handling because // drag events are automatically triggered by mouse events in Flex. // But this is not the case in AIR. Mouse events do not trigger those // native drag events and so we need to construct those events manually // and dispatch them on the corresponding objects to replay them. if(interaction is AutomationDragEvent) return super.replayAutomatableEvent(interaction); // we have delegated the replay to the underlying the richEditabale Text. if(skinnableTextBase.textDisplay is RichEditableText) return RichEditableText(skinnableTextBase.textDisplay).replayAutomatableEvent(interaction); else return super.replayAutomatableEvent(interaction); } //-------------------------------------------------------------------------- // // Event handlers // //-------------------------------------------------------------------------- /** * Method which gets called after the component has been initialized. * This can be used to access any sub-components and act on the component. * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 1.5 * @productversion Flex 4 */ override protected function componentInitialized():void { super.componentInitialized(); skinnableTextBase.addEventListener(AutomationRecordEvent.RECORD, inputField_recordHandler1, false, 0, true); } private function inputField_recordHandler1(event1:AutomationRecordEvent):void { if(event1.automationObject == skinnableTextBase.textDisplay) { // let us record the evnet from the richEditableText as our event recordAutomatableEvent(event1.replayableEvent); } } /** * @private * Prevent duplicate ENTER key recordings. */ override protected function keyDownHandler(event:KeyboardEvent):void { ; } /** * @private */ override public function get automationTabularData():Object { return new RichEditableTextTabularData(skinnableTextBase.textDisplay as RichEditableText); } /** * @private */ override public function get numAutomationChildren():int { var scrollBars:Array = getScrollBars(skinnableTextBase,skinnableTextBase.skin); return scrollBars?scrollBars.length:0; } override public function getAutomationChildAt(index:int):IAutomationObject { var scrollBars:Array = getScrollBars(skinnableTextBase,skinnableTextBase.skin); if(scrollBars && index < scrollBars.length) return scrollBars[index]; return null; } /** * @private */ override public function getAutomationChildren():Array { return getScrollBars(skinnableTextBase,skinnableTextBase.skin); } protected function getScrollBars(passedObj:Object, stopWithSkin:UIComponent):Array { var scroller:spark.components.Scroller = null; if(passedObj) scroller = getScroller(passedObj,null); else scroller = getScroller(skinnableTextBase,stopWithSkin); if(scroller) { var tempArray:Array = new Array(); if(scroller.horizontalScrollBar) tempArray.push(scroller.horizontalScrollBar); if(scroller.verticalScrollBar) tempArray.push(scroller.verticalScrollBar); } return tempArray; } protected function getScroller(passedObj:Object, stopWithSkin:UIComponent):spark.components.Scroller { if(passedObj) { if( !(passedObj.hasOwnProperty("numChildren") && passedObj.hasOwnProperty("getChildAt"))) return null; } var requiredObject:Object = null; if(passedObj) requiredObject = passedObj; else // just to ensure that if no object is passed, we will consider it on the // current object. requiredObject = skinnableTextBase; var n:int = requiredObject.numChildren; var obj:Object; for (var i:int = 0; i