From dc106eff3495f310f4f92c322aaa9c546737bd07 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Tue, 28 Nov 2017 13:11:17 +1100 Subject: [PATCH 1/2] Add FocusBead and focus bead interface --- .../Basic/src/main/royale/BasicClasses.as | 4 + .../org/apache/royale/html/beads/FocusBead.as | 103 ++++++++++++++++++ .../apache/royale/html/beads/IFocusBead.as | 37 +++++++ 3 files changed, 144 insertions(+) create mode 100644 frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/FocusBead.as create mode 100644 frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/IFocusBead.as diff --git a/frameworks/projects/Basic/src/main/royale/BasicClasses.as b/frameworks/projects/Basic/src/main/royale/BasicClasses.as index b67b03aea2..f04298a2ca 100644 --- a/frameworks/projects/Basic/src/main/royale/BasicClasses.as +++ b/frameworks/projects/Basic/src/main/royale/BasicClasses.as @@ -252,6 +252,10 @@ internal class BasicClasses import org.apache.royale.css2.DragMove; DragMove; import org.apache.royale.css2.DragReject; DragReject; } + + import org.apache.royale.html.beads.IFocusBead; IFocusBead; + import org.apache.royale.html.beads.FocusBead; FocusBead; + } } diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/FocusBead.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/FocusBead.as new file mode 100644 index 0000000000..3090ffec34 --- /dev/null +++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/FocusBead.as @@ -0,0 +1,103 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.IUIBase; + import org.apache.royale.core.IStrand; + + /** + * The FocusBead class allows teh focus to be changed on a component. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.9 + */ + public class FocusBead implements IFocusBead + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.9 + */ + public function FocusBead() + { + } + + private var _strand:IStrand; + + /** + * @copy org.apache.royale.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.9 + */ + public function set strand(value:IStrand):void + { + _strand = value; + } + + /** + * Set the focus on the component. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.9 + */ + public function focus():void + { + COMPILE::JS { + host.element.focus(); + } + COMPILE::SWF { + host["stage"].focus = host; + } + } + + /** + * Remove the focus on the component. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.9 + */ + public function blur():void + { + COMPILE::JS { + host.element.blur(); + } + COMPILE::SWF { + host["stage"].focus = null; + } + } + + private function get host():IUIBase + { + return _strand as IUIBase; + } + + } +} diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/IFocusBead.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/IFocusBead.as new file mode 100644 index 0000000000..44a9c1159a --- /dev/null +++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/IFocusBead.as @@ -0,0 +1,37 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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; + + /** + * The IFocusBead interface marks a component as being a bead that + * can set and unset / blur the focus. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.9 + */ + public interface IFocusBead extends IBead + { + function focus():void; + function blur():void; + } +} From c0d608c951d1631dd15c721b2a3bf238d85a01a6 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Tue, 28 Nov 2017 13:12:37 +1100 Subject: [PATCH 2/2] Add focus and blur methods to express TextButton using a FocusBead --- .../org/apache/royale/express/TextButton.as | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/frameworks/projects/Express/src/main/royale/org/apache/royale/express/TextButton.as b/frameworks/projects/Express/src/main/royale/org/apache/royale/express/TextButton.as index b8b673818b..bb11c84c25 100644 --- a/frameworks/projects/Express/src/main/royale/org/apache/royale/express/TextButton.as +++ b/frameworks/projects/Express/src/main/royale/org/apache/royale/express/TextButton.as @@ -21,6 +21,8 @@ package org.apache.royale.express import org.apache.royale.events.Event; import org.apache.royale.html.TextButton; import org.apache.royale.html.beads.DisableBead; + import org.apache.royale.html.beads.IFocusBead; + import org.apache.royale.html.beads.FocusBead; import org.apache.royale.html.accessories.ToolTipBead; /** @@ -30,7 +32,7 @@ package org.apache.royale.express * @flexcomponent spark.components.Button * @flexdocurl https://flex.apache.org/asdoc/spark/components/Button.html * @commentary The Royale Express TextButton is pre-packaged with beads to do: - * @commentary See also the Royale Express ImageButton and the Royale Express ImageAndTextButton. + * @commentary See also the Royale Express ImageButton and the Royale Express ImageAndTextButton. */ public class TextButton extends org.apache.royale.html.TextButton { @@ -118,5 +120,35 @@ package org.apache.royale.express dispatchEvent(new Event("toolTipChanged")); } + + /** + * Return the focus bead and create it if needed + */ + protected function get focusBead():IFocusBead + { + var focusBead:IFocusBead = getBeadByType(IFocusBead) as IFocusBead; + + if (focusBead == null) { + focusBead = new FocusBead(); + addBead(focusBead); + } + + return focusBead; + } + /** + * Give the button focus + */ + public function focus():void + { + focusBead.focus(); + } + + /** + * Remove focus from the button + */ + public function blur():void + { + focusBead.focus(); + } } }