Bug 1816170 - Disable perftest-on-autoland cron. r=aglavic
[gecko.git] / layout / inspector / InspectorUtils.h
blobc418305c530a1031519cd2bc459ef76d971af5b3
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/.
6 */
8 #ifndef mozilla_dom_InspectorUtils_h
9 #define mozilla_dom_InspectorUtils_h
11 #include "mozilla/dom/InspectorUtilsBinding.h"
12 #include "mozilla/UniquePtr.h"
13 #include "nsLayoutUtils.h"
15 class nsAtom;
16 class nsINode;
17 class nsINodeList;
18 class nsRange;
20 namespace mozilla {
21 class BindingStyleRule;
22 class StyleSheet;
23 namespace css {
24 class Rule;
25 } // namespace css
26 namespace dom {
27 class CharacterData;
28 class Document;
29 class Element;
30 class InspectorFontFace;
31 } // namespace dom
32 } // namespace mozilla
34 namespace mozilla {
35 namespace dom {
37 /**
38 * A collection of utility methods for use by devtools.
40 class InspectorUtils {
41 public:
42 static void GetAllStyleSheets(GlobalObject& aGlobal, Document& aDocument,
43 bool aDocumentOnly,
44 nsTArray<RefPtr<StyleSheet>>& aResult);
45 static void GetCSSStyleRules(GlobalObject& aGlobal, Element& aElement,
46 const nsAString& aPseudo,
47 bool aIncludeVisitedStyle,
48 nsTArray<RefPtr<BindingStyleRule>>& aResult);
50 /**
51 * Get the line number of a rule.
53 * @param aRule The rule.
54 * @return The rule's line number. Line numbers are 1-based.
56 static uint32_t GetRuleLine(GlobalObject& aGlobal, css::Rule& aRule);
58 /**
59 * Get the column number of a rule.
61 * @param aRule The rule.
62 * @return The rule's column number. Column numbers are 1-based.
64 static uint32_t GetRuleColumn(GlobalObject& aGlobal, css::Rule& aRule);
66 /**
67 * Like getRuleLine, but if the rule is in a <style> element,
68 * returns a line number relative to the start of the element.
70 * @param aRule the rule to examine
71 * @return the line number of the rule, possibly relative to the
72 * <style> element
74 static uint32_t GetRelativeRuleLine(GlobalObject& aGlobal, css::Rule& aRule);
76 static bool HasRulesModifiedByCSSOM(GlobalObject& aGlobal,
77 StyleSheet& aSheet);
79 // Utilities for working with selectors. We don't have a JS OM representation
80 // of a single selector or a selector list yet, but given a rule we can index
81 // into the selector list.
83 // These methods would probably make more sense being [ChromeOnly] APIs on
84 // CSSStyleRule itself (bug 1428245).
85 static uint32_t GetSelectorCount(GlobalObject& aGlobal,
86 BindingStyleRule& aRule);
88 // For all three functions below, aSelectorIndex is 0-based
89 static void GetSelectorText(GlobalObject& aGlobal, BindingStyleRule& aRule,
90 uint32_t aSelectorIndex, nsACString& aText,
91 ErrorResult& aRv);
92 static uint64_t GetSpecificity(GlobalObject& aGlobal, BindingStyleRule& aRule,
93 uint32_t aSelectorIndex, ErrorResult& aRv);
94 // Note: This does not handle scoped selectors correctly, because it has no
95 // idea what the right scope is.
96 static bool SelectorMatchesElement(GlobalObject& aGlobal, Element& aElement,
97 BindingStyleRule& aRule,
98 uint32_t aSelectorIndex,
99 const nsAString& aPseudo,
100 bool aRelevantLinkVisited,
101 ErrorResult& aRv);
103 // Utilities for working with CSS properties
105 // Returns true if the string names a property that is inherited by default.
106 static bool IsInheritedProperty(GlobalObject& aGlobal,
107 const nsACString& aPropertyName);
109 // Get a list of all our supported property names. Optionally
110 // property aliases included.
111 static void GetCSSPropertyNames(GlobalObject& aGlobal,
112 const PropertyNamesOptions& aOptions,
113 nsTArray<nsString>& aResult);
115 // Get a list of all properties controlled by preference, as well as
116 // their corresponding preference names.
117 static void GetCSSPropertyPrefs(GlobalObject& aGlobal,
118 nsTArray<PropertyPref>& aResult);
120 // Get a list of all valid keywords and colors for aProperty.
121 static void GetCSSValuesForProperty(GlobalObject& aGlobal,
122 const nsACString& aPropertyName,
123 nsTArray<nsString>& aResult,
124 ErrorResult& aRv);
126 // Utilities for working with CSS colors
127 static void RgbToColorName(GlobalObject& aGlobal, uint8_t aR, uint8_t aG,
128 uint8_t aB, nsAString& aResult);
130 // Convert a given CSS color string to rgba. Returns null on failure or an
131 // InspectorRGBATuple on success.
133 // NOTE: Converting a color to RGBA may be lossy when converting from some
134 // formats e.g. CMYK.
135 static void ColorToRGBA(GlobalObject&, const nsACString& aColorString,
136 const Document*,
137 Nullable<InspectorRGBATuple>& aResult);
139 // Check whether a given color is a valid CSS color.
140 static bool IsValidCSSColor(GlobalObject& aGlobal,
141 const nsACString& aColorString);
143 // Utilities for obtaining information about a CSS property.
145 // Get a list of the longhands corresponding to the given CSS property. If
146 // the property is a longhand already, just returns the property itself.
147 // Throws on unsupported property names.
148 static void GetSubpropertiesForCSSProperty(GlobalObject& aGlobal,
149 const nsACString& aProperty,
150 nsTArray<nsString>& aResult,
151 ErrorResult& aRv);
153 // Check whether a given CSS property is a shorthand. Throws on unsupported
154 // property names.
155 static bool CssPropertyIsShorthand(GlobalObject& aGlobal,
156 const nsACString& aProperty,
157 ErrorResult& aRv);
159 // Check whether values of the given type are valid values for the property.
160 // For shorthands, checks whether there's a corresponding longhand property
161 // that accepts values of this type. Throws on unsupported properties or
162 // unknown types.
163 static bool CssPropertySupportsType(GlobalObject& aGlobal,
164 const nsACString& aProperty,
165 InspectorPropertyType, ErrorResult& aRv);
167 static bool Supports(GlobalObject&, const nsACString& aDeclaration,
168 const SupportsOptions&);
170 static bool IsIgnorableWhitespace(GlobalObject& aGlobalObject,
171 CharacterData& aDataNode) {
172 return IsIgnorableWhitespace(aDataNode);
174 static bool IsIgnorableWhitespace(CharacterData& aDataNode);
176 // Returns the "parent" of a node. The parent of a document node is the
177 // frame/iframe containing that document. aShowingAnonymousContent says
178 // whether we are showing anonymous content.
179 static nsINode* GetParentForNode(nsINode& aNode,
180 bool aShowingAnonymousContent);
181 static nsINode* GetParentForNode(GlobalObject& aGlobalObject, nsINode& aNode,
182 bool aShowingAnonymousContent) {
183 return GetParentForNode(aNode, aShowingAnonymousContent);
186 static already_AddRefed<nsINodeList> GetChildrenForNode(
187 GlobalObject& aGlobalObject, nsINode& aNode,
188 bool aShowingAnonymousContent) {
189 return GetChildrenForNode(aNode, aShowingAnonymousContent);
191 static already_AddRefed<nsINodeList> GetChildrenForNode(
192 nsINode& aNode, bool aShowingAnonymousContent);
195 * Setting and removing content state on an element. Both these functions
196 * call EventStateManager::SetContentState internally; the difference is
197 * that for the remove case we simply pass in nullptr for the element.
198 * Use them accordingly.
200 * When removing the active state, you may optionally also clear the active
201 * document as well by setting aClearActiveDocument
203 * @return Returns true if the state was set successfully. See more details
204 * in EventStateManager.h SetContentState.
206 static bool SetContentState(GlobalObject& aGlobal, Element& aElement,
207 uint64_t aState, ErrorResult& aRv);
208 static bool RemoveContentState(GlobalObject& aGlobal, Element& aElement,
209 uint64_t aState, bool aClearActiveDocument,
210 ErrorResult& aRv);
211 static uint64_t GetContentState(GlobalObject& aGlobal, Element& aElement);
213 static void GetUsedFontFaces(GlobalObject& aGlobal, nsRange& aRange,
214 uint32_t aMaxRanges, // max number of ranges to
215 // record for each face
216 bool aSkipCollapsedWhitespace,
217 nsLayoutUtils::UsedFontFaceList& aResult,
218 ErrorResult& aRv);
221 * Get the names of all the supported pseudo-elements.
222 * Pseudo-elements which are only accepted in UA style sheets are
223 * not included.
225 static void GetCSSPseudoElementNames(GlobalObject& aGlobal,
226 nsTArray<nsString>& aResult);
228 // pseudo-class style locking methods. aPseudoClass must be a valid
229 // pseudo-class selector string, e.g. ":hover". ":any-link" and
230 // non-event-state pseudo-classes are ignored. aEnabled sets whether the
231 // psuedo-class should be locked to on or off.
232 static void AddPseudoClassLock(GlobalObject& aGlobal, Element& aElement,
233 const nsAString& aPseudoClass, bool aEnabled);
234 static void RemovePseudoClassLock(GlobalObject& aGlobal, Element& aElement,
235 const nsAString& aPseudoClass);
236 static bool HasPseudoClassLock(GlobalObject& aGlobal, Element& aElement,
237 const nsAString& aPseudoClass);
238 static void ClearPseudoClassLocks(GlobalObject& aGlobal, Element& aElement);
240 static bool IsElementThemed(GlobalObject& aGlobal, Element& aElement);
242 static Element* ContainingBlockOf(GlobalObject&, Element&);
244 MOZ_CAN_RUN_SCRIPT
245 static already_AddRefed<nsINodeList> GetOverflowingChildrenOfElement(
246 GlobalObject& aGlobal, Element& element);
249 * Parse CSS and update the style sheet in place.
251 * @param DOMCSSStyleSheet aSheet
252 * @param UTF8String aInput
253 * The new source string for the style sheet.
255 static void ParseStyleSheet(GlobalObject& aGlobal, StyleSheet& aSheet,
256 const nsACString& aInput, ErrorResult& aRv);
259 * Check if the provided name can be custom element name.
261 static bool IsCustomElementName(GlobalObject&, const nsAString& aName,
262 const nsAString& aNamespaceURI);
265 } // namespace dom
266 } // namespace mozilla
268 #endif // mozilla_dom_InspectorUtils_h