Repository: flex-asjs Updated Branches: refs/heads/develop 9b83abe72 -> cb67c4173
Introduce DispatchKeyboardEventBead Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/cb67c417 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/cb67c417 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/cb67c417 Branch: refs/heads/develop Commit: cb67c417354b9aebe69f63ce56a6428ab78a9802 Parents: 9b83abe Author: yishayw <[email protected]> Authored: Tue Mar 14 14:50:58 2017 +0200 Committer: yishayw <[email protected]> Committed: Tue Mar 14 14:50:58 2017 +0200 ---------------------------------------------------------------------- .../projects/Core/src/main/flex/CoreClasses.as | 1 + .../org/apache/flex/events/KeyboardEvent.as | 19 ++- .../flex/events/utils/KeyboardEventConverter.as | 80 +++++++++++ .../projects/HTML/.actionScriptProperties | 1 - .../html/beads/DispatchKeyboardEventBead.as | 139 +++++++++++++++++++ .../HTML/src/main/resources/basic-manifest.xml | 1 + 6 files changed, 237 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/cb67c417/frameworks/projects/Core/src/main/flex/CoreClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/CoreClasses.as b/frameworks/projects/Core/src/main/flex/CoreClasses.as index 018a180..60bcb66 100644 --- a/frameworks/projects/Core/src/main/flex/CoreClasses.as +++ b/frameworks/projects/Core/src/main/flex/CoreClasses.as @@ -119,6 +119,7 @@ internal class CoreClasses import org.apache.flex.events.IEventDispatcher; IEventDispatcher; import org.apache.flex.events.MouseEvent; MouseEvent; import org.apache.flex.events.KeyboardEvent; KeyboardEvent; + import org.apache.flex.events.utils.KeyboardEventConverter; KeyboardEventConverter; COMPILE::SWF { import org.apache.flex.core.StageProxy; StageProxy; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/cb67c417/frameworks/projects/Core/src/main/flex/org/apache/flex/events/KeyboardEvent.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/KeyboardEvent.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/KeyboardEvent.as index c92a0b3..a304735 100644 --- a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/KeyboardEvent.as +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/KeyboardEvent.as @@ -21,8 +21,8 @@ package org.apache.flex.events public class KeyboardEvent extends Event { - public static const KEY_DOWN:String = "keyDown"; - public static const KEY_UP:String = "keyUp"; + public static const KEY_DOWN:String = "key_down"; + public static const KEY_UP:String = "key_up"; public function KeyboardEvent( type:String, @@ -101,7 +101,20 @@ package org.apache.flex.events public function get modifierKey():Boolean { - return false; + return shiftKey || ctrlKey || metaKey; } + + private var _specialKey:Boolean; + public function get specialKey():Boolean + + { + return _specialKey; + } + + public function set specialKey(value:Boolean):void + { + _specialKey = value; + } + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/cb67c417/frameworks/projects/Core/src/main/flex/org/apache/flex/events/utils/KeyboardEventConverter.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/utils/KeyboardEventConverter.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/utils/KeyboardEventConverter.as new file mode 100644 index 0000000..24aa879 --- /dev/null +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/utils/KeyboardEventConverter.as @@ -0,0 +1,80 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.events.utils +{ + import org.apache.flex.events.KeyboardEvent; + + COMPILE::SWF + { + import flash.events.KeyboardEvent; + } + + /** + * Converts low level keyboard events to FlexJS KeyboardEvents + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.8 + */ + public class KeyboardEventConverter + { + + /** + * Converts Flash keyboard events to FlexJS ones. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.8 + */ + COMPILE::SWF + public static function convert(oldEvent:flash.events.KeyboardEvent):org.apache.flex.events.KeyboardEvent + { + var code:String = KeyConverter.convertKeyCode(oldEvent.keyCode); + var key:String = KeyConverter.convertCharCode(oldEvent.charCode); + var type:String = oldEvent.type == flash.events.KeyboardEvent.KEY_DOWN ? org.apache.flex.events.KeyboardEvent.KEY_DOWN : + org.apache.flex.events.KeyboardEvent.KEY_UP; + var newEvent:org.apache.flex.events.KeyboardEvent = new org.apache.flex.events.KeyboardEvent(type, key, code); + newEvent.altKey = oldEvent.altKey; + // newEvent.ctrlKey = oldEvent.controlKey; // TODO + newEvent.specialKey = oldEvent.ctrlKey; + return newEvent; + } + + /** + * Converts JS keyboard events to FlexJS ones. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.8 + */ + COMPILE::JS + public static function convert(oldEvent:KeyboardEvent):org.apache.flex.events.KeyboardEvent + { + var type:String = oldEvent.type == "keydown" ? "key_down" : "key_up"; + var newEvent:org.apache.flex.events.KeyboardEvent = new org.apache.flex.events.KeyboardEvent(type, oldEvent.key, oldEvent.code); + newEvent.altKey = oldEvent.altKey; + // newEvent.ctrlKey = oldEvent.controlKey; // TODO + newEvent.specialKey = oldEvent.ctrlKey; + return newEvent; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/cb67c417/frameworks/projects/HTML/.actionScriptProperties ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/.actionScriptProperties b/frameworks/projects/HTML/.actionScriptProperties index e8bc3ee..f491247 100644 --- a/frameworks/projects/HTML/.actionScriptProperties +++ b/frameworks/projects/HTML/.actionScriptProperties @@ -27,7 +27,6 @@ limitations under the License. </excludedEntries> </libraryPathEntry> <libraryPathEntry kind="3" linkType="1" path="/Core/target/Core.swc" useDefaultLinkType="false"/> - <libraryPathEntry kind="3" linkType="1" path="/Graphics/target/Graphics.swc" useDefaultLinkType="false"/> <libraryPathEntry kind="3" linkType="2" path="${PROJECT_FRAMEWORKS}/libs/air/airglobal.swc" useDefaultLinkType="false"/> </libraryPath> <sourceAttachmentPath/> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/cb67c417/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DispatchKeyboardEventBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DispatchKeyboardEventBead.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DispatchKeyboardEventBead.as new file mode 100644 index 0000000..da69b05 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DispatchKeyboardEventBead.as @@ -0,0 +1,139 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.html.beads +{ + + import org.apache.flex.core.IBead; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.events.KeyboardEvent; + import org.apache.flex.events.utils.KeyboardEventConverter; + + COMPILE::JS + { + import org.apache.flex.core.IRenderedObject; + import goog.events; + } + + COMPILE::SWF + { + import flash.events.KeyboardEvent; + import org.apache.flex.html.beads.ITextFieldView; + } + + /** + * The DispatchKeyboardEventBead class dispatched INPUT_FINISHED on strand + * when enter is pressed, or when foucus is out. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class DispatchKeyboardEventBead implements IBead + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function DispatchKeyboardEventBead() + { + } + + private var _strand:IStrand; + + /** + * @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 + { + _strand = value; + + COMPILE::SWF + { + if (!attachEventListeners()) + { + (_strand as IEventDispatcher).addEventListener("viewChanged", viewChangedHandler); + } + } + COMPILE::JS + { + (_strand as Object).element.addEventListener('keydown', keyEventHandler); + (_strand as Object).element.addEventListener('keyup', keyEventHandler); + } + } + + + /** + * @private + */ + COMPILE::SWF + private function viewChangedHandler(e:Event):void + { + attachEventListeners(); + } + + /** + * @private + */ + COMPILE::SWF + private function attachEventListeners():Boolean + { + var viewBead:ITextFieldView = _strand.getBeadByType(ITextFieldView) as ITextFieldView; + if (!viewBead) return false; + viewBead.textField.addEventListener(flash.events.KeyboardEvent.KEY_DOWN, keyEventHandler); + viewBead.textField.addEventListener(flash.events.KeyboardEvent.KEY_UP, keyEventHandler); + return true; + } + + + /** + * @private + */ + COMPILE::SWF + protected function keyEventHandler(event:flash.events.KeyboardEvent):void + { + // this will otherwise bubble an event of flash.events.Event + event.stopImmediatePropagation(); + var newEvent:org.apache.flex.events.KeyboardEvent = KeyboardEventConverter.convert(event); + (_strand as IEventDispatcher).dispatchEvent(newEvent); + } + + /** + * @private + */ + COMPILE::JS + protected function keyEventHandler(event:KeyboardEvent):void + { + var newEvent:org.apache.flex.events.KeyboardEvent = KeyboardEventConverter.convert(event); + (_strand as IEventDispatcher).dispatchEvent(newEvent); + } + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/cb67c417/frameworks/projects/HTML/src/main/resources/basic-manifest.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/resources/basic-manifest.xml b/frameworks/projects/HTML/src/main/resources/basic-manifest.xml index 7356316..8f132a6 100644 --- a/frameworks/projects/HTML/src/main/resources/basic-manifest.xml +++ b/frameworks/projects/HTML/src/main/resources/basic-manifest.xml @@ -84,6 +84,7 @@ <component id="AccordionItemRenderer" class="org.apache.flex.html.supportClasses.AccordionItemRenderer"/> <component id="AccordionCollapseBead" class="org.apache.flex.html.beads.AccordionCollapseBead"/> <component id="DispatchInputFinishedBead" class="org.apache.flex.html.beads.DispatchInputFinishedBead"/> + <component id="DispatchKeyboardEventBead" class="org.apache.flex.html.beads.DispatchKeyboardEventBead"/> <component id="TreeItemRenderer" class="org.apache.flex.html.supportClasses.TreeItemRenderer"/> <component id="DataItemRenderer" class="org.apache.flex.html.supportClasses.DataItemRenderer"/> <component id="MXMLItemRenderer" class="org.apache.flex.html.supportClasses.MXMLItemRenderer"/>
