royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yish...@apache.org
Subject [royale-asjs] 01/04: Adding HideComboPopupOnMouseDownBead
Date Tue, 22 May 2018 08:37:02 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 6932fbfc6558b9a3ce0d4cc815b55be922af61a5
Author: DESKTOP-RH4S838\Yishay <yishayjobs@hotmail.com>
AuthorDate: Thu May 17 10:43:25 2018 +0300

    Adding HideComboPopupOnMouseDownBead
---
 .../Basic/src/main/resources/basic-manifest.xml    |   1 +
 .../html/beads/HideComboPopupOnMouseDownBead.as    | 111 +++++++++++++++++++++
 2 files changed, 112 insertions(+)

diff --git a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
index 65ded61..700f8b1 100644
--- a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
+++ b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
@@ -88,6 +88,7 @@
     <component id="AccordionView" class="org.apache.royale.html.beads.AccordionView"/>
     <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="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/HideComboPopupOnMouseDownBead.as
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/HideComboPopupOnMouseDownBead.as
new file mode 100644
index 0000000..ba48f52
--- /dev/null
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/HideComboPopupOnMouseDownBead.as
@@ -0,0 +1,111 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.utils.callLater;
+	import org.apache.royale.utils.loadBeadFromValuesManager;
+	import org.apache.royale.core.IBeadController;
+    import org.apache.royale.core.IBead;
+	import org.apache.royale.core.IComboBoxModel;
+	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.MouseEvent;
+	import org.apache.royale.html.TextInput;
+	import org.apache.royale.html.List;
+	import org.apache.royale.html.beads.IComboBoxView;
+	
+	/**
+	 *  The HideComboPopupOnMouseDownBead can be used with ComboBox to make sure mouse down
events
+	 *  close an open popup. For this bead to work the application needs to be sized to the
+	 *  window size. See org.apache.royale.core.BrowserResizeListener for a way to achieve this.
+	 *  
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion Royale 9.3
+	 */
+	public class HideComboPopupOnMouseDownBead implements IBead
+	{
+		public function HideComboPopupOnMouseDownBead()
+		{
+		}
+		
+		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.0
+		 *  @royaleignorecoercion HTMLInputElement
+		 *  @royaleignorecoercion org.apache.royale.core.UIBase;
+		 */
+		public function set strand(value:IStrand):void
+		{
+			_strand = value;
+			viewBead = _strand.getBeadByType(IComboBoxView) as IComboBoxView;
+			if (viewBead) {
+				finishSetup(null);
+			} else {
+				IEventDispatcher(_strand).addEventListener("viewChanged", finishSetup);
+			}
+		}
+		
+		protected function finishSetup(event:Event):void
+		{
+			if (viewBead == null) {
+				viewBead = loadBeadFromValuesManager(IComboBoxView, "iBeadView", _strand) as IComboBoxView;
+			}
+			IEventDispatcher(viewBead.popUp).addEventListener("show", handlePopupShow);
+			IEventDispatcher(viewBead.popUp).addEventListener("hide", handlePopupHide);
+		}
+		
+		protected function handleControlMouseDown(event:MouseEvent):void
+		{			
+			event.stopImmediatePropagation();
+		}
+		
+		protected function handlePopupShow(event:Event):void
+		{
+			IEventDispatcher(viewBead.popUp).addEventListener(MouseEvent.MOUSE_DOWN, handleControlMouseDown);
+			IEventDispatcher(_strand).addEventListener(MouseEvent.MOUSE_DOWN, handleControlMouseDown);
+			callLater(function():void {
+				IUIBase(viewBead.popUp).topMostEventDispatcher.addEventListener(MouseEvent.MOUSE_DOWN,
handleTopMostEventDispatcherMouseDown);
+			});
+		}
+		
+		protected function handleTopMostEventDispatcherMouseDown(event:MouseEvent):void
+		{
+			viewBead.popUpVisible = false;
+		}
+		
+		protected function handlePopupHide(event:Event):void
+		{
+			IEventDispatcher(viewBead.popUp).removeEventListener(MouseEvent.MOUSE_DOWN, handleControlMouseDown);
+			IEventDispatcher(_strand).removeEventListener(MouseEvent.MOUSE_DOWN, handleControlMouseDown);
+			IUIBase(viewBead.popUp).topMostEventDispatcher.removeEventListener(MouseEvent.MOUSE_DOWN,
handleTopMostEventDispatcherMouseDown);
+		}
+	}
+}

-- 
To stop receiving notification emails like this one, please contact
yishayw@apache.org.

Mime
View raw message