PageRenderTime 94ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/Sample/mx/core/UITextField.as

https://github.com/ingydotnet/yaml-oscon2009-talk
ActionScript | 2056 lines | 776 code | 284 blank | 996 comment | 98 complexity | 64d84e499c9368bbaeb459da69f2be83 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // ADOBE SYSTEMS INCORPORATED
  4. // Copyright 2004-2007 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. package mx.core
  12. {
  13. import flash.display.DisplayObject;
  14. import flash.display.DisplayObjectContainer;
  15. import flash.display.Sprite;
  16. import flash.events.Event;
  17. import flash.text.TextField;
  18. import flash.text.TextFormat;
  19. import flash.text.TextLineMetrics;
  20. import flash.utils.getQualifiedClassName;
  21. import mx.automation.IAutomationObject;
  22. import mx.core.FlexVersion;
  23. import mx.managers.ISystemManager;
  24. import mx.managers.IToolTipManagerClient;
  25. import mx.managers.SystemManager;
  26. import mx.managers.ToolTipManager;
  27. import mx.resources.IResourceManager;
  28. import mx.resources.ResourceManager;
  29. import mx.styles.ISimpleStyleClient;
  30. import mx.styles.IStyleClient;
  31. import mx.styles.StyleManager;
  32. import mx.styles.StyleProtoChain;
  33. import mx.utils.StringUtil;
  34. use namespace mx_internal;
  35. include "../styles/metadata/LeadingStyle.as"
  36. include "../styles/metadata/PaddingStyles.as"
  37. include "../styles/metadata/TextStyles.as"
  38. [ResourceBundle("core")]
  39. /**
  40. * The UITextField class defines the component used by many Flex
  41. * components to display text.
  42. * For example, the mx.controls.Button control uses a
  43. * UITextField component to define the label area of the Button control.
  44. *
  45. * <p>The UITextField class extends the flash.text.TextField class to
  46. * support additional functionality required by Flex, such as CSS styles,
  47. * invalidation/measurement/layout, enabling/disabling, tooltips, and IME
  48. * (Input Method Editor) support for entering Chinese, Japanese, and
  49. * Korean text.</p>
  50. *
  51. * @see flash.text.TextField
  52. * @see mx.core.UITextFormat
  53. */
  54. public class UITextField extends FlexTextField
  55. implements IAutomationObject, IIMESupport,
  56. IFlexModule,
  57. IInvalidating, ISimpleStyleClient,
  58. IToolTipManagerClient, IUITextField
  59. {
  60. include "../core/Version.as";
  61. //--------------------------------------------------------------------------
  62. //
  63. // Implementation notes
  64. //
  65. //--------------------------------------------------------------------------
  66. /*
  67. UITextField extends the Player's TextField class,
  68. so here are some notes about TextField.
  69. The property values of a new TextField are as follows:
  70. alwaysShowSelection = false
  71. autoSize = TextFieldAutoSize.NONE
  72. background = false
  73. backgroundColor = 0xFFFFFF
  74. border = false
  75. borderColor = 0x000000
  76. caretIndex = 0
  77. condenseWhite = false
  78. displayAsPassword = false
  79. embedFonts = false
  80. height = 100
  81. htmlText = ""
  82. length = 0
  83. maxChars = 0
  84. mouseWheelEnabled = true
  85. multiline = false
  86. numLines = 1
  87. restrict = null
  88. selectable = true
  89. selectionBeginIndex = 0
  90. selectionEndIndex = 0
  91. text = ""
  92. textColor = 0x000000
  93. textHeight = 0
  94. textWidth = 0
  95. type = TextFieldType.DYNAMIC
  96. width = 100
  97. wordWrap = false
  98. Many of these properties are coupled.
  99. For example, setting 'text' affects 'htmlText', 'length',
  100. 'textWidth', and 'textHeight'.
  101. If 'autoSize' isn't "none", it also affects 'width' and 'height'.
  102. The 'htmlText' getter and setter aren't symmetrical;
  103. if you set it and then get it, you don't get what you just set;
  104. you'll get additional HTML markup corresponding to the
  105. defaultTextFormat.
  106. If you set both the 'text' and the 'htmlText' properties
  107. of a TextField, the last one set wins.
  108. These setters do a lot of work; for example, suppose you set the 'text'.
  109. If it is an autosizing TextField, it computes the new width and height.
  110. If it is a wordwrapping TextField, it computes the appropriate line
  111. breaks.
  112. If you then get the 'text' property, it is what you just set.
  113. If you get the 'length', it is the length of the 'text' string.
  114. If you get the 'htmlText', it will contain a lot of autogenerated
  115. HTML markup corresponding to the defaultTextFormat, which was applied
  116. as a run across the entire new text.
  117. Now suppose you set the 'htmlText' property.
  118. The Player parses the string, separating the text characters
  119. from the markup.
  120. It first applies the defaultTextFormat as a run across the entire new
  121. text; it then uses the markup to modify this TextFormat or create
  122. additional TextFormat runs.
  123. When it's done it discards the 'htmlText' string that you set.
  124. If you then get the 'htmlText', it will not be what you just set; it
  125. will contain additional HTML markup corresponding to defaultTextFormat
  126. If you get the 'text', it will be text characters in the 'htmlText',
  127. without any of the HTML markup.
  128. If you get the 'length', it is the length of the 'text' string.
  129. If you set a TextFormat run with setTextFormat(), it will change the
  130. runs created from the HTML markup in the 'htmlText' that was last set.
  131. This is why, in the validateNow() method in UITextField, the original
  132. 'htmlText' is reapplied after the TextFormat is changed.
  133. The 'condenseWhite' property only applies when setting 'htmlText',
  134. not 'text'.
  135. Changing 'condenseWhite' after setting 'htmlText' doesn't affect
  136. anything except future settings of 'htmlText'.
  137. The width and height of the TextField are 4 pixels greater than
  138. the textWidth and textHeight.
  139. */
  140. //--------------------------------------------------------------------------
  141. //
  142. // Class constants
  143. //
  144. //--------------------------------------------------------------------------
  145. /**
  146. * @private
  147. * The padding to be added to textWidth to get the width
  148. * of a TextField that can display the text without clipping.
  149. */
  150. mx_internal static const TEXT_WIDTH_PADDING:int = 5;
  151. /**
  152. * @private
  153. * The padding to be added to textHeight to get the height
  154. * of a TextField that can display the text without clipping.
  155. */
  156. mx_internal static const TEXT_HEIGHT_PADDING:int = 4;
  157. //--------------------------------------------------------------------------
  158. //
  159. // Class variables
  160. //
  161. //--------------------------------------------------------------------------
  162. /**
  163. * @private
  164. * Most resources are fetched on the fly from the ResourceManager,
  165. * so they automatically get the right resource when the locale changes.
  166. * But since truncateToFit() can be called frequently,
  167. * this class caches this resource value in this variable
  168. * and updates it when the locale changes.
  169. */
  170. private static var truncationIndicatorResource:String;
  171. /**
  172. * @private
  173. */
  174. mx_internal static var debuggingBorders:Boolean = false;
  175. //--------------------------------------------------------------------------
  176. //
  177. // Class properties
  178. //
  179. //--------------------------------------------------------------------------
  180. //----------------------------------
  181. // embeddedFontRegistry
  182. //----------------------------------
  183. /**
  184. * @private
  185. * Storage for the _embeddedFontRegistry property.
  186. * Note: This gets initialized on first access,
  187. * not when this class is initialized, in order to ensure
  188. * that the Singleton registry has already been initialized.
  189. */
  190. private static var _embeddedFontRegistry:IEmbeddedFontRegistry;
  191. /**
  192. * @private
  193. * A reference to the embedded font registry.
  194. * Single registry in the system.
  195. * Used to look up the moduleFactory of a font.
  196. */
  197. private static function get embeddedFontRegistry():IEmbeddedFontRegistry
  198. {
  199. if (!_embeddedFontRegistry)
  200. {
  201. _embeddedFontRegistry = IEmbeddedFontRegistry(
  202. Singleton.getInstance("mx.core::IEmbeddedFontRegistry"));
  203. }
  204. return _embeddedFontRegistry;
  205. }
  206. //--------------------------------------------------------------------------
  207. //
  208. // Constructor
  209. //
  210. //--------------------------------------------------------------------------
  211. /**
  212. * Constructor.
  213. */
  214. public function UITextField()
  215. {
  216. super();
  217. // Although a TextField's 'text' is initially "",
  218. // getLineMetrics() will return bad values until some text is set.
  219. super.text = "";
  220. focusRect = false;
  221. selectable = false;
  222. tabEnabled = false;
  223. if (debuggingBorders)
  224. border = true;
  225. if (!truncationIndicatorResource)
  226. {
  227. truncationIndicatorResource = resourceManager.getString(
  228. "core", "truncationIndicator");
  229. }
  230. addEventListener(Event.CHANGE, changeHandler);
  231. addEventListener("textFieldStyleChange", textFieldStyleChangeHandler);
  232. // Register as a weak listener for "change" events from ResourceManager.
  233. // If UITextFields registered as a strong listener,
  234. // they wouldn't get garbage collected.
  235. resourceManager.addEventListener(
  236. Event.CHANGE, resourceManager_changeHandler, false, 0, true);
  237. }
  238. //--------------------------------------------------------------------------
  239. //
  240. // Variables
  241. //
  242. //--------------------------------------------------------------------------
  243. /**
  244. * @private
  245. * Cached value of the TextFormat read from the Styles.
  246. */
  247. private var cachedTextFormat:TextFormat;
  248. /**
  249. * @private
  250. *
  251. * Cache last value of embedded font.
  252. */
  253. private var cachedEmbeddedFont:EmbeddedFont = null;
  254. /**
  255. * @private
  256. */
  257. private var invalidateDisplayListFlag:Boolean = true;
  258. /**
  259. * @private
  260. */
  261. mx_internal var styleChangedFlag:Boolean = true;
  262. /**
  263. * @private
  264. * This var is either the last value of 'htmlText' that was set
  265. * or null (if 'text' was set instead of 'htmlText').
  266. *
  267. * This var is different from getting the 'htmlText',
  268. * because when you set 'htmlText' into a TextField and then get it,
  269. * you don't get what you set; what you get includes additional
  270. * HTML markup generated from the defaultTextFormat
  271. * (which for a Flex component is based on the CSS styles).
  272. *
  273. * When you set 'htmlText', a TextField parses through it
  274. * and creates TextFormat runs based on the HTML markup.
  275. * It applies these on top of the defaultTextFormat.
  276. * A TextField saves the non-markup characters as the 'text',
  277. * but it doesn't save the original 'htmlText',
  278. * so we have to do this ourselves.
  279. *
  280. * If the CSS styles change, validateNow() will get called
  281. * and a new TextFormat based on the new CSS styles
  282. * will get applied to the entire TextField, wiping
  283. * out any TextFormats that came from the HTML markup.
  284. * So we use this var to re-apply the original markup
  285. * after a CSS change.
  286. */
  287. private var explicitHTMLText:String = null;
  288. /**
  289. * @private
  290. * Color set explicitly by setColor(); overrides style lookup.
  291. */
  292. mx_internal var explicitColor:uint = StyleManager.NOT_A_COLOR;
  293. /**
  294. * @private
  295. */
  296. private var resourceManager:IResourceManager =
  297. ResourceManager.getInstance();
  298. /**
  299. * @private
  300. */
  301. private var untruncatedText:String;
  302. //--------------------------------------------------------------------------
  303. //
  304. // Overridden properties
  305. //
  306. //--------------------------------------------------------------------------
  307. //----------------------------------
  308. // htmlText
  309. //----------------------------------
  310. /**
  311. * @private
  312. */
  313. override public function set htmlText(value:String):void
  314. {
  315. // TextField's htmlText property can't be set to null.
  316. if (!value)
  317. value = "";
  318. // Performance optimization: if the htmlText hasn't changed,
  319. // don't let the player think that we're dirty.
  320. if (isHTML && super.htmlText == value)
  321. return;
  322. // Reapply the format because TextField would otherwise reset to
  323. // black, Times New Roman, 12
  324. if (cachedTextFormat && styleSheet == null)
  325. defaultTextFormat = cachedTextFormat;
  326. super.htmlText = value;
  327. // Remember the htmlText that we've set,
  328. // because the TextField doesn't remember it for us.
  329. // We need it so that we can re-apply the HTML markup
  330. // in validateNow() after the CSS styles change
  331. explicitHTMLText = value;
  332. if (invalidateDisplayListFlag)
  333. validateNow();
  334. }
  335. //----------------------------------
  336. // parent
  337. //----------------------------------
  338. /**
  339. * @private
  340. * Reference to this component's virtual parent container.
  341. * "Virtual" means that this parent may not be the same
  342. * as the one that the Player returns as the 'parent'
  343. * property of a DisplayObject.
  344. * For example, if a Container has created a contentPane
  345. * to improve scrolling performance,
  346. * then its "children" are really its grandchildren
  347. * and their "parent" is actually their grandparent,
  348. * because we don't want developers to be concerned with
  349. * whether a contentPane exists or not.
  350. */
  351. mx_internal var _parent:DisplayObjectContainer;
  352. /**
  353. * The parent container or component for this component.
  354. */
  355. override public function get parent():DisplayObjectContainer
  356. {
  357. // Flash PlaceObject tags can have super.parent set
  358. // before we get to setting the _parent property.
  359. return _parent ? _parent : super.parent;
  360. }
  361. //----------------------------------
  362. // text
  363. //----------------------------------
  364. /**
  365. * @private
  366. */
  367. override public function set text(value:String):void
  368. {
  369. // TextField's text property can't be set to null.
  370. if (!value)
  371. value = "";
  372. // Performance optimization: if the text hasn't changed,
  373. // don't let the player think that we're dirty.
  374. if (!isHTML && super.text == value)
  375. return;
  376. super.text = value;
  377. explicitHTMLText = null;
  378. if (invalidateDisplayListFlag)
  379. validateNow();
  380. }
  381. //--------------------------------------------------------------------------
  382. //
  383. // Properties
  384. //
  385. //--------------------------------------------------------------------------
  386. //----------------------------------
  387. // automationDelegate
  388. //----------------------------------
  389. /**
  390. * @private
  391. */
  392. private var _automationDelegate:IAutomationObject;
  393. /**
  394. * The delegate object which is handling the automation related functionality.
  395. *
  396. */
  397. public function get automationDelegate():Object
  398. {
  399. return _automationDelegate;
  400. }
  401. /**
  402. * @private
  403. */
  404. public function set automationDelegate(value:Object):void
  405. {
  406. _automationDelegate = value as IAutomationObject;
  407. }
  408. //----------------------------------
  409. // automationName
  410. //----------------------------------
  411. /**
  412. * @private
  413. * Storage for the automationName property.
  414. */
  415. private var _automationName:String;
  416. /**
  417. * @inheritDoc
  418. */
  419. public function get automationName():String
  420. {
  421. if (_automationName)
  422. return _automationName;
  423. if (automationDelegate)
  424. return automationDelegate.automationName;
  425. return "";
  426. }
  427. /**
  428. * @private
  429. */
  430. public function set automationName(value:String):void
  431. {
  432. _automationName = value;
  433. }
  434. /**
  435. * @inheritDoc
  436. */
  437. public function get automationValue():Array
  438. {
  439. if (automationDelegate)
  440. return automationDelegate.automationValue;
  441. return [""];
  442. }
  443. //----------------------------------
  444. // baselinePosition
  445. //----------------------------------
  446. /**
  447. * The y-coordinate of the baseline of the first line of text.
  448. */
  449. public function get baselinePosition():Number
  450. {
  451. var tlm:TextLineMetrics;
  452. if (FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
  453. {
  454. tlm = getLineMetrics(0);;
  455. return height - 4 - tlm.descent;
  456. }
  457. // The text styles aren't known until there is a parent.
  458. if (!parent)
  459. return NaN;
  460. // getLineMetrics() returns strange numbers for an empty string,
  461. // so instead we get the metrics for a non-empty string.
  462. var isEmpty:Boolean = text == "";
  463. if (isEmpty)
  464. super.text = "Wj";
  465. tlm = getLineMetrics(0);
  466. if (isEmpty)
  467. super.text = "";
  468. // TextFields have 2 pixels of padding all around.
  469. return 2 + tlm.ascent;
  470. }
  471. //----------------------------------
  472. // className
  473. //----------------------------------
  474. /**
  475. * The name of this instance's class, such as
  476. * <code>"DataGridItemRenderer"</code>.
  477. *
  478. * <p>This string does not include the package name.
  479. * If you need the package name as well, call the
  480. * <code>getQualifiedClassName()</code> method in the flash.utils package.
  481. * It will return a string such as
  482. * <code>"mx.controls.dataGridClasses::DataGridItemRenderer"</code>.</p>
  483. */
  484. public function get className():String
  485. {
  486. var name:String = getQualifiedClassName(this);
  487. // If there is a package name, strip it off.
  488. var index:int = name.indexOf("::");
  489. if (index != -1)
  490. name = name.substr(index + 2);
  491. return name;
  492. }
  493. //----------------------------------
  494. // document
  495. //----------------------------------
  496. /**
  497. * @private
  498. * Storage for the enabled property.
  499. */
  500. private var _document:Object;
  501. /**
  502. * A reference to the document object associated with this UITextField object.
  503. * A document object is an Object at the top of the hierarchy of a Flex application,
  504. * MXML component, or AS component.
  505. */
  506. public function get document():Object
  507. {
  508. return _document;
  509. }
  510. /**
  511. * @private
  512. */
  513. public function set document(value:Object):void
  514. {
  515. _document = value;
  516. }
  517. //----------------------------------
  518. // enabled
  519. //----------------------------------
  520. /**
  521. * @private
  522. * Storage for the enabled property.
  523. */
  524. private var _enabled:Boolean = true;
  525. /**
  526. * A Boolean value that indicates whether the component is enabled.
  527. * This property only affects
  528. * the color of the text and not whether the UITextField is editable.
  529. * To control editability, use the
  530. * <code>flash.text.TextField.type</code> property.
  531. *
  532. * @default true
  533. * @see flash.text.TextField
  534. */
  535. public function get enabled():Boolean
  536. {
  537. return _enabled;
  538. }
  539. /**
  540. * @private
  541. */
  542. public function set enabled(value:Boolean):void
  543. {
  544. mouseEnabled = value;
  545. _enabled = value;
  546. styleChanged("color");
  547. }
  548. //----------------------------------
  549. // explicitHeight
  550. //----------------------------------
  551. /**
  552. * @private
  553. * Storage for the explicitHeight property.
  554. */
  555. private var _explicitHeight:Number;
  556. /**
  557. * @copy mx.core.UIComponent#explicitHeight
  558. */
  559. public function get explicitHeight():Number
  560. {
  561. return _explicitHeight;
  562. }
  563. /**
  564. * @private
  565. */
  566. public function set explicitHeight(value:Number):void
  567. {
  568. _explicitHeight = value;
  569. }
  570. //----------------------------------
  571. // explicitMaxHeight
  572. //----------------------------------
  573. /**
  574. * Number that specifies the maximum height of the component,
  575. * in pixels, in the component's coordinates, if the maxHeight property
  576. * is set. Because maxHeight is read-only, this method returns NaN.
  577. * You must override this method and add a setter to use this
  578. * property.
  579. *
  580. * @see mx.core.UIComponent#explicitMaxHeight
  581. *
  582. * @default NaN
  583. */
  584. public function get explicitMaxHeight():Number
  585. {
  586. return NaN;
  587. }
  588. //----------------------------------
  589. // explicitMaxWidth
  590. //----------------------------------
  591. /**
  592. * Number that specifies the maximum width of the component,
  593. * in pixels, in the component's coordinates, if the maxWidth property
  594. * is set. Because maxWidth is read-only, this method returns NaN.
  595. * You must override this method and add a setter to use this
  596. * property.
  597. *
  598. * @see mx.core.UIComponent#explicitMaxWidth
  599. *
  600. * @default NaN
  601. */
  602. public function get explicitMaxWidth():Number
  603. {
  604. return NaN;
  605. }
  606. //----------------------------------
  607. // explicitMinHeight
  608. //----------------------------------
  609. /**
  610. * @copy mx.core.UIComponent#explicitMinHeight
  611. */
  612. public function get explicitMinHeight():Number
  613. {
  614. return NaN;
  615. }
  616. //----------------------------------
  617. // explicitMinWidth
  618. //----------------------------------
  619. /**
  620. * @copy mx.core.UIComponent#explicitMinWidth
  621. */
  622. public function get explicitMinWidth():Number
  623. {
  624. return NaN;
  625. }
  626. //----------------------------------
  627. // explicitWidth
  628. //----------------------------------
  629. /**
  630. * @private
  631. * Storage for the explicitWidth property.
  632. */
  633. private var _explicitWidth:Number;
  634. /**
  635. * @copy mx.core.UIComponent#explicitWidth
  636. */
  637. public function get explicitWidth():Number
  638. {
  639. return _explicitWidth;
  640. }
  641. /**
  642. * @private
  643. */
  644. public function set explicitWidth(value:Number):void
  645. {
  646. _explicitWidth = value;
  647. }
  648. //----------------------------------
  649. // focusPane
  650. //----------------------------------
  651. /**
  652. * @inheritDoc
  653. */
  654. public function get focusPane():Sprite
  655. {
  656. return null;
  657. }
  658. /**
  659. * @private
  660. */
  661. public function set focusPane(value:Sprite):void
  662. {
  663. }
  664. //----------------------------------
  665. // ignorePadding
  666. //----------------------------------
  667. /**
  668. * @private
  669. * Storage for the ignorePadding property.
  670. */
  671. private var _ignorePadding:Boolean = true;
  672. /**
  673. * If <code>true</code>, the <code>paddingLeft</code> and
  674. * <code>paddingRight</code> styles will not add space
  675. * around the text of the component.
  676. *
  677. * @default true
  678. */
  679. public function get ignorePadding():Boolean
  680. {
  681. return _ignorePadding;
  682. }
  683. /**
  684. * @private
  685. */
  686. public function set ignorePadding(value:Boolean):void
  687. {
  688. _ignorePadding = value;
  689. styleChanged(null);
  690. }
  691. //----------------------------------
  692. // imeMode
  693. //----------------------------------
  694. /**
  695. * @private
  696. * Storage for the imeMode property.
  697. */
  698. private var _imeMode:String = null;
  699. /**
  700. * Specifies the IME (input method editor) mode.
  701. * The IME enables users to enter text in Chinese, Japanese, and Korean.
  702. * Flex sets the specified IME mode when the control gets the focus,
  703. * and sets it back to the previous value when the control loses the focus.
  704. *
  705. * <p>The flash.system.IMEConversionMode class defines constants for the
  706. * valid values for this property.
  707. * You can also specify <code>null</code> to specify no IME.</p>
  708. *
  709. * @see flash.system.IMEConversionMode
  710. *
  711. * @default null
  712. */
  713. public function get imeMode():String
  714. {
  715. return _imeMode;
  716. }
  717. /**
  718. * @private
  719. */
  720. public function set imeMode(value:String):void
  721. {
  722. _imeMode = value;
  723. }
  724. //----------------------------------
  725. // includeInLayout
  726. //----------------------------------
  727. /**
  728. * @private
  729. * Storage for the includeInLayout property.
  730. */
  731. private var _includeInLayout:Boolean = true;
  732. /**
  733. * @copy mx.core.UIComponent#includeInLayout
  734. */
  735. public function get includeInLayout():Boolean
  736. {
  737. return _includeInLayout;
  738. }
  739. /**
  740. * @private
  741. */
  742. public function set includeInLayout(value:Boolean):void
  743. {
  744. if (_includeInLayout != value)
  745. {
  746. _includeInLayout = value;
  747. var p:IInvalidating = parent as IInvalidating;
  748. if (p)
  749. {
  750. p.invalidateSize();
  751. p.invalidateDisplayList();
  752. }
  753. }
  754. }
  755. //----------------------------------
  756. // inheritingStyles
  757. //----------------------------------
  758. /**
  759. * @private
  760. * Storage for the inheritingStyles property.
  761. */
  762. private var _inheritingStyles:Object = UIComponent.STYLE_UNINITIALIZED;
  763. /**
  764. * The beginning of this UITextField's chain of inheriting styles.
  765. * The <code>getStyle()</code> method accesses
  766. * <code>inheritingStyles[styleName]</code> to search the entire
  767. * prototype-linked chain.
  768. * This object is set up by the <code>initProtoChain()</code> method.
  769. * You typically never need to access this property directly.
  770. */
  771. public function get inheritingStyles():Object
  772. {
  773. return _inheritingStyles;
  774. }
  775. /**
  776. * @private
  777. */
  778. public function set inheritingStyles(value:Object):void
  779. {
  780. _inheritingStyles = value;
  781. }
  782. //----------------------------------
  783. // initialized
  784. //----------------------------------
  785. /**
  786. * @private
  787. * Storage for the initialize property.
  788. */
  789. private var _initialized:Boolean = false;
  790. /**
  791. * A flag that determines if an object has been through all three phases
  792. * of layout validation (provided that any were required)
  793. */
  794. public function get initialized():Boolean
  795. {
  796. return _initialized;
  797. }
  798. /**
  799. * @private
  800. */
  801. public function set initialized(value:Boolean):void
  802. {
  803. _initialized = value;
  804. }
  805. //----------------------------------
  806. // isHTML
  807. //----------------------------------
  808. /**
  809. * @private
  810. */
  811. private function get isHTML():Boolean
  812. {
  813. return explicitHTMLText != null;
  814. }
  815. //----------------------------------
  816. // isPopUp
  817. //----------------------------------
  818. /**
  819. * @copy mx.core.UIComponent#isPopUp
  820. */
  821. public function get isPopUp():Boolean
  822. {
  823. return false;
  824. }
  825. /**
  826. * @private
  827. */
  828. public function set isPopUp(value:Boolean):void
  829. {
  830. }
  831. //----------------------------------
  832. // maxHeight
  833. //----------------------------------
  834. /**
  835. * @copy mx.core.UIComponent#maxHeight
  836. */
  837. public function get maxHeight():Number
  838. {
  839. return UIComponent.DEFAULT_MAX_HEIGHT;
  840. }
  841. //----------------------------------
  842. // maxWidth
  843. //----------------------------------
  844. /**
  845. * @copy mx.core.UIComponent#maxWidth
  846. */
  847. public function get maxWidth():Number
  848. {
  849. return UIComponent.DEFAULT_MAX_WIDTH;
  850. }
  851. //----------------------------------
  852. // measuredHeight
  853. //----------------------------------
  854. /**
  855. * @copy mx.core.UIComponent#measuredHeight
  856. */
  857. public function get measuredHeight():Number
  858. {
  859. validateNow();
  860. if (!stage)
  861. return textHeight + TEXT_HEIGHT_PADDING;
  862. return textHeight * transform.concatenatedMatrix.a + TEXT_HEIGHT_PADDING;
  863. }
  864. //----------------------------------
  865. // measuredMinHeight
  866. //----------------------------------
  867. /**
  868. * @copy mx.core.UIComponent#measuredMinHeight
  869. */
  870. public function get measuredMinHeight():Number
  871. {
  872. return 0;
  873. }
  874. /**
  875. * @private
  876. */
  877. public function set measuredMinHeight(value:Number):void
  878. {
  879. }
  880. //----------------------------------
  881. // measuredMinWidth
  882. //----------------------------------
  883. /**
  884. * @copy mx.core.UIComponent#measuredMinWidth
  885. */
  886. public function get measuredMinWidth():Number
  887. {
  888. return 0;
  889. }
  890. /**
  891. * @private
  892. */
  893. public function set measuredMinWidth(value:Number):void
  894. {
  895. }
  896. //----------------------------------
  897. // measuredWidth
  898. //----------------------------------
  899. /**
  900. * @copy mx.core.UIComponent#measuredWidth
  901. */
  902. public function get measuredWidth():Number
  903. {
  904. validateNow();
  905. if (!stage)
  906. return textWidth + TEXT_WIDTH_PADDING;
  907. return textWidth * transform.concatenatedMatrix.d + TEXT_WIDTH_PADDING;
  908. }
  909. //----------------------------------
  910. // minHeight
  911. //----------------------------------
  912. /**
  913. * @copy mx.core.UIComponent#minHeight
  914. */
  915. public function get minHeight():Number
  916. {
  917. return 0;
  918. }
  919. //----------------------------------
  920. // minWidth
  921. //----------------------------------
  922. /**
  923. * @copy mx.core.UIComponent#minWidth
  924. */
  925. public function get minWidth():Number
  926. {
  927. return 0;
  928. }
  929. //----------------------------------
  930. // moduleFactory
  931. //----------------------------------
  932. /**
  933. * @private
  934. * Storage for the moduleFactory property.
  935. */
  936. private var _moduleFactory:IFlexModuleFactory;
  937. [Inspectable(environment="none")]
  938. /**
  939. * The moduleFactory that is used to create TextFields in the correct SWF context. This is necessary so that
  940. * embedded fonts will work.
  941. */
  942. public function get moduleFactory():IFlexModuleFactory
  943. {
  944. return _moduleFactory;
  945. }
  946. /**
  947. * @private
  948. */
  949. public function set moduleFactory(factory:IFlexModuleFactory):void
  950. {
  951. _moduleFactory = factory;
  952. }
  953. //----------------------------------
  954. // nestLevel
  955. //----------------------------------
  956. /**
  957. * @private
  958. * Storage for the nestLevel property.
  959. */
  960. private var _nestLevel:int = 0;
  961. /**
  962. * @copy mx.core.UIComponent#nestLevel
  963. */
  964. public function get nestLevel():int
  965. {
  966. return _nestLevel;
  967. }
  968. /**
  969. * @private
  970. */
  971. public function set nestLevel(value:int):void
  972. {
  973. // If my parent hasn't been attached to the display list, then its nestLevel
  974. // will be zero. If it tries to set my nestLevel to 1, ignore it. We'll
  975. // update nest levels again after the parent is added to the display list.
  976. //
  977. // Also punt if the new value for nestLevel is the same as my current value.
  978. if (value > 1 && _nestLevel != value)
  979. {
  980. _nestLevel = value;
  981. StyleProtoChain.initTextField(this);
  982. styleChangedFlag = true;
  983. validateNow();
  984. }
  985. }
  986. //----------------------------------
  987. // nonInheritingStyles
  988. //----------------------------------
  989. /**
  990. * @private
  991. * Storage for the nonInheritingStyles property.
  992. */
  993. private var _nonInheritingStyles:Object = UIComponent.STYLE_UNINITIALIZED;
  994. /**
  995. * The beginning of this UITextField's chain of non-inheriting styles.
  996. * The <code>getStyle()</code> method accesses
  997. * <code>nonInheritingStyles[styleName]</code> method to search the entire
  998. * prototype-linked chain.
  999. * This object is set up by the <code>initProtoChain()</code> method.
  1000. * You typically never need to access this property directly.
  1001. */
  1002. public function get nonInheritingStyles():Object
  1003. {
  1004. return _nonInheritingStyles;
  1005. }
  1006. /**
  1007. * @private
  1008. */
  1009. public function set nonInheritingStyles(value:Object):void
  1010. {
  1011. _nonInheritingStyles = value;
  1012. }
  1013. //----------------------------------
  1014. // percentHeight
  1015. //----------------------------------
  1016. /**
  1017. * @copy mx.core.UIComponent#percentHeight
  1018. */
  1019. public function get percentHeight():Number
  1020. {
  1021. return NaN;
  1022. }
  1023. /**
  1024. * @private
  1025. */
  1026. public function set percentHeight(value:Number):void
  1027. {
  1028. }
  1029. //----------------------------------
  1030. // percentWidth
  1031. //----------------------------------
  1032. /**
  1033. * @copy mx.core.UIComponent#percentWidth
  1034. */
  1035. public function get percentWidth():Number
  1036. {
  1037. return NaN;
  1038. }
  1039. /**
  1040. * @private
  1041. */
  1042. public function set percentWidth(value:Number):void
  1043. {
  1044. }
  1045. //----------------------------------
  1046. // processedDescriptors
  1047. //----------------------------------
  1048. /**
  1049. * @private
  1050. */
  1051. private var _processedDescriptors:Boolean = true;
  1052. /**
  1053. * Set to <code>true</code> after the <code>createChildren()</code>
  1054. * method creates any internal component children.
  1055. */
  1056. public function get processedDescriptors():Boolean
  1057. {
  1058. return _processedDescriptors;
  1059. }
  1060. /**
  1061. * @private
  1062. */
  1063. public function set processedDescriptors(value:Boolean):void
  1064. {
  1065. _processedDescriptors = value;
  1066. }
  1067. //----------------------------------
  1068. // styleName
  1069. //----------------------------------
  1070. /**
  1071. * @private
  1072. * Storage for the styleName property.
  1073. */
  1074. private var _styleName:Object /* String, CSSStyleDeclaration, or UIComponent */;
  1075. /**
  1076. * @copy mx.core.UIComponent#styleName
  1077. */
  1078. public function get styleName():Object /* String, CSSStyleDeclaration, or UIComponent */
  1079. {
  1080. return _styleName;
  1081. }
  1082. /**
  1083. * @private
  1084. */
  1085. public function set styleName(value:Object /* String, CSSStyleDeclaration, or UIComponent */):void
  1086. {
  1087. if (_styleName === value)
  1088. return;
  1089. _styleName = value;
  1090. if (parent)
  1091. {
  1092. StyleProtoChain.initTextField(this);
  1093. styleChanged("styleName");
  1094. }
  1095. // If we don't have a parent pointer yet, then we'll wait
  1096. // and initialize the proto chain when the parentChanged()
  1097. // method is called.
  1098. }
  1099. //----------------------------------
  1100. // systemManager
  1101. //----------------------------------
  1102. /**
  1103. * @copy mx.core.UIComponent#systemManager
  1104. */
  1105. public function get systemManager():ISystemManager
  1106. {
  1107. var o:DisplayObject = parent;
  1108. while (o)
  1109. {
  1110. var ui:IUIComponent = o as IUIComponent;
  1111. if (ui)
  1112. return ui.systemManager;
  1113. o = o.parent;
  1114. }
  1115. return null;
  1116. }
  1117. /**
  1118. * @private
  1119. */
  1120. public function set systemManager(value:ISystemManager):void
  1121. {
  1122. // Not supported
  1123. }
  1124. //----------------------------------
  1125. // nonZeroTextHeight
  1126. //----------------------------------
  1127. /**
  1128. * Unlike textHeight, this returns a non-zero value
  1129. * even when the text is empty.
  1130. * In this case, it returns what the textHeight would be
  1131. * if the text weren't empty.
  1132. */
  1133. public function get nonZeroTextHeight():Number
  1134. {
  1135. if (super.text == "")
  1136. {
  1137. super.text = "Wj";
  1138. var result:Number = textHeight;
  1139. super.text = "";
  1140. return result;
  1141. }
  1142. return textHeight;
  1143. }
  1144. //----------------------------------
  1145. // toolTip
  1146. //----------------------------------
  1147. /**
  1148. * @private
  1149. * Storage for the toolTip property.
  1150. */
  1151. mx_internal var _toolTip:String;
  1152. /**
  1153. * @copy mx.core.UIComponent#toolTip
  1154. */
  1155. public function get toolTip():String
  1156. {
  1157. return _toolTip;
  1158. }
  1159. /**
  1160. * @private
  1161. */
  1162. public function set toolTip(value:String):void
  1163. {
  1164. var oldValue:String = _toolTip;
  1165. _toolTip = value;
  1166. ToolTipManager.registerToolTip(this, oldValue, value);
  1167. }
  1168. //----------------------------------
  1169. // tweeningProperties
  1170. //----------------------------------
  1171. /**
  1172. * @copy mx.core.UIComponent#tweeningProperties
  1173. */
  1174. public function get tweeningProperties():Array
  1175. {
  1176. return null;
  1177. }
  1178. /**
  1179. * @private
  1180. */
  1181. public function set tweeningProperties(value:Array):void
  1182. {
  1183. }
  1184. //----------------------------------
  1185. // updateCompletePendingFlag
  1186. //----------------------------------
  1187. /**
  1188. * @private
  1189. * Storage for the updateCompletePendingFlag property.
  1190. */
  1191. private var _updateCompletePendingFlag:Boolean = false;
  1192. /**
  1193. * A flag that determines if an object has been through all three phases
  1194. * of layout validation (provided that any were required)
  1195. */
  1196. public function get updateCompletePendingFlag():Boolean
  1197. {
  1198. return _updateCompletePendingFlag;
  1199. }
  1200. /**
  1201. * @private
  1202. */
  1203. public function set updateCompletePendingFlag(value:Boolean):void
  1204. {
  1205. _updateCompletePendingFlag = value;
  1206. }
  1207. //--------------------------------------------------------------------------
  1208. //
  1209. // Overridden methods: TextField
  1210. //
  1211. //--------------------------------------------------------------------------
  1212. /**
  1213. * @private
  1214. */
  1215. override public function setTextFormat(format:TextFormat,
  1216. beginIndex:int = -1,
  1217. endIndex:int = -1):void
  1218. {
  1219. // It is an exception to call setTextFormat()
  1220. // when styleSheet is applied.
  1221. if (styleSheet)
  1222. return;
  1223. super.setTextFormat(format, beginIndex, endIndex);
  1224. // Since changing the TextFormat will change the htmlText,
  1225. // dispatch an event so that listeners can react to this.
  1226. dispatchEvent(new Event("textFormatChange"));
  1227. }
  1228. /**
  1229. * @private
  1230. */
  1231. override public function insertXMLText(beginIndex:int, endIndex:int,
  1232. richText:String,
  1233. pasting:Boolean = false):void
  1234. {
  1235. super.insertXMLText(beginIndex, endIndex, richText, pasting);
  1236. dispatchEvent(new Event("textInsert"));
  1237. }
  1238. /**
  1239. * @private
  1240. */
  1241. override public function replaceText(beginIndex:int, endIndex:int,
  1242. newText:String):void
  1243. {
  1244. super.replaceText(beginIndex, endIndex, newText);
  1245. dispatchEvent(new Event("textReplace"));
  1246. }
  1247. //--------------------------------------------------------------------------
  1248. //
  1249. // Methods
  1250. //
  1251. //--------------------------------------------------------------------------
  1252. /**
  1253. * Initializes this component.
  1254. *
  1255. * <p>This method is required by the IUIComponent interface,
  1256. * but it actually does nothing for a UITextField.</p>
  1257. */
  1258. public function initialize():void
  1259. {
  1260. }
  1261. /**
  1262. * @copy mx.core.UIComponent#getExplicitOrMeasuredWidth()
  1263. */
  1264. public function getExplicitOrMeasuredWidth():Number
  1265. {
  1266. return !isNaN(explicitWidth) ? explicitWidth : measuredWidth;
  1267. }
  1268. /**
  1269. * @copy mx.core.UIComponent#getExplicitOrMeasuredHeight()
  1270. */
  1271. public function getExplicitOrMeasuredHeight():Number
  1272. {
  1273. return !isNaN(explicitHeight) ? explicitHeight : measuredHeight;
  1274. }
  1275. /**
  1276. * Sets the <code>visible</code> property of this UITextField object.
  1277. *
  1278. * @param visible <code>true</code> to make this UITextField visible,
  1279. * and <code>false</code> to make it invisible.
  1280. *
  1281. * @param noEvent <code>true</code> to suppress generating an event when you change visibility.
  1282. */
  1283. public function setVisible(visible:Boolean, noEvent:Boolean = false):void
  1284. {
  1285. this.visible = visible
  1286. }
  1287. /**
  1288. * @copy mx.core.UIComponent#setFocus()
  1289. */
  1290. public function setFocus():void
  1291. {
  1292. systemManager.stage.focus = this;
  1293. }
  1294. /**
  1295. * Returns a UITextFormat object that contains formatting information for this component.
  1296. * This method is similar to the <code>getTextFormat()</code> method of the
  1297. * flash.text.TextField class, but it returns a UITextFormat object instead
  1298. * of a TextFormat object.
  1299. *
  1300. * <p>The UITextFormat class extends the TextFormat class to add the text measurement methods
  1301. * <code>measureText()</code> and <code>measureHTMLText()</code>.</p>
  1302. *
  1303. * @return An object that contains formatting information for this component.
  1304. *
  1305. * @see mx.core.UITextFormat
  1306. * @see flash.text.TextField
  1307. */
  1308. public function getUITextFormat():UITextFormat
  1309. {
  1310. validateNow();
  1311. var textFormat:UITextFormat = new UITextFormat(creatingSystemManager());
  1312. textFormat.moduleFactory = moduleFactory;
  1313. textFormat.copyFrom(getTextFormat());
  1314. textFormat.antiAliasType = antiAliasType;
  1315. textFormat.gridFitType = gridFitType;
  1316. textFormat.sharpness = sharpness;
  1317. textFormat.thickness = thickness;
  1318. return textFormat;
  1319. }
  1320. /**
  1321. * @copy mx.core.UIComponent#move()
  1322. */
  1323. public function move(x:Number, y:Number):void
  1324. {
  1325. // Performance optimization: if the position hasn't changed, don't let
  1326. // the player think that we're dirty
  1327. if (this.x != x)
  1328. this.x = x;
  1329. if (this.y != y)
  1330. this.y = y;
  1331. }
  1332. /**
  1333. * @copy mx.core.UIComponent#setActualSize()
  1334. */
  1335. public function setActualSize(w:Number, h:Number):void
  1336. {
  1337. // Performance optimization: if the size hasn't changed, don't let
  1338. // the player think that we're dirty
  1339. if (width != w)
  1340. width = w;
  1341. if (height != h)
  1342. height = h;
  1343. }
  1344. /**
  1345. * @copy mx.core.UIComponent#getStyle()
  1346. */
  1347. public function getStyle(styleProp:String):*
  1348. {
  1349. if (StyleManager.inheritingStyles[styleProp])
  1350. {
  1351. return inheritingStyles ?
  1352. inheritingStyles[styleProp] :
  1353. IStyleClient(parent).getStyle(styleProp);
  1354. }
  1355. else
  1356. {
  1357. return nonInheritingStyles ?
  1358. nonInheritingStyles[styleProp] :
  1359. IStyleClient(parent).getStyle(styleProp);
  1360. }
  1361. }
  1362. /**
  1363. * Does nothing.
  1364. * A UITextField cannot have inline styles.
  1365. *
  1366. * @param styleProp Name of the style property.
  1367. *
  1368. * @param newValue New value for the style.
  1369. */
  1370. public function setStyle(styleProp:String, value:*):void
  1371. {
  1372. }
  1373. /**
  1374. * This function is called when a UITextField object is assigned
  1375. * a parent.
  1376. * You typically never need to call this method.
  1377. *
  1378. * @param p The parent of this UITextField object.
  1379. */
  1380. public function parentChanged(p:DisplayObjectContainer):void
  1381. {
  1382. if (!p)
  1383. {
  1384. _parent = null;
  1385. _nestLevel = 0;
  1386. }
  1387. else if (p is IStyleClient)
  1388. {
  1389. _parent = p;
  1390. }
  1391. else if (p is SystemManager)
  1392. {
  1393. _parent = p;
  1394. }
  1395. else
  1396. {
  1397. _parent = p.parent;
  1398. }
  1399. }
  1400. /**
  1401. * @copy mx.core.UIComponent#styleChanged()
  1402. */
  1403. public function styleChanged(styleProp:String):void
  1404. {
  1405. styleChangedFlag = true;
  1406. if (!invalidateDisplayListFlag)
  1407. {
  1408. invalidateDisplayListFlag = true;
  1409. if ("callLater" in parent)
  1410. Object(parent).callLater(validateNow);
  1411. }
  1412. }
  1413. /**
  1414. * @copy mx.core.UIComponent#validateNow()
  1415. */
  1416. public function validateNow():void
  1417. {
  1418. // If we don't have a parent pointer yet, then any attempts to get
  1419. // style information will fail. Do nothing now - this function will
  1420. // be called again when parentChanged is called.
  1421. if (!parent)
  1422. return;
  1423. if (!isNaN(explicitWidth) && super.width != explicitWidth)
  1424. super.width = (explicitWidth > 4) ? explicitWidth : 4;
  1425. if (!isNaN(explicitHeight) && super.height != explicitHeight)
  1426. super.height = explicitHeight;
  1427. // Set the text format.
  1428. if (styleChangedFlag)
  1429. {
  1430. var textFormat:TextFormat = getTextStyles();
  1431. if (textFormat.font)
  1432. {
  1433. var embeddedFont:EmbeddedFont = getEmbeddedFont(
  1434. textFormat.font, textFormat.bold, textFormat.italic);
  1435. var fontModuleFactory:IFlexModuleFactory =
  1436. embeddedFontRegistry.getAssociatedModuleFactory(
  1437. embeddedFont, moduleFactory);
  1438. // if we found the font, then it is embedded.
  1439. // Some fonts are not listed in info(), so are not in the above registry.
  1440. // Call isFontFaceEmbedded() which get the list of embedded fonts from the player.
  1441. if (fontModuleFactory != null)
  1442. {
  1443. embedFonts = true;
  1444. }
  1445. else
  1446. {
  1447. var sm:ISystemManager = creatingSystemManager();
  1448. embedFonts = sm != null && sm.isFontFaceEmbedded(textFormat);
  1449. }
  1450. }
  1451. else
  1452. {
  1453. embedFonts = getStyle("embedFonts");
  1454. }
  1455. if (getStyle("fontAntiAliasType") != undefined)
  1456. {
  1457. antiAliasType = getStyle("fontAntiAliasType");
  1458. gridFitType = getStyle("fontGridFitType");
  1459. sharpness = getStyle("fontSharpness");
  1460. thickness = getStyle("fontThickness");
  1461. }
  1462. if (!styleSheet)
  1463. {
  1464. super.setTextFormat(textFormat);
  1465. defaultTextFormat = textFormat;
  1466. }
  1467. // Since changing the TextFormat will change the htmlText,
  1468. // dispatch an event so that listeners can react to this.
  1469. dispatchEvent(new Event("textFieldStyleChange"));
  1470. }
  1471. styleChangedFlag = false;
  1472. invalidateDisplayListFlag = false;
  1473. }
  1474. /**
  1475. * Returns the TextFormat object that represents
  1476. * character formatting information for this UITextField object.
  1477. *
  1478. * @return A TextFormat object.
  1479. *
  1480. * @see flash.text.TextFormat
  1481. */
  1482. public function getTextStyles():TextFormat
  1483. {
  1484. var textFormat:TextFormat = new TextFormat();
  1485. textFormat.align = getStyle("textAlign");
  1486. textFormat.bold = getStyle("fontWeight") == "bold";
  1487. if (enabled)
  1488. {
  1489. if (explicitColor == StyleManager.NOT_A_COLOR)
  1490. textFormat.color = getStyle("color");
  1491. else
  1492. textFormat.color = explicitColor;
  1493. }
  1494. else
  1495. {
  1496. textFormat.color = getStyle("disabledColor");
  1497. }
  1498. textFormat.font = StringUtil.tr

Large files files are truncated, but you can click here to view the full file