Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AABBD200CA6 for ; Mon, 8 May 2017 20:59:16 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A936F160BCB; Mon, 8 May 2017 18:59:16 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id AB718160BBF for ; Mon, 8 May 2017 20:59:15 +0200 (CEST) Received: (qmail 33874 invoked by uid 500); 8 May 2017 18:59:14 -0000 Mailing-List: contact commits-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list commits@flex.apache.org Received: (qmail 33447 invoked by uid 99); 8 May 2017 18:59:13 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 May 2017 18:59:13 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 4EE72E96A2; Mon, 8 May 2017 18:59:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aharui@apache.org To: commits@flex.apache.org Date: Mon, 08 May 2017 18:59:23 -0000 Message-Id: In-Reply-To: <05b616d7ef1c49bcb39effb9a01cac0b@git.apache.org> References: <05b616d7ef1c49bcb39effb9a01cac0b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [11/21] git commit: [flex-asjs] [refs/heads/tlf] - handle keyboard and other events archived-at: Mon, 08 May 2017 18:59:16 -0000 handle keyboard and other events Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/70e2c0d6 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/70e2c0d6 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/70e2c0d6 Branch: refs/heads/tlf Commit: 70e2c0d6b1ab7161567144eb6e6a0f7490e2844a Parents: af36a26 Author: Alex Harui Authored: Sat May 6 21:37:26 2017 -0700 Committer: Alex Harui Committed: Mon May 8 11:59:02 2017 -0700 ---------------------------------------------------------------------- .../projects/TLF/src/main/flex/TLFClasses.as | 1 + .../beads/DispatchTLFKeyboardEventBead.as | 191 +++++++++++++++++++ 2 files changed, 192 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/70e2c0d6/frameworks/projects/TLF/src/main/flex/TLFClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/TLF/src/main/flex/TLFClasses.as b/frameworks/projects/TLF/src/main/flex/TLFClasses.as index dd6d6ed..e398e7c 100644 --- a/frameworks/projects/TLF/src/main/flex/TLFClasses.as +++ b/frameworks/projects/TLF/src/main/flex/TLFClasses.as @@ -24,6 +24,7 @@ package // import org.apache.flex.textLayout.accessibility.TextAccImpl; TextAccImpl; + import org.apache.flex.textLayout.beads.DispatchTLFKeyboardEventBead; DispatchTLFKeyboardEventBead; import org.apache.flex.textLayout.container.TextContainerManager; TextContainerManager; import org.apache.flex.textLayout.TextLayoutVersion; TextLayoutVersion; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/70e2c0d6/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/beads/DispatchTLFKeyboardEventBead.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/beads/DispatchTLFKeyboardEventBead.as b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/beads/DispatchTLFKeyboardEventBead.as new file mode 100644 index 0000000..286698d --- /dev/null +++ b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/beads/DispatchTLFKeyboardEventBead.as @@ -0,0 +1,191 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.textLayout.beads +{ + + import org.apache.flex.core.IBead; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.UIBase; + 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; + import org.apache.flex.textLayout.events.FocusEvent; + + COMPILE::JS + { + import org.apache.flex.core.IRenderedObject; + import goog.events; + } + + COMPILE::SWF + { + import flash.events.Event; + import flash.events.KeyboardEvent; + } + + /** + * 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 DispatchTLFKeyboardEventBead implements IBead + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function DispatchTLFKeyboardEventBead() + { + } + + 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:org.apache.flex.events.Event):void + { + attachEventListeners(); + } + + /** + * @private + */ + COMPILE::SWF + private function attachEventListeners():Boolean + { + var host:UIBase = _strand as UIBase; + host.$displayObject.addEventListener(flash.events.KeyboardEvent.KEY_DOWN, keyEventHandler); + host.$displayObject.addEventListener(flash.events.KeyboardEvent.KEY_UP, keyEventHandler); + host.$displayObject.addEventListener(flash.events.Event.ACTIVATE, eventHandler); + host.$displayObject.addEventListener(flash.events.Event.DEACTIVATE, eventHandler); + host.$displayObject.addEventListener(flash.events.FocusEvent.FOCUS_IN, focusEventHandler); + host.$displayObject.addEventListener(flash.events.FocusEvent.FOCUS_OUT, focusEventHandler); + 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); + if(newEvent.defaultPrevented) + { + event.preventDefault(); + } + + + } + + /** + * @private + */ + COMPILE::SWF + protected function eventHandler(event:flash.events.Event):void + { + if (event is org.apache.flex.events.Event) return; + + // this will otherwise dispatch an event of flash.events.Event + event.stopImmediatePropagation(); + var newEvent:org.apache.flex.events.Event = new org.apache.flex.events.Event(event.type); + (_strand as IEventDispatcher).dispatchEvent(newEvent); + if(newEvent.defaultPrevented) + { + event.preventDefault(); + } + } + + /** + * @private + */ + COMPILE::SWF + protected function focusEventHandler(event:flash.events.FocusEvent):void + { + if (event is org.apache.flex.events.Event) return; + + // this will otherwise dispatch an event of flash.events.FocusEvent + event.stopImmediatePropagation(); + var newEvent:org.apache.flex.textLayout.events.FocusEvent = new org.apache.flex.textLayout.events.FocusEvent(event.type); + (_strand as IEventDispatcher).dispatchEvent(newEvent); + if(newEvent.defaultPrevented) + { + event.preventDefault(); + } + } + + /** + * @private + */ + COMPILE::JS + protected function keyEventHandler(event:KeyboardEvent):void + { + event.stopImmediatePropagation(); + var newEvent:org.apache.flex.events.KeyboardEvent = KeyboardEventConverter.convert(event); + (_strand as IEventDispatcher).dispatchEvent(newEvent); + if(newEvent.defaultPrevented) + { + event.preventDefault(); + } + } + + } +}