Repository: flex-asjs
Updated Branches:
  refs/heads/tlf ef940e3f4 -> 914e666c7


Reverted removal of buttonDown
added getter for textBlockStart (fixes a bug on line start/end selection)
Changed getAtomIndexAtPoint() to local coordinates
Added handling of more events in ContainerController


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/914e666c
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/914e666c
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/914e666c

Branch: refs/heads/tlf
Commit: 914e666c7a1960d9cccab8eafa3a4583b87a92b0
Parents: ef940e3
Author: Added floor to binary search <[email protected]>
Authored: Sun Jun 18 13:34:04 2017 +0300
Committer: Added floor to binary search <[email protected]>
Committed: Sun Jun 18 13:34:04 2017 +0300

----------------------------------------------------------------------
 .../flex/org/apache/flex/events/MouseEvent.as   |  6 ++---
 .../flex/textLayout/compose/ITextFlowLine.as    |  1 +
 .../flex/textLayout/compose/TextFlowLine.as     | 27 ++++++++++++++++++++
 .../textLayout/container/ContainerController.as | 14 +++++++++-
 .../container/TextContainerManager.as           | 10 ++------
 .../flex/textLayout/edit/SelectionManager.as    | 17 ++++--------
 .../flex/textLayout/elements/LinkElement.as     |  8 ++----
 .../events/FlowElementMouseEventManager.as      |  9 +------
 .../flex/org/apache/flex/text/html/TextLine.as  | 10 +++++---
 9 files changed, 59 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/914e666c/frameworks/projects/Core/src/main/flex/org/apache/flex/events/MouseEvent.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/MouseEvent.as 
b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/MouseEvent.as
index c2fe391..1cea36d 100644
--- 
a/frameworks/projects/Core/src/main/flex/org/apache/flex/events/MouseEvent.as
+++ 
b/frameworks/projects/Core/src/main/flex/org/apache/flex/events/MouseEvent.as
@@ -247,6 +247,7 @@ package org.apache.flex.events
                        this.ctrlKey = ctrlKey;
                        this.altKey = altKey;
                        this.shiftKey = shiftKey;
+                       this.buttonDown = buttonDown;
                        this.delta = delta;
                        this.commandKey = commandKey;
                        this.controlKey = controlKey;
@@ -279,10 +280,7 @@ package org.apache.flex.events
                public var ctrlKey:Boolean;
                public var altKey:Boolean;
                public var shiftKey:Boolean;
-        // MDL says buttonDown is unreliable in JS for mouseMove so hide
-        // the API so folks get compile errors and keep their own flags
-        // for mouseDown/mouseUp
-               private var buttonDown:Boolean;
+               public var buttonDown:Boolean;
                public var delta:int;
                public var commandKey:Boolean;
                public var controlKey:Boolean;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/914e666c/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/compose/ITextFlowLine.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/compose/ITextFlowLine.as
 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/compose/ITextFlowLine.as
index 2ef9404..bfa84b1 100644
--- 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/compose/ITextFlowLine.as
+++ 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/compose/ITextFlowLine.as
@@ -56,6 +56,7 @@ package org.apache.flex.textLayout.compose
                function get paragraph():IParagraphElement;
                function get absoluteStart():int;
                function setAbsoluteStart(val:int):void;
+               function get textBlockStart():int;
                function get textLength():int;
                function setTextLength(val:int):void;
                function get spaceBefore():Number;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/914e666c/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/compose/TextFlowLine.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/compose/TextFlowLine.as
 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/compose/TextFlowLine.as
index cf207b6..64a3d54 100644
--- 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/compose/TextFlowLine.as
+++ 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/compose/TextFlowLine.as
@@ -524,6 +524,27 @@ package org.apache.flex.textLayout.compose
                {
                        return _absoluteStart;
                }
+               public function get textBlockStart():int
+               {
+                       var start:int = absoluteStart;
+                       var paraStart:int = paragraph.getAbsoluteStart();
+                       start -= paraStart;
+                       var tbs:Vector.<ITextBlock> = paragraph.getTextBlocks();
+                       if(tbs.length > 1)
+                       {
+                               var textBlock:ITextBlock = 
paragraph.getTextBlockAtPosition(start);
+                               for(var i:int = 0; i < tbs.length; i++)
+                               {
+                                       if(textBlock == tbs[i])
+                                               break;
+                                       start -= tbs[i].content.rawText.length;
+                               }
+                       }
+
+                       return start;
+
+
+               }
 
                /** @private */
                public function setAbsoluteStart(val:int):void
@@ -1616,6 +1637,10 @@ package org.apache.flex.textLayout.compose
                        for each (drawRect in selCache.selectionBlocks)
                        {
                                drawRect = drawRect.clone();
+                               // if(blockProgression == BlockProgression.TB)
+                               //      drawRect.y += nextLine.y - 
nextLine.ascent;
+                               // else
+                               //      drawRect.x += nextLine.x - 
nextLine.ascent;//TODO does this make sense?
                                convertLineRectToContainer(drawRect, true);
                                createSelectionRect(selObj, color, drawRect.x, 
drawRect.y, drawRect.width, drawRect.height);
                        }
@@ -1947,6 +1972,8 @@ package org.apache.flex.textLayout.compose
                                // NB - Never use baseline adjustments for TCY. 
 They don't make sense here.(I think) - gak 06.03.08
                                if (blockProgression == BlockProgression.RL)
                                        globalStart.y = begCharRect.y + 
(startMetrics.width / 2); // TODO-9/5/8:Behavior for leading down TBD
+                               else// Harbs 6-13-17 Not sure how this used to 
work without this.
+                                       globalStart.y = begCharRect.y;
 
                                if (justRule != JustificationRule.EAST_ASIAN)
                                {

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/914e666c/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/container/ContainerController.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/container/ContainerController.as
 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/container/ContainerController.as
index e6ed682..76cb412 100644
--- 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/container/ContainerController.as
+++ 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/container/ContainerController.as
@@ -2088,6 +2088,8 @@ package org.apache.flex.textLayout.container
                
                public function mouseOverHandler(event:MouseEvent):void
                {
+                       if(!event.buttonDown)
+                       event.buttonDown = buttonDown;
                        if (interactionManager && !event.defaultPrevented)
                                interactionManager.mouseOverHandler(event);
                }
@@ -2095,6 +2097,8 @@ package org.apache.flex.textLayout.container
                /** @private Does required mouseOver handling.  Calls 
mouseOverHandler.  @see #mouseOverHandler */
                public function requiredMouseOverHandler(event:MouseEvent):void
                {
+                       if(!event.buttonDown)
+                       event.buttonDown = buttonDown;
                        attachAllListeners();
                        getInteractionHandler().mouseOverHandler(event);
                }
@@ -2111,6 +2115,8 @@ package org.apache.flex.textLayout.container
                 */                             
                public function mouseOutHandler(event:MouseEvent):void
                {
+                       if(!event.buttonDown)
+                       event.buttonDown = buttonDown;
                        if (interactionManager && !event.defaultPrevented)
                                interactionManager.mouseOutHandler(event);
                }
@@ -2162,6 +2168,7 @@ package org.apache.flex.textLayout.container
                
                public function mouseDownHandler(event:MouseEvent):void
                {
+                       buttonDown = true;
                        if (interactionManager && !event.defaultPrevented)
                        {
                                interactionManager.mouseDownHandler(event);
@@ -2207,6 +2214,7 @@ package org.apache.flex.textLayout.container
                 */
                public function mouseUpHandler(event:MouseEvent):void
                {
+                       buttonDown = false;
                        if (interactionManager && event && 
!event.defaultPrevented)
                        {
                                interactionManager.mouseUpHandler(event);
@@ -2325,11 +2333,13 @@ package org.apache.flex.textLayout.container
                
                public function mouseMoveHandler(event:MouseEvent):void
                {
+                       if(!event.buttonDown)
+                               event.buttonDown = buttonDown;
                        if (interactionManager && !event.defaultPrevented)
                        {
 //TODO fix this
                                // only autoscroll if we haven't hit something 
on the stage related to this particular TextFlow
-                               if (buttonDown && 
!hitOnMyFlowExceptLastContainer(event))
+                               if (event.buttonDown && 
!hitOnMyFlowExceptLastContainer(event))
                                        // autoScrollIfNecessary(event.stageX, 
event.stageY);
                                interactionManager.mouseMoveHandler(event);
                        }
@@ -2338,6 +2348,8 @@ package org.apache.flex.textLayout.container
                /** @private */
                public function rootMouseMoveHandler(event:MouseEvent):void
                {   
+                       if(!event.buttonDown)
+                               event.buttonDown = buttonDown;
                        getInteractionHandler().mouseMoveHandler(event); 
                }
                

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/914e666c/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/container/TextContainerManager.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/container/TextContainerManager.as
 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/container/TextContainerManager.as
index 77c7cb8..457dd88 100644
--- 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/container/TextContainerManager.as
+++ 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/container/TextContainerManager.as
@@ -2525,14 +2525,8 @@ class RemappedMouseEvent extends 
org.apache.flex.events.MouseEvent
                        containerPoint = new Point();
 
                /* event.commandKey,event.controlKey,event.clickCount are also 
supported in AIR.  IMHO they are a nonissue for the initial click */
-        COMPILE::SWF
-        {
-               
super(event.type,event.bubbles,event.cancelable,containerPoint.x,containerPoint.y,event.relatedObject,event.ctrlKey,event.altKey,event.shiftKey,event.buttonDown,event.delta);
-        }
-        COMPILE::JS
-        {
-            
super(event.type,event.bubbles,event.cancelable,containerPoint.x,containerPoint.y,event.relatedObject,event.ctrlKey,event.altKey,event.shiftKey,false,event.delta);
        
-        }
+               
super(event.type,event.bubbles,event.cancelable,containerPoint.x,containerPoint.y,event.relatedObject,event.ctrlKey,event.altKey,event.shiftKey,event.buttonDown,event.delta);
+               
                _event = event;
        }
 

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/914e666c/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/edit/SelectionManager.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/edit/SelectionManager.as
 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/edit/SelectionManager.as
index 6a9d11c..04c4255 100644
--- 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/edit/SelectionManager.as
+++ 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/edit/SelectionManager.as
@@ -1524,7 +1524,7 @@ package org.apache.flex.textLayout.edit
                                        }
                                        else
                                        {
-                                               var lastLinePosInPar:int = 
textFlowLine.absoluteStart + textFlowLine.textLength - 1;
+                                               var lastLinePosInPar:int = 
textFlowLine.textBlockStart + textFlowLine.textLength - 1;
                                                var lastChar:String = 
textLine.textBlock.content.rawText.charAt(lastLinePosInPar);
                                                if (lastChar == " ")
                                                {
@@ -1693,7 +1693,7 @@ package org.apache.flex.textLayout.edit
                        //
                        // As a result, we need to be performing the less 
common case check prior to adjusting the
                        // coordinates.
-                       pt = PointUtils.localToGlobal(pt, textLine);// 
textLine.localToGlobal(pt);
+                       // pt = PointUtils.localToGlobal(pt, textLine);// 
textLine.localToGlobal(pt);
                        var elemIdx:int = textLine.getAtomIndexAtPoint(pt.x, 
pt.y);
                        // trace("global point: " + pt);
                        // trace("elemIdx: " + elemIdx);
@@ -1710,7 +1710,7 @@ package org.apache.flex.textLayout.edit
                                        pt.y = 0;
 
                                // get the global again and get try for the 
element again
-                               pt = PointUtils.localToGlobal(pt, textLine);// 
textLine.localToGlobal(pt);
+                               // pt = PointUtils.localToGlobal(pt, 
textLine);// textLine.localToGlobal(pt);
                                elemIdx = textLine.getAtomIndexAtPoint(pt.x, 
pt.y);
                                // trace("global point (second): " + pt);
                                // trace("elemIdx (second): " + elemIdx);
@@ -1722,7 +1722,7 @@ package org.apache.flex.textLayout.edit
                                // we need to use global coordinates here.  
reset pt and get conversion...
                                pt.x = localX;
                                pt.y = localY;
-                               pt = PointUtils.localToGlobal(pt, textLine);// 
textLine.localToGlobal(pt);
+                               // pt = PointUtils.localToGlobal(pt, 
textLine);// textLine.localToGlobal(pt);
                                if (textLine.parent)
                                        pt = PointUtils.globalToLocal(pt, 
textLine.parent);// textLine.parent.globalToLocal(pt);
 
@@ -1976,9 +1976,6 @@ package org.apache.flex.textLayout.edit
                // ///////////////////////////////////
                // Mouse and keyboard methods
                // ///////////////////////////////////
-        
-        private var buttonDown:Boolean;
-        
                /** 
                 *  @copy IInteractionEventHandler#mouseDownHandler()
                 * 
@@ -1989,8 +1986,6 @@ package org.apache.flex.textLayout.edit
                 */
                public function mouseDownHandler(event:MouseEvent):void
                {
-            buttonDown = true;
-            
                        if (subManager)
                                subManager.selectRange(-1, -1);
 
@@ -2052,7 +2047,7 @@ package org.apache.flex.textLayout.edit
                                setMouseCursor(MouseCursor.IBEAM);
                        }
 
-                       if (buttonDown)
+                       if (event.buttonDown)
                        {
                                var cell:ITableCellElement = 
_textFlow.parentElement as ITableCellElement;
 
@@ -2114,8 +2109,6 @@ package org.apache.flex.textLayout.edit
                 */
                public function mouseUpHandler(event:MouseEvent):void
                {
-            buttonDown = false;
-            
                        if (!_mouseOverSelectionArea)
                        {
                                setMouseCursor(MouseCursor.AUTO);

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/914e666c/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/elements/LinkElement.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/elements/LinkElement.as
 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/elements/LinkElement.as
index 6cfdb84..72cc6ca 100644
--- 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/elements/LinkElement.as
+++ 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/elements/LinkElement.as
@@ -496,15 +496,12 @@ package org.apache.flex.textLayout.elements
                        }
                }
 
-        private var buttonDown:Boolean;
-        
                /** @private
                 * The ElementMouseEventManager calls this method directly. 
Note that the mouse
                 * coordinates are unrelated to any coordinate in the container 
or this element.
                 */
                public function 
mouseDownHandler(mgr:FlowElementMouseEventManager, evt:MouseEvent):void
                {
-            buttonDown = true;
                        mgr.setHandCursor(true);
                        setToState(LinkState.ACTIVE);
                        evt.stopImmediatePropagation();
@@ -517,7 +514,7 @@ package org.apache.flex.textLayout.elements
                public function 
mouseMoveHandler(mgr:FlowElementMouseEventManager, evt:MouseEvent):void
                {
                        mgr.setHandCursor(true);
-                       setToState(buttonDown ? LinkState.ACTIVE : 
LinkState.HOVER);
+                       setToState(evt.buttonDown ? LinkState.ACTIVE : 
LinkState.HOVER);
                }
 
                /** @private
@@ -537,7 +534,7 @@ package org.apache.flex.textLayout.elements
                public function 
mouseOverHandler(mgr:FlowElementMouseEventManager, evt:MouseEvent):void
                {
                        mgr.setHandCursor(true);
-                       setToState(buttonDown ? LinkState.ACTIVE : 
LinkState.HOVER);
+                       setToState(evt.buttonDown ? LinkState.ACTIVE : 
LinkState.HOVER);
                }
 
                /** @private
@@ -546,7 +543,6 @@ package org.apache.flex.textLayout.elements
                 */
                public function 
mouseUpHandler(mgr:FlowElementMouseEventManager, evt:MouseEvent):void
                {
-            buttonDown = false;
                        mgr.setHandCursor(true);
                        setToState(LinkState.HOVER);
                        evt.stopImmediatePropagation();

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/914e666c/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/events/FlowElementMouseEventManager.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/events/FlowElementMouseEventManager.as
 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/events/FlowElementMouseEventManager.as
index 7c53953..02a0e7c 100644
--- 
a/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/events/FlowElementMouseEventManager.as
+++ 
b/frameworks/projects/TLF/src/main/flex/org/apache/flex/textLayout/events/FlowElementMouseEventManager.as
@@ -524,8 +524,6 @@ package org.apache.flex.textLayout.events
                                link.mouseOutHandler(this, _lastMouseEvent);
                }
                
-        private var buttonDown:Boolean;
-        
                /** @private
                 * Process mouse events.
                 * 
@@ -538,11 +536,6 @@ package org.apache.flex.textLayout.events
                        if (!_hitTests)
                                return;
                        
-            if (evt.type == MouseEvent.MOUSE_DOWN)
-                buttonDown = true;
-            else if (evt.type == MouseEvent.MOUSE_UP)
-                buttonDown = false;
-            
                        // note that mouseOver and mouseOut are used for 
hit-testing only
                        // need the last mouse event's button state to pass in 
to LinkElement
                        // in case the state of the Ctrl key changes (see 
hitTestKeyEventHandler())
@@ -556,7 +549,7 @@ package org.apache.flex.textLayout.events
                                if (_currentElement)
                                        // generate a mouseOut event
                                        
localDispatchEvent(FlowElementMouseEvent.ROLL_OUT, evt);
-                               else if (buttonDown)
+                               else if (evt.buttonDown)
                                        // do not interact if the button is 
down to not disturb e.g. 
                                        // a mark operation in the container
                                        _blockInteraction = true;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/914e666c/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/TextLine.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/TextLine.as 
b/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/TextLine.as
index 1bbdf65..5818a60 100644
--- 
a/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/TextLine.as
+++ 
b/frameworks/projects/Text/src/main/flex/org/apache/flex/text/html/TextLine.as
@@ -24,6 +24,7 @@ package org.apache.flex.text.html
                import flash.text.TextField;
                import flash.text.TextFormat;
                import flash.text.TextFieldAutoSize;
+               import flash.geom.Point;
        }
        COMPILE::JS
        {
@@ -400,16 +401,17 @@ package org.apache.flex.text.html
                        return charIndex;
                }
 
-               public function getAtomIndexAtPoint(stageX:Number, 
stageY:Number):int
+               public function getAtomIndexAtPoint(localX:Number, 
localY:Number):int
                {
                        COMPILE::SWF
                        {
-                               return textField.getCharIndexAtPoint(stageX, 
stageY);
+                               var pt:Point = 
textField.parent.localToGlobal(new Point(localX,localY));
+                               return textField.getCharIndexAtPoint(pt.x, 
pt.y);
                        }
                        COMPILE::JS
                        {
-                               var pt:Point = new Point(stageX, stageY);
-                               pt = PointUtils.globalToLocal(pt, this);
+                               var pt:Point = new Point(localX, localY);
+                               // pt = PointUtils.globalToLocal(pt, this);
                                var s:String = element.firstChild.textContent;
                                if (s === "") return 0;
                                // pick a starting point for which atom it 
might be.

Reply via email to