widget/windows/nsNativeDragSource.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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"
    15 /*
    16  * class nsNativeDragSource
    17  */
    18 nsNativeDragSource::nsNativeDragSource(nsIDOMDataTransfer* aDataTransfer) :
    19   m_cRef(0),
    20   m_hCursor(nullptr),
    21   mUserCancelled(false)
    22 {
    23   mDataTransfer = do_QueryInterface(aDataTransfer);
    24 }
    26 nsNativeDragSource::~nsNativeDragSource()
    27 {
    28 }
    30 STDMETHODIMP
    31 nsNativeDragSource::QueryInterface(REFIID riid, void** ppv)
    32 {
    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;
    41   }
    43   return E_NOINTERFACE;
    44 }
    46 STDMETHODIMP_(ULONG)
    47 nsNativeDragSource::AddRef(void)
    48 {
    49   ++m_cRef;
    50   NS_LOG_ADDREF(this, m_cRef, "nsNativeDragSource", sizeof(*this));
    51   return m_cRef;
    52 }
    54 STDMETHODIMP_(ULONG)
    55 nsNativeDragSource::Release(void)
    56 {
    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;
    64 }
    66 STDMETHODIMP
    67 nsNativeDragSource::QueryContinueDrag(BOOL fEsc, DWORD grfKeyState)
    68 {
    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));
    75   }
    77   if (fEsc) {
    78     mUserCancelled = true;
    79     return DRAGDROP_S_CANCEL;
    80   }
    82   if (!(grfKeyState & MK_LBUTTON) || (grfKeyState & MK_RBUTTON))
    83     return DRAGDROP_S_DROP;
    85   return S_OK;
    86 }
    88 STDMETHODIMP
    89 nsNativeDragSource::GiveFeedback(DWORD dwEffect)
    90 {
    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;
    99     }
   100   }
   102   if (m_hCursor) {
   103     ::SetCursor(m_hCursor);
   104     return S_OK;
   105   }
   107   // Let the system choose which cursor to apply.
   108   return DRAGDROP_S_USEDEFAULTCURSORS;
   109 }

mercurial