haikuwebkit/LayoutTests/editing/pasteboard/paste-cocoa-writer-markup-w...

54 lines
1.7 KiB
HTML
Raw Permalink Normal View History

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. Canonical link: https://commits.webkit.org/215139@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249535 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-09-05 17:44:38 +00:00
<!DOCTYPE html>
<html>
<body>
<button id="start">Start</button>
<div id="editor" style="font-family: Arial" contenteditable>hello</div>
<script src="../../resources/js-test.js"></script>
<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>