OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2007 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 // Modified from Apple's version to not directly call any windows methods as | |
27 // they may not be available to us in the multiprocess | |
28 | |
29 #include "config.h" | |
30 #include "DragData.h" | |
31 | |
32 #include "ClipboardWin.h" | |
33 #include "ClipboardUtilitiesWin.h" | |
34 #include "DocumentFragment.h" | |
35 #include "KURL.h" | |
36 #include "PlatformString.h" | |
37 #include "Markup.h" | |
38 #include "WCDataObject.h" | |
39 | |
40 #undef LOG | |
41 #include "base/file_util.h" | |
42 #include "base/string_util.h" | |
43 #include "net/base/base64.h" | |
44 #include "webkit/glue/glue_util.h" | |
45 #include "webkit/glue/webdropdata.h" | |
46 #include "webkit/glue/webkit_glue.h" | |
47 | |
48 namespace { | |
49 | |
50 bool containsHTML(const WebDropData& drop_data) { | |
51 std::wstring html; | |
52 return drop_data.cf_html.length() > 0 | |
53 || drop_data.text_html.length() > 0; | |
54 } | |
55 | |
56 // Our DragDataRef is actually a WebDropData* instead of a IDataObject*. | |
57 // Provide a helper method for converting back. | |
58 WebDropData* dropData(DragDataRef dragData) { | |
59 return reinterpret_cast<WebDropData*>(dragData); | |
60 } | |
61 | |
62 } | |
63 | |
64 namespace WebCore { | |
65 | |
66 PassRefPtr<Clipboard> DragData::createClipboard(ClipboardAccessPolicy policy) co
nst | |
67 { | |
68 WCDataObject* data; | |
69 WCDataObject::createInstance(&data); | |
70 RefPtr<ClipboardWin> clipboard = ClipboardWin::create(true, data, policy); | |
71 // The clipboard keeps a reference to the WCDataObject, so we can release | |
72 // our reference to it. | |
73 data->Release(); | |
74 | |
75 return clipboard.release(); | |
76 } | |
77 | |
78 bool DragData::containsURL() const | |
79 { | |
80 return dropData(m_platformDragData)->url.is_valid(); | |
81 } | |
82 | |
83 String DragData::asURL(String* title) const | |
84 { | |
85 WebDropData* data = dropData(m_platformDragData); | |
86 if (!data->url.is_valid()) | |
87 return String(); | |
88 | |
89 // |title| can be NULL | |
90 if (title) | |
91 *title = webkit_glue::StdWStringToString(data->url_title); | |
92 return webkit_glue::StdStringToString(data->url.spec()); | |
93 } | |
94 | |
95 bool DragData::containsFiles() const | |
96 { | |
97 return !dropData(m_platformDragData)->filenames.empty(); | |
98 } | |
99 | |
100 void DragData::asFilenames(Vector<String>& result) const | |
101 { | |
102 WebDropData* data = dropData(m_platformDragData); | |
103 for (size_t i = 0; i < data->filenames.size(); ++i) { | |
104 result.append(webkit_glue::StdWStringToString(data->filenames[i])); | |
105 } | |
106 } | |
107 | |
108 bool DragData::containsPlainText() const | |
109 { | |
110 return !dropData(m_platformDragData)->plain_text.empty(); | |
111 } | |
112 | |
113 String DragData::asPlainText() const | |
114 { | |
115 return webkit_glue::StdWStringToString(dropData( | |
116 m_platformDragData)->plain_text); | |
117 } | |
118 | |
119 bool DragData::containsColor() const | |
120 { | |
121 return false; | |
122 } | |
123 | |
124 bool DragData::canSmartReplace() const | |
125 { | |
126 // Mimic the situations in which mac allows drag&drop to do a smart replace. | |
127 // This is allowed whenever the drag data contains a 'range' (ie., | |
128 // ClipboardWin::writeRange is called). For example, dragging a link | |
129 // should not result in a space being added. | |
130 WebDropData* data = dropData(m_platformDragData); | |
131 return !data->cf_html.empty() && !data->plain_text.empty() && | |
132 !data->url.is_valid(); | |
133 } | |
134 | |
135 bool DragData::containsCompatibleContent() const | |
136 { | |
137 return containsPlainText() || containsURL() | |
138 || ::containsHTML(*dropData(m_platformDragData)) | |
139 || containsColor(); | |
140 } | |
141 | |
142 PassRefPtr<DocumentFragment> DragData::asFragment(Document* doc) const | |
143 { | |
144 /* | |
145 * Order is richest format first. On OSX this is: | |
146 * * Web Archive | |
147 * * Filenames | |
148 * * HTML | |
149 * * RTF | |
150 * * TIFF | |
151 * * PICT | |
152 */ | |
153 | |
154 // TODO(tc): Disabled because containsFilenames is hardcoded to return | |
155 // false. We need to implement fragmentFromFilenames when this is | |
156 // re-enabled in Apple's win port. | |
157 //if (containsFilenames()) | |
158 // if (PassRefPtr<DocumentFragment> fragment = fragmentFromFilenames(doc
, m_platformDragData)) | |
159 // return fragment; | |
160 | |
161 WebDropData* data = dropData(m_platformDragData); | |
162 if (!data->cf_html.empty()) { | |
163 RefPtr<DocumentFragment> fragment = fragmentFromCF_HTML(doc, | |
164 webkit_glue::StdWStringToString(data->cf_html)); | |
165 return fragment; | |
166 } | |
167 | |
168 if (!data->text_html.empty()) { | |
169 String url; | |
170 RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(doc, | |
171 webkit_glue::StdWStringToString(data->text_html), url); | |
172 return fragment; | |
173 } | |
174 | |
175 return 0; | |
176 } | |
177 | |
178 Color DragData::asColor() const | |
179 { | |
180 return Color(); | |
181 } | |
182 | |
183 } | |
OLD | NEW |