diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /mobile/android/actors/SelectionActionDelegateParent.sys.mjs | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | mobile/android/actors/SelectionActionDelegateParent.sys.mjs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/mobile/android/actors/SelectionActionDelegateParent.sys.mjs b/mobile/android/actors/SelectionActionDelegateParent.sys.mjs new file mode 100644 index 0000000000..3ef5830ce4 --- /dev/null +++ b/mobile/android/actors/SelectionActionDelegateParent.sys.mjs @@ -0,0 +1,72 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import { GeckoViewActorParent } from "resource://gre/modules/GeckoViewActorParent.sys.mjs"; + +export class SelectionActionDelegateParent extends GeckoViewActorParent { + respondTo = null; + actionId = null; + + get rootActor() { + return this.browsingContext.top.currentWindowGlobal.getActor( + "SelectionActionDelegate" + ); + } + + receiveMessage(aMessage) { + const { data, name } = aMessage; + switch (name) { + case "ShowSelectionAction": { + this.rootActor.showSelectionAction(this, data); + break; + } + + case "HideSelectionAction": { + this.rootActor.hideSelectionAction(this, data.reason); + break; + } + + default: { + super.receiveMessage(aMessage); + } + } + } + + hideSelectionAction(aRespondTo, reason) { + // Mark previous actions as stale. Don't do this for "invisibleselection" + // or "scroll" because previous actions should still be valid even after + // these events occur. + if (reason !== "invisibleselection" && reason !== "scroll") { + this.actionId = null; + } + + this.eventDispatcher?.sendRequest({ + type: "GeckoView:HideSelectionAction", + reason, + }); + } + + showSelectionAction(aRespondTo, aData) { + this.actionId = Services.uuid.generateUUID().toString(); + this.respondTo = aRespondTo; + + this.eventDispatcher?.sendRequest({ + type: "GeckoView:ShowSelectionAction", + actionId: this.actionId, + ...aData, + }); + } + + executeSelectionAction(aData) { + if (this.actionId === null || aData.actionId != this.actionId) { + warn`Stale response ${aData.id} ${aData.actionId}`; + return; + } + this.respondTo.sendAsyncMessage("ExecuteSelectionAction", aData); + } +} + +const { debug, warn } = SelectionActionDelegateParent.initLogging( + "SelectionActionDelegate" +); |