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

Implement custom 'negative' values for @counter-style

Bug: 687225
Change-Id: I92de1e68336d49393ae7609e745cfbd749c0db7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2585904Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835917}
parent 4afef7bd
...@@ -237,6 +237,15 @@ CounterStyle::CounterStyle(const StyleRuleCounterStyle& rule) ...@@ -237,6 +237,15 @@ CounterStyle::CounterStyle(const StyleRuleCounterStyle& rule)
} }
} }
if (const CSSValue* negative = rule.GetNegative()) {
if (const CSSValuePair* pair = DynamicTo<CSSValuePair>(negative)) {
negative_prefix_ = SymbolToString(pair->First());
negative_suffix_ = SymbolToString(pair->Second());
} else {
negative_prefix_ = SymbolToString(*negative);
}
}
// TODO(crbug.com/687225): Implement and populate other fields. // TODO(crbug.com/687225): Implement and populate other fields.
} }
...@@ -255,6 +264,11 @@ void CounterStyle::ResolveExtends(const CounterStyle& extended) { ...@@ -255,6 +264,11 @@ void CounterStyle::ResolveExtends(const CounterStyle& extended) {
if (system_ == CounterStyleSystem::kAdditive) if (system_ == CounterStyleSystem::kAdditive)
additive_weights_ = extended.additive_weights_; additive_weights_ = extended.additive_weights_;
if (!style_rule_->GetNegative()) {
negative_prefix_ = extended.negative_prefix_;
negative_suffix_ = extended.negative_suffix_;
}
// TODO(crbug.com/687225): Implement and populate other fields. // TODO(crbug.com/687225): Implement and populate other fields.
} }
...@@ -322,12 +336,14 @@ String CounterStyle::GenerateRepresentation(int value) const { ...@@ -322,12 +336,14 @@ String CounterStyle::GenerateRepresentation(int value) const {
return fallback_style_->GenerateRepresentation(value); return fallback_style_->GenerateRepresentation(value);
} }
// TODO(crbug.com/687225): Implement non-default 'pad' and 'negative' values. // TODO(crbug.com/687225): Implement non-default 'pad' value.
StringBuilder result; StringBuilder result;
if (NeedsNegativeSign(value)) if (NeedsNegativeSign(value))
result.Append("-"); result.Append(negative_prefix_);
result.Append(initial_representation); result.Append(initial_representation);
if (NeedsNegativeSign(value))
result.Append(negative_suffix_);
return result.ToString(); return result.ToString();
} }
......
...@@ -97,6 +97,9 @@ class CORE_EXPORT CounterStyle final : public GarbageCollected<CounterStyle> { ...@@ -97,6 +97,9 @@ class CORE_EXPORT CounterStyle final : public GarbageCollected<CounterStyle> {
// Additive weights, for the 'additive' system only. // Additive weights, for the 'additive' system only.
Vector<wtf_size_t> additive_weights_; Vector<wtf_size_t> additive_weights_;
String negative_prefix_ = "-";
String negative_suffix_;
friend class CounterStyleMapTest; friend class CounterStyleMapTest;
}; };
......
...@@ -176,4 +176,34 @@ TEST_F(CounterStyleTest, CyclicFallback) { ...@@ -176,4 +176,34 @@ TEST_F(CounterStyleTest, CyclicFallback) {
EXPECT_EQ("6", foo.GenerateRepresentation(6)); EXPECT_EQ("6", foo.GenerateRepresentation(6));
} }
TEST_F(CounterStyleTest, CustomNegative) {
InsertStyleElement(R"CSS(
@counter-style financial-decimal {
system: extends decimal;
negative: '(' ')';
}
@counter-style extended {
system: extends financial-decimal;
}
)CSS");
UpdateAllLifecyclePhasesForTest();
// Getting custom 'negative' directly from descriptor value.
const CounterStyle& financial_decimal = GetCounterStyle("financial-decimal");
EXPECT_EQ("(999)", financial_decimal.GenerateRepresentation(-999));
EXPECT_EQ("(1)", financial_decimal.GenerateRepresentation(-1));
EXPECT_EQ("0", financial_decimal.GenerateRepresentation(0));
EXPECT_EQ("1", financial_decimal.GenerateRepresentation(1));
EXPECT_EQ("99", financial_decimal.GenerateRepresentation(99));
// Getting custom 'negative' indirectly by extending a counter style.
const CounterStyle& extended = GetCounterStyle("extended");
EXPECT_EQ("(999)", extended.GenerateRepresentation(-999));
EXPECT_EQ("(1)", extended.GenerateRepresentation(-1));
EXPECT_EQ("0", extended.GenerateRepresentation(0));
EXPECT_EQ("1", extended.GenerateRepresentation(1));
EXPECT_EQ("99", extended.GenerateRepresentation(99));
}
} // namespace blink } // 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