haikuwebkit/LayoutTests/fast/events/input-events-paste-rich-dat...

14 lines
691 B
Plaintext
Raw Permalink Normal View History

Support InputEvent.dataTransfer for the InputEvent spec https://bugs.webkit.org/show_bug.cgi?id=163213 <rdar://problem/28700407> Reviewed by Ryosuke Niwa. Source/WebCore: Adds support for the dataTransfer attribute of InputEvent, which contains both HTML and plain text representations of inserted content corresponding to input types "insertFromPaste", "insertFromDrop" and "insertReplacementText". The specification calls for the data transfer's drag data item list to contain this information via two entries with type strings "text/html" and "text/plain". However, WebKit does not yet support the DataTransfer.items -- in lieu of this, we will provide this information for now via getData("text/plain") and getData("text/html"), respectively. To support this attribute, we need a special type of DataTransfer which is readonly and returns canned data given a type string. To implement this, we introduce StaticPasteboard, a type of Pasteboard which is initialized with a map of type string to data. When asked for its data via getData, the StaticPasteboard searches its map for the requested type and returns the result, if any. An editing command may now create a new DataTransfer via DataTransfer::createForInputEvent from HTML and plaintext strings, and then vend this information to its dispatched input events by overriding CompositeEditCommand::inputEventDataTransfer. Some further work will be needed to ensure that all information exposed via this DataTransfer does not contain hidden content. To do this, we should create a new Document, "paste" the contents of our copied HTML string into it, then simulate selecting the content and generating markup from the selection to create a sanitized DocumentFragment corresponding to the original copied HTML. This will be addressed in a future patch. Tests: fast/events/input-events-paste-rich-datatransfer.html fast/events/input-events-spell-checking-datatransfer.html * PlatformEfl.cmake: * PlatformGTK.cmake: * PlatformWin.cmake: Add StaticPasteboard.cpp. * WebCore.xcodeproj/project.pbxproj: * dom/DataTransfer.cpp: (WebCore::DataTransfer::DataTransfer): (WebCore::DataTransfer::createForInputEvent): Initializes a new DataTransfer for the purposes of input events. This takes a HTML and plain text representations of the data being inserted and creates a new readonly DataTransfer backed by a StaticPasteboard that only knows how to map the "text/plain" data type to the given plaintext string and "text/html" to the given HTML text. * dom/DataTransfer.h: * dom/InputEvent.cpp: (WebCore::InputEvent::create): (WebCore::InputEvent::InputEvent): (WebCore::InputEvent::dataTransfer): * dom/InputEvent.h: * dom/InputEvent.idl: Add the InputEvent.dataTransfer attribute. * dom/Node.cpp: * editing/CompositeEditCommand.cpp: (WebCore::CompositeEditCommand::inputEventDataTransfer): Add a new hook for CompositeEditCommands to vend a DataTransfer for the purposes of input events. By default, this is null. * editing/CompositeEditCommand.h: * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): (WebCore::dispatchInputEvent): (WebCore::dispatchBeforeInputEvents): (WebCore::dispatchInputEvents): (WebCore::Editor::willApplyEditing): (WebCore::Editor::appliedEditing): * editing/ReplaceRangeWithTextCommand.cpp: (WebCore::ReplaceRangeWithTextCommand::willApplyCommand): (WebCore::ReplaceRangeWithTextCommand::doApply): (WebCore::ReplaceRangeWithTextCommand::inputEventDataTransfer): * editing/ReplaceRangeWithTextCommand.h: * editing/ReplaceSelectionCommand.cpp: (WebCore::ReplaceSelectionCommand::willApplyCommand): Initialize the ReplacementFragment here before applying the command, adjusting the DocumentFragment to be inserted in the process. (WebCore::ReplaceSelectionCommand::doApply): (WebCore::ReplaceSelectionCommand::inputEventDataTransfer): (WebCore::ReplaceSelectionCommand::ensureReplacementFragment): Returns the ReplacementFragment used to apply the command, initializing it if necessary and stripping extraneous nodes off of the document fragment in the process. Since ReplaceSelectionCommand may be used as a top-level editing command or a child of another CompositeEditCommand such as the ReplaceRangeWithTextCommand, the ReplacementFragment may be initialized either in willApplyCommand or in doApply. * editing/ReplaceSelectionCommand.h: * editing/SpellingCorrectionCommand.cpp: (WebCore::SpellingCorrectionCommand::willApplyCommand): (WebCore::SpellingCorrectionCommand::doApply): (WebCore::SpellingCorrectionCommand::inputEventDataTransfer): * editing/SpellingCorrectionCommand.h: Using the replacement text fragment, create and return a DataTransfer for input events. * platform/Pasteboard.h: * platform/StaticPasteboard.cpp: Added. (WebCore::StaticPasteboard::create): (WebCore::StaticPasteboard::StaticPasteboard): (WebCore::StaticPasteboard::hasData): (WebCore::StaticPasteboard::types): (WebCore::StaticPasteboard::readString): * platform/StaticPasteboard.h: Copied from Source/WebCore/dom/InputEvent.cpp. * platform/efl/PasteboardEfl.cpp: (WebCore::Pasteboard::writeMarkup): (WebCore::Pasteboard::write): (WebCore::Pasteboard::read): * platform/gtk/PasteboardGtk.cpp: (WebCore::Pasteboard::writeMarkup): * platform/ios/PasteboardIOS.mm: (WebCore::Pasteboard::writeMarkup): * platform/mac/PasteboardMac.mm: (WebCore::Pasteboard::Pasteboard): (WebCore::Pasteboard::writeMarkup): * platform/win/PasteboardWin.cpp: (WebCore::Pasteboard::write): (WebCore::Pasteboard::read): To account for virtual methods on Pasteboard, add implementations for methods that were previously defined but unimplemented on these platforms. LayoutTests: Adds 2 new layout tests verifying that input events dispatched as a result of pasting or spell checking contain DataTransfers that have rich and plain text representations of the contents being inserted. * fast/events/input-events-fired-when-typing-expected.txt: * fast/events/input-events-fired-when-typing.html: * fast/events/input-events-paste-rich-datatransfer-expected.txt: Added. * fast/events/input-events-paste-rich-datatransfer.html: Added. * fast/events/input-events-spell-checking-datatransfer-expected.txt: Added. * fast/events/input-events-spell-checking-datatransfer.html: Added. * platform/ios-simulator/TestExpectations: Canonical link: https://commits.webkit.org/181698@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207841 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-25 20:23:10 +00:00
To manually test this, copy and paste into the first contenteditable. The following contenteditables should reflect the pasted contents.
destination after pasting (text/html):
| <b>
Inserting an image, selecting, underlining, and then deleting leaves the typing style with both "-webkit-text-decorations-in-effect" and "text-decoration" https://bugs.webkit.org/show_bug.cgi?id=179431 Reviewed by Ryosuke Niwa. Source/WebCore: When inserting an image element, selecting it, underlining the selection, deleting, and then inserting text, we crash on a debug assert. This codepath was exercised by an API test added in <https://trac.webkit.org/r224512>. This assertion happens due to the following sequence of events: 1. DeleteSelectionCommand::saveTypingStyleState computes a typing style. 2. In doing so, it calls into EditingStyle::init, which observes that "-webkit-text-decorations-in-effect" is present and appends "text-decoration" with an identical CSS value to the EditingStyle's mutable style properties. 3. DeleteSelectionCommand::calculateTypingStyleAfterDelete sets the current selection's typing style to the above typing style. 4. Later on, when we try to insert text, we compute the StyleChange using the above typing style, which calls into reconcileTextDecorationProperties. 5. reconcileTextDecorationProperties debug asserts that "-webkit-text-decorations-in-effect" and "text-decoration" don't coexist on the EditingStyle's (i.e. the typing style's) mutable properties; since (2) added both properties, this assertion fires. It appears that step (2) shouldn't be adding "text-decoration" in addition to EditingStyle's mutable style properties, since doing so would violate the requirements of reconcileTextDecorationProperties. As such, we can tweak EditingStyle::init to *replace* the "-webkit-text-decorations-in-effect" property with "text-decoration" instead; this matches the behavior of reconcileTextDecorationProperties, and ensures that we only have the "text-decorations" property when we try to insert text in step (4). Test: editing/execCommand/underline-selection-containing-image.html * editing/EditingStyle.cpp: (WebCore::EditingStyle::init): LayoutTests: Adds a new layout test to fix a debug assertion. See WebCore/ChangeLog for more details. Additionally rebaselines a few existing tests that serialize markup strings to include `text-decoration: none;`. * editing/execCommand/underline-selection-containing-image-expected.txt: Added. * editing/execCommand/underline-selection-containing-image.html: Added. * editing/pasteboard/data-transfer-get-data-on-drop-rich-text-expected.txt: * fast/events/before-input-events-prevent-drag-and-drop-expected.txt: * fast/events/input-events-paste-rich-datatransfer-expected.txt: * fast/events/ondrop-text-html-expected.txt: Canonical link: https://commits.webkit.org/195547@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224649 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-09 23:26:55 +00:00
| style="caret-color: rgb(255, 0, 0); color: rgb(255, 0, 0); font-family: -webkit-standard; font-style: normal; font-variant-caps: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;"
Support InputEvent.dataTransfer for the InputEvent spec https://bugs.webkit.org/show_bug.cgi?id=163213 <rdar://problem/28700407> Reviewed by Ryosuke Niwa. Source/WebCore: Adds support for the dataTransfer attribute of InputEvent, which contains both HTML and plain text representations of inserted content corresponding to input types "insertFromPaste", "insertFromDrop" and "insertReplacementText". The specification calls for the data transfer's drag data item list to contain this information via two entries with type strings "text/html" and "text/plain". However, WebKit does not yet support the DataTransfer.items -- in lieu of this, we will provide this information for now via getData("text/plain") and getData("text/html"), respectively. To support this attribute, we need a special type of DataTransfer which is readonly and returns canned data given a type string. To implement this, we introduce StaticPasteboard, a type of Pasteboard which is initialized with a map of type string to data. When asked for its data via getData, the StaticPasteboard searches its map for the requested type and returns the result, if any. An editing command may now create a new DataTransfer via DataTransfer::createForInputEvent from HTML and plaintext strings, and then vend this information to its dispatched input events by overriding CompositeEditCommand::inputEventDataTransfer. Some further work will be needed to ensure that all information exposed via this DataTransfer does not contain hidden content. To do this, we should create a new Document, "paste" the contents of our copied HTML string into it, then simulate selecting the content and generating markup from the selection to create a sanitized DocumentFragment corresponding to the original copied HTML. This will be addressed in a future patch. Tests: fast/events/input-events-paste-rich-datatransfer.html fast/events/input-events-spell-checking-datatransfer.html * PlatformEfl.cmake: * PlatformGTK.cmake: * PlatformWin.cmake: Add StaticPasteboard.cpp. * WebCore.xcodeproj/project.pbxproj: * dom/DataTransfer.cpp: (WebCore::DataTransfer::DataTransfer): (WebCore::DataTransfer::createForInputEvent): Initializes a new DataTransfer for the purposes of input events. This takes a HTML and plain text representations of the data being inserted and creates a new readonly DataTransfer backed by a StaticPasteboard that only knows how to map the "text/plain" data type to the given plaintext string and "text/html" to the given HTML text. * dom/DataTransfer.h: * dom/InputEvent.cpp: (WebCore::InputEvent::create): (WebCore::InputEvent::InputEvent): (WebCore::InputEvent::dataTransfer): * dom/InputEvent.h: * dom/InputEvent.idl: Add the InputEvent.dataTransfer attribute. * dom/Node.cpp: * editing/CompositeEditCommand.cpp: (WebCore::CompositeEditCommand::inputEventDataTransfer): Add a new hook for CompositeEditCommands to vend a DataTransfer for the purposes of input events. By default, this is null. * editing/CompositeEditCommand.h: * editing/Editor.cpp: (WebCore::dispatchBeforeInputEvent): (WebCore::dispatchInputEvent): (WebCore::dispatchBeforeInputEvents): (WebCore::dispatchInputEvents): (WebCore::Editor::willApplyEditing): (WebCore::Editor::appliedEditing): * editing/ReplaceRangeWithTextCommand.cpp: (WebCore::ReplaceRangeWithTextCommand::willApplyCommand): (WebCore::ReplaceRangeWithTextCommand::doApply): (WebCore::ReplaceRangeWithTextCommand::inputEventDataTransfer): * editing/ReplaceRangeWithTextCommand.h: * editing/ReplaceSelectionCommand.cpp: (WebCore::ReplaceSelectionCommand::willApplyCommand): Initialize the ReplacementFragment here before applying the command, adjusting the DocumentFragment to be inserted in the process. (WebCore::ReplaceSelectionCommand::doApply): (WebCore::ReplaceSelectionCommand::inputEventDataTransfer): (WebCore::ReplaceSelectionCommand::ensureReplacementFragment): Returns the ReplacementFragment used to apply the command, initializing it if necessary and stripping extraneous nodes off of the document fragment in the process. Since ReplaceSelectionCommand may be used as a top-level editing command or a child of another CompositeEditCommand such as the ReplaceRangeWithTextCommand, the ReplacementFragment may be initialized either in willApplyCommand or in doApply. * editing/ReplaceSelectionCommand.h: * editing/SpellingCorrectionCommand.cpp: (WebCore::SpellingCorrectionCommand::willApplyCommand): (WebCore::SpellingCorrectionCommand::doApply): (WebCore::SpellingCorrectionCommand::inputEventDataTransfer): * editing/SpellingCorrectionCommand.h: Using the replacement text fragment, create and return a DataTransfer for input events. * platform/Pasteboard.h: * platform/StaticPasteboard.cpp: Added. (WebCore::StaticPasteboard::create): (WebCore::StaticPasteboard::StaticPasteboard): (WebCore::StaticPasteboard::hasData): (WebCore::StaticPasteboard::types): (WebCore::StaticPasteboard::readString): * platform/StaticPasteboard.h: Copied from Source/WebCore/dom/InputEvent.cpp. * platform/efl/PasteboardEfl.cpp: (WebCore::Pasteboard::writeMarkup): (WebCore::Pasteboard::write): (WebCore::Pasteboard::read): * platform/gtk/PasteboardGtk.cpp: (WebCore::Pasteboard::writeMarkup): * platform/ios/PasteboardIOS.mm: (WebCore::Pasteboard::writeMarkup): * platform/mac/PasteboardMac.mm: (WebCore::Pasteboard::Pasteboard): (WebCore::Pasteboard::writeMarkup): * platform/win/PasteboardWin.cpp: (WebCore::Pasteboard::write): (WebCore::Pasteboard::read): To account for virtual methods on Pasteboard, add implementations for methods that were previously defined but unimplemented on these platforms. LayoutTests: Adds 2 new layout tests verifying that input events dispatched as a result of pasting or spell checking contain DataTransfers that have rich and plain text representations of the contents being inserted. * fast/events/input-events-fired-when-typing-expected.txt: * fast/events/input-events-fired-when-typing.html: * fast/events/input-events-paste-rich-datatransfer-expected.txt: Added. * fast/events/input-events-paste-rich-datatransfer.html: Added. * fast/events/input-events-spell-checking-datatransfer-expected.txt: Added. * fast/events/input-events-spell-checking-datatransfer.html: Added. * platform/ios-simulator/TestExpectations: Canonical link: https://commits.webkit.org/181698@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207841 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-25 20:23:10 +00:00
| "LayoutTests"
| <i>
| "are"
| <u>
| "fun!"
destination after pasting (text/plain):
| "LayoutTestsarefun!"