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("resource://devtools/shared/protocol.js");
13 } = require("resource://devtools/shared/specs/page-style.js");
16 * PageStyleFront, the front object for the PageStyleActor
18 class PageStyleFront
extends FrontClassWithSpec(pageStyleSpec
) {
19 _attributesCache
= new Map();
21 constructor(conn
, targetFront
, parentFront
) {
22 super(conn
, targetFront
, parentFront
);
23 this.inspector
= this.getParent();
25 this._clearAttributesCache
= this._clearAttributesCache
.bind(this);
26 this.on("stylesheet-updated", this._clearAttributesCache
);
27 this.walker
.on("new-mutations", this._clearAttributesCache
);
35 return this.inspector
.walker
;
38 get supportsFontStretchLevel4() {
39 return this._form
.traits
&& this._form
.traits
.fontStretchLevel4
;
42 get supportsFontStyleLevel4() {
43 return this._form
.traits
&& this._form
.traits
.fontStyleLevel4
;
46 get supportsFontVariations() {
47 return this._form
.traits
&& this._form
.traits
.fontVariations
;
50 get supportsFontWeightLevel4() {
51 return this._form
.traits
&& this._form
.traits
.fontWeightLevel4
;
54 getMatchedSelectors(node
, property
, options
) {
55 return super.getMatchedSelectors(node
, property
, options
).then(ret
=> {
60 async
getApplied(node
, options
= {}) {
61 const ret
= await
super.getApplied(node
, options
);
65 addNewRule(node
, pseudoClasses
) {
66 return super.addNewRule(node
, pseudoClasses
).then(ret
=> {
67 return ret
.entries
[0];
72 * Get an array of existing attribute values in a node document, given an attribute type.
74 * @param {String} search: A string to filter attribute value on.
75 * @param {String} attributeType: The type of attribute we want to retrieve the values.
76 * @param {Element} node: The element we want to get possible attributes for. This will
77 * be used to get the document where the search is happening.
78 * @returns {Array<String>} An array of strings
80 async
getAttributesInOwnerDocument(search
, attributeType
, node
) {
82 throw new Error("`type` should not be empty");
89 const lcFilter
= search
.toLowerCase();
91 // If the new filter includes the string that was used on our last trip to the server,
92 // we can filter the cached results instead of calling the server again.
94 this._attributesCache
&&
95 this._attributesCache
.has(attributeType
) &&
96 search
.startsWith(this._attributesCache
.get(attributeType
).search
)
98 const cachedResults
= this._attributesCache
100 .results
.filter(item
=> item
.toLowerCase().startsWith(lcFilter
));
102 "getAttributesInOwnerDocument-cache-hit",
105 return cachedResults
;
108 const results
= await
super.getAttributesInOwnerDocument(
113 this._attributesCache
.set(attributeType
, { search
, results
});
117 _clearAttributesCache() {
118 this._attributesCache
.clear();
122 exports
.PageStyleFront
= PageStyleFront
;
123 registerFront(PageStyleFront
);