Bug 1544714 - ensure that the contrast ratio check required stylesheet does not get removed while calculating contrast. r=pbro
authorYura Zenevich <yura.zenevich@gmail.com>
Thu, 18 Apr 2019 07:16:07 +0000
changeset 470067 9dafc71a1f375a6865521e7e26073394b0c8cd0b
parent 470066 edb8832eafa11ea93d652b277ac192f7ae0a2c19
child 470068 2091fc58b1314cd0579eb04e2140b3ad563bbb16
push id112843
push useraiakab@mozilla.com
push dateFri, 19 Apr 2019 09:50:22 +0000
treeherdermozilla-inbound@c06f27cbfe40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbro
bugs1544714
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1544714 - ensure that the contrast ratio check required stylesheet does not get removed while calculating contrast. r=pbro Differential Revision: https://phabricator.services.mozilla.com/D27897
devtools/server/actors/accessibility/walker.js
--- a/devtools/server/actors/accessibility/walker.js
+++ b/devtools/server/actors/accessibility/walker.js
@@ -151,16 +151,17 @@ function getAudit(acc, report) {
  * accessibility engine by storing a reference to the XPCOM accessibility
  * service.
  */
 const AccessibleWalkerActor = ActorClassWithSpec(accessibleWalkerSpec, {
   initialize(conn, targetActor) {
     Actor.prototype.initialize.call(this, conn);
     this.targetActor = targetActor;
     this.refMap = new Map();
+    this._loadedSheets = new WeakMap();
     this.setA11yServiceGetter();
     this.onPick = this.onPick.bind(this);
     this.onHovered = this.onHovered.bind(this);
     this._preventContentEvent = this._preventContentEvent.bind(this);
     this.onKey = this.onKey.bind(this);
     this.onHighlighterEvent = this.onHighlighterEvent.bind(this);
   },
 
@@ -522,45 +523,53 @@ const AccessibleWalkerActor = ActorClass
    * Ensure that nothing interferes with the audit for an accessible object
    * (CSS, overlays) by load accessibility highlighter style sheet used for
    * preventing transitions and applying transparency when calculating colour
    * contrast as well as temporarily hiding accessible highlighter overlay.
    * @param  {Object} win
    *         Window where highlighting happens.
    */
   clearStyles(win) {
-    if (this._sheetLoaded) {
+    const requests = this._loadedSheets.get(win);
+    if (requests != null) {
+      this._loadedSheets.set(win, requests + 1);
       return;
     }
 
     // Disable potential mouse driven transitions (This is important because accessibility
     // highlighter temporarily modifies text color related CSS properties. In case where
     // there are transitions that affect them, there might be unexpected side effects when
     // taking a snapshot for contrast measurement).
     loadSheet(win, HIGHLIGHTER_STYLES_SHEET);
-    this._sheetLoaded = true;
+    this._loadedSheets.set(win, 1);
     this.hideHighlighter();
   },
 
   /**
    * Restore CSS and overlays that could've interfered with the audit for an
    * accessible object by unloading accessibility highlighter style sheet used
    * for preventing transitions and applying transparency when calculating
    * colour contrast and potentially restoring accessible highlighter overlay.
    * @param  {Object} win
    *         Window where highlighting was happenning.
    */
   restoreStyles(win) {
-    if (!this._sheetLoaded) {
+    const requests = this._loadedSheets.get(win);
+    if (!requests) {
+      return;
+    }
+
+    if (requests > 1) {
+      this._loadedSheets.set(win, requests - 1);
       return;
     }
 
     this.showHighlighter();
     removeSheet(win, HIGHLIGHTER_STYLES_SHEET);
-    this._sheetLoaded = false;
+    this._loadedSheets.delete(win);
   },
 
   hideHighlighter() {
     // TODO: Fix this workaround that temporarily removes higlighter bounds
     // overlay that can interfere with the contrast ratio calculation.
     if (this._highlighter) {
       const highlighter = this._highlighter.instance;
       highlighter.hideAccessibleBounds();