Ticket #5528: 5528.2.patch

File 5528.2.patch, 9.6 KB (added by Alfonso Martínez de Lizarrondo, 13 years ago)

Proposed patch

  • _source/core/dom/element.js

     
    11181118                 */
    11191119                setStyle : function( name, value )
    11201120                {
     1121                        // Update the DOM style
    11211122                        this.$.style[ CKEDITOR.tools.cssStyleToDomStyle( name ) ] = value;
     1123
     1124                        // Invalidate the stored style
     1125                        // TODO: update correctly
     1126                        this.removeAttribute( '_cke_saved_style' );
    11221127                        return this;
    11231128                },
    11241129
  • _source/core/tools.js

     
    1 /*
     1/*
    22Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
    33For licensing, see LICENSE.html or http://ckeditor.com/license
    44*/
     
    346346                },
    347347
    348348                /**
     349                 * Try to avoid differences in the style attribute
     350                 * @param {String} The style data to be normalized
     351                 * @param {Boolean} Parse the data using the browser
     352                 * @returns {String} The normalized value.
     353                 */
     354                normalizeCssText : function( unparsedCssText, nativeNormalize )
     355                {
     356                        var styleText;
     357                        if ( nativeNormalize !== false )
     358                        {
     359                                // Injects the style in a temporary span object, so the browser parses it,
     360                                // retrieving its final format.
     361                                var temp = new CKEDITOR.dom.element( 'span' );
     362                                temp.setAttribute( 'style', unparsedCssText );
     363                                styleText = temp.getAttribute( 'style' ) || '';
     364                        }
     365                        else
     366                                styleText = unparsedCssText;
     367
     368                        if ( !styleText )
     369                                return styleText;
     370
     371                        // Lowercase properties in IE #5930
     372                        CKEDITOR.env.ie && ( styleText = styleText.replace( /(?:(^\s*|;\s*)([^\:]+))/g, function( match, separator, name )
     373                                                {
     374                                                                return separator + name.toLowerCase();
     375                                                }) );
     376
     377                        styleText = CKEDITOR.tools.convertRGBToHex( styleText );
     378
     379                        // Shrinking white-spaces around colon and semi-colon (#4147).
     380                        // Compensate tail semi-colon.
     381                        return styleText.replace( /\s*([;:])\s*/g, '$1' )
     382                                                                .replace( /;$/, '')
     383                                                                // Trimming spaces after comma (e.g. font-family name)(#4107).
     384                                                                .replace( /,\s+/g, ',' );
     385                },
     386
     387                /**
     388                * Convert a CSS rgb(R, G, B) color back to #RRGGBB format.
     389                 * @param Css style string (can include more than one color
     390                 * @return Converted css style.
     391                */
     392                convertRGBToHex : function( cssStyle )
     393                {
     394                        return cssStyle.replace( /(?:rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\))/gi, function( match, red, green, blue )
     395                                {
     396                                        red = parseInt( red, 10 ).toString( 16 );
     397                                        green = parseInt( green, 10 ).toString( 16 );
     398                                        blue = parseInt( blue, 10 ).toString( 16 );
     399                                        var color = [red, green, blue] ;
     400
     401                                        // Add padding zeros if the hex value is less than 0x10.
     402                                        for ( var i = 0 ; i < color.length ; i++ )
     403                                                color[i] = String( '0' + color[i] ).slice( -2 ) ;
     404
     405                                        return '#' + color.join( '' ) ;
     406                                });
     407                },
     408
     409                /**
    349410                 * Gets a unique number for this CKEDITOR execution session. It returns
    350411                 * progressive numbers starting at 1.
    351412                 * @function
  • _source/plugins/htmldataprocessor/plugin.js

     
    4343        // 1. For IE version >=8,  empty blocks are displayed correctly themself in wysiwiyg;
    4444        // 2. For the rest, at least table cell and list item need no filler space.
    4545        // (#6248)
    46         if ( fromSource && CKEDITOR.env.ie && 
     46        if ( fromSource && CKEDITOR.env.ie &&
    4747                ( document.documentMode > 7
    4848                || block.name in CKEDITOR.dtd.tr
    4949                || block.name in CKEDITOR.dtd.$listItem ) )
     
    7979                        block.add( new CKEDITOR.htmlParser.text( '\xa0' ) );
    8080        }
    8181
     82        // The current style might have updated values for position or size if the user
     83        // has manually resized or moved an absolutely positioned element
     84        function updateStyles( current, saved)
     85        {
     86                // Properties that we want to update
     87                // these ones aren't "distorted" or destroyed by the browsers like what happens with "background"
     88                // or vendor specific prefixes (-moz, -o, -webkit, -ms)
     89                // So we get them from the current style and replace them in the saved style
     90                var properties = [ 'width', 'height', 'top', 'left', 'right', 'bottom' ],
     91                        propertyReg,
     92                        partialStyle = '';
     93
     94                for ( var i = 0 ; i < properties.length ; i++ )
     95                {
     96                        propertyReg = new RegExp( '(?:^|;)\s*(' + properties[ i ] + '\s*:.+)(?:$|;)', 'i') ;
     97                        var match = current.match( propertyReg );
     98                        match && ( partialStyle += ';' + match[ 1 ] );
     99                        saved = saved.replace( propertyReg, '' );
     100                }
     101
     102                // Combine the old and current styles and clean up extra semi-colons
     103                return ( saved + CKEDITOR.tools.normalizeCssText( partialStyle ) )
     104                                .replace( /;+/g, ';' )
     105                                .replace( /(^;|;$)/, '' );
     106        }
     107
    82108        var dtd = CKEDITOR.dtd;
    83109
    84110        // Find out the list of block-like tags that can contain <br>.
     
    149175                                                        savedAttributeName = '_cke_saved_' + attributeNames[ i ];
    150176                                                        savedAttributeName in attribs && ( delete attribs[ attributeNames[ i ] ] );
    151177                                                }
     178                                                // Process style
     179                                                if ( '_cke_saved_style' in attribs )
     180                                                {
     181                                                        // Size might have been adjusted by manually resizing the object, also position of absolutely positioned elements
     182                                                        attribs[ 'style' ] = updateStyles( attribs[ 'style' ], attribs[ '_cke_saved_style' ]);
     183                                                        delete attribs[ '_cke_saved_style' ];
     184                                                }
     185                                                else
     186                                                {
     187                                                        // Process to generate normalized output
     188                                                        attribs[ 'style' ] && (attribs[ 'style' ] = CKEDITOR.tools.normalizeCssText( attribs[ 'style' ], false ));
     189                                                }
    152190                                        }
    153191
    154192                                        return element;
     
    247285        for ( i in blockLikeTags )
    248286                defaultHtmlBlockFilterRules.elements[ i ] = extendBlockForOutput;
    249287
    250         if ( CKEDITOR.env.ie )
    251         {
    252                 // IE outputs style attribute in capital letters. We should convert
    253                 // them back to lower case.
    254                 defaultHtmlFilterRules.attributes.style = function( value, element )
    255                 {
    256                         return value.toLowerCase();
    257                 };
    258         }
    259 
    260288        function protectReadOnly( element )
    261289        {
    262290                element.attributes.contenteditable = "false";
     
    273301        }
    274302
    275303        var protectAttributeRegex = /<((?:a|area|img|input)[\s\S]*?\s)((href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+)))([^>]*)>/gi,
     304                protectStyleRegex = /\s(style\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+)))/gi,
    276305                findSavedSrcRegex = /\s_cke_saved_src\s*=/;
    277306
    278307        var protectElementsRegex = /(?:<style(?=[ >])[^>]*>[\s\S]*<\/style>)|(?:<(:?link|meta|base)[^>]*>)/gi,
     
    285314
    286315        function protectAttributes( html )
    287316        {
    288                 return html.replace( protectAttributeRegex, function( tag, beginning, fullAttr, attrName, end )
     317                html = html.replace( protectAttributeRegex, function( tag, beginning, fullAttr, attrName, end )
    289318                        {
    290319                                // We should not rewrite the _cke_saved_src attribute (#5218)
    291320                                if ( attrName == 'src' && findSavedSrcRegex.test( tag ) )
     
    293322                                else
    294323                                        return '<' + beginning + fullAttr + ' _cke_saved_' + fullAttr + end + '>';
    295324                        });
     325
     326                return html.replace( protectStyleRegex, '$& _cke_saved_$1' );
    296327        }
    297328
    298329        function protectElements( html )
  • _source/plugins/styles/plugin.js

     
    1 /*
     1/*
    22Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
    33For licensing, see LICENSE.html or http://ckeditor.com/license
    44*/
     
    231231
    232232                                                // Special treatment for 'style' attribute is required.
    233233                                                if ( attName == 'style' ?
    234                                                         compareCssText( attribs[ attName ], normalizeCssText( elementAttr, false ) )
     234                                                        compareCssText( attribs[ attName ], CKEDITOR.tools.normalizeCssText( elementAttr, false ) )
    235235                                                        : attribs[ attName ] == elementAttr  )
    236236                                                {
    237237                                                        if ( !fullMatch )
     
    345345                // Browsers make some changes to the style when applying them. So, here
    346346                // we normalize it to the browser format.
    347347                if ( stylesText.length )
    348                         stylesText = normalizeCssText( stylesText );
     348                        stylesText = CKEDITOR.tools.normalizeCssText( stylesText );
    349349
    350350                stylesText += specialStylesText;
    351351
     
    12871287                return temp[ isStyle ? 'getStyle' : 'getAttribute' ]( name );
    12881288        }
    12891289
    1290         // Make the comparison of style text easier by standardizing it.
    1291         function normalizeCssText( unparsedCssText, nativeNormalize )
    1292         {
    1293                 var styleText;
    1294                 if ( nativeNormalize !== false )
    1295                 {
    1296                         // Injects the style in a temporary span object, so the browser parses it,
    1297                         // retrieving its final format.
    1298                         var temp = new CKEDITOR.dom.element( 'span' );
    1299                         temp.setAttribute( 'style', unparsedCssText );
    1300                         styleText = temp.getAttribute( 'style' ) || '';
    1301                 }
    1302                 else
    1303                         styleText = unparsedCssText;
    1304 
    1305                 // Shrinking white-spaces around colon and semi-colon (#4147).
    1306                 // Compensate tail semi-colon.
    1307                 return styleText.replace( /\s*([;:])\s*/, '$1' )
    1308                                                          .replace( /([^\s;])$/, '$1;')
    1309                                                         // Trimming spaces after comma(#4107),
    1310                                                         // remove quotations(#6403),
    1311                                                         // mostly for differences on "font-family".
    1312                                                          .replace( /,\s+/g, ',' )
    1313                                                          .replace( /\"/g,'' )
    1314                                                          .toLowerCase();
    1315         }
    1316 
    13171290        // Turn inline style text properties into one hash.
    13181291        function parseStyleText( styleText )
    13191292        {
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy