• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007, 2008 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 COMPUTER, 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 COMPUTER, 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 "DragData.h"
28 
29 #include "ClipboardQt.h"
30 #include "Document.h"
31 #include "DocumentFragment.h"
32 #include "markup.h"
33 #include "NotImplemented.h"
34 
35 #include <QList>
36 #include <QMimeData>
37 #include <QUrl>
38 #include <QColor>
39 
40 namespace WebCore {
41 
canSmartReplace() const42 bool DragData::canSmartReplace() const
43 {
44     return false;
45 }
46 
containsColor() const47 bool DragData::containsColor() const
48 {
49     if (!m_platformDragData)
50         return false;
51     return m_platformDragData->hasColor();
52 }
53 
containsFiles() const54 bool DragData::containsFiles() const
55 {
56     if (!m_platformDragData)
57         return false;
58     QList<QUrl> urls = m_platformDragData->urls();
59     foreach(const QUrl &url, urls) {
60         if (!url.toLocalFile().isEmpty())
61             return true;
62     }
63     return false;
64 }
65 
asFilenames(Vector<String> & result) const66 void DragData::asFilenames(Vector<String>& result) const
67 {
68     if (!m_platformDragData)
69         return;
70     QList<QUrl> urls = m_platformDragData->urls();
71     foreach(const QUrl &url, urls) {
72         QString file = url.toLocalFile();
73         if (!file.isEmpty())
74             result.append(file);
75     }
76 }
77 
containsPlainText() const78 bool DragData::containsPlainText() const
79 {
80     if (!m_platformDragData)
81         return false;
82     return m_platformDragData->hasText() || m_platformDragData->hasUrls();
83 }
84 
asPlainText() const85 String DragData::asPlainText() const
86 {
87     if (!m_platformDragData)
88         return String();
89     String text = m_platformDragData->text();
90     if (!text.isEmpty())
91         return text;
92 
93     // FIXME: Should handle rich text here
94 
95     return asURL(0);
96 }
97 
asColor() const98 Color DragData::asColor() const
99 {
100     if (!m_platformDragData)
101         return Color();
102     return qvariant_cast<QColor>(m_platformDragData->colorData());
103 }
104 
createClipboard(ClipboardAccessPolicy policy) const105 PassRefPtr<Clipboard> DragData::createClipboard(ClipboardAccessPolicy policy) const
106 {
107     return ClipboardQt::create(policy, m_platformDragData);
108 }
109 
containsCompatibleContent() const110 bool DragData::containsCompatibleContent() const
111 {
112     if (!m_platformDragData)
113         return false;
114     return containsColor() || containsURL() || m_platformDragData->hasHtml() || m_platformDragData->hasText();
115 }
116 
containsURL() const117 bool DragData::containsURL() const
118 {
119     if (!m_platformDragData)
120         return false;
121     return m_platformDragData->hasUrls();
122 }
123 
asURL(String * title) const124 String DragData::asURL(String* title) const
125 {
126     if (!m_platformDragData)
127         return String();
128     QList<QUrl> urls = m_platformDragData->urls();
129     return urls.first().toString();
130 }
131 
132 
asFragment(Document * doc) const133 PassRefPtr<DocumentFragment> DragData::asFragment(Document* doc) const
134 {
135     if (m_platformDragData && m_platformDragData->hasHtml())
136         return createFragmentFromMarkup(doc, m_platformDragData->html(), "");
137 
138     return 0;
139 }
140 
141 }
142 
143