carlosgc@webkit.org | 528e601 | 2014-10-04 08:37:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "Editor.h" |
| 28 | |
| 29 | #include "ClipboardUtilitiesWin.h" |
| 30 | #include "DocumentFragment.h" |
| 31 | #include "Frame.h" |
cdumez@apple.com | 7035dd7 | 2022-05-18 16:00:15 +0000 | [diff] [blame] | 32 | #include "FrameDestructionObserverInlines.h" |
carlosgc@webkit.org | 528e601 | 2014-10-04 08:37:57 +0000 | [diff] [blame] | 33 | #include "FrameSelection.h" |
| 34 | #include "Pasteboard.h" |
darin@apple.com | 2e2bfd7 | 2020-07-29 16:36:40 +0000 | [diff] [blame] | 35 | #include "Range.h" |
carlosgc@webkit.org | 528e601 | 2014-10-04 08:37:57 +0000 | [diff] [blame] | 36 | #include "windows.h" |
| 37 | |
| 38 | namespace WebCore { |
| 39 | |
mitz@apple.com | 17d242d | 2018-09-12 22:26:12 +0000 | [diff] [blame] | 40 | void Editor::pasteWithPasteboard(Pasteboard* pasteboard, OptionSet<PasteOption> options) |
carlosgc@webkit.org | 528e601 | 2014-10-04 08:37:57 +0000 | [diff] [blame] | 41 | { |
darin@apple.com | ea4947c | 2020-07-22 04:45:40 +0000 | [diff] [blame] | 42 | auto range = selectedRange(); |
carlosgc@webkit.org | 528e601 | 2014-10-04 08:37:57 +0000 | [diff] [blame] | 43 | if (!range) |
| 44 | return; |
| 45 | |
| 46 | bool chosePlainText; |
darin@apple.com | f91ef17 | 2020-08-03 00:47:52 +0000 | [diff] [blame] | 47 | auto fragment = pasteboard->documentFragment(*m_document.frame(), *range, options.contains(PasteOption::AllowPlainText), chosePlainText); |
mitz@apple.com | 17d242d | 2018-09-12 22:26:12 +0000 | [diff] [blame] | 48 | |
| 49 | if (fragment && options.contains(PasteOption::AsQuotation)) |
| 50 | quoteFragmentForPasting(*fragment); |
| 51 | |
darin@apple.com | ea4947c | 2020-07-22 04:45:40 +0000 | [diff] [blame] | 52 | if (fragment && shouldInsertFragment(*fragment, *range, EditorInsertAction::Pasted)) |
mitz@apple.com | 17d242d | 2018-09-12 22:26:12 +0000 | [diff] [blame] | 53 | pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, options.contains(PasteOption::IgnoreMailBlockquote) ? MailBlockquoteHandling::IgnoreBlockquote : MailBlockquoteHandling::RespectBlockquote); |
carlosgc@webkit.org | 528e601 | 2014-10-04 08:37:57 +0000 | [diff] [blame] | 54 | } |
| 55 | |
drousso@apple.com | 0a75516 | 2021-12-11 02:06:54 +0000 | [diff] [blame] | 56 | void Editor::platformCopyFont() |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | void Editor::platformPasteFont() |
| 61 | { |
| 62 | } |
| 63 | |
carlosgc@webkit.org | 528e601 | 2014-10-04 08:37:57 +0000 | [diff] [blame] | 64 | template <typename PlatformDragData> |
jh718.park@samsung.com | 9f99af5 | 2016-03-15 00:22:45 +0000 | [diff] [blame] | 65 | static RefPtr<DocumentFragment> createFragmentFromPlatformData(PlatformDragData& platformDragData, Frame& frame) |
carlosgc@webkit.org | 528e601 | 2014-10-04 08:37:57 +0000 | [diff] [blame] | 66 | { |
| 67 | if (containsFilenames(&platformDragData)) { |
cdumez@apple.com | 73f55a7c | 2017-05-07 20:02:31 +0000 | [diff] [blame] | 68 | if (auto fragment = fragmentFromFilenames(frame.document(), &platformDragData)) |
carlosgc@webkit.org | 528e601 | 2014-10-04 08:37:57 +0000 | [diff] [blame] | 69 | return fragment; |
| 70 | } |
| 71 | |
| 72 | if (containsHTML(&platformDragData)) { |
jh718.park@samsung.com | 9f99af5 | 2016-03-15 00:22:45 +0000 | [diff] [blame] | 73 | if (RefPtr<DocumentFragment> fragment = fragmentFromHTML(frame.document(), &platformDragData)) |
carlosgc@webkit.org | 528e601 | 2014-10-04 08:37:57 +0000 | [diff] [blame] | 74 | return fragment; |
| 75 | } |
| 76 | return nullptr; |
| 77 | } |
| 78 | |
darin@apple.com | e729ead | 2020-04-27 15:05:00 +0000 | [diff] [blame] | 79 | RefPtr<DocumentFragment> Editor::webContentFromPasteboard(Pasteboard& pasteboard, const SimpleRange&, bool /*allowPlainText*/, bool& /*chosePlainText*/) |
carlosgc@webkit.org | 528e601 | 2014-10-04 08:37:57 +0000 | [diff] [blame] | 80 | { |
| 81 | if (COMPtr<IDataObject> platformDragData = pasteboard.dataObject()) |
shihchieh_lee@apple.com | 501b37c | 2020-04-28 16:36:38 +0000 | [diff] [blame] | 82 | return createFragmentFromPlatformData(*platformDragData, *m_document.frame()); |
carlosgc@webkit.org | 528e601 | 2014-10-04 08:37:57 +0000 | [diff] [blame] | 83 | |
shihchieh_lee@apple.com | 501b37c | 2020-04-28 16:36:38 +0000 | [diff] [blame] | 84 | return createFragmentFromPlatformData(pasteboard.dragDataMap(), *m_document.frame()); |
carlosgc@webkit.org | 528e601 | 2014-10-04 08:37:57 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | } // namespace WebCore |