-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Content with -webkit-user-select: none should be skipped during copy
https://bugs.webkit.org/show_bug.cgi?id=80159 Reviewed by Darin Adler. Exclude content with -webkit-user-select: none when copying. This patch introduces TextIteratorBehavior::IgnoresUserSelectNone to exclude such content from plain text, and adds IgnoreUserSelectNone as an argument to serializePreservingVisualAppearance to exclude such content from HTML. It also updates HTMLConverter::_enterElement to exclude such content from RTFD. Finally, this patch also updates DOMSelection::toString to have the same treatment. * LayoutTests/editing/pasteboard/copy-content-with-user-select-none-expected.txt: Added. * LayoutTests/editing/pasteboard/copy-content-with-user-select-none.html: Added. * Source/WebCore/editing/Editor.cpp: (WebCore::Editor::selectedText const): (WebCore::Editor::selectedTextForDataTransfer const): * Source/WebCore/editing/TextIterator.cpp: (WebCore::isRendererVisible): Added. (WebCore::TextIterator::advance): (WebCore::hasVisibleTextNode): (WebCore::TextIterator::handleTextNodeFirstLetter): * Source/WebCore/editing/TextIteratorBehavior.h: * Source/WebCore/editing/cocoa/EditorCocoa.mm: (WebCore::Editor::selectionInHTMLFormat): * Source/WebCore/editing/cocoa/HTMLConverter.mm: (HTMLConverter::_enterElement): * Source/WebCore/editing/gtk/EditorGtk.cpp: (WebCore::Editor::writeSelectionToPasteboard): * Source/WebCore/editing/libwpe/EditorLibWPE.cpp: (WebCore::Editor::writeSelectionToPasteboard): * Source/WebCore/editing/mac/EditorMac.mm: (WebCore::Editor::writeImageToPasteboard): * Source/WebCore/editing/markup.cpp: (WebCore::StyledMarkupAccumulator::StyledMarkupAccumulator): (WebCore::StyledMarkupAccumulator::renderedTextRespectingRange): (WebCore::StyledMarkupAccumulator::traverseNodesForSerialization): (WebCore::serializePreservingVisualAppearanceInternal): (WebCore::serializePreservingVisualAppearance): (WebCore::sanitizedMarkupForFragmentInDocument): * Source/WebCore/editing/markup.h: * Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp: (WebCore::LegacyWebArchive::createFromSelection): * Source/WebCore/page/DOMSelection.cpp: (WebCore::DOMSelection::toString const): * Tools/TestWebKitAPI/Tests/WebKitCocoa/CopyRTF.mm: (CopyRTF.StripsUserSelectNone): Canonical link: https://commits.webkit.org/257749@main
- Loading branch information
Showing
15 changed files
with
120 additions
and
22 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
LayoutTests/editing/pasteboard/copy-content-with-user-select-none-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
This tests copying excludes content with user-select: none. | ||
To manually test, copy "hello world foo bar" below then paste. | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS getSelection().toString().includes("hello") is true | ||
PASS getSelection().toString().includes("world") is false | ||
PASS getSelection().toString().includes("foo") is false | ||
PASS getSelection().toString().includes("bar") is true | ||
PASS event.clipboardData.getData("text/plain").includes("hello") is true | ||
PASS event.clipboardData.getData("text/plain").includes("world") is false | ||
PASS event.clipboardData.getData("text/plain").includes("foo") is false | ||
PASS event.clipboardData.getData("text/plain").includes("bar") is true | ||
PASS event.clipboardData.getData("text/html").includes("hello") is true | ||
PASS event.clipboardData.getData("text/html").includes("world") is false | ||
PASS event.clipboardData.getData("text/html").includes("foo") is false | ||
PASS event.clipboardData.getData("text/html").includes("bar") is true | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
hello world foo bar | ||
hello bar | ||
|
48 changes: 48 additions & 0 deletions
48
LayoutTests/editing/pasteboard/copy-content-with-user-select-none.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<div id="source">hello <span style="-webkit-user-select: none; user-select: none;">world </span><span inert>foo </span>bar</div> | ||
<div id="destination" contenteditable></div> | ||
<pre id="output"></pre> | ||
</body> | ||
<script src="../../resources/js-test.js"></script> | ||
<script> | ||
|
||
description(`This tests copying excludes content with user-select: none.<br> | ||
To manually test, copy "hello world foo bar" below then paste.`); | ||
|
||
jsTestIsAsync = true; | ||
getSelection().setBaseAndExtent(source, 0, source, source.childNodes.length); | ||
|
||
source.addEventListener("copy", () => { | ||
shouldBeTrue('getSelection().toString().includes("hello")'); | ||
shouldBeFalse('getSelection().toString().includes("world")'); | ||
shouldBeFalse('getSelection().toString().includes("foo")'); | ||
shouldBeTrue('getSelection().toString().includes("bar")'); | ||
}); | ||
|
||
destination.addEventListener("paste", () => { | ||
shouldBeTrue('event.clipboardData.getData("text/plain").includes("hello")'); | ||
shouldBeFalse('event.clipboardData.getData("text/plain").includes("world")'); | ||
shouldBeFalse('event.clipboardData.getData("text/plain").includes("foo")'); | ||
shouldBeTrue('event.clipboardData.getData("text/plain").includes("bar")'); | ||
shouldBeTrue('event.clipboardData.getData("text/html").includes("hello")'); | ||
shouldBeFalse('event.clipboardData.getData("text/html").includes("world")'); | ||
shouldBeFalse('event.clipboardData.getData("text/html").includes("foo")'); | ||
shouldBeTrue('event.clipboardData.getData("text/html").includes("bar")'); | ||
finishJSTest(); | ||
}); | ||
|
||
if (window.testRunner && window.internals) { | ||
testRunner.dumpAsText(); | ||
testRunner.execCommand("Copy"); | ||
destination.focus(); | ||
testRunner.execCommand("Paste"); | ||
} else { | ||
source.addEventListener("copy", () => { | ||
setTimeout(() => destination.focus(), 0); | ||
}); | ||
} | ||
|
||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters