PageRenderTime 38ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/FD3/FlashDevelop/Bin/Debug/Library/AS3/frameworks/FlashIDE/fl/managers/FocusManager.as

https://bitbucket.org/kkszysiu/flashdevelop
ActionScript | 263 lines | 83 code | 3 blank | 177 comment | 0 complexity | 51f3cb73c7ad5a18cebd401bddf2905b MD5 | raw file
  1. package fl.managers
  2. {
  3. import flash.display.Sprite;
  4. import flash.display.MovieClip;
  5. import flash.display.Stage;
  6. import flash.display.SimpleButton;
  7. import flash.display.DisplayObject;
  8. import flash.display.DisplayObjectContainer;
  9. import flash.display.InteractiveObject;
  10. import flash.text.TextField;
  11. import flash.text.TextFieldType;
  12. import flash.ui.Keyboard;
  13. import flash.events.Event;
  14. import flash.events.FocusEvent;
  15. import flash.events.MouseEvent;
  16. import flash.events.KeyboardEvent;
  17. import fl.controls.Button;
  18. import fl.controls.TextInput;
  19. import fl.core.UIComponent;
  20. import flash.system.Capabilities;
  21. import flash.utils.*;
  22. /**
  23. * The FocusManager class manages focus for a set of components that are navigated by mouse * or keyboard as a <em>tab loop</em>. * * <p>A tab loop is typically navigated by using the Tab key; focus moves between the components * in the tab loop in a circular pattern from the first component that has focus, to the last, * and then back again to the first. A tab loop includes all the components and tab-enabled * components in a container. An application can contain numerous tab loops.</p> * * <p>A FocusManager instance is responsible for a single tab loop; an application uses * a different FocusManager instance to manage each tab loop that it contains, although * a main application is always associated with at least one FocusManager instance. An * application may require additional FocusManager instances if it includes a popup window, * for example, that separately contains one or more tab loops of components.</p> * * <p>All components that can be managed by a FocusManager instance must implement the * fl.managers.IFocusManagerComponent interface. Objects for which Flash Player * manages focus are not required to implement the IFocusManagerComponent interface.</p> * * <p>The FocusManager class also manages how the default button is implemented. A default button * dispatches a <code>click</code> event when the Enter key is pressed on a form, * depending on where focus is at the time. The default button does not dispatch the * <code>click</code> event if a text area has focus or if a value is being edited in * a component, for example, in a ComboBox or NumericStepper component.</p> * * @see IFocusManager * @see IFocusManagerComponent * * @includeExample examples/FocusManagerExample.as * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  24. */
  25. public class FocusManager implements IFocusManager
  26. {
  27. /**
  28. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  29. */
  30. private var _form : DisplayObjectContainer;
  31. /**
  32. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  33. */
  34. private var focusableObjects : Dictionary;
  35. /**
  36. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  37. */
  38. private var focusableCandidates : Array;
  39. /**
  40. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  41. */
  42. private var activated : Boolean;
  43. /**
  44. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  45. */
  46. private var calculateCandidates : Boolean;
  47. /**
  48. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  49. */
  50. private var lastFocus : InteractiveObject;
  51. /**
  52. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  53. */
  54. private var _showFocusIndicator : Boolean;
  55. /**
  56. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  57. */
  58. private var lastAction : String;
  59. /**
  60. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  61. */
  62. private var defButton : Button;
  63. /**
  64. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  65. */
  66. private var _defaultButton : Button;
  67. /**
  68. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  69. */
  70. private var _defaultButtonEnabled : Boolean;
  71. /**
  72. * Gets or sets the current default button. * * <p>The default button is the button on a form that dispatches a * <code>click</code> event when the Enter key is pressed, * depending on where focus is at the time.</p> * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  73. */
  74. public function get defaultButton () : Button;
  75. /**
  76. * @private (setter) * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  77. */
  78. public function set defaultButton (value:Button) : void;
  79. /**
  80. * @copy fl.managers.IFocusManager#defaultButtonEnabled * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  81. */
  82. public function get defaultButtonEnabled () : Boolean;
  83. /**
  84. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  85. */
  86. public function set defaultButtonEnabled (value:Boolean) : void;
  87. /**
  88. * Gets the next unique tab index to use in this tab loop. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  89. */
  90. public function get nextTabIndex () : int;
  91. /**
  92. * Gets or sets a value that indicates whether a component that has focus should be marked with a visual indicator of focus. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  93. */
  94. public function get showFocusIndicator () : Boolean;
  95. /**
  96. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  97. */
  98. public function set showFocusIndicator (value:Boolean) : void;
  99. /**
  100. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  101. */
  102. public function get form () : DisplayObjectContainer;
  103. /**
  104. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  105. */
  106. public function set form (value:DisplayObjectContainer) : void;
  107. /**
  108. * Creates a new FocusManager instance. * * <p>A focus manager manages focus within the children of a * DisplayObjectContainer object.</p> * * @param container A DisplayObjectContainer that hosts the focus manager, * or <code>stage</code>. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  109. */
  110. public function FocusManager (container:DisplayObjectContainer);
  111. /**
  112. * @private * Listen for children being added and see if they are focus candidates. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  113. */
  114. private function addedHandler (event:Event) : void;
  115. /**
  116. * @private * Listen for children being removed. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  117. */
  118. private function removedHandler (event:Event) : void;
  119. /**
  120. * @private * Do a tree walk and add all children you can find. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  121. */
  122. private function addFocusables (o:DisplayObject, skipTopLevel:Boolean = false) : void;
  123. /**
  124. * @private * Removes the DisplayObject and all its children. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  125. */
  126. private function removeFocusables (o:DisplayObject) : void;
  127. /**
  128. * @private * Checks if the DisplayObject is visible for the tab loop. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  129. */
  130. private function isTabVisible (o:DisplayObject) : Boolean;
  131. /**
  132. * @private * Checks if the DisplayObject is a valid candidate for the tab loop. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  133. */
  134. private function isValidFocusCandidate (o:DisplayObject, groupName:String) : Boolean;
  135. /**
  136. * @private * Checks if the DisplayObject is enabled and visible, or * a selectable or input TextField * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  137. */
  138. private function isEnabledAndVisible (o:DisplayObject) : Boolean;
  139. /**
  140. * @private * Add or remove object if tabbing properties change. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  141. */
  142. private function tabEnabledChangeHandler (event:Event) : void;
  143. /**
  144. * @private * Called when a focusable object's <code>tabIndex</code> property changes. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  145. */
  146. private function tabIndexChangeHandler (event:Event) : void;
  147. /**
  148. * @private * Add or remove object if tabbing properties change. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  149. */
  150. private function tabChildrenChangeHandler (event:Event) : void;
  151. /**
  152. * Activates the FocusManager instance. * * <p>The FocusManager instance adds event handlers that allow it to monitor * focus-related keyboard and mouse activity.</p> * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  153. */
  154. public function activate () : void;
  155. /**
  156. * Deactivates the FocusManager. * * <p>The FocusManager removes the event handlers that allow it to monitor * focus-related keyboard and mouse activity.</p> * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  157. */
  158. public function deactivate () : void;
  159. /**
  160. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  161. */
  162. private function focusInHandler (event:FocusEvent) : void;
  163. /**
  164. * @private * Useful for debugging. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  165. */
  166. private function focusOutHandler (event:FocusEvent) : void;
  167. /**
  168. * @private * Restore focus to the element that had it last. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  169. */
  170. private function activateHandler (event:Event) : void;
  171. /**
  172. * @private * Useful for debugging. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  173. */
  174. private function deactivateHandler (event:Event) : void;
  175. /**
  176. * @private * This gets called when mouse clicks on a focusable object. * We block Flash Player behavior. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  177. */
  178. private function mouseFocusChangeHandler (event:FocusEvent) : void;
  179. /**
  180. * @private * This function is called when the tab key is hit. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  181. */
  182. private function keyFocusChangeHandler (event:FocusEvent) : void;
  183. /**
  184. * @private * Watch for the Enter key. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  185. */
  186. private function keyDownHandler (event:KeyboardEvent) : void;
  187. /**
  188. * @private * This gets called when the focus changes due to a mouse click. * * <p><strong>Note:</strong> If focus is moving to a TextField, it is not * necessary to call <code>setFocus()</code> on it because the player handles it; * calling <code>setFocus()</code> on a TextField that has scrollable text * causes the text to auto-scroll to the end, making the * mouse click set the insertion point in the wrong place.</p> * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  189. */
  190. private function mouseDownHandler (event:MouseEvent) : void;
  191. /**
  192. * @private * Call this method to make the system * think the Enter key was pressed and the default button was clicked. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  193. */
  194. public function sendDefaultButtonEvent () : void;
  195. /**
  196. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  197. */
  198. private function setFocusToNextObject (event:FocusEvent) : void;
  199. /**
  200. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  201. */
  202. private function hasFocusableObjects () : Boolean;
  203. /**
  204. * Retrieves the interactive object that would receive focus * if the user pressed the Tab key to navigate to the next object. * This method retrieves the object that currently has focus * if there are no other valid objects in the application. * * @param backward If this parameter is set to <code>true</code>, * focus moves in a backward direction, causing this method to retrieve * the object that would receive focus next if the Shift+Tab key combination * were pressed. * * @return The next component to receive focus. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  205. */
  206. public function getNextFocusManagerComponent (backward:Boolean = false) : InteractiveObject;
  207. /**
  208. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  209. */
  210. private function getIndexOfFocusedObject (o:DisplayObject) : int;
  211. /**
  212. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  213. */
  214. private function getIndexOfNextObject (i:int, shiftKey:Boolean, bSearchAll:Boolean, groupName:String) : int;
  215. /**
  216. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  217. */
  218. private function sortFocusableObjects () : void;
  219. /**
  220. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  221. */
  222. private function sortFocusableObjectsTabIndex () : void;
  223. /**
  224. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  225. */
  226. private function sortByDepth (aa:InteractiveObject, bb:InteractiveObject) : Number;
  227. /**
  228. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  229. */
  230. private function getChildIndex (parent:DisplayObjectContainer, child:DisplayObject) : int;
  231. /**
  232. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  233. */
  234. private function sortByTabIndex (a:InteractiveObject, b:InteractiveObject) : int;
  235. /**
  236. * Gets the interactive object that currently has focus. * Adobe recommends calling this method instead of using the Stage object * because this method indicates which component has focus. * The Stage might return a subcomponent in that component. * * @return The interactive object that currently has focus. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  237. */
  238. public function getFocus () : InteractiveObject;
  239. /**
  240. * Sets focus on an IFocusManagerComponent component. This method does * not check for component visibility, enabled state, or other conditions. * * @param component An object that can receive focus. * * @internal Do you guys have a code snippet/test case/sample you could give us for this? (rberry(at)adobe.com) * Adobe: [LM] {StyleManager.setFocus(myBtn);} * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  241. */
  242. public function setFocus (component:InteractiveObject) : void;
  243. /**
  244. * Sets the <code>showFocusIndicator</code> value to <code>true</code> * and draws the visual focus indicator on the object with focus, if any. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  245. */
  246. public function showFocus () : void;
  247. /**
  248. * Sets the <code>showFocusIndicator</code> value to <code>false</code> * and removes the visual focus indicator from the object that has focus, if any. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  249. */
  250. public function hideFocus () : void;
  251. /**
  252. * Retrieves the interactive object that contains the given object, if any. * The player can set focus to a subcomponent of a Flash component; * this method determines which interactive object has focus from * the component perspective. * * @param component An object that can have player-level focus. * * @return The object containing the <code>component</code> or, if one is * not found, the <code>component</code> itself. * * @internal Description needs explanation of relationship between interactive object (param and return type) and * FocusManagerComponent, which the function claims to be finding. Do you guys have a code snippet/test * case/sample you could give us for this? (rberry(at)adobe.com) * Metaliq: Anybody? * Adobe: [LM] Changed description to InteractiveObject. This was changed to InteractiveObject because the FocusManager supports native flash objects too. * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  253. */
  254. public function findFocusManagerComponent (component:InteractiveObject) : InteractiveObject;
  255. /**
  256. * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0
  257. */
  258. private function getTopLevelFocusTarget (o:InteractiveObject) : InteractiveObject;
  259. }
  260. }