Commit 3f1e8557 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Chromium LUCI CQ

Add a UA style sheet for predefined counter styles

This patch adds a basic UA style sheet for the 'decimal' and 'disc'
counter styles, and plumbs them into RuleSet. This is in preparation to
implement tree-scoped counter style references.

Bug: 687225
Change-Id: If4effec939a2bfdedc5079e95c4c593f622db652
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2574071Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833915}
parent 78556ccd
......@@ -14,6 +14,7 @@
<include name="IDR_UASTYLE_VIEW_SOURCE_CSS" file="../renderer/core/css/view-source.css" type="BINDATA" compress="gzip"/>
<include name="IDR_UASTYLE_THEME_CHROMIUM_ANDROID_CSS" file="../renderer/core/html/resources/android.css" type="BINDATA" compress="gzip"/>
<include name="IDR_UASTYLE_FULLSCREEN_ANDROID_CSS" file="../renderer/core/css/fullscreenAndroid.css" type="BINDATA" compress="gzip"/>
<include name="IDR_UASTYLE_PREDEFINED_COUNTER_STYLES_CSS" file="../renderer/core/css/predefined_counter_styles.css" type="BINDATA" compress="gzip"/>
<include name="IDR_UASTYLE_THEME_CHROMIUM_LINUX_CSS" file="../renderer/core/html/resources/linux.css" type="BINDATA" compress="gzip"/>
<if expr="is_macosx">
<include name="IDR_UASTYLE_THEME_MAC_CSS" file="../renderer/core/html/resources/mac.css" type="BINDATA" compress="gzip"/>
......
......@@ -94,9 +94,16 @@ CSSDefaultStyleSheets::CSSDefaultStyleSheets()
RuntimeEnabledFeatures::ForcedColorsEnabled()
? UncompressResourceAsASCIIString(IDR_UASTYLE_THEME_FORCED_COLORS_CSS)
: String();
// Predefined @counter-style rules
String predefined_counter_styles_sheet =
RuntimeEnabledFeatures::CSSAtRuleCounterStyleEnabled()
? UncompressResourceAsASCIIString(
IDR_UASTYLE_PREDEFINED_COUNTER_STYLES_CSS)
: String();
String default_rules = UncompressResourceAsASCIIString(IDR_UASTYLE_HTML_CSS) +
LayoutTheme::GetTheme().ExtraDefaultStyleSheet() +
forced_colors_style_sheet;
forced_colors_style_sheet +
predefined_counter_styles_sheet;
default_style_sheet_ = ParseUASheet(default_rules);
......
......@@ -945,10 +945,15 @@ StyleRuleCounterStyle* CSSParserImpl::ConsumeCounterStyleRule(
return nullptr;
if (name_token.GetType() != kIdentToken ||
!css_parsing_utils::IsCustomIdent<CSSValueID::kNone, CSSValueID::kDecimal,
CSSValueID::kDisc>(name_token.Id()))
!css_parsing_utils::IsCustomIdent<CSSValueID::kNone>(name_token.Id()))
return nullptr;
if (GetContext()->Mode() != kUASheetMode) {
if (name_token.Id() == CSSValueID::kDecimal ||
name_token.Id() == CSSValueID::kDisc)
return nullptr;
}
AtomicString name(name_token.Value().ToString());
if (observer_) {
......
/*
* Copyright 2020 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* TODO: Add the remaining counter styles */
@counter-style decimal {
system: numeric;
symbols: '0' '1' '2' '3' '4' '5' '6' '7' '8' '9';
}
@counter-style disc {
system: cyclic;
symbols: \2022;
suffix: " ";
}
......@@ -370,6 +370,12 @@ void RuleSet::AddPropertyRule(StyleRuleProperty* rule) {
property_rules_.push_back(rule);
}
void RuleSet::AddCounterStyleRule(StyleRuleCounterStyle* rule) {
EnsurePendingRules(); // So that counter_style_rules_.ShrinkToFit() gets
// called.
counter_style_rules_.push_back(rule);
}
void RuleSet::AddScrollTimelineRule(StyleRuleScrollTimeline* rule) {
EnsurePendingRules(); // So that property_rules_.ShrinkToFit() gets called.
scroll_timeline_rules_.push_back(rule);
......@@ -410,6 +416,9 @@ void RuleSet::AddChildRules(const HeapVector<Member<StyleRuleBase>>& rules,
AddKeyframesRule(keyframes_rule);
} else if (auto* property_rule = DynamicTo<StyleRuleProperty>(rule)) {
AddPropertyRule(property_rule);
} else if (auto* counter_style_rule =
DynamicTo<StyleRuleCounterStyle>(rule)) {
AddCounterStyleRule(counter_style_rule);
} else if (auto* scroll_timeline_rule =
DynamicTo<StyleRuleScrollTimeline>(rule)) {
AddScrollTimelineRule(scroll_timeline_rule);
......@@ -498,6 +507,7 @@ void RuleSet::CompactRules() {
page_rules_.ShrinkToFit();
font_face_rules_.ShrinkToFit();
keyframes_rules_.ShrinkToFit();
counter_style_rules_.ShrinkToFit();
property_rules_.ShrinkToFit();
deep_combinator_or_shadow_pseudo_rules_.ShrinkToFit();
part_pseudo_rules_.ShrinkToFit();
......@@ -540,6 +550,7 @@ void RuleSet::Trace(Visitor* visitor) const {
visitor->Trace(font_face_rules_);
visitor->Trace(keyframes_rules_);
visitor->Trace(property_rules_);
visitor->Trace(counter_style_rules_);
visitor->Trace(scroll_timeline_rules_);
visitor->Trace(deep_combinator_or_shadow_pseudo_rules_);
visitor->Trace(part_pseudo_rules_);
......
......@@ -29,6 +29,7 @@
#include "third_party/blink/renderer/core/css/resolver/media_query_result.h"
#include "third_party/blink/renderer/core/css/rule_feature_set.h"
#include "third_party/blink/renderer/core/css/style_rule.h"
#include "third_party/blink/renderer/core/css/style_rule_counter_style.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_linked_stack.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
......@@ -265,6 +266,9 @@ class CORE_EXPORT RuleSet final : public GarbageCollected<RuleSet> {
const HeapVector<Member<StyleRuleProperty>>& PropertyRules() const {
return property_rules_;
}
const HeapVector<Member<StyleRuleCounterStyle>>& CounterStyleRules() const {
return counter_style_rules_;
}
const HeapVector<Member<StyleRuleScrollTimeline>>& ScrollTimelineRules()
const {
return scroll_timeline_rules_;
......@@ -323,6 +327,7 @@ class CORE_EXPORT RuleSet final : public GarbageCollected<RuleSet> {
void AddKeyframesRule(StyleRuleKeyframes*);
void AddPropertyRule(StyleRuleProperty*);
void AddScrollTimelineRule(StyleRuleScrollTimeline*);
void AddCounterStyleRule(StyleRuleCounterStyle*);
bool MatchMediaForAddRules(const MediaQueryEvaluator& evaluator,
const MediaQuerySet* media_queries);
......@@ -371,6 +376,7 @@ class CORE_EXPORT RuleSet final : public GarbageCollected<RuleSet> {
HeapVector<Member<StyleRuleFontFace>> font_face_rules_;
HeapVector<Member<StyleRuleKeyframes>> keyframes_rules_;
HeapVector<Member<StyleRuleProperty>> property_rules_;
HeapVector<Member<StyleRuleCounterStyle>> counter_style_rules_;
HeapVector<Member<StyleRuleScrollTimeline>> scroll_timeline_rules_;
HeapVector<MinimalRuleData> deep_combinator_or_shadow_pseudo_rules_;
HeapVector<MinimalRuleData> content_pseudo_element_rules_;
......
......@@ -30,6 +30,7 @@
#include "third_party/blink/renderer/core/css/rule_set.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/css/css_default_style_sheets.h"
#include "third_party/blink/renderer/core/css/css_keyframes_rule.h"
#include "third_party/blink/renderer/core/css/css_rule_list.h"
#include "third_party/blink/renderer/core/css/css_test_helpers.h"
......@@ -391,4 +392,14 @@ TEST(RuleSetTest, KeyframesRulesVendorPrefixed) {
EXPECT_FALSE(rule->IsVendorPrefixed());
}
TEST(RuleSetTest, UACounterStyleRules) {
ScopedCSSAtRuleCounterStyleForTest enabled_scope(true);
RuleSet* default_rule_set = CSSDefaultStyleSheets::Instance().DefaultStyle();
ASSERT_TRUE(default_rule_set);
ASSERT_FALSE(default_rule_set->CounterStyleRules().IsEmpty());
EXPECT_EQ("decimal", default_rule_set->CounterStyleRules()[0]->GetName());
}
} // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment