Title: [249535] trunk
Revision
249535
Author
[email protected]
Date
2019-09-05 10:44:38 -0700 (Thu, 05 Sep 2019)

Log Message

REGRESSION (iOS 13): Bulleted list copied from Notes to Mail results in Times New Roman
https://bugs.webkit.org/show_bug.cgi?id=201490

Reviewed by Daniel Bates.

Source/WebCore:

The bug was caused by an element in the pasted content not having any explicit font name resolving
to use the font-family value of `-webkit-standard`. When such an inline style is inserted into
Mail's WKWebView which sets a different font family, ReplaceSelectionCommand would fail to strip away,
making the pasted content using the default font family of Times New Roman.

Fixed the bug by stripping away font-family set to -webkit-standard in the sanitization document
since that's indicative of the pasted content not having any font family being specified.

In the future, we should consider making regular copy (as opposed to the copy for sanitization)
resolve generic font family names to concrete font names since different WKWebView might be using
different concrete font names. Unfortuantely, such a change is quite involved and risky since various
paste side code in EditingStyle that removes redundant inline styles (i.e. redundant `font-family`)
need to be aware of this special font family resolution.

Tests: editing/pasteboard/paste-cocoa-writer-markup-with-webkit-standard-font-family.html
       PasteHTML.DoesNotAddStandardFontFamily

* editing/EditingStyle.cpp:
(WebCore::EditingStyle::mergeInlineAndImplicitStyleOfElement):
(WebCore::EditingStyle::wrappingStyleForSerialization):
(WebCore::familyNameFromCSSPrimitiveValue): Added.
(WebCore::loneFontFamilyName): Extracted from usesForbiddenSystemFontAsOnlyFontFamilyName. Fixed
a bug that it was not handling the case when `font-family` property's value is a CSSPrimitiveValue
instead of a CSSValueList.
(WebCore::usesForbiddenSystemFontAsOnlyFontFamilyName): Deleted.
(WebCore::EditingStyle::mergeStyleFromRulesForSerialization): Remove `font-family` property when
StandardFontFamilySerializationMode::Strip is specified and its value is `-webkit-standard`.
* editing/EditingStyle.h:
* editing/markup.cpp:
(WebCore::StyledMarkupAccumulator::StyledMarkupAccumulator): Added
StandardFontFamilySerializationMode as an argument.
(WebCore::StyledMarkupAccumulator::appendStartTag):
(WebCore::StyledMarkupAccumulator::serializeNodes):
(WebCore::serializePreservingVisualAppearanceInternal): Ditto.
(WebCore::serializePreservingVisualAppearance): Use StandardFontFamilySerializationMode::Keep
to preserve the pre-existing behavior.
(WebCore::sanitizedMarkupForFragmentInDocument): Use StandardFontFamilySerializationMode::Strip
as this is the code used by sanitization code.

Tools:

Added a test.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm:
* TestWebKitAPI/Tests/WebKitCocoa/cocoa-writer-markup-with-lists.html: Added.

LayoutTests:

Added a test to make sure -webkit-standard font family name isn't stripped away when sanitization is not in effect.

* editing/pasteboard/paste-cocoa-writer-markup-with-webkit-standard-font-family-expected.txt: Added.
* editing/pasteboard/paste-cocoa-writer-markup-with-webkit-standard-font-family.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (249534 => 249535)


--- trunk/LayoutTests/ChangeLog	2019-09-05 17:27:14 UTC (rev 249534)
+++ trunk/LayoutTests/ChangeLog	2019-09-05 17:44:38 UTC (rev 249535)
@@ -1,3 +1,15 @@
+2019-09-05  Ryosuke Niwa  <[email protected]>
+
+        REGRESSION (iOS 13): Bulleted list copied from Notes to Mail results in Times New Roman
+        https://bugs.webkit.org/show_bug.cgi?id=201490
+
+        Reviewed by Daniel Bates.
+
+        Added a test to make sure -webkit-standard font family name isn't stripped away when sanitization is not in effect.
+
+        * editing/pasteboard/paste-cocoa-writer-markup-with-webkit-standard-font-family-expected.txt: Added.
+        * editing/pasteboard/paste-cocoa-writer-markup-with-webkit-standard-font-family.html: Added.
+
 2019-09-05  Chris Fleizach  <[email protected]>
 
         AX: children cache are not re-computed if tab index is removed

Added: trunk/LayoutTests/editing/pasteboard/paste-cocoa-writer-markup-with-webkit-standard-font-family-expected.txt (0 => 249535)


--- trunk/LayoutTests/editing/pasteboard/paste-cocoa-writer-markup-with-webkit-standard-font-family-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/paste-cocoa-writer-markup-with-webkit-standard-font-family-expected.txt	2019-09-05 17:44:38 UTC (rev 249535)
@@ -0,0 +1,12 @@
+This tests pasting a markup with -webkit-standard font family name. WebKit should not strip it away upon paste.
+To manually test, click on "start" first then trigger paste from menu or callout bar or press cmd+v
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS event.clipboardData.getData('text/html') is markup
+PASS editor.innerHTML.includes('-webkit-standard') is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/editing/pasteboard/paste-cocoa-writer-markup-with-webkit-standard-font-family.html (0 => 249535)


--- trunk/LayoutTests/editing/pasteboard/paste-cocoa-writer-markup-with-webkit-standard-font-family.html	                        (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/paste-cocoa-writer-markup-with-webkit-standard-font-family.html	2019-09-05 17:44:38 UTC (rev 249535)
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<body>
+<button id="start">Start</button>
+<div id="editor" style="font-family: Arial" contenteditable>hello</div>
+<script src=""
+<script>
+
+jsTestIsAsync = true;
+
+description(`This tests pasting a markup with -webkit-standard font family name. WebKit should not strip it away upon paste.<br>
+To manually test, click on "start" first then trigger paste from menu or callout bar or press cmd+v`);
+
+const markup = `<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<meta http-equiv="Content-Style-Type" content="text/css">
+<meta name="Generator" content="Cocoa HTML Writer">
+</head>
+<body>
+<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px '-webkit-standard'; color: #454545">Hello</p>
+</body>
+</html>`;
+
+editor.focus();
+start.addEventListener('click', () => {
+    editor.focus();
+    document.execCommand('selectAll');
+    document.execCommand('copy');
+    if (window.testRunner)
+        document.execCommand('paste');
+});
+editor.addEventListener('copy', (event) => {
+    event.clipboardData.setData('text/html', markup);
+    event.preventDefault();
+});
+editor.addEventListener('paste', (event) => {
+    shouldBe(`event.clipboardData.getData('text/html')`, `markup`);
+    document.execCommand('insertHTML', false, event.clipboardData.getData('text/html'));
+    shouldBeTrue(`editor.innerHTML.includes('-webkit-standard')`);
+    editor.innerHTML = '';
+    event.preventDefault();
+    start.style.display = 'none';
+    finishJSTest();
+});
+
+if (window.testRunner)
+    start.click();
+
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (249534 => 249535)


--- trunk/Source/WebCore/ChangeLog	2019-09-05 17:27:14 UTC (rev 249534)
+++ trunk/Source/WebCore/ChangeLog	2019-09-05 17:44:38 UTC (rev 249535)
@@ -1,3 +1,49 @@
+2019-09-05  Ryosuke Niwa  <[email protected]>
+
+        REGRESSION (iOS 13): Bulleted list copied from Notes to Mail results in Times New Roman
+        https://bugs.webkit.org/show_bug.cgi?id=201490
+
+        Reviewed by Daniel Bates.
+
+        The bug was caused by an element in the pasted content not having any explicit font name resolving
+        to use the font-family value of `-webkit-standard`. When such an inline style is inserted into
+        Mail's WKWebView which sets a different font family, ReplaceSelectionCommand would fail to strip away,
+        making the pasted content using the default font family of Times New Roman.
+
+        Fixed the bug by stripping away font-family set to -webkit-standard in the sanitization document
+        since that's indicative of the pasted content not having any font family being specified.
+
+        In the future, we should consider making regular copy (as opposed to the copy for sanitization)
+        resolve generic font family names to concrete font names since different WKWebView might be using
+        different concrete font names. Unfortuantely, such a change is quite involved and risky since various
+        paste side code in EditingStyle that removes redundant inline styles (i.e. redundant `font-family`)
+        need to be aware of this special font family resolution.
+
+        Tests: editing/pasteboard/paste-cocoa-writer-markup-with-webkit-standard-font-family.html
+               PasteHTML.DoesNotAddStandardFontFamily
+
+        * editing/EditingStyle.cpp:
+        (WebCore::EditingStyle::mergeInlineAndImplicitStyleOfElement):
+        (WebCore::EditingStyle::wrappingStyleForSerialization):
+        (WebCore::familyNameFromCSSPrimitiveValue): Added.
+        (WebCore::loneFontFamilyName): Extracted from usesForbiddenSystemFontAsOnlyFontFamilyName. Fixed
+        a bug that it was not handling the case when `font-family` property's value is a CSSPrimitiveValue
+        instead of a CSSValueList.
+        (WebCore::usesForbiddenSystemFontAsOnlyFontFamilyName): Deleted.
+        (WebCore::EditingStyle::mergeStyleFromRulesForSerialization): Remove `font-family` property when
+        StandardFontFamilySerializationMode::Strip is specified and its value is `-webkit-standard`.
+        * editing/EditingStyle.h:
+        * editing/markup.cpp:
+        (WebCore::StyledMarkupAccumulator::StyledMarkupAccumulator): Added
+        StandardFontFamilySerializationMode as an argument.
+        (WebCore::StyledMarkupAccumulator::appendStartTag):
+        (WebCore::StyledMarkupAccumulator::serializeNodes):
+        (WebCore::serializePreservingVisualAppearanceInternal): Ditto.
+        (WebCore::serializePreservingVisualAppearance): Use StandardFontFamilySerializationMode::Keep
+        to preserve the pre-existing behavior.
+        (WebCore::sanitizedMarkupForFragmentInDocument): Use StandardFontFamilySerializationMode::Strip
+        as this is the code used by sanitization code.
+
 2019-09-05  Chris Fleizach  <[email protected]>
 
         AX: children cache are not re-computed if tab index is removed

Modified: trunk/Source/WebCore/editing/EditingStyle.cpp (249534 => 249535)


--- trunk/Source/WebCore/editing/EditingStyle.cpp	2019-09-05 17:27:14 UTC (rev 249534)
+++ trunk/Source/WebCore/editing/EditingStyle.cpp	2019-09-05 17:44:38 UTC (rev 249535)
@@ -1157,10 +1157,10 @@
     return copyEditingProperties(style, AllEditingProperties);
 }
 
-void EditingStyle::mergeInlineAndImplicitStyleOfElement(StyledElement& element, CSSPropertyOverrideMode mode, PropertiesToInclude propertiesToInclude)
+void EditingStyle::mergeInlineAndImplicitStyleOfElement(StyledElement& element, CSSPropertyOverrideMode mode, PropertiesToInclude propertiesToInclude, StandardFontFamilySerializationMode standardFontFamilySerializationMode)
 {
     auto styleFromRules = EditingStyle::create();
-    styleFromRules->mergeStyleFromRulesForSerialization(element);
+    styleFromRules->mergeStyleFromRulesForSerialization(element, standardFontFamilySerializationMode);
 
     if (element.inlineStyle())
         styleFromRules->m_mutableStyle->mergeAndOverrideOnConflict(*element.inlineStyle());
@@ -1181,7 +1181,7 @@
     }
 }
 
-Ref<EditingStyle> EditingStyle::wrappingStyleForSerialization(Node& context, bool shouldAnnotate)
+Ref<EditingStyle> EditingStyle::wrappingStyleForSerialization(Node& context, bool shouldAnnotate, StandardFontFamilySerializationMode standardFontFamilySerializationMode)
 {
     if (shouldAnnotate) {
         auto wrappingStyle = EditingStyle::create(&context, EditingStyle::EditingPropertiesInEffect);
@@ -1202,7 +1202,7 @@
     // When not annotating for interchange, we only preserve inline style declarations.
     for (Node* node = &context; node && !node->isDocumentNode(); node = node->parentNode()) {
         if (is<StyledElement>(*node) && !isMailBlockquote(node))
-            wrappingStyle->mergeInlineAndImplicitStyleOfElement(downcast<StyledElement>(*node), EditingStyle::DoNotOverrideValues, EditingStyle::EditingPropertiesInEffect);
+            wrappingStyle->mergeInlineAndImplicitStyleOfElement(downcast<StyledElement>(*node), DoNotOverrideValues, EditingPropertiesInEffect, standardFontFamilySerializationMode);
     }
 
     return wrappingStyle;
@@ -1282,22 +1282,29 @@
     m_mutableStyle = styleFromMatchedRules;
 }
 
-static bool usesForbiddenSystemFontAsOnlyFontFamilyName(CSSValue& value)
+static String familyNameFromCSSPrimitiveValue(const CSSPrimitiveValue& primitiveValue)
 {
+    if (!primitiveValue.isFontFamily())
+        return { };
+    return primitiveValue.fontFamily().familyName;
+}
+
+static String loneFontFamilyName(const CSSValue& value)
+{
+    if (is<CSSPrimitiveValue>(value))
+        return familyNameFromCSSPrimitiveValue(downcast<CSSPrimitiveValue>(value));
+
     if (!is<CSSValueList>(value) || downcast<CSSValueList>(value).length() != 1)
-        return false;
+        return { };
 
     auto& item = *downcast<CSSValueList>(value).item(0);
     if (!is<CSSPrimitiveValue>(item))
-        return false;
+        return { };
 
-    auto& primitiveValue = downcast<CSSPrimitiveValue>(item);
-    if (!primitiveValue.isFontFamily())
-        return false;
-    return FontCache::isSystemFontForbiddenForEditing(primitiveValue.fontFamily().familyName);
+    return familyNameFromCSSPrimitiveValue(downcast<CSSPrimitiveValue>(item));
 }
 
-void EditingStyle::mergeStyleFromRulesForSerialization(StyledElement& element)
+void EditingStyle::mergeStyleFromRulesForSerialization(StyledElement& element, StandardFontFamilySerializationMode standardFontFamilySerializationMode)
 {
     mergeStyleFromRules(element);
 
@@ -1313,8 +1320,11 @@
         for (unsigned i = 0; i < propertyCount; ++i) {
             StyleProperties::PropertyReference property = m_mutableStyle->propertyAt(i);
             CSSValue& value = *property.value();
-            if (property.id() == CSSPropertyFontFamily && usesForbiddenSystemFontAsOnlyFontFamilyName(value)) {
-                shouldRemoveFontFamily = true;
+            if (property.id() == CSSPropertyFontFamily) {
+                auto familyName = loneFontFamilyName(value);
+                if (FontCache::isSystemFontForbiddenForEditing(familyName)
+                    || (standardFontFamilySerializationMode == StandardFontFamilySerializationMode::Strip && familyName == standardFamily))
+                    shouldRemoveFontFamily = true;
                 continue;
             }
             if (!is<CSSPrimitiveValue>(value))

Modified: trunk/Source/WebCore/editing/EditingStyle.h (249534 => 249535)


--- trunk/Source/WebCore/editing/EditingStyle.h	2019-09-05 17:27:14 UTC (rev 249534)
+++ trunk/Source/WebCore/editing/EditingStyle.h	2019-09-05 17:44:38 UTC (rev 249535)
@@ -60,6 +60,9 @@
 
 enum class TextDecorationChange { None, Add, Remove };
 
+// FIXME: "Keep" should be "Resolve" instead and resolve all generic font family names.
+enum class StandardFontFamilySerializationMode : uint8_t { Keep, Strip };
+
 class EditingStyle : public RefCounted<EditingStyle> {
 public:
 
@@ -141,9 +144,9 @@
     void mergeTypingStyle(Document&);
     enum CSSPropertyOverrideMode { OverrideValues, DoNotOverrideValues };
     void mergeInlineStyleOfElement(StyledElement&, CSSPropertyOverrideMode, PropertiesToInclude = AllProperties);
-    static Ref<EditingStyle> wrappingStyleForSerialization(Node& context, bool shouldAnnotate);
+    static Ref<EditingStyle> wrappingStyleForSerialization(Node& context, bool shouldAnnotate, StandardFontFamilySerializationMode);
     void mergeStyleFromRules(StyledElement&);
-    void mergeStyleFromRulesForSerialization(StyledElement&);
+    void mergeStyleFromRulesForSerialization(StyledElement&, StandardFontFamilySerializationMode);
     void removeStyleFromRulesAndContext(StyledElement&, Node* context);
     void removePropertiesInElementDefaultStyle(Element&);
     void forceInline();
@@ -181,7 +184,7 @@
     void extractFontSizeDelta();
     template<typename T> TriState triStateOfStyle(T& styleToCompare, ShouldIgnoreTextOnlyProperties) const;
     bool conflictsWithInlineStyleOfElement(StyledElement&, RefPtr<MutableStyleProperties>* newInlineStyle, EditingStyle* extractedStyle) const;
-    void mergeInlineAndImplicitStyleOfElement(StyledElement&, CSSPropertyOverrideMode, PropertiesToInclude);
+    void mergeInlineAndImplicitStyleOfElement(StyledElement&, CSSPropertyOverrideMode, PropertiesToInclude, StandardFontFamilySerializationMode);
     void mergeStyle(const StyleProperties*, CSSPropertyOverrideMode);
 
     RefPtr<MutableStyleProperties> m_mutableStyle;

Modified: trunk/Source/WebCore/editing/markup.cpp (249534 => 249535)


--- trunk/Source/WebCore/editing/markup.cpp	2019-09-05 17:27:14 UTC (rev 249534)
+++ trunk/Source/WebCore/editing/markup.cpp	2019-09-05 17:44:38 UTC (rev 249535)
@@ -222,7 +222,7 @@
     enum RangeFullySelectsNode { DoesFullySelectNode, DoesNotFullySelectNode };
 
     StyledMarkupAccumulator(const Position& start, const Position& end, Vector<Node*>* nodes, ResolveURLs, SerializeComposedTree,
-        AnnotateForInterchange, MSOListMode, bool needsPositionStyleConversion, Node* highestNodeToBeSerialized = nullptr);
+        AnnotateForInterchange, StandardFontFamilySerializationMode, MSOListMode, bool needsPositionStyleConversion, Node* highestNodeToBeSerialized = nullptr);
 
     Node* serializeNodes(const Position& start, const Position& end);
     void wrapWithNode(Node&, bool convertBlocksToInlines = false, RangeFullySelectsNode = DoesFullySelectNode);
@@ -318,14 +318,15 @@
     RefPtr<EditingStyle> m_wrappingStyle;
     bool m_useComposedTree;
     bool m_needsPositionStyleConversion;
+    StandardFontFamilySerializationMode m_standardFontFamilySerializationMode;
+    bool m_shouldPreserveMSOList;
     bool m_needRelativeStyleWrapper { false };
     bool m_needClearingDiv { false };
-    bool m_shouldPreserveMSOList;
     bool m_inMSOList { false };
 };
 
 inline StyledMarkupAccumulator::StyledMarkupAccumulator(const Position& start, const Position& end, Vector<Node*>* nodes, ResolveURLs urlsToResolve, SerializeComposedTree serializeComposedTree,
-    AnnotateForInterchange annotate, MSOListMode msoListMode, bool needsPositionStyleConversion, Node* highestNodeToBeSerialized)
+    AnnotateForInterchange annotate, StandardFontFamilySerializationMode standardFontFamilySerializationMode, MSOListMode msoListMode, bool needsPositionStyleConversion, Node* highestNodeToBeSerialized)
     : MarkupAccumulator(nodes, urlsToResolve)
     , m_start(start)
     , m_end(end)
@@ -333,6 +334,7 @@
     , m_highestNodeToBeSerialized(highestNodeToBeSerialized)
     , m_useComposedTree(serializeComposedTree == SerializeComposedTree::Yes)
     , m_needsPositionStyleConversion(needsPositionStyleConversion)
+    , m_standardFontFamilySerializationMode(standardFontFamilySerializationMode)
     , m_shouldPreserveMSOList(msoListMode == MSOListMode::Preserve)
 {
 }
@@ -531,7 +533,7 @@
 
         if (shouldAnnotateOrForceInline) {
             if (shouldAnnotate())
-                newInlineStyle->mergeStyleFromRulesForSerialization(downcast<HTMLElement>(*const_cast<Element*>(&element)));
+                newInlineStyle->mergeStyleFromRulesForSerialization(downcast<HTMLElement>(*const_cast<Element*>(&element)), m_standardFontFamilySerializationMode);
 
             if (addDisplayInline)
                 newInlineStyle->forceInline();
@@ -579,7 +581,7 @@
     }
 
     if (m_highestNodeToBeSerialized && m_highestNodeToBeSerialized->parentNode())
-        m_wrappingStyle = EditingStyle::wrappingStyleForSerialization(*m_highestNodeToBeSerialized->parentNode(), shouldAnnotate());
+        m_wrappingStyle = EditingStyle::wrappingStyleForSerialization(*m_highestNodeToBeSerialized->parentNode(), shouldAnnotate(), m_standardFontFamilySerializationMode);
 
     return traverseNodesForSerialization(startNode.get(), pastEnd, NodeTraversalMode::EmitString);
 }
@@ -822,7 +824,7 @@
 }
 
 static String serializePreservingVisualAppearanceInternal(const Position& start, const Position& end, Vector<Node*>* nodes, ResolveURLs urlsToResolve, SerializeComposedTree serializeComposedTree,
-    AnnotateForInterchange annotate, ConvertBlocksToInlines convertBlocksToInlines, MSOListMode msoListMode)
+    AnnotateForInterchange annotate, ConvertBlocksToInlines convertBlocksToInlines, StandardFontFamilySerializationMode standardFontFamilySerializationMode, MSOListMode msoListMode)
 {
     static NeverDestroyed<const String> interchangeNewlineString(MAKE_STATIC_STRING_IMPL("<br class=\"" AppleInterchangeNewline "\">"));
 
@@ -848,7 +850,7 @@
 
     Node* specialCommonAncestor = highestAncestorToWrapMarkup(start, end, *commonAncestor, annotate);
 
-    StyledMarkupAccumulator accumulator(start, end, nodes, urlsToResolve, serializeComposedTree, annotate, msoListMode, needsPositionStyleConversion, specialCommonAncestor);
+    StyledMarkupAccumulator accumulator(start, end, nodes, urlsToResolve, serializeComposedTree, annotate, standardFontFamilySerializationMode, msoListMode, needsPositionStyleConversion, specialCommonAncestor);
 
     Position startAdjustedForInterchangeNewline = start;
     if (annotate == AnnotateForInterchange::Yes && needInterchangeNewlineAfter(visibleStart)) {
@@ -917,13 +919,13 @@
 String serializePreservingVisualAppearance(const Range& range, Vector<Node*>* nodes, AnnotateForInterchange annotate, ConvertBlocksToInlines convertBlocksToInlines, ResolveURLs urlsToReslve)
 {
     return serializePreservingVisualAppearanceInternal(range.startPosition(), range.endPosition(), nodes, urlsToReslve, SerializeComposedTree::No,
-        annotate, convertBlocksToInlines, MSOListMode::DoNotPreserve);
+        annotate, convertBlocksToInlines, StandardFontFamilySerializationMode::Keep, MSOListMode::DoNotPreserve);
 }
 
 String serializePreservingVisualAppearance(const VisibleSelection& selection, ResolveURLs resolveURLs, SerializeComposedTree serializeComposedTree, Vector<Node*>* nodes)
 {
     return serializePreservingVisualAppearanceInternal(selection.start(), selection.end(), nodes, resolveURLs, serializeComposedTree,
-        AnnotateForInterchange::Yes, ConvertBlocksToInlines::No, MSOListMode::DoNotPreserve);
+        AnnotateForInterchange::Yes, ConvertBlocksToInlines::No, StandardFontFamilySerializationMode::Keep, MSOListMode::DoNotPreserve);
 }
 
 
@@ -950,7 +952,7 @@
 
     // SerializeComposedTree::No because there can't be a shadow tree in the pasted fragment.
     auto result = serializePreservingVisualAppearanceInternal(firstPositionInNode(bodyElement.get()), lastPositionInNode(bodyElement.get()), nullptr,
-        ResolveURLs::YesExcludingLocalFileURLsForPrivacy, SerializeComposedTree::No, AnnotateForInterchange::Yes, ConvertBlocksToInlines::No,  msoListMode);
+        ResolveURLs::YesExcludingLocalFileURLsForPrivacy, SerializeComposedTree::No, AnnotateForInterchange::Yes, ConvertBlocksToInlines::No,  StandardFontFamilySerializationMode::Strip, msoListMode);
 
     if (msoListMode == MSOListMode::Preserve) {
         StringBuilder builder;

Modified: trunk/Tools/ChangeLog (249534 => 249535)


--- trunk/Tools/ChangeLog	2019-09-05 17:27:14 UTC (rev 249534)
+++ trunk/Tools/ChangeLog	2019-09-05 17:44:38 UTC (rev 249535)
@@ -1,5 +1,18 @@
 2019-09-05  Ryosuke Niwa  <[email protected]>
 
+        REGRESSION (iOS 13): Bulleted list copied from Notes to Mail results in Times New Roman
+        https://bugs.webkit.org/show_bug.cgi?id=201490
+
+        Reviewed by Daniel Bates.
+
+        Added a test.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm:
+        * TestWebKitAPI/Tests/WebKitCocoa/cocoa-writer-markup-with-lists.html: Added.
+
+2019-09-05  Ryosuke Niwa  <[email protected]>
+
         Remove unused SPI that accesses MemoryCache directly
         https://bugs.webkit.org/show_bug.cgi?id=201468
 

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (249534 => 249535)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-09-05 17:27:14 UTC (rev 249534)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-09-05 17:44:38 UTC (rev 249535)
@@ -733,6 +733,7 @@
 		9B62630C1F8C25C8007EE29B /* copy-url.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B62630B1F8C2510007EE29B /* copy-url.html */; };
 		9B7A37C41F8AEBA5004AA228 /* CopyURL.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9B7A37C21F8AEBA5004AA228 /* CopyURL.mm */; };
 		9B7D740F1F8378770006C432 /* paste-rtfd.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B7D740E1F8377E60006C432 /* paste-rtfd.html */; };
