Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / widget / windows / nsNativeDragSource.cpp
blobca5459e9dfe15c40e6bab85d2d18badc9ac5fea0
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 "nsToolkit.h"
11 #include "nsWidgetsCID.h"
12 #include "nsIDragService.h"
13 #include "nsServiceManagerUtils.h"
14 #include "mozilla/dom/DataTransfer.h"
17 * class nsNativeDragSource
19 nsNativeDragSource::nsNativeDragSource(
20 mozilla::dom::DataTransfer* aDataTransfer)
21 : m_cRef(0), m_hCursor(nullptr), mUserCancelled(false) {
22 mDataTransfer = aDataTransfer;
25 nsNativeDragSource::~nsNativeDragSource() {}
27 STDMETHODIMP
28 nsNativeDragSource::QueryInterface(REFIID riid, void** ppv) {
29 *ppv = nullptr;
31 if (IID_IUnknown == riid || IID_IDropSource == riid) *ppv = this;
33 if (nullptr != *ppv) {
34 ((LPUNKNOWN)*ppv)->AddRef();
35 return S_OK;
38 return E_NOINTERFACE;
41 STDMETHODIMP_(ULONG)
42 nsNativeDragSource::AddRef(void) {
43 ++m_cRef;
44 NS_LOG_ADDREF(this, m_cRef, "nsNativeDragSource", sizeof(*this));
45 return m_cRef;
48 STDMETHODIMP_(ULONG)
49 nsNativeDragSource::Release(void) {
50 --m_cRef;
51 NS_LOG_RELEASE(this, m_cRef, "nsNativeDragSource");
52 if (0 != m_cRef) return m_cRef;
54 delete this;
55 return 0;
58 STDMETHODIMP
59 nsNativeDragSource::QueryContinueDrag(BOOL fEsc, DWORD grfKeyState) {
60 nsCOMPtr<nsIDragService> dragService =
61 do_GetService("@mozilla.org/widget/dragservice;1");
62 if (dragService) {
63 DWORD pos = ::GetMessagePos();
64 dragService->DragMoved(GET_X_LPARAM(pos), GET_Y_LPARAM(pos));
67 if (fEsc) {
68 mUserCancelled = true;
69 return DRAGDROP_S_CANCEL;
72 if (!(grfKeyState & MK_LBUTTON) || (grfKeyState & MK_RBUTTON))
73 return DRAGDROP_S_DROP;
75 return S_OK;
78 STDMETHODIMP
79 nsNativeDragSource::GiveFeedback(DWORD dwEffect) {
80 // For drags involving tabs, we do some custom work with cursors.
81 if (mDataTransfer) {
82 nsAutoString cursor;
83 mDataTransfer->GetMozCursor(cursor);
84 if (cursor.EqualsLiteral("default")) {
85 m_hCursor = ::LoadCursor(0, IDC_ARROW);
86 } else {
87 m_hCursor = nullptr;
91 if (m_hCursor) {
92 ::SetCursor(m_hCursor);
93 return S_OK;
96 // Let the system choose which cursor to apply.
97 return DRAGDROP_S_USEDEFAULTCURSORS;