Skip to content
Permalink
Browse files
Implement the CSS4 'revert' keyword.
https://bugs.webkit.org/show_bug.cgi?id=149702

Reviewed by Simon Fraser.

Source/WebCore:

Added new tests in fast/css and fast/css/variables.

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:
Add CSSRevertValue to the project and makefiles.

* css/CSSParser.cpp:
(WebCore::parseKeywordValue):
Make sure to handle "revert" in the keyword parsing path (along with inherit/initial/unset).

(WebCore::CSSParser::parseValue):
(WebCore::CSSParser::parseCustomPropertyDeclaration):
At the parser level, "revert" is just like inherit/initial/unset and gets its own special
singleton value, CSSRevertValue.

* css/CSSRevertValue.cpp: Added.
(WebCore::CSSRevertValue::customCSSText):
* css/CSSRevertValue.h: Added.
(WebCore::CSSRevertValue::create):
(WebCore::CSSRevertValue::equals):
(WebCore::CSSRevertValue::CSSRevertValue):
This value is identical to the inherit/initial/unset values, i.e., its own special value
that can be used to indicate a revert when doing style resolution.

* css/CSSValue.cpp:
(WebCore::CSSValue::cssValueType):
(WebCore::CSSValue::equals):
(WebCore::CSSValue::cssText):
(WebCore::CSSValue::destroy):
* css/CSSValue.h:
(WebCore::CSSValue::isInheritedValue):
(WebCore::CSSValue::isInitialValue):
(WebCore::CSSValue::isUnsetValue):
(WebCore::CSSValue::isRevertValue):
Add the RevertClass to CSSValue and make sure it is handled in all the appropriate methods.

* css/CSSValueKeywords.in:
Add the "revert" keyword to the list of allowed CSS keywords.

* css/CSSValuePool.cpp:
(WebCore::CSSValuePool::CSSValuePool):
* css/CSSValuePool.h:
(WebCore::CSSValuePool::createRevertValue):
Add support for a CSSRevertValue singleton, just like inherit/unset/initial.

* css/FontLoader.cpp:
(WebCore::FontLoader::resolveFontStyle):
Add "unset" and "revert" as special keywords to be ignored. This code seems to be turned off,
but patching it anyway.

* css/SelectorChecker.h:
Add a MatchDefault value of 0 to the LinkMatchMask. This enables it to be used as an index
to the correct value in Property (in the style resolution code).

* css/StyleResolver.cpp:
(WebCore::StyleResolver::State::initForStyleResolve):
Delete any lingering old CascadedProperty rollbacks for UA/user rules.

(WebCore::StyleResolver::styleForKeyframe):
(WebCore::StyleResolver::styleForPage):
(WebCore::StyleResolver::applyMatchedProperties):
Pass along the MatchResult as an additional parameter, since we need it to lazily compute
the cascade rollbacks if the "revert" keyword is encountered.

(WebCore::StyleResolver::cascadedPropertiesForRollback):
This method will lazily create and return a new CascadedProperties pointer that is cached
in the StyleResolver's state. This will contain only UA rules (for user reverts) and UA/user
rules (for author reverts). These will only be computed at most once for a given element
when doing a reversion, and they will be computed lazily, i.e., only if a revert is
requested.

(WebCore::StyleResolver::applyProperty):
Pass along the LinkMatchMask and the MatchResult to applyProperty. This way we know specifically
which link type we were computing if we have to revert (so that we roll back and look at the
same index in the reverted version). The MatchResult is passed along because it is needed
to build the CascadedProperties rollbacks.

The basic idea is that if a revert is encountered, the level that the rule came from is
checked. If it is UA level, just treat as "unset." If it is author or user level, get
the correct CascadedProperties rollback and repeat the applyProperty using the property
found in the rollback. If the property is not present in the cascade rollback, then the
revert becomes an unset.

(WebCore::StyleResolver::CascadedProperties::hasCustomProperty):
(WebCore::StyleResolver::CascadedProperties::customProperty):
Helpers used by applyProperty to check on custom properties, since they can revert too
just like a regular property can.

(WebCore::StyleResolver::CascadedProperties::setPropertyInternal):
(WebCore::StyleResolver::CascadedProperties::set):
(WebCore::StyleResolver::CascadedProperties::setDeferred):
Passing along the CascadeLevel (UA, User, Author) so that it can be stored in the Property.
This way when we do property application, we always know where the rule came from so
that the reversion can be handled properly.

(WebCore::StyleResolver::CascadedProperties::addStyleProperties):
(WebCore::cascadeLevelForIndex):
(WebCore::StyleResolver::CascadedProperties::addMatches):
When style properties are added, also figure out the CascadeLevel and pass it along to be
stored in the Property. We use the MatchResult's ranges to know where a property comes from.

(WebCore::StyleResolver::CascadedProperties::applyDeferredProperties):
(WebCore::StyleResolver::CascadedProperties::Property::apply):
(WebCore::StyleResolver::applyCascadedProperties):
Pass along the MatchResult so we know how to build the rollback.

* css/StyleResolver.h:
(WebCore::StyleResolver::State::cascadeLevel):
(WebCore::StyleResolver::State::setCascadeLevel):
(WebCore::StyleResolver::State::authorRollback):
(WebCore::StyleResolver::State::userRollback):
(WebCore::StyleResolver::State::setAuthorRollback):
(WebCore::StyleResolver::State::setUserRollback):
(WebCore::StyleResolver::state):
(WebCore::StyleResolver::cascadeLevel):
(WebCore::StyleResolver::setCascadeLevel):
Move CascadedProperties into the header. Add CascadeLevel to Property. Add the level and
rollbacks to the resolver's state.

LayoutTests:

* fast/css/all-keyword-revert-expected.html: Added.
* fast/css/all-keyword-revert.html: Added.
* fast/css/revert-color-expected.html: Added.
* fast/css/revert-color.html: Added.
* fast/css/revert-margins-expected.html: Added.
* fast/css/revert-margins.html: Added.
* fast/css/variables/all-keyword-revert-expected.html: Added.
* fast/css/variables/all-keyword-revert.html: Added.
* fast/css/variables/revert-inheritance-expected.html: Added.
* fast/css/variables/revert-inheritance.html: Added.
* fast/css/variables/revert-no-inheritance-expected.html: Added.
* fast/css/variables/revert-no-inheritance.html: Added.
* fast/css/variables/revert-variable-reference-expected.html: Added.
* fast/css/variables/revert-variable-reference.html: Added.



Canonical link: https://commits.webkit.org/168422@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@191252 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
David Hyatt committed Oct 17, 2015
1 parent edb6ec1 commit cf8d8c634240332708da495511e22b5a547660b6
Showing 31 changed files with 725 additions and 96 deletions.
@@ -1,3 +1,25 @@
2015-10-17 David Hyatt <hyatt@apple.com>

Implement the CSS4 'revert' keyword.
https://bugs.webkit.org/show_bug.cgi?id=149702

Reviewed by Simon Fraser.

* fast/css/all-keyword-revert-expected.html: Added.
* fast/css/all-keyword-revert.html: Added.
* fast/css/revert-color-expected.html: Added.
* fast/css/revert-color.html: Added.
* fast/css/revert-margins-expected.html: Added.
* fast/css/revert-margins.html: Added.
* fast/css/variables/all-keyword-revert-expected.html: Added.
* fast/css/variables/all-keyword-revert.html: Added.
* fast/css/variables/revert-inheritance-expected.html: Added.
* fast/css/variables/revert-inheritance.html: Added.
* fast/css/variables/revert-no-inheritance-expected.html: Added.
* fast/css/variables/revert-no-inheritance.html: Added.
* fast/css/variables/revert-variable-reference-expected.html: Added.
* fast/css/variables/revert-variable-reference.html: Added.

2015-10-17 Myles C. Maxfield <mmaxfield@apple.com>

Delete FontPlatformData::allowsLigatures()
@@ -0,0 +1,11 @@
<head>
<style>
html {
font-size: small;
background-color: #F0F0F0;
color: blue;
}
</style>
</head>
<body>
<blockquote id="quote">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</blockquote> Phasellus eget velit sagittis.
@@ -0,0 +1,18 @@
<head>
<style>
html {
font-size: small;
background-color: #F0F0F0;
color: blue;
}

blockquote {
display:inline;
background-color: skyblue;
color: red;
all: revert;
}
</style>
</head>
<body>
<blockquote id="quote">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</blockquote> Phasellus eget velit sagittis.
@@ -0,0 +1,16 @@
<head>
<style>
html {
font-size: small;
background-color: #F0F0F0;
color: blue;
}

blockquote { background-color: skyblue; }

</style>
</head>
<body>
<blockquote>This text should be blue.</blockquote>
</body>
</html>
@@ -0,0 +1,19 @@
<head>
<style>
html {
font-size: small;
background-color: #F0F0F0;
color: blue;
}

blockquote {
background-color: skyblue;
color: red;
color: revert;
}
</style>
</head>
<body>
<blockquote id="quote">This text should be blue.</blockquote>
</body>
</html>
@@ -0,0 +1,14 @@
<head>
<style>
blockquote {
margin-top:0;
margin-bottom:0;
border:1px solid black;
}
</style>
</head>
<body>
<blockquote id="quote">This blockquote should have user agent margins for the left and right but the top and bottom margins should be 0.</blockquote>
<blockquote id="quote">This blockquote should have user agent margins for the left and right but the top and bottom margins should be 0.</blockquote>
</body>
</html>
@@ -0,0 +1,15 @@
<head>
<style>
blockquote {
margin:0;
margin-right:revert;
margin-left:revert;
border:1px solid black;
}
</style>
</head>
<body>
<blockquote id="quote">This blockquote should have user agent margins for the left and right but the top and bottom margins should be 0.</blockquote>
<blockquote id="quote">This blockquote should have user agent margins for the left and right but the top and bottom margins should be 0.</blockquote>
</body>
</html>
@@ -0,0 +1,11 @@
<head>
<style>
html {
font-size: small;
background-color: #F0F0F0;
color: blue;
}
</style>
</head>
<body>
<span id="quote">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span> Phasellus eget velit sagittis.
@@ -0,0 +1,19 @@
<head>
<title>Test of failed variable lookup because of "revert" on a custom property causing all to reset everything.</title>
<style>
html {
font-size: small;
background-color: #F0F0F0;
color: blue;
--a: revert;
}

blockquote {
background-color: skyblue;
color: red;
all: var(--a);
}
</style>
</head>
<body>
<blockquote id="quote">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</blockquote> Phasellus eget velit sagittis.
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
--><html><head><title>CSS Reftest Reference</title>
<link href="mailto:cam@mcc.id.au" rel="author" title="Cameron McCormack">
<style>
p {
color: green;
}
</style>
</head><body><p>This text must be green.</p>
</body></html>
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
--><html><head><title>CSS Test: Test declaring a variable whose value is "revert" where there is a variable to inherit from.</title>
<style>
body {
--a: green;
color: crimson;
}
p {
color: red;
}
p {
color: orange;
--a: revert;
color: var(--a);
}
</style>
</head><body><p>This text must be green.</p>
</body></html>
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
--><html><head><title>CSS Reftest Reference</title>
<link href="mailto:cam@mcc.id.au" rel="author" title="Cameron McCormack">
<style>
p {
color: green;
}
</style>
</head><body><p>This text must be green.</p>
</body></html>
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
--><html><head><title>CSS Test: Test declaring a variable whose value is "revert" where there is no variable to inherit from.</title>
<style>
p {
color: red;
}
p {
color: orange;
--a: revert;
color: var(--a,green);
}
</style>
</head><body><p>This text must be green.</p>
</body></html>
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
--><html><head><title>CSS Reftest Reference</title>
<link href="mailto:cam@mcc.id.au" rel="author" title="Cameron McCormack">
<style>
p {
color: green;
}
</style>
</head><body><p>This text must be green.</p>
</body></html>
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
--><html><head><title>CSS Test: Test declaring a variable whose value consists of a reference to a variable whose value is "revert".</title>
<style>
body {
--b: green;
color: red;
}
p {
color: orange;
--a: var(--b);
--b: revert;
color: var(--a);
}
</style>
</head><body><p>This text must be green.</p>
</body></html>
@@ -1338,6 +1338,7 @@ set(WebCore_SOURCES
css/CSSProperty.cpp
css/CSSPropertySourceData.cpp
css/CSSReflectValue.cpp
css/CSSRevertValue.cpp
css/CSSRule.cpp
css/CSSRuleList.cpp
css/CSSSegmentedFontFace.cpp

0 comments on commit cf8d8c6

Please sign in to comment.