Skip to content

Commit

Permalink
Bug 1893119: Part 20 - Move EndDragSession from nsIDragService to nsI…
Browse files Browse the repository at this point in the history
…DragSession a=diannaS

This is a straightforward move.  It does take the liberty of breaking out an
EndDragSessionImpl method, which will be needed later.

Original Revision: https://phabricator.services.mozilla.com/D211083

Differential Revision: https://phabricator.services.mozilla.com/D221173
  • Loading branch information
davidp3 committed Sep 6, 2024
1 parent 57eda89 commit b1e6aa6
Showing 27 changed files with 235 additions and 180 deletions.
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ function simulateItemDragAndEnd(aToDrag, aTarget) {
aToDrag.parentNode
);
} finally {
ds.endDragSession(true);
ds.getCurrentSession().endDragSession(true);
}
}

Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ add_task(async function () {
overflowChevron
);
} finally {
ds.endDragSession(true);
ds.getCurrentSession().endDragSession(true);
}

info("Overflow panel is shown.");
11 changes: 9 additions & 2 deletions dom/base/nsGlobalWindowOuter.cpp
Original file line number Diff line number Diff line change
@@ -6211,8 +6211,15 @@ nsGlobalWindowOuter* nsGlobalWindowOuter::EnterModalState() {
// If there are any drag and drop operations in flight, try to end them.
nsCOMPtr<nsIDragService> ds =
do_GetService("@mozilla.org/widget/dragservice;1");
if (ds) {
ds->EndDragSession(true, 0);
if (ds && topWin->GetDocShell()) {
if (PresShell* presShell = topWin->GetDocShell()->GetPresShell()) {
if (nsViewManager* vm = presShell->GetViewManager()) {
RefPtr<nsIWidget> widget = vm->GetRootWidget();
if (nsCOMPtr<nsIDragSession> session = ds->GetCurrentSession(widget)) {
session->EndDragSession(true, 0);
}
}
}
}

// Clear the capturing content if it is under topDoc.
2 changes: 1 addition & 1 deletion dom/events/test/test_bug508479.html
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@
event.initDragEvent("drop", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null, dataTransfer);
fireEvent(element, event);
} finally {
ds.endDragSession(false);
ds.getCurrentSession().endDragSession(false);
ok(!ds.getCurrentSession(), "There shouldn't be a drag session anymore!");
}
}
24 changes: 10 additions & 14 deletions dom/ipc/BrowserChild.cpp
Original file line number Diff line number Diff line change
@@ -1980,22 +1980,18 @@ mozilla::ipc::IPCResult BrowserChild::RecvEndDragSession(
const bool& aDoneDrag, const bool& aUserCancelled,
const LayoutDeviceIntPoint& aDragEndPoint, const uint32_t& aKeyModifiers,
const uint32_t& aDropEffect) {
nsCOMPtr<nsIDragService> dragService =
do_GetService("@mozilla.org/widget/dragservice;1");
if (dragService) {
RefPtr<nsIDragSession> dragSession = GetDragSession();
if (dragSession) {
if (aUserCancelled) {
dragSession->UserCancelled();
}
RefPtr<nsIDragSession> dragSession = GetDragSession();
if (dragSession) {
if (aUserCancelled) {
dragSession->UserCancelled();
}

RefPtr<DataTransfer> dataTransfer = dragSession->GetDataTransfer();
if (dataTransfer) {
dataTransfer->SetDropEffectInt(aDropEffect);
}
dragSession->SetDragEndPoint(aDragEndPoint.x, aDragEndPoint.y);
RefPtr<DataTransfer> dataTransfer = dragSession->GetDataTransfer();
if (dataTransfer) {
dataTransfer->SetDropEffectInt(aDropEffect);
}
dragService->EndDragSession(aDoneDrag, aKeyModifiers);
dragSession->SetDragEndPoint(aDragEndPoint.x, aDragEndPoint.y);
dragSession->EndDragSession(aDoneDrag, aKeyModifiers);
}
return IPC_OK();
}
2 changes: 1 addition & 1 deletion layout/base/tests/test_bug603550.html
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@
event.initDragEvent("drop", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null, null);
fireEvent(element, event);
} finally {
ds.endDragSession(false);
ds.getCurrentSession().endDragSession(false);
ok(!ds.getCurrentSession(), "There shouldn't be a drag session anymore!");
}
}
2 changes: 1 addition & 1 deletion layout/xul/test/browser_bug706743.js
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ add_task(async function () {
await new Promise(resolve => setTimeout(resolve, 100));
} finally {
removeEventListener("popupshown", tooltipNotExpected, true);
dragService.endDragSession(true);
dragService.getCurrentSession().endDragSession(true);
}

await BrowserTestUtils.synthesizeMouse(
21 changes: 10 additions & 11 deletions testing/mochitest/tests/SimpleTest/EventUtils.js
Original file line number Diff line number Diff line change
@@ -685,7 +685,6 @@ function getDragService() {
* synthesize DOM events basically.
*/
function _maybeEndDragSession(left, top, aEvent, aWindow) {
const dragService = getDragService();
let utils = _getDOMWindowUtils(aWindow);
const dragSession = utils.dragSession;
if (!dragSession) {
@@ -696,7 +695,7 @@ function _maybeEndDragSession(left, top, aEvent, aWindow) {
// need to synthesize a "drop" event or call setDragEndPointForTests here to
// set proper left/top to `dragend` event.
try {
dragService.endDragSession(false, _parseModifiers(aEvent, aWindow));
dragSession.endDragSession(false, _parseModifiers(aEvent, aWindow));
} catch (e) {}
return true;
}
@@ -3154,7 +3153,7 @@ function synthesizeDragOver(
const obs = _EU_Cc["@mozilla.org/observer-service;1"].getService(
_EU_Ci.nsIObserverService
);
let utils = _getDOMWindowUtils(aDestWindow);
let utils = _getDOMWindowUtils(aWindow);
var sess = utils.dragSession;

// This method runs before other callbacks, and acts as a way to inject the
@@ -3363,7 +3362,9 @@ function synthesizeDrop(
aDragEvent
);
} finally {
ds.endDragSession(true, _parseModifiers(aDragEvent));
let srcWindowUtils = _getDOMWindowUtils(aWindow);
const srcDragSession = srcWindowUtils.dragSession;
srcDragSession.endDragSession(true, _parseModifiers(aDragEvent));
}
}

@@ -3533,10 +3534,6 @@ async function synthesizePlainDragAndDrop(aParams) {
);
}

const ds = _EU_Cc["@mozilla.org/widget/dragservice;1"].getService(
_EU_Ci.nsIDragService
);

const editingHost = (() => {
if (!srcElement.matches(":read-write")) {
return null;
@@ -3884,7 +3881,10 @@ async function synthesizePlainDragAndDrop(aParams) {
}
srcWindow.addEventListener("dragend", onDragEnd, { capture: true });
try {
ds.endDragSession(true, _parseModifiers(dragEvent));
srcWindowUtils.dragSession.endDragSession(
true,
_parseModifiers(dragEvent)
);
if (!expectSrcElementDisconnected && !dragEndEvent) {
// eslint-disable-next-line no-unsafe-finally
throw new Error(
@@ -4427,8 +4427,7 @@ async function synthesizeMockDragAndDrop(aParams) {
!expectNoDragTargetEvents
? `received as a ${expectedMessage} event`
: "ignored"
}` +
`, followed by a dragend event`
}, followed by a dragend event`
);

currentTargetScreenPos = [
5 changes: 3 additions & 2 deletions toolkit/modules/SubDialog.sys.mjs
Original file line number Diff line number Diff line change
@@ -184,8 +184,9 @@ SubDialog.prototype = {
// The drag service getService call fails in puppeteer tests on Linux,
// so this is in a try...catch as it shouldn't stop us from opening the
// dialog. Bug 1806870 tracks fixing this.
if (lazy.dragService.getCurrentSession(this._window)) {
lazy.dragService.endDragSession(true);
let session = lazy.dragService.getCurrentSession(this._window);
if (session) {
session.endDragSession(true);
}
} catch (ex) {
console.error(ex);
Original file line number Diff line number Diff line change
@@ -160,7 +160,7 @@ async function simulateDragAndDrop(win, dragData) {
{ _domDispatchOnly: true }
);

dragService.endDragSession(true);
dragService.getDragSession(win).endDragSession(true);
}

// Simulates dropping a URL onto the manager
36 changes: 28 additions & 8 deletions widget/MockDragServiceController.cpp
Original file line number Diff line number Diff line change
@@ -31,14 +31,31 @@ class MockDragService : public nsBaseDragService {

// mDragAction is not yet handled properly in the MockDragService.
// This should be updated with each drag event. Instead, we always MOVE.
//
// We still need to end the drag session on the source widget.
// In normal (non-mock) Gecko operation, this happens regardless
// of whether the drop/cancel happened over one of our widgets.
// For instance, Windows does this in StartInvokingDragSession, after
// DoDragDrop returns, gtk does this on eDragTaskSourceEnd and cocoa
// does this in -[NSDraggingSource draggingSession: endedAt: operation:].
//
// Here, we know the source and target are Gecko windows (the test
// framework does not support dragging to/from other apps). We could
// end the source drag session on drop and cancel, but sometimes we
// will want a dragleave to end the session (representing a drag cancel
// from Gecko) and other we times don't (like when dragging from one Gecko
// widget to another). Therefore, we instead rely on the test to tell
// us when to end the source session by calling
// MockDragServiceController::EndSourceDragSession().
// Note that, like in non-mocked DND, we do this regardless of whether
// the source and target were the same widget -- in that case,
// EndDragSession is just called twice.
mDragAction = DRAGDROP_ACTION_MOVE;
StartDragSession(aWidget);
return NS_OK;
}

bool IsMockService() override { return true; }

uint32_t mLastModifierKeyState = 0;
};

static void SetDragEndPointFromScreenPoint(
@@ -133,7 +150,6 @@ MockDragServiceController::SendEvent(
LayoutDeviceIntPoint(aScreenX, aScreenY) - clientPosInScreenCoords;

RefPtr<MockDragService> ds = mDragService;
ds->mLastModifierKeyState = aKeyModifiers;

if (aEventType == EventType::eDragEnter) {
// We expect StartDragSession to return an "error" when a drag session
@@ -166,7 +182,8 @@ MockDragServiceController::SendEvent(
rv = currentDragSession->GetSourceNode(getter_AddRefs(sourceNode));
NS_ENSURE_SUCCESS(rv, rv);
if (!sourceNode) {
rv = ds->EndDragSession(false /* doneDrag */, aKeyModifiers);
rv = currentDragSession->EndDragSession(false /* doneDrag */,
aKeyModifiers);
NS_ENSURE_SUCCESS(rv, rv);
}
} break;
@@ -184,7 +201,8 @@ MockDragServiceController::SendEvent(
widget->DispatchInputEvent(widgetEvent.get());
SetDragEndPointFromScreenPoint(currentDragSession, presCxt,
LayoutDeviceIntPoint(aScreenX, aScreenY));
rv = ds->EndDragSession(true /* doneDrag */, aKeyModifiers);
rv = currentDragSession->EndDragSession(true /* doneDrag */,
aKeyModifiers);
NS_ENSURE_SUCCESS(rv, rv);
} break;
default:
@@ -197,8 +215,10 @@ MockDragServiceController::SendEvent(
NS_IMETHODIMP
MockDragServiceController::CancelDrag(uint32_t aKeyModifiers = 0) {
RefPtr<MockDragService> ds = mDragService;
ds->mLastModifierKeyState = aKeyModifiers;
return ds->EndDragSession(false /* doneDrag */, aKeyModifiers);
nsCOMPtr<nsIDragSession> currentDragSession;
ds->GetCurrentSession(nullptr, getter_AddRefs(currentDragSession));
MOZ_ASSERT(currentDragSession);
return currentDragSession->EndDragSession(false /* doneDrag */,
aKeyModifiers);
}

} // namespace mozilla::test
7 changes: 4 additions & 3 deletions widget/android/nsDragService.cpp
Original file line number Diff line number Diff line change
@@ -165,11 +165,12 @@ nsDragSession::IsDataFlavorSupported(const char* aDataFlavor, bool* _retval) {
return NS_OK;
}

NS_IMETHODIMP
nsDragService::EndDragSession(bool aDoneDrag, uint32_t aKeyModifiers) {
nsresult nsDragSession::EndDragSessionImpl(bool aDoneDrag,
uint32_t aKeyModifiers) {
java::GeckoDragAndDrop::EndDragSession();

nsresult rv = nsBaseDragService::EndDragSession(aDoneDrag, aKeyModifiers);
nsresult rv =
nsBaseDragSession::EndDragSessionImpl(aDoneDrag, aKeyModifiers);
mTransferable = nullptr;
return rv;
}
6 changes: 3 additions & 3 deletions widget/android/nsDragService.h
Original file line number Diff line number Diff line change
@@ -34,6 +34,9 @@ class nsDragSession : public nsBaseDragService {

virtual bool MustUpdateDataTransfer(mozilla::EventMessage aMessage) override;

MOZ_CAN_RUN_SCRIPT nsresult EndDragSessionImpl(
bool aDoneDrag, uint32_t aKeyModifiers) override;

protected:
virtual ~nsDragSession() = default;

@@ -53,9 +56,6 @@ class nsDragService final : public nsDragSession {

NS_DECL_ISUPPORTS_INHERITED

MOZ_CAN_RUN_SCRIPT NS_IMETHOD EndDragSession(bool aDoneDrag,
uint32_t aKeyModifiers) override;

static void SetDropData(
mozilla::java::GeckoDragAndDrop::DropData::Param aDropData);

10 changes: 5 additions & 5 deletions widget/android/nsWindow.cpp
Original file line number Diff line number Diff line change
@@ -2678,8 +2678,8 @@ void nsWindow::OnDragEvent(int32_t aAction, int64_t aTime, float aX, float aY,
return;
}

if (aAction == java::sdk::DragEvent::ACTION_DRAG_ENDED) {
dragService->EndDragSession(false, 0);
if (dragSession && aAction == java::sdk::DragEvent::ACTION_DRAG_ENDED) {
dragSession->EndDragSession(false, 0);
return;
}

@@ -2708,7 +2708,7 @@ void nsWindow::OnDragEvent(int32_t aAction, int64_t aTime, float aX, float aY,
nsCOMPtr<nsINode> sourceNode;
dragSession->GetSourceNode(getter_AddRefs(sourceNode));
if (!sourceNode) {
dragService->EndDragSession(false, 0);
dragSession->EndDragSession(false, 0);
}
return;
}
@@ -2744,12 +2744,12 @@ void nsWindow::OnDragEvent(int32_t aAction, int64_t aTime, float aX, float aY,
// initiated in a different app. End the drag session,
// since we're done with it for now (until the user
// drags back into mozilla).
dragService->EndDragSession(false, 0);
dragSession->EndDragSession(false, 0);
}
break;
}
case eDrop:
dragService->EndDragSession(true, 0);
dragSession->EndDragSession(true, 0);
break;
default:
break;
14 changes: 4 additions & 10 deletions widget/cocoa/nsChildView.mm
Original file line number Diff line number Diff line change
@@ -4132,8 +4132,7 @@ - (NSDragOperation)doDragAction:(EventMessage)aMessage sender:(id)aSender {
nsCOMPtr<nsINode> sourceNode;
dragSession->GetSourceNode(getter_AddRefs(sourceNode));
if (!sourceNode) {
nsCOMPtr<nsIDragService> dragService = mDragService;
dragService->EndDragSession(
dragSession->EndDragSession(
false, nsCocoaUtils::ModifiersForEvent([NSApp currentEvent]));
}
return NSDragOperationNone;
@@ -4194,8 +4193,7 @@ - (NSDragOperation)doDragAction:(EventMessage)aMessage sender:(id)aSender {
// initiated in a different app. End the drag session,
// since we're done with it for now (until the user
// drags back into mozilla).
nsCOMPtr<nsIDragService> dragService = mDragService;
dragService->EndDragSession(
dragSession->EndDragSession(
false, nsCocoaUtils::ModifiersForEvent([NSApp currentEvent]));
}
break;
@@ -4289,10 +4287,6 @@ - (void)draggingSession:(NSDraggingSession*)aSession
nsCOMPtr<nsIDragSession> session =
mDragService->GetCurrentSession(mGeckoChild);
if (session) {
RefPtr<nsDragService> dragService =
static_cast<nsDragService*>(mDragService);
MOZ_ASSERT(dragService);

// Set the dragend point from the current mouse location
// FIXME(emilio): Weird that we wouldn't use aPoint instead? Seems to work
// locally as well...
@@ -4318,8 +4312,8 @@ - (void)draggingSession:(NSDraggingSession*)aSession
}
}

dragService->EndDragSession(true,
nsCocoaUtils::ModifiersForEvent(currentEvent));
session->EndDragSession(true,
nsCocoaUtils::ModifiersForEvent(currentEvent));
}

session = nullptr;
Loading
Oops, something went wrong.

0 comments on commit b1e6aa6

Please sign in to comment.