1/*
2 *  This library is free software; you can redistribute it and/or
3 *  modify it under the terms of the GNU Lesser General Public
4 *  License as published by the Free Software Foundation; either
5 *  version 2 of the License, or (at your option) any later version.
6 *
7 *  This library is distributed in the hope that it will be useful,
8 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
9 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 *  Lesser General Public License for more details.
11 *
12 *  You should have received a copy of the GNU Lesser General Public
13 *  License along with this library; if not, write to the Free Software
14 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
15 */
16
17#include "config.h"
18#include "DragData.h"
19
20#include "DataObjectGtk.h"
21#include "Document.h"
22#include "DocumentFragment.h"
23#include "Frame.h"
24#include "markup.h"
25
26namespace WebCore {
27
28bool DragData::canSmartReplace() const
29{
30    return false;
31}
32
33bool DragData::containsColor() const
34{
35    return false;
36}
37
38bool DragData::containsFiles() const
39{
40    return m_platformDragData->hasFilenames();
41}
42
43unsigned DragData::numberOfFiles() const
44{
45    return m_platformDragData->filenames().size();
46}
47
48void DragData::asFilenames(Vector<String>& result) const
49{
50    result = m_platformDragData->filenames();
51}
52
53bool DragData::containsPlainText() const
54{
55    return m_platformDragData->hasText();
56}
57
58String DragData::asPlainText(Frame*) const
59{
60    return m_platformDragData->text();
61}
62
63Color DragData::asColor() const
64{
65    return Color();
66}
67
68bool DragData::containsCompatibleContent() const
69{
70    return containsPlainText() || containsURL(0) || m_platformDragData->hasMarkup() || containsColor() || containsFiles();
71}
72
73bool DragData::containsURL(Frame* frame, FilenameConversionPolicy filenamePolicy) const
74{
75    return !asURL(frame, filenamePolicy).isEmpty();
76}
77
78String DragData::asURL(Frame*, FilenameConversionPolicy filenamePolicy, String* title) const
79{
80    if (!m_platformDragData->hasURL())
81        return String();
82    if (filenamePolicy != ConvertFilenames) {
83        URL url(URL(), m_platformDragData->url());
84        if (url.isLocalFile())
85            return String();
86    }
87
88    String url(m_platformDragData->url());
89    if (title)
90        *title = m_platformDragData->urlLabel();
91    return url;
92}
93
94
95PassRefPtr<DocumentFragment> DragData::asFragment(Frame* frame, Range&, bool, bool&) const
96{
97    if (!m_platformDragData->hasMarkup())
98        return nullptr;
99
100    if (!frame->document())
101        return nullptr;
102
103    return createFragmentFromMarkup(*frame->document(), m_platformDragData->markup(), "");
104}
105
106}
107