You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by gr...@apache.org on 2019/04/09 23:19:43 UTC
[royale-asjs] branch develop updated: Improvements to
MouseEvent.createMouseEvent method: avoid try/catch in favor of a startup
check,
and avoid MouseEventInit class entirely (with Language.as coercion). code
reformat: avoid mix of spaces/tabs (used spaces)
This is an automated email from the ASF dual-hosted git repository.
gregdove pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/develop by this push:
new e92274b Improvements to MouseEvent.createMouseEvent method: avoid try/catch in favor of a startup check, and avoid MouseEventInit class entirely (with Language.as coercion). code reformat: avoid mix of spaces/tabs (used spaces)
e92274b is described below
commit e92274b01b947a925d4e181c068336348b698aec
Author: greg-dove <gr...@gmail.com>
AuthorDate: Wed Apr 10 11:18:21 2019 +1200
Improvements to MouseEvent.createMouseEvent method: avoid try/catch in favor of a startup check, and avoid MouseEventInit class entirely (with Language.as coercion).
code reformat: avoid mix of spaces/tabs (used spaces)
---
.../royale/org/apache/royale/events/MouseEvent.as | 999 +++++++++++----------
1 file changed, 512 insertions(+), 487 deletions(-)
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/events/MouseEvent.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/events/MouseEvent.as
index f277ae7..4ce22a6 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/events/MouseEvent.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/events/MouseEvent.as
@@ -18,6 +18,8 @@
////////////////////////////////////////////////////////////////////////////////
package org.apache.royale.events
{
+ import org.apache.royale.events.MouseEvent;
+
COMPILE::SWF
{
import flash.display.InteractiveObject;
@@ -27,47 +29,48 @@ package org.apache.royale.events
COMPILE::JS
{
import window.MouseEvent;
- import goog.events.BrowserEvent;
+
+ import goog.events.BrowserEvent;
+
import org.apache.royale.core.HTMLElementWrapper;
- import org.apache.royale.events.Event;
+ import org.apache.royale.events.Event;
import org.apache.royale.events.utils.MouseEventConverter;
- import org.apache.royale.conversions.MouseEventInit;
}
import org.apache.royale.core.IRoyaleElement;
import org.apache.royale.events.IBrowserEvent;
import org.apache.royale.geom.Point;
import org.apache.royale.utils.PointUtils;
-
-
- /**
- * Mouse events
+
+
+ /**
+ * Mouse events
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.0
- */
- COMPILE::SWF
- public class MouseEvent extends flash.events.MouseEvent implements IRoyaleEvent
- {
+ */
+ COMPILE::SWF
+ public class MouseEvent extends flash.events.MouseEvent implements IRoyaleEvent
+ {
private static function platformConstant(s:String):String
{
return s;
}
-
- public static const MOUSE_DOWN:String = platformConstant("mouseDown");
+
+ public static const MOUSE_DOWN:String = platformConstant("mouseDown");
public static const MOUSE_MOVE:String = platformConstant("mouseMove");
- public static const MOUSE_UP:String = platformConstant("mouseUp");
- public static const MOUSE_OUT:String = platformConstant("mouseOut");
- public static const MOUSE_OVER:String = platformConstant("mouseOver");
- public static const ROLL_OVER:String = platformConstant("rollOver");
- public static const ROLL_OUT:String = platformConstant("rollOut");
+ public static const MOUSE_UP:String = platformConstant("mouseUp");
+ public static const MOUSE_OUT:String = platformConstant("mouseOut");
+ public static const MOUSE_OVER:String = platformConstant("mouseOver");
+ public static const ROLL_OVER:String = platformConstant("rollOver");
+ public static const ROLL_OUT:String = platformConstant("rollOut");
public static const CLICK:String = "click";
- public static const DOUBLE_CLICK:String = "doubleClick";
- public static const WHEEL : String = "mouseWheel";
-
- /**
+ public static const DOUBLE_CLICK:String = "doubleClick";
+ public static const WHEEL:String = "mouseWheel";
+
+ /**
* Constructor.
*
* @param type The name of the event.
@@ -79,16 +82,16 @@ package org.apache.royale.events
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
- public function MouseEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false,
+ public function MouseEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false,
localX:Number = NaN, localY:Number = NaN,
relatedObject:Object = null,
ctrlKey:Boolean = false, altKey:Boolean = false, shiftKey:Boolean = false,
buttonDown:Boolean = false, delta:int = 0,
commandKey:Boolean = false, controlKey:Boolean = false,
clickCount:int = 0, targetBeforeBubbling:IEventDispatcher = null)
- {
- super(type, bubbles, cancelable);
-
+ {
+ super(type, bubbles, cancelable);
+
this.localX = localX;
this.localY = localY;
this.relatedObject = relatedObject as InteractiveObject;
@@ -97,50 +100,53 @@ package org.apache.royale.events
this.shiftKey = shiftKey;
this.buttonDown = buttonDown;
this.delta = delta;
- this.targetBeforeBubbling = targetBeforeBubbling;
- }
-
+ this.targetBeforeBubbling = targetBeforeBubbling;
+ }
+
// these map directly to JS MouseEvent fields.
public function get clientX():Number
{
return screenX;
}
+
public function set clientX(value:Number):void
{
localX = value;
}
+
public function get clientY():Number
{
return screenY;
}
+
public function set clientY(value:Number):void
{
localY = value;
}
-
+
private var _stagePoint:Point;
- // TODO remove this when figure out how to preserve the real target
+ // TODO remove this when figure out how to preserve the real target
public var targetBeforeBubbling:Object;
-
+
public function get screenX():Number
{
if (!target) return localX;
if (!_stagePoint)
{
var localPoint:Point = new Point(localX, localY);
- var referenceObject:Object = targetBeforeBubbling ? targetBeforeBubbling : target;
+ var referenceObject:Object = targetBeforeBubbling ? targetBeforeBubbling : target;
_stagePoint = PointUtils.localToGlobal(localPoint, referenceObject);
}
return _stagePoint.x;
}
-
+
public function get screenY():Number
{
if (!target) return localY;
if (!_stagePoint)
{
var localPoint:Point = new Point(localX, localY);
- var referenceObject:Object = targetBeforeBubbling ? targetBeforeBubbling : target;
+ var referenceObject:Object = targetBeforeBubbling ? targetBeforeBubbling : target;
_stagePoint = PointUtils.localToGlobal(localPoint, referenceObject);
}
return _stagePoint.y;
@@ -149,48 +155,52 @@ package org.apache.royale.events
/**
* @private
*/
- override public function clone():flash.events.Event
+ override public function clone():flash.events.Event
{
return cloneEvent() as flash.events.Event;
}
- /**
+
+ /**
* The horizontal scroll delta for wheel events
- * In Flash this always returns 0.
+ * In Flash this always returns 0.
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.9
- */
- public function get deltaX():int
- {
- return 0;
- }
- /**
- * Horizontal wheel events are not supported in Flash
- */
- public function set deltaX(value:int):void
- {
-
- }
-
- /**
+ */
+ public function get deltaX():int
+ {
+ return 0;
+ }
+
+ /**
+ * Horizontal wheel events are not supported in Flash
+ */
+ public function set deltaX(value:int):void
+ {
+
+ }
+
+ /**
* The vertical scroll delta for wheel events
- * In Flash this just proxies to the delta
+ * In Flash this just proxies to the delta
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.9
- */
- public function get deltaY():int
- {
- return delta
- }
- public function set deltaY(value:int):void
- {
- delta = value;
- }
+ */
+ public function get deltaY():int
+ {
+ return delta
+ }
+
+ public function set deltaY(value:int):void
+ {
+ delta = value;
+ }
+
/**
* Create a copy/clone of the Event object.
*
@@ -202,13 +212,13 @@ package org.apache.royale.events
public function cloneEvent():IRoyaleEvent
{
var e:org.apache.royale.events.MouseEvent = new org.apache.royale.events.MouseEvent(type, bubbles, cancelable,
- localX, localY, relatedObject, ctrlKey, altKey, shiftKey,
- buttonDown, delta
- /* got errors for commandKey, commandKey, controlKey, clickCount*/);
- e.targetBeforeBubbling = targetBeforeBubbling;
- return e;
+ localX, localY, relatedObject, ctrlKey, altKey, shiftKey,
+ buttonDown, delta
+ /* got errors for commandKey, commandKey, controlKey, clickCount*/);
+ e.targetBeforeBubbling = targetBeforeBubbling;
+ return e;
}
-
+
/**
* Determine if the target is the same as the event's target. The event's target
* can sometimes be an internal target so this tests if the outer component
@@ -218,7 +228,7 @@ package org.apache.royale.events
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.0
- * @royaleignorecoercion org.apache.royale.core.IRoyaleElement
+ * @royaleignorecoercion org.apache.royale.core.IRoyaleElement
*/
public function isSameTarget(potentialTarget:IEventDispatcher):Boolean
{
@@ -227,7 +237,7 @@ package org.apache.royale.events
if ((target as IRoyaleElement).royale_wrapper == potentialTarget) return true;
return false;
}
-
+
/**
* defaultPrevented is true if <code>preventDefault()</code> was called.
*
@@ -238,11 +248,11 @@ package org.apache.royale.events
*/
public function get defaultPrevented():Boolean
{
- return isDefaultPrevented();
+ return isDefaultPrevented();
}
-
- }
-
+
+ }
+
/**
* Mouse events
*
@@ -250,459 +260,477 @@ package org.apache.royale.events
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.0
- *
+ *
* @royalesuppresspublicvarwarning
*/
- COMPILE::JS
- public class MouseEvent extends Event implements IRoyaleEvent, IBrowserEvent
- {
- private static function platformConstant(s:String):String
- {
- return s.toLowerCase();
- }
-
- public static const MOUSE_DOWN:String = platformConstant("mouseDown");
- public static const MOUSE_MOVE:String = platformConstant("mouseMove");
- public static const MOUSE_UP:String = platformConstant("mouseUp");
- public static const MOUSE_OUT:String = platformConstant("mouseOut");
- public static const MOUSE_OVER:String = platformConstant("mouseOver");
- public static const ROLL_OVER:String = platformConstant("rollOver");
- public static const ROLL_OUT:String = platformConstant("rollOut");
- public static const CLICK:String = "click";
- public static const DOUBLE_CLICK:String = "dblclick";
- public static const WHEEL : String = "wheel";
-
- /**
- * Constructor.
- *
- * @param type The name of the event.
- * @param bubbles Whether the event bubbles.
- * @param cancelable Whether the event can be canceled.
- *
- * @langversion 3.0
- * @playerversion Flash 10.2
- * @playerversion AIR 2.6
- * @productversion Royale 0.0
- */
- public function MouseEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false,
- localX:Number = NaN, localY:Number = NaN,
- relatedObject:Object = null,
- ctrlKey:Boolean = false, altKey:Boolean = false, shiftKey:Boolean = false,
- buttonDown:Boolean = false, delta:int = 0,
- commandKey:Boolean = false, controlKey:Boolean = false,
- clickCount:int = 0, targetBeforeBubbling:IEventDispatcher = null)
- {
- super(type, bubbles, cancelable);
-
- this.localX = localX;
- this.localY = localY;
- this.relatedObject = relatedObject;
- this.ctrlKey = ctrlKey;
- this.altKey = altKey;
- this.shiftKey = shiftKey;
- this.buttonDown = buttonDown;
- this.delta = delta;
- this.commandKey = commandKey;
- this.controlKey = controlKey;
- this.clickCount = clickCount;
- }
-
- /**
- * @type {?goog.events.BrowserEvent}
- */
- private var wrappedEvent:Object;
-
- /**
- * @type {MouseEvent}
- * @royalesuppresspublicvarwarning
- */
- public var nativeEvent:Object;
-
- public function wrapEvent(event:goog.events.BrowserEvent):void
+ COMPILE::JS
+ public class MouseEvent extends Event implements IRoyaleEvent, IBrowserEvent
+ {
+ private static function platformConstant(s:String):String
+ {
+ return s.toLowerCase();
+ }
+
+ public static const MOUSE_DOWN:String = platformConstant("mouseDown");
+ public static const MOUSE_MOVE:String = platformConstant("mouseMove");
+ public static const MOUSE_UP:String = platformConstant("mouseUp");
+ public static const MOUSE_OUT:String = platformConstant("mouseOut");
+ public static const MOUSE_OVER:String = platformConstant("mouseOver");
+ public static const ROLL_OVER:String = platformConstant("rollOver");
+ public static const ROLL_OUT:String = platformConstant("rollOut");
+ public static const CLICK:String = "click";
+ public static const DOUBLE_CLICK:String = "dblclick";
+ public static const WHEEL:String = "wheel";
+
+ /**
+ * Constructor.
+ *
+ * @param type The name of the event.
+ * @param bubbles Whether the event bubbles.
+ * @param cancelable Whether the event can be canceled.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.0
+ */
+ public function MouseEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false,
+ localX:Number = NaN, localY:Number = NaN,
+ relatedObject:Object = null,
+ ctrlKey:Boolean = false, altKey:Boolean = false, shiftKey:Boolean = false,
+ buttonDown:Boolean = false, delta:int = 0,
+ commandKey:Boolean = false, controlKey:Boolean = false,
+ clickCount:int = 0, targetBeforeBubbling:IEventDispatcher = null)
+ {
+ super(type, bubbles, cancelable);
+
+ this.localX = localX;
+ this.localY = localY;
+ this.relatedObject = relatedObject;
+ this.ctrlKey = ctrlKey;
+ this.altKey = altKey;
+ this.shiftKey = shiftKey;
+ this.buttonDown = buttonDown;
+ this.delta = delta;
+ this.commandKey = commandKey;
+ this.controlKey = controlKey;
+ this.clickCount = clickCount;
+ }
+
+ /**
+ * @type {?goog.events.BrowserEvent}
+ */
+ private var wrappedEvent:Object;
+
+ /**
+ * @type {MouseEvent}
+ * @royalesuppresspublicvarwarning
+ */
+ public var nativeEvent:Object;
+
+ public function wrapEvent(event:goog.events.BrowserEvent):void
{
wrappedEvent = event;
- nativeEvent = event.getBrowserEvent();
- }
-
- public var relatedObject:Object;
- public var ctrlKey:Boolean;
- public var altKey:Boolean;
- public var shiftKey:Boolean;
- private var _buttons:int = -1;
- public function get buttonDown():Boolean
- {
- return button > -1 && button < 3;
- }
- public function set buttonDown(value:Boolean):void
- {
- _button = value ? 0 : 9;// any value over 2 will be interpreted as no button down
- }
-
- private var _button:int = -1;
-
- /**
- * see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
- */
- public function get button():int
- {
- if(_button > -1)
- return _button;
- return nativeEvent["button"];
- }
-
- public function set button(value:int):void
- {
- _button = value;
- }
-
- /**
- * see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
- */
- public function get buttons():int
- {
- if(_buttons > -1)
- return _buttons;
- return nativeEvent["buttons"];
- }
- public function set buttons(value:int):void
- {
- _buttons = value;
- }
-
- private var _delta:int;
- /**
+ nativeEvent = event.getBrowserEvent();
+ }
+
+ public var relatedObject:Object;
+ public var ctrlKey:Boolean;
+ public var altKey:Boolean;
+ public var shiftKey:Boolean;
+ private var _buttons:int = -1;
+
+ public function get buttonDown():Boolean
+ {
+ return button > -1 && button < 3;
+ }
+
+ public function set buttonDown(value:Boolean):void
+ {
+ _button = value ? 0 : 9;// any value over 2 will be interpreted as no button down
+ }
+
+ private var _button:int = -1;
+
+ /**
+ * see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
+ */
+ public function get button():int
+ {
+ if (_button > -1)
+ return _button;
+ return nativeEvent["button"];
+ }
+
+ public function set button(value:int):void
+ {
+ _button = value;
+ }
+
+ /**
+ * see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
+ */
+ public function get buttons():int
+ {
+ if (_buttons > -1)
+ return _buttons;
+ return nativeEvent["buttons"];
+ }
+
+ public function set buttons(value:int):void
+ {
+ _buttons = value;
+ }
+
+ private var _delta:int;
+ /**
* The vertical scroll delta for wheel events
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.9
- */
- public function get delta():int
- {
- return nativeEvent ? nativeEvent.deltaY : _delta;
- }
- public function set delta(value:int):void
- {
- _delta = value;
- }
-
- private var _deltaX:int;
- /**
+ */
+ public function get delta():int
+ {
+ return nativeEvent ? nativeEvent.deltaY : _delta;
+ }
+
+ public function set delta(value:int):void
+ {
+ _delta = value;
+ }
+
+ private var _deltaX:int;
+ /**
* The horizontal scroll delta for wheel events
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.9
- */
- public function get deltaX():int
- {
- return nativeEvent ? nativeEvent.deltaX : _deltaX;
- }
- public function set deltaX(value:int):void
- {
- _deltaX = value;
- }
-
- private var _deltaY:int;
- /**
+ */
+ public function get deltaX():int
+ {
+ return nativeEvent ? nativeEvent.deltaX : _deltaX;
+ }
+
+ public function set deltaX(value:int):void
+ {
+ _deltaX = value;
+ }
+
+ private var _deltaY:int;
+ /**
* The vertical scroll delta for wheel events
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.9
- */
- public function get deltaY():int
- {
- return nativeEvent ? nativeEvent.deltaY : _deltaY;
- }
- public function set deltaY(value:int):void
- {
- _deltaY = value;
- }
-
- public var commandKey:Boolean;
- public var controlKey:Boolean;
- public var clickCount:int;
-
+ */
+ public function get deltaY():int
+ {
+ return nativeEvent ? nativeEvent.deltaY : _deltaY;
+ }
+
+ public function set deltaY(value:int):void
+ {
+ _deltaY = value;
+ }
+
+ public var commandKey:Boolean;
+ public var controlKey:Boolean;
+ public var clickCount:int;
+
private var _target:Object;
-
- /**
+
+ /**
* @copy org.apache.royale.events.BrowserEvent#target
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.0
- */
+ */
override public function get target():Object
- {
- return wrappedEvent ? getTargetWrapper(wrappedEvent.target) : _target;
- }
+ {
+ return wrappedEvent ? getTargetWrapper(wrappedEvent.target) : _target;
+ }
+
override public function set target(value:Object):void
- {
- _target = value;
- }
-
- /**
+ {
+ _target = value;
+ }
+
+ /**
* @copy org.apache.royale.events.BrowserEvent#currentTarget
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.0
- */
+ */
override public function get currentTarget():Object
- {
- return wrappedEvent ? getTargetWrapper(wrappedEvent.currentTarget) : _target;
- }
+ {
+ return wrappedEvent ? getTargetWrapper(wrappedEvent.currentTarget) : _target;
+ }
+
override public function set currentTarget(value:Object):void
- {
- _target = value;
- }
-
- // TODO remove this when figure out how to preserve the real target
- // The problem only manifests in SWF, so this alias is good enough for now
- public function get targetBeforeBubbling():Object
- {
- return target;
- }
- /**
- * X-coordinate relative to the window.
- * @type {number}
+ {
+ _target = value;
+ }
+
+ // TODO remove this when figure out how to preserve the real target
+ // The problem only manifests in SWF, so this alias is good enough for now
+ public function get targetBeforeBubbling():Object
+ {
+ return target;
+ }
+
+ /**
+ * X-coordinate relative to the window.
+ * @type {number}
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.0
- */
- public function get clientX():Number
- {
- return wrappedEvent ? wrappedEvent.clientX : _localX;
- }
-
- public function get localX():Number
- {
- return clientX;
- }
- private var _localX:Number;
-
- public function set localX(value:Number):void
- {
- _localX = value;
- }
-
- /**
- * Y-coordinate relative to the window.
- * @type {number}
+ */
+ public function get clientX():Number
+ {
+ return wrappedEvent ? wrappedEvent.clientX : _localX;
+ }
+
+ public function get localX():Number
+ {
+ return clientX;
+ }
+
+ private var _localX:Number;
+
+ public function set localX(value:Number):void
+ {
+ _localX = value;
+ }
+
+ /**
+ * Y-coordinate relative to the window.
+ * @type {number}
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.0
- */
- public function get clientY():Number
- {
- return wrappedEvent ? wrappedEvent.clientY : _localY;
- }
-
- public function get localY():Number
- {
- return clientY;
- }
-
- private var _localY:Number;
-
- public function set localY(value:Number):void
- {
- _localY = value;
- }
-
- /**
- * X-coordinate relative to the monitor.
- * @type {number}
+ */
+ public function get clientY():Number
+ {
+ return wrappedEvent ? wrappedEvent.clientY : _localY;
+ }
+
+ public function get localY():Number
+ {
+ return clientY;
+ }
+
+ private var _localY:Number;
+
+ public function set localY(value:Number):void
+ {
+ _localY = value;
+ }
+
+ /**
+ * X-coordinate relative to the monitor.
+ * @type {number}
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.0
- */
- public function get screenX():Number
- {
- if(wrappedEvent) return wrappedEvent.screenX;
- if (!target) return localX;
- return stagePoint.x;
- }
-
- /**
- * Y-coordinate relative to the monitor.
- * @type {number}
+ */
+ public function get screenX():Number
+ {
+ if (wrappedEvent) return wrappedEvent.screenX;
+ if (!target) return localX;
+ return stagePoint.x;
+ }
+
+ /**
+ * Y-coordinate relative to the monitor.
+ * @type {number}
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.0
- */
- public function get screenY():Number
- {
- if(wrappedEvent) return wrappedEvent.screenY;
- if (!target) return localY;
- return stagePoint.y;
- }
+ */
+ public function get screenY():Number
+ {
+ if (wrappedEvent) return wrappedEvent.screenY;
+ if (!target) return localY;
+ return stagePoint.y;
+ }
+
private var _stagePoint:Point;
- private function get stagePoint():Point
- {
- if (!_stagePoint)
- {
- var localPoint:Point = new Point(localX, localY);
- _stagePoint = PointUtils.localToGlobal(localPoint, target);
- }
- return _stagePoint;
- }
-
- /**
- * Whether the default action has been prevented.
+ private function get stagePoint():Point
+ {
+ if (!_stagePoint)
+ {
+ var localPoint:Point = new Point(localX, localY);
+ _stagePoint = PointUtils.localToGlobal(localPoint, target);
+ }
+ return _stagePoint;
+ }
+
+ /**
+ * Whether the default action has been prevented.
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.0
- */
- override public function preventDefault():void
- {
- if(wrappedEvent)
- wrappedEvent.preventDefault();
- else
- {
- super.preventDefault();
- _defaultPrevented = true;
- }
- }
-
- private var _defaultPrevented:Boolean;
- /**
- * Whether the default action has been prevented.
- * @type {boolean}
+ */
+ override public function preventDefault():void
+ {
+ if (wrappedEvent)
+ wrappedEvent.preventDefault();
+ else
+ {
+ super.preventDefault();
+ _defaultPrevented = true;
+ }
+ }
+
+ private var _defaultPrevented:Boolean;
+ /**
+ * Whether the default action has been prevented.
+ * @type {boolean}
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.0
- */
+ */
override public function get defaultPrevented():Boolean
- {
- return wrappedEvent ? wrappedEvent.defaultPrevented : _defaultPrevented;
- }
+ {
+ return wrappedEvent ? wrappedEvent.defaultPrevented : _defaultPrevented;
+ }
+
override public function set defaultPrevented(value:Boolean):void
- {
- _defaultPrevented = value;
- }
-
- /**
- * @private
- */
- private static function installRollOverMixin():Boolean
- {
- window.addEventListener(MOUSE_OVER,
- mouseOverHandler, false);
- return true;
- }
-
-
- /**
- * @param e The event.
- * RollOver/RollOut is entirely implemented in mouseOver because
- * when a parent and child share an edge, you only get a mouseout
- * for the child and not the parent and you need to send rollout
- * to both. A similar issue exists for rollover.
- */
- private static function mouseOverHandler(e:MouseEvent):void
- {
- var j:int;
- var m:int;
- var outs:Array;
- var me:window.MouseEvent;
- var parent:Object;
- var target:Object = e.target.royale_wrapper;
- if (target == null)
- return; // probably over the html tag
- var targets:Array = MouseEvent.targets;
- var index:int = targets.indexOf(target);
- if (index != -1) {
- // get all children
- outs = targets.slice(index + 1);
- m = outs.length;
- for (j = 0; j < m; j++)
- {
- me = makeMouseEvent(
- ROLL_OUT, e);
- outs[j].element.dispatchEvent(me);
- }
- MouseEvent.targets = targets.slice(0, index + 1);
- }
- else {
- var newTargets:Array = [target];
- if (!('parent' in target))
- parent = null;
- else
- parent = target.parent;
- while (parent) {
- index = targets.indexOf(parent);
- if (index == -1) {
- newTargets.unshift(parent);
- if (!('parent' in parent))
- break;
- parent = parent.parent;
- }
- else {
- outs = targets.slice(index + 1);
- m = outs.length;
- for (j = 0; j < m; j++) {
- me = makeMouseEvent(
- ROLL_OUT, e);
- outs[j].element.dispatchEvent(me);
- }
- targets = targets.slice(0, index + 1);
- break;
- }
- }
- var n:int = newTargets.length;
- for (var i:int = 0; i < n; i++) {
- me = makeMouseEvent(
- ROLL_OVER, e);
- newTargets[i].element.dispatchEvent(me);
- }
- MouseEvent.targets = targets.concat(newTargets);
- }
- }
-
-
- /**
- */
- private static var rollOverMixin:Boolean =
- installRollOverMixin();
-
-
- /**
- */
- private static var targets:Array = [];
-
- /**
- * @param {string} type The event type.
- * @param {Event} e The mouse event.
- * @return {MouseEvent} The new event.
- */
- private static function makeMouseEvent(type:String, e:window.MouseEvent):window.MouseEvent
- {
- var out:window.MouseEvent = MouseEvent.createMouseEvent(type, false, false, {
- view: e.view, detail: e.detail, screenX: e.screenX, screenY: e.screenY,
- clientX: e.clientX, clientY: e.clientY, ctrlKey: e.ctrlKey, altKey: e.altKey,
- shiftKey: e.shiftKey, metaKey: e.metaKey, button: e.button, relatedTarget: e.relatedTarget});
- return out;
- };
-
+ {
+ _defaultPrevented = value;
+ }
+
+ /**
+ * @private
+ */
+ private static function installRollOverMixin():Boolean
+ {
+ window.addEventListener(MOUSE_OVER,
+ mouseOverHandler, false);
+ return true;
+ }
+
+
+ /**
+ * @param e The event.
+ * RollOver/RollOut is entirely implemented in mouseOver because
+ * when a parent and child share an edge, you only get a mouseout
+ * for the child and not the parent and you need to send rollout
+ * to both. A similar issue exists for rollover.
+ */
+ private static function mouseOverHandler(e:MouseEvent):void
+ {
+ var j:int;
+ var m:int;
+ var outs:Array;
+ var me:window.MouseEvent;
+ var parent:Object;
+ var target:Object = e.target.royale_wrapper;
+ if (target == null)
+ return; // probably over the html tag
+ var targets:Array = MouseEvent.targets;
+ var index:int = targets.indexOf(target);
+ if (index != -1)
+ {
+ // get all children
+ outs = targets.slice(index + 1);
+ m = outs.length;
+ for (j = 0; j < m; j++)
+ {
+ me = makeMouseEvent(
+ ROLL_OUT, e);
+ outs[j].element.dispatchEvent(me);
+ }
+ MouseEvent.targets = targets.slice(0, index + 1);
+ } else
+ {
+ var newTargets:Array = [target];
+ if (!('parent' in target))
+ parent = null;
+ else
+ parent = target.parent;
+ while (parent)
+ {
+ index = targets.indexOf(parent);
+ if (index == -1)
+ {
+ newTargets.unshift(parent);
+ if (!('parent' in parent))
+ break;
+ parent = parent.parent;
+ } else
+ {
+ outs = targets.slice(index + 1);
+ m = outs.length;
+ for (j = 0; j < m; j++)
+ {
+ me = makeMouseEvent(
+ ROLL_OUT, e);
+ outs[j].element.dispatchEvent(me);
+ }
+ targets = targets.slice(0, index + 1);
+ break;
+ }
+ }
+ var n:int = newTargets.length;
+ for (var i:int = 0; i < n; i++)
+ {
+ me = makeMouseEvent(
+ ROLL_OVER, e);
+ newTargets[i].element.dispatchEvent(me);
+ }
+ MouseEvent.targets = targets.concat(newTargets);
+ }
+ }
+
+
+ /**
+ */
+ private static var rollOverMixin:Boolean =
+ installRollOverMixin();
+
+
+ /**
+ */
+ private static var targets:Array = [];
+
+ /**
+ * @param {string} type The event type.
+ * @param {Event} e The mouse event.
+ * @return {MouseEvent} The new event.
+ */
+ private static function makeMouseEvent(type:String, e:window.MouseEvent):window.MouseEvent
+ {
+ var out:window.MouseEvent = MouseEvent.createMouseEvent(type, false, false, {
+ view: e.view, detail: e.detail, screenX: e.screenX, screenY: e.screenY,
+ clientX: e.clientX, clientY: e.clientY, ctrlKey: e.ctrlKey, altKey: e.altKey,
+ shiftKey: e.shiftKey, metaKey: e.metaKey, button: e.button, relatedTarget: e.relatedTarget
+ });
+ return out;
+ };
+
/**
* Create a copy/clone of the Event object.
*
@@ -714,45 +742,51 @@ package org.apache.royale.events
override public function cloneEvent():IRoyaleEvent
{
return new org.apache.royale.events.MouseEvent(type, bubbles, cancelable,
- localX, localY, relatedObject, ctrlKey, altKey, shiftKey,
- buttonDown, delta
- /* got errors for commandKey, commandKey, controlKey, clickCount*/);
+ localX, localY, relatedObject, ctrlKey, altKey, shiftKey,
+ buttonDown, delta
+ /* got errors for commandKey, commandKey, controlKey, clickCount*/);
}
+
/**
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.9
*/
- override public function stopImmediatePropagation():void
- {
- if(wrappedEvent)
+ override public function stopImmediatePropagation():void
+ {
+ if (wrappedEvent)
{
- wrappedEvent.stopPropagation();
- nativeEvent.stopImmediatePropagation();
+ wrappedEvent.stopPropagation();
+ nativeEvent.stopImmediatePropagation();
}
- }
-
+ }
+
/**
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.9
*/
- override public function stopPropagation():void
- {
- if(wrappedEvent)
- wrappedEvent.stopPropagation();
- }
-
+ override public function stopPropagation():void
+ {
+ if (wrappedEvent)
+ wrappedEvent.stopPropagation();
+ }
+
public static function setupConverter():Boolean
{
HTMLElementWrapper.converterMap["MouseEvent"] = MouseEventConverter;
+ _useNativeConstructor = typeof window.MouseEvent == 'function';
return true;
}
public static var initialized:Boolean = setupConverter();
+ private static var _useNativeConstructor:Boolean;
+ /**
+ * @royaleignorecoercion MouseEventInit
+ */
public static function createMouseEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false,
params:Object = null):Object
{
@@ -761,29 +795,20 @@ package org.apache.royale.events
if (!params)
params = {};
- try
+ if (_useNativeConstructor)
{
params.bubbles = bubbles;
params.cancelable = cancelable;
- var initObject:MouseEventInit = MouseEventInit(params);
- mouseEvent = new window.MouseEvent(type, initObject);
- return mouseEvent;
- }
- catch (e:Error)
- {
-
- }
-
- if (!mouseEvent)
+ mouseEvent = new window.MouseEvent(type, params as window.MouseEventInit);
+ } else
{
mouseEvent = document.createEvent('MouseEvent');
mouseEvent.initMouseEvent(type, bubbles, cancelable, params.view,
- params.detail, params.screenX, params.screenY, params.clientX, params.clientY,
- params.ctrlKey, params.altKey, params.shiftKey, params.metaKey, params.button, params.relatedTarget);
+ params.detail, params.screenX, params.screenY, params.clientX, params.clientY,
+ params.ctrlKey, params.altKey, params.shiftKey, params.metaKey, params.button, params.relatedTarget);
+
}
-
return mouseEvent;
}
-
- }
+ }
}