flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [5/5] git commit: [flex-asjs] [refs/heads/core_js_to_as] - fix rollovers and other mouseevents
Date Tue, 01 Dec 2015 09:14:23 GMT
fix rollovers and other mouseevents


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

Branch: refs/heads/core_js_to_as
Commit: eb92af6710fbe5782123335c9cb0a524176d1905
Parents: 872e685
Author: Alex Harui <aharui@apache.org>
Authored: Tue Dec 1 01:14:05 2015 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Tue Dec 1 01:14:05 2015 -0800

----------------------------------------------------------------------
 .../as/src/org/apache/flex/events/MouseEvent.as | 142 +++++++++++++++++--
 1 file changed, 134 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/eb92af67/frameworks/projects/Core/as/src/org/apache/flex/events/MouseEvent.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/as/src/org/apache/flex/events/MouseEvent.as b/frameworks/projects/Core/as/src/org/apache/flex/events/MouseEvent.as
index a15971e..756438f 100644
--- a/frameworks/projects/Core/as/src/org/apache/flex/events/MouseEvent.as
+++ b/frameworks/projects/Core/as/src/org/apache/flex/events/MouseEvent.as
@@ -22,11 +22,16 @@ package org.apache.flex.events
     {
         import flash.events.MouseEvent;
     }
+    COMPILE::JS
+    {
+        import window.MouseEvent;
+    }
     
     import org.apache.flex.core.IUIBase;
     import org.apache.flex.geom.Point;
     import org.apache.flex.utils.PointUtils;
     
+    
 	/**
 	 *  Mouse events
      *  
@@ -37,15 +42,27 @@ package org.apache.flex.events
 	 */
 	public class MouseEvent extends Event
 	{
-		public static const MOUSE_DOWN:String = "mouseDown";
-        public static const MOUSE_MOVE:String = "mouseMove";
-		public static const MOUSE_UP:String = "mouseUp";
-		public static const MOUSE_OUT:String = "mouseOut";
-		public static const MOUSE_OVER:String = "mouseOver";
-		public static const ROLL_OVER:String = "rollOver";
-		public static const ROLL_OUT:String = "rollOut";
+        private static function platformConstant(s:String):String
+        {
+            COMPILE::AS3
+            {
+                return s;
+            }
+            COMPILE::JS
+            {
+                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";
-
+        
          /**
          *  Constructor.
          *  
@@ -160,5 +177,114 @@ package org.apache.flex.events
             }
             return _stagePoint.y;            
         }
+        
+        /**
+         * @private
+         */
+        COMPILE::JS
+        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.
+         */
+        COMPILE::JS
+        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.flexjs_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);
+            }
+        }
+        
+        
+        /**
+         */
+        COMPILE::JS
+        private static var rollOverMixin:Boolean =
+            installRollOverMixin();
+        
+        
+        /**
+         */
+        COMPILE::JS
+        private static var targets:Array = [];
+
+        /**
+         * @param {string} type The event type.
+         * @param {Event} e The mouse event.
+         * @return {MouseEvent} The new event.
+         */
+        COMPILE::JS
+        private static function makeMouseEvent(type:String, e:window.MouseEvent):window.MouseEvent
+        {
+            var out:window.MouseEvent = new window.MouseEvent(type);
+            out.initMouseEvent(type, false, false,
+                e.view, e.detail, e.screenX, e.screenY,
+                e.clientX, e.clientY, e.ctrlKey, e.altKey,
+                e.shiftKey, e.metaKey, e.button, e.relatedTarget);
+            return out;
+        };
+
 	}
 }


Mime
View raw message