flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mih...@apache.org
Subject git commit: [flex-sdk] [refs/heads/develop] - FLEX-34979 CAUSE: The transformation of the spark Sort and SortField from extending AdvancedStyleClient to implementing its interfaces and using an instance of it as a class member had some more bugs: -the id
Date Tue, 08 Dec 2015 15:46:24 GMT
Repository: flex-sdk
Updated Branches:
  refs/heads/develop 64216e917 -> d22d68726


FLEX-34979
CAUSE:
The transformation of the spark Sort and SortField from extending AdvancedStyleClient to implementing
its interfaces and using an instance of it as a class member had some more bugs:
-the id setter didn't exist
-when AdvancedStyleClient dispatched an event, Sort / SortField didn't pick up on it and dispatch
forward
-When AdvancedStyleClient initialized it added itself as a styleClient to the document. This
is undesired for Sort and SortField because from then on the style code would used the AdvancedStyleClient
member instead of the Sort / SortField instances, as before, which meant that their relevant
functions (such as setStyle or styleChanged) were never called.

SOLUTION:
-there is now an id setter in AdvancedStyleClientImplementation
-AdvancedStyleClient_ was introduced to be able to override some functions of AdvancedStyleClient
-Sort and SortField now listen to the events dispatched via their AdvancedStyleClient_ member
and pass on the events if there's a listener for them
-on initialization we now add the Sort / SortField instances as styleClients to the document
instead of their AdvancedStyleClient members, which should now be hidden from any code interacting
with Sort and SortField (this is achieved in AdvancedStyleClient_)
-all the instances where AdvancedStyleClient interacted with the StyleProtoChain using 'this'
were changed into using the Sort / SortField instances

NOTES:
-Since some of the public functions in AdvancedStyleClient (getStyle, setStyle, styleChanged)
are also called internally from other AdvancedStyleClient functions (or could be, in the future),
and we need them to hit the Sort / SortField implementations instead, AdvancedStyleClient_
now overrides those functions and makes sure that the Sort / SortField versions are called.
-AdvancedStyleClient.setDeferredStyles() was made protected so that AdvancedStyleClient_.as
can override it to make sure that StyleProtoChain.setStyle is always called referring to Sort
or SortField instead of the instance of AdvancedStyleClient_ they use internally.


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

Branch: refs/heads/develop
Commit: d22d68726e271ac680efe56296270b4a68876d92
Parents: 64216e9
Author: Mihai Chira <mihaic@apache.org>
Authored: Tue Dec 8 16:45:49 2015 +0100
Committer: Mihai Chira <mihaic@apache.org>
Committed: Tue Dec 8 16:45:49 2015 +0100

----------------------------------------------------------------------
 .../src/mx/styles/AdvancedStyleClient.as        |   7 +-
 .../AdvancedStyleClientImplementation.as        |  24 ++++-
 .../spark/collections/AdvancedStyleClient_.as   | 107 +++++++++++++++++++
 .../spark/src/spark/collections/Sort.as         |  18 ++--
 .../spark/src/spark/collections/SortField.as    |  11 +-
 5 files changed, 148 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/d22d6872/frameworks/projects/framework/src/mx/styles/AdvancedStyleClient.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/styles/AdvancedStyleClient.as b/frameworks/projects/framework/src/mx/styles/AdvancedStyleClient.as
index a8b095c..6b2dc21 100644
--- a/frameworks/projects/framework/src/mx/styles/AdvancedStyleClient.as
+++ b/frameworks/projects/framework/src/mx/styles/AdvancedStyleClient.as
@@ -89,7 +89,7 @@ public class AdvancedStyleClient extends EventDispatcher
      *  Keeps track of the setStyles() calls that have been deferred
      *  until a moduleFactory is set.
      */
-    private var deferredSetStyles:Object;
+    protected var deferredSetStyles:Object;
 
     //--------------------------------------------------------------------------
     //