+		9B9332CE2320C745002D50E8 /* cocoa-writer-markup-with-lists.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B9332CD2320C73E002D50E8 /* cocoa-writer-markup-with-lists.html */; };
 		9BAD7F3E22690F2000F8DA66 /* DeallocWebViewInEventListener.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9BAD7F3D22690F1400F8DA66 /* DeallocWebViewInEventListener.mm */; };
 		9BAE177B22E2BBFB00DF3098 /* cocoa-writer-markup-with-system-fonts.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9BAE177A22E2BB6B00DF3098 /* cocoa-writer-markup-with-system-fonts.html */; };
 		9BCB7C2820130600003E7C0C /* PasteHTML.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9BCB7C2620130600003E7C0C /* PasteHTML.mm */; };
@@ -1160,6 +1161,7 @@
 				839AA35F21A26B0300980DD6 /* client-side-redirect.html in Copy Resources */,
 				1A50AA201A2A51FC00F4C345 /* close-from-within-create-page.html in Copy Resources */,
 				9B270FEE1DDC2C0B002D53F3 /* closed-shadow-tree-test.html in Copy Resources */,
+				9B9332CE2320C745002D50E8 /* cocoa-writer-markup-with-lists.html in Copy Resources */,
 				9BAE177B22E2BBFB00DF3098 /* cocoa-writer-markup-with-system-fonts.html in Copy Resources */,
 				E5036F78211BC25400BFDBE2 /* color-drop.html in Copy Resources */,
 				0F16BED82304A1F300B4A167 /* composited.html in Copy Resources */,
