Repository: flex-asjs
Updated Branches:
  refs/heads/develop b77371d86 -> dd0de0427


Containers now monitor changes to the size of their children.


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

Branch: refs/heads/develop
Commit: dd0de04277322053aa595a2bd19a9b0dcf0e8ab3
Parents: b77371d
Author: Peter Ent <p...@apache.org>
Authored: Thu Jun 25 11:24:09 2015 -0400
Committer: Peter Ent <p...@apache.org>
Committed: Thu Jun 25 11:24:09 2015 -0400

----------------------------------------------------------------------
 .../org/apache/flex/html/beads/ContainerView.as | 58 +++++++++++++++++---
 .../flex/html/beads/layouts/HorizontalLayout.as |  4 +-
 .../flex/html/beads/layouts/VerticalLayout.as   |  4 +-
 3 files changed, 53 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/dd0de042/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/ContainerView.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/ContainerView.as 
b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/ContainerView.as
index b02d904..27cac85 100644
--- 
a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/ContainerView.as
+++ 
b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/ContainerView.as
@@ -119,6 +119,7 @@ package org.apache.flex.html.beads
                                displayBackgroundAndBorder(host);
                        }
                        
+                       host.addEventListener("childrenAdded", 
childrenChangedHandler);
                        host.addEventListener("childrenAdded", changeHandler);
                        host.addEventListener("layoutNeeded", changeHandler);
                        host.addEventListener("widthChanged", resizeHandler);
@@ -176,6 +177,54 @@ package org.apache.flex.html.beads
                        }
                }
                
+               /**
+                * Whenever children are added, listeners are added to detect 
changes
+                * in their size. 
+                *  
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion FlexJS 0.0
+                */
+               protected function childrenChangedHandler(event:Event):void
+               {
+                       var host:UIBase = _strand as UIBase;
+                       var n:Number = actualParent.numElements;
+                       for (var i:int=0; i < n; i++) {
+                               var child:IUIBase = 
actualParent.getElementAt(i) as IUIBase;
+                               if (host.isWidthSizedToContent()) {
+                                       
child.addEventListener("widthChanged",childResizeHandler);
+                               }
+                               if (host.isHeightSizedToContent()) {
+                                       
child.addEventListener("heightChanged",childResizeHandler);
+                               }
+                       }
+               }
+               
+               private var resizingChildren:Boolean = false;
+               
+               /**
+                * This event handles changes to the size of children of the 
container by running
+                * the layout again and adjusting the size of the container or 
viewport as necessary. 
+                *  
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion FlexJS 0.0
+                */
+               protected function childResizeHandler(event:Event):void
+               {
+                       // during this process we don't want the layout to 
trigger
+                       // an endless event chain should any children get 
resized
+                       // by the layout.
+                       if (resizingChildren) return;
+                       resizingChildren = true;
+                       
+                       var child:UIBase = event.target as UIBase;
+                       changeHandler(event);
+                       resizingChildren = false;
+               }
+               
                                
                /**
                 * Event handler invoked whenever the size or children are 
added/removed
@@ -209,16 +258,7 @@ package org.apache.flex.html.beads
                        // model's content size properties. 
                        if (viewport.runLayout()) 
                        {
-                               // remove size change handlers so that any size 
changes internally
-                               // are not picked up and processed which could 
result in an infinite
-                               // chain of events.
-//                             host.removeEventListener("widthChanged", 
resizeHandler);
-//                             host.removeEventListener("heightChanged", 
resizeHandler);
-                               
                                handleContentResize();
-                               
-//                             host.addEventListener("widthChanged", 
resizeHandler);
-//                             host.addEventListener("heightChanged", 
resizeHandler);
                        }                       
                        
                        // update the contentArea so that it exposes all of the 
items as placed

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/dd0de042/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/layouts/HorizontalLayout.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/layouts/HorizontalLayout.as
 
b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/layouts/HorizontalLayout.as
index 2f02262..6a5922c 100644
--- 
a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/layouts/HorizontalLayout.as
+++ 
b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/layouts/HorizontalLayout.as
@@ -263,11 +263,11 @@ package org.apache.flex.html.beads.layouts
                        // size is stored in the model.
                        var sizeChanged:Boolean = false;
                        if (viewportModel != null) {
-                               if (viewportModel.contentHeight < maxHeight) {
+                               if (viewportModel.contentHeight != maxHeight) {
                                        viewportModel.contentHeight = maxHeight;
                                        sizeChanged = true;
                                }
-                               if (viewportModel.contentWidth < xx) {
+                               if (viewportModel.contentWidth != xx) {
                                        viewportModel.contentWidth = xx;
                                        sizeChanged = true;
                                }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/dd0de042/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/layouts/VerticalLayout.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/layouts/VerticalLayout.as
 
b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/layouts/VerticalLayout.as
index 97eda29..623bffa 100644
--- 
a/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/layouts/VerticalLayout.as
+++ 
b/frameworks/projects/HTML/as/src/org/apache/flex/html/beads/layouts/VerticalLayout.as
@@ -266,11 +266,11 @@ package org.apache.flex.html.beads.layouts
                        // size is stored in the model.
                        var sizeChanged:Boolean = false;
                        if (viewportModel != null) {
-                               if (viewportModel.contentHeight < yy) {
+                               if (viewportModel.contentHeight != yy) {
                                        viewportModel.contentHeight = yy;
                                        sizeChanged = true;
                                }
-                               if (viewportModel.contentWidth < maxWidth) {
+                               if (viewportModel.contentWidth != maxWidth) {
                                        viewportModel.contentWidth = maxWidth;
                                        sizeChanged = true;
                                }

Reply via email to