haikuwebkit/LayoutTests/editing/pasteboard/copy-paste-with-shadow-cont...

41 lines
1.4 KiB
HTML
Raw Permalink Normal View History

Enable selectionAcrossShadowBoundariesEnabled by default in WebKitLegacy https://bugs.webkit.org/show_bug.cgi?id=190238 Reviewed by Antti Koivisto. Source/WebCore: Enable the feature by default. * page/Settings.yaml: Source/WebKitLegacy/mac: Enabled the feature by default. * WebView/WebPreferences.mm: (+[WebPreferences initialize]): Tools: * DumpRenderTree/TestOptions.h: * DumpRenderTree/mac/DumpRenderTree.mm: (resetWebPreferencesToConsistentValues): LayoutTests: Removed the unnecessary webkit-test-runner directive. * editing/pasteboard/copy-paste-across-shadow-boundaries-1.html: * editing/pasteboard/copy-paste-across-shadow-boundaries-2.html: * editing/pasteboard/copy-paste-across-shadow-boundaries-3.html: * editing/pasteboard/copy-paste-across-shadow-boundaries-4.html: * editing/pasteboard/copy-paste-across-shadow-boundaries-with-style-1.html: * editing/pasteboard/copy-paste-across-shadow-boundaries-with-style-2.html: * editing/pasteboard/copy-paste-with-shadow-content.html: * editing/selection/selection-across-shadow-boundaries-mixed-editability-1.html: * editing/selection/selection-across-shadow-boundaries-mixed-editability-2.html: * editing/selection/selection-across-shadow-boundaries-mixed-editability-3.html: * editing/selection/selection-across-shadow-boundaries-mixed-editability-4.html: * editing/selection/selection-across-shadow-boundaries-mixed-editability-5.html: * editing/selection/selection-across-shadow-boundaries-readonly-1.html: * editing/selection/selection-across-shadow-boundaries-readonly-2.html: * editing/selection/selection-across-shadow-boundaries-readonly-3.html: * editing/selection/selection-across-shadow-boundaries-user-select-all-1.html: Canonical link: https://commits.webkit.org/205193@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236788 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-10-03 09:45:18 +00:00
<!DOCTYPE html>
Copying content with shadow DOM doesn't copy any contents https://bugs.webkit.org/show_bug.cgi?id=157443 Reviewed by Wenson Hsieh. Source/WebCore: This patch adds the support for copying and pasting content across shadow boundaries in HTML and plain text, which is enabled whenever selection across shadow boundaries is enabled. To do this, TextIterator now has a constructor which takes two Positions, and the node traversal code in StyledMarkupAccumulator has been abstracted via helper functions as done for TextIterator. When serializing a HTMl slot element, serialize it as a span with "display: contents" to make sure when the content is pasted into a shadow tree, it wouldn't affect the slot assignment of the shadow tree. Tests: editing/pasteboard/copy-paste-across-shadow-boundaries-1.html editing/pasteboard/copy-paste-across-shadow-boundaries-2.html editing/pasteboard/copy-paste-across-shadow-boundaries-3.html editing/pasteboard/copy-paste-across-shadow-boundaries-4.html editing/pasteboard/copy-paste-across-shadow-boundaries-with-style-1.html editing/pasteboard/copy-paste-across-shadow-boundaries-with-style-2.html editing/pasteboard/copy-paste-with-shadow-content.html * dom/ComposedTreeIterator.h: (WebCore::assignedSlotIgnoringUserAgentShadow): Moved from TextIterator.cpp. (WebCore::shadowRootIgnoringUserAgentShadow): Ditto. (WebCore::firstChildInComposedTreeIgnoringUserAgentShadow): Ditto. (WebCore::nextSiblingInComposedTreeIgnoringUserAgentShadow): Ditto. * dom/Position.h: (WebCore::Position::treeScope const): Added. * editing/EditingStyle.cpp: (WebCore::EditingStyle::addDisplayContents): Added. * editing/EditingStyle.h: * editing/Editor.cpp: (WebCore::Editor::selectedText const): Use the new behavior when selectionAcrossShadowBoundariesEnabled is set. (WebCore::Editor::selectedTextForDataTransfer const): Ditto. * editing/MarkupAccumulator.cpp: (WebCore::MarkupAccumulator::appendEndElement): Renamed from appendEndTag. Now takes StringBuilder. * editing/MarkupAccumulator.h: (WebCore::MarkupAccumulator::appendEndTag): * editing/TextIterator.cpp: (WebCore::TextIterator::TextIterator): Added a new variant which takes two positions. (WebCore::TextIterator::init): (WebCore::firstChild): (WebCore::nextSibling): (WebCore::plainText): Ditto. * editing/TextIterator.h: * editing/cocoa/EditorCocoa.mm: (WebCore::Editor::selectionInHTMLFormat): Use the new behavior if selectionAcrossShadowBoundariesEnabled is set. * editing/gtk/EditorGtk.cpp: (WebCore::Editor::writeSelectionToPasteboard): Ditto. * editing/markup.cpp: (WebCore::StyledMarkupAccumulator::parentNode): Added. (WebCore::StyledMarkupAccumulator::firstChild): Added. (WebCore::StyledMarkupAccumulator::nextSibling): Added. (WebCore::StyledMarkupAccumulator::nextSkippingChildren): Added. (WebCore::StyledMarkupAccumulator::hasChildNodes): Added. (WebCore::StyledMarkupAccumulator::isDescendantOf): Added. (WebCore::StyledMarkupAccumulator::StyledMarkupAccumulator): (WebCore::StyledMarkupAccumulator::appendElement): Serialize a slot element as a span with display: contents. (WebCore::StyledMarkupAccumulator::appendEndElement): Added. Ditto. (WebCore::StyledMarkupAccumulator::serializeNodes): (WebCore::StyledMarkupAccumulator::traverseNodesForSerialization): Use the newly added helper functions to traverse the composed tree when m_useComposedTree is set. (WebCore::commonShadowIncludingAncestor): Added. (WebCore::serializePreservingVisualAppearanceInternal): Added SerializeComposedTree as an argument. Also use StyledMarkupAccumulator::parentNode to serialize special common ancestors; e.g. to preserve b, i, etc... (WebCore::serializePreservingVisualAppearance): Ditto to the variant which takes VisibleSelection. (WebCore::sanitizedMarkupForFragmentInDocument): * editing/markup.h: * editing/wpe/EditorWPE.cpp: (WebCore::Editor::writeSelectionToPasteboard): * loader/archive/cf/LegacyWebArchive.cpp: (WebCore::LegacyWebArchive::createFromSelection): * page/PageSerializer.cpp: (WebCore::PageSerializer::SerializerMarkupAccumulator::appendEndElement): * testing/Internals.cpp: (WebCore::Internals::setSelectionWithoutValidation): Added. A helper function to create a selection across shadow boundaries for testing purposes. * testing/Internals.h: * testing/Internals.idl: LayoutTests: Added tests for copying and pasting across shadow boundaries with HTML and plain text. * editing/pasteboard/copy-paste-across-shadow-boundaries-1-expected.txt: Added. * editing/pasteboard/copy-paste-across-shadow-boundaries-1.html: Added. * editing/pasteboard/copy-paste-across-shadow-boundaries-2-expected.txt: Added. * editing/pasteboard/copy-paste-across-shadow-boundaries-2.html: Added. * editing/pasteboard/copy-paste-across-shadow-boundaries-3-expected.txt: Added. * editing/pasteboard/copy-paste-across-shadow-boundaries-3.html: Added. * editing/pasteboard/copy-paste-across-shadow-boundaries-4-expected.txt: Added. * editing/pasteboard/copy-paste-across-shadow-boundaries-4.html: Added. * editing/pasteboard/copy-paste-across-shadow-boundaries-with-style-1-expected.txt: Added. * editing/pasteboard/copy-paste-across-shadow-boundaries-with-style-1.html: Added. * editing/pasteboard/copy-paste-across-shadow-boundaries-with-style-2-expected.txt: Added. * editing/pasteboard/copy-paste-across-shadow-boundaries-with-style-2.html: Added. * editing/pasteboard/copy-paste-with-shadow-content-expected.txt: Added. * editing/pasteboard/copy-paste-with-shadow-content.html: Added. Canonical link: https://commits.webkit.org/205190@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236785 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-10-03 06:28:07 +00:00
<html>
<body>
<p id="description">This tests copying and pasting content with a shadow tree.<br>
To test manually, copy paste the content in the blue box to the green box below. All the text shoul be copied & pasted</p>
<style> .box { border: solid 1px; padding: 0.2rem; margin-bottom: 1rem; } </style>
<div id="source" class="box" style="border-color: blue">hello <span id="host">world</span> rocks</div>
<div id="destination" class="box" style="border-color: blue" contenteditable></div>
<pre id="htmlResult"></pre>
<pre id="textResult"></pre>
<script src="../../resources/dump-as-markup.js"></script>
<script>
Markup.description(description.textContent);
Markup.waitUntilDone();
const shadowRoot = host.attachShadow({mode: 'open'});
shadowRoot.innerHTML = '<slot></slot> WebKit';
getSelection().selectAllChildren(source);
destination.addEventListener('paste', (event) => {
htmlResult.textContent = event.clipboardData.getData('text/html');
textResult.textContent = event.clipboardData.getData('text/plain');
setTimeout(() => {
Markup.dump(destination, 'pasted');
Markup.dump(destination, 'text/html');
Markup.dump(textResult, 'text/plain');
Markup.notifyDone();
}, 0);
});
if (window.testRunner) {
document.execCommand('copy');
destination.focus();
document.execCommand('paste');
}
</script>
</body>
</html>