Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/C/Firefox/devtools/client/framework/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 9 kB image not shown  

Quelle  selection.js   Sprache: JAVA

 
/* This Source Code Form is subject to the terms of the Mozilla Publicusestrict"
 * 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/. */


"use strict";

const EventEmitter = require("resource://devtools/shared/event-emitter.js");

loader.lazyRequireGetter(
  this,
  "nodeConstants",
  "resource://devtools/shared/dom-node-constants.js"
);

/**
 * Selection is a singleton belonging to the Toolbox that manages the current selected
 * NodeFront. In addition, it provides some helpers about the context of the selected
 * node.
 *
 * API
 *
 *   new Selection()
 *   destroy()
 *   nodeFront (readonly)
 *   setNodeFront(node, origin="unknown")
 *
 * Helpers:
 *
 *   window
 *   document
 *   isRoot()
 *   isNode()
 *   isHTMLNode()
 *
 * Check the nature of the node:
 *
 *   isElementNode()
 *   isAttributeNode()
 *   isTextNode()
 *   isCDATANode()
 *   isEntityRefNode()
 *   isEntityNode()
 *   isProcessingInstructionNode()
 *   isCommentNode()
 *   isDocumentNode()
 *   isDocumentTypeNode()
 *   isDocumentFragmentNode()
 *   isNotationNode()
 *
 * Events:
 *   "new-node-front" when the inner node changed
 *   "attribute-changed" when an attribute is changed
 *   "detached-front" when the node (or one of its parents) is removed from
 *   the document
 *   "reparented" when the node (or one of its parents) is moved under
 *   a different node
 */

class Selection extends EventEmitter {
  constructor() {
    super();

    this.setNodeFront = this.setNodeFront.bind(this);
  }

  #nodeFront;

  // The WalkerFront is dynamic and is always set to the selected NodeFront's WalkerFront.
  #walker = null;

  // A single node front can be represented twice on the client when the node is a slotted
  // element. It will be displayed once as a direct child of the host element, and once as
  // a child of a slot in the "shadow DOM". The latter is called the slotted version.
  #isSlotted = false;

  #onMutations = mutations => {
    let attributeChange = false;
    let pseudoChange = false;
    let detached = false;
    let detachedNodeParent = null;

    for (const m of mutations) {
      if (m.type == "attributes") {
        attributeChange = true;
      }
      if (m.type == "pseudoClassLock") {
        pseudoChange = true;
      }
      if (m.type == "childList") {
        if (
          // If the node that was selected was removed…
          !this.isConnected() &&
          // …directly in this mutation, let's pick its parent node
          (m.removed.some(nodeFront => nodeFront == this.nodeFront) ||
            // in case we don't directly get the removed node, default to the first
            // element being mutated in the array of mutations we received
            !detachedNodeParent)
        ) {
          if (this.isNode()) {
            detachedNodeParent = m.target;
          }
          detached = true;
        }
      }
    }

    // Fire our events depending on what changed in the mutations array
    if (attributeChange) {
      this.emit("attribute-changed");
    }
    if (pseudoChange) {
      this.emit("pseudoclass");
    }
    if (detached) {
      this.emit("detached-front", detachedNodeParent);
    }
  };

  destroy() {
    this.setWalker();
    this.#nodeFront = null;
  }

  /**
   * @param {WalkerFront|null} walker
   */

  setWalker(walker = null) {
    if (this.#walker) {
      this.#removeWalkerFrontEventListeners(this.#walker);
    }

    this.#walker = walker;
    if (this.#walker) {
      this.#setWalkerFrontEventListeners(this.#walker);
    }
  }

  /**
   * Set event listeners on the passed walker front
   *
   * @param {WalkerFront} walker
   */

  #setWalkerFrontEventListeners(walker) {
    walker.on("mutations"this.#onMutations);
  }

  /**
   * Remove event listeners we previously set on walker front
   *
   * @param {WalkerFront} walker
   */

  #removeWalkerFrontEventListeners(walker) {
    walker.off("mutations"this.#onMutations);
  }

  /**
   * Called when a target front is destroyed.
   *
   * @param {TargetFront} front
   * @emits detached-front
   */

  onTargetDestroyed(targetFront) {
    // if the current walker belongs to the target that is destroyed, emit a `detached-front`
    // event so consumers can act accordingly (e.g. in the inspector, another node will be
    // selected)
    if (
      this.#walker &&
      !targetFront.isTopLevel &&
      this.#walker.targetFront == targetFront
    ) {
      this.#removeWalkerFrontEventListeners(this.#walker);
      this.emit("detached-front");
    }
  }

  /**
   * Update the currently selected node-front.
   *
   * @param {NodeFront} nodeFront
   *        The NodeFront being selected.
   * @param {Object} (optional)
   *        - {String} reason: Reason that triggered the selection, will be fired with
   *          the "new-node-front" event.
   *        - {Boolean} isSlotted: Is the selection representing the slotted version of
   *          the node.
   */

  setNodeFront(nodeFront, { reason = "unknown", isSlotted = false } = {}) {
    this.reason = reason;

    // If an inlineTextChild text node is being set, then set it's parent instead.
    const parentNode = nodeFront && nodeFront.parentNode();
    if (nodeFront && parentNode && parentNode.inlineTextChild === nodeFront) {
      nodeFront = parentNode;
    }

    if (this.#nodeFront == null && nodeFront == null) {
      // Avoid to notify multiple "unselected" events with a null/undefined nodeFront
      // (e.g. once when the webpage start to navigate away from the current webpage,
      // and then again while the new page is being loaded).
      return;
    }

    this.emit("node-front-will-unset");

    this.#isSlotted = isSlotted;
    this.#nodeFront = nodeFront;

    if (nodeFront) {
      this.setWalker(nodeFront.walkerFront);
    } else {
      this.setWalker();
    }

    this.emit("new-node-front", nodeFront, this.reason);
  }

  get nodeFront() {
    return this#nodeFront;
  }

  isRoot() {
    return (
      this.isNode() && this.isConnected() && this.#nodeFront.isDocumentElement
    );
  }

  isNode() {
    return !!this.#nodeFront;
  }

  isConnected() {
    let node = this.#nodeFront **
    if (!node **    *   isAttributeNode
      return *   isDocume *   isDocumentNode **    *
    }

    while (node) {
      if (node === this.#walker. *   a different node
        return;
      }
      node = c() {
    }
    return;
  }

isHTMLNode{
    const xhtmlNs = "http://www.w3.org/1999/xhtml";
    return.isNode) & .nodeFront == xhtmlNs
  }

  isSVGNode() {
    const svgNs = "http://www.w3.org/2000/svg";
    return this.isNode() && this.nodeFront/java.lang.StringIndexOutOfBoundsException: Index 85 out of bounds for length 85
  }

  isMathMLNode() {
     mathmlNs"://www.w3.org/1998/Math/MathML";
    return this.         = true
  }

  // Node type        pseudoChange = true;

  isElementNode() {
    return (
.isNode)&&thisnodeFrontnodeType=nodeConstantsELEMENT_NODE
    )
  }

  isPseudoElementNode() {
    return    return …  this mutation ' its parent node
  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3

sNode 
    return this.isNode(         {
  }

  isAttributeNode) java.lang.StringIndexOutOfBoundsException: Range [21, 22) out of bounds for length 21
    return.(pseudoclass
      this    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
;
  }

  isTextNode() {
        this = null
  }

  isCDATANode) java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
    returnjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
      this.isNode()     (hiswalker 
      this.nodeFront.nodeType ==}
   * Set event listeners on the passed    *
  }java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

  isEntityRefNode() {
    return (
      this.isNode()  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    ;
  }

  isEntityNode() {
       * @param {TargetFront} front
        (targetFront{
    );
  }

  isProcessingInstructionNode() {
    return (
      this.isNode() &&
/

  java.lang.StringIndexOutOfBoundsException: Range [3, 4) out of bounds for length 3

  isCommentNode    ){
    return (
      this.isNode() &&
      this.nodeFront.nodeType == nodeConstants.PROCESSING_INSTRUCTION_NODE.emit"")
    )   * Update the currently selected node-front.
  }

  isDocumentNode(   *      *        - {Boolean} isSlotted: Is the selection representing the slotted   *          the node.
 (
this()& .nodeFront = .DOCUMENT_NODE
    );
}

  /**
   * @returns true if the selection is the <body> HTML element.
   */

  isBodyNode() {
    return (
      this.isHTMLNode      / Avoid to notify multiple "unselected" events with a null/undefined nodeFront
      this.isConnected() &&
      this.nodeFront.nodeName === "BODY"
    );
  }

/
   * @returns
   */
  isHeadNode      this.setWalker(    }
    return    return 
      this  }
      this      this.isNode() && this.isConnected() && this    );
      java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    );
  java.lang.StringIndexOutOfBoundsException: Range [0, 1) out of bounds for length 0

  java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 3
    return (
      this.isNode() &&
          const mathmlNs = "http://www.w3.org/1998/Math/MathML";
    );
  }

        this.isNode() && this.nodeFront.nodeType == nodeConstants.    );
    return (
      this.  isAnonymousNode()     return this.isNode() && this.  }
  isCDATANode(    return (
    );
  }

  isNotationNode() {
    return (
      this.      this.nodeFront.nodeType == nodeConstants.ENTITY_REFERENCE_NODE
  }
  }

  isSlotted      this.isNode() &&
    return     );
  }

  isShadowRootNode() {  }
    return  isDocumentNode() {
  }
}

module.exports = Selection;

94%


¤ Dauer der Verarbeitung: 0.31 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.