flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [07/16] git commit: [flex-asjs] [refs/heads/develop] - implement rollover support
Date Mon, 05 Jan 2015 23:21:26 GMT
implement rollover support


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

Branch: refs/heads/develop
Commit: 03d6279302df429f295798f0a297c9babb45ded3
Parents: 71df7b1
Author: Alex Harui <aharui@apache.org>
Authored: Mon Jan 5 10:14:45 2015 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Mon Jan 5 15:21:01 2015 -0800

----------------------------------------------------------------------
 .../src/org/apache/flex/events/MouseEvent.js    | 110 ++++++++++++++++++-
 1 file changed, 107 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/03d62793/frameworks/js/FlexJS/src/org/apache/flex/events/MouseEvent.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/events/MouseEvent.js b/frameworks/js/FlexJS/src/org/apache/flex/events/MouseEvent.js
index 95f77a2..ac9d632 100644
--- a/frameworks/js/FlexJS/src/org/apache/flex/events/MouseEvent.js
+++ b/frameworks/js/FlexJS/src/org/apache/flex/events/MouseEvent.js
@@ -14,21 +14,24 @@
 
 goog.provide('org.apache.flex.events.MouseEvent');
 
+goog.require('goog.events.BrowserEvent');
+
 
 
 /**
  * @constructor
- * @extends {MouseEvent}
+ * @extends {goog.events.BrowserEvent}
+ *
  * This is a shim class.  As long as you don't test
  * with "is" or "as", your code should work even
  * if the runtime is actually sending a native
  * browser MouseEvent
  */
 org.apache.flex.events.MouseEvent = function() {
-  window.MouseEvent.base(this, 'constructor');
+  org.apache.flex.events.MouseEvent.base(this, 'constructor');
 };
 goog.inherits(org.apache.flex.events.MouseEvent,
-    window.MouseEvent);
+    goog.events.BrowserEvent);
 
 
 /**
@@ -82,3 +85,104 @@ org.apache.flex.events.MouseEvent.prototype.FLEXJS_CLASS_INFO =
     { names: [{ name: 'MouseEvent',
                 qName: 'org.apache.flex.events.MouseEvent' }] };
 
+
+/**
+ * @return {boolean}
+ */
+org.apache.flex.events.MouseEvent.installRollOverMixin = function() {
+  window.addEventListener(org.apache.flex.events.MouseEvent.MOUSE_OVER,
+    org.apache.flex.events.MouseEvent.mouseOverHandler);
+  return true;
+};
+
+
+/**
+ * @param {Event} 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.
+ */
+org.apache.flex.events.MouseEvent.mouseOverHandler = function(e) {
+  var j, m, outs, me, parent;
+  var target = e.target.flexjs_wrapper;
+  if (target === undefined)
+    return; // probably over the html tag
+  var targets = org.apache.flex.events.MouseEvent.targets;
+  var index = targets.indexOf(target);
+  if (index != -1) {
+    // get all children
+    outs = targets.slice(index + 1);
+    m = outs.length;
+    for (j = 0; j < m; j++) {
+      me = org.apache.flex.events.MouseEvent.makeMouseEvent(
+               org.apache.flex.events.MouseEvent.ROLL_OUT, e);
+      outs[j].dispatchEvent(me);
+    }
+    org.apache.flex.events.MouseEvent.targets = targets.slice(0, index + 1);
+  }
+  else {
+    var newTargets = [target];
+    if (target.get_parent === undefined)
+      parent = null;
+    else
+      parent = target.get_parent();
+    while (parent) {
+      index = targets.indexOf(parent);
+      if (index == -1) {
+        newTargets.unshift(parent);
+        if (parent.get_parent === undefined)
+          break;
+        parent = parent.get_parent();
+      }
+      else {
+        outs = targets.slice(index + 1);
+        m = outs.length;
+        for (j = 0; j < m; j++) {
+          me = org.apache.flex.events.MouseEvent.makeMouseEvent(
+                   org.apache.flex.events.MouseEvent.ROLL_OUT, e);
+          outs[j].dispatchEvent(me);
+        }
+        targets = targets.slice(0, index + 1);
+        break;
+      }
+    }
+    var n = newTargets.length;
+    for (var i = 0; i < n; i++) {
+      me = org.apache.flex.events.MouseEvent.makeMouseEvent(
+                   org.apache.flex.events.MouseEvent.ROLL_OVER, e);
+                   newTargets[i].dispatchEvent(me);
+    }
+    org.apache.flex.events.MouseEvent.targets = targets.concat(newTargets);
+  }
+};
+
+
+/**
+ * @type {boolean}
+ */
+org.apache.flex.events.MouseEvent.rollOverMixin =
+    org.apache.flex.events.MouseEvent.installRollOverMixin();
+
+
+/**
+ * @type {Object}
+ */
+org.apache.flex.events.MouseEvent.targets = [];
+
+
+/**
+ * @param {string} type The event type.
+ * @param {Event} e The mouse event.
+ * @return {MouseEvent} The new event.
+ */
+org.apache.flex.events.MouseEvent.makeMouseEvent = function(type, e) {
+  var out = new MouseEvent(type);
+  out.initMouseEvent(type);
+  out.screenX = e.screenX;
+  out.screenY = e.screenY;
+  out.ctrlKey = e.ctrlKey;
+  out.shiftKey = e.shiftKey;
+  out.alttKey = e.altKey;
+  return out;
+};


Mime
View raw message