@@ -235,15 +235,14 @@ public class AdvancedStyleClient extends EventDispatcher
         return StyleManager.getStyleManager(moduleFactory);
     }
 
-    private function setDeferredStyles():void
+    protected function setDeferredStyles():void
     {
         if (!deferredSetStyles)
             return;
 
         for (var styleProp:String in deferredSetStyles)
         {
-            StyleProtoChain.setStyle(
-                                this, styleProp, deferredSetStyles[styleProp]);
+            StyleProtoChain.setStyle(this, styleProp, deferredSetStyles[styleProp]);
         }
 
         deferredSetStyles = null;

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/d22d6872/frameworks/projects/spark/src/spark/collections/AdvancedStyleClientImplementation.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/spark/src/spark/collections/AdvancedStyleClientImplementation.as
b/frameworks/projects/spark/src/spark/collections/AdvancedStyleClientImplementation.as
index a1429db..9e4e087 100644
--- a/frameworks/projects/spark/src/spark/collections/AdvancedStyleClientImplementation.as
+++ b/frameworks/projects/spark/src/spark/collections/AdvancedStyleClientImplementation.as
@@ -1,8 +1,11 @@
 import mx.core.IFlexModuleFactory;
+import mx.core.UIComponent;
 import mx.styles.AdvancedStyleClient;
 import mx.styles.CSSStyleDeclaration;
 import mx.styles.IAdvancedStyleClient;
 import mx.styles.IStyleManager2;
+import mx.styles.StyleProtoChain;
+import mx.utils.NameUtil;
 
 ////////////////////////////////////////////////////////////////////////////////
 //
@@ -23,13 +26,30 @@ import mx.styles.IStyleManager2;
 //
 ////////////////////////////////////////////////////////////////////////////////
 
-private var _advancedStyleClient:AdvancedStyleClient = new AdvancedStyleClient();
+private var _advancedStyleClient:AdvancedStyleClient_;
+
+private function initAdvancedStyleClient():void
+{
+    _advancedStyleClient = new AdvancedStyleClient_(this);
+    _advancedStyleClient.addEventListener("allStylesChanged", dispatchIfListenersExist);
+}
+
+private function dispatchIfListenersExist(event:Event):void
+{
+    if(hasEventListener(event.type))
+        dispatchEvent(event);
+}
 
 public function get id():String
 {
     return _advancedStyleClient.id;
 }
 
+public function set id(value:String):void
+{
+    _advancedStyleClient.id = value;
+}
+
 public function get styleParent():IAdvancedStyleClient
 {
     return _advancedStyleClient.styleParent;
@@ -142,7 +162,9 @@ public function set styleName(value:Object):void
 
 public function styleChanged(styleProp:String):void
 {
+    _advancedStyleClient.addEventListener(styleProp + "Changed", dispatchIfListenersExist);
     _styleChanged(styleProp);
+    _advancedStyleClient.removeEventListener(styleProp + "Changed", dispatchIfListenersExist);
 }
 
 public function get styleManager():IStyleManager2

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/d22d6872/frameworks/projects/spark/src/spark/collections/AdvancedStyleClient_.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/spark/src/spark/collections/AdvancedStyleClient_.as b/frameworks/projects/spark/src/spark/collections/AdvancedStyleClient_.as
new file mode 100644
index 0000000..1dc8959
--- /dev/null
+++ b/frameworks/projects/spark/src/spark/collections/AdvancedStyleClient_.as
@@ -0,0 +1,107 @@
+package spark.collections {
+    import mx.core.FlexGlobals;
+    import mx.core.UIComponent;
+    import mx.styles.AdvancedStyleClient;
+    import mx.styles.IAdvancedStyleClient;
+    import mx.styles.StyleProtoChain;
+    import mx.utils.NameUtil;
+
+    public class AdvancedStyleClient_ extends AdvancedStyleClient {
+        private var _styleClient:IAdvancedStyleClient;
+
+        public function AdvancedStyleClient_(styleClient:IAdvancedStyleClient)
+        {
+            super();
+            _styleClient = styleClient;
+        }
+
+        override public function initialized(document:Object, id:String):void
+        {
+            var uiComponent:UIComponent = document as UIComponent;
+
+            if (uiComponent == null)
+                uiComponent = FlexGlobals.topLevelApplication as UIComponent;
+
+            this.id = id;
+
+            this.moduleFactory = uiComponent.moduleFactory;
+
+            uiComponent.addStyleClient(_styleClient);
+        }
+
+        override protected function setDeferredStyles():void
+        {
+            if (!deferredSetStyles)
+                return;
+
+            for (var styleProp:String in deferredSetStyles)
+            {
+                StyleProtoChain.setStyle(_styleClient, styleProp, deferredSetStyles[styleProp]);
+            }
+
+            deferredSetStyles = null;
+        }
+
+        override public function setStyle(styleProp:String, newValue:*):void
+        {
+            _styleClient.setStyle(styleProp, newValue);
+        }
+
+        public function setStyleImpl(styleProp:String, newValue:*):void
+        {
+            // If there is no module factory then defer the set
+            // style until a module factory is set.
+            if (moduleFactory)
+            {
+                StyleProtoChain.setStyle(_styleClient, styleProp, newValue);
+            }
+            else
+            {
+                if (!deferredSetStyles)
+                    deferredSetStyles = {};
+
+                deferredSetStyles[styleProp] = newValue;
+            }
+        }
+
+        override public function getStyle(styleProp:String):*
+        {
+            return _styleClient.getStyle(styleProp);
+        }
+
+        public function getStyleImpl(styleProp:String):*
+        {
+            return super.getStyle(styleProp);
+        }
+
+        override public function matchesCSSType(cssType:String):Boolean
+        {
+            return StyleProtoChain.matchesCSSType(_styleClient, cssType);
+        }
+
+        override public function get className():String
+        {
+            return NameUtil.getUnqualifiedClassName(_styleClient);
+        }
+
+        override public function getClassStyleDeclarations():Array
+        {
+            return StyleProtoChain.getClassStyleDeclarations(_styleClient);
+        }
+
+        override public function regenerateStyleCache(recursive:Boolean):void
+        {
+            StyleProtoChain.initProtoChain(_styleClient);
+        }
+
+        override public function styleChanged(styleProp:String):void
+        {
+            _styleClient.styleChanged(styleProp);
+        }
+
+        public function styleChangedImpl(styleProp:String):void
+        {
+            super.styleChanged(styleProp);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/d22d6872/frameworks/projects/spark/src/spark/collections/Sort.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/spark/src/spark/collections/Sort.as b/frameworks/projects/spark/src/spark/collections/Sort.as
index d581c9a..0f31834 100644
--- a/frameworks/projects/spark/src/spark/collections/Sort.as
+++ b/frameworks/projects/spark/src/spark/collections/Sort.as
@@ -21,15 +21,11 @@ package spark.collections
 {
 
     import flash.events.Event;
-
-    import mx.core.IFlexModule;
-    import mx.core.IMXMLObject;
-
-    import mx.core.mx_internal;
     import mx.styles.IAdvancedStyleClient;
     import mx.collections.ISortField;
-    import mx.collections.errors.SortError;
     import mx.core.FlexGlobals;
+    import mx.core.IFlexModule;
+    import mx.core.IMXMLObject;
 
     [DefaultProperty("fields")]
 [ResourceBundle("collections")]
@@ -260,6 +256,8 @@ public class Sort extends mx.collections.Sort implements IAdvancedStyleClient,
I
     {
         super(fields, customCompareFunction, unique);
         mx_internal::useSortOn = false;
+
+        initAdvancedStyleClient();
     }
 
     //--------------------------------------------------------------------------
@@ -297,7 +295,7 @@ public class Sort extends mx.collections.Sort implements IAdvancedStyleClient,
I
     private function _getStyle(styleProp:String):*
     {
         if (styleProp != "locale")
-            return _advancedStyleClient.getStyle(styleProp);
+            return _advancedStyleClient.getStyleImpl(styleProp);
 
         if ((localeStyle !== undefined) && (localeStyle !== null))
             return localeStyle;
@@ -324,7 +322,7 @@ public class Sort extends mx.collections.Sort implements IAdvancedStyleClient,
I
      */
     private function _setStyle(styleProp:String, newValue:*):void
     {
-        _advancedStyleClient.setStyle(styleProp, newValue);
+        _advancedStyleClient.setStyleImpl(styleProp, newValue);
 
         if (styleProp != "locale")
             return;
@@ -355,7 +353,7 @@ public class Sort extends mx.collections.Sort implements IAdvancedStyleClient,
I
     private function _styleChanged(styleProp:String):void
     {
         localeChanged();
-        _advancedStyleClient.styleChanged(styleProp);
+        _advancedStyleClient.styleChangedImpl(styleProp);
     }
 
     //--------------------------------------------------------------------------
@@ -417,7 +415,7 @@ public class Sort extends mx.collections.Sort implements IAdvancedStyleClient,
I
      */
     private function localeChanged():void
     {
-        const newLocaleStyle:* = _advancedStyleClient.getStyle("locale");
+        const newLocaleStyle:* = _advancedStyleClient.getStyleImpl("locale");
 
         if (localeStyle === newLocaleStyle)
             return;

http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/d22d6872/frameworks/projects/spark/src/spark/collections/SortField.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/spark/src/spark/collections/SortField.as b/frameworks/projects/spark/src/spark/collections/SortField.as
index 814bf34..760b725 100644
--- a/frameworks/projects/spark/src/spark/collections/SortField.as
+++ b/frameworks/projects/spark/src/spark/collections/SortField.as
@@ -193,6 +193,8 @@ public class SortField extends mx.collections.SortField implements IAdvancedStyl
                               customCompareFunction:Function = null)
     {
         super(name, false, descending, numeric, sortCompareType, customCompareFunction);
+
+        initAdvancedStyleClient();
     }
 	
     //--------------------------------------------------------------------------
@@ -285,7 +287,7 @@ public class SortField extends mx.collections.SortField implements IAdvancedStyl
     private function _getStyle(styleProp:String):*
     {
         if (styleProp != "locale")
-            return _advancedStyleClient.getStyle(styleProp);
+            return _advancedStyleClient.getStyleImpl(styleProp);
 
         if ((localeStyle !== undefined) && (localeStyle !== null))
             return localeStyle;
@@ -314,7 +316,7 @@ public class SortField extends mx.collections.SortField implements IAdvancedStyl
      */
     private function _setStyle(styleProp:String, newValue:*):void
     {
-        _advancedStyleClient.setStyle(styleProp, newValue);
+        _advancedStyleClient.setStyleImpl(styleProp, newValue);
 
         if (styleProp != "locale")
             return;
@@ -347,7 +349,8 @@ public class SortField extends mx.collections.SortField implements IAdvancedStyl
     private function _styleChanged(styleProp:String):void
     {
         localeChanged();
-        _advancedStyleClient.styleChanged(styleProp);
+
+        _advancedStyleClient.styleChangedImpl(styleProp);
     }
 
 
@@ -482,7 +485,7 @@ public class SortField extends mx.collections.SortField implements IAdvancedStyl
      */
     private function localeChanged():void
     {
-        const newLocaleStyle:* = _advancedStyleClient.getStyle("locale");
+        const newLocaleStyle:* = _advancedStyleClient.getStyleImpl("locale");
 
         if (localeStyle === newLocaleStyle)
             return;


Mime
View raw message