summaryrefslogtreecommitdiffstats
path: root/layout/inspector/InspectorUtils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'layout/inspector/InspectorUtils.cpp')
-rw-r--r--layout/inspector/InspectorUtils.cpp93
1 files changed, 82 insertions, 11 deletions
diff --git a/layout/inspector/InspectorUtils.cpp b/layout/inspector/InspectorUtils.cpp
index e2111aa9bd..f1886a0dd0 100644
--- a/layout/inspector/InspectorUtils.cpp
+++ b/layout/inspector/InspectorUtils.cpp
@@ -351,9 +351,7 @@ uint32_t InspectorUtils::GetRelativeRuleLine(GlobalObject& aGlobal,
return aRule.GetLineNumber() + 1;
}
-
-void InspectorUtils::GetRuleIndex(GlobalObject& aGlobal,
- css::Rule& aRule,
+void InspectorUtils::GetRuleIndex(GlobalObject& aGlobal, css::Rule& aRule,
nsTArray<uint32_t>& aResult) {
css::Rule* currentRule = &aRule;
@@ -401,21 +399,56 @@ 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) {
+static uint32_t CollectAtRules(ServoCSSRuleList& aRuleList,
+ Sequence<OwningNonNull<css::Rule>>& aResult) {
+ uint32_t len = aRuleList.Length();
+ uint32_t ruleCount = len;
+ for (uint32_t i = 0; i < len; ++i) {
css::Rule* rule = aRuleList.GetRule(i);
- aResult.AppendElement(rule);
+ // This collect rules we want to display in Devtools Style Editor toolbar.
+ // When adding a new StyleCssRuleType, put it in the "default" list, and
+ // file a new bug with
+ // https://bugzilla.mozilla.org/enter_bug.cgi?product=DevTools&component=Style%20Editor&short_desc=Consider%20displaying%20new%20XXX%20rule%20type%20in%20at-rules%20sidebar
+ // so the DevTools team gets notified and can decide if it should be
+ // displayed.
+ switch (rule->Type()) {
+ case StyleCssRuleType::Media:
+ case StyleCssRuleType::Supports:
+ case StyleCssRuleType::LayerBlock:
+ case StyleCssRuleType::Container: {
+ Unused << aResult.AppendElement(OwningNonNull(*rule), fallible);
+ break;
+ }
+ case StyleCssRuleType::Style:
+ case StyleCssRuleType::Import:
+ case StyleCssRuleType::Document:
+ case StyleCssRuleType::LayerStatement:
+ case StyleCssRuleType::FontFace:
+ case StyleCssRuleType::Page:
+ case StyleCssRuleType::Property:
+ case StyleCssRuleType::Keyframes:
+ case StyleCssRuleType::Keyframe:
+ case StyleCssRuleType::Margin:
+ case StyleCssRuleType::Namespace:
+ case StyleCssRuleType::CounterStyle:
+ case StyleCssRuleType::FontFeatureValues:
+ case StyleCssRuleType::FontPaletteValues:
+ break;
+ }
+
if (rule->IsGroupRule()) {
- CollectRules(*static_cast<css::GroupRule*>(rule)->CssRules(), aResult);
+ ruleCount += CollectAtRules(
+ *static_cast<css::GroupRule*>(rule)->CssRules(), aResult);
}
}
+ return ruleCount;
}
-void InspectorUtils::GetAllStyleSheetCSSStyleRules(
+void InspectorUtils::GetStyleSheetRuleCountAndAtRules(
GlobalObject& aGlobal, StyleSheet& aSheet,
- nsTArray<RefPtr<css::Rule>>& aResult) {
- CollectRules(*aSheet.GetCssRulesInternal(), aResult);
+ InspectorStyleSheetRuleCountAndAtRulesResult& aResult) {
+ aResult.mRuleCount =
+ CollectAtRules(*aSheet.GetCssRulesInternal(), aResult.mAtRules);
}
/* static */
@@ -602,6 +635,26 @@ void InspectorUtils::ColorToRGBA(GlobalObject&, const nsACString& aColorString,
}
/* static */
+void InspectorUtils::ColorTo(GlobalObject&, const nsACString& aFromColor,
+ const nsACString& aToColorSpace,
+ Nullable<InspectorColorToResult>& aResult) {
+ nsCString resultColor;
+ nsTArray<float> resultComponents;
+ bool resultAdjusted = false;
+
+ if (!ServoCSSParser::ColorTo(aFromColor, aToColorSpace, &resultColor,
+ &resultComponents, &resultAdjusted)) {
+ aResult.SetNull();
+ return;
+ }
+
+ auto& result = aResult.SetValue();
+ result.mColor.AssignASCII(resultColor);
+ result.mComponents = std::move(resultComponents);
+ result.mAdjusted = resultAdjusted;
+}
+
+/* static */
bool InspectorUtils::IsValidCSSColor(GlobalObject& aGlobalObject,
const nsACString& aColorString) {
return ServoCSSParser::IsValidCSSColor(aColorString);
@@ -946,5 +999,23 @@ void InspectorUtils::GetCSSRegisteredProperties(
}
}
+/* static */
+void InspectorUtils::GetRuleBodyTextOffsets(
+ GlobalObject&, const nsACString& aInitialText,
+ Nullable<InspectorGetRuleBodyTextResult>& aResult) {
+ uint32_t resultStartOffset;
+ uint32_t resultEndOffset;
+
+ if (!Servo_GetRuleBodyTextOffsets(&aInitialText, &resultStartOffset,
+ &resultEndOffset)) {
+ aResult.SetNull();
+ return;
+ }
+
+ InspectorGetRuleBodyTextResult& offsets = aResult.SetValue();
+ offsets.mStartOffset = resultStartOffset;
+ offsets.mEndOffset = resultEndOffset;
+}
+
} // namespace dom
} // namespace mozilla