Changeset 209682 in webkit


Ignore:
Timestamp:
Dec 11, 2016 10:10:03 AM (7 years ago)
Author:
mitz@apple.com
Message:

[Cocoa] NSAttributedString representation of text copied from -webkit-nbsp-mode:space element contains non-breaking space characters, but shouldn’t
https://bugs.webkit.org/show_bug.cgi?id=165515
<rdar://problem/4108460>

Reviewed by Darin Adler.

Source/WebCore:

Test: platform/mac/fast/text/attributed-substring-from-range.html

  • editing/cocoa/HTMLConverter.mm:

(HTMLConverter::_processText): Emit a space instead of a non-breaking space if the text node

is styled with -webkit-nbsp-mode:space.

(WebCore::editingAttributedStringFromRange): Replace all non-breaking spaces with spaces if

they come from a text node with -webkit-nbsp-mode:space.

LayoutTests:

  • platform/mac/fast/text/attributed-substring-from-range-expected.txt: Updated.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r209677 r209682  
     12016-12-11  Dan Bernstein  <mitz@apple.com>
     2
     3        [Cocoa] NSAttributedString representation of text copied from -webkit-nbsp-mode:space element contains non-breaking space characters, but shouldn’t
     4        https://bugs.webkit.org/show_bug.cgi?id=165515
     5        <rdar://problem/4108460>
     6
     7        Reviewed by Darin Adler.
     8
     9        * platform/mac/fast/text/attributed-substring-from-range-expected.txt: Updated.
     10
    1112016-12-10  Simon Fraser  <simon.fraser@apple.com>
    212
  • trunk/LayoutTests/platform/mac/fast/text/attributed-substring-from-range-expected.txt

    r25367 r209682  
    1414total length: 15
    1515one space: " "
    16 two spaces: "  "
    17 three spaces: "   "
    18 four spaces: "    "
     16two spaces: "  "
     17three spaces: "   "
     18four spaces: "    "
    1919
    2020Testing space-only runs (1..2...3....4.5)
  • trunk/Source/WebCore/ChangeLog

    r209680 r209682  
     12016-12-11  Dan Bernstein  <mitz@apple.com>
     2
     3        [Cocoa] NSAttributedString representation of text copied from -webkit-nbsp-mode:space element contains non-breaking space characters, but shouldn’t
     4        https://bugs.webkit.org/show_bug.cgi?id=165515
     5        <rdar://problem/4108460>
     6
     7        Reviewed by Darin Adler.
     8
     9        Test: platform/mac/fast/text/attributed-substring-from-range.html
     10
     11        * editing/cocoa/HTMLConverter.mm:
     12        (HTMLConverter::_processText): Emit a space instead of a non-breaking space if the text node
     13          is styled with -webkit-nbsp-mode:space.
     14        (WebCore::editingAttributedStringFromRange): Replace all non-breaking spaces with spaces if
     15          they come from a text node with -webkit-nbsp-mode:space.
     16
    1172016-12-11  Konstantin Tokarev  <annulen@yandex.ru>
    218
  • trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm

    r208565 r209682  
    22372237        bool wasLeading = true;
    22382238        StringBuilder builder;
     2239        LChar noBreakSpaceRepresentation = 0;
    22392240        for (unsigned i = 0; i < count; i++) {
    22402241            UChar c = originalString.at(i);
     
    22452246                if (wasSpace)
    22462247                    builder.append(' ');
    2247                 builder.append(c);
     2248                if (c != noBreakSpace)
     2249                    builder.append(c);
     2250                else {
     2251                    if (!noBreakSpaceRepresentation)
     2252                        noBreakSpaceRepresentation = _caches->propertyValueForNode(characterData, CSSPropertyWebkitNbspMode) == "space" ? ' ' : noBreakSpace;
     2253                    builder.append(noBreakSpaceRepresentation);
     2254                }
    22482255                wasSpace = false;
    22492256                wasLeading = false;
     
    25202527            [attrs.get() removeObjectForKey:NSBackgroundColorAttributeName];
    25212528
    2522         [string replaceCharactersInRange:NSMakeRange(stringLength, 0) withString:it.text().createNSStringWithoutCopying().get()];
     2529        RetainPtr<NSString> text;
     2530        if (style.nbspMode() == NBNORMAL)
     2531            text = it.text().createNSStringWithoutCopying();
     2532        else
     2533            text = it.text().toString().replace(noBreakSpace, ' ');
     2534
     2535        [string replaceCharactersInRange:NSMakeRange(stringLength, 0) withString:text.get()];
    25232536        [string setAttributes:attrs.get() range:NSMakeRange(stringLength, currentTextLength)];
    25242537        stringLength += currentTextLength;
Note: See TracChangeset for help on using the changeset viewer.