Changeset 207841 in webkit
- Timestamp:
- Oct 25, 2016 1:23:10 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 30 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r207840 r207841 1 2016-10-25 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Support InputEvent.dataTransfer for the InputEvent spec 4 https://bugs.webkit.org/show_bug.cgi?id=163213 5 <rdar://problem/28700407> 6 7 Reviewed by Ryosuke Niwa. 8 9 Adds 2 new layout tests verifying that input events dispatched as a result of pasting or spell checking contain 10 DataTransfers that have rich and plain text representations of the contents being inserted. 11 12 * fast/events/input-events-fired-when-typing-expected.txt: 13 * fast/events/input-events-fired-when-typing.html: 14 * fast/events/input-events-paste-rich-datatransfer-expected.txt: Added. 15 * fast/events/input-events-paste-rich-datatransfer.html: Added. 16 * fast/events/input-events-spell-checking-datatransfer-expected.txt: Added. 17 * fast/events/input-events-spell-checking-datatransfer.html: Added. 18 * platform/ios-simulator/TestExpectations: 19 1 20 2016-10-25 Andy Estes <aestes@apple.com> 2 21 -
trunk/LayoutTests/fast/events/input-events-fired-when-typing-expected.txt
r207670 r207841 5 5 PASS event.__lookupGetter__('inputType') is defined. 6 6 PASS event.__lookupGetter__('data') is defined. 7 PASS event.__lookupGetter__('dataTransfer') is defined. 7 8 PASS event.getTargetRanges is defined. 8 9 PASS event.target.id is expectedTargetID … … 13 14 PASS event.__lookupGetter__('inputType') is defined. 14 15 PASS event.__lookupGetter__('data') is defined. 16 PASS event.__lookupGetter__('dataTransfer') is defined. 15 17 PASS event.getTargetRanges is defined. 16 18 PASS event.target.id is expectedTargetID … … 21 23 PASS event.__lookupGetter__('inputType') is defined. 22 24 PASS event.__lookupGetter__('data') is defined. 25 PASS event.__lookupGetter__('dataTransfer') is defined. 23 26 PASS event.getTargetRanges is defined. 24 27 PASS event.target.id is expectedTargetID … … 29 32 PASS event.__lookupGetter__('inputType') is defined. 30 33 PASS event.__lookupGetter__('data') is defined. 34 PASS event.__lookupGetter__('dataTransfer') is defined. 31 35 PASS event.getTargetRanges is defined. 32 36 PASS event.target.id is expectedTargetID -
trunk/LayoutTests/fast/events/input-events-fired-when-typing.html
r207670 r207841 37 37 shouldBeDefined("event.__lookupGetter__('inputType')"); 38 38 shouldBeDefined("event.__lookupGetter__('data')"); 39 shouldBeDefined("event.__lookupGetter__('dataTransfer')"); 39 40 shouldBeDefined("event.getTargetRanges"); 40 41 shouldBe("event.target.id", "expectedTargetID"); … … 49 50 shouldBeDefined("event.__lookupGetter__('inputType')"); 50 51 shouldBeDefined("event.__lookupGetter__('data')"); 52 shouldBeDefined("event.__lookupGetter__('dataTransfer')"); 51 53 shouldBeDefined("event.getTargetRanges"); 52 54 shouldBe("event.target.id", "expectedTargetID"); -
trunk/LayoutTests/platform/ios-simulator/TestExpectations
r207698 r207841 1212 1212 fast/events/input-events-ime-recomposition.html [ Failure ] 1213 1213 fast/events/input-events-ime-composition.html [ Failure ] 1214 fast/events/input-events-paste-rich-datatransfer.html [ Failure ] 1215 fast/events/input-events-spell-checking-datatransfer.html [ Failure ] 1214 1216 fast/events/before-input-events-prevent-default.html [ Failure ] 1215 1217 fast/events/before-input-events-prevent-default-in-textfield.html [ Failure ] -
trunk/Source/WebCore/ChangeLog
r207840 r207841 1 2016-10-25 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Support InputEvent.dataTransfer for the InputEvent spec 4 https://bugs.webkit.org/show_bug.cgi?id=163213 5 <rdar://problem/28700407> 6 7 Reviewed by Ryosuke Niwa. 8 9 Adds support for the dataTransfer attribute of InputEvent, which contains both HTML and plain text 10 representations of inserted content corresponding to input types "insertFromPaste", "insertFromDrop" and 11 "insertReplacementText". The specification calls for the data transfer's drag data item list to contain this 12 information via two entries with type strings "text/html" and "text/plain". However, WebKit does not yet support 13 the DataTransfer.items -- in lieu of this, we will provide this information for now via getData("text/plain") 14 and getData("text/html"), respectively. 15 16 To support this attribute, we need a special type of DataTransfer which is readonly and returns canned data 17 given a type string. To implement this, we introduce StaticPasteboard, a type of Pasteboard which is initialized 18 with a map of type string to data. When asked for its data via getData, the StaticPasteboard searches its map 19 for the requested type and returns the result, if any. 20 21 An editing command may now create a new DataTransfer via DataTransfer::createForInputEvent from HTML and 22 plaintext strings, and then vend this information to its dispatched input events by overriding 23 CompositeEditCommand::inputEventDataTransfer. 24 25 Some further work will be needed to ensure that all information exposed via this DataTransfer does not contain 26 hidden content. To do this, we should create a new Document, "paste" the contents of our copied HTML string into 27 it, then simulate selecting the content and generating markup from the selection to create a sanitized 28 DocumentFragment corresponding to the original copied HTML. This will be addressed in a future patch. 29 30 Tests: fast/events/input-events-paste-rich-datatransfer.html 31 fast/events/input-events-spell-checking-datatransfer.html 32 33 * PlatformEfl.cmake: 34 * PlatformGTK.cmake: 35 * PlatformWin.cmake: 36 37 Add StaticPasteboard.cpp. 38 39 * WebCore.xcodeproj/project.pbxproj: 40 * dom/DataTransfer.cpp: 41 (WebCore::DataTransfer::DataTransfer): 42 (WebCore::DataTransfer::createForInputEvent): 43 44 Initializes a new DataTransfer for the purposes of input events. This takes a HTML and plain text 45 representations of the data being inserted and creates a new readonly DataTransfer backed by a StaticPasteboard 46 that only knows how to map the "text/plain" data type to the given plaintext string and "text/html" to the 47 given HTML text. 48 49 * dom/DataTransfer.h: 50 * dom/InputEvent.cpp: 51 (WebCore::InputEvent::create): 52 (WebCore::InputEvent::InputEvent): 53 (WebCore::InputEvent::dataTransfer): 54 * dom/InputEvent.h: 55 * dom/InputEvent.idl: 56 57 Add the InputEvent.dataTransfer attribute. 58 59 * dom/Node.cpp: 60 * editing/CompositeEditCommand.cpp: 61 (WebCore::CompositeEditCommand::inputEventDataTransfer): 62 63 Add a new hook for CompositeEditCommands to vend a DataTransfer for the purposes of input events. By default, 64 this is null. 65 66 * editing/CompositeEditCommand.h: 67 * editing/Editor.cpp: 68 (WebCore::dispatchBeforeInputEvent): 69 (WebCore::dispatchInputEvent): 70 (WebCore::dispatchBeforeInputEvents): 71 (WebCore::dispatchInputEvents): 72 (WebCore::Editor::willApplyEditing): 73 (WebCore::Editor::appliedEditing): 74 * editing/ReplaceRangeWithTextCommand.cpp: 75 (WebCore::ReplaceRangeWithTextCommand::willApplyCommand): 76 (WebCore::ReplaceRangeWithTextCommand::doApply): 77 (WebCore::ReplaceRangeWithTextCommand::inputEventDataTransfer): 78 * editing/ReplaceRangeWithTextCommand.h: 79 * editing/ReplaceSelectionCommand.cpp: 80 (WebCore::ReplaceSelectionCommand::willApplyCommand): 81 82 Initialize the ReplacementFragment here before applying the command, adjusting the DocumentFragment to be 83 inserted in the process. 84 85 (WebCore::ReplaceSelectionCommand::doApply): 86 (WebCore::ReplaceSelectionCommand::inputEventDataTransfer): 87 (WebCore::ReplaceSelectionCommand::ensureReplacementFragment): 88 89 Returns the ReplacementFragment used to apply the command, initializing it if necessary and stripping extraneous 90 nodes off of the document fragment in the process. Since ReplaceSelectionCommand may be used as a top-level 91 editing command or a child of another CompositeEditCommand such as the ReplaceRangeWithTextCommand, the 92 ReplacementFragment may be initialized either in willApplyCommand or in doApply. 93 94 * editing/ReplaceSelectionCommand.h: 95 * editing/SpellingCorrectionCommand.cpp: 96 (WebCore::SpellingCorrectionCommand::willApplyCommand): 97 (WebCore::SpellingCorrectionCommand::doApply): 98 (WebCore::SpellingCorrectionCommand::inputEventDataTransfer): 99 * editing/SpellingCorrectionCommand.h: 100 101 Using the replacement text fragment, create and return a DataTransfer for input events. 102 103 * platform/Pasteboard.h: 104 * platform/StaticPasteboard.cpp: Added. 105 (WebCore::StaticPasteboard::create): 106 (WebCore::StaticPasteboard::StaticPasteboard): 107 (WebCore::StaticPasteboard::hasData): 108 (WebCore::StaticPasteboard::types): 109 (WebCore::StaticPasteboard::readString): 110 * platform/StaticPasteboard.h: Copied from Source/WebCore/dom/InputEvent.cpp. 111 * platform/efl/PasteboardEfl.cpp: 112 (WebCore::Pasteboard::writeMarkup): 113 (WebCore::Pasteboard::write): 114 (WebCore::Pasteboard::read): 115 * platform/gtk/PasteboardGtk.cpp: 116 (WebCore::Pasteboard::writeMarkup): 117 * platform/ios/PasteboardIOS.mm: 118 (WebCore::Pasteboard::writeMarkup): 119 * platform/mac/PasteboardMac.mm: 120 (WebCore::Pasteboard::Pasteboard): 121 (WebCore::Pasteboard::writeMarkup): 122 * platform/win/PasteboardWin.cpp: 123 (WebCore::Pasteboard::write): 124 (WebCore::Pasteboard::read): 125 126 To account for virtual methods on Pasteboard, add implementations for methods that were previously defined but 127 unimplemented on these platforms. 128 1 129 2016-10-25 Andy Estes <aestes@apple.com> 2 130 -
trunk/Source/WebCore/PlatformEfl.cmake
r207590 r207841 88 88 89 89 platform/KillRingNone.cpp 90 platform/StaticPasteboard.cpp 90 91 91 92 platform/audio/efl/AudioBusEfl.cpp -
trunk/Source/WebCore/PlatformGTK.cmake
r207667 r207841 85 85 86 86 platform/KillRingNone.cpp 87 platform/StaticPasteboard.cpp 87 88 platform/UserAgentQuirks.cpp 88 89 -
trunk/Source/WebCore/PlatformWin.cmake
r206779 r207841 61 61 platform/KillRingNone.cpp 62 62 platform/LocalizedStrings.cpp 63 platform/StaticPasteboard.cpp 63 64 platform/VNodeTracker.cpp 64 65 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r207835 r207841 6373 6373 F40EA8AB1B867E4400CE5581 /* NSScrollingInputFilterSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = F40EA8AA1B867D6500CE5581 /* NSScrollingInputFilterSPI.h */; settings = {ATTRIBUTES = (Private, ); }; }; 6374 6374 F42FFB461984B71600F6837F /* LengthRepeat.h in Headers */ = {isa = PBXBuildFile; fileRef = F42FFB451984B71600F6837F /* LengthRepeat.h */; }; 6375 F433E9031DBBDBA200EF0D14 /* StaticPasteboard.h in Headers */ = {isa = PBXBuildFile; fileRef = F433E9021DBBDBA200EF0D14 /* StaticPasteboard.h */; settings = {ATTRIBUTES = (Private, ); }; }; 6376 F433E9051DBBDFCA00EF0D14 /* StaticPasteboard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F433E9041DBBDBC200EF0D14 /* StaticPasteboard.cpp */; }; 6375 6377 F44EBBD91DB5D21400277334 /* StaticRange.h in Headers */ = {isa = PBXBuildFile; fileRef = F44EBBD81DB5D21400277334 /* StaticRange.h */; settings = {ATTRIBUTES = (Private, ); }; }; 6376 6378 F44EBBDB1DB5DD9D00277334 /* StaticRange.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F44EBBDA1DB5DD9D00277334 /* StaticRange.cpp */; }; … … 14192 14194 F40EA8AA1B867D6500CE5581 /* NSScrollingInputFilterSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSScrollingInputFilterSPI.h; sourceTree = "<group>"; }; 14193 14195 F42FFB451984B71600F6837F /* LengthRepeat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LengthRepeat.h; sourceTree = "<group>"; }; 14196 F433E9021DBBDBA200EF0D14 /* StaticPasteboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StaticPasteboard.h; sourceTree = "<group>"; }; 14197 F433E9041DBBDBC200EF0D14 /* StaticPasteboard.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StaticPasteboard.cpp; sourceTree = "<group>"; }; 14194 14198 F44EBBD61DB5D1B600277334 /* StaticRange.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = StaticRange.idl; sourceTree = "<group>"; }; 14195 14199 F44EBBD81DB5D21400277334 /* StaticRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StaticRange.h; sourceTree = "<group>"; }; … … 22184 22188 4B3043C60AE0370300A82647 /* Sound.h */, 22185 22189 F587866202DE3B1101EA4122 /* SSLKeyGenerator.h */, 22190 F433E9041DBBDBC200EF0D14 /* StaticPasteboard.cpp */, 22191 F433E9021DBBDBA200EF0D14 /* StaticPasteboard.h */, 22186 22192 93B2D8150F9920D2006AE6B2 /* SuddenTermination.h */, 22187 22193 97627B9714FB5424002CDCA1 /* Supplementable.h */, … … 24521 24527 079D086B162F21F900DB8658 /* CaptionUserPreferencesMediaAF.h in Headers */, 24522 24528 07B7116D1D899E63009F0FFB /* CaptureDevice.h in Headers */, 24529 F433E9031DBBDBA200EF0D14 /* StaticPasteboard.h in Headers */, 24523 24530 07B7116F1D899E63009F0FFB /* CaptureDeviceManager.h in Headers */, 24524 24531 99CC0B4F18BE9849006CEBCC /* CapturingInputCursor.h in Headers */, … … 29014 29021 514C76720CE923A1007EF3CD /* HTTPParsers.cpp in Sources */, 29015 29022 371A67CB11C6C7DB00047B8B /* HyphenationCF.cpp in Sources */, 29023 F433E9051DBBDFCA00EF0D14 /* StaticPasteboard.cpp in Sources */, 29016 29024 97E4028F13A696ED00913D67 /* IconController.cpp in Sources */, 29017 29025 5126E6BB0A2E3B12005C29FA /* IconDatabase.cpp in Sources */, -
trunk/Source/WebCore/dom/DataTransfer.cpp
r206867 r207841 37 37 #include "Image.h" 38 38 #include "Pasteboard.h" 39 #include "StaticPasteboard.h" 39 40 40 41 namespace WebCore { … … 60 61 , m_pasteboard(WTFMove(pasteboard)) 61 62 #if ENABLE(DRAG_SUPPORT) 62 , m_forDrag(type != CopyAndPaste)63 , m_forDrag(type == DragAndDrop) 63 64 , m_forFileDrag(forFileDrag) 64 65 , m_dropEffect(ASCIILiteral("uninitialized")) … … 68 69 { 69 70 #if !ENABLE(DRAG_SUPPORT) 70 ASSERT_UNUSED(type, type == CopyAndPaste);71 ASSERT_UNUSED(type, type != DragAndDrop); 71 72 ASSERT_UNUSED(forFileDrag, !forFileDrag); 72 73 #endif … … 197 198 198 199 return !type.isNull() && types().contains(type); 200 } 201 202 Ref<DataTransfer> DataTransfer::createForInputEvent(const String& plainText, const String& htmlText) 203 { 204 TypeToStringMap typeToStringMap; 205 typeToStringMap.set(ASCIILiteral("text/plain"), plainText); 206 typeToStringMap.set(ASCIILiteral("text/html"), htmlText); 207 return adoptRef(*new DataTransfer(DataTransferAccessPolicy::Readable, StaticPasteboard::create(WTFMove(typeToStringMap)), InputEvent)); 199 208 } 200 209 -
trunk/Source/WebCore/dom/DataTransfer.h
r200192 r207841 46 46 public: 47 47 static Ref<DataTransfer> createForCopyAndPaste(DataTransferAccessPolicy); 48 static Ref<DataTransfer> createForInputEvent(const String& plainText, const String& htmlText); 48 49 49 50 WEBCORE_EXPORT ~DataTransfer(); … … 98 99 99 100 private: 100 enum Type { CopyAndPaste, DragAndDrop };101 enum Type { CopyAndPaste, DragAndDrop, InputEvent }; 101 102 DataTransfer(DataTransferAccessPolicy, std::unique_ptr<Pasteboard>, Type = CopyAndPaste, bool forFileDrag = false); 102 103 -
trunk/Source/WebCore/dom/InputEvent.cpp
r207670 r207841 28 28 29 29 #include "DOMWindow.h" 30 #include "DataTransfer.h" 30 31 #include "EventNames.h" 31 32 #include "Node.h" … … 36 37 namespace WebCore { 37 38 38 InputEvent::InputEvent(const AtomicString& eventType, const String& inputType, bool canBubble, bool cancelable, DOMWindow* view, const String& data, const Vector<RefPtr<StaticRange>>& targetRanges, int detail) 39 Ref<InputEvent> InputEvent::create(const AtomicString& eventType, const String& inputType, bool canBubble, bool cancelable, WebCore::DOMWindow *view, const String& data, RefPtr<DataTransfer>&& dataTransfer, const Vector<RefPtr<StaticRange>>& targetRanges, int detail) 40 { 41 return adoptRef(*new InputEvent(eventType, inputType, canBubble, cancelable, view, data, WTFMove(dataTransfer), targetRanges, detail)); 42 } 43 44 InputEvent::InputEvent(const AtomicString& eventType, const String& inputType, bool canBubble, bool cancelable, DOMWindow* view, const String& data, RefPtr<DataTransfer>&& dataTransfer, const Vector<RefPtr<StaticRange>>& targetRanges, int detail) 39 45 : UIEvent(eventType, canBubble, cancelable, view, detail) 40 46 , m_inputType(inputType) 41 47 , m_data(data) 48 , m_dataTransfer(dataTransfer) 42 49 , m_targetRanges(targetRanges) 43 50 { … … 51 58 } 52 59 60 RefPtr<DataTransfer> InputEvent::dataTransfer() const 61 { 62 return m_dataTransfer; 63 } 64 53 65 } // namespace WebCore -
trunk/Source/WebCore/dom/InputEvent.h
r207670 r207841 36 36 class InputEvent final : public UIEvent { 37 37 public: 38 static Ref<InputEvent> create(const AtomicString& eventType, const String& inputType, bool canBubble, bool cancelable, DOMWindow* view, const String& data, const Vector<RefPtr<StaticRange>>& targetRanges, int detail)39 {40 return adoptRef(*new InputEvent(eventType, inputType, canBubble, cancelable, view, data, targetRanges, detail));41 }42 43 38 struct Init : UIEventInit { 44 39 String data; 45 40 }; 46 41 42 static Ref<InputEvent> create(const AtomicString& eventType, const String& inputType, bool canBubble, bool cancelable, DOMWindow* view, const String& data, RefPtr<DataTransfer>&&, const Vector<RefPtr<StaticRange>>& targetRanges, int detail); 47 43 static Ref<InputEvent> create(const AtomicString& type, const Init& initializer, IsTrusted isTrusted = IsTrusted::No) 48 44 { … … 50 46 } 51 47 52 InputEvent(const AtomicString& eventType, const String& inputType, bool canBubble, bool cancelable, DOMWindow*, const String& data, const Vector<RefPtr<StaticRange>>& targetRanges, int detail);48 InputEvent(const AtomicString& eventType, const String& inputType, bool canBubble, bool cancelable, DOMWindow*, const String& data, RefPtr<DataTransfer>&&, const Vector<RefPtr<StaticRange>>& targetRanges, int detail); 53 49 InputEvent(const AtomicString& eventType, const Init&, IsTrusted); 54 50 … … 59 55 const String& inputType() const { return m_inputType; } 60 56 const String& data() const { return m_data; } 57 RefPtr<DataTransfer> dataTransfer() const; 61 58 const Vector<RefPtr<StaticRange>>& getTargetRanges() { return m_targetRanges; } 62 59 … … 64 61 String m_inputType; 65 62 String m_data; 63 RefPtr<DataTransfer> m_dataTransfer; 66 64 Vector<RefPtr<StaticRange>> m_targetRanges; 67 65 }; -
trunk/Source/WebCore/dom/InputEvent.idl
r207670 r207841 30 30 readonly attribute DOMString inputType; 31 31 readonly attribute DOMString? data; 32 readonly attribute DataTransfer? dataTransfer; 32 33 33 34 sequence<StaticRange> getTargetRanges(); -
trunk/Source/WebCore/dom/Node.cpp
r207627 r207841 35 35 #include "ContainerNodeAlgorithms.h" 36 36 #include "ContextMenuController.h" 37 #include "DataTransfer.h" 37 38 #include "DocumentType.h" 38 39 #include "ElementIterator.h" -
trunk/Source/WebCore/editing/CompositeEditCommand.cpp
r207834 r207841 31 31 #include "ApplyStyleCommand.h" 32 32 #include "BreakBlockquoteCommand.h" 33 #include "DataTransfer.h" 33 34 #include "DeleteFromTextNodeCommand.h" 34 35 #include "DeleteSelectionCommand.h" … … 400 401 } 401 402 403 RefPtr<DataTransfer> CompositeEditCommand::inputEventDataTransfer() const 404 { 405 return nullptr; 406 } 407 402 408 EditCommandComposition* CompositeEditCommand::ensureComposition() 403 409 { -
trunk/Source/WebCore/editing/CompositeEditCommand.h
r207698 r207841 36 36 37 37 class EditingStyle; 38 class DataTransfer; 38 39 class HTMLElement; 39 40 class StaticRange; … … 119 120 virtual bool isBeforeInputEventCancelable() const { return true; } 120 121 Vector<RefPtr<StaticRange>> targetRangesForBindings() const; 122 virtual RefPtr<DataTransfer> inputEventDataTransfer() const; 121 123 122 124 protected: -
trunk/Source/WebCore/editing/Editor.cpp
r207698 r207841 112 112 namespace WebCore { 113 113 114 static bool dispatchBeforeInputEvent(Element& element, const AtomicString& inputType, const String& data = { }, const Vector<RefPtr<StaticRange>>& targetRanges = { }, bool cancelable = true)114 static bool dispatchBeforeInputEvent(Element& element, const AtomicString& inputType, const String& data = { }, RefPtr<DataTransfer>&& dataTransfer = nullptr, const Vector<RefPtr<StaticRange>>& targetRanges = { }, bool cancelable = true) 115 115 { 116 116 auto* settings = element.document().settings(); … … 118 118 return true; 119 119 120 return element.dispatchEvent(InputEvent::create(eventNames().beforeinputEvent, inputType, true, cancelable, element.document().defaultView(), data, targetRanges, 0));121 } 122 123 static void dispatchInputEvent(Element& element, const AtomicString& inputType, const String& data = { }, const Vector<RefPtr<StaticRange>>& targetRanges = { })120 return element.dispatchEvent(InputEvent::create(eventNames().beforeinputEvent, inputType, true, cancelable, element.document().defaultView(), data, WTFMove(dataTransfer), targetRanges, 0)); 121 } 122 123 static void dispatchInputEvent(Element& element, const AtomicString& inputType, const String& data = { }, RefPtr<DataTransfer>&& dataTransfer = nullptr, const Vector<RefPtr<StaticRange>>& targetRanges = { }) 124 124 { 125 125 auto* settings = element.document().settings(); 126 126 if (settings && settings->inputEventsEnabled()) 127 element.dispatchEvent(InputEvent::create(eventNames().inputEvent, inputType, true, false, element.document().defaultView(), data, targetRanges, 0));127 element.dispatchEvent(InputEvent::create(eventNames().inputEvent, inputType, true, false, element.document().defaultView(), data, WTFMove(dataTransfer), targetRanges, 0)); 128 128 else 129 129 element.dispatchInputEvent(); … … 1064 1064 } 1065 1065 1066 static bool dispatchBeforeInputEvents(RefPtr<Element> startRoot, RefPtr<Element> endRoot, const AtomicString& inputTypeName, const String& data = { }, const Vector<RefPtr<StaticRange>>& targetRanges = { }, bool cancelable = true)1066 static bool dispatchBeforeInputEvents(RefPtr<Element> startRoot, RefPtr<Element> endRoot, const AtomicString& inputTypeName, const String& data = { }, RefPtr<DataTransfer>&& dataTransfer = nullptr, const Vector<RefPtr<StaticRange>>& targetRanges = { }, bool cancelable = true) 1067 1067 { 1068 1068 bool continueWithDefaultBehavior = true; 1069 1069 if (startRoot) 1070 continueWithDefaultBehavior &= dispatchBeforeInputEvent(*startRoot, inputTypeName, data, targetRanges, cancelable);1070 continueWithDefaultBehavior &= dispatchBeforeInputEvent(*startRoot, inputTypeName, data, WTFMove(dataTransfer), targetRanges, cancelable); 1071 1071 if (endRoot && endRoot != startRoot) 1072 continueWithDefaultBehavior &= dispatchBeforeInputEvent(*endRoot, inputTypeName, data, targetRanges, cancelable);1072 continueWithDefaultBehavior &= dispatchBeforeInputEvent(*endRoot, inputTypeName, data, WTFMove(dataTransfer), targetRanges, cancelable); 1073 1073 return continueWithDefaultBehavior; 1074 1074 } 1075 1075 1076 static void dispatchInputEvents(RefPtr<Element> startRoot, RefPtr<Element> endRoot, const AtomicString& inputTypeName, const String& data = { }, const Vector<RefPtr<StaticRange>>& targetRanges = { })1076 static void dispatchInputEvents(RefPtr<Element> startRoot, RefPtr<Element> endRoot, const AtomicString& inputTypeName, const String& data = { }, RefPtr<DataTransfer>&& dataTransfer = nullptr, const Vector<RefPtr<StaticRange>>& targetRanges = { }) 1077 1077 { 1078 1078 if (startRoot) 1079 dispatchInputEvent(*startRoot, inputTypeName, data, targetRanges);1079 dispatchInputEvent(*startRoot, inputTypeName, data, WTFMove(dataTransfer), targetRanges); 1080 1080 if (endRoot && endRoot != startRoot) 1081 dispatchInputEvent(*endRoot, inputTypeName, data, targetRanges);1081 dispatchInputEvent(*endRoot, inputTypeName, data, WTFMove(dataTransfer), targetRanges); 1082 1082 } 1083 1083 … … 1088 1088 return true; 1089 1089 1090 return dispatchBeforeInputEvents(composition->startingRootEditableElement(), composition->endingRootEditableElement(), command.inputEventTypeName(), command.inputEventData(), targetRanges, command.isBeforeInputEventCancelable());1090 return dispatchBeforeInputEvents(composition->startingRootEditableElement(), composition->endingRootEditableElement(), command.inputEventTypeName(), command.inputEventData(), command.inputEventDataTransfer(), targetRanges, command.isBeforeInputEventCancelable()); 1091 1091 } 1092 1092 … … 1107 1107 1108 1108 changeSelectionAfterCommand(newSelection, options); 1109 dispatchInputEvents(composition->startingRootEditableElement(), composition->endingRootEditableElement(), cmd->inputEventTypeName(), cmd->inputEventData() );1109 dispatchInputEvents(composition->startingRootEditableElement(), composition->endingRootEditableElement(), cmd->inputEventTypeName(), cmd->inputEventData(), cmd->inputEventDataTransfer()); 1110 1110 1111 1111 updateEditorUINowIfScheduled(); -
trunk/Source/WebCore/editing/ReplaceRangeWithTextCommand.cpp
r207670 r207841 28 28 29 29 #include "AlternativeTextController.h" 30 #include "DataTransfer.h" 30 31 #include "Document.h" 31 32 #include "DocumentFragment.h" … … 47 48 } 48 49 50 bool ReplaceRangeWithTextCommand::willApplyCommand() 51 { 52 m_textFragment = createFragmentFromText(*m_rangeToBeReplaced, m_text); 53 return CompositeEditCommand::willApplyCommand(); 54 } 55 49 56 void ReplaceRangeWithTextCommand::doApply() 50 57 { … … 62 69 63 70 applyCommandToComposite(SetSelectionCommand::create(selection, FrameSelection::defaultSetSelectionOptions())); 64 65 auto fragment = createFragmentFromText(*m_rangeToBeReplaced, m_text); 66 applyCommandToComposite(ReplaceSelectionCommand::create(document(), WTFMove(fragment), ReplaceSelectionCommand::MatchStyle, EditActionPaste)); 71 applyCommandToComposite(ReplaceSelectionCommand::create(document(), WTFMove(m_textFragment), ReplaceSelectionCommand::MatchStyle, EditActionPaste)); 67 72 } 68 73 … … 75 80 } 76 81 82 RefPtr<DataTransfer> ReplaceRangeWithTextCommand::inputEventDataTransfer() const 83 { 84 if (!isEditingTextAreaOrTextInput()) 85 return DataTransfer::createForInputEvent(m_text, createMarkup(*m_textFragment)); 86 87 return CompositeEditCommand::inputEventDataTransfer(); 88 } 89 77 90 Vector<RefPtr<StaticRange>> ReplaceRangeWithTextCommand::targetRanges() const 78 91 { -
trunk/Source/WebCore/editing/ReplaceRangeWithTextCommand.h
r207670 r207841 31 31 namespace WebCore { 32 32 33 class DocumentFragment; 34 33 35 class ReplaceRangeWithTextCommand : public CompositeEditCommand { 34 36 public: … … 40 42 private: 41 43 ReplaceRangeWithTextCommand(RefPtr<Range> rangeToBeReplaced, const String& text); 44 bool willApplyCommand() final; 42 45 void doApply() override; 43 46 String inputEventData() const final; 47 RefPtr<DataTransfer> inputEventDataTransfer() const final; 44 48 Vector<RefPtr<StaticRange>> targetRanges() const final; 45 49 46 50 RefPtr<Range> m_rangeToBeReplaced; 51 RefPtr<DocumentFragment> m_textFragment; 47 52 String m_text; 48 53 }; -
trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp
r207396 r207841 33 33 #include "BreakBlockquoteCommand.h" 34 34 #include "CSSStyleDeclaration.h" 35 #include "DataTransfer.h" 35 36 #include "Document.h" 36 37 #include "DocumentFragment.h" … … 69 70 70 71 enum EFragmentType { EmptyFragment, SingleTextNodeFragment, TreeFragment }; 72 73 static void removeHeadContents(ReplacementFragment&); 71 74 72 75 // --- ReplacementFragment helper class … … 910 913 } 911 914 915 bool ReplaceSelectionCommand::willApplyCommand() 916 { 917 ensureReplacementFragment(); 918 m_documentFragmentPlainText = m_documentFragment->textContent(); 919 m_documentFragmentHTMLMarkup = createMarkup(*m_documentFragment); 920 return CompositeEditCommand::willApplyCommand(); 921 } 922 912 923 void ReplaceSelectionCommand::doApply() 913 924 { … … 923 934 m_matchStyle = false; 924 935 925 ReplacementFragment fragment(document(), m_documentFragment.get(), selection);936 ReplacementFragment& fragment = *ensureReplacementFragment(); 926 937 if (performTrivialReplace(fragment)) 927 938 return; … … 1045 1056 // any work performed after this that queries or uses the typing style. 1046 1057 frame().selection().clearTypingStyle(); 1047 1048 removeHeadContents(fragment);1049 1058 1050 1059 // We don't want the destination to end up inside nodes that weren't selected. To avoid that, we move the … … 1263 1272 } 1264 1273 1274 RefPtr<DataTransfer> ReplaceSelectionCommand::inputEventDataTransfer() const 1275 { 1276 if (isEditingTextAreaOrTextInput()) 1277 return CompositeEditCommand::inputEventDataTransfer(); 1278 1279 return DataTransfer::createForInputEvent(m_documentFragmentPlainText, m_documentFragmentHTMLMarkup); 1280 } 1281 1265 1282 bool ReplaceSelectionCommand::shouldRemoveEndBR(Node* endBR, const VisiblePosition& originalVisPosBeforeEndBR) 1266 1283 { … … 1496 1513 } 1497 1514 1515 ReplacementFragment* ReplaceSelectionCommand::ensureReplacementFragment() 1516 { 1517 if (!m_replacementFragment) { 1518 m_replacementFragment = std::make_unique<ReplacementFragment>(document(), m_documentFragment.get(), endingSelection()); 1519 removeHeadContents(*m_replacementFragment); 1520 } 1521 1522 return m_replacementFragment.get(); 1523 } 1524 1498 1525 // During simple pastes, where we're just pasting a text node into a run of text, we insert the text node 1499 1526 // directly into the text node that holds the selection. This is much faster than the generalized code in -
trunk/Source/WebCore/editing/ReplaceSelectionCommand.h
r207010 r207841 60 60 61 61 String inputEventData() const final; 62 RefPtr<DataTransfer> inputEventDataTransfer() const final; 63 bool willApplyCommand() final; 62 64 virtual void doApply(); 63 65 … … 112 114 void mergeTextNodesAroundPosition(Position&, Position& positionOnlyToBeUpdated); 113 115 116 ReplacementFragment* ensureReplacementFragment(); 114 117 bool performTrivialReplace(const ReplacementFragment&); 115 118 … … 122 125 bool m_matchStyle; 123 126 RefPtr<DocumentFragment> m_documentFragment; 127 std::unique_ptr<ReplacementFragment> m_replacementFragment; 128 String m_documentFragmentHTMLMarkup; 129 String m_documentFragmentPlainText; 124 130 bool m_preventNesting; 125 131 bool m_movingParagraph; -
trunk/Source/WebCore/editing/SpellingCorrectionCommand.cpp
r207670 r207841 28 28 29 29 #include "AlternativeTextController.h" 30 #include "DataTransfer.h" 30 31 #include "Document.h" 31 32 #include "DocumentFragment.h" … … 91 92 } 92 93 94 bool SpellingCorrectionCommand::willApplyCommand() 95 { 96 m_correctionFragment = createFragmentFromText(*m_rangeToBeCorrected, m_correction); 97 return CompositeEditCommand::willApplyCommand(); 98 } 99 93 100 void SpellingCorrectionCommand::doApply() 94 101 { … … 103 110 return; 104 111 105 auto fragment = createFragmentFromText(*m_rangeToBeCorrected, m_correction);106 107 112 applyCommandToComposite(SetSelectionCommand::create(m_selectionToBeCorrected, FrameSelection::defaultSetSelectionOptions() | FrameSelection::SpellCorrectionTriggered)); 108 113 #if USE(AUTOCORRECTION_PANEL) … … 110 115 #endif 111 116 112 applyCommandToComposite(ReplaceSelectionCommand::create(document(), WTFMove( fragment), ReplaceSelectionCommand::MatchStyle, EditActionPaste));117 applyCommandToComposite(ReplaceSelectionCommand::create(document(), WTFMove(m_correctionFragment), ReplaceSelectionCommand::MatchStyle, EditActionPaste)); 113 118 } 114 119 … … 127 132 } 128 133 134 RefPtr<DataTransfer> SpellingCorrectionCommand::inputEventDataTransfer() const 135 { 136 if (!isEditingTextAreaOrTextInput()) 137 return DataTransfer::createForInputEvent(m_correction, createMarkup(*m_correctionFragment)); 138 139 return CompositeEditCommand::inputEventDataTransfer(); 140 } 141 129 142 bool SpellingCorrectionCommand::shouldRetainAutocorrectionIndicator() const 130 143 { -
trunk/Source/WebCore/editing/SpellingCorrectionCommand.h
r207670 r207841 40 40 private: 41 41 SpellingCorrectionCommand(PassRefPtr<Range> rangeToBeCorrected, const String& correction); 42 bool willApplyCommand() final; 42 43 void doApply() override; 43 44 bool shouldRetainAutocorrectionIndicator() const override; … … 45 46 String inputEventData() const final; 46 47 Vector<RefPtr<StaticRange>> targetRanges() const final; 48 RefPtr<DataTransfer> inputEventDataTransfer() const final; 47 49 48 50 RefPtr<Range> m_rangeToBeCorrected; 49 51 VisibleSelection m_selectionToBeCorrected; 52 RefPtr<DocumentFragment> m_correctionFragment; 50 53 String m_corrected; 51 54 String m_correction; -
trunk/Source/WebCore/platform/Pasteboard.h
r207797 r207841 139 139 public: 140 140 Pasteboard(); 141 ~Pasteboard();141 virtual ~Pasteboard(); 142 142 143 143 #if PLATFORM(GTK) … … 155 155 static std::unique_ptr<Pasteboard> createPrivate(); // Temporary pasteboard. Can put data on this and then write to another pasteboard with writePasteboard. 156 156 157 bool hasData();158 Vector<String> types();159 String readString(const String& type);160 161 v oid writeString(const String& type, const String& data);162 v oid clear();163 v oid clear(const String& type);164 165 v oid read(PasteboardPlainText&);166 v oid read(PasteboardWebContentReader&);167 168 v oid write(const PasteboardURL&);169 v oid write(const PasteboardImage&);170 v oid write(const PasteboardWebContent&);171 172 Vector<String> readFilenames();173 bool canSmartReplace();174 175 v oid writeMarkup(const String& markup);157 virtual bool hasData(); 158 virtual Vector<String> types(); 159 virtual String readString(const String& type); 160 161 virtual void writeString(const String& type, const String& data); 162 virtual void clear(); 163 virtual void clear(const String& type); 164 165 virtual void read(PasteboardPlainText&); 166 virtual void read(PasteboardWebContentReader&); 167 168 virtual void write(const PasteboardURL&); 169 virtual void write(const PasteboardImage&); 170 virtual void write(const PasteboardWebContent&); 171 172 virtual Vector<String> readFilenames(); 173 virtual bool canSmartReplace(); 174 175 virtual void writeMarkup(const String& markup); 176 176 enum SmartReplaceOption { CanSmartReplace, CannotSmartReplace }; 177 WEBCORE_EXPORT void writePlainText(const String&, SmartReplaceOption); // FIXME: Two separate functions would be clearer than one function with an argument.178 v oid writePasteboard(const Pasteboard& sourcePasteboard);177 virtual WEBCORE_EXPORT void writePlainText(const String&, SmartReplaceOption); // FIXME: Two separate functions would be clearer than one function with an argument. 178 virtual void writePasteboard(const Pasteboard& sourcePasteboard); 179 179 180 180 #if ENABLE(DRAG_SUPPORT) … … 182 182 static std::unique_ptr<Pasteboard> createForDragAndDrop(const DragData&); 183 183 184 v oid setDragImage(DragImageRef, const IntPoint& hotSpot);184 virtual void setDragImage(DragImageRef, const IntPoint& hotSpot); 185 185 #endif 186 186 -
trunk/Source/WebCore/platform/StaticPasteboard.h
r207840 r207841 24 24 */ 25 25 26 #include "config.h" 27 #include "InputEvent.h" 26 #pragma once 28 27 29 #include "DOMWindow.h" 30 #include "EventNames.h" 31 #include "Node.h" 32 #include "NotImplemented.h" 33 #include <wtf/NeverDestroyed.h> 34 #include <wtf/Vector.h> 28 #include "Pasteboard.h" 29 #include <wtf/HashMap.h> 30 #include <wtf/text/StringHash.h> 35 31 36 32 namespace WebCore { 37 33 38 InputEvent::InputEvent(const AtomicString& eventType, const String& inputType, bool canBubble, bool cancelable, DOMWindow* view, const String& data, const Vector<RefPtr<StaticRange>>& targetRanges, int detail) 39 : UIEvent(eventType, canBubble, cancelable, view, detail) 40 , m_inputType(inputType) 41 , m_data(data) 42 , m_targetRanges(targetRanges) 43 { 34 typedef HashMap<String, String> TypeToStringMap; 35 36 class StaticPasteboard final : public Pasteboard { 37 public: 38 static std::unique_ptr<StaticPasteboard> create(TypeToStringMap&&); 39 40 StaticPasteboard(TypeToStringMap&&); 41 42 bool hasData() final; 43 Vector<String> types() final; 44 String readString(const String& type) final; 45 46 void writeString(const String&, const String&) final { } 47 void clear() final { } 48 void clear(const String&) final { } 49 50 void read(PasteboardPlainText&) final { } 51 void read(PasteboardWebContentReader&) final { } 52 53 void write(const PasteboardURL&) final { } 54 void write(const PasteboardImage&) final { } 55 void write(const PasteboardWebContent&) final { } 56 57 Vector<String> readFilenames() final { return { }; } 58 bool canSmartReplace() final { return false; } 59 60 void writeMarkup(const String&) final { } 61 void writePlainText(const String&, SmartReplaceOption) final { } 62 void writePasteboard(const Pasteboard&) final { } 63 64 #if ENABLE(DRAG_SUPPORT) 65 void setDragImage(DragImageRef, const IntPoint&) final { } 66 #endif 67 68 private: 69 TypeToStringMap m_typeToStringMap; 70 }; 71 44 72 } 45 46 InputEvent::InputEvent(const AtomicString& eventType, const Init& initializer, IsTrusted isTrusted)47 : UIEvent(eventType, initializer, isTrusted)48 , m_inputType(emptyString())49 , m_data(initializer.data)50 {51 }52 53 } // namespace WebCore -
trunk/Source/WebCore/platform/efl/PasteboardEfl.cpp
r176780 r207841 126 126 } 127 127 128 void Pasteboard::writeMarkup(const String&) 129 { 130 notImplemented(); 128 131 } 132 133 void Pasteboard::write(const PasteboardWebContent&) 134 { 135 notImplemented(); 136 } 137 138 void Pasteboard::read(PasteboardWebContentReader&) 139 { 140 notImplemented(); 141 } 142 143 void Pasteboard::write(const PasteboardImage&) 144 { 145 notImplemented(); 146 } 147 148 } -
trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp
r206256 r207841 88 88 } 89 89 90 Pasteboard::Pasteboard() 91 : m_selectionData(SelectionData::create()) 92 { 93 } 94 90 95 Pasteboard::~Pasteboard() 91 96 { … … 272 277 } 273 278 279 void Pasteboard::read(PasteboardWebContentReader&) 280 { 281 } 282 274 283 bool Pasteboard::hasData() 275 284 { … … 334 343 } 335 344 336 } 345 void Pasteboard::writeMarkup(const String&) 346 { 347 } 348 349 } -
trunk/Source/WebCore/platform/ios/PasteboardIOS.mm
r205516 r207841 89 89 } 90 90 91 void Pasteboard::writeMarkup(const String&) 92 { 93 } 94 91 95 std::unique_ptr<Pasteboard> Pasteboard::createForCopyAndPaste() 92 96 { -
trunk/Source/WebCore/platform/mac/PasteboardMac.mm
r207797 r207841 108 108 } 109 109 110 Pasteboard::Pasteboard() 111 : m_pasteboardName(emptyString()) 112 , m_changeCount(0) 113 { 114 } 115 110 116 Pasteboard::Pasteboard(const String& pasteboardName) 111 117 : m_pasteboardName(pasteboardName) … … 282 288 } 283 289 290 void Pasteboard::writeMarkup(const String&) 291 { 292 } 293 284 294 void Pasteboard::read(PasteboardPlainText& text) 285 295 { -
trunk/Source/WebCore/platform/win/PasteboardWin.cpp
r203324 r207841 1052 1052 } 1053 1053 1054 void Pasteboard::write(const PasteboardWebContent&) 1055 { 1056 } 1057 1058 void Pasteboard::read(PasteboardWebContentReader&) 1059 { 1060 } 1061 1062 void Pasteboard::write(const PasteboardImage&) 1063 { 1064 } 1065 1054 1066 } // namespace WebCore
Note: See TracChangeset
for help on using the changeset viewer.