You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ah...@apache.org on 2020/02/28 07:52:38 UTC

[royale-asjs] branch develop updated: fix SWF side MXTests. Broke when Yishay added Focus and Keyboard event handlers. Will fix JS side in another commit

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


The following commit(s) were added to refs/heads/develop by this push:
     new 211260a  fix SWF side MXTests.  Broke when Yishay added Focus and Keyboard event handlers.  Will fix JS side in another commit
211260a is described below

commit 211260a4d054f31c0f4c3ea269bafb382f21f96f
Author: Alex Harui <ah...@apache.org>
AuthorDate: Thu Feb 27 23:52:23 2020 -0800

    fix SWF side MXTests.  Broke when Yishay added Focus and Keyboard event handlers.  Will fix JS side in another commit
---
 .../src/main/royale/mx/controls/TextInput.as       |   6 +-
 .../src/main/royale/mx/core/Application.as         |   2 +
 .../src/main/royale/mx/core/UIComponent.as         |   7 ++
 .../src/main/royale/mx/events/FocusEvent.as        |   6 +-
 .../src/main/royale/mx/events/KeyboardEvent.as     |  22 ++--
 .../royale/mx/events/utils/FocusEventConverter.as  | 105 ++++++++++++++++++-
 .../mx/events/utils/KeyboardEventConverter.as      | 112 +++++++++++++++++++--
 7 files changed, 232 insertions(+), 28 deletions(-)

diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/TextInput.as b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/TextInput.as
index 7db5101..84cd5bc 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/TextInput.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/TextInput.as
@@ -994,7 +994,7 @@ public class TextInput extends UIComponent implements ITextInput
     //  listData
     //----------------------------------
 
-    private var _listData:BaseListData;
+    private var _listData:Object;
 
     [Bindable("dataChange")]
     [Inspectable(environment="none")]
@@ -1019,7 +1019,7 @@ public class TextInput extends UIComponent implements ITextInput
      *  @playerversion AIR 1.1
      *  @productversion Flex 3
      */
-    public function get listData():BaseListData
+    public function get listData():Object
     {
         return _listData;
     }
@@ -1027,7 +1027,7 @@ public class TextInput extends UIComponent implements ITextInput
     /**
      *  @private
      */
