Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsNativeDragSource.h" |
michael@0 | 7 | #include <stdio.h> |
michael@0 | 8 | #include "nsISupportsImpl.h" |
michael@0 | 9 | #include "nsString.h" |
michael@0 | 10 | #include "nsIServiceManager.h" |
michael@0 | 11 | #include "nsToolkit.h" |
michael@0 | 12 | #include "nsWidgetsCID.h" |
michael@0 | 13 | #include "nsIDragService.h" |
michael@0 | 14 | |
michael@0 | 15 | /* |
michael@0 | 16 | * class nsNativeDragSource |
michael@0 | 17 | */ |
michael@0 | 18 | nsNativeDragSource::nsNativeDragSource(nsIDOMDataTransfer* aDataTransfer) : |
michael@0 | 19 | m_cRef(0), |
michael@0 | 20 | m_hCursor(nullptr), |
michael@0 | 21 | mUserCancelled(false) |
michael@0 | 22 | { |
michael@0 | 23 | mDataTransfer = do_QueryInterface(aDataTransfer); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | nsNativeDragSource::~nsNativeDragSource() |
michael@0 | 27 | { |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | STDMETHODIMP |
michael@0 | 31 | nsNativeDragSource::QueryInterface(REFIID riid, void** ppv) |
michael@0 | 32 | { |
michael@0 | 33 | *ppv=nullptr; |
michael@0 | 34 | |
michael@0 | 35 | if (IID_IUnknown==riid || IID_IDropSource==riid) |
michael@0 | 36 | *ppv=this; |
michael@0 | 37 | |
michael@0 | 38 | if (nullptr!=*ppv) { |
michael@0 | 39 | ((LPUNKNOWN)*ppv)->AddRef(); |
michael@0 | 40 | return S_OK; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | return E_NOINTERFACE; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | STDMETHODIMP_(ULONG) |
michael@0 | 47 | nsNativeDragSource::AddRef(void) |
michael@0 | 48 | { |
michael@0 | 49 | ++m_cRef; |
michael@0 | 50 | NS_LOG_ADDREF(this, m_cRef, "nsNativeDragSource", sizeof(*this)); |
michael@0 | 51 | return m_cRef; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | STDMETHODIMP_(ULONG) |
michael@0 | 55 | nsNativeDragSource::Release(void) |
michael@0 | 56 | { |
michael@0 | 57 | --m_cRef; |
michael@0 | 58 | NS_LOG_RELEASE(this, m_cRef, "nsNativeDragSource"); |
michael@0 | 59 | if (0 != m_cRef) |
michael@0 | 60 | return m_cRef; |
michael@0 | 61 | |
michael@0 | 62 | delete this; |
michael@0 | 63 | return 0; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | STDMETHODIMP |
michael@0 | 67 | nsNativeDragSource::QueryContinueDrag(BOOL fEsc, DWORD grfKeyState) |
michael@0 | 68 | { |
michael@0 | 69 | static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID); |
michael@0 | 70 | |
michael@0 | 71 | nsCOMPtr<nsIDragService> dragService = do_GetService(kCDragServiceCID); |
michael@0 | 72 | if (dragService) { |
michael@0 | 73 | DWORD pos = ::GetMessagePos(); |
michael@0 | 74 | dragService->DragMoved(GET_X_LPARAM(pos), GET_Y_LPARAM(pos)); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | if (fEsc) { |
michael@0 | 78 | mUserCancelled = true; |
michael@0 | 79 | return DRAGDROP_S_CANCEL; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | if (!(grfKeyState & MK_LBUTTON) || (grfKeyState & MK_RBUTTON)) |
michael@0 | 83 | return DRAGDROP_S_DROP; |
michael@0 | 84 | |
michael@0 | 85 | return S_OK; |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | STDMETHODIMP |
michael@0 | 89 | nsNativeDragSource::GiveFeedback(DWORD dwEffect) |
michael@0 | 90 | { |
michael@0 | 91 | // For drags involving tabs, we do some custom work with cursors. |
michael@0 | 92 | if (mDataTransfer) { |
michael@0 | 93 | nsAutoString cursor; |
michael@0 | 94 | mDataTransfer->GetMozCursor(cursor); |
michael@0 | 95 | if (cursor.EqualsLiteral("default")) { |
michael@0 | 96 | m_hCursor = ::LoadCursor(0, IDC_ARROW); |
michael@0 | 97 | } else { |
michael@0 | 98 | m_hCursor = nullptr; |
michael@0 | 99 | } |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | if (m_hCursor) { |
michael@0 | 103 | ::SetCursor(m_hCursor); |
michael@0 | 104 | return S_OK; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | // Let the system choose which cursor to apply. |
michael@0 | 108 | return DRAGDROP_S_USEDEFAULTCURSORS; |
michael@0 | 109 | } |