[Laszlo-checkins] r11662 - in openlaszlo/trunk/WEB-INF/lps/lfc: kernel/swf kernel/swf9 views

bargull@openlaszlo.org bargull at openlaszlo.org
Fri Oct 31 05:55:20 PDT 2008


Author: bargull
Date: 2008-10-31 05:55:14 -0700 (Fri, 31 Oct 2008)
New Revision: 11662

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzInputTextSprite.as
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzInputTextSprite.as
   openlaszlo/trunk/WEB-INF/lps/lfc/views/LzInputText.lzs
Log:
Change 20081002-bargull-pTS by bargull at dell--p4--2-53 on 2008-10-02 11:32:19
    in /home/Admin/src/svn/openlaszlo/trunk
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: inputtext focus control

New Features:

Bugs Fixed: LPP-7101, LPP-7120, LPP-7119, LPP-7267

Technical Reviewer: max
QA Reviewer: promanik
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:
(This is a revised changeset from a change at early october.)
LzInputSprite (swf8):
- removed "updateData" (only necessary in LzInputText)
- removed focus-check in "__handlelostFocus"
- moved "gotBlur" and "__onChanged" so it's easier to follow code

LzInputTextSprite (swf9): 
- removed "updateData" (only necessary in LzInputText)
- removed focus-check in "__handlelostFocus"
- added defered execution in "__lostFocus", that way control flow is like in swf8
- set keyboard focus in "gotFocus"
- unset keyboard focus in "gotBlur"
- use String#replace instead of split+join, because it's faster (I've tested it!)

LzInputText:
- temporarily split "inputtextevent" into a dhtml and swf version, because dhtml has its own issues (LPP-7113)
- "inputtextevent" (dhtml): use lz.ModeManager.rawMouseEvent to propagate mouse-events, leave the rest untouched
- "inputtextevent" (swf): check current focus when you get an "onblur"-event 
    

Tests:
see bugreport



Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzInputTextSprite.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzInputTextSprite.as	2008-10-31 12:27:05 UTC (rev 11661)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzInputTextSprite.as	2008-10-31 12:55:14 UTC (rev 11662)
@@ -57,12 +57,9 @@
     
     this.password = args.password  ? true : false;
     textclip.password = this.password;
-
 }
 
 
-
-
 LzInputTextSprite.prototype = new LzTextSprite(null);
 
 
@@ -174,16 +171,25 @@
 }
 
 /**
+  * Called from LzInputText#_gotFocusEvent() after focus was set by lz.Focus
   * @access private
   */
-LzInputTextSprite.prototype.gotFocus = function (  ){
-    //Debug.write('LzInputTextSprite.__handleOnFocus');
+LzInputTextSprite.prototype.gotFocus = function () {
     if ( this.hasFocus ) { return; }
     this.select();
     this.hasFocus = true;
 }
 
-LzInputTextSprite.prototype.select = function (  ){
+/**
+  * Called from LzInputText#_gotBlurEvent() after focus was cleared by lz.Focus
+  * @access private
+  */
+LzInputTextSprite.prototype.gotBlur = function () {
+    this.hasFocus = false;
+    this.deselect();
+}
+
+LzInputTextSprite.prototype.select = function () {
     var sf = targetPath(this.__LZtextclip);
 
     // calling setFocus() bashes the scroll and hscroll values, so save them
@@ -198,53 +204,29 @@
     this.__LZtextclip.background = false;
 }
 
-
-LzInputTextSprite.prototype.deselect = function (  ){
-    var sf =  targetPath(this.__LZtextclip);
+LzInputTextSprite.prototype.deselect = function () {
+    var sf = targetPath(this.__LZtextclip);
     if( Selection.getFocus() == sf ) {
         Selection.setFocus( null );
     }
 }
 
 /**
-  * @access private
-  */
-LzInputTextSprite.prototype.gotBlur = function (  ){
-    //Debug.write('LzInputTextSprite.__handleOnBlur');
-    this.hasFocus = false;
-    this.deselect();
-}
-
-/**
   * Register for update on every frame when the text field gets the focus.
   * Set the behavior of the enter key depending on whether the field is
   * multiline or not.
   * 
   * @access private
   */
-TextField.prototype.__gotFocus = function ( oldfocus ){
+TextField.prototype.__gotFocus = function (oldfocus) {
     // scroll text fields horizontally back to start
     if (this.__lzview) this.__lzview.inputtextevent('onfocus');
 }
 
-
-
 /**
-  * Register to be called when the text field is modified. Convert this
-  * into a LFC ontext event. 
   * @access private
   */
-TextField.prototype.__onChanged = function ( ){
-    if (this.__lzview) {
-        this.__owner.text = this.__owner.getText();
-        this.__lzview.inputtextevent('onchange', this.__owner.text);
-    }
-}
-
-/**
-  * @access private
-  */
-TextField.prototype.__lostFocus = function ( ){
+TextField.prototype.__lostFocus = function () {
     if (this['__handlelostFocusdel'] == null) this.__handlelostFocusdel = new LzDelegate(this, "__handlelostFocus");
     lz.Idle.callOnIdle(this.__handlelostFocusdel);
 }
@@ -255,24 +237,22 @@
   * cleared, the button doesn't send mouse events.
   * @access private
   */
-TextField.prototype.__handlelostFocus = function ( ignore ){
-    //Debug.write('lostfocus', this.__lzview.hasFocus, lz.Focus.lastfocus, this, lz.Focus.getFocus(), this.__lzview, this.__lzview.inputtextevent);
-    if (this.__lzview == lz.Focus.getFocus()) {
-        lz.Focus.clearFocus();
-        if (this.__lzview) this.__lzview.inputtextevent('onblur');
-    }    
+TextField.prototype.__handlelostFocus = function (ignore) {
+    if (this.__lzview) this.__lzview.inputtextevent('onblur');
 }
 
 /**
-  * Retrieves the contents of the text field for use by a datapath. See
-  * <code>LzDatapath.updateData</code> for more on this.
-  * @access protected
+  * Register to be called when the text field is modified. Convert this
+  * into a LFC ontext event. 
+  * @access private
   */
-LzInputTextSprite.prototype.updateData = function (){
-    return this.__LZtextclip.text;
+TextField.prototype.__onChanged = function () {
+    if (this.__lzview) {
+        this.__owner.text = this.__owner.getText();
+        this.__lzview.inputtextevent('onchange', this.__owner.text);
+    }
 }
 
-
 /**
   * Sets whether user can modify input text field
   * @param Boolean enabled: true if the text field can be edited

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzInputTextSprite.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzInputTextSprite.as	2008-10-31 12:27:05 UTC (rev 11661)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzInputTextSprite.as	2008-10-31 12:55:14 UTC (rev 11662)
@@ -12,12 +12,13 @@
   * @shortdesc Used for input text.
   * 
   */
-class LzInputTextSprite extends LzTextSprite {
+public class LzInputTextSprite extends LzTextSprite {
 
     #passthrough (toplevel:true) {  
         import flash.display.*;
         import flash.events.*;
         import flash.text.*;
+        import flash.utils.setTimeout;
     }#
 
     #passthrough  {
@@ -27,14 +28,12 @@
         super(newowner);
     }
 
-
     var __handlelostFocusdel;
     var enabled = true;
     var focusable = true;
     var hasFocus = false;
     var scroll = 0;
 
-
     override public function __initTextProperties (args:Object) {
         super.__initTextProperties(args);
         // We do not support html in input fields. 
@@ -65,39 +64,41 @@
         textfield.addEventListener(FocusEvent.FOCUS_OUT, __lostFocus);
 
         this.hasFocus = false;
-
     }
 
     /**
+     * Called from LzInputText#_gotFocusEvent() after focus was set by lz.Focus
      * @access private
      */
-    public function gotFocus ( ){
-        //Debug.write('LzInputTextSprite.__handleOnFocus');
+    public function gotFocus () :void {
         if ( this.hasFocus ) { return; }
+        // assign keyboard control
+        LFCApplication.stage.focus = this.textfield;
         this.select();
         this.hasFocus = true;
     }
 
-    function select (  ){
-        textfield.setSelection(0, textfield.text.length);
-
-    }
-
-    // XXXX selectionBeginIndex    property
-    
-    function deselect (  ){
-        textfield.setSelection(0,0);
-    }
-
     /**
+     * Called from LzInputText#_gotBlurEvent() after focus was cleared by lz.Focus
      * @access private
      */
-    function gotBlur (  ){
-        //Debug.write('LzInputTextSprite.__handleOnBlur');
+    function gotBlur () :void {
         this.hasFocus = false;
         this.deselect();
+        if (LFCApplication.stage.focus === this.textfield) {
+            // remove keyboard control
+            LFCApplication.stage.focus = null;
+        }
     }
 
+    function select () :void {
+        textfield.setSelection(0, textfield.text.length);
+    }
+
+    function deselect () :void {
+        textfield.setSelection(0, 0);
+    }
+
     /**
      * TODO [hqm 2008-01] I have no idea whether this comment
      * still applies:
@@ -107,32 +108,18 @@
      * 
      * @access private
      */
-    function __gotFocus ( event:Event ){
+    function __gotFocus (event:FocusEvent) :void {
         // scroll text fields horizontally back to start
         if (owner) owner.inputtextevent('onfocus');
     }
 
-
-
     /**
-     * Register to be called when the text field is modified. Convert this
-     * into a LFC ontext event. 
      * @access private
-     */
-    function __onChanged (event:Event ){
-        this.text = this.getText();
-        if (owner) owner.inputtextevent('onchange', this.text);
-    }
-
-    /**
-     * @access private
      * TODO [hqm 2008-01] Does we still need this workaround???
      */
-    function __lostFocus (event:Event){
-        __handlelostFocus(event);
-        //trace('lost focus', event.target);
-        //if (this['__handlelostFocusdel'] == null) this.__handlelostFocusdel = new LzDelegate(this, "__handlelostFocus");
-        //lz.Idle.callOnIdle(this.__handlelostFocusdel);
+    function __lostFocus (event:FocusEvent) :void {
+        // defer execution, see swf8 kernel
+        setTimeout(this.__handlelostFocus, 1, event);
     }
 
     /**
@@ -143,37 +130,34 @@
      * cleared, the button doesn't send mouse events.
      * @access private
      */
-    function __handlelostFocus (evt ){
-        if (owner == lz.Focus.getFocus()) {
-            lz.Focus.clearFocus();
-            if (owner) owner.inputtextevent('onblur');
-        }    
+    function __handlelostFocus (event:Event) :void {
+        if (owner) owner.inputtextevent('onblur');
     }
-    
+
     /**
-     * Get the current text for this inputtext-sprite.
-     * @protected
+     * Register to be called when the text field is modified. Convert this
+     * into a LFC ontext event. 
+     * @access private
      */
-    override public function getText():String {
-        // We normalize swf's \r to \n
-        return this.textfield.text.split('\r').join('\n');
+    function __onChanged (event:Event) :void {
+        this.text = this.getText();
+        if (owner) owner.inputtextevent('onchange', this.text);
     }
 
     /**
-     * Retrieves the contents of the text field for use by a datapath. See
-     * <code>LzDatapath.updateData</code> for more on this.
-     * @access protected
+     * Get the current text for this inputtext-sprite.
+     * @protected
      */
-    function updateData (){
-        return textfield.text;
+    override public function getText() :String {
+        // We normalize swf's \r to \n
+        return this.textfield.text.replace(/\r/g, '\n');
     }
 
-
     /**
      * Sets whether user can modify input text field
      * @param Boolean enabled: true if the text field can be edited
      */
-    function setEnabled (enabled){
+    function setEnabled (enabled) :void {
         this.enabled = enabled;
         if (enabled) {
             textfield.type = 'input';
@@ -185,12 +169,11 @@
     /**
      * Set the html flag on this text view
      */
-    function setHTML (htmlp) {
+    function setHTML (htmlp) :void {
         // TODO [hqm 2008-10] what do we do here?
     }
 
-
-    override public function getTextfieldHeight ( ){
+    override public function getTextfieldHeight () {
         return this.textfield.height;
     }
 

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/views/LzInputText.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/views/LzInputText.lzs	2008-10-31 12:27:05 UTC (rev 11661)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/views/LzInputText.lzs	2008-10-31 12:55:14 UTC (rev 11662)
@@ -168,9 +168,11 @@
     isprite.gotBlur();
 }
 
-
+if ($dhtml) {
+private static const __LZinputmouse = {onclick: true, onmousedown: true, onmouseout: true};
 /** @access private 
  * Receive input text events from sprite
+ * TODO: [20081030 anba] (LPP-7113) re-merge with swf-version when working on LPP-7113
  */
 function inputtextevent (eventname, value = null) {
     //Debug.warn('inputtextevent', eventname, value);
@@ -197,9 +199,53 @@
     } else if (eventname == 'onblur') {
         this._focused = false;
     }
-    if (this[eventname].ready) this[eventname].sendEvent(value);
+    // we get these events from LzInputTextSprite:
+    // onblur, onselect, onfocus, onchange, 
+    // onmousedown, onmouseout, onclick
+    if (LzInputText.__LZinputmouse[eventname]) {
+        // use the service class to propagate mouse-events
+        lz.ModeManager.handleMouseEvent(this, eventname);
+    } else {
+        // FIXME: [20081030 anba] this isn't quite right, 
+        // e.g. we must use lz.Focus for focus events!
+        if (this[eventname].ready) this[eventname].sendEvent(value);
+    }
 }
+} else {
+/** @access private 
+ * Receive input text events from sprite
+ */
+function inputtextevent (eventname:String, value:* = null) :void {
+    if (eventname == 'onfocus' && this._focused) return;
+    if (eventname == 'onblur' && ! this._focused) return;
 
+    if (eventname == 'onfocus') {
+        this._focused = true;
+        if (lz.Focus.getFocus() !== this) {
+            var tabdown:Boolean = lz.Keys.isKeyDown('tab');
+            lz.Focus.setFocus(this, tabdown);
+        }
+    } else if (eventname == 'onchange') {
+        //multiline resizable fields adjust their height
+        var isprite:LzInputTextSprite = (this.sprite cast LzInputTextSprite);    
+        this.text = isprite.getText();
+        if ( this.multiline && 
+             this.sizeToHeight && 
+             this.height != isprite.getTextfieldHeight() ) {
+            this.setHeight(isprite.getTextfieldHeight());
+        }
+        if (this.ontext.ready) this.ontext.sendEvent(value);
+    } else if (eventname == 'onblur') {
+        this._focused = false;
+        if (lz.Focus.getFocus() === this) {
+            lz.Focus.clearFocus();
+        }
+    } else if ($debug) {
+        Debug.warn("unhandled inputtextevent='%s' in %#w", eventname, this);
+    }
+}
+}
+
 /**
   * Retrieves the contents of the text field for use by a datapath. See
   * <link linkend="LzDatapath.prototype.updateData"><method>LzDatapath.updateData()</method></link> for more on this.
@@ -228,9 +274,6 @@
     if (this.onenabled.ready) this.onenabled.sendEvent(enabled);
 }
 
-
-
-
 /**
   * Sets whether user can modify input text field
   * @param Boolean enabled: true if the text field can be edited



More information about the Laszlo-checkins mailing list