@@ -2090,6 +2092,7 @@
 		9B79164F1BD89D0D00D50B8F /* FirstResponderScrollingPosition.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FirstResponderScrollingPosition.mm; sourceTree = "<group>"; };
 		9B7A37C21F8AEBA5004AA228 /* CopyURL.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CopyURL.mm; sourceTree = "<group>"; };
 		9B7D740E1F8377E60006C432 /* paste-rtfd.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "paste-rtfd.html"; sourceTree = "<group>"; };
+		9B9332CD2320C73E002D50E8 /* cocoa-writer-markup-with-lists.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "cocoa-writer-markup-with-lists.html"; sourceTree = "<group>"; };
 		9BAD7F3D22690F1400F8DA66 /* DeallocWebViewInEventListener.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeallocWebViewInEventListener.mm; sourceTree = "<group>"; };
 		9BAE177A22E2BB6B00DF3098 /* cocoa-writer-markup-with-system-fonts.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "cocoa-writer-markup-with-system-fonts.html"; sourceTree = "<group>"; };
 		9BCB7C2620130600003E7C0C /* PasteHTML.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PasteHTML.mm; sourceTree = "<group>"; };
@@ -3166,6 +3169,7 @@
 				2EFF06C41D8867700004BB30 /* change-video-source-on-click.html */,
 				2EFF06C61D886A560004BB30 /* change-video-source-on-end.html */,
 				839AA35E21A26ACD00980DD6 /* client-side-redirect.html */,
+				9B9332CD2320C73E002D50E8 /* cocoa-writer-markup-with-lists.html */,
 				9BAE177A22E2BB6B00DF3098 /* cocoa-writer-markup-with-system-fonts.html */,
 				E5036F77211BC22800BFDBE2 /* color-drop.html */,
 				F4B825D61EF4DBD4006E417F /* compressed-files.zip */,

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm (249534 => 249535)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm	2019-09-05 17:27:14 UTC (rev 249534)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm	2019-09-05 17:44:38 UTC (rev 249535)
@@ -360,6 +360,33 @@
         [webView stringByEvaluatingJavaScript:@"getComputedStyle(document.body).fontFamily"]);
 }
 
+TEST(PasteHTML, DoesNotAddStandardFontFamily)
+{
+    writeHTMLToPasteboard([NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"cocoa-writer-markup-with-lists" ofType:@"html" inDirectory:@"TestWebKitAPI.resources"] encoding:NSUTF8StringEncoding error:NULL]);
+
+    auto webView = createWebViewWithCustomPasteboardDataSetting(true);
+    [webView synchronouslyLoadTestPageNamed:@"paste-rtfd"];
+    [webView stringByEvaluatingJavaScript:@"document.body.style.fontFamily = 'Arial'"];
+    [webView paste:nil];
+
+    EXPECT_WK_STREQ("[\"text/html\"]", [webView stringByEvaluatingJavaScript:@"JSON.stringify(clipboardData.types)"]);
+    [webView stringByEvaluatingJavaScript:@"window.htmlInDataTransfer = clipboardData.values[0]"];
+    [webView stringByEvaluatingJavaScript:@"window.pastedHTML = editor.innerHTML"];
+
+    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"pastedHTML.includes('Hello')"].boolValue);
+    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"pastedHTML.includes('font-weight: bold')"].boolValue);
+    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!pastedHTML.includes('-webkit-standard')"].boolValue);
+
+    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"htmlInDataTransfer.includes('Hello')"].boolValue);
+    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"htmlInDataTransfer.includes('font-weight: bold')"].boolValue);
+    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!htmlInDataTransfer.includes('-webkit-standard')"].boolValue);
+
+    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"getComputedStyle(document.querySelector('.s2')).fontFamily"],
+        [webView stringByEvaluatingJavaScript:@"getComputedStyle(document.body).fontFamily"]);
+    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"getComputedStyle(document.querySelector('.s4')).fontFamily"],
+        [webView stringByEvaluatingJavaScript:@"getComputedStyle(document.body).fontFamily"]);
+}
+
 #if ENABLE(DARK_MODE_CSS) && HAVE(OS_DARK_MODE_SUPPORT)
 
 TEST(PasteHTML, TransformColorsOfDarkContent)

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/cocoa-writer-markup-with-lists.html (0 => 249535)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/cocoa-writer-markup-with-lists.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/cocoa-writer-markup-with-lists.html	2019-09-05 17:44:38 UTC (rev 249535)
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<meta http-equiv="Content-Style-Type" content="text/css">
+<title></title>
+<meta name="Generator" content="Cocoa HTML Writer">
+<style type="text/css">
+p.p1 {margin: 0.0px 0.0px 3.0px 0.0px; font: 22.0px '.AppleSystemUIFont'; color: #454545; min-height: 26.3px}
+p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px '.SF UI Mono'; color: #454545}
+li.li2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px '.AppleSystemUIFont'; color: #454545}
+span.s1 {font-family: '.SFUI-Heavy'; font-weight: bold; font-style: normal; font-size: 22.00px}
+span.s2 {font-family: '.SFUI-Regular'; font-weight: normal; font-style: normal; font-size: 12.00px}
+span.s3 {font-family: '.SFUI-Regular'; font-weight: normal; font-style: normal; font-size: 17.00px}
+span.s4 {font-family: '.SFUI-Semibold'; font-weight: bold; font-style: normal; font-size: 17.00px}
+span.s5 {font-family: '.SFUIMono-Regular'; font-weight: normal; font-style: normal; font-size: 17.00px}
+ul.ul1 {list-style-type: hyphen}
+</style>
+</head>
+<body>
+<p class="p1"><span class="s1"></span><br></p>
+<ul class="ul1">
+<li class="li2"><span class="s2"></span><span class="s3">Hello</span></li>
+<li class="li2"><span class="s2"></span><span class="s4">World</span></li>
+</ul>
+<p class="p3"><span class="s5">World</span></p>
+</body>
+</html>
\ No newline at end of file
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to