-    public function set listData(value:BaseListData):void
+    public function set listData(value:Object):void
     {
         _listData = value;
     }
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 ce2874b..69f1194 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/core/Application.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/core/Application.as
@@ -368,6 +368,8 @@ public class Application extends Container implements IStrand, IParent, IEventDi
 	private function initHandler(event:flash.events.Event):void
 	{
 		MouseEventConverter.setupAllConverters(stage);
+		FocusEventConverter.setupAllConverters(stage);
+		KeyboardEventConverter.setupAllConverters(stage);
 		
 		if (dispatchEvent(new org.apache.royale.events.Event("preinitialize", false, true)))
 			this.initializeApplication();
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/core/UIComponent.as b/frameworks/projects/MXRoyale/src/main/royale/mx/core/UIComponent.as
index 8277549..ab06da7 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/core/UIComponent.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/core/UIComponent.as
@@ -51,6 +51,8 @@ import mx.events.KeyboardEvent;
 import mx.events.MoveEvent;
 import mx.events.PropertyChangeEvent;
 import mx.events.ResizeEvent;
+import mx.events.utils.KeyboardEventConverter;
+import mx.events.utils.FocusEventConverter;
 import mx.managers.ICursorManager;
 import mx.managers.IFocusManager;
 import mx.managers.IFocusManagerContainer;
@@ -621,6 +623,11 @@ public class UIComponent extends UIBase
         super();
         if (this is IFocusManagerComponent)
         {
+			COMPILE::SWF
+			{
+				KeyboardEventConverter.setupInstanceConverters(this);
+				FocusEventConverter.setupInstanceConverters(this);
+			}
             addEventListener(FocusEvent.FOCUS_IN, focusInHandler);
             addEventListener(FocusEvent.FOCUS_OUT, focusOutHandler);
             addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/events/FocusEvent.as b/frameworks/projects/MXRoyale/src/main/royale/mx/events/FocusEvent.as
index 27f6a73..3242c5c 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/events/FocusEvent.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/events/FocusEvent.as
@@ -49,10 +49,10 @@ public class FocusEvent extends flash.events.FocusEvent
 {
     public static const FOCUS_IN:String = "focusIn";
     public static const FOCUS_OUT:String = "focusOut";
-	public function FocusEvent(type:String, bubbles:Boolean = false,
-                              cancelable:Boolean = false ,relatedObject:InteractiveObject = null, shiftKey:Boolean = false, keyCode:uint = 0, direction:String = "none")
+	public function FocusEvent(type:String/*, bubbles:Boolean = false,
+                              cancelable:Boolean = false ,relatedObject:InteractiveObject = null, shiftKey:Boolean = false, keyCode:uint = 0, direction:String = "none"*/)
     {
-        super(type, bubbles, cancelable,relatedObject,shiftKey,keyCode,direction);
+        super(type/*, bubbles, cancelable,relatedObject,shiftKey,keyCode,direction*/);
     }
 }
 
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/events/KeyboardEvent.as b/frameworks/projects/MXRoyale/src/main/royale/mx/events/KeyboardEvent.as
index 3b23aab..c93baf2 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/events/KeyboardEvent.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/events/KeyboardEvent.as
@@ -46,7 +46,14 @@ public class KeyboardEvent extends flash.events.KeyboardEvent
 	shiftKeyValue:Boolean = false, 
 	controlKeyValue:Boolean = false, commandKeyValue:Boolean = false)
     {
-        super(type, bubbles, cancelable,charCodeValue,keyCodeValue,keyLocationValue,ctrlKeyValue,altKeyValue,shiftKeyValue,controlKeyValue,commandKeyValue);
+        super(type, bubbles, cancelable);
+		charCode = charCodeValue;
+		keyCode = keyCodeValue;
+		//,keyLocationValue,
+		ctrlKey = ctrlKeyValue;
+		altKey = altKeyValue;
+		shiftKey = shiftKeyValue;
+		//,controlKeyValue,commandKeyValue);
     }
 	
 	
@@ -58,16 +65,7 @@ public class KeyboardEvent extends flash.events.KeyboardEvent
 	public static const DELETE:uint = platformConstant(46);
 	public static const END:uint = platformConstant(35);
 	public static const KEY_UP:String = platformConstant1("keyUp");
-	
-	public function get KEY_DOWN():String
-	{
-		return "keyDown";
-	}
 		
-	public function set KEY_DOWN(val:String):void
-	{
-	} 
-	
     public function get key():String
     {
         return String.fromCharCode(charCode);
@@ -127,10 +125,6 @@ public class KeyboardEvent extends org.apache.royale.events.KeyboardEvent
         	{
             	return s.toLowerCase();
         	}
-		public static function get capsLock():Boolean
-	        {
-	        return true;
-	        }
 	//--------------------------------------------------------------------------
 	//
 	//  Class constants
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/events/utils/FocusEventConverter.as b/frameworks/projects/MXRoyale/src/main/royale/mx/events/utils/FocusEventConverter.as
index a731ac0..308f085 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/events/utils/FocusEventConverter.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/events/utils/FocusEventConverter.as
@@ -24,6 +24,8 @@ package mx.events.utils
 	COMPILE::SWF
 	{
 		import flash.events.FocusEvent;
+        import flash.events.IEventDispatcher;
+        import org.apache.royale.events.utils.IHandlesOriginalEvent;
 	}
 	
 	/**
@@ -48,10 +50,111 @@ package mx.events.utils
 		COMPILE::SWF
 		public static function convert(oldEvent:flash.events.FocusEvent):mx.events.FocusEvent
 		{
-			var newEvent:mx.events.FocusEvent = new mx.events.FocusEvent(oldEvent.type, true);
+			var newEvent:mx.events.FocusEvent = new mx.events.FocusEvent(oldEvent.type);
 			return newEvent;
 		}
 		
+		COMPILE::SWF
+		private static function focusEventConverter(event:flash.events.Event):void
+        {
+            if (event is flash.events.FocusEvent && (!(event is mx.events.FocusEvent)))
+            {
+				var p:* = event.target;
+				while (p != null) {
+					if (p is IHandlesOriginalEvent) return;
+					p = p.parent;
+				}
+				
+                var newEvent:mx.events.FocusEvent = 
+                    convert(flash.events.FocusEvent(event));
+                if (newEvent) 
+                {
+                    // some events are not converted if there are no JS equivalents
+                    event.stopImmediatePropagation();
+					//newEvent.targetBeforeBubbling = event.target; might be needed
+                    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
+         */
+		COMPILE::SWF
+        public static var allConvertedEvents:Array = [
+            flash.events.FocusEvent.KEY_FOCUS_CHANGE,
+            flash.events.FocusEvent.MOUSE_FOCUS_CHANGE,
+            flash.events.FocusEvent.FOCUS_IN,
+            flash.events.FocusEvent.FOCUS_OUT
+            ];
+            
+        /**
+         *  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
+         */
+		COMPILE::SWF
+        public static var perInstanceConvertedEvents:Array = [
+            flash.events.FocusEvent.KEY_FOCUS_CHANGE,
+            flash.events.FocusEvent.MOUSE_FOCUS_CHANGE,
+            flash.events.FocusEvent.FOCUS_OUT
+        ];
+        
+        /**
+         *  The event handler that converts the events.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+		COMPILE::SWF
+        public static var eventHandler:Function = focusEventConverter;
+        
+        /**
+         *  Set up the top level converter.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+		COMPILE::SWF
+        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
+         */
+		COMPILE::SWF
+        public static function setupInstanceConverters(target:IEventDispatcher):void
+        {
+            for each (var eventType:String in perInstanceConvertedEvents)
+                target.addEventListener(eventType, eventHandler, false, 9999);
+        }
+
+		
 		/**
 		 *  Converts JS keyboard events to Royale ones.
 		 *  
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/events/utils/KeyboardEventConverter.as b/frameworks/projects/MXRoyale/src/main/royale/mx/events/utils/KeyboardEventConverter.as
index 4aa2a96..8422e26 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/events/utils/KeyboardEventConverter.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/events/utils/KeyboardEventConverter.as
@@ -25,8 +25,9 @@ package mx.events.utils
 
 	COMPILE::SWF
 	{
+		import flash.events.IEventDispatcher;
 		import flash.events.KeyboardEvent;
-        import org.apache.royale.events.KeyboardEvent;
+        import org.apache.royale.events.utils.IHandlesOriginalEvent;
 	}
 	COMPILE::JS
 	{
@@ -54,18 +55,115 @@ package mx.events.utils
 		 *  @productversion Royale 0.8
 		 */
 		COMPILE::SWF
-		public static function convert(oldEvent:flash.events.KeyboardEvent):org.apache.royale.events.KeyboardEvent
+		public static function convert(oldEvent:flash.events.KeyboardEvent):mx.events.KeyboardEvent
 		{
-			var code:String = KeyConverter.convertKeyCode(oldEvent.keyCode);
-			var key:String = KeyConverter.convertCharCode(oldEvent.charCode);
-			var type:String = oldEvent.type == flash.events.KeyboardEvent.KEY_DOWN ? org.apache.royale.events.KeyboardEvent.KEY_DOWN : 
-				org.apache.royale.events.KeyboardEvent.KEY_UP;
-			var newEvent:org.apache.royale.events.KeyboardEvent = new org.apache.royale.events.KeyboardEvent(type, key, code, oldEvent.shiftKey);
+			//var code:String = KeyConverter.convertKeyCode(oldEvent.keyCode);
+			//var key:String = KeyConverter.convertCharCode(oldEvent.charCode);
+			var type:String = oldEvent.type == flash.events.KeyboardEvent.KEY_DOWN ? mx.events.KeyboardEvent.KEY_DOWN : 
+				mx.events.KeyboardEvent.KEY_UP;
+			var newEvent:mx.events.KeyboardEvent = new mx.events.KeyboardEvent(type, true, false, oldEvent.charCode, oldEvent.keyCode, 0,
+					oldEvent.ctrlKey, oldEvent.altKey, oldEvent.shiftKey);
 			newEvent.altKey = oldEvent.altKey;
 //			newEvent.ctrlKey = oldEvent.controlKey; // TODO
 			return newEvent;
 		}
 		
+		COMPILE::SWF
+        private static function keyEventConverter(event:flash.events.Event):void
+        {
+            if (event is flash.events.KeyboardEvent && (!(event is mx.events.KeyboardEvent)))
+            {
+				var p:* = event.target;
+				while (p != null) {
+					if (p is IHandlesOriginalEvent) return;
+					p = p.parent;
+				}
+				
+                var newEvent:mx.events.KeyboardEvent = 
+                    convert(flash.events.KeyboardEvent(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
+         */
+		COMPILE::SWF
+        public static var allConvertedEvents:Array = [
+			flash.events.KeyboardEvent.KEY_DOWN,
+			flash.events.KeyboardEvent.KEY_UP
+            ];
+            
+        /**
+         *  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
+         */
+		COMPILE::SWF
+        public static var perInstanceConvertedEvents:Array = [
+            flash.events.KeyboardEvent.KEY_UP
+        ];
+        
+        /**
+         *  The event handler that converts the events.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+		COMPILE::SWF
+        public static var eventHandler:Function = keyEventConverter;
+        
+        /**
+         *  Set up the top level converter.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+		COMPILE::SWF
+        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
+         */
+		COMPILE::SWF
+        public static function setupInstanceConverters(target:IEventDispatcher):void
+        {
+            for each (var eventType:String in perInstanceConvertedEvents)
+                target.addEventListener(eventType, eventHandler, false, 9999);
+        }
+
 		/**
 		 *  Converts JS keyboard events to Royale ones.
 		 *