From 1c56792626313c099fb11ade916faf7f3e2e3cbb Mon Sep 17 00:00:00 2001 From: Agi Sferro Date: Tue, 27 Oct 2020 16:18:25 +0000 Subject: [PATCH] Bug 1648156 - Migrate GeckoViewSelectionActionChild to actor. r=snorp Differential Revision: https://phabricator.services.mozilla.com/D94648 --- .../SelectionActionDelegateChild.jsm} | 184 ++++++++---------- mobile/android/actors/moz.build | 1 + mobile/android/chrome/geckoview/geckoview.js | 15 +- mobile/android/chrome/geckoview/jar.mn | 1 - 4 files changed, 97 insertions(+), 104 deletions(-) rename mobile/android/{chrome/geckoview/GeckoViewSelectionActionChild.js => actors/SelectionActionDelegateChild.jsm} (65%) diff --git a/mobile/android/chrome/geckoview/GeckoViewSelectionActionChild.js b/mobile/android/actors/SelectionActionDelegateChild.jsm similarity index 65% rename from mobile/android/chrome/geckoview/GeckoViewSelectionActionChild.js rename to mobile/android/actors/SelectionActionDelegateChild.jsm index 439c30529ecd..82a7b23a3e2b 100644 --- a/mobile/android/chrome/geckoview/GeckoViewSelectionActionChild.js +++ b/mobile/android/actors/SelectionActionDelegateChild.jsm @@ -1,104 +1,104 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ /* 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/. */ -const { GeckoViewChildModule } = ChromeUtils.import( - "resource://gre/modules/GeckoViewChildModule.jsm" +const { GeckoViewActorChild } = ChromeUtils.import( + "resource://gre/modules/GeckoViewActorChild.jsm" ); -var { XPCOMUtils } = ChromeUtils.import( +const { XPCOMUtils } = ChromeUtils.import( "resource://gre/modules/XPCOMUtils.jsm" ); -var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); +const EXPORTED_SYMBOLS = ["SelectionActionDelegateChild"]; // Dispatches GeckoView:ShowSelectionAction and GeckoView:HideSelectionAction to // the GeckoSession on accessible caret changes. -class GeckoViewSelectionActionChild extends GeckoViewChildModule { +class SelectionActionDelegateChild extends GeckoViewActorChild { constructor(aModuleName, aMessageManager) { super(aModuleName, aMessageManager); this._seqNo = 0; this._isActive = false; this._previousMessage = ""; - - this._actions = [ - { - id: "org.mozilla.geckoview.HIDE", - predicate: _ => true, - perform: _ => this.handleEvent({ type: "pagehide" }), - }, - { - id: "org.mozilla.geckoview.CUT", - predicate: e => - !e.collapsed && e.selectionEditable && !this._isPasswordField(e), - perform: _ => docShell.doCommand("cmd_cut"), - }, - { - id: "org.mozilla.geckoview.COPY", - predicate: e => !e.collapsed && !this._isPasswordField(e), - perform: _ => docShell.doCommand("cmd_copy"), - }, - { - id: "org.mozilla.geckoview.PASTE", - predicate: e => - e.selectionEditable && - Services.clipboard.hasDataMatchingFlavors( - ["text/unicode"], - Ci.nsIClipboard.kGlobalClipboard - ), - perform: _ => this._performPaste(), - }, - { - id: "org.mozilla.geckoview.DELETE", - predicate: e => !e.collapsed && e.selectionEditable, - perform: _ => docShell.doCommand("cmd_delete"), - }, - { - id: "org.mozilla.geckoview.COLLAPSE_TO_START", - predicate: e => !e.collapsed && e.selectionEditable, - perform: e => docShell.doCommand("cmd_moveLeft"), - }, - { - id: "org.mozilla.geckoview.COLLAPSE_TO_END", - predicate: e => !e.collapsed && e.selectionEditable, - perform: e => docShell.doCommand("cmd_moveRight"), - }, - { - id: "org.mozilla.geckoview.UNSELECT", - predicate: e => !e.collapsed && !e.selectionEditable, - perform: e => docShell.doCommand("cmd_selectNone"), - }, - { - id: "org.mozilla.geckoview.SELECT_ALL", - predicate: e => { - if (e.reason === "longpressonemptycontent") { - return false; - } - if (e.selectionEditable && e.target && e.target.activeElement) { - const element = e.target.activeElement; - let value = ""; - if (element.value) { - value = element.value; - } else if ( - element.isContentEditable || - e.target.designMode === "on" - ) { - value = element.innerText; - } - // Do not show SELECT_ALL if the editable is empty - // or all the editable text is already selected. - return value !== "" && value !== e.selectedTextContent; - } - return true; - }, - perform: e => docShell.doCommand("cmd_selectAll"), - }, - ]; } + _actions = [ + { + id: "org.mozilla.geckoview.HIDE", + predicate: _ => true, + perform: _ => this.handleEvent({ type: "pagehide" }), + }, + { + id: "org.mozilla.geckoview.CUT", + predicate: e => + !e.collapsed && e.selectionEditable && !this._isPasswordField(e), + perform: _ => this.docShell.doCommand("cmd_cut"), + }, + { + id: "org.mozilla.geckoview.COPY", + predicate: e => !e.collapsed && !this._isPasswordField(e), + perform: _ => this.docShell.doCommand("cmd_copy"), + }, + { + id: "org.mozilla.geckoview.PASTE", + predicate: e => + e.selectionEditable && + Services.clipboard.hasDataMatchingFlavors( + ["text/unicode"], + Ci.nsIClipboard.kGlobalClipboard + ), + perform: _ => this._performPaste(), + }, + { + id: "org.mozilla.geckoview.DELETE", + predicate: e => !e.collapsed && e.selectionEditable, + perform: _ => this.docShell.doCommand("cmd_delete"), + }, + { + id: "org.mozilla.geckoview.COLLAPSE_TO_START", + predicate: e => !e.collapsed && e.selectionEditable, + perform: e => this.docShell.doCommand("cmd_moveLeft"), + }, + { + id: "org.mozilla.geckoview.COLLAPSE_TO_END", + predicate: e => !e.collapsed && e.selectionEditable, + perform: e => this.docShell.doCommand("cmd_moveRight"), + }, + { + id: "org.mozilla.geckoview.UNSELECT", + predicate: e => !e.collapsed && !e.selectionEditable, + perform: e => this.docShell.doCommand("cmd_selectNone"), + }, + { + id: "org.mozilla.geckoview.SELECT_ALL", + predicate: e => { + if (e.reason === "longpressonemptycontent") { + return false; + } + if (e.selectionEditable && e.target && e.target.activeElement) { + const element = e.target.activeElement; + let value = ""; + if (element.value) { + value = element.value; + } else if ( + element.isContentEditable || + e.target.designMode === "on" + ) { + value = element.innerText; + } + // Do not show SELECT_ALL if the editable is empty + // or all the editable text is already selected. + return value !== "" && value !== e.selectedTextContent; + } + return true; + }, + perform: e => this.docShell.doCommand("cmd_selectAll"), + }, + ]; + _performPaste() { this.handleEvent({ type: "pagehide" }); - docShell.doCommand("cmd_paste"); + this.docShell.doCommand("cmd_paste"); } _isPasswordField(aEvent) { @@ -163,23 +163,6 @@ class GeckoViewSelectionActionChild extends GeckoViewChildModule { return offset; } - onEnable() { - debug`onEnable`; - addEventListener("mozcaretstatechanged", this, { mozSystemGroup: true }); - addEventListener("pagehide", this, { capture: true, mozSystemGroup: true }); - addEventListener("deactivate", this, { mozSystemGroup: true }); - } - - onDisable() { - debug`onDisable`; - removeEventListener("mozcaretstatechanged", this, { mozSystemGroup: true }); - removeEventListener("pagehide", this, { - capture: true, - mozSystemGroup: true, - }); - removeEventListener("deactivate", this, { mozSystemGroup: true }); - } - /** * Receive and act on AccessibleCarets caret state-change * (mozcaretstatechanged and pagehide) events. @@ -322,7 +305,6 @@ class GeckoViewSelectionActionChild extends GeckoViewChildModule { } } -const { debug, warn } = GeckoViewSelectionActionChild.initLogging( - "GeckoViewSelectionAction" +const { debug, warn } = SelectionActionDelegateChild.initLogging( + "SelectionActionDelegate" ); -const module = GeckoViewSelectionActionChild.create(this); diff --git a/mobile/android/actors/moz.build b/mobile/android/actors/moz.build index 333d236849e3..6e51c42fb14d 100644 --- a/mobile/android/actors/moz.build +++ b/mobile/android/actors/moz.build @@ -16,5 +16,6 @@ FINAL_TARGET_FILES.actors += [ "ProgressDelegateChild.jsm", "ProgressDelegateParent.jsm", "ScrollDelegateChild.jsm", + "SelectionActionDelegateChild.jsm", "WebBrowserChromeChild.jsm", ] diff --git a/mobile/android/chrome/geckoview/geckoview.js b/mobile/android/chrome/geckoview/geckoview.js index 0e33bed8f81e..3a0921760d77 100644 --- a/mobile/android/chrome/geckoview/geckoview.js +++ b/mobile/android/chrome/geckoview/geckoview.js @@ -643,8 +643,19 @@ function startup() { { name: "GeckoViewSelectionAction", onEnable: { - frameScript: - "chrome://geckoview/content/GeckoViewSelectionActionChild.js", + actors: { + SelectionActionDelegate: { + child: { + moduleURI: "resource:///actors/SelectionActionDelegateChild.jsm", + events: { + mozcaretstatechanged: { mozSystemGroup: true }, + pagehide: { capture: true, mozSystemGroup: true }, + deactivate: { mozSystemGroup: true }, + }, + }, + allFrames: true, + }, + }, }, }, { diff --git a/mobile/android/chrome/geckoview/jar.mn b/mobile/android/chrome/geckoview/jar.mn index 8ea8b0515862..9b43bdfa0bd6 100644 --- a/mobile/android/chrome/geckoview/jar.mn +++ b/mobile/android/chrome/geckoview/jar.mn @@ -15,7 +15,6 @@ geckoview.jar: content/GeckoViewAutofillChild.js content/GeckoViewMediaChild.js content/GeckoViewMediaControlChild.js - content/GeckoViewSelectionActionChild.js content/SessionStateAggregator.js % content branding %content/branding/