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

Side by Side Diff: webkit/port/platform/WCDataObject.cpp

Issue 7419: Move many files that were suffixed Win.cpp to Chromium.cpp, and place them in... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 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
« no previous file with comments | « webkit/port/platform/WCDataObject.h ('k') | webkit/port/platform/WheelEventWin.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "config.h"
27
28 #include "WCDataObject.h"
29
30 #include "PlatformString.h"
31
32 namespace WebCore {
33
34 class WCEnumFormatEtc : public IEnumFORMATETC
35 {
36 public:
37 WCEnumFormatEtc(const Vector<FORMATETC>& formats);
38 WCEnumFormatEtc(const Vector<FORMATETC*>& formats);
39
40 //IUnknown members
41 STDMETHOD(QueryInterface)(REFIID, void**);
42 STDMETHOD_(ULONG, AddRef)(void);
43 STDMETHOD_(ULONG, Release)(void);
44
45 //IEnumFORMATETC members
46 STDMETHOD(Next)(ULONG, LPFORMATETC, ULONG*);
47 STDMETHOD(Skip)(ULONG);
48 STDMETHOD(Reset)(void);
49 STDMETHOD(Clone)(IEnumFORMATETC**);
50
51 private:
52 long m_ref;
53 Vector<FORMATETC> m_formats;
54 size_t m_current;
55 };
56
57
58
59 WCEnumFormatEtc::WCEnumFormatEtc(const Vector<FORMATETC>& formats)
60 : m_ref(1)
61 , m_current(0)
62 {
63 for(size_t i = 0; i < formats.size(); ++i)
64 m_formats.append(formats[i]);
65 }
66
67 WCEnumFormatEtc::WCEnumFormatEtc(const Vector<FORMATETC*>& formats)
68 : m_ref(1)
69 , m_current(0)
70 {
71 for(size_t i = 0; i < formats.size(); ++i)
72 m_formats.append(*formats[i]);
73 }
74
75 STDMETHODIMP WCEnumFormatEtc::QueryInterface(REFIID riid, void** ppvObject)
76 {
77 *ppvObject = 0;
78 if (IsEqualIID(riid, IID_IUnknown) ||
79 IsEqualIID(riid, IID_IEnumFORMATETC)) {
80 *ppvObject = this;
81 AddRef();
82 return S_OK;
83 }
84
85 return E_NOINTERFACE;
86 }
87
88 STDMETHODIMP_(ULONG) WCEnumFormatEtc::AddRef(void)
89 {
90 return InterlockedIncrement(&m_ref);
91 }
92
93 STDMETHODIMP_(ULONG) WCEnumFormatEtc::Release(void)
94 {
95 long c = InterlockedDecrement(&m_ref);
96 if (c == 0)
97 delete this;
98 return c;
99 }
100
101 STDMETHODIMP WCEnumFormatEtc::Next(ULONG celt, LPFORMATETC lpFormatEtc, ULONG* p celtFetched)
102 {
103 if(pceltFetched != 0)
104 *pceltFetched=0;
105
106 ULONG cReturn = celt;
107
108 if(celt <= 0 || lpFormatEtc == 0 || m_current >= m_formats.size())
109 return S_FALSE;
110
111 if(pceltFetched == 0 && celt != 1) // pceltFetched can be 0 only for 1 item request
112 return S_FALSE;
113
114 while (m_current < m_formats.size() && cReturn > 0) {
115 *lpFormatEtc++ = m_formats[m_current++];
116 --cReturn;
117 }
118 if (pceltFetched != 0)
119 *pceltFetched = celt - cReturn;
120
121 return (cReturn == 0) ? S_OK : S_FALSE;
122 }
123
124 STDMETHODIMP WCEnumFormatEtc::Skip(ULONG celt)
125 {
126 if((m_current + int(celt)) >= m_formats.size())
127 return S_FALSE;
128 m_current += celt;
129 return S_OK;
130 }
131
132 STDMETHODIMP WCEnumFormatEtc::Reset(void)
133 {
134 m_current = 0;
135 return S_OK;
136 }
137
138 STDMETHODIMP WCEnumFormatEtc::Clone(IEnumFORMATETC** ppCloneEnumFormatEtc)
139 {
140 if(!ppCloneEnumFormatEtc)
141 return E_POINTER;
142
143 WCEnumFormatEtc *newEnum = new WCEnumFormatEtc(m_formats);
144 if(!newEnum)
145 return E_OUTOFMEMORY;
146
147 newEnum->AddRef();
148 newEnum->m_current = m_current;
149 *ppCloneEnumFormatEtc = newEnum;
150 return S_OK;
151 }
152
153
154
155 //////////////////////////////////////////////////////////////////////////
156
157 HRESULT WCDataObject::createInstance(WCDataObject** result)
158 {
159 if (!result)
160 return E_POINTER;
161 *result = new WCDataObject();
162 return S_OK;
163 }
164
165 WCDataObject::WCDataObject()
166 : m_ref(1)
167 {
168 }
169
170 WCDataObject::~WCDataObject()
171 {
172 for(size_t i = 0; i < m_medium.size(); ++i) {
173 ReleaseStgMedium(m_medium[i]);
174 delete m_medium[i];
175 }
176 WTF::deleteAllValues(m_formats);
177 }
178
179 STDMETHODIMP WCDataObject::QueryInterface(REFIID riid,void** ppvObject)
180 {
181 *ppvObject = 0;
182 if (IID_IUnknown==riid || IID_IDataObject==riid)
183 *ppvObject=this;
184 if (*ppvObject) {
185 AddRef();
186 return S_OK;
187 }
188 return E_NOINTERFACE;
189 }
190
191 STDMETHODIMP_(ULONG) WCDataObject::AddRef( void)
192 {
193 return InterlockedIncrement(&m_ref);
194 }
195
196 STDMETHODIMP_(ULONG) WCDataObject::Release( void)
197 {
198 long c = InterlockedDecrement(&m_ref);
199 if (c == 0)
200 delete this;
201 return c;
202 }
203
204 STDMETHODIMP WCDataObject::GetData(FORMATETC* pformatetcIn, STGMEDIUM* pmedium)
205 {
206 if(!pformatetcIn || !pmedium)
207 return E_POINTER;
208 pmedium->hGlobal = 0;
209
210 for(size_t i=0; i < m_formats.size(); ++i) {
211 if(/*pformatetcIn->tymed & m_formats[i]->tymed &&*/ // tymed can be 0 (TYMED_NULL) - but it can have a medium that contains an pUnkForRelease
212 pformatetcIn->lindex == m_formats[i]->lindex &&
213 pformatetcIn->dwAspect == m_formats[i]->dwAspect &&
214 pformatetcIn->cfFormat == m_formats[i]->cfFormat) {
215 CopyMedium(pmedium, m_medium[i], m_formats[i]);
216 return S_OK;
217 }
218 }
219 return DV_E_FORMATETC;
220 }
221
222 STDMETHODIMP WCDataObject::GetDataHere(FORMATETC*, STGMEDIUM*)
223 {
224 return E_NOTIMPL;
225 }
226
227 STDMETHODIMP WCDataObject::QueryGetData(FORMATETC* pformatetc)
228 {
229 if(!pformatetc)
230 return E_POINTER;
231
232 if (!(DVASPECT_CONTENT & pformatetc->dwAspect))
233 return (DV_E_DVASPECT);
234 HRESULT hr = DV_E_TYMED;
235 for(size_t i = 0; i < m_formats.size(); ++i) {
236 if(pformatetc->tymed & m_formats[i]->tymed) {
237 if(pformatetc->cfFormat == m_formats[i]->cfFormat)
238 return S_OK;
239 else
240 hr = DV_E_CLIPFORMAT;
241 }
242 else
243 hr = DV_E_TYMED;
244 }
245 return hr;
246 }
247
248 STDMETHODIMP WCDataObject::GetCanonicalFormatEtc(FORMATETC*, FORMATETC*)
249 {
250 return DATA_S_SAMEFORMATETC;
251 }
252
253 STDMETHODIMP WCDataObject::SetData(FORMATETC* pformatetc, STGMEDIUM* pmedium, BO OL fRelease)
254 {
255 if(!pformatetc || !pmedium)
256 return E_POINTER;
257
258 FORMATETC* fetc=new FORMATETC;
259 if (!fetc)
260 return E_OUTOFMEMORY;
261
262 STGMEDIUM* pStgMed = new STGMEDIUM;
263
264 if(!pStgMed) {
265 delete fetc;
266 return E_OUTOFMEMORY;
267 }
268
269 ZeroMemory(fetc,sizeof(FORMATETC));
270 ZeroMemory(pStgMed,sizeof(STGMEDIUM));
271
272 *fetc = *pformatetc;
273 m_formats.append(fetc);
274
275 if(fRelease)
276 *pStgMed = *pmedium;
277 else
278 CopyMedium(pStgMed, pmedium, pformatetc);
279 m_medium.append(pStgMed);
280
281 return S_OK;
282 }
283
284 void WCDataObject::CopyMedium(STGMEDIUM* pMedDest, STGMEDIUM* pMedSrc, FORMATETC * pFmtSrc)
285 {
286 switch(pMedSrc->tymed)
287 {
288 case TYMED_HGLOBAL:
289 pMedDest->hGlobal = (HGLOBAL)OleDuplicateData(pMedSrc->hGlobal,pFmtSrc-> cfFormat, 0);
290 break;
291 case TYMED_GDI:
292 pMedDest->hBitmap = (HBITMAP)OleDuplicateData(pMedSrc->hBitmap,pFmtSrc-> cfFormat, 0);
293 break;
294 case TYMED_MFPICT:
295 pMedDest->hMetaFilePict = (HMETAFILEPICT)OleDuplicateData(pMedSrc->hMeta FilePict,pFmtSrc->cfFormat, 0);
296 break;
297 case TYMED_ENHMF:
298 pMedDest->hEnhMetaFile = (HENHMETAFILE)OleDuplicateData(pMedSrc->hEnhMet aFile,pFmtSrc->cfFormat, 0);
299 break;
300 case TYMED_FILE:
301 pMedSrc->lpszFileName = (LPOLESTR)OleDuplicateData(pMedSrc->lpszFileName ,pFmtSrc->cfFormat, 0);
302 break;
303 case TYMED_ISTREAM:
304 pMedDest->pstm = pMedSrc->pstm;
305 pMedSrc->pstm->AddRef();
306 break;
307 case TYMED_ISTORAGE:
308 pMedDest->pstg = pMedSrc->pstg;
309 pMedSrc->pstg->AddRef();
310 break;
311 default:
312 break;
313 }
314 pMedDest->tymed = pMedSrc->tymed;
315 pMedDest->pUnkForRelease = 0;
316 if(pMedSrc->pUnkForRelease != 0) {
317 pMedDest->pUnkForRelease = pMedSrc->pUnkForRelease;
318 pMedSrc->pUnkForRelease->AddRef();
319 }
320 }
321 STDMETHODIMP WCDataObject::EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC** ppe numFormatEtc)
322 {
323 if(!ppenumFormatEtc)
324 return E_POINTER;
325
326 *ppenumFormatEtc=0;
327 switch (dwDirection)
328 {
329 case DATADIR_GET:
330 *ppenumFormatEtc= new WCEnumFormatEtc(m_formats);
331 if(!(*ppenumFormatEtc))
332 return E_OUTOFMEMORY;
333 break;
334
335 case DATADIR_SET:
336 default:
337 return E_NOTIMPL;
338 break;
339 }
340
341 return S_OK;
342 }
343
344 STDMETHODIMP WCDataObject::DAdvise(FORMATETC*, DWORD, IAdviseSink*,DWORD*)
345 {
346 return OLE_E_ADVISENOTSUPPORTED;
347 }
348
349 STDMETHODIMP WCDataObject::DUnadvise(DWORD)
350 {
351 return E_NOTIMPL;
352 }
353
354 HRESULT STDMETHODCALLTYPE WCDataObject::EnumDAdvise(IEnumSTATDATA**)
355 {
356 return OLE_E_ADVISENOTSUPPORTED;
357 }
358
359 void WCDataObject::clearData(CLIPFORMAT format)
360 {
361 size_t ptr = 0;
362 while (ptr < m_formats.size()) {
363 if (m_formats[ptr]->cfFormat == format) {
364 FORMATETC* current = m_formats[ptr];
365 m_formats[ptr] = m_formats[m_formats.size() - 1];
366 m_formats[m_formats.size() - 1] = 0;
367 m_formats.removeLast();
368 delete current;
369 STGMEDIUM* medium = m_medium[ptr];
370 m_medium[ptr] = m_medium[m_medium.size() - 1];
371 m_medium[m_medium.size() - 1] = 0;
372 m_medium.removeLast();
373 ReleaseStgMedium(medium);
374 delete medium;
375 continue;
376 }
377 ptr++;
378 }
379 }
380
381
382 }
OLDNEW
« no previous file with comments | « webkit/port/platform/WCDataObject.h ('k') | webkit/port/platform/WheelEventWin.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698