Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: Source/WebCore/platform/win/DragDataWin.cpp

Issue 13642009: WebCore: Remove PLATFORM(WIN) files we do not use. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Baidu Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #include "config.h"
28 #include "DragData.h"
29
30 #include "COMPtr.h"
31 #include "ClipboardUtilitiesWin.h"
32 #include "Frame.h"
33 #include "DocumentFragment.h"
34 #include "Markup.h"
35 #include "TextEncoding.h"
36 #include <objidl.h>
37 #include <shlwapi.h>
38 #include <wininet.h>
39 #include <wtf/Forward.h>
40 #include <wtf/Hashmap.h>
41 #include <wtf/PassRefPtr.h>
42 #include <wtf/RefPtr.h>
43 #include <wtf/text/WTFString.h>
44
45 namespace WebCore {
46
47 DragData::DragData(const DragDataMap& data, const IntPoint& clientPosition, cons t IntPoint& globalPosition,
48 DragOperation sourceOperationMask, DragApplicationFlags flags)
49 : m_clientPosition(clientPosition)
50 , m_globalPosition(globalPosition)
51 , m_platformDragData(0)
52 , m_draggingSourceOperationMask(sourceOperationMask)
53 , m_applicationFlags(flags)
54 , m_dragDataMap(data)
55 {
56 }
57
58 bool DragData::containsURL(Frame*, FilenameConversionPolicy filenamePolicy) cons t
59 {
60 if (m_platformDragData)
61 return SUCCEEDED(m_platformDragData->QueryGetData(urlWFormat()))
62 || SUCCEEDED(m_platformDragData->QueryGetData(urlFormat()))
63 || (filenamePolicy == ConvertFilenames
64 && (SUCCEEDED(m_platformDragData->QueryGetData(filenameWFormat() ))
65 || SUCCEEDED(m_platformDragData->QueryGetData(filenameFormat ()))));
66 return m_dragDataMap.contains(urlWFormat()->cfFormat) || m_dragDataMap.conta ins(urlFormat()->cfFormat)
67 || (filenamePolicy == ConvertFilenames && (m_dragDataMap.contains(filena meWFormat()->cfFormat) || m_dragDataMap.contains(filenameFormat()->cfFormat)));
68 }
69
70 const DragDataMap& DragData::dragDataMap()
71 {
72 if (!m_dragDataMap.isEmpty() || !m_platformDragData)
73 return m_dragDataMap;
74 // Enumerate clipboard content and load it in the map.
75 COMPtr<IEnumFORMATETC> itr;
76
77 if (FAILED(m_platformDragData->EnumFormatEtc(DATADIR_GET, &itr)) || !itr)
78 return m_dragDataMap;
79
80 FORMATETC dataFormat;
81 while (itr->Next(1, &dataFormat, 0) == S_OK) {
82 Vector<String> dataStrings;
83 getClipboardData(m_platformDragData, &dataFormat, dataStrings);
84 if (!dataStrings.isEmpty())
85 m_dragDataMap.set(dataFormat.cfFormat, dataStrings);
86 }
87 return m_dragDataMap;
88 }
89
90 void DragData::getDragFileDescriptorData(int& size, String& pathname)
91 {
92 size = 0;
93 if (m_platformDragData)
94 getFileDescriptorData(m_platformDragData, size, pathname);
95 }
96
97 void DragData::getDragFileContentData(int size, void* dataBlob)
98 {
99 if (m_platformDragData)
100 getFileContentData(m_platformDragData, size, dataBlob);
101 }
102
103 String DragData::asURL(Frame*, FilenameConversionPolicy filenamePolicy, String* title) const
104 {
105 return (m_platformDragData) ? getURL(m_platformDragData, filenamePolicy, tit le) : getURL(&m_dragDataMap, filenamePolicy, title);
106 }
107
108 bool DragData::containsFiles() const
109 {
110 #if OS(WINCE)
111 return false;
112 #else
113 return (m_platformDragData) ? SUCCEEDED(m_platformDragData->QueryGetData(cfH DropFormat())) : m_dragDataMap.contains(cfHDropFormat()->cfFormat);
114 #endif
115 }
116
117 unsigned DragData::numberOfFiles() const
118 {
119 #if OS(WINCE)
120 return 0;
121 #else
122 if (!m_platformDragData)
123 return 0;
124
125 STGMEDIUM medium;
126 if (FAILED(m_platformDragData->GetData(cfHDropFormat(), &medium)))
127 return 0;
128
129 HDROP hdrop = static_cast<HDROP>(GlobalLock(medium.hGlobal));
130
131 if (!hdrop)
132 return 0;
133
134 unsigned numFiles = DragQueryFileW(hdrop, 0xFFFFFFFF, 0, 0);
135
136 DragFinish(hdrop);
137 GlobalUnlock(medium.hGlobal);
138
139 return numFiles;
140 #endif
141 }
142
143 void DragData::asFilenames(Vector<String>& result) const
144 {
145 #if !OS(WINCE)
146 if (m_platformDragData) {
147 WCHAR filename[MAX_PATH];
148
149 STGMEDIUM medium;
150 if (FAILED(m_platformDragData->GetData(cfHDropFormat(), &medium)))
151 return;
152
153 HDROP hdrop = reinterpret_cast<HDROP>(GlobalLock(medium.hGlobal));
154
155 if (!hdrop)
156 return;
157
158 const unsigned numFiles = DragQueryFileW(hdrop, 0xFFFFFFFF, 0, 0);
159 for (unsigned i = 0; i < numFiles; i++) {
160 if (!DragQueryFileW(hdrop, i, filename, WTF_ARRAY_LENGTH(filename)))
161 continue;
162 result.append(static_cast<UChar*>(filename));
163 }
164
165 // Free up memory from drag
166 DragFinish(hdrop);
167
168 GlobalUnlock(medium.hGlobal);
169 return;
170 }
171 result = m_dragDataMap.get(cfHDropFormat()->cfFormat);
172 #endif
173 }
174
175 bool DragData::containsPlainText() const
176 {
177 if (m_platformDragData)
178 return SUCCEEDED(m_platformDragData->QueryGetData(plainTextWFormat()))
179 || SUCCEEDED(m_platformDragData->QueryGetData(plainTextFormat()));
180 return m_dragDataMap.contains(plainTextWFormat()->cfFormat) || m_dragDataMap .contains(plainTextFormat()->cfFormat);
181 }
182
183 String DragData::asPlainText(Frame*) const
184 {
185 return (m_platformDragData) ? getPlainText(m_platformDragData) : getPlainTex t(&m_dragDataMap);
186 }
187
188 bool DragData::containsColor() const
189 {
190 return false;
191 }
192
193 bool DragData::canSmartReplace() const
194 {
195 if (m_platformDragData)
196 return SUCCEEDED(m_platformDragData->QueryGetData(smartPasteFormat()));
197 return m_dragDataMap.contains(smartPasteFormat()->cfFormat);
198 }
199
200 bool DragData::containsCompatibleContent() const
201 {
202 return containsPlainText() || containsURL(0)
203 || ((m_platformDragData) ? (containsHTML(m_platformDragData) || contains Filenames(m_platformDragData))
204 : (containsHTML(&m_dragDataMap) || containsFilenames(&m_dragDataMap) ))
205 || containsColor();
206 }
207
208 PassRefPtr<DocumentFragment> DragData::asFragment(Frame* frame, PassRefPtr<Range >, bool, bool&) const
209 {
210 /*
211 * Order is richest format first. On OSX this is:
212 * * Web Archive
213 * * Filenames
214 * * HTML
215 * * RTF
216 * * TIFF
217 * * PICT
218 */
219
220 if (m_platformDragData) {
221 if (containsFilenames(m_platformDragData)) {
222 if (PassRefPtr<DocumentFragment> fragment = fragmentFromFilenames(fr ame->document(), m_platformDragData))
223 return fragment;
224 }
225
226 if (containsHTML(m_platformDragData)) {
227 if (PassRefPtr<DocumentFragment> fragment = fragmentFromHTML(frame-> document(), m_platformDragData))
228 return fragment;
229 }
230 } else {
231 if (containsFilenames(&m_dragDataMap)) {
232 if (PassRefPtr<DocumentFragment> fragment = fragmentFromFilenames(fr ame->document(), &m_dragDataMap))
233 return fragment;
234 }
235
236 if (containsHTML(&m_dragDataMap)) {
237 if (PassRefPtr<DocumentFragment> fragment = fragmentFromHTML(frame-> document(), &m_dragDataMap))
238 return fragment;
239 }
240 }
241 return 0;
242 }
243
244 Color DragData::asColor() const
245 {
246 return Color();
247 }
248
249 }
OLDNEW
« no previous file with comments | « Source/WebCore/platform/win/DelayLoadedModulesEnumerator.cpp ('k') | Source/WebCore/platform/win/DragImageCGWin.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698