mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1839168 - [devtools] Add InspectorUtils.getAllStyleSheetCSSStyleRules
method. r=emilio.
This method returns a flat list of all the rules in a given stylesheet. This will be helpful for DevTools so we don't have to recursively walk through all the children rules (which is slow on the JS DevTools server). Differential Revision: https://phabricator.services.mozilla.com/D181505
This commit is contained in:
parent
02b6c343ec
commit
b15d728a25
@ -22,6 +22,10 @@ namespace InspectorUtils {
|
||||
unsigned long getRuleColumn(CSSRule rule);
|
||||
unsigned long getRelativeRuleLine(CSSRule rule);
|
||||
boolean hasRulesModifiedByCSSOM(CSSStyleSheet sheet);
|
||||
// Get a flat list of all rules (including nested ones) of a given stylesheet.
|
||||
// Useful for DevTools as this is faster than in JS where we'd have a lot of
|
||||
// proxy access overhead building the same list.
|
||||
sequence<CSSRule> getAllStyleSheetCSSStyleRules(CSSStyleSheet sheet);
|
||||
boolean isInheritedProperty(UTF8String property);
|
||||
sequence<DOMString> getCSSPropertyNames(optional PropertyNamesOptions options = {});
|
||||
sequence<PropertyPref> getCSSPropertyPrefs();
|
||||
|
@ -364,6 +364,23 @@ bool InspectorUtils::HasRulesModifiedByCSSOM(GlobalObject& aGlobal,
|
||||
return aSheet.HasModifiedRulesForDevtools();
|
||||
}
|
||||
|
||||
static void CollectRules(ServoCSSRuleList& aRuleList,
|
||||
nsTArray<RefPtr<css::Rule>>& aResult) {
|
||||
for (uint32_t i = 0, len = aRuleList.Length(); i < len; ++i) {
|
||||
css::Rule* rule = aRuleList.GetRule(i);
|
||||
aResult.AppendElement(rule);
|
||||
if (rule->IsGroupRule()) {
|
||||
CollectRules(*static_cast<css::GroupRule*>(rule)->CssRules(), aResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InspectorUtils::GetAllStyleSheetCSSStyleRules(
|
||||
GlobalObject& aGlobal, StyleSheet& aSheet,
|
||||
nsTArray<RefPtr<css::Rule>>& aResult) {
|
||||
CollectRules(*aSheet.GetCssRulesInternal(), aResult);
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool InspectorUtils::IsInheritedProperty(GlobalObject& aGlobalObject,
|
||||
const nsACString& aPropertyName) {
|
||||
|
@ -75,6 +75,10 @@ class InspectorUtils {
|
||||
static bool HasRulesModifiedByCSSOM(GlobalObject& aGlobal,
|
||||
StyleSheet& aSheet);
|
||||
|
||||
static void GetAllStyleSheetCSSStyleRules(
|
||||
GlobalObject& aGlobal, StyleSheet& aSheet,
|
||||
nsTArray<RefPtr<css::Rule>>& aResult);
|
||||
|
||||
// Utilities for working with CSS properties
|
||||
//
|
||||
// Returns true if the string names a property that is inherited by default.
|
||||
|
@ -44,6 +44,8 @@ class GroupRule : public Rule {
|
||||
GroupRule(const GroupRule&) = delete;
|
||||
bool IsCCLeaf() const override;
|
||||
|
||||
bool IsGroupRule() const final { return true; }
|
||||
|
||||
#ifdef DEBUG
|
||||
void List(FILE* out = stdout, int32_t aIndent = 0) const override;
|
||||
#endif
|
||||
|
@ -58,6 +58,8 @@ class Rule : public nsISupports, public nsWrapperCache {
|
||||
// sense that it doesn't have any outgoing owning edges.
|
||||
virtual bool IsCCLeaf() const MOZ_MUST_OVERRIDE;
|
||||
|
||||
virtual bool IsGroupRule() const { return false; }
|
||||
|
||||
#ifdef DEBUG
|
||||
virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user