Title: [209682] trunk
Revision
209682
Author
[email protected]
Date
2016-12-11 10:10:03 -0800 (Sun, 11 Dec 2016)

Log 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.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (209681 => 209682)


--- trunk/LayoutTests/ChangeLog	2016-12-11 12:48:46 UTC (rev 209681)
+++ trunk/LayoutTests/ChangeLog	2016-12-11 18:10:03 UTC (rev 209682)
@@ -1,3 +1,13 @@
+2016-12-11  Dan Bernstein  <[email protected]>
+
+        [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.
+
+        * platform/mac/fast/text/attributed-substring-from-range-expected.txt: Updated.
+
 2016-12-10  Simon Fraser  <[email protected]>
 
         Support the deprecated dictionary constructor for DOMPointReadOnly and DOMPoint

Modified: trunk/LayoutTests/platform/mac/fast/text/attributed-substring-from-range-expected.txt (209681 => 209682)


--- trunk/LayoutTests/platform/mac/fast/text/attributed-substring-from-range-expected.txt	2016-12-11 12:48:46 UTC (rev 209681)
+++ trunk/LayoutTests/platform/mac/fast/text/attributed-substring-from-range-expected.txt	2016-12-11 18:10:03 UTC (rev 209682)
@@ -13,9 +13,9 @@
 Testing proper space runs (1._2.__3.___4_5)
 total length: 15
 one space: " "
-two spaces: "  "
-three spaces: "   "
-four spaces: "    "
+two spaces: "  "
+three spaces: "   "
+four spaces: "    "
 
 Testing space-only runs (1..2...3....4.5)
 total length: 9

Modified: trunk/Source/WebCore/ChangeLog (209681 => 209682)


--- trunk/Source/WebCore/ChangeLog	2016-12-11 12:48:46 UTC (rev 209681)
+++ trunk/Source/WebCore/ChangeLog	2016-12-11 18:10:03 UTC (rev 209682)
@@ -1,3 +1,19 @@
+2016-12-11  Dan Bernstein  <[email protected]>
+
+        [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.
+
+        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.
+
 2016-12-11  Konstantin Tokarev  <[email protected]>
 
         Unreviewed, add KHR include dir to fix ANGLE build after r209665

Modified: trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm (209681 => 209682)


--- trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm	2016-12-11 12:48:46 UTC (rev 209681)
+++ trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm	2016-12-11 18:10:03 UTC (rev 209682)
@@ -2236,6 +2236,7 @@
         unsigned count = originalString.length();
         bool wasLeading = true;
         StringBuilder builder;
+        LChar noBreakSpaceRepresentation = 0;
         for (unsigned i = 0; i < count; i++) {
             UChar c = originalString.at(i);
             bool isWhitespace = c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == 0xc || c == 0x200b;
@@ -2244,7 +2245,13 @@
             else {
                 if (wasSpace)
                     builder.append(' ');
-                builder.append(c);
+                if (c != noBreakSpace)
+                    builder.append(c);
+                else {
+                    if (!noBreakSpaceRepresentation)
+                        noBreakSpaceRepresentation = _caches->propertyValueForNode(characterData, CSSPropertyWebkitNbspMode) == "space" ? ' ' : noBreakSpace;
+                    builder.append(noBreakSpaceRepresentation);
+                }
                 wasSpace = false;
                 wasLeading = false;
             }
@@ -2519,7 +2526,13 @@
         else
             [attrs.get() removeObjectForKey:NSBackgroundColorAttributeName];
 
-        [string replaceCharactersInRange:NSMakeRange(stringLength, 0) withString:it.text().createNSStringWithoutCopying().get()];
+        RetainPtr<NSString> text;
+        if (style.nbspMode() == NBNORMAL)
+            text = it.text().createNSStringWithoutCopying();
+        else
+            text = it.text().toString().replace(noBreakSpace, ' ');
+
+        [string replaceCharactersInRange:NSMakeRange(stringLength, 0) withString:text.get()];
         [string setAttributes:attrs.get() range:NSMakeRange(stringLength, currentTextLength)];
         stringLength += currentTextLength;
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to