GSaha567/seq_level_training_data
052
1text,length,is_long_context,metric_val,label_metric2"////////////////////////////////////////////////////////////////////////////////3//4// ADOBE SYSTEMS INCORPORATED5// Copyright 2006-2007 Adobe Systems Incorporated6// All Rights Reserved.7//8// NOTICE: Adobe permits you to use, modify, and distribute this file9// in accordance with the terms of the license agreement accompanying it.10//11////////////////////////////////////////////////////////////////////////////////12 13package mx.managers14{15 16import flash.display.DisplayObject;17import flash.events.Event;18import flash.events.EventDispatcher;19import flash.events.IEventDispatcher;20import flash.events.MouseEvent;21import flash.events.TimerEvent;22import flash.geom.Point;23import flash.geom.Rectangle;24import flash.utils.Timer;25import mx.controls.ToolTip;26import mx.core.FlexGlobals;27import mx.core.IFlexModule;28import mx.core.IInvalidating;29import mx.core.IToolTip;30import mx.core.IUIComponent;31import mx.core.LayoutDirection;32import mx.core.mx_internal;33import mx.effects.IAbstractEffect;34import mx.effects.EffectManager;35import mx.events.DynamicEvent;36import mx.events.EffectEvent;37import mx.events.ToolTipEvent;38import mx.managers.IToolTipManagerClient;39import mx.styles.IStyleClient;40import mx.validators.IValidatorListener;41import mx.core.ILayoutDirectionElement;42 43use namespace mx_internal;44 45[ExcludeClass]46 47/**48 * @private49 * The ToolTipManager lets you set basic ToolTip and error tip functionality,50 * such as display delay and the disabling of ToolTips.51 *52 * @see mx.controls.ToolTip53 * @see mx.validators.Validator54 */55public class ToolTipManagerImpl extends EventDispatcher56 implements IToolTipManager257{58// include ""../core/Version.as"";59 60 //--------------------------------------------------------------------------61 //62 // Class variables63 //64 //--------------------------------------------------------------------------65 66 /**67 * @private68 */69 private static var instance:IToolTipManager2;70 71 /**72 * @private73 * 74 * Place to hook in additional classes75 */76 public static var mixins:Array;77 78 //--------------------------------------------------------------------------79 //80 // Class methods81 //82 //--------------------------------------------------------------------------83 84 /**85 * @private86 */87 public static function getInstance():IToolTipManager288 {89 if (!instance)90 instance = new ToolTipManagerImpl();91 92 return instance;93 }94 95 //--------------------------------------------------------------------------96 //97 // Constructor98 //99 //--------------------------------------------------------------------------100 101 /**102 * @private103 */104 public function ToolTipManagerImpl()105 {106 super();107 108 if (instance)109 throw new Error(""Instance already exists."");110 111 if (mixins)112 {113 var n:int = mixins.length;114 for (var i:int = 0; i < n; i++)115 {116 new mixins[int(i)](this);117 }118 }119 120 if (hasEventListener(""initialize""))121 dispatchEvent(new Event(""initialize""));122 123 }124 125 //--------------------------------------------------------------------------126 //127 // Variables128 //129 //--------------------------------------------------------------------------130 131 /**132 * @private133 * A flag that keeps track of whether this class's initialize()134 * method has been executed.135 */136 mx_internal var initialized:Boolean = false;137 138 /**139 * @private140 * This timer is used to delay the appearance of a normal ToolTip141 * after the mouse moves over a target; an error tip has no such delay.142 *143 * <p>This timer, which is lazily created, is started when the mouse144 * moves over an object with a ToolTip, with a duration specified145 * by showDelay.146 * If the mouse moves out of this object before the timer fires,147 * the ToolTip is never created.148 * If the mouse stays over the object until the timer fires,149 * the ToolTip is created and its showEffect is started.150 */151 mx_internal var showTimer:Timer;152 153 /**154 * @private155 * This timer is used to make the tooltip ""time out"" and hide itself156 * if the mouse stays over a target.157 *158 * <p>This timer, which is lazily created, is started159 * when the showEffect ends.160 * When it fires, the hideEffect is started.</p>161 */162 mx_internal var hideTimer:Timer;163 164 /**165 * @private166 * This timer is used to implement mousing quickly over multiple targets167 * with ToolTip...168 *169 * <p>This timer, which is lazily created, is started170 * when ...</p>171 */172 mx_internal var scrubTimer:Timer;173 174 /**175 * @private176 */177 mx_internal var currentText:String;178 179 /**180 * @private181 */182 mx_internal var isError:Boolean;183 184 /**185 * The UIComponent with the ToolTip assigned to it186 * that was most recently under the mouse.187 * During much of the tool tip life cycle this property188 * has the same value as the <code>currentTarget</code> property.189 * 190 * @langversion 3.0191 * @playerversion Flash 9192 * @playerversion AIR 1.1193 * @productversion Flex 3194 */195 mx_internal var previousTarget:DisplayObject;196 197 //--------------------------------------------------------------------------198 //199 // Properties200 //201 //--------------------------------------------------------------------------202 203 //----------------------------------204 // currentTarget205 //----------------------------------206 207 /**208 * @private209 */210 private var _currentTarget:DisplayObject;211 212 /**213 * The UIComponent that is currently displaying a ToolTip,214 * or <code>null</code> if none is.215 * 216 * @langversion 3.0217 * @playerversion Flash 9218 * @playerversion AIR 1.1219 * @productversion Flex 3220 */221 public function get currentTarget():DisplayObject222 {223 return _currentTarget;224 }225 226 /**227 * @private228 */229 public function set currentTarget(value:DisplayObject):void230 {231 _currentTarget = value;232 }233 234 //----------------------------------235 // currentToolTip236 //----------------------------------237 238 /**239 * @private240 */241 mx_internal var _currentToolTip:DisplayObject;242 243 /**244 * The ToolTip object that is currently visible,245 * or <code>null</code> if none is shown.246 * 247 * @langversion 3.0248 * @playerversion Flash 9249 * @playerversion AIR 1.1250 * @productversion Flex 3251 */252 public function get currentToolTip():IToolTip253 {254 return _currentToolTip as IToolTip;255 }256 257 /**258 * @private259 */260 public function set currentToolTip(value:IToolTip):void261 {262 _currentToolTip = value as DisplayObject;263 264 if (hasEventListener(""currentToolTip""))265 dispatchEvent(new Event(""currentToolTip""));266 }267 268 //----------------------------------269 // enabled270 //----------------------------------271 272 /**273 * @private274 */275 private var _enabled:Boolean = true;276 277 /**278 * If <code>true</code>, the ToolTipManager will automatically show279 * ToolTips when the user moves the mouse pointer over components.280 * If <code>false</code>, no ToolTips will be shown.281 *282 * @default true283 * 284 * @langversion 3.0285 * @playerversion Flash 9286 * @playerversion AIR 1.1287 * @productversion Flex 3288 */289 public function get enabled():Boolean 290 {291 return _enabled;292 }293 294 /**295 * @private296 */297 public function set enabled(value:Boolean):void298 {299 _enabled = value;300 }301 302 //----------------------------------303 // hideDelay304 //----------------------------------305 306 /**307 * @private308 */309 private var _hideDelay:Number = 10000; // milliseconds310 311 /**312 * The amount of time, in milliseconds, that Flex waits313 * to hide the ToolTip after it appears.314 * Once Flex hides a ToolTip, the user must move the mouse315 * off the component and then back onto it to see the ToolTip again.316 * If you set <code>hideDelay</code> to <code>Infinity</code>,317 * Flex does not hide the ToolTip until the user triggers an event,318 * such as moving the mouse off of the component.319 *320 * @default 10000321 * 322 * @langversion 3.0323 * @playerversion Flash 9324 * @playerversion AIR 1.1325 * @productversion Flex 3326 */327 public function get hideDelay():Number 328 {329 return _hideDelay;330 }331 332 /**333 * @private334 */335 public function set hideDelay(value:Number):void336 {337 _hideDelay = value;338 }339 340 //----------------------------------341 // hideEffect342 //----------------------------------343 344 /**345 * @private346 */347 private var _hideEffect:IAbstractEffect;348 349 /**350 * The effect that plays when a ToolTip is hidden,351 * or <code>null</code> if the ToolTip should disappear with no effect.352 *353 * <p>Effects are not marshaled across applicationDomains in a sandbox354 * as they may not be supportable in different versions</p>355 *356 * @default null357 * 358 * @langversion 3.0359 * @playerversion Flash 9360 * @playerversion AIR 1.1361 * @productversion Flex 3362 */363 public function get hideEffect():IAbstractEffect364 {365 return _hideEffect;366 }367 368 /**369 * @private370 */371 public function set hideEffect(value:IAbstractEffect):void372 {373 _hideEffect = value as IAbstractEffect;374 }375 376 //----------------------------------377 // scrubDelay378 //----------------------------------379 380 /**381 * @private382 */383 private var _scrubDelay:Number = 100; // milliseconds384 385 /**386 * The amount of time, in milliseconds, that a user can take387 * when moving the mouse between controls before Flex again waits388 * for the duration of <code>showDelay</code> to display a ToolTip.389 *390 * <p>This setting is useful if the user moves quickly from one control391 * to another; after displaying the first ToolTip, Flex will display392 * the others immediately rather than waiting.393 * The shorter the setting for <code>scrubDelay</code>, the more394 * likely that the user must wait for an amount of time specified395 * by <code>showDelay</code> in order to see the next ToolTip.396 * A good use of this property is if you have several buttons on a397 * toolbar, and the user will quickly scan across them to see brief398 * descriptions of their functionality.</p>399 *400 * @default 100401 * 402 * @langversion 3.0403 * @playerversion Flash 9404 * @playerversion AIR 1.1405 * @productversion Flex 3406 */407 public function get scrubDelay():Number 408 {409 return _scrubDelay;410 }411 412 /**413 * @private414 */415 public function set scrubDelay(value:Number):void416 {417 _scrubDelay = value;418 }419 420 //----------------------------------421 // showDelay422 //----------------------------------423 424 /**425 * @private426 */427 private var _showDelay:Number = 500; // milliseconds428 429 /**430 * The amount of time, in milliseconds, that Flex waits431 * before displaying the ToolTip box once a user432 * moves the mouse over a component that has a ToolTip.433 * To make the ToolTip appear instantly, set <code>showDelay</code> to 0.434 *435 * @default 500436 * 437 * @langversion 3.0438 * @playerversion Flash 9439 * @playerversion AIR 1.1440 * @productversion Flex 3441 */442 public function get showDelay():Number 443 {444 return _showDelay;445 }446 447 /**448 * @private449 */450 public function set showDelay(value:Number):void451 {452 _showDelay = value;453 }454 455 //----------------------------------456 // showEffect457 //----------------------------------458 459 /**460 * @private461 */462 private var _showEffect:IAbstractEffect;463 464 /**465 * The effect that plays when a ToolTip is shown,466 * or <code>null</code> if the ToolTip should appear with no effect.467 *468 * <p>Effects are not marshaled across applicationDomains in a sandbox469 * as they may not be supportable in different versions</p>470 *471 * @default null472 * 473 * @langversion 3.0474 * @playerversion Flash 9475 * @playerversion AIR 1.1476 * @productversion Flex 3477 */478 public function get showEffect():IAbstractEffect479 {480 return _showEffect;481 }482 483 /**484 * @private485 */486 public function set showEffect(value:IAbstractEffect):void487 {488 _showEffect = value as IAbstractEffect;489 }490 491 //----------------------------------492 // toolTipClass493 //----------------------------------494 495 /**496 * @private497 */498 private var _toolTipClass:Class = ToolTip;499 500 /**501 * The class to use for creating ToolTips.502 * 503 * <p>The ToolTipClass is not marshaled across applicationDomains in a sandbox504 * as they may not be supportable in different versions. Child505 * applications should only be interested in setting the tooltip506 * for objects within themselves</p>507 *508 * @default mx.controls.ToolTip509 * 510 * @langversion 3.0511 * @playerversion Flash 9512 * @playerversion AIR 1.1513 * @productversion Flex 3514 */515 public function get toolTipClass():Class 516 {517 return _toolTipClass;518 }519 520 /**521 * @private522 */523 public function set toolTipClass(value:Class):void524 {525 _toolTipClass = value;526 }527 528 //--------------------------------------------------------------------------529 //530 // Methods531 //532 //--------------------------------------------------------------------------533 534 /**535 * @private536 * Initializes the class.537 *538 * <p>This method sets up three Timer objects that ToolTipManager539 * starts and stops while tracking the mouse.540 * The repeatCount is set to 1 so that they fire only once.541 * Their duration is set later, just before they are started.542 * The timers are never destroyed once they are created here.</p>543 *544 * <p>This method is called by targetChanged(); Flex waits to initialize545 * the class until mouse-tracking happens in order to optimize546 * startup time.</p>547 */548 mx_internal function initialize():void549 {550 if (!showTimer)551 {552 showTimer = new Timer(0, 1);553 showTimer.addEventListener(TimerEvent.TIMER,554 showTimer_timerHandler);555 }556 557 if (!hideTimer)558 {559 hideTimer = new Timer(0, 1);560 hideTimer.addEventListener(TimerEvent.TIMER,561 hideTimer_timerHandler);562 }563 564 if (!scrubTimer)565 scrubTimer = new Timer(0, 1);566 567 initialized = true;568 }569 570 /**571 * Registers a target UIComponent or UITextField, and the text572 * for its ToolTip, with the ToolTipManager.573 * This causes the ToolTipManager to display a ToolTip574 * when the mouse hovers over the target.575 *576 * <p>This method is called by the setter577 * for the toolTip property in UIComponent and UITextField.</p>578 *579 * @param target The UIComponent or UITextField that owns the ToolTip.580 *581 * @param oldToolTip The old text that was displayed582 * in the ToolTip.583 * 584 * @param newToolTip The new text to display in the ToolTip.585 * If null, no ToolTip will be displayed when the mouse hovers586 * over the target.587 * 588 * @langversion 3.0589 * @playerversion Flash 9590 * @playerversion AIR 1.1591 * @productversion Flex 3592 */593 public function registerToolTip(target:DisplayObject,594 oldToolTip:String,595 newToolTip:String):void596 {597 if (!oldToolTip && newToolTip)598 {599 target.addEventListener(MouseEvent.MOUSE_OVER,600 toolTipMouseOverHandler);601 target.addEventListener(MouseEvent.MOUSE_OUT,602 toolTipMouseOutHandler);603 604 // If the mouse is already over the object605 // that's getting a toolTip, show the tip.606 if (mouseIsOver(target))607 showImmediately(target);608 }609 else if (oldToolTip && !newToolTip)610 {611 target.removeEventListener(MouseEvent.MOUSE_OVER,612 toolTipMouseOverHandler);613 target.removeEventListener(MouseEvent.MOUSE_OUT,614 toolTipMouseOutHandler);615 616 // If the mouse is over the object whose toolTip617 // is being removed, hide the tip.618 if (mouseIsOver(target))619 hideImmediately(target);620 }621 }622 623 /**624 * Registers a target UIComponent, and the text625 * for its error tip, with the ToolTipManager.626 * This causes the ToolTipManager to display an error tip627 * when the mouse hovers over the target.628 *629 * <p>This method is called by the setter630 * for the errorString property in UIComponent.</p>631 *632 * @param target The UIComponent or UITextField that owns the ToolTip.633 * 634 * @param oldErrorString The old text that was displayed635 * in the error tip.636 *637 * @param newErrorString The new text to display in the error tip.638 * If null, no error tip will be displayed when the mouse hovers639 * over the target.640 * 641 * @langversion 3.0642 * @playerversion Flash 9643 * @playerversion AIR 1.1644 * @productversion Flex 3645 */646 public function registerErrorString(target:DisplayObject,647 oldErrorString:String,648 newErrorString:String):void649 {650 if (!oldErrorString && newErrorString)651 {652 target.addEventListener(MouseEvent.MOUSE_OVER,653 errorTipMouseOverHandler);654 target.addEventListener(MouseEvent.MOUSE_OUT,655 errorTipMouseOutHandler);656 657 // If the mouse is already over the object658 // that's getting an errorTip, show the tip.659 if (mouseIsOver(target))660 showImmediately(target);661 }662 else if (oldErrorString && !newErrorString)663 {664 target.removeEventListener(MouseEvent.MOUSE_OVER,665 errorTipMouseOverHandler);666 target.removeEventListener(MouseEvent.MOUSE_OUT,667 errorTipMouseOutHandler);668 669 // If the mouse is over the object whose toolTip670 // is being removed, hide the tip.671 if (mouseIsOver(target))672 hideImmediately(target);673 }674 }675 676 /**677 * @private678 * Returns true if the mouse is over the specified target.679 */680 private function mouseIsOver(target:DisplayObject):Boolean681 {682 if (!target || !target.stage)683 return false;684 685 //SDK:13465 - If we pass through the above if block, then686 //we have a target component and its been added to the 687 //display list. If the mouse coordinates are (0,0), there 688 //is a chance the component has not been positioned yet 689 //and we'll end up mistakenly showing tooltips since the 690 //target hitTest will return true. 691 if ((target.stage.mouseX == 0) && (target.stage.mouseY == 0))692 return false;693 694 if (target is ILayoutManagerClient && !ILayoutManagerClient(target).initialized)695 return false;696 697 return target.hitTestPoint(target.stage.mouseX,698 target.stage.mouseY, true);699 }700 701 /**702 * @private703 * Shows the tip immediately when the toolTip or errorTip property 704 * becomes non-null and the mouse is over the target.705 */706 private function showImmediately(target:DisplayObject):void707 {708 var oldShowDelay:Number = ToolTipManager.showDelay;709 ToolTipManager.showDelay = 0;710 checkIfTargetChanged(target);711 ToolTipManager.showDelay = oldShowDelay;712 }713 714 /**715 * @private716 * Hides the tip immediately when the toolTip or errorTip property 717 * becomes null and the mouse is over the target.718 */719 private function hideImmediately(target:DisplayObject):void720 {721 checkIfTargetChanged(null);722 }723 724 /**725 * Replaces the ToolTip, if necessary.726 *727 * <p>Determines whether the UIComponent or UITextField object728 * with the ToolTip assigned to it that is currently under the mouse729 * pointer is the most recent such object.730 * If not, it removes the old ToolTip and displays the new one.</p>731 *732 * @param displayObject The UIComponent or UITextField that is currently under the mouse.733 * 734 * @langversion 3.0735 * @playerversion Flash 9736 * @playerversion AIR 1.1737 * @productversion Flex 3738 */739 mx_internal function checkIfTargetChanged(displayObject:DisplayObject):void740 {741 if (!enabled)742 return;743 744 findTarget(displayObject);745 746 if (currentTarget != previousTarget)747 {748 targetChanged();749 previousTarget = currentTarget;750 }751 }752 753 /**754 * Searches from the <code>displayObject</code> object up the chain755 * of parent objects until it finds a UIComponent or UITextField object756 * with a <code>toolTip</code> or <code>errorString</code> property.757 * Treats an empty string as a valid <code>toolTip</code> property.758 * Sets the <code>currentTarget</code> property.759 * 760 * @langversion 3.0761 * @playerversion Flash 9762 * @playerversion AIR 1.1763 * @productversion Flex 3764 */765 mx_internal function findTarget(displayObject:DisplayObject):void766 {767 // Walk up the DisplayObject parent chain looking for a UIComponent768 // with a toolTip or errorString property. Note that we stop769 // even if we find a tooltip which is an empty string. Although770 // we don't display empty tooltips, we have to track when we771 // are over a movieclip with an empty tooltip so that we can772 // hide any previous tooltip. This allows a child to set773 // toolTip="""" to ""cancel"" its parent's toolTip.774 while (displayObject)775 {776 if (displayObject is IValidatorListener)777 {778 currentText = IValidatorListener(displayObject).errorString;779 var showErrorTip:Boolean;780 if (displayObject is IStyleClient)781 showErrorTip = IStyleClient(displayObject).getStyle(""showErrorTip"");782 if (currentText != null && currentText != """" && showErrorTip)783 {784 currentTarget = displayObject;785 isError = true;786 return;787 }788 }789 790 if (displayObject is IToolTipManagerClient)791 {792 currentText = IToolTipManagerClient(displayObject).toolTip;793 if (currentText != null)794 {795 currentTarget = displayObject;796 isError = false;797 return;798 }799 }800 801 displayObject = displayObject.parent;802 }803 804 currentText = null;805 currentTarget = null;806 }807 808 /**809 * Removes any ToolTip that is currently displayed and displays810 * the ToolTip for the UIComponent that is currently under the mouse811 * pointer, as determined by the <code>currentTarget</code> property.812 * 813 * @langversion 3.0814 * @playerversion Flash 9815 * @playerversion AIR 1.1816 * @productversion Flex 3817 */818 mx_internal function targetChanged():void819 {820 // Do lazy creation of the Timer objects this class uses.821 if (!initialized)822 initialize()823 824 var event:ToolTipEvent;825 826 if (previousTarget && currentToolTip)827 {828 if (currentToolTip is IToolTip)829 {830 event = new ToolTipEvent(ToolTipEvent.TOOL_TIP_HIDE);831 event.toolTip = currentToolTip;832 previousTarget.dispatchEvent(event);833 }834 else835 {836 if (hasEventListener(ToolTipEvent.TOOL_TIP_HIDE))837 dispatchEvent(new Event(ToolTipEvent.TOOL_TIP_HIDE));838 }839 } 840 841 reset();842 843 if (currentTarget)844 {845 // Don't display empty tooltips.846 if (currentText == """")847 return;848 849 // Dispatch a ""startToolTip"" event850 // from the object displaying the tooltip.851 event = new ToolTipEvent(ToolTipEvent.TOOL_TIP_START);852 currentTarget.dispatchEvent(event);853 854 if (showDelay == 0 || scrubTimer.running)855 {856 // Create the tooltip and start its showEffect.857 createTip();858 initializeTip();859 positionTip();860 showTip();861 }862 else863 {864 showTimer.delay = showDelay;865 showTimer.start();866 // After the delay, showTimer_timerHandler()867 // will create the tooltip and start its showEffect.868 }869 }870 }871 872 /**873 * Creates an invisible new ToolTip.874 *875 * <p>If the ToolTipManager's <code>enabled</code> property is876 * <code>true</code> this method is automatically called877 * when the user moves the mouse over an object that has878 * the <code>toolTip</code> property set,879 * The ToolTipManager makes subsequent calls to880 * <code>initializeTip()</code>, <code>positionTip()</code>,881 * and <code>showTip()</code> to complete the display882 * of the ToolTip.</p>883 *884 * <p>The type of ToolTip that is created is determined by the885 * <code>toolTipClass</code> property.886 * By default, this is the ToolTip class.887 * This class can be styled to appear as either a normal ToolTip888 * (which has a yellow background by default) or as an error tip889 * for validation errors (which is red by default).</p>890 *891 * <p>After creating the ToolTip with the <code>new</code>892 * operator, this method stores a reference to it in the893 * <code>currentToolTip</code> property.894 * It then uses addChild() to add this ToolTip to the895 * SystemManager's toolTips layer.</p>896 * 897 * @langversion 3.0898 * @playerversion Flash 9899 * @playerversion AIR 1.1900 * @productversion Flex 3901 */902 mx_internal function createTip():void903 {904 // Dispatch a ""createToolTip"" event905 // from the object displaying the tooltip.906 var event:ToolTipEvent =907 new ToolTipEvent(ToolTipEvent.TOOL_TIP_CREATE);908 currentTarget.dispatchEvent(event);909 910 if (event.toolTip)911 currentToolTip = event.toolTip;912 else913 currentToolTip = new toolTipClass();914 915 currentToolTip.visible = false;916 917 // Set the tooltip to be in the same module factory as the target to the918 // correct style manager is used. Don't overwrite an existing module factory.919 if (currentToolTip is IFlexModule && IFlexModule(currentToolTip).moduleFactory == null && 920 currentTarget is IFlexModule)921 IFlexModule(currentToolTip).moduleFactory = IFlexModule(currentTarget).moduleFactory;922 923 if (hasEventListener(""createTip""))924 if (!dispatchEvent(new Event(""createTip"", false, true)))925 return;926 927 var sm:ISystemManager = getSystemManager(currentTarget) as ISystemManager;928 sm.topLevelSystemManager.toolTipChildren.addChild(currentToolTip as DisplayObject);929 }930 931 /**932 * Initializes a newly created ToolTip with the appropriate text,933 * based on the object under the mouse.934 *935 * <p>If the ToolTipManager's <code>enabled</code> property is936 * <code>true</code> this method is automatically called937 * when the user moves the mouse over an object that has938 * the <code>toolTip</code> property set.939 * The ToolTipManager calls <code>createTip()</code> before940 * this method, and <code>positionTip()</code> and941 * <code>showTip()</code> after.</p>942 *943 * <p>If a normal ToolTip is being displayed, this method944 * sets its text as specified by the <code>toolTip</code>945 * property of the object under the mouse.946 * If an error tip is being displayed, the text is as947 * specified by the <code>errorString</code> property948 * of the object under the mouse.</p>949 *950 * <p>This method also makes the ToolTip the appropriate951 * size for the text that it needs to display.</p>952 * 953 * @langversion 3.0954 * @playerversion Flash 9955 * @playerversion AIR 1.1956 * @productversion Flex 3957 */958 mx_internal function initializeTip():void959 {960 // Set the text of the tooltip.961 if (currentToolTip is IToolTip)962 IToolTip(currentToolTip).text = currentText;963 964 if (isError && currentToolTip is IStyleClient)965 IStyleClient(currentToolTip).setStyle(""styleName"", ""errorTip"");966 967 sizeTip(currentToolTip);968 969 if (currentToolTip is IStyleClient)970 {971 // Set up its ""show"" and ""hide"" effects.972 if (showEffect)973 IStyleClient(currentToolTip).setStyle(""showEffect"", showEffect);974 if (hideEffect)975 IStyleClient(currentToolTip).setStyle(""hideEffect"", hideEffect);976 }977 978 if (showEffect || hideEffect)979 {980 currentToolTip.addEventListener(EffectEvent.EFFECT_END,981 effectEndHandler);982 }983 }984 985 /**986 * @private987 * Objects added to the SystemManager's ToolTip layer don't get988 * automatically measured or sized, so ToolTipManager has to989 * measure it and set its size.990 */991 public function sizeTip(toolTip:IToolTip):void992 {993 // Force measure() to be called on the tooltip.994 // Otherwise, its measured size will be 0.995 if (toolTip is IInvalidating)996 IInvalidating(toolTip).validateNow();997 998 toolTip.setActualSize(999 toolTip.getExplicitOrMeasuredWidth(),1000 toolTip.getExplicitOrMeasuredHeight());1001 }1002 1003 /**1004 * Positions a newly created and initialized ToolTip on the stage.1005 *1006 * <p>If the ToolTipManager's <code>enabled</code> property is1007 * <code>true</code> this method is automatically called1008 * when the user moves the mouse over an object that has1009 * the <code>toolTip</code> property set.1010 * The ToolTipManager calls <code>createTip()</code> and1011 * <code>initializeTip()</code> before this method,1012 * and <code>showTip()</code> after.</p>1013 *1014 * <p>If a normal ToolTip is being displayed, this method positions1015 * its upper-left (upper-right) corner near the lower-right (lower-left)1016 * of the arrow cursor. This method ensures that the ToolTip is 1017 * completely in view.1018 * 1019 * @langversion 3.01020 * @playerversion Flash 91021 * @playerversion AIR 1.11022 * @productversion Flex 31023 */1024 mx_internal function positionTip():void1025 {1026 // Determine layoutDirection of the target component.1027 var layoutDirection:String;1028 if (currentTarget is ILayoutDirectionElement)1029 layoutDirection = ILayoutDirectionElement(currentTarget).layoutDirection;1030 else1031 layoutDirection = LayoutDirection.LTR;1032 1033 const mirror:Boolean = (layoutDirection == LayoutDirection.RTL);1034 1035 var x:Number;1036 var y:Number;1037 1038 // the screen should only be as wide as the application, not necessarily the stage1039 var screenWidth:Number = FlexGlobals.topLevelApplication.measuredWidth;1040 var screenHeight:Number = FlexGlobals.topLevelApplication.measuredHeight;1041 1042 if (isError)1043 {1044 // Tooltips are laid out in the same direction as the target 1045 // component.1046 var tipElt:ILayoutDirectionElement = 1047 currentToolTip as ILayoutDirectionElement;1048 1049 if (tipElt && 1050 tipElt.layoutDirection != layoutDirection)1051 {1052 tipElt.layoutDirection = layoutDirection;1053 // sizeTip below will call validateNow()1054 tipElt.invalidateLayoutDirection();1055 }1056 1057 var targetGlobalBounds:Rectangle = 1058 getGlobalBounds(currentTarget, currentToolTip.root, mirror);1059 1060 x = mirror ?1061 targetGlobalBounds.left - 4 :1062 targetGlobalBounds.right + 4;1063 y = targetGlobalBounds.top - 1;1064 1065 // If there's no room to the right (left) of the control, put it 1066 // above or below, with the left (right) edge of the error tip 1067 // aligned with the left (right) edge of the target.1068 var noRoom:Boolean = mirror ?1069 x < currentToolTip.width : 1070 x + currentToolTip.width > screenWidth; 1071 if (noRoom)1072 {1073 var newWidth:Number = NaN;1074 var oldWidth:Number = NaN;1075 1076 x = mirror ?1077 targetGlobalBounds.right + 2 - currentToolTip.width :1078 targetGlobalBounds.left - 2;1079 1080 // If the error tip would be too wide for the stage,1081 // reduce the maximum width to fit onstage. Note that1082 // we have to reassign the text in order to get the tip1083 // to relayout after changing the border style and maxWidth.1084 if (mirror)1085 {1086 if (x < currentToolTip.width + 4) 1087 {1088 // -4 on the left, +2 on the right = -21089 x = 4;1090 newWidth = targetGlobalBounds.right - 2; 1091 }1092 }1093 else1094 {1095 if (x + currentToolTip.width + 4 > screenWidth)1096 newWidth = screenWidth - x - 4; 1097 }1098 1099 if (!isNaN(newWidth))1100 {1101 oldWidth = Object(toolTipClass).maxWidth;1102 Object(toolTipClass).maxWidth = newWidth;1103 if (currentToolTip is IStyleClient)1104 IStyleClient(currentToolTip).setStyle(""borderStyle"", ""errorTipAbove"");1105 currentToolTip[""text""] = currentToolTip[""text""];1106 } 1107 1108 // Even if the error tip will fit onstage, we still need to1109 // change the border style and get the error tip to relayout.1110 else1111 {1112 if (currentToolTip is IStyleClient)1113 IStyleClient(currentToolTip).setStyle(""borderStyle"", ""errorTipAbove"");1114 currentToolTip[""text""] = currentToolTip[""text""];1115 }1116 1117 if (currentToolTip.height + 2 < targetGlobalBounds.top)1118 {1119 // There's room to put it above the control.1120 y = targetGlobalBounds.top - (currentToolTip.height + 2);1121 }1122 else1123 {1124 // No room above, put it below the control.1125 y = targetGlobalBounds.bottom + 2;1126 1127 if (!isNaN(newWidth))1128 Object(toolTipClass).maxWidth = newWidth;1129 if (currentToolTip is IStyleClient)1130 IStyleClient(currentToolTip).setStyle(""borderStyle"", ""errorTipBelow"");1131 currentToolTip[""text""] = currentToolTip[""text""];1132 }1133 }1134 1135 // Since the border style of the error tip may have changed,1136 // we have to force a remeasurement and change its size.1137 // This is because objects in the toolTips layer1138 // don't undergo normal measurement and layout.1139 sizeTip(currentToolTip)1140 1141 // If we changed the tooltip max size, we change it back.1142 // Otherwise, if RTL, and x wasn't set for maxWidth, reposition 1143 // because the width may have changed during the remeasure.1144 if (!isNaN(oldWidth))1145 Object(toolTipClass).maxWidth = oldWidth;1146 else if (mirror)1147 x = targetGlobalBounds.right + 2 - currentToolTip.width;1148 }1149 else1150 {1151 var sm:ISystemManager = getSystemManager(currentTarget);1152 // Position the upper-left (upper-right) of the tooltip1153 // at the lower-right (lower-left) of the arrow cursor.1154 x = DisplayObject(sm).mouseX + 11; 1155 if (mirror)1156 x -= currentToolTip.width;1157 y = DisplayObject(sm).mouseY + 22;1158 1159 // If the tooltip is too wide to fit onstage, move it left (right).1160 var toolTipWidth:Number = currentToolTip.width;1161 if (mirror)1162 {1163 if (x < 2)1164 x = 2;1165 }1166 else if (x + toolTipWidth > screenWidth)1167 {1168 x = screenWidth - toolTipWidth;1169 }1170 1171 // If the tooltip is too tall to fit onstage, move it up.1172 var toolTipHeight:Number = currentToolTip.height;1173 if (y + toolTipHeight > screenHeight)1174 y = screenHeight - toolTipHeight;1175 1176 var pos:Point = new Point(x, y);1177 pos = DisplayObject(sm).localToGlobal(pos);1178 pos = DisplayObject(sm.getSandboxRoot()).globalToLocal(pos);1179 x = pos.x;1180 y = pos.y;1181 }1182 1183 currentToolTip.move(x, y);1184 }1185 1186 /**1187 * Shows a newly created, initialized, and positioned ToolTip.1188 *1189 * <p>If the ToolTipManager's <code>enabled</code> property is1190 * <code>true</code> this method is automatically called1191 * when the user moves the mouse over an object that has1192 * the <code>toolTip</code> property set.1193 * The ToolTipManager calls <code>createTip()</code>,1194 * <code>initializeTip()</code>, and <code>positionTip()</code>1195 * before this method.</p>1196 *1197 * <p>This method first dispatches a <code>""showToolTip""</code>1198 * event from the object under the mouse.1199 * This gives you a chance to do special processing on a1200 * particular object's ToolTip just before it becomes visible.