tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SwitchDocumentDirectionChild.sys.mjs (975B)


      1 /* vim: set ts=2 sw=2 sts=2 et tw=80: */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 export class SwitchDocumentDirectionChild extends JSWindowActorChild {
      7  receiveMessage(message) {
      8    if (message.name == "SwitchDocumentDirection") {
      9      let docShell = this.manager.browsingContext.docShell;
     10      let document = docShell.QueryInterface(Ci.nsIWebNavigation).document;
     11      this.switchDocumentDirection(document);
     12    }
     13  }
     14 
     15  switchDocumentDirection(document) {
     16    // document.dir can also be "auto", in which case it won't change
     17    if (document.dir == "ltr" || document.dir == "") {
     18      document.dir = "rtl";
     19    } else if (document.dir == "rtl") {
     20      document.dir = "ltr";
     21    }
     22 
     23    for (let frame of document.defaultView.frames) {
     24      this.switchDocumentDirection(frame.document);
     25    }
     26  }
     27 }