tor-browser

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

read-only-editor.js (1964B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 const nodeConstants = require("resource://devtools/shared/dom-node-constants.js");
      8 
      9 /**
     10 * Creates an editor for non-editable nodes.
     11 */
     12 class ReadOnlyEditor {
     13  constructor(container, nodeFront) {
     14    this.container = container;
     15    this.markup = this.container.markup;
     16    this.buildMarkup();
     17 
     18    if (nodeFront.nodeType == nodeConstants.DOCUMENT_TYPE_NODE) {
     19      this.elt.classList.add("comment", "doctype");
     20      this.tag.textContent = nodeFront.doctypeString;
     21    } else if (nodeFront.isShadowRoot) {
     22      this.tag.textContent = `#shadow-root (${nodeFront.shadowRootMode})`;
     23    } else {
     24      this.tag.textContent = nodeFront.displayName;
     25      if (nodeFront.isPseudoElement) {
     26        this.tag.classList.add("pseudo", "force-color-on-flash");
     27      }
     28    }
     29 
     30    // Make the "tag" part of this editor focusable.
     31    this.tag.setAttribute("tabindex", "-1");
     32  }
     33  buildMarkup() {
     34    const doc = this.markup.doc;
     35 
     36    this.elt = doc.createElement("span");
     37    this.elt.classList.add("editor");
     38 
     39    this.tag = doc.createElement("span");
     40    this.tag.classList.add("tag");
     41    this.elt.appendChild(this.tag);
     42  }
     43 
     44  destroy() {
     45    // We might be already destroyed.
     46    if (!this.elt) {
     47      return;
     48    }
     49 
     50    this.elt.remove();
     51    this.elt = null;
     52    this.tag = null;
     53  }
     54 
     55  /**
     56   * Show overflow highlight if showOverflowHighlight is true, otherwise hide it.
     57   *
     58   * @param {boolean} showOverflowHighlight
     59   */
     60  setOverflowHighlight(showOverflowHighlight) {
     61    this.container.tagState.classList.toggle(
     62      "overflow-causing-highlighted",
     63      showOverflowHighlight
     64    );
     65  }
     66 
     67  /**
     68   * Stub method for consistency with ElementEditor.
     69   */
     70  getInfoAtNode() {
     71    return null;
     72  }
     73 }
     74 
     75 module.exports = ReadOnlyEditor;