tor-browser

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

slotted-node-container.js (1851B)


      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 SlottedNodeEditor = require("resource://devtools/client/inspector/markup/views/slotted-node-editor.js");
      8 const MarkupContainer = require("resource://devtools/client/inspector/markup/views/markup-container.js");
      9 
     10 class SlottedNodeContainer extends MarkupContainer {
     11  constructor(markupView, node) {
     12    super();
     13    super.initialize(markupView, node, "slottednodecontainer");
     14 
     15    this.editor = new SlottedNodeEditor(this, node);
     16    this.tagLine.appendChild(this.editor.elt);
     17    this.hasChildren = false;
     18  }
     19  _onMouseDown(event) {
     20    if (event.target.classList.contains("reveal-link")) {
     21      event.stopPropagation();
     22      event.preventDefault();
     23      return;
     24    }
     25    MarkupContainer.prototype._onMouseDown.call(this, event);
     26  }
     27 
     28  /**
     29   * Slotted node containers never display children and should not react to toggle.
     30   */
     31  _onToggle(event) {
     32    event.stopPropagation();
     33  }
     34 
     35  _revealFromSlot() {
     36    const reason = "reveal-from-slot";
     37    this.markup.inspector.selection.setNodeFront(this.node, { reason });
     38    Glean.devtoolsShadowdom.revealLinkClicked.set(true);
     39  }
     40 
     41  _onKeyDown(event) {
     42    MarkupContainer.prototype._onKeyDown.call(this, event);
     43 
     44    const isActionKey = event.code == "Enter" || event.code == "Space";
     45    if (event.target.classList.contains("reveal-link") && isActionKey) {
     46      this._revealFromSlot();
     47    }
     48  }
     49 
     50  async onContainerClick(event) {
     51    if (!event.target.classList.contains("reveal-link")) {
     52      return;
     53    }
     54 
     55    this._revealFromSlot();
     56  }
     57 
     58  isDraggable() {
     59    return false;
     60  }
     61 
     62  isSlotted() {
     63    return true;
     64  }
     65 }
     66 
     67 module.exports = SlottedNodeContainer;