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"
8 #include "nsISupportsImpl.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() {}
28 nsNativeDragSource::QueryInterface(REFIID riid
, void** ppv
) {
31 if (IID_IUnknown
== riid
|| IID_IDropSource
== riid
) *ppv
= this;
33 if (nullptr != *ppv
) {
34 ((LPUNKNOWN
)*ppv
)->AddRef();
42 nsNativeDragSource::AddRef(void) {
44 NS_LOG_ADDREF(this, m_cRef
, "nsNativeDragSource", sizeof(*this));
49 nsNativeDragSource::Release(void) {
51 NS_LOG_RELEASE(this, m_cRef
, "nsNativeDragSource");
52 if (0 != m_cRef
) return m_cRef
;
59 nsNativeDragSource::QueryContinueDrag(BOOL fEsc
, DWORD grfKeyState
) {
60 nsCOMPtr
<nsIDragService
> dragService
=
61 do_GetService("@mozilla.org/widget/dragservice;1");
63 nsCOMPtr
<nsIDragSession
> session
;
64 dragService
->GetCurrentSession(nullptr, getter_AddRefs(session
));
66 DWORD pos
= ::GetMessagePos();
67 session
->DragMoved(GET_X_LPARAM(pos
), GET_Y_LPARAM(pos
));
72 mUserCancelled
= true;
73 return DRAGDROP_S_CANCEL
;
76 if (!(grfKeyState
& MK_LBUTTON
) || (grfKeyState
& MK_RBUTTON
))
77 return DRAGDROP_S_DROP
;
83 nsNativeDragSource::GiveFeedback(DWORD dwEffect
) {
84 // For drags involving tabs, we do some custom work with cursors.
87 mDataTransfer
->GetMozCursor(cursor
);
88 if (cursor
.EqualsLiteral("default")) {
89 m_hCursor
= ::LoadCursor(0, IDC_ARROW
);
96 ::SetCursor(m_hCursor
);
100 // Let the system choose which cursor to apply.
101 return DRAGDROP_S_USEDEFAULTCURSORS
;