Bug 1824589 - Convert toolkit/components/narrate to ES modules. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D173644
This commit is contained in:
Mark Banner 2023-03-27 16:06:59 +00:00
Родитель bde19f5f7a
Коммит 9eb2063059
8 изменённых файлов: 23 добавлений и 51 удалений

Просмотреть файл

@ -75,7 +75,7 @@ void DOMSecurityMonitor::AuditParsingOfHTMLXMLFragments(
nsLiteralCString("resource://devtools/client/shared/widgets/tooltip/"
"inactive-css-tooltip-helper.js"),
"resource://devtools/client/shared/widgets/Spectrum.js"_ns,
"resource://gre/modules/narrate/VoiceSelect.jsm"_ns,
"resource://gre/modules/narrate/VoiceSelect.sys.mjs"_ns,
"resource://normandy-vendor/ReactDOM.js"_ns,
// ------------------------------------------------------------------
// test pages

Просмотреть файл

@ -2,25 +2,15 @@
* 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/. */
"use strict";
const { VoiceSelect } = ChromeUtils.import(
"resource://gre/modules/narrate/VoiceSelect.jsm"
);
const { Narrator } = ChromeUtils.import(
"resource://gre/modules/narrate/Narrator.jsm"
);
const { AsyncPrefs } = ChromeUtils.importESModule(
"resource://gre/modules/AsyncPrefs.sys.mjs"
);
var EXPORTED_SYMBOLS = ["NarrateControls"];
import { AsyncPrefs } from "resource://gre/modules/AsyncPrefs.sys.mjs";
import { Narrator } from "resource://gre/modules/narrate/Narrator.sys.mjs";
import { VoiceSelect } from "resource://gre/modules/narrate/VoiceSelect.sys.mjs";
var gStrings = Services.strings.createBundle(
"chrome://global/locale/narrate.properties"
);
function NarrateControls(win, languagePromise) {
export function NarrateControls(win, languagePromise) {
this._winRef = Cu.getWeakReference(win);
this._languagePromise = languagePromise;

Просмотреть файл

@ -2,10 +2,6 @@
* 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/. */
"use strict";
var EXPORTED_SYMBOLS = ["Narrator"];
// Maximum time into paragraph when pressing "skip previous" will go
// to previous paragraph and not the start of current one.
const PREV_THRESHOLD = 2000;
@ -25,7 +21,7 @@ const kTextStylesRules = [
"word-spacing",
];
function Narrator(win, languagePromise) {
export function Narrator(win, languagePromise) {
this._winRef = Cu.getWeakReference(win);
this._languagePromise = languagePromise;
this._inTest = Services.prefs.getBoolPref("narrate.test");
@ -327,8 +323,8 @@ Highlighter.prototype = {
/**
* Highlight the range within offsets relative to the container.
*
* @param {Number} startOffset the start offset
* @param {Number} length the length in characters of the range
* @param {number} startOffset the start offset
* @param {number} length the length in characters of the range
*/
highlight(startOffset, length) {
let containerRect = this.container.getBoundingClientRect();
@ -392,7 +388,7 @@ Highlighter.prototype = {
* Returns specified amount of highlight nodes. Creates new ones if necessary
* and purges any additional nodes that are not needed.
*
* @param {Number} count number of nodes needed
* @param {number} count number of nodes needed
*/
_getFreshHighlightNodes(count) {
let doc = this.container.ownerDocument;
@ -418,8 +414,8 @@ Highlighter.prototype = {
* Create and return a range object with the start and end offsets relative
* to the container node.
*
* @param {Number} startOffset the start offset
* @param {Number} endOffset the end offset
* @param {number} startOffset the start offset
* @param {number} endOffset the end offset
*/
_getRange(startOffset, endOffset) {
let doc = this.container.ownerDocument;

Просмотреть файл

@ -2,11 +2,7 @@
* 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/. */
"use strict";
var EXPORTED_SYMBOLS = ["VoiceSelect"];
function VoiceSelect(win, label) {
export function VoiceSelect(win, label) {
this._winRef = Cu.getWeakReference(win);
let element = win.document.createElement("div");

Просмотреть файл

@ -7,6 +7,10 @@
with Files("**"):
BUG_COMPONENT = ("Toolkit", "Reader Mode")
EXTRA_JS_MODULES.narrate = ["NarrateControls.jsm", "Narrator.jsm", "VoiceSelect.jsm"]
EXTRA_JS_MODULES.narrate = [
"NarrateControls.sys.mjs",
"Narrator.sys.mjs",
"VoiceSelect.sys.mjs",
]
BROWSER_CHROME_MANIFESTS += ["test/browser.ini"]

Просмотреть файл

@ -2,21 +2,11 @@
* 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/. */
"use strict";
import { ContentTaskUtils } from "resource://testing-common/ContentTaskUtils.sys.mjs";
import { Preferences } from "resource://gre/modules/Preferences.sys.mjs";
import { setTimeout } from "resource://gre/modules/Timer.sys.mjs";
const { Preferences } = ChromeUtils.importESModule(
"resource://gre/modules/Preferences.sys.mjs"
);
const { ContentTaskUtils } = ChromeUtils.importESModule(
"resource://testing-common/ContentTaskUtils.sys.mjs"
);
const { setTimeout } = ChromeUtils.importESModule(
"resource://gre/modules/Timer.sys.mjs"
);
var EXPORTED_SYMBOLS = ["NarrateTestUtils"];
var NarrateTestUtils = {
export var NarrateTestUtils = {
TOGGLE: ".narrate-toggle",
POPUP: ".narrate-dropdown .dropdown-popup",
VOICE_SELECT: ".narrate-voices .select-toggle",

Просмотреть файл

@ -1,7 +1,7 @@
[DEFAULT]
support-files =
head.js
NarrateTestUtils.jsm
NarrateTestUtils.sys.mjs
moby_dick.html
[browser_narrate.js]

Просмотреть файл

@ -11,12 +11,8 @@ const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
AsyncPrefs: "resource://gre/modules/AsyncPrefs.sys.mjs",
NarrateControls: "resource://gre/modules/narrate/NarrateControls.sys.mjs",
});
ChromeUtils.defineModuleGetter(
lazy,
"NarrateControls",
"resource://gre/modules/narrate/NarrateControls.jsm"
);
ChromeUtils.defineModuleGetter(
lazy,
"NimbusFeatures",