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/. */
10 } = require("devtools/shared/protocol");
11 const flags = require("devtools/shared/flags");
13 customHighlighterSpec,
15 } = require("devtools/shared/specs/highlighters");
17 class HighlighterFront extends FrontClassWithSpec(highlighterSpec) {
18 constructor(client, targetFront, parentFront) {
19 super(client, targetFront, parentFront);
21 this.isNodeFrontHighlighted = false;
22 this.isPicking = false;
25 // Update the object given a form representation off the wire.
27 this.actorID = json.actor;
28 // FF42+ HighlighterActors starts exposing custom form, with traits object
29 this.traits = json.traits || {};
33 * Start the element picker on the debuggee target.
34 * @param {Boolean} doFocus - Optionally focus the content area once the picker is
36 * @return promise that resolves when the picker has started or immediately
37 * if it is already started
43 this.isPicking = true;
44 if (doFocus && super.pickAndFocus) {
45 return super.pickAndFocus();
51 * Stop the element picker.
52 * @return promise that resolves when the picker has stopped or immediately
53 * if it is already stopped
56 if (!this.isPicking) {
57 return Promise.resolve();
59 this.isPicking = false;
60 return super.cancelPick();
64 * Show the box model highlighter on a node in the content page.
65 * The node needs to be a NodeFront, as defined by the inspector actor
66 * @see devtools/server/actors/inspector/inspector.js
67 * @param {NodeFront} nodeFront The node to highlight
68 * @param {Object} options
69 * @return A promise that resolves when the node has been highlighted
71 async highlight(nodeFront, options = {}) {
76 this.isNodeFrontHighlighted = true;
77 await this.showBoxModel(nodeFront, options);
78 this.emit("node-highlight", nodeFront);
82 * Hide the highlighter.
83 * @param {Boolean} forceHide Only really matters in test mode (when
84 * flags.testing is true). In test mode, hovering over several nodes
85 * in the markup view doesn't hide/show the highlighter to ease testing. The
86 * highlighter stays visible at all times, except when the mouse leaves the
87 * markup view, which is when this param is passed to true
88 * @return a promise that resolves when the highlighter is hidden
90 async unhighlight(forceHide = false) {
91 forceHide = forceHide || !flags.testing;
93 if (this.isNodeFrontHighlighted && forceHide) {
94 this.isNodeFrontHighlighted = false;
95 await this.hideBoxModel();
98 this.emit("node-unhighlight");
102 exports.HighlighterFront = HighlighterFront;
103 registerFront(HighlighterFront);
105 class CustomHighlighterFront extends FrontClassWithSpec(customHighlighterSpec) {
106 constructor(client, targetFront, parentFront) {
107 super(client, targetFront, parentFront);
109 this._isShown = false;
113 this._isShown = true;
114 return super.show(...args);
118 this._isShown = false;
123 return this._isShown;
127 exports.CustomHighlighterFront = CustomHighlighterFront;
128 registerFront(CustomHighlighterFront);