flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [3/3] git commit: [flex-asjs] [refs/heads/develop] - implement browser resize handling and application minWidth/minHeight
Date Tue, 15 Sep 2015 06:37:02 GMT
implement browser resize handling and application minWidth/minHeight


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

Branch: refs/heads/develop
Commit: 1a580f49a3f37632a4e7bddc74364a04de1dba59
Parents: 7d03090
Author: Alex Harui <aharui@apache.org>
Authored: Mon Sep 14 23:37:33 2015 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Mon Sep 14 23:37:33 2015 -0700

----------------------------------------------------------------------
 .../as/src/org/apache/flex/core/Application.as  |  19 +++-
 .../apache/flex/core/BrowserResizeListener.as   | 110 +++++++++++++++++++
 .../src/org/apache/flex/core/BrowserScroller.as |   1 -
 frameworks/projects/Core/basic-manifest.xml     |   1 +
 .../js/src/org/apache/flex/core/Application.js  |   3 +-
 .../apache/flex/core/BrowserResizeListener.js   |  78 +++++++++++++
 6 files changed, 204 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1a580f49/frameworks/projects/Core/as/src/org/apache/flex/core/Application.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/as/src/org/apache/flex/core/Application.as b/frameworks/projects/Core/as/src/org/apache/flex/core/Application.as
index 0d933b6..fbcf83b 100644
--- a/frameworks/projects/Core/as/src/org/apache/flex/core/Application.as
+++ b/frameworks/projects/Core/as/src/org/apache/flex/core/Application.as
@@ -183,12 +183,19 @@ package org.apache.flex.core
             {
                 initialView.applicationModel =  model;
         	    this.addElement(initialView);
-                if (!isNaN(initialView.percentWidth) && !isNaN(initialView.percentHeight))
-                    initialView.setWidthAndHeight(stage.stageWidth, stage.stageHeight, true);
-                else if (!isNaN(initialView.percentWidth))
-                    initialView.setWidth(stage.stageWidth);
-                else if (!isNaN(initialView.percentHeight))
-                    initialView.setHeight(stage.stageHeight);
+                // if someone has installed a resize listener, fake an event to run it now
+                if (stage.hasEventListener("resize"))
+                    stage.dispatchEvent(new flash.events.Event("resize"));
+                else
+                {
+                    // otherwise, size once like this
+                    if (!isNaN(initialView.percentWidth) && !isNaN(initialView.percentHeight))
+                        initialView.setWidthAndHeight(stage.stageWidth, stage.stageHeight,
true);
+                    else if (!isNaN(initialView.percentWidth))
+                        initialView.setWidth(stage.stageWidth);
+                    else if (!isNaN(initialView.percentHeight))
+                        initialView.setHeight(stage.stageHeight);
+                }
                 var bgColor:Object = ValuesManager.valuesImpl.getValue(this, "background-color");
                 if (bgColor != null)
                 {

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1a580f49/frameworks/projects/Core/as/src/org/apache/flex/core/BrowserResizeListener.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/as/src/org/apache/flex/core/BrowserResizeListener.as
b/frameworks/projects/Core/as/src/org/apache/flex/core/BrowserResizeListener.as
new file mode 100644
index 0000000..21544ca
--- /dev/null
+++ b/frameworks/projects/Core/as/src/org/apache/flex/core/BrowserResizeListener.as
@@ -0,0 +1,110 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.core
+{
+    import flash.events.Event;
+    import flash.external.ExternalInterface;
+    import flash.utils.getQualifiedClassName;
+    
+    /**
+     *  The BrowserResizeListener class listens for browser
+     *  resizing and resizes the application accordingly.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+	public class BrowserResizeListener implements IBead
+	{
+        /**
+         *  Constructor.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+		public function BrowserResizeListener()
+		{
+		}
+		
+        private var app:Application;
+        
+        /**
+         *  Minimum height
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public var minHeight:Number;
+        
+        /**
+         *  Minimum width
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public var minWidth:Number;
+        
+        /**
+         *  @copy org.apache.flex.core.IBead#strand
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public function set strand(value:IStrand):void
+        {
+            app = value as Application;
+            app.stage.addEventListener("resize", resizeHandler);
+            if (ExternalInterface.available && (!isNaN(minWidth) || !isNaN(minHeight)))
+            {
+                // Get application name.  This assumes that the wrapper is using an
+                // object tag with the id that matches the application name
+                var appName:String = getQualifiedClassName(app);
+                var js:String = "var o = document.getElementById('" + appName + "');";
+                if (!isNaN(minWidth))
+                    js += "o.style.minWidth = '" + minWidth.toString() + "px';";
+                if (!isNaN(minHeight))
+                    js += "o.style.minHeight = '" + minHeight.toString() + "px';"
+                ExternalInterface.call("eval", js); 
+            }
+        }
+        
+        private function resizeHandler(event:Event):void
+        {
+            var initialView:UIBase = app.initialView;
+            if (!isNaN(initialView.percentWidth) && !isNaN(initialView.percentHeight))
+                initialView.setWidthAndHeight(Math.max(minWidth, app.stage.stageWidth), 
+                    Math.max(minHeight, app.stage.stageHeight), true);
+            else if (!isNaN(initialView.percentWidth))
+                initialView.setWidth(Math.max(minWidth, app.stage.stageWidth));
+            else if (!isNaN(initialView.percentHeight))
+                initialView.setHeight(Math.max(minHeight, app.stage.stageHeight));
+            
+        }
+
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1a580f49/frameworks/projects/Core/as/src/org/apache/flex/core/BrowserScroller.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/as/src/org/apache/flex/core/BrowserScroller.as b/frameworks/projects/Core/as/src/org/apache/flex/core/BrowserScroller.as
index 355453a..544c056 100644
--- a/frameworks/projects/Core/as/src/org/apache/flex/core/BrowserScroller.as
+++ b/frameworks/projects/Core/as/src/org/apache/flex/core/BrowserScroller.as
@@ -64,7 +64,6 @@ package org.apache.flex.core
         
         private function viewChangedHandler(event:Event):void
         {
-            // some day also listen to initial view for size changes
             if (ExternalInterface.available)
             {
                 // Get application name.  This assumes that the wrapper is using an

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1a580f49/frameworks/projects/Core/basic-manifest.xml
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/basic-manifest.xml b/frameworks/projects/Core/basic-manifest.xml
index 65f0db8..97a664b 100644
--- a/frameworks/projects/Core/basic-manifest.xml
+++ b/frameworks/projects/Core/basic-manifest.xml
@@ -23,6 +23,7 @@
 
     <component id="Application" class="org.apache.flex.core.Application"/>
     <component id="BrowserScroller" class="org.apache.flex.core.BrowserScroller"/>
+    <component id="BrowserResizeHandler" class="org.apache.flex.core.BrowserResizeListener"/>
     <component id="SimpleValuesImpl" class="org.apache.flex.core.SimpleValuesImpl"/>
     <component id="SimpleCSSValuesImpl" class="org.apache.flex.core.SimpleCSSValuesImpl"/>
     <component id="ViewBase" class="org.apache.flex.core.ViewBase"/>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1a580f49/frameworks/projects/Core/js/src/org/apache/flex/core/Application.js
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/js/src/org/apache/flex/core/Application.js b/frameworks/projects/Core/js/src/org/apache/flex/core/Application.js
index 8ac8d91..2887da2 100644
--- a/frameworks/projects/Core/js/src/org/apache/flex/core/Application.js
+++ b/frameworks/projects/Core/js/src/org/apache/flex/core/Application.js
@@ -72,7 +72,8 @@ org.apache.flex.core.Application.prototype.start = function() {
   this.element = document.getElementsByTagName('body')[0];
   this.element.flexjs_wrapper = this;
   this.element.className = 'Application';
-  this.element.style.overflow = 'hidden';
+  if (!this.element.style.overflow)
+    this.element.style.overflow = 'hidden';
 
   org.apache.flex.utils.MXMLDataInterpreter.generateMXMLInstances(this, null, this.MXMLDescriptor);
 

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1a580f49/frameworks/projects/Core/js/src/org/apache/flex/core/BrowserResizeListener.js
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/js/src/org/apache/flex/core/BrowserResizeListener.js
b/frameworks/projects/Core/js/src/org/apache/flex/core/BrowserResizeListener.js
new file mode 100644
index 0000000..1e16897
--- /dev/null
+++ b/frameworks/projects/Core/js/src/org/apache/flex/core/BrowserResizeListener.js
@@ -0,0 +1,78 @@
+/**
+ * Licensed 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.
+ */
+
+goog.provide('org.apache.flex.core.BrowserResizeListener');
+
+
+
+/**
+ * @constructor
+ */
+org.apache.flex.core.BrowserResizeListener = function() {
+  this.strand_ = null;
+};
+
+
+/**
+ * Metadata
+ *
+ * @type {Object.<string, Array.<Object>>}
+ */
+org.apache.flex.core.BrowserResizeListener.prototype.FLEXJS_CLASS_INFO =
+    { names: [{ name: 'BrowserResizeListener',
+                qName: 'org.apache.flex.core.BrowserResizeListener'}]};
+
+
+/**
+ * @type {number}
+ */
+org.apache.flex.core.BrowserResizeListener.prototype.minHeight = NaN;
+
+
+/**
+ * @type {number}
+ */
+org.apache.flex.core.BrowserResizeListener.prototype.minWidth = NaN;
+
+
+/**
+ * @param {Event} e The event.
+ */
+org.apache.flex.core.BrowserResizeListener.prototype.resizeHandler = function(e) {
+  var initialView = this.strand_.initialView;
+  var element = this.strand_.element;
+  if (!isNaN(initialView.percentWidth) || !isNaN(initialView.percentHeight)) {
+    element.style.height = window.innerHeight.toString() + 'px';
+    element.style.width = window.innerWidth.toString() + 'px';
+    initialView.dispatchEvent('sizeChanged'); // kick off layout if % sizes
+  }
+};
+
+
+Object.defineProperties(org.apache.flex.core.BrowserResizeListener.prototype, {
+    /** @export */
+    strand: {
+        /** @this {org.apache.flex.core.BrowserResizeListener} */
+        set: function(value) {
+            this.strand_ = value;
+            window.addEventListener('resize',
+                    goog.bind(this.resizeHandler, this));
+            if (!isNaN(this.minWidth))
+              document.body.style.minWidth = this.minWidth.toString() + 'px';
+            if (!isNaN(this.minHeight))
+              document.body.style.minHeight = this.minHeight.toString() + 'px';
+            document.body.style.overflow = 'auto';
+        }
+    }
+});


Mime
View raw message