• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4 
5 #ifndef CEF_TESTS_CEFCLIENT_BROWSER_OSR_DRAGDROP_WIN_H_
6 #define CEF_TESTS_CEFCLIENT_BROWSER_OSR_DRAGDROP_WIN_H_
7 #pragma once
8 
9 // When generating projects with CMake the CEF_USE_ATL value will be defined
10 // automatically if using a supported Visual Studio version. Pass -DUSE_ATL=OFF
11 // to the CMake command-line to disable use of ATL.
12 // Uncomment this line to manually enable ATL support.
13 // #define CEF_USE_ATL 1
14 
15 #if defined(CEF_USE_ATL)
16 
17 #include <atlcomcli.h>
18 #include <objidl.h>
19 #include <stdio.h>
20 
21 #include "tests/cefclient/browser/osr_dragdrop_events.h"
22 
23 namespace client {
24 
25 #define DEFAULT_QUERY_INTERFACE(__Class)                            \
26   HRESULT __stdcall QueryInterface(const IID& iid, void** object) { \
27     *object = nullptr;                                              \
28     if (IsEqualIID(iid, IID_IUnknown)) {                            \
29       IUnknown* obj = this;                                         \
30       *object = obj;                                                \
31     } else if (IsEqualIID(iid, IID_##__Class)) {                    \
32       __Class* obj = this;                                          \
33       *object = obj;                                                \
34     } else {                                                        \
35       return E_NOINTERFACE;                                         \
36     }                                                               \
37     AddRef();                                                       \
38     return S_OK;                                                    \
39   }
40 #define IUNKNOWN_IMPLEMENTATION                     \
41   ULONG __stdcall AddRef() { return ++ref_count_; } \
42   ULONG __stdcall Release() {                       \
43     if (--ref_count_ == 0) {                        \
44       delete this;                                  \
45       return 0U;                                    \
46     }                                               \
47     return ref_count_;                              \
48   }                                                 \
49                                                     \
50  protected:                                         \
51   ULONG ref_count_;
52 
53 class DropTargetWin : public IDropTarget {
54  public:
55   static CComPtr<DropTargetWin> Create(OsrDragEvents* callback, HWND hWnd);
56 
57   CefBrowserHost::DragOperationsMask StartDragging(
58       CefRefPtr<CefBrowser> browser,
59       CefRefPtr<CefDragData> drag_data,
60       CefRenderHandler::DragOperationsMask allowed_ops,
61       int x,
62       int y);
63 
64   // IDropTarget implementation:
65   HRESULT __stdcall DragEnter(IDataObject* data_object,
66                               DWORD key_state,
67                               POINTL cursor_position,
68                               DWORD* effect);
69 
70   HRESULT __stdcall DragOver(DWORD key_state,
71                              POINTL cursor_position,
72                              DWORD* effect);
73 
74   HRESULT __stdcall DragLeave();
75 
76   HRESULT __stdcall Drop(IDataObject* data_object,
77                          DWORD key_state,
78                          POINTL cursor_position,
79                          DWORD* effect);
80 
DEFAULT_QUERY_INTERFACE(IDropTarget)81   DEFAULT_QUERY_INTERFACE(IDropTarget)
82   IUNKNOWN_IMPLEMENTATION
83 
84  protected:
85   DropTargetWin(OsrDragEvents* callback, HWND hWnd)
86       : ref_count_(0), callback_(callback), hWnd_(hWnd) {}
~DropTargetWin()87   virtual ~DropTargetWin() {}
88 
89  private:
90   OsrDragEvents* callback_;
91   HWND hWnd_;
92 
93   CefRefPtr<CefDragData> current_drag_data_;
94 };
95 
96 class DropSourceWin : public IDropSource {
97  public:
98   static CComPtr<DropSourceWin> Create();
99 
100   // IDropSource implementation:
101   HRESULT __stdcall GiveFeedback(DWORD dwEffect);
102 
103   HRESULT __stdcall QueryContinueDrag(BOOL fEscapePressed, DWORD grfKeyState);
104 
DEFAULT_QUERY_INTERFACE(IDropSource)105   DEFAULT_QUERY_INTERFACE(IDropSource)
106   IUNKNOWN_IMPLEMENTATION
107 
108  protected:
109   explicit DropSourceWin() : ref_count_(0) {}
~DropSourceWin()110   virtual ~DropSourceWin() {}
111 };
112 
113 class DragEnumFormatEtc : public IEnumFORMATETC {
114  public:
115   static HRESULT CreateEnumFormatEtc(UINT cfmt,
116                                      FORMATETC* afmt,
117                                      IEnumFORMATETC** ppEnumFormatEtc);
118 
119   //
120   // IEnumFormatEtc members
121   //
122   HRESULT __stdcall Next(ULONG celt,
123                          FORMATETC* pFormatEtc,
124                          ULONG* pceltFetched);
125   HRESULT __stdcall Skip(ULONG celt);
126   HRESULT __stdcall Reset(void);
127   HRESULT __stdcall Clone(IEnumFORMATETC** ppEnumFormatEtc);
128 
129   //
130   // Construction / Destruction
131   //
132   DragEnumFormatEtc(FORMATETC* pFormatEtc, int nNumFormats);
133   virtual ~DragEnumFormatEtc();
134 
135   static void DeepCopyFormatEtc(FORMATETC* dest, FORMATETC* source);
136 
137   DEFAULT_QUERY_INTERFACE(IEnumFORMATETC)
138   IUNKNOWN_IMPLEMENTATION
139 
140  private:
141   ULONG m_nIndex;           // current enumerator index
142   ULONG m_nNumFormats;      // number of FORMATETC members
143   FORMATETC* m_pFormatEtc;  // array of FORMATETC objects
144 };
145 
146 class DataObjectWin : public IDataObject {
147  public:
148   static CComPtr<DataObjectWin> Create(FORMATETC* fmtetc,
149                                        STGMEDIUM* stgmed,
150                                        int count);
151 
152   // IDataObject memberS
153   HRESULT __stdcall GetDataHere(FORMATETC* pFormatEtc, STGMEDIUM* pmedium);
154   HRESULT __stdcall QueryGetData(FORMATETC* pFormatEtc);
155   HRESULT __stdcall GetCanonicalFormatEtc(FORMATETC* pFormatEct,
156                                           FORMATETC* pFormatEtcOut);
157   HRESULT __stdcall SetData(FORMATETC* pFormatEtc,
158                             STGMEDIUM* pMedium,
159                             BOOL fRelease);
160   HRESULT __stdcall DAdvise(FORMATETC* pFormatEtc,
161                             DWORD advf,
162                             IAdviseSink*,
163                             DWORD*);
164   HRESULT __stdcall DUnadvise(DWORD dwConnection);
165   HRESULT __stdcall EnumDAdvise(IEnumSTATDATA** ppEnumAdvise);
166 
167   HRESULT __stdcall EnumFormatEtc(DWORD dwDirection,
168                                   IEnumFORMATETC** ppEnumFormatEtc);
169   HRESULT __stdcall GetData(FORMATETC* pFormatEtc, STGMEDIUM* pMedium);
170 
171   DEFAULT_QUERY_INTERFACE(IDataObject)
172   IUNKNOWN_IMPLEMENTATION
173 
174  protected:
175   int m_nNumFormats;
176   FORMATETC* m_pFormatEtc;
177   STGMEDIUM* m_pStgMedium;
178 
179   static HGLOBAL DupGlobalMem(HGLOBAL hMem);
180 
181   int LookupFormatEtc(FORMATETC* pFormatEtc);
182 
183   explicit DataObjectWin(FORMATETC* fmtetc, STGMEDIUM* stgmed, int count);
~DataObjectWin()184   virtual ~DataObjectWin() {}
185 };
186 
187 }  // namespace client
188 
189 #endif  // defined(CEF_USE_ATL)
190 
191 #endif  // CEF_TESTS_CEFCLIENT_BROWSER_OSR_DRAGDROP_WIN_H_
192