Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/app/htmltransferable.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <vcl/htmltransferable.hxx>
21
#include <sot/exchange.hxx>
22
#include <sot/formats.hxx>
23
#include <vcl/svapp.hxx>
24
#include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp>
25
#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
26
#include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
27
#include <cppuhelper/queryinterface.hxx>
28
#include <boost/property_tree/json_parser.hpp>
29
30
using namespace ::com::sun::star;
31
32
namespace vcl::unohelper
33
{
34
HtmlTransferable::HtmlTransferable(OString sData)
35
0
    : data(std::move(sData))
36
0
{
37
0
}
38
39
0
HtmlTransferable::~HtmlTransferable() {}
40
41
// css::uno::XInterface
42
uno::Any HtmlTransferable::queryInterface(const uno::Type& rType)
43
0
{
44
0
    uno::Any aRet = ::cppu::queryInterface(rType, static_cast<datatransfer::XTransferable*>(this));
45
0
    return (aRet.hasValue() ? aRet : OWeakObject::queryInterface(rType));
46
0
}
47
48
// css::datatransfer::XTransferable
49
uno::Any HtmlTransferable::getTransferData(const datatransfer::DataFlavor& rFlavor)
50
0
{
51
0
    SotClipboardFormatId nT = SotExchange::GetFormat(rFlavor);
52
0
    if (nT != SotClipboardFormatId::HTML)
53
0
    {
54
0
        throw datatransfer::UnsupportedFlavorException();
55
0
    }
56
0
    size_t size = data.getLength();
57
0
    uno::Sequence<sal_Int8> sData(size);
58
0
    std::memcpy(sData.getArray(), data.getStr(), size);
59
0
    return uno::Any(sData);
60
0
}
61
62
uno::Sequence<datatransfer::DataFlavor> HtmlTransferable::getTransferDataFlavors()
63
0
{
64
0
    uno::Sequence<datatransfer::DataFlavor> aDataFlavors(1);
65
0
    auto ref = aDataFlavors.getArray()[0];
66
0
    ref.MimeType = "text/html";
67
0
    ref.DataType = cppu::UnoType<uno::Sequence<sal_Int8>>::get();
68
0
    SotExchange::GetFormatDataFlavor(SotClipboardFormatId::HTML, aDataFlavors.getArray()[0]);
69
0
    return aDataFlavors;
70
0
}
71
72
sal_Bool HtmlTransferable::isDataFlavorSupported(const datatransfer::DataFlavor& rFlavor)
73
0
{
74
0
    SotClipboardFormatId nT = SotExchange::GetFormat(rFlavor);
75
0
    return (nT == SotClipboardFormatId::HTML);
76
0
}
77
78
} // namespace vcl::unohelper