Bumping manifests a=b2g-bump
[gecko.git] / widget / windows / nsNativeDragSource.cpp
blob857907076703295ca97f9103bcb81446558360c8
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsNativeDragSource.h"
7 #include <stdio.h>
8 #include "nsISupportsImpl.h"
9 #include "nsString.h"
10 #include "nsIServiceManager.h"
11 #include "nsToolkit.h"
12 #include "nsWidgetsCID.h"
13 #include "nsIDragService.h"
16 * class nsNativeDragSource
18 nsNativeDragSource::nsNativeDragSource(nsIDOMDataTransfer* aDataTransfer) :
19 m_cRef(0),
20 m_hCursor(nullptr),
21 mUserCancelled(false)
23 mDataTransfer = do_QueryInterface(aDataTransfer);
26 nsNativeDragSource::~nsNativeDragSource()
30 STDMETHODIMP
31 nsNativeDragSource::QueryInterface(REFIID riid, void** ppv)
33 *ppv=nullptr;
35 if (IID_IUnknown==riid || IID_IDropSource==riid)
36 *ppv=this;
38 if (nullptr!=*ppv) {
39 ((LPUNKNOWN)*ppv)->AddRef();
40 return S_OK;
43 return E_NOINTERFACE;
46 STDMETHODIMP_(ULONG)
47 nsNativeDragSource::AddRef(void)
49 ++m_cRef;
50 NS_LOG_ADDREF(this, m_cRef, "nsNativeDragSource", sizeof(*this));
51 return m_cRef;
54 STDMETHODIMP_(ULONG)
55 nsNativeDragSource::Release(void)
57 --m_cRef;
58 NS_LOG_RELEASE(this, m_cRef, "nsNativeDragSource");
59 if (0 != m_cRef)
60 return m_cRef;
62 delete this;
63 return 0;
66 STDMETHODIMP
67 nsNativeDragSource::QueryContinueDrag(BOOL fEsc, DWORD grfKeyState)
69 static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID);
71 nsCOMPtr<nsIDragService> dragService = do_GetService(kCDragServiceCID);
72 if (dragService) {
73 DWORD pos = ::GetMessagePos();
74 dragService->DragMoved(GET_X_LPARAM(pos), GET_Y_LPARAM(pos));
77 if (fEsc) {
78 mUserCancelled = true;
79 return DRAGDROP_S_CANCEL;
82 if (!(grfKeyState & MK_LBUTTON) || (grfKeyState & MK_RBUTTON))
83 return DRAGDROP_S_DROP;
85 return S_OK;
88 STDMETHODIMP
89 nsNativeDragSource::GiveFeedback(DWORD dwEffect)
91 // For drags involving tabs, we do some custom work with cursors.
92 if (mDataTransfer) {
93 nsAutoString cursor;
94 mDataTransfer->GetMozCursor(cursor);
95 if (cursor.EqualsLiteral("default")) {
96 m_hCursor = ::LoadCursor(0, IDC_ARROW);
97 } else {
98 m_hCursor = nullptr;
102 if (m_hCursor) {
103 ::SetCursor(m_hCursor);
104 return S_OK;
107 // Let the system choose which cursor to apply.
108 return DRAGDROP_S_USEDEFAULTCURSORS;