This is an automated email from the ASF dual-hosted git repository. aharui pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
commit 9399d78ecf71cab35e80c6721407118f1684c102 Author: Alex Harui <aha...@apache.org> AuthorDate: Wed Nov 21 17:57:57 2018 -0800 emulation applications replace the event converter to use mx.events.MouseEvent and switch all emulation components to output mx.events.MouseEvent --- .../src/main/royale/ControlsExample.mxml | 1 - .../MXRoyale/src/main/royale/mx/controls/Button.as | 2 +- .../MXRoyale/src/main/royale/mx/controls/Label.as | 2 +- .../src/main/royale/mx/core/Application.as | 8 +- .../src/main/royale/mx/events/MouseEvent.as | 47 +++++- .../royale/mx/events/utils/MouseEventConverter.as | 188 +++++++++++++++++++++ .../main/royale/spark/components/Application.as | 10 ++ 7 files changed, 249 insertions(+), 9 deletions(-) diff --git a/examples/mxroyale/ControlsExample/src/main/royale/ControlsExample.mxml b/examples/mxroyale/ControlsExample/src/main/royale/ControlsExample.mxml index 34d68bc..31a3584 100644 --- a/examples/mxroyale/ControlsExample/src/main/royale/ControlsExample.mxml +++ b/examples/mxroyale/ControlsExample/src/main/royale/ControlsExample.mxml @@ -43,7 +43,6 @@ limitations under the License. <fx:Script> <![CDATA[ import org.apache.royale.events.Event; - import org.apache.royale.events.MouseEvent; private function pushMePushed(event:MouseEvent):void { diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Button.as b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Button.as index 4394b85..c9edf24 100644 --- a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Button.as +++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Button.as @@ -57,7 +57,7 @@ use namespace mx_internal; * @playerversion AIR 2.6 * @productversion Royale 0.0 */ -[Event(name="click", type="org.apache.royale.events.MouseEvent")] +[Event(name="click", type="mx.events.MouseEvent")] /** * Dispatched when the user presses the Button control. diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Label.as b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Label.as index 103bdb2..788d978 100644 --- a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Label.as +++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Label.as @@ -79,7 +79,7 @@ import org.apache.royale.core.ITextModel; * @playerversion AIR 2.6 * @productversion Royale 0.9.0 */ -[Event(name="click", type="org.apache.royale.events.MouseEvent")] +[Event(name="click", type="mx.events.MouseEvent")] //-------------------------------------- diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/core/Application.as b/frameworks/projects/MXRoyale/src/main/royale/mx/core/Application.as index 7139394..a7f7be9 100644 --- a/frameworks/projects/MXRoyale/src/main/royale/mx/core/Application.as +++ b/frameworks/projects/MXRoyale/src/main/royale/mx/core/Application.as @@ -54,14 +54,18 @@ import flash.display.StageQuality; import flash.display.StageScaleMode; import flash.system.ApplicationDomain; import flash.utils.getQualifiedClassName; -import org.apache.royale.events.utils.MouseEventConverter; } import mx.containers.beads.ApplicationLayout; import mx.containers.beads.BoxLayout; +import mx.events.utils.MouseEventConverter; import mx.managers.FocusManager; import mx.managers.ISystemManager; +COMPILE::JS { + import org.apache.royale.core.HTMLElementWrapper; +} + import org.apache.royale.binding.ApplicationDataBinding; import org.apache.royale.binding.ContainerDataBinding; import org.apache.royale.core.AllCSSValuesImpl; @@ -605,6 +609,8 @@ public class Application extends Container implements IStrand, IParent, IEventDi COMPILE::JS public function initializeApplication():void { + HTMLElementWrapper.converterMap["MouseEvent"] = MouseEventConverter; + initManagers(); // if (initialView) diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/events/MouseEvent.as b/frameworks/projects/MXRoyale/src/main/royale/mx/events/MouseEvent.as index 4047ceb..1961364 100644 --- a/frameworks/projects/MXRoyale/src/main/royale/mx/events/MouseEvent.as +++ b/frameworks/projects/MXRoyale/src/main/royale/mx/events/MouseEvent.as @@ -21,6 +21,7 @@ package mx.events { /* import mx.events.Event;*/ import org.apache.royale.events.Event; +import org.apache.royale.events.IEventDispatcher; import org.apache.royale.events.IRoyaleEvent; import org.apache.royale.events.MouseEvent; @@ -106,23 +107,59 @@ public class MouseEvent extends org.apache.royale.events.MouseEvent * @param cancelable Specifies whether the behavior * associated with the event can be prevented. * - * @param oldX The previous x coordinate of the object, in pixels. + * @param localX The x coordinate of the mouse relative to the target, in pixels. * - * @param oldY The previous y coordinate of the object, in pixels. + * @param localY The y coordinate of the mouse relative to the target, in pixels. * * @langversion 3.0 * @playerversion Flash 9 * @playerversion AIR 1.1 * @productversion Royale 0.9.3 */ + COMPILE::SWF public function MouseEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, - oldX:Number = NaN, oldY:Number = NaN) + 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, localX, localY, relatedObject, + ctrlKey, altKey, shiftKey, buttonDown, delta, commandKey, controlKey, + clickCount, targetBeforeBubbling); } + /** + * Constructor. + * + * @param type The event type; indicates the action that caused the event. + * + * @param bubbles Specifies whether the event can bubble + * up the display list hierarchy. + * + * @param cancelable Specifies whether the behavior + * associated with the event can be prevented. + * + * @param localX The x coordinate of the mouse relative to the target, in pixels. + * + * @param localY The y coordinate of the mouse relative to the target, in pixels. + * + * @langversion 3.0 + * @playerversion Flash 9 + * @playerversion AIR 1.1 + * @productversion Royale 0.9.3 + */ + COMPILE::JS + public function MouseEvent(type:String, bubbles:Boolean = false, + cancelable:Boolean = false, + localX:Number = NaN, localY:Number = NaN) + { + super(type, bubbles, cancelable); + this.localX = localX; + this.localY = localY; + } diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/events/utils/MouseEventConverter.as b/frameworks/projects/MXRoyale/src/main/royale/mx/events/utils/MouseEventConverter.as new file mode 100644 index 0000000..c72a82d --- /dev/null +++ b/frameworks/projects/MXRoyale/src/main/royale/mx/events/utils/MouseEventConverter.as @@ -0,0 +1,188 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package mx.events.utils +{ COMPILE::SWF + { + import flash.events.Event; + import flash.events.IEventDispatcher; + import flash.events.MouseEvent; + import org.apache.royale.events.utils.IHandlesOriginalEvent; + } + + import mx.events.MouseEvent; + import org.apache.royale.events.MouseEvent; + + /** + * Mouse events conversion. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.0 + */ + COMPILE::SWF + public class MouseEventConverter + { + /** + * A map of events that are not converted, because there is no + * JS equivalent. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.0 + */ + public static const UNCONVERTED_EVENTS:Object = {}; + + /** + * A method used to copy properties from flash.events.MouseEvent to + * org.apache.royale.events.Event. The set of properties can be + * different based on platform and runtime. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.0 + */ + public static var convert:Function = flashConvert; + + private static function flashConvert(event:flash.events.MouseEvent):org.apache.royale.events.MouseEvent + { +// if (UNCONVERTED_EVENTS[event.type]) +// return null; + + var newEvent:mx.events.MouseEvent = + new mx.events.MouseEvent(event.type, event.bubbles, event.cancelable, + event.localX, event.localY, event.relatedObject, + event.ctrlKey, event.altKey, event.shiftKey, + event.buttonDown, event.delta); + + return newEvent; + } + + private static function mouseEventConverter(event:flash.events.Event):void + { + if (event is flash.events.MouseEvent && (!(event is org.apache.royale.events.MouseEvent))) + { + var p:* = event.target; + while (p != null) { + if (p is IHandlesOriginalEvent) return; + p = p.parent; + } + + var newEvent:mx.events.MouseEvent = + convert(flash.events.MouseEvent(event)); + if (newEvent) + { + // some events are not converted if there are no JS equivalents + event.stopImmediatePropagation(); + newEvent.targetBeforeBubbling = event.target; + event.target.dispatchEvent(newEvent); + } + else + trace("did not convert", event.type); + } + } + + /** + * The list of events to convert. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.0 + */ + public static var allConvertedEvents:Array = [ + flash.events.MouseEvent.CLICK, + flash.events.MouseEvent.DOUBLE_CLICK, + flash.events.MouseEvent.MOUSE_DOWN, + flash.events.MouseEvent.MOUSE_UP, + flash.events.MouseEvent.ROLL_OVER, + flash.events.MouseEvent.ROLL_OUT, + flash.events.MouseEvent.MOUSE_OVER, + flash.events.MouseEvent.MOUSE_OUT, + flash.events.MouseEvent.MOUSE_MOVE, + flash.events.MouseEvent.MOUSE_WHEEL + ]; + + /** + * The list of events to convert on each instance. + * Per-instance killers are needed for "out" events because + * they can be sent after the instance is removed from the + * display list so the main converter can't intercept them + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.0 + */ + public static var perInstanceConvertedEvents:Array = [ + flash.events.MouseEvent.MOUSE_UP, + flash.events.MouseEvent.ROLL_OUT, + flash.events.MouseEvent.MOUSE_OUT + ]; + + /** + * The event handler that converts the events. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.0 + */ + public static var eventHandler:Function = mouseEventConverter; + + /** + * Set up the top level converter. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.0 + */ + public static function setupAllConverters(target:IEventDispatcher, capture:Boolean = true):void + { + for each (var eventType:String in allConvertedEvents) + target.addEventListener(eventType, eventHandler, capture, 9999); + } + + /** + * Set up some event handlers on each instance. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.0 + */ + public static function setupInstanceConverters(target:IEventDispatcher):void + { + for each (var eventType:String in perInstanceConvertedEvents) + target.addEventListener(eventType, eventHandler, false, 9999); + } + } + COMPILE::JS + public class MouseEventConverter + { + public static function convert(nativeEvent:Object):mx.events.MouseEvent + { + return new mx.events.MouseEvent(nativeEvent["type"], nativeEvent["bubbles"], nativeEvent["cancelable"]); + } + } + +} diff --git a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/Application.as b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/Application.as index e070d6c..86d92a8 100644 --- a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/Application.as +++ b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/Application.as @@ -63,8 +63,13 @@ COMPILE::SWF { import mx.core.mx_internal; import mx.core.FlexGlobals; +import mx.events.utils.MouseEventConverter; import mx.managers.ISystemManager; +COMPILE::JS { + import org.apache.royale.core.HTMLElementWrapper; +} + import org.apache.royale.binding.ApplicationDataBinding; import org.apache.royale.core.AllCSSValuesImpl; import org.apache.royale.core.IFlexInfo; @@ -314,6 +319,11 @@ public class Application extends SkinnableContainer implements IStrand, IParent, this.valuesImpl = new AllCSSValuesImpl(); addBead(new ApplicationDataBinding()); + + COMPILE::JS + { + HTMLElementWrapper.converterMap["MouseEvent"] = MouseEventConverter; + } }