Files
palemoon27/browser/modules/FormValidationHandler.jsm
roytam1 351263e4a5 import changes from `dev' branch of rmottola/Arctic-Fox:
- missing bits of Bug 1207245 - part 1 - move RefCounted<T> (dccd21b327)
- Bug 1193583 - Fix out-of-date reftests. (r=jorendorff) (66ee3c50d5)
- Bug 1193583 - Fix misc XPConnect and devtools tests. (r=jorendorff) (9ed7a460d1)
- Bug 589199 - Make a global lexical scope and hook it up to JS entry points. (r=efaust) (1fde4fba9b)
- Bug 589199 - Parse and emit bytecode for global lexicals. (r=efaust) (86d168b94d)
- Bug 589199 - Support global lexicals in the interpreter. (r=efaust) (e5fa8ae995)
- Bug 589199 - Support global lexicals in Baseline. (r=jandem) (7b744015fe)
- Bug 589199 - Support global lexicals in Ion. (r=jandem) (446f05ce97)
- Bug 589199 - Fix eval static scope to play with the global lexical scope. (r=efaust) (4a7e4face1)
- Bug 589199 - Fix up the global lexical scope when merging off-thread compiled scripts. (r=bhackett) (30ff41230d)
- Bug 589199 - Fix jit-tests and js reftests. (r=efaust) (6171fa2c62)
- Bug 1202902 - Support non-syntactic extensible lexical scopes. (r=billm) (a2f553d464)
- No bug - Rename Definition::CONST to Definition::CONSTANT to avoid macro name collision on Windows. (r=Waldo) (74dfc52b28)
- Bug 589199 - Implement all-or-nothing redeclaration checks for global and eval scripts. (r=efaust) (33684af400)
- fix misspatch of 589199 (0dbeca332b)
- var->let and some misspatches (f2af7240b3)
- Bug 1212183 - Fix DOM getter optimizations in the JITs. (r=jandem) (df74d3e88d)
- Bug 1212605 - Emit global name conflicts check for Ion scripts regardless of scope chain usage. (r=efaust) (a370f28465)
- Bug 1213552 - Fix typo in using TI to guard against introducing shadowing global lexical bindings. (r=efaust) (188f583410)
- Bug 1213552 - Followup: add test. (b0ca61190b)
- let-var + XP backport (40abaf773c)
- Bug 1188290 - Remove an incomplete assertion about store buffer state; r=jandem (7344dd4819)
- Bug 1209754 - Assert that all post-barriers happen on the main thread; r=jonco (9a7431aa6d)
- comment of 854037 (c026b72e69)
- fix definitions (9b140aaafb)
2022-08-19 09:49:49 +08:00

158 lines
4.8 KiB
JavaScript

/* 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/. */
/*
* Chrome side handling of form validation popup.
*/
"use strict";
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
this.EXPORTED_SYMBOLS = [ "FormValidationHandler" ];
Cu.import("resource://gre/modules/Services.jsm");
var FormValidationHandler =
{
_panel: null,
_anchor: null,
/*
* Public apis
*/
init: function () {
let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
mm.addMessageListener("FormValidation:ShowPopup", this);
mm.addMessageListener("FormValidation:HidePopup", this);
},
uninit: function () {
let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
mm.removeMessageListener("FormValidation:ShowPopup", this);
mm.removeMessageListener("FormValidation:HidePopup", this);
this._panel = null;
this._anchor = null;
},
hidePopup: function () {
this._hidePopup();
},
/*
* Events
*/
receiveMessage: function (aMessage) {
let window = aMessage.target.ownerDocument.defaultView;
let json = aMessage.json;
let tabBrowser = window.gBrowser;
switch (aMessage.name) {
case "FormValidation:ShowPopup":
// target is the <browser>, make sure we're receiving a message
// from the foreground tab.
if (tabBrowser && aMessage.target != tabBrowser.selectedBrowser) {
return;
}
this._showPopup(window, json);
break;
case "FormValidation:HidePopup":
this._hidePopup();
break;
}
},
observe: function (aSubject, aTopic, aData) {
this._hidePopup();
},
handleEvent: function (aEvent) {
switch (aEvent.type) {
case "FullZoomChange":
case "TextZoomChange":
case "ZoomChangeUsingMouseWheel":
case "scroll":
this._hidePopup();
break;
case "popuphiding":
this._onPopupHiding(aEvent);
break;
}
},
/*
* Internal
*/
_onPopupHiding: function (aEvent) {
aEvent.originalTarget.removeEventListener("popuphiding", this, true);
let tabBrowser = aEvent.originalTarget.ownerDocument.getElementById("content");
tabBrowser.selectedBrowser.removeEventListener("scroll", this, true);
tabBrowser.selectedBrowser.removeEventListener("FullZoomChange", this, false);
tabBrowser.selectedBrowser.removeEventListener("TextZoomChange", this, false);
tabBrowser.selectedBrowser.removeEventListener("ZoomChangeUsingMouseWheel", this, false);
this._panel.hidden = true;
this._panel = null;
this._anchor.hidden = true;
this._anchor = null;
},
/*
* Shows the form validation popup at a specified position or updates the
* messaging and position if the popup is already displayed.
*
* @aWindow - the chrome window
* @aPanelData - Object that contains popup information
* aPanelData stucture detail:
* contentRect - the bounding client rect of the target element. If
* content is remote, this is relative to the browser, otherwise its
* relative to the window.
* position - popup positional string constants.
* message - the form element validation message text.
*/
_showPopup: function (aWindow, aPanelData) {
let previouslyShown = !!this._panel;
this._panel = aWindow.document.getElementById("invalid-form-popup");
this._panel.firstChild.textContent = aPanelData.message;
this._panel.hidden = false;
let tabBrowser = aWindow.gBrowser;
this._anchor = tabBrowser.formValidationAnchor;
this._anchor.left = aPanelData.contentRect.left;
this._anchor.top = aPanelData.contentRect.top;
this._anchor.width = aPanelData.contentRect.width;
this._anchor.height = aPanelData.contentRect.height;
this._anchor.hidden = false;
// Display the panel if it isn't already visible.
if (!previouslyShown) {
// Cleanup after the popup is hidden
this._panel.addEventListener("popuphiding", this, true);
// Hide if the user scrolls the page
tabBrowser.selectedBrowser.addEventListener("scroll", this, true);
tabBrowser.selectedBrowser.addEventListener("FullZoomChange", this, false);
tabBrowser.selectedBrowser.addEventListener("TextZoomChange", this, false);
tabBrowser.selectedBrowser.addEventListener("ZoomChangeUsingMouseWheel", this, false);
// Open the popup
this._panel.openPopup(this._anchor, aPanelData.position, 0, 0, false);
}
},
/*
* Hide the popup if currently displayed. Will fire an event to onPopupHiding
* above if visible.
*/
_hidePopup: function () {
if (this._panel) {
this._panel.hidePopup();
}
}
};