Bug 1763481 - Get the drag service without NS_DEFINE_IID. r=NeilDeakin

mDragService was already a refcounted pointer, but I had
to change the type to a COMPtr because do_getService()
returns a smart pointer type.

Differential Revision: https://phabricator.services.mozilla.com/D143218
This commit is contained in:
Andrew McCreight 2022-04-11 14:54:25 +00:00
parent f330048feb
commit 157f547e74
4 changed files with 18 additions and 25 deletions

View File

@ -314,8 +314,6 @@ class CurrentX11TimeGetter {
} // namespace mozilla
static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID);
// The window from which the focus manager asks us to dispatch key events.
static nsWindow* gFocusWindow = nullptr;
static bool gBlockActivateEvent = false;
@ -4428,7 +4426,8 @@ void nsWindow::OnContainerFocusOutEvent(GdkEventFocus* aEvent) {
if (mWindowType == eWindowType_toplevel ||
mWindowType == eWindowType_dialog) {
nsCOMPtr<nsIDragService> dragService = do_GetService(kCDragServiceCID);
nsCOMPtr<nsIDragService> dragService =
do_GetService("@mozilla.org/widget/dragservice;1");
nsCOMPtr<nsIDragSession> dragSession;
dragService->GetCurrentSession(getter_AddRefs(dragSession));
@ -7152,7 +7151,8 @@ bool nsWindow::CheckForRollup(gdouble aMouseX, gdouble aMouseY, bool aIsWheel,
/* static */
bool nsWindow::DragInProgress(void) {
nsCOMPtr<nsIDragService> dragService = do_GetService(kCDragServiceCID);
nsCOMPtr<nsIDragService> dragService =
do_GetService("@mozilla.org/widget/dragservice;1");
if (!dragService) {
return false;
}
@ -7176,7 +7176,8 @@ MOZ_CAN_RUN_SCRIPT static void WaylandDragWorkaround(GdkEventButton* aEvent) {
return;
}
nsCOMPtr<nsIDragService> dragService = do_GetService(kCDragServiceCID);
nsCOMPtr<nsIDragService> dragService =
do_GetService("@mozilla.org/widget/dragservice;1");
if (!dragService) {
return;
}

View File

@ -56,9 +56,8 @@ nsNativeDragSource::Release(void) {
STDMETHODIMP
nsNativeDragSource::QueryContinueDrag(BOOL fEsc, DWORD grfKeyState) {
static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID);
nsCOMPtr<nsIDragService> dragService = do_GetService(kCDragServiceCID);
nsCOMPtr<nsIDragService> dragService =
do_GetService("@mozilla.org/widget/dragservice;1");
if (dragService) {
DWORD pos = ::GetMessagePos();
dragService->DragMoved(GET_X_LPARAM(pos), GET_Y_LPARAM(pos));

View File

@ -21,9 +21,6 @@
using namespace mozilla;
using namespace mozilla::widget;
/* Define Interface IDs */
static NS_DEFINE_IID(kIDragServiceIID, NS_IDRAGSERVICE_IID);
// This is cached for Leave notification
static POINTL gDragLastPoint;
@ -39,19 +36,12 @@ nsNativeDragTarget::nsNativeDragTarget(nsIWidget* aWidget)
mTookOwnRef(false),
mWidget(aWidget),
mDropTargetHelper(nullptr) {
static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID);
mHWnd = (HWND)mWidget->GetNativeData(NS_NATIVE_WINDOW);
/*
* Create/Get the DragService that we have implemented
*/
CallGetService(kCDragServiceCID, &mDragService);
mDragService = do_GetService("@mozilla.org/widget/dragservice;1");
}
nsNativeDragTarget::~nsNativeDragTarget() {
NS_RELEASE(mDragService);
if (mDropTargetHelper) {
mDropTargetHelper->Release();
mDropTargetHelper = nullptr;
@ -163,7 +153,7 @@ void nsNativeDragTarget::DispatchDragDropEvent(EventMessage aEventMessage,
modifierKeyState.InitInputEvent(event);
event.mInputSource =
static_cast<nsBaseDragService*>(mDragService)->GetInputSource();
static_cast<nsBaseDragService*>(mDragService.get())->GetInputSource();
mWidget->DispatchInputEvent(&event);
}
@ -191,7 +181,7 @@ void nsNativeDragTarget::ProcessDrag(EventMessage aEventMessage,
// DRAGDROP_ACTION_UNINITIALIZED, it means that the last event was sent
// to the child process and this event is also being sent to the child
// process. In this case, use the last event's action instead.
nsDragService* dragService = static_cast<nsDragService*>(mDragService);
nsDragService* dragService = static_cast<nsDragService*>(mDragService.get());
currSession->GetDragAction(&geckoAction);
int32_t childDragAction = dragService->TakeChildProcessDragAction();
@ -274,7 +264,8 @@ nsNativeDragTarget::DragEnter(LPDATAOBJECT pIDataSource, DWORD grfKeyState,
// This cast is ok because in the constructor we created a
// the actual implementation we wanted, so we know this is
// a nsDragService. It should be a private interface, though.
nsDragService* winDragService = static_cast<nsDragService*>(mDragService);
nsDragService* winDragService =
static_cast<nsDragService*>(mDragService.get());
winDragService->SetIDataObject(pIDataSource);
// Now process the native drag state and then dispatch the event
@ -324,7 +315,8 @@ nsNativeDragTarget::DragOver(DWORD grfKeyState, POINTL ptl, LPDWORD pdwEffect) {
// The drop helper only updates the image during DragEnter, so emulate
// a DragEnter if the image was changed.
POINT pt = {ptl.x, ptl.y};
nsDragService* dragService = static_cast<nsDragService*>(mDragService);
nsDragService* dragService =
static_cast<nsDragService*>(mDragService.get());
GetDropTargetHelper()->DragEnter(mHWnd, dragService->GetDataObject(), &pt,
*pdwEffect);
}
@ -422,7 +414,8 @@ nsNativeDragTarget::Drop(LPDATAOBJECT pData, DWORD grfKeyState, POINTL aPT,
// This cast is ok because in the constructor we created a
// the actual implementation we wanted, so we know this is
// a nsDragService (but it should still be a private interface)
nsDragService* winDragService = static_cast<nsDragService*>(mDragService);
nsDragService* winDragService =
static_cast<nsDragService*>(mDragService.get());
winDragService->SetIDataObject(pData);
// NOTE: ProcessDrag spins the event loop which may destroy arbitrary objects.

View File

@ -89,7 +89,7 @@ class nsNativeDragTarget final : public IDropTarget {
// Gecko Stuff
nsIWidget* mWidget;
nsIDragService* mDragService;
nsCOMPtr<nsIDragService> mDragService;
// Drag target helper
IDropTargetHelper* GetDropTargetHelper();