Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add focus bead for TextButton #94

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frameworks/projects/Basic/src/main/royale/BasicClasses.as
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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 <ul><li>enabled: Boolean</li><li>toolTip: String</li><li>secure: Boolean</li></ul>See also the Royale Express ImageButton and the Royale Express ImageAndTextButton.
* @commentary <ul><li>enabled: Boolean</li><li>toolTip: String</li><li>secure: Boolean</li><li>focus</li></ul>See also the Royale Express ImageButton and the Royale Express ImageAndTextButton.
*/
public class TextButton extends org.apache.royale.html.TextButton
{
Expand Down Expand Up @@ -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();
}
}
}