Bug 1514940 - part 1: Forcibly disable new keyCode/charCode value of keypress events if the document is Confluence r=smaug,Ehsan,kmag
Old Confluence does not aware of conflated model keypress event (see UI Events
spec, https://w3c.github.io/uievents/#determine-keypress-keyCode).
Additionally, Confluence can be hosted with any domains. Therefore, we cannot
use blacklist to disable the conflated model keypress event only on it.
This patch checks whether current or parent document is Confluence with JS
module, called KeyPressEventModelCheckerChild. For kicking this module,
nsHTMLDocument dispatches an custom event, CheckKeyPressEventModel, when it
becomes editable only first time. Finally, if it's a Confluence instance, the
module let PresShell know that we need to use split model keypress event in it.
Differential Revision: https://phabricator.services.mozilla.com/D17907
--HG--
extra : moz-landing-system : lando
2019-02-05 14:35:43 +03:00
|
|
|
/* -*- mode: js; indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 sts=2 et tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
2023-03-16 15:50:27 +03:00
|
|
|
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
|
Bug 1514940 - part 1: Forcibly disable new keyCode/charCode value of keypress events if the document is Confluence r=smaug,Ehsan,kmag
Old Confluence does not aware of conflated model keypress event (see UI Events
spec, https://w3c.github.io/uievents/#determine-keypress-keyCode).
Additionally, Confluence can be hosted with any domains. Therefore, we cannot
use blacklist to disable the conflated model keypress event only on it.
This patch checks whether current or parent document is Confluence with JS
module, called KeyPressEventModelCheckerChild. For kicking this module,
nsHTMLDocument dispatches an custom event, CheckKeyPressEventModel, when it
becomes editable only first time. Finally, if it's a Confluence instance, the
module let PresShell know that we need to use split model keypress event in it.
Differential Revision: https://phabricator.services.mozilla.com/D17907
--HG--
extra : moz-landing-system : lando
2019-02-05 14:35:43 +03:00
|
|
|
|
2023-03-16 15:50:27 +03:00
|
|
|
export class KeyPressEventModelCheckerChild extends JSWindowActorChild {
|
Bug 1514940 - part 1: Forcibly disable new keyCode/charCode value of keypress events if the document is Confluence r=smaug,Ehsan,kmag
Old Confluence does not aware of conflated model keypress event (see UI Events
spec, https://w3c.github.io/uievents/#determine-keypress-keyCode).
Additionally, Confluence can be hosted with any domains. Therefore, we cannot
use blacklist to disable the conflated model keypress event only on it.
This patch checks whether current or parent document is Confluence with JS
module, called KeyPressEventModelCheckerChild. For kicking this module,
nsHTMLDocument dispatches an custom event, CheckKeyPressEventModel, when it
becomes editable only first time. Finally, if it's a Confluence instance, the
module let PresShell know that we need to use split model keypress event in it.
Differential Revision: https://phabricator.services.mozilla.com/D17907
--HG--
extra : moz-landing-system : lando
2019-02-05 14:35:43 +03:00
|
|
|
// Currently, the event is dispatched only when the document becomes editable
|
|
|
|
// because of contenteditable. If you need to add new editor which is in
|
|
|
|
// designMode, you need to change MaybeDispatchCheckKeyPressEventModelEvent()
|
2019-05-31 04:37:26 +03:00
|
|
|
// of Document.
|
Bug 1514940 - part 1: Forcibly disable new keyCode/charCode value of keypress events if the document is Confluence r=smaug,Ehsan,kmag
Old Confluence does not aware of conflated model keypress event (see UI Events
spec, https://w3c.github.io/uievents/#determine-keypress-keyCode).
Additionally, Confluence can be hosted with any domains. Therefore, we cannot
use blacklist to disable the conflated model keypress event only on it.
This patch checks whether current or parent document is Confluence with JS
module, called KeyPressEventModelCheckerChild. For kicking this module,
nsHTMLDocument dispatches an custom event, CheckKeyPressEventModel, when it
becomes editable only first time. Finally, if it's a Confluence instance, the
module let PresShell know that we need to use split model keypress event in it.
Differential Revision: https://phabricator.services.mozilla.com/D17907
--HG--
extra : moz-landing-system : lando
2019-02-05 14:35:43 +03:00
|
|
|
handleEvent(aEvent) {
|
|
|
|
if (!AppConstants.DEBUG) {
|
|
|
|
// Stop propagation in opt build to save the propagation cost.
|
|
|
|
// However, the event is necessary for running test_bug1514940.html.
|
|
|
|
// Therefore, we need to keep propagating it at least on debug build.
|
|
|
|
aEvent.stopImmediatePropagation();
|
|
|
|
}
|
|
|
|
|
2019-05-31 04:37:26 +03:00
|
|
|
// Currently, even if we set Document.KEYPRESS_EVENT_MODEL_CONFLATED
|
Bug 1514940 - part 1: Forcibly disable new keyCode/charCode value of keypress events if the document is Confluence r=smaug,Ehsan,kmag
Old Confluence does not aware of conflated model keypress event (see UI Events
spec, https://w3c.github.io/uievents/#determine-keypress-keyCode).
Additionally, Confluence can be hosted with any domains. Therefore, we cannot
use blacklist to disable the conflated model keypress event only on it.
This patch checks whether current or parent document is Confluence with JS
module, called KeyPressEventModelCheckerChild. For kicking this module,
nsHTMLDocument dispatches an custom event, CheckKeyPressEventModel, when it
becomes editable only first time. Finally, if it's a Confluence instance, the
module let PresShell know that we need to use split model keypress event in it.
Differential Revision: https://phabricator.services.mozilla.com/D17907
--HG--
extra : moz-landing-system : lando
2019-02-05 14:35:43 +03:00
|
|
|
// here, conflated model isn't used forcibly. If you need it, you need
|
|
|
|
// to change WidgetKeyboardEvent, dom::KeyboardEvent and PresShell.
|
2019-05-31 04:37:26 +03:00
|
|
|
let model = Document.KEYPRESS_EVENT_MODEL_DEFAULT;
|
2019-05-24 01:00:58 +03:00
|
|
|
if (
|
|
|
|
this._isOldOfficeOnlineServer(aEvent.target) ||
|
|
|
|
this._isOldConfluence(aEvent.target.ownerGlobal)
|
|
|
|
) {
|
2019-05-31 04:37:26 +03:00
|
|
|
model = Document.KEYPRESS_EVENT_MODEL_SPLIT;
|
Bug 1514940 - part 1: Forcibly disable new keyCode/charCode value of keypress events if the document is Confluence r=smaug,Ehsan,kmag
Old Confluence does not aware of conflated model keypress event (see UI Events
spec, https://w3c.github.io/uievents/#determine-keypress-keyCode).
Additionally, Confluence can be hosted with any domains. Therefore, we cannot
use blacklist to disable the conflated model keypress event only on it.
This patch checks whether current or parent document is Confluence with JS
module, called KeyPressEventModelCheckerChild. For kicking this module,
nsHTMLDocument dispatches an custom event, CheckKeyPressEventModel, when it
becomes editable only first time. Finally, if it's a Confluence instance, the
module let PresShell know that we need to use split model keypress event in it.
Differential Revision: https://phabricator.services.mozilla.com/D17907
--HG--
extra : moz-landing-system : lando
2019-02-05 14:35:43 +03:00
|
|
|
}
|
|
|
|
aEvent.target.setKeyPressEventModel(model);
|
|
|
|
}
|
|
|
|
|
2019-05-24 01:00:58 +03:00
|
|
|
_isOldOfficeOnlineServer(aDocument) {
|
|
|
|
let editingElement = aDocument.getElementById(
|
|
|
|
"WACViewPanel_EditingElement"
|
|
|
|
);
|
2019-06-03 17:05:18 +03:00
|
|
|
// If it's not Office Online Server, don't include it into the telemetry
|
|
|
|
// because we just need to collect percentage of old version in all loaded
|
|
|
|
// Office Online Server instances.
|
2019-05-24 01:00:58 +03:00
|
|
|
if (!editingElement) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
let isOldVersion = !editingElement.classList.contains(
|
|
|
|
"WACViewPanel_DisableLegacyKeyCodeAndCharCode"
|
|
|
|
);
|
2019-06-03 17:05:18 +03:00
|
|
|
Services.telemetry.keyedScalarAdd(
|
|
|
|
"dom.event.office_online_load_count",
|
|
|
|
isOldVersion ? "old" : "new",
|
|
|
|
1
|
|
|
|
);
|
2019-05-24 01:00:58 +03:00
|
|
|
return isOldVersion;
|
|
|
|
}
|
|
|
|
|
Bug 1514940 - part 1: Forcibly disable new keyCode/charCode value of keypress events if the document is Confluence r=smaug,Ehsan,kmag
Old Confluence does not aware of conflated model keypress event (see UI Events
spec, https://w3c.github.io/uievents/#determine-keypress-keyCode).
Additionally, Confluence can be hosted with any domains. Therefore, we cannot
use blacklist to disable the conflated model keypress event only on it.
This patch checks whether current or parent document is Confluence with JS
module, called KeyPressEventModelCheckerChild. For kicking this module,
nsHTMLDocument dispatches an custom event, CheckKeyPressEventModel, when it
becomes editable only first time. Finally, if it's a Confluence instance, the
module let PresShell know that we need to use split model keypress event in it.
Differential Revision: https://phabricator.services.mozilla.com/D17907
--HG--
extra : moz-landing-system : lando
2019-02-05 14:35:43 +03:00
|
|
|
_isOldConfluence(aWindow) {
|
|
|
|
if (!aWindow) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// aWindow should be an editor window in <iframe>. However, we don't know
|
|
|
|
// whether it can be without <iframe>. Anyway, there should be tinyMCE
|
|
|
|
// object in the parent window or in the window.
|
|
|
|
let tinyMCEObject;
|
|
|
|
// First, try to retrieve tinyMCE object from parent window.
|
|
|
|
try {
|
|
|
|
tinyMCEObject = ChromeUtils.waiveXrays(aWindow.parent).tinyMCE;
|
|
|
|
} catch (e) {
|
|
|
|
// Ignore the exception for now.
|
|
|
|
}
|
|
|
|
// Next, if there is no tinyMCE object in the parent window, let's check
|
|
|
|
// the window.
|
|
|
|
if (!tinyMCEObject) {
|
|
|
|
try {
|
|
|
|
tinyMCEObject = ChromeUtils.waiveXrays(aWindow).tinyMCE;
|
|
|
|
} catch (e) {
|
|
|
|
// Fallthrough to return false below.
|
|
|
|
}
|
|
|
|
// If we couldn't find tinyMCE object, let's assume that it's not
|
|
|
|
// Confluence instance.
|
|
|
|
if (!tinyMCEObject) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If there is tinyMCE object, we can assume that we loaded Confluence
|
|
|
|
// instance. So, let's check the version whether it allows conflated
|
|
|
|
// keypress event model.
|
|
|
|
try {
|
2023-05-20 15:26:53 +03:00
|
|
|
let { author, version } =
|
|
|
|
new tinyMCEObject.plugins.CursorTargetPlugin().getInfo();
|
2019-03-14 08:39:38 +03:00
|
|
|
// If it's not Confluence, don't include it into the telemetry because
|
|
|
|
// we just need to collect percentage of old version in all loaded
|
|
|
|
// Confluence instances.
|
|
|
|
if (author !== "Atlassian") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
let isOldVersion = version === "1.0";
|
|
|
|
Services.telemetry.keyedScalarAdd(
|
|
|
|
"dom.event.confluence_load_count",
|
|
|
|
isOldVersion ? "old" : "new",
|
|
|
|
1
|
|
|
|
);
|
|
|
|
return isOldVersion;
|
Bug 1514940 - part 1: Forcibly disable new keyCode/charCode value of keypress events if the document is Confluence r=smaug,Ehsan,kmag
Old Confluence does not aware of conflated model keypress event (see UI Events
spec, https://w3c.github.io/uievents/#determine-keypress-keyCode).
Additionally, Confluence can be hosted with any domains. Therefore, we cannot
use blacklist to disable the conflated model keypress event only on it.
This patch checks whether current or parent document is Confluence with JS
module, called KeyPressEventModelCheckerChild. For kicking this module,
nsHTMLDocument dispatches an custom event, CheckKeyPressEventModel, when it
becomes editable only first time. Finally, if it's a Confluence instance, the
module let PresShell know that we need to use split model keypress event in it.
Differential Revision: https://phabricator.services.mozilla.com/D17907
--HG--
extra : moz-landing-system : lando
2019-02-05 14:35:43 +03:00
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|