first step for cursor management
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/04e2f745 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/04e2f745 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/04e2f745 Branch: refs/heads/tlf Commit: 04e2f745a7a3cac90e55ccc072290755963bc101 Parents: f52192f Author: Alex Harui <[email protected]> Authored: Wed Jun 21 22:13:41 2017 -0700 Committer: Alex Harui <[email protected]> Committed: Thu Jun 22 11:57:28 2017 -0700 ---------------------------------------------------------------------- .../Basic/src/main/flex/BasicClasses.as | 1 + .../main/flex/org/apache/flex/css2/Cursors.as | 225 +++++++++++++++++++ manualtests/CursorTest/build.xml | 73 ++++++ manualtests/CursorTest/src/CursorTest.mxml | 56 +++++ 4 files changed, 355 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/04e2f745/frameworks/projects/Basic/src/main/flex/BasicClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/BasicClasses.as b/frameworks/projects/Basic/src/main/flex/BasicClasses.as index fbf9a67..f8f4014 100644 --- a/frameworks/projects/Basic/src/main/flex/BasicClasses.as +++ b/frameworks/projects/Basic/src/main/flex/BasicClasses.as @@ -27,6 +27,7 @@ package */ internal class BasicClasses { + import org.apache.flex.css2.Cursors; Cursors; import org.apache.flex.html.ToolTip; ToolTip; import org.apache.flex.html.accessories.NumericOnlyTextInputBead; NumericOnlyTextInputBead; import org.apache.flex.html.beads.DispatchInputFinishedBead; DispatchInputFinishedBead; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/04e2f745/frameworks/projects/Basic/src/main/flex/org/apache/flex/css2/Cursors.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Basic/src/main/flex/org/apache/flex/css2/Cursors.as b/frameworks/projects/Basic/src/main/flex/org/apache/flex/css2/Cursors.as new file mode 100644 index 0000000..8671ca0 --- /dev/null +++ b/frameworks/projects/Basic/src/main/flex/org/apache/flex/css2/Cursors.as @@ -0,0 +1,225 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.css2 +{ + import org.apache.flex.core.IUIBase; + import org.apache.flex.events.MouseEvent; + + COMPILE::SWF + { + import flash.display.DisplayObject; + import flash.geom.Point; + import flash.ui.Mouse; + import flash.ui.MouseCursor; + } + COMPILE::JS + { + import org.apache.flex.core.WrappedHTMLElement; + } + + /** + * The Label class implements the basic control for labeling + * other controls. + * + * @toplevel + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class Cursors + { + public static const AUTO:String = "auto"; + + COMPILE::SWF + public static const DEFAULT:String = "arrow"; + COMPILE::JS + public static const DEFAULT:String = "default"; + + COMPILE::SWF + public static const POINTER:String = "button"; + COMPILE::JS + public static const POINTER:String = "pointer"; + + COMPILE::SWF + public static const MOVE:String = "hand"; + COMPILE::JS + public static const MOVE:String = "move"; + + COMPILE::SWF + public static const TEXT:String = "ibeam"; + COMPILE::JS + public static const TEXT:String = "text"; + + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function Cursors() + { + super(); + } + + /** + * The name of the cursor + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public static function getCursor(obj:IUIBase):String + { + COMPILE::SWF + { + var cursorData:CursorData = obj.getBeadByType(CursorData) as CursorData; + if (cursorData) + return cursorData.cursor; + return Mouse.cursor; + } + COMPILE::JS + { + return obj.element.style.cursor; + } + } + + /** + * @private + */ + public static function setCursor(obj:IUIBase, cursor:String):void + { + COMPILE::SWF + { + var cursorData:CursorData = obj.getBeadByType(CursorData) as CursorData; + if (!cursorData) + { + cursorData = new CursorData(); + obj.addBead(cursorData); + obj.addEventListener(MouseEvent.MOUSE_OVER, overHandler); + obj.addEventListener(MouseEvent.MOUSE_OUT, outHandler); + } + cursorData.cursor = cursor; + + var displayObject:DisplayObject = obj as DisplayObject; + var pt:Point = new Point(displayObject.mouseX, displayObject.mouseY); + pt = displayObject.localToGlobal(pt); + + var o:Array = displayObject.stage.getObjectsUnderPoint(pt); + for each (var s:DisplayObject in o) + { + var iui:IUIBase = s as IUIBase; + if (!iui) + iui = s.parent as IUIBase; + if (!iui && s.parent) + iui = s.parent.parent as IUIBase; + if (iui) + { + var actualCursor:String = getCursor(iui); + if (actualCursor) + { + Mouse.cursor = actualCursor; + return; + } + } + } + } + COMPILE::JS + { + obj.element.style.cursor = cursor; + } + + } + + + /** + * @private + */ + COMPILE::SWF + public static function overHandler(event:MouseEvent):void + { + var o:Array = event.target.stage.getObjectsUnderPoint(new Point(event.stageX, event.stageY)); + for each (var s:DisplayObject in o) + { + var iui:IUIBase = s as IUIBase; + if (!iui) + iui = s.parent as IUIBase; + if (!iui && s.parent) + iui = s.parent.parent as IUIBase; + if (iui) + if (iui) + { + var cursor:String = getCursor(iui); + if (cursor) + { + Mouse.cursor = cursor; + return; + } + } + } + } + + /** + * @private + */ + COMPILE::SWF + public static function outHandler(event:MouseEvent):void + { + if (event.relatedObject) + { + var o:Array = event.relatedObject.stage.getObjectsUnderPoint(new Point(event.stageX, event.stageY)); + for each (var s:DisplayObject in o) + { + var iui:IUIBase = s as IUIBase; + if (!iui) + iui = s.parent as IUIBase; + if (!iui && s.parent) + iui = s.parent.parent as IUIBase; + if (iui) + { + var cursor:String = getCursor(iui); + if (cursor) + { + Mouse.cursor = cursor; + return; + } + } + } + } + Mouse.cursor = MouseCursor.AUTO; + } + + } +} + +import org.apache.flex.core.IBead; +import org.apache.flex.core.IStrand; + +class CursorData implements IBead +{ + public var cursor:String; + + public function set strand(value:IStrand):void + { + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/04e2f745/manualtests/CursorTest/build.xml ---------------------------------------------------------------------- diff --git a/manualtests/CursorTest/build.xml b/manualtests/CursorTest/build.xml new file mode 100644 index 0000000..c0f971f --- /dev/null +++ b/manualtests/CursorTest/build.xml @@ -0,0 +1,73 @@ +<?xml version="1.0"?> +<!-- + + 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. + +--> + + +<project name="cursortest" default="main" basedir="."> + <property name="FLEXJS_HOME" location="../.."/> + <property name="example" value="CursorTest" /> + <property name="swf.version" value="11" /> + + <property environment="env"/> + <property file="${FLEXJS_HOME}/build.properties"/> + <property name="FLEX_HOME" value="${FLEXJS_HOME}"/> + <!-- use this to add keep metadata option --> + <property name="theme_arg" value="-keep-as3-metadata+=Event" /> + <available file="${env.FALCON_HOME}/lib/falcon-mxmlc.jar" + type="file" + property="FALCON_HOME" + value="${env.FALCON_HOME}"/> + + <available file="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk/lib/falcon-mxmlc.jar" + type="file" + property="FALCON_HOME" + value="${FLEXJS_HOME}/../flex-falcon/compiler/generated/dist/sdk"/> + + <available file="${env.FALCONJX_HOME}/lib/jsc.jar" + type="file" + property="FALCONJX_HOME" + value="${env.FALCONJX_HOME}"/> + + <available file="${FLEXJS_HOME}/../flex-falcon/compiler.jx/lib/jsc.jar" + type="file" + property="FALCONJX_HOME" + value="${FLEXJS_HOME}/../flex-falcon/compiler.jx"/> + + <available file="${env.GOOG_HOME}/closure/goog/base.js" + type="file" + property="GOOG_HOME" + value="${env.GOOG_HOME}"/> + + <available file="${FLEXJS_HOME}/js/lib/google/closure-library/closure/goog/base.js" + type="file" + property="GOOG_HOME" + value="${FLEXJS_HOME}/js/lib/google/closure-library"/> + + <include file="${basedir}/../build_example.xml" /> + + <target name="main" depends="clean,build_example.compile,build_example.compilejs" description="Clean build of FlexJSUI.swc"> + </target> + + <target name="clean"> + <delete dir="${basedir}/bin" failonerror="false" /> + <delete dir="${basedir}/bin-debug" failonerror="false" /> + <delete dir="${basedir}/bin-release" failonerror="false" /> + </target> + +</project> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/04e2f745/manualtests/CursorTest/src/CursorTest.mxml ---------------------------------------------------------------------- diff --git a/manualtests/CursorTest/src/CursorTest.mxml b/manualtests/CursorTest/src/CursorTest.mxml new file mode 100644 index 0000000..78b8d3b --- /dev/null +++ b/manualtests/CursorTest/src/CursorTest.mxml @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="utf-8"?> +<!--- +// +// 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. +// +//////////////////////////////////////////////////////////////////////////////// +--> +<js:Application xmlns:fx="http://ns.adobe.com/mxml/2009" + xmlns:local="*" + xmlns:models="models.*" + xmlns:controllers="controllers.*" + xmlns:js="library://ns.apache.org/flexjs/basic" + > + <fx:Script> + <![CDATA[ + import org.apache.flex.css2.Cursors; + + private const dp:Array = [Cursors.AUTO, Cursors.DEFAULT, Cursors.POINTER, Cursors.MOVE, Cursors.TEXT, + "alias", "all-scroll", "cell", "context-menu", "col-resize", "copy", "crosshair", + "e-resize", "ew-resize", "help", "n-resize", "nw-resize", "nwse-resize", "no-drop", + "not-allowed", "progress", "row-resize", "s-resize", "se-resize", "sw-resize", + "vertical-text", "w-resize", "wait", "zoom-in", "zoom-out"] + + ]]> + </fx:Script> + <js:beads> + <js:ApplicationDataBinding /> + </js:beads> + <js:valuesImpl> + <js:SimpleCSSValuesImpl /> + </js:valuesImpl> + <js:initialView> + <js:View width="100%" height="100%" > + <js:beads> + <js:BasicLayout /> + </js:beads> + <js:Label id="foo" text="foo" x="10" y="10"/> + <js:Label id="bar" text="bar" x="10" y="100"/> + <js:DropDownList id="ddlfoo" dataProvider="{dp}" x="100" y="10" change="Cursors.setCursor(foo, ddlfoo.selectedItem as String)"/> + <js:DropDownList id="ddlbar" dataProvider="{dp}" x="100" y="100" change="Cursors.setCursor(bar, ddlbar.selectedItem as String)"/> + </js:View> + </js:initialView> +</js:Application>
