flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [1/3] git commit: [flex-asjs] [refs/heads/refactor-sprite] - implement event proxy for wrapped elements. Most events will be forwarded, but some events in bubble phase cannot be forwarded because you can't set the event.target in Flash. Instead, you wi
Date Thu, 04 Aug 2016 04:46:09 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/refactor-sprite 5e60e10c0 -> 184ef2d81


implement event proxy for wrapped elements.  Most events will be forwarded, but some events
in bubble phase cannot be forwarded because you can't set the event.target in Flash.  Instead,
you will have to use the isSameTarget method to compare targets


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/68453ef1
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/68453ef1
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/68453ef1

Branch: refs/heads/refactor-sprite
Commit: 68453ef1d189c52d37ddbe736b15e5efec2f809c
Parents: 5e60e10
Author: Alex Harui <aharui@apache.org>
Authored: Tue Aug 2 23:25:21 2016 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Tue Aug 2 23:25:21 2016 -0700

----------------------------------------------------------------------
 .../org/apache/flex/core/HTMLElementWrapper.as  | 44 ++++++++++++-
 .../org/apache/flex/events/ElementEvents.as     | 18 ++++++
 .../main/flex/org/apache/flex/events/Event.as   | 51 +++++++++++++--
 .../flex/org/apache/flex/events/IFlexJSEvent.as | 48 ++++++++++++++
 .../flex/org/apache/flex/events/MouseEvent.as   | 67 +++++++++++++++++++-
 .../org/apache/flex/events/ItemAddedEvent.as    |  3 +-
 .../org/apache/flex/events/ItemClickedEvent.as  |  3 +-
 .../org/apache/flex/events/ItemRemovedEvent.as  |  3 +-
 .../beads/controllers/DropDownListController.as | 21 +++---
 9 files changed, 235 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/68453ef1/frameworks/projects/Core/src/main/flex/org/apache/flex/core/HTMLElementWrapper.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/HTMLElementWrapper.as
b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/HTMLElementWrapper.as
index 1b42a83..8d5dfc2 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/core/HTMLElementWrapper.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/core/HTMLElementWrapper.as
@@ -26,7 +26,15 @@ package org.apache.flex.core
         import goog.events;
         import goog.events.EventTarget;
     }
-    import org.apache.flex.events.Event;        
+    COMPILE::SWF
+    {
+        import flash.events.Event;
+        import flash.events.IEventDispatcher;
+        import org.apache.flex.events.ElementEvents;
+        import org.apache.flex.events.IFlexJSEvent;
+    }
+    
+    import org.apache.flex.events.Event;
     import org.apache.flex.events.EventDispatcher;
 
     COMPILE::SWF
@@ -122,6 +130,40 @@ package org.apache.flex.core
             return null;
         }
         
+        override public function addEventListener(type:String, handler:Function, opt_capture:Boolean
= false, priority:int = 0, weak:Boolean = false):void
+        {
+            var source:IEventDispatcher = getActualDispatcher_(type) as IEventDispatcher;
+            if (source != this)
+                source.addEventListener(type, forwarder, opt_capture);
+            
+            super.addEventListener(type, handler, opt_capture);
+        }
+        
+        override public function removeEventListener(type:String, handler:Function, opt_capture:Boolean
= false):void
+        {
+            var source:IEventDispatcher = getActualDispatcher_(type) as IEventDispatcher;
+            if (source != this)
+                source.removeEventListener(type, handler, opt_capture);
+            
+            super.removeEventListener(type, handler, opt_capture);
+        }
+        
+        private function getActualDispatcher_(type:String):IEventDispatcher
+        {
+            var source:IEventDispatcher = this;
+            if (ElementEvents.elementEvents[type]) {
+                // mouse and keyboard events also dispatch off the element.
+                source = this.element as IEventDispatcher;
+            }
+            return source;
+        }
+        
+        private function forwarder(event:flash.events.Event):void
+        {
+            if (event is IFlexJSEvent)
+                event = IFlexJSEvent(event).cloneEvent() as flash.events.Event;
+            dispatchEvent(event);
+        }
     }
     
 	COMPILE::JS

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/68453ef1/frameworks/projects/Core/src/main/flex/org/apache/flex/events/ElementEvents.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/ElementEvents.as
b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/ElementEvents.as
index ad510fc..157e3b0 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/ElementEvents.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/ElementEvents.as
@@ -23,6 +23,24 @@ package org.apache.flex.events
 	COMPILE::SWF
 	public class ElementEvents
 	{
+        //--------------------------------------
+        //   Static Property
+        //--------------------------------------
+        
+        static public const elementEvents:Object = {
+            'click': 1,
+            'change': 1,
+            'keyup': 1,
+            'keydown': 1,
+            'load': 1,
+            'mouseover': 1,
+            'mouseout': 1,
+            'mouseup': 1,
+            'mousedown': 1,
+            'mousemove': 1,
+            'rollover': 1,
+            'rollout': 1
+        };
 	}
 
 	COMPILE::JS

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/68453ef1/frameworks/projects/Core/src/main/flex/org/apache/flex/events/Event.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/Event.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/Event.as
index 5d8c81e..e27a88e 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/Event.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/Event.as
@@ -18,6 +18,8 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.flex.events
 {
+    import org.apache.flex.core.IFlexJSElement;
+
     COMPILE::SWF {
         import flash.events.Event;
     }
@@ -40,7 +42,7 @@ package org.apache.flex.events
 	 * @productversion FlexJS 0.0
 	 */
 	COMPILE::SWF
-	public class Event extends flash.events.Event
+	public class Event extends flash.events.Event implements IFlexJSEvent
 	{
 
 		//--------------------------------------
@@ -83,7 +85,7 @@ package org.apache.flex.events
 		 */
 		public override function clone():flash.events.Event
 		{
-			return cloneEvent();
+			return cloneEvent() as flash.events.Event;
 		}
 
 		/**
@@ -94,14 +96,33 @@ package org.apache.flex.events
 		 * @playerversion AIR 2.6
 		 * @productversion FlexJS 0.0
 		 */
-		public function cloneEvent():org.apache.flex.events.Event
+		public function cloneEvent():IFlexJSEvent
 		{
 			return new org.apache.flex.events.Event(type, bubbles, cancelable);
 		}
+        
+        /**
+         * 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
+         * matches the potential target
+         *
+         * @langversion 3.0
+         * @playerversion Flash 10.2
+         * @playerversion AIR 2.6
+         * @productversion FlexJS 0.0
+         */
+        public function isSameTarget(potentialTarget:IEventDispatcher):Boolean
+        {
+            if (potentialTarget === target) return true;
+            if (target is IFlexJSElement)
+                if (IFlexJSElement(target).flexjs_wrapper === potentialTarget) return true;
+            return false;
+        }
+        
 	}
 
     COMPILE::JS
-    public class Event extends goog.events.Event {
+    public class Event extends goog.events.Event implements IFlexJSEvent {
 
 		public static const CHANGE:String = "change";
 		public static const COMPLETE:String = "complete";
@@ -127,9 +148,29 @@ package org.apache.flex.events
 			throw new Error("stopImmediatePropagation");
 		}
 		
-		public function cloneEvent():org.apache.flex.events.Event
+		public function cloneEvent():IFlexJSEvent
 		{
 			return new org.apache.flex.events.Event(type, bubbles, cancelable);
 		}
+        
+        /**
+         * 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
+         * matches the potential target
+         *
+         * @langversion 3.0
+         * @playerversion Flash 10.2
+         * @playerversion AIR 2.6
+         * @productversion FlexJS 0.0
+         * @flexjsignorecoercion Object
+         */
+        public function isSameTarget(potentialTarget:IEventDispatcher):Boolean
+        {
+            if (potentialTarget === target) return true;
+            if (target is IFlexJSElement)
+                if ((target as Object).flexjs_wrapper === potentialTarget) return true;
+            return false;
+        }
+
     }
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/68453ef1/frameworks/projects/Core/src/main/flex/org/apache/flex/events/IFlexJSEvent.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/IFlexJSEvent.as
b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/IFlexJSEvent.as
new file mode 100644
index 0000000..f230477
--- /dev/null
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/IFlexJSEvent.as
@@ -0,0 +1,48 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 org.apache.flex.events
+{
+
+	/**
+	 * This class simply wraps flash.events.Event so that
+	 * no flash packages are needed on the JS side.
+	 * At runtime, this class is not always the event object
+	 * that is dispatched.  In most cases we are dispatching
+	 * DOMEvents instead, so as long as you don't actually
+	 * check the typeof(event) it will work
+	 *
+	 * @langversion 3.0
+	 * @playerversion Flash 10.2
+	 * @playerversion AIR 2.6
+	 * @productversion FlexJS 0.0
+	 */
+	public interface IFlexJSEvent
+	{
+
+		/**
+		 * Create a copy/clone of the Event object.
+		 *
+		 * @langversion 3.0
+		 * @playerversion Flash 10.2
+		 * @playerversion AIR 2.6
+		 * @productversion FlexJS 0.0
+		 */
+		function cloneEvent():IFlexJSEvent;
+	}
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/68453ef1/frameworks/projects/Core/src/main/flex/org/apache/flex/events/MouseEvent.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/MouseEvent.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/MouseEvent.as
index e8b3d8c..a6f4e3c 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/MouseEvent.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/MouseEvent.as
@@ -20,6 +20,7 @@ package org.apache.flex.events
 {
     COMPILE::SWF
     {
+        import flash.events.Event;
         import flash.events.MouseEvent;
 		import flash.display.InteractiveObject;
     }
@@ -27,7 +28,8 @@ package org.apache.flex.events
     {
         import window.MouseEvent;
     }
-
+    
+    import org.apache.flex.core.IFlexJSElement;
     import org.apache.flex.core.IUIBase;
     import org.apache.flex.geom.Point;
     import org.apache.flex.utils.PointUtils;
@@ -42,7 +44,7 @@ package org.apache.flex.events
      *  @productversion FlexJS 0.0
 	 */
 	COMPILE::SWF
-	public class MouseEvent extends flash.events.MouseEvent
+	public class MouseEvent extends flash.events.MouseEvent implements IFlexJSEvent
 	{
         private static function platformConstant(s:String):String
         {
@@ -132,10 +134,53 @@ package org.apache.flex.events
             }
             return _stagePoint.y;
         }
+        
+        /**
+         * @private
+         */
+        public override function clone():flash.events.Event
+        {
+            return cloneEvent() as flash.events.Event;
+        }
+        
+        /**
+         * Create a copy/clone of the Event object.
+         *
+         * @langversion 3.0
+         * @playerversion Flash 10.2
+         * @playerversion AIR 2.6
+         * @productversion FlexJS 0.0
+         */
+        public function cloneEvent():IFlexJSEvent
+        {
+            return new org.apache.flex.events.MouseEvent(type, bubbles, cancelable,
+                localX, localY, relatedObject, ctrlKey, altKey, shiftKey,
+                buttonDown, delta
+                /* got errors for commandKey, commandKey, controlKey, clickCount*/);
+        }
+
+        /**
+         * 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
+         * matches the potential target
+         *
+         * @langversion 3.0
+         * @playerversion Flash 10.2
+         * @playerversion AIR 2.6
+         * @productversion FlexJS 0.0
+         */
+        public function isSameTarget(potentialTarget:IEventDispatcher):Boolean
+        {
+            if (potentialTarget === target) return true;
+            if (target is IFlexJSElement)
+                if (IFlexJSElement(target).flexjs_wrapper === potentialTarget) return true;
+            return false;
+        }
+
 	}
 
 	COMPILE::JS
-	public class MouseEvent extends Event
+	public class MouseEvent extends Event implements IFlexJSEvent
 	{
 		private static function platformConstant(s:String):String
 		{
@@ -364,5 +409,21 @@ package org.apache.flex.events
 			return out;
 		};
 
+        /**
+         * Create a copy/clone of the Event object.
+         *
+         * @langversion 3.0
+         * @playerversion Flash 10.2
+         * @playerversion AIR 2.6
+         * @productversion FlexJS 0.0
+         */
+        override public function cloneEvent():IFlexJSEvent
+        {
+            return new org.apache.flex.events.MouseEvent(type, bubbles, cancelable,
+                localX, localY, relatedObject, ctrlKey, altKey, shiftKey,
+                buttonDown, delta
+            /* got errors for commandKey, commandKey, controlKey, clickCount*/);
+        }
+
 	}
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/68453ef1/frameworks/projects/HTML/src/main/flex/org/apache/flex/events/ItemAddedEvent.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/events/ItemAddedEvent.as
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/events/ItemAddedEvent.as
index a6ae756..d67c406 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/events/ItemAddedEvent.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/events/ItemAddedEvent.as
@@ -21,6 +21,7 @@ package org.apache.flex.events
 {
 
 	import org.apache.flex.events.CustomEvent;
+	import org.apache.flex.events.IFlexJSEvent;
 	
 	/**
 	 * The ItemAddedEvent is dispatched by IItemRendererParent objects whenenver an
@@ -78,7 +79,7 @@ package org.apache.flex.events
 		/**
 		 * @private
 		 */
-		override public function cloneEvent():org.apache.flex.events.Event
+		override public function cloneEvent():IFlexJSEvent
 		{
 			var newEvent:ItemAddedEvent = new ItemAddedEvent(type);
 			newEvent.item = item;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/68453ef1/frameworks/projects/HTML/src/main/flex/org/apache/flex/events/ItemClickedEvent.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/events/ItemClickedEvent.as
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/events/ItemClickedEvent.as
index febc798..0b7cdce 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/events/ItemClickedEvent.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/events/ItemClickedEvent.as
@@ -21,6 +21,7 @@ package org.apache.flex.events
 {
 
 	import org.apache.flex.events.CustomEvent;
+	import org.apache.flex.events.IFlexJSEvent;
 	
 	/**
 	 * The ItemClickedEvent is a custom event issued by an itemRenderer to
@@ -103,7 +104,7 @@ package org.apache.flex.events
 		/**
 		 * @private
 		 */
-		override public function cloneEvent():org.apache.flex.events.Event
+		override public function cloneEvent():IFlexJSEvent
 		{
 			var newEvent:ItemClickedEvent = new ItemClickedEvent(type);
 			newEvent.index = index;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/68453ef1/frameworks/projects/HTML/src/main/flex/org/apache/flex/events/ItemRemovedEvent.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/events/ItemRemovedEvent.as
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/events/ItemRemovedEvent.as
index 313f3f9..d5dcb80 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/events/ItemRemovedEvent.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/events/ItemRemovedEvent.as
@@ -21,6 +21,7 @@ package org.apache.flex.events
 {
 
 	import org.apache.flex.events.CustomEvent;
+	import org.apache.flex.events.IFlexJSEvent;
 	
 	/**
 	 * The ItemRemovedEvent is dispatched by IItemRendererParent objects whenenver an
@@ -78,7 +79,7 @@ package org.apache.flex.events
 		/**
 		 * @private
 		 */
-		override public function cloneEvent():org.apache.flex.events.Event
+		override public function cloneEvent():IFlexJSEvent
 		{
 			var newEvent:ItemRemovedEvent = new ItemRemovedEvent(type);
 			newEvent.item = item;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/68453ef1/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DropDownListController.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DropDownListController.as
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DropDownListController.as
index c279dc5..c84d9d0 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DropDownListController.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DropDownListController.as
@@ -18,9 +18,6 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.flex.html.beads.controllers
 {
-	import flash.display.DisplayObject;
-	import flash.geom.Point;
-	
 	import org.apache.flex.core.IBead;
 	import org.apache.flex.core.IBeadController;
 	import org.apache.flex.core.ISelectionModel;
@@ -30,8 +27,10 @@ package org.apache.flex.html.beads.controllers
 	import org.apache.flex.events.Event;
 	import org.apache.flex.events.IEventDispatcher;
 	import org.apache.flex.events.MouseEvent;
-	import org.apache.flex.html.beads.IDropDownListView;
-
+    import org.apache.flex.geom.Point;
+   	import org.apache.flex.html.beads.IDropDownListView;
+    import org.apache.flex.utils.PointUtils;
+    
     /**
      *  The DropDownListController class is the controller for
      *  org.apache.flex.html.DropDownList.  Controllers
@@ -81,22 +80,22 @@ package org.apache.flex.html.beads.controllers
             var viewBead:IDropDownListView = _strand.getBeadByType(IDropDownListView) as
IDropDownListView;
             var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as
ISelectionModel;
             var popUpModel:ISelectionModel = UIBase(viewBead.popUp).model as ISelectionModel;
-            DisplayObject(viewBead.popUp).width = DisplayObject(_strand).width;
+            IUIBase(viewBead.popUp).width = IUIBase(_strand).width;
             popUpModel.dataProvider = selectionModel.dataProvider;
             popUpModel.labelField = selectionModel.labelField;
             viewBead.popUpVisible = true; // adds to display list as well
             popUpModel.selectedIndex = selectionModel.selectedIndex;
-            var pt:Point = new Point(DisplayObject(_strand).x, DisplayObject(_strand).y +
DisplayObject(_strand).height);
-            pt = DisplayObject(_strand).parent.localToGlobal(pt);
-			DisplayObject(viewBead.popUp).x = pt.x;
-			DisplayObject(viewBead.popUp).y = pt.y;
+            var pt:Point = new Point(IUIBase(_strand).x, IUIBase(_strand).y + IUIBase(_strand).height);
+            pt = PointUtils.localToGlobal(pt, IUIBase(_strand).parent);
+            IUIBase(viewBead.popUp).x = pt.x;
+            IUIBase(viewBead.popUp).y = pt.y;
             IEventDispatcher(viewBead.popUp).addEventListener("change", changeHandler);
             IUIBase(_strand).topMostEventDispatcher.addEventListener(org.apache.flex.events.MouseEvent.CLICK,
dismissHandler);
         }
         
         private function dismissHandler(event:org.apache.flex.events.MouseEvent):void
         {
-            if (event.target == _strand) return;
+            if (event.isSameTarget(_strand as IEventDispatcher)) return;
             
             IUIBase(_strand).topMostEventDispatcher.removeEventListener(org.apache.flex.events.MouseEvent.CLICK,
dismissHandler);
             var viewBead:IDropDownListView = _strand.getBeadByType(IDropDownListView) as
IDropDownListView;


Mime
View raw message