Ticket #3304: 3304_5.patch

File 3304_5.patch, 11.4 KB (added by Garry Yao, 15 years ago)
  • _source/plugins/find/dialogs/find.js

     
    55
    66(function()
    77{
    8         // Element tag names which prevent characters counting.
    9         var characterBoundaryElementsEnum =
     8        function guardDomWalkerNonEmptyTextNode( node )
    109        {
    11                 address :1, blockquote :1, dl :1, h1 :1, h2 :1, h3 :1,
    12                 h4 :1, h5 :1, h6 :1, p :1, pre :1, li :1, dt :1, de :1, div :1, td:1, th:1
    13         };
     10                if ( node.type == CKEDITOR.NODE_TEXT && node.$.length > 0 )
     11                        return true;
     12                else
     13                        return false;
     14        }
    1415
    15         var guardDomWalkerNonEmptyTextNode = function( evt )
     16        /**
     17         * Elements which break characters been considered as sequence.
     18        */
     19        function checkCharactersBoundary ( node )
    1620        {
    17                 if ( evt.data.to && evt.data.to.type == CKEDITOR.NODE_TEXT
    18                         && evt.data.to.$.length > 0 )
    19                         this.stop();
    20                 CKEDITOR.dom.domWalker.blockBoundary( { br : 1 } ).call( this, evt );
    21         };
    22 
     21                var dtd = CKEDITOR.dtd;
     22                return node.isBlockBoundary(
     23                        CKEDITOR.tools.extend( {}, dtd.$empty, dtd.$nonEditable ) );
     24        }
    2325
    2426        /**
    2527         * Get the cursor object which represent both current character and it's dom
     
    7577                 * Iterator which walk through document char by char.
    7678                 * @param {Object} start
    7779                 * @param {Number} offset
     80                 * @param {Boolean} isStrict
    7881                 */
    79                 var characterWalker = function( start, offset )
     82                var characterWalker = function( start, offset , isStrict )
    8083                {
    8184                        var isCursor = typeof( start.textNode ) !== 'undefined';
    8285                        this.textNode = isCursor ? start.textNode : start;
     
    8184                        var isCursor = typeof( start.textNode ) !== 'undefined';
    8285                        this.textNode = isCursor ? start.textNode : start;
    8386                        this.offset = isCursor ? start.offset : offset;
     87                        var walker = new CKEDITOR.dom.walker( this.textNode );
     88                        walker[ isStrict? 'guard' : 'evaluator' ] =
     89                                guardDomWalkerNonEmptyTextNode;
    8490                        this._ = {
    85                                 walker : new CKEDITOR.dom.domWalker( this.textNode ),
     91                                walker : walker,
    8692                                matchBoundary : false
    8793                        };
    8894                };
     
    107113
    108114                                // If we are at the end of the text node, use dom walker to get
    109115                                // the next text node.
    110                                 var data = null;
    111                                 while ( !data || ( data.node && data.node.type !=
    112                                         CKEDITOR.NODE_TEXT ) )
     116                                var node = null;
     117                                while ( !node )
    113118                                {
    114                                         data = this._.walker.forward(
    115                                                 guardDomWalkerNonEmptyTextNode );
     119                                        node = this._.walker.next( true );
    116120
    117                                         // Block boundary? BR? Document boundary?
    118                                         if ( !data.node
    119                                                 || ( data.node.type !== CKEDITOR.NODE_TEXT
    120                                                         && data.node.getName() in
    121                                                         characterBoundaryElementsEnum ) )
     121                                        // Marking as match boundaries.
     122                                        if( node === false
     123                                           && checkCharactersBoundary( this._.walker.current ) )
    122124                                                this._.matchBoundary = true;
     125                                        // Already reach document end.
     126                                        if ( !this._.walker.current )
     127                                                break;
     128                                       
    123129                                }
    124                                 this.textNode = data.node;
     130                                this.textNode = node;
    125131                                this.offset = 0;
    126132                                return cursorStep.call( this );
    127133                        },
     
    138144                                }
    139145
    140146                                // Start of text node -> use dom walker to get the previous text node.
    141                                 var data = null;
    142                                 while ( !data
    143                                 || ( data.node && data.node.type != CKEDITOR.NODE_TEXT ) )
     147                                var node = null;
     148                                while ( !node )
    144149                                {
    145                                         data = this._.walker.reverse( guardDomWalkerNonEmptyTextNode );
     150                                        node = this._.walker.previous( true );
    146151
    147                                         // Block boundary? BR? Document boundary?
    148                                         if ( !data.node || ( data.node.type !== CKEDITOR.NODE_TEXT &&
    149                                         data.node.getName() in characterBoundaryElementsEnum ) )
     152                                        // Marking as match boundaries.
     153                                        if( node === false
     154                                                && checkCharactersBoundary( this._.walker.current ) )
    150155                                                this._.matchBoundary = true;
     156                                       
     157                                        // Already reach document end.
     158                                        if ( !this._.walker.current )
     159                                                break;
    151160                                }
    152                                 this.textNode = data.node;
    153                                 this.offset = data.node.length - 1;
     161                                this.textNode = node;
     162                                this.offset = node.length - 1;
    154163                                return cursorStep.call( this );
    155164                        }
    156165                };
     
    465474                                                        var cursors = this.range.getCursors(),
    466475                                                                tail = cursors[ cursors.length - 1 ],
    467476                                                                head = cursors[ 0 ],
    468                                                                 headWalker = new characterWalker( head ),
    469                                                                 tailWalker = new characterWalker( tail );
     477                                                                headWalker = new characterWalker( head, null, true ),
     478                                                                tailWalker = new characterWalker( tail, null, true );
    470479
    471480                                                        if ( ! ( isWordSeparator(
    472481                                                                                headWalker.back().character )
  • _source/core/loader.js

     
    3939                        'core/dom/node'                 : [ 'core/dom/domobject', 'core/tools' ],
    4040                        'core/dom/nodelist'             : [ 'core/dom/node' ],
    4141                        'core/dom/domobject'    : [ 'core/dom/event' ],
    42                         'core/dom/domwalker'    : [ 'core/dom/node', 'core/dom/element', 'core/dom/document' ],
    43                         'core/dom/range'                : [ 'core/dom/document', 'core/dom/documentfragment', 'core/dom/element', 'core/dom/domwalker', 'core/dom/walker' ],
     42                        'core/dom/range'                : [ 'core/dom/document', 'core/dom/documentfragment', 'core/dom/element', 'core/dom/walker' ],
    4443                        'core/dom/text'                 : [ 'core/dom/node', 'core/dom/domobject' ],
    4544                        'core/dom/walker'               : [ 'core/dom/node' ],
    4645                        'core/dom/window'               : [ 'core/dom/domobject' ],
  • _source/core/dom/range.js

     
    366366                 */
    367367                createBookmark : function( serializable )
    368368                {
    369                         var startNode, endNode;
     369                        var bookmark, startNode, endNode;
    370370                        var baseId;
    371371                        var clone;
    372372
     
    410410                        }
    411411                        else
    412412                                this.moveToPosition( startNode, CKEDITOR.POSITION_AFTER_END );
    413 
    414                         return {
     413                       
     414                        return ( bookmark = {
    415415                                startNode : serializable ? baseId + 'S' : startNode,
    416416                                endNode : serializable ? baseId + 'E' : endNode,
    417                                 serializable : serializable
    418                         };
     417                                serializable : serializable,
     418
     419                                /**
     420                                 * Drop the bookmark nodes from the document when
     421                                 * 'moveToBookmark' is never invoked since it's been
     422                                 * used as marker node.
     423                                 */
     424                                destroy : CKEDITOR.tools.bind( function()
     425                                {
     426                                        var bm = this.createBookmark();
     427                                        this.moveToBookmark( bookmark );
     428                                        this.moveToBookmark( bm );
     429                                }, this )
     430                        } );
    419431                },
    420432
    421433                /**
     
    10881100                                case CKEDITOR.ENLARGE_BLOCK_CONTENTS:
    10891101                                case CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS:
    10901102                                        // DFS backward to get the block/list item boundary at or before the start.
    1091 
    1092                                         // Get the boundaries nodes.
    1093                                         var startNode = this.getTouchedStartNode(),
    1094                                                 endNode = this.getTouchedEndNode();
    1095 
    1096                                         if ( startNode.type == CKEDITOR.NODE_ELEMENT && startNode.isBlockBoundary() )
    1097                                         {
    1098                                                 this.setStartAt( startNode,
    1099                                                         CKEDITOR.dtd.$empty[ startNode.getName() ] ?
    1100                                                                 CKEDITOR.POSITION_AFTER_END :
    1101                                                                 CKEDITOR.POSITION_AFTER_START );
    1102                                         }
    1103                                         else
    1104                                         {
    1105                                                 // Get the function used to check the enlaarging limits.
    1106                                                 var guardFunction = ( unit == CKEDITOR.ENLARGE_BLOCK_CONTENTS ?
    1107                                                                 CKEDITOR.dom.domWalker.blockBoundary() :
    1108                                                                 CKEDITOR.dom.domWalker.listItemBoundary() );
     1103                                        // Get the outter boundaries nodes.
     1104                                        var startNode, endNode;
     1105                                       
     1106                                        // Establish boundaries by bookmark nodes.
     1107                                        var bm = this.createBookmark();
     1108                                        startNode= bm.startNode;
     1109                                        endNode = bm.endNode || startNode;
    11091110
    1110                                                 // Create the DOM walker, which will traverse the DOM.
    1111                                                 var walker = new CKEDITOR.dom.domWalker( startNode );
     1111                                        // Enlarging the start and end boundary.
     1112                                        var walker = new CKEDITOR.dom.walker( startNode ),
     1113                                        enlargeable,
     1114                                        blockGuard = 
     1115                                                CKEDITOR.dom.walker.blockBoundary(
     1116                                                        CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ? { br : 1 } : null );
     1117                                        walker.guard = blockGuard;
    11121118
    1113                                                 // Go walk in reverse sense.
    1114                                                 var data = walker.reverse( guardFunction );
    1115 
    1116                                                 var boundaryEvent = data.events.shift();
    1117 
    1118                                                 this.setStartBefore( boundaryEvent.from );
    1119                                         }
     1119                                        // If we don't care BR, the walker could only check siblings
     1120                                        // since block could never be berried as children of inline elements.
     1121                                        if ( !CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS )
     1122                                                walker.startFromSibling = true;
     1123                                        if ( enlargeable = walker.lastBackward() )
     1124                                                this.setStartAt( enlargeable, CKEDITOR.POSITION_BEFORE_START );
    11201125
    1121                                         if ( endNode.type == CKEDITOR.NODE_ELEMENT && endNode.isBlockBoundary() )
    1122                                         {
    1123                                                 this.setEndAt( endNode,
    1124                                                         CKEDITOR.dtd.$empty[ endNode.getName() ] ?
    1125                                                                 CKEDITOR.POSITION_BEFORE_START :
    1126                                                                 CKEDITOR.POSITION_BEFORE_END );
    1127                                         }
    1128                                         else
    1129                                         {
    1130                                                 // DFS forward to get the block/list item boundary at or before the end.
    1131                                                 walker.setNode( endNode );
    1132                                                 data = walker.forward( guardFunction );
    1133                                                 boundaryEvent = data.events.shift();
     1126                                        walker.reset();
     1127                                        walker.startNode = endNode;
     1128                                        if ( enlargeable = walker.lastForward() )
     1129                                                this.setEndAt( enlargeable, CKEDITOR.POSITION_AFTER_END );
    11341130
    1135                                                 this.setEndAfter( boundaryEvent.from );
    1136                                         }
     1131                                        bm.destroy();
    11371132                        }
    11381133                },
    11391134
  • _source/core/dom/walker.js

     
    4444                                node = null;
    4545                }
    4646                else
    47                         node = this.startNode[ getSourceNodeFn ]( true, type, guard );
     47                        node = this.startNode[ getSourceNodeFn ]( false, type, guard );
    4848
    4949                while ( node && !this._.end )
    5050                {
     
    217217                        checkBackward : function()
    218218                        {
    219219                                return iterate.call( this, true, true ) !== false;
     220                        },
     221                       
     222                        /**
     223                         * Reset walker to initial state.
     224                         */
     225                        reset : function()
     226                        {
     227                                delete this._.end;
     228                                delete this.current;
    220229                        }
    221230                }
    222231        });
     232
     233        /*
     234         * Anything whose display computed style is block, list-item, table,
     235         * table-row-group, table-header-group, table-footer-group, table-row,
     236         * table-column-group, table-column, table-cell, table-caption, or whose node
     237         * name is hr, br (when enterMode is br only) is a block boundary.
     238         */
     239        var blockBoundaryDisplayMatch =
     240        {
     241                block : 1,
     242                'list-item' : 1,
     243                table : 1,
     244                'table-row-group' : 1,
     245                'table-header-group' : 1,
     246                'table-footer-group' : 1,
     247                'table-row' : 1,
     248                'table-column-group' : 1,
     249                'table-column' : 1,
     250                'table-cell' : 1,
     251                'table-caption' : 1
     252        },
     253        blockBoundaryNodeNameMatch = { hr : 1 };
     254
     255        CKEDITOR.dom.element.prototype.isBlockBoundary = function( customNodeNames )
     256        {
     257                var nodeNameMatches = CKEDITOR.tools.extend(
     258                        blockBoundaryNodeNameMatch, customNodeNames || {} );
     259
     260                return blockBoundaryDisplayMatch[ this.getComputedStyle( 'display' ) ] ||
     261                        nodeNameMatches[ this.getName() ];
     262        };
     263
     264        CKEDITOR.dom.walker.blockBoundary = function( customNodeNames )
     265        {
     266                return function( node , type )
     267                {
     268                        return ! ( node.type == CKEDITOR.NODE_ELEMENT
     269                                                && node.isBlockBoundary( customNodeNames ) );
     270                };
     271        };
     272       
     273        CKEDITOR.dom.walker.listItemBoundary = function()
     274        {
     275                        return this.blockBoundary( { br : 1 } );
     276        };
     277
    223278})();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy