You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by yi...@apache.org on 2019/05/26 09:14:42 UTC

[royale-asjs] branch develop updated: Add bead to keep combo popup within browser viewport

This is an automated email from the ASF dual-hosted git repository.

yishayw pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new 61028dc  Add bead to keep combo popup within browser viewport
     new 06d7815  Merge branch 'develop' of https://github.com/apache/royale-asjs into develop
61028dc is described below

commit 61028dca2cae446b903188a35a159bea880bbfcc
Author: DESKTOP-RH4S838\Yishay <yi...@hotmail.com>
AuthorDate: Sun May 26 12:13:32 2019 +0300

    Add bead to keep combo popup within browser viewport
---
 .../Basic/src/main/resources/basic-manifest.xml    |   1 +
 .../html/beads/KeepComboPopupWithinParentBounds.as | 114 +++++++++++++++++++++
 2 files changed, 115 insertions(+)

diff --git a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
index 2f7e83e..a2239a7 100644
--- a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
+++ b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
@@ -109,6 +109,7 @@
     <component id="CenterElement" class="org.apache.royale.html.beads.CenterElement"/>
     <component id="StyleInheritanceBead" class="org.apache.royale.html.beads.StyleInheritanceBead"/>
     <component id="HideComboPopupOnMouseDownBead" class="org.apache.royale.html.beads.HideComboPopupOnMouseDownBead"/>
+    <component id="KeepComboPopupWithinParentBounds" class="org.apache.royale.html.beads.KeepComboPopupWithinParentBounds"/>
     <component id="StyleInheritanceWithObserverBead" class="org.apache.royale.html.beads.StyleInheritanceWithObserverBead"/>
     <component id="CrossBrowserFireListenerOverrideBead" class="org.apache.royale.html.beads.CrossBrowserFireListenerOverrideBead" />
     <component id="AccessibilityAltBead" class="org.apache.royale.html.beads.AccessibilityAltBead" />
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/KeepComboPopupWithinParentBounds.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/KeepComboPopupWithinParentBounds.as
new file mode 100644
index 0000000..63bd399
--- /dev/null
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/KeepComboPopupWithinParentBounds.as
@@ -0,0 +1,114 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.royale.html.beads
+{
+	import org.apache.royale.core.IBead;
+	import org.apache.royale.core.IPopUpHost;
+	import org.apache.royale.core.IStrand;
+	import org.apache.royale.core.IUIBase;
+	import org.apache.royale.events.Event;
+	import org.apache.royale.events.IEventDispatcher;
+	import org.apache.royale.events.ValueEvent;
+	import org.apache.royale.geom.Point;
+	import org.apache.royale.utils.PointUtils;
+	import org.apache.royale.utils.UIUtils;
+	import org.apache.royale.utils.loadBeadFromValuesManager;
+	
+	/**
+	 *  The KeepComboPopupWithinParentBounds can be used with ComboBox to make sure its popup does not
+	 *  overflow its parent bounds.
+	 *  
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion Royale 9.6
+	 */
+	public class KeepComboPopupWithinParentBounds implements IBead
+	{
+		public function KeepComboPopupWithinParentBounds()
+		{
+		}
+		
+		private var _strand:IStrand;
+		
+		protected var viewBead:IComboBoxView;
+		
+		/**
+		 *  @copy org.apache.royale.core.IBead#strand
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.6
+		 *  @royaleignorecoercion HTMLInputElement
+		 *  @royaleignorecoercion org.apache.royale.core.UIBase;
+		 */
+		public function set strand(value:IStrand):void
+		{
+			_strand = value;
+			viewBead = _strand.getBeadByType(IComboBoxView) as IComboBoxView;
+			var popupHost:IPopUpHost = UIUtils.findPopUpHost(_strand as IUIBase);
+			(popupHost.popUpParent as IEventDispatcher).addEventListener("childrenAdded", childrenAddedHandler);
+		}
+		
+		private function childrenAddedHandler(event:ValueEvent):void
+		{
+			if (viewBead == null) {
+				viewBead = loadBeadFromValuesManager(IComboBoxView, "iBeadView", _strand) as IComboBoxView;
+			}
+			if (event.value == viewBead.popUp)
+			{
+				movePopUp();
+			}
+		}
+
+		protected function movePopUp():void
+		{
+			var popup:IUIBase = viewBead.popUp as IUIBase;
+			var button:IUIBase = viewBead.popupButton as IUIBase;
+			var popupParent:IUIBase = popup.parent as IUIBase;
+			// fix bottom right corner
+			var innerWidth:Number;
+			var innerHeight:Number;
+			COMPILE::JS
+			{
+				innerWidth = window.innerWidth;
+				innerHeight = window.innerHeight;
+			}
+			var isRightOutOfBounds:Boolean = popup.x + popup.width > popupParent.width;
+			var isBottomOutOfBounds:Boolean = popup.y + popup.height > popupParent.height;
+			if (!isBottomOutOfBounds && !isRightOutOfBounds)
+			{
+				return;
+			}
+			var origin:Point = new Point(0, button.y);
+			var relocated:Point = PointUtils.localToGlobal(origin,_strand);
+			if (isRightOutOfBounds)
+			{
+				popup.x = relocated.x - popup.width;
+			}
+			if (isBottomOutOfBounds)
+			{
+				popup.y = relocated.y - popup.height;
+			}
+			// currently, the default is to go down and rignt so the above should be enough
+			// when that changes we can modify or extends this bead
+		}
+	}
+}