blob: 7cd3cbfe6beecfffed12926745898864f0378745 [file] [log] [blame]
carlosgc@webkit.org528e6012014-10-04 08:37:57 +00001/*
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.com7035dd72022-05-18 16:00:15 +000032#include "FrameDestructionObserverInlines.h"
carlosgc@webkit.org528e6012014-10-04 08:37:57 +000033#include "FrameSelection.h"
34#include "Pasteboard.h"
darin@apple.com2e2bfd72020-07-29 16:36:40 +000035#include "Range.h"
carlosgc@webkit.org528e6012014-10-04 08:37:57 +000036#include "windows.h"
37
38namespace WebCore {
39
mitz@apple.com17d242d2018-09-12 22:26:12 +000040void Editor::pasteWithPasteboard(Pasteboard* pasteboard, OptionSet<PasteOption> options)
carlosgc@webkit.org528e6012014-10-04 08:37:57 +000041{
darin@apple.comea4947c2020-07-22 04:45:40 +000042 auto range = selectedRange();
carlosgc@webkit.org528e6012014-10-04 08:37:57 +000043 if (!range)
44 return;
45
46 bool chosePlainText;
darin@apple.comf91ef172020-08-03 00:47:52 +000047 auto fragment = pasteboard->documentFragment(*m_document.frame(), *range, options.contains(PasteOption::AllowPlainText), chosePlainText);
mitz@apple.com17d242d2018-09-12 22:26:12 +000048
49 if (fragment && options.contains(PasteOption::AsQuotation))
50 quoteFragmentForPasting(*fragment);
51
darin@apple.comea4947c2020-07-22 04:45:40 +000052 if (fragment && shouldInsertFragment(*fragment, *range, EditorInsertAction::Pasted))
mitz@apple.com17d242d2018-09-12 22:26:12 +000053 pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, options.contains(PasteOption::IgnoreMailBlockquote) ? MailBlockquoteHandling::IgnoreBlockquote : MailBlockquoteHandling::RespectBlockquote);
carlosgc@webkit.org528e6012014-10-04 08:37:57 +000054}
55
drousso@apple.com0a755162021-12-11 02:06:54 +000056void Editor::platformCopyFont()
57{
58}
59
60void Editor::platformPasteFont()
61{
62}
63
carlosgc@webkit.org528e6012014-10-04 08:37:57 +000064template <typename PlatformDragData>
jh718.park@samsung.com9f99af52016-03-15 00:22:45 +000065static RefPtr<DocumentFragment> createFragmentFromPlatformData(PlatformDragData& platformDragData, Frame& frame)
carlosgc@webkit.org528e6012014-10-04 08:37:57 +000066{
67 if (containsFilenames(&platformDragData)) {
cdumez@apple.com73f55a7c2017-05-07 20:02:31 +000068 if (auto fragment = fragmentFromFilenames(frame.document(), &platformDragData))
carlosgc@webkit.org528e6012014-10-04 08:37:57 +000069 return fragment;
70 }
71
72 if (containsHTML(&platformDragData)) {
jh718.park@samsung.com9f99af52016-03-15 00:22:45 +000073 if (RefPtr<DocumentFragment> fragment = fragmentFromHTML(frame.document(), &platformDragData))
carlosgc@webkit.org528e6012014-10-04 08:37:57 +000074 return fragment;
75 }
76 return nullptr;
77}
78
darin@apple.come729ead2020-04-27 15:05:00 +000079RefPtr<DocumentFragment> Editor::webContentFromPasteboard(Pasteboard& pasteboard, const SimpleRange&, bool /*allowPlainText*/, bool& /*chosePlainText*/)
carlosgc@webkit.org528e6012014-10-04 08:37:57 +000080{
81 if (COMPtr<IDataObject> platformDragData = pasteboard.dataObject())
shihchieh_lee@apple.com501b37c2020-04-28 16:36:38 +000082 return createFragmentFromPlatformData(*platformDragData, *m_document.frame());
carlosgc@webkit.org528e6012014-10-04 08:37:57 +000083
shihchieh_lee@apple.com501b37c2020-04-28 16:36:38 +000084 return createFragmentFromPlatformData(pasteboard.dragDataMap(), *m_document.frame());
carlosgc@webkit.org528e6012014-10-04 08:37:57 +000085}
86
87} // namespace WebCore