blob: dae20f2d9dd2a5c134a2e3149a6b3047fb3588e6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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 {
installHelperSheet,
isNodeValid,
addPseudoClassLock,
removePseudoClassLock
} = require("./utils/markup");
// SimpleOutlineHighlighter's stylesheet
const HIGHLIGHTED_PSEUDO_CLASS = ":-moz-devtools-highlighted";
const SIMPLE_OUTLINE_SHEET = `.__fx-devtools-hide-shortcut__ {
visibility: hidden !important
}
${HIGHLIGHTED_PSEUDO_CLASS} {
outline: 2px dashed #F06!important;
outline-offset: -2px!important
}`;
/**
* The SimpleOutlineHighlighter is a class that has the same API than the
* BoxModelHighlighter, but adds a pseudo-class on the target element itself
* to draw a simple css outline around the element.
* It is used by the HighlighterActor when canvasframe-based highlighters can't
* be used. This is the case for XUL windows.
*/
function SimpleOutlineHighlighter(highlighterEnv) {
this.chromeDoc = highlighterEnv.document;
}
SimpleOutlineHighlighter.prototype = {
/**
* Destroy the nodes. Remove listeners.
*/
destroy: function () {
this.hide();
this.chromeDoc = null;
},
/**
* Show the highlighter on a given node
* @param {DOMNode} node
*/
show: function (node) {
if (isNodeValid(node) && (!this.currentNode || node !== this.currentNode)) {
this.hide();
this.currentNode = node;
installHelperSheet(node.ownerDocument.defaultView, SIMPLE_OUTLINE_SHEET);
addPseudoClassLock(node, HIGHLIGHTED_PSEUDO_CLASS);
}
return true;
},
/**
* Hide the highlighter, the outline and the infobar.
*/
hide: function () {
if (this.currentNode) {
removePseudoClassLock(this.currentNode, HIGHLIGHTED_PSEUDO_CLASS);
this.currentNode = null;
}
}
};
exports.SimpleOutlineHighlighter = SimpleOutlineHighlighter;
|