1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/windows/nsNativeDragSource.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,109 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsNativeDragSource.h" 1.10 +#include <stdio.h> 1.11 +#include "nsISupportsImpl.h" 1.12 +#include "nsString.h" 1.13 +#include "nsIServiceManager.h" 1.14 +#include "nsToolkit.h" 1.15 +#include "nsWidgetsCID.h" 1.16 +#include "nsIDragService.h" 1.17 + 1.18 +/* 1.19 + * class nsNativeDragSource 1.20 + */ 1.21 +nsNativeDragSource::nsNativeDragSource(nsIDOMDataTransfer* aDataTransfer) : 1.22 + m_cRef(0), 1.23 + m_hCursor(nullptr), 1.24 + mUserCancelled(false) 1.25 +{ 1.26 + mDataTransfer = do_QueryInterface(aDataTransfer); 1.27 +} 1.28 + 1.29 +nsNativeDragSource::~nsNativeDragSource() 1.30 +{ 1.31 +} 1.32 + 1.33 +STDMETHODIMP 1.34 +nsNativeDragSource::QueryInterface(REFIID riid, void** ppv) 1.35 +{ 1.36 + *ppv=nullptr; 1.37 + 1.38 + if (IID_IUnknown==riid || IID_IDropSource==riid) 1.39 + *ppv=this; 1.40 + 1.41 + if (nullptr!=*ppv) { 1.42 + ((LPUNKNOWN)*ppv)->AddRef(); 1.43 + return S_OK; 1.44 + } 1.45 + 1.46 + return E_NOINTERFACE; 1.47 +} 1.48 + 1.49 +STDMETHODIMP_(ULONG) 1.50 +nsNativeDragSource::AddRef(void) 1.51 +{ 1.52 + ++m_cRef; 1.53 + NS_LOG_ADDREF(this, m_cRef, "nsNativeDragSource", sizeof(*this)); 1.54 + return m_cRef; 1.55 +} 1.56 + 1.57 +STDMETHODIMP_(ULONG) 1.58 +nsNativeDragSource::Release(void) 1.59 +{ 1.60 + --m_cRef; 1.61 + NS_LOG_RELEASE(this, m_cRef, "nsNativeDragSource"); 1.62 + if (0 != m_cRef) 1.63 + return m_cRef; 1.64 + 1.65 + delete this; 1.66 + return 0; 1.67 +} 1.68 + 1.69 +STDMETHODIMP 1.70 +nsNativeDragSource::QueryContinueDrag(BOOL fEsc, DWORD grfKeyState) 1.71 +{ 1.72 + static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID); 1.73 + 1.74 + nsCOMPtr<nsIDragService> dragService = do_GetService(kCDragServiceCID); 1.75 + if (dragService) { 1.76 + DWORD pos = ::GetMessagePos(); 1.77 + dragService->DragMoved(GET_X_LPARAM(pos), GET_Y_LPARAM(pos)); 1.78 + } 1.79 + 1.80 + if (fEsc) { 1.81 + mUserCancelled = true; 1.82 + return DRAGDROP_S_CANCEL; 1.83 + } 1.84 + 1.85 + if (!(grfKeyState & MK_LBUTTON) || (grfKeyState & MK_RBUTTON)) 1.86 + return DRAGDROP_S_DROP; 1.87 + 1.88 + return S_OK; 1.89 +} 1.90 + 1.91 +STDMETHODIMP 1.92 +nsNativeDragSource::GiveFeedback(DWORD dwEffect) 1.93 +{ 1.94 + // For drags involving tabs, we do some custom work with cursors. 1.95 + if (mDataTransfer) { 1.96 + nsAutoString cursor; 1.97 + mDataTransfer->GetMozCursor(cursor); 1.98 + if (cursor.EqualsLiteral("default")) { 1.99 + m_hCursor = ::LoadCursor(0, IDC_ARROW); 1.100 + } else { 1.101 + m_hCursor = nullptr; 1.102 + } 1.103 + } 1.104 + 1.105 + if (m_hCursor) { 1.106 + ::SetCursor(m_hCursor); 1.107 + return S_OK; 1.108 + } 1.109 + 1.110 + // Let the system choose which cursor to apply. 1.111 + return DRAGDROP_S_USEDEFAULTCURSORS; 1.112 +}