-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing CounterStyle representation from StyleRuleCounterStyle #7114
Merged
webkit-early-warning-system
merged 1 commit into
WebKit:main
from
vitorroriz:eng/Implement-representation-for-CounterStyle-translated-from-StyleRuleCounterStyle
Jan 4, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/* | ||
* Copyright (C) 2022 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "config.h" | ||
#include "CSSCounterStyle.h" | ||
|
||
#include "CSSCounterStyleDescriptors.h" | ||
#include "CSSCounterStyleRule.h" | ||
#include "CSSPrimitiveValue.h" | ||
#include "CSSValuePair.h" | ||
|
||
namespace WebCore { | ||
|
||
String CSSCounterStyle::counterForSystemCyclic(int) | ||
{ | ||
// FIXME: implement counter for system rdar://103648354 | ||
return ""_s; | ||
} | ||
String CSSCounterStyle::counterForSystemFixed(int) | ||
{ | ||
// FIXME: implement counter for system rdar://103648354 | ||
return ""_s; | ||
} | ||
String CSSCounterStyle::counterForSystemSymbolic(int) | ||
{ | ||
// FIXME: implement counter for system rdar://103648354 | ||
return ""_s; | ||
} | ||
String CSSCounterStyle::counterForSystemAlphabetic(int) | ||
{ | ||
// FIXME: implement counter for system rdar://103648354 | ||
return ""_s; | ||
} | ||
String CSSCounterStyle::counterForSystemNumeric(int) | ||
{ | ||
// FIXME: implement counter for system rdar://103648354 | ||
return ""_s; | ||
} | ||
String CSSCounterStyle::counterForSystemAdditive(int) | ||
{ | ||
// FIXME: implement counter for system rdar://103648354 | ||
return ""_s; | ||
} | ||
String CSSCounterStyle::initialRepresentation(int) | ||
{ | ||
// FIXME: implement counter initial representation rdar://103648354 | ||
return ""_s; | ||
} | ||
String CSSCounterStyle::text(int value) | ||
{ | ||
// FIXME: implement text representation for CounterStyle rdar://103648354. | ||
return String::number(value); | ||
} | ||
bool CSSCounterStyle::isInRange(int value) const | ||
{ | ||
if (isAutoRange()) { | ||
switch (system()) { | ||
case CSSCounterStyleDescriptors::System::Cyclic: | ||
case CSSCounterStyleDescriptors::System::Numeric: | ||
case CSSCounterStyleDescriptors::System::Fixed: | ||
return true; | ||
case CSSCounterStyleDescriptors::System::Alphabetic: | ||
case CSSCounterStyleDescriptors::System::Symbolic: | ||
return value >= 1; | ||
case CSSCounterStyleDescriptors::System::Additive: | ||
return value >= 0; | ||
case CSSCounterStyleDescriptors::System::Extends: | ||
ASSERT_NOT_REACHED(); | ||
return true; | ||
} | ||
} | ||
|
||
for (const auto& [lowerBound, higherBound] : ranges()) { | ||
if (value >= lowerBound && value <= higherBound) | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
CSSCounterStyle::CSSCounterStyle(const CSSCounterStyleDescriptors& descriptors, bool isPredefinedCounterStyle) | ||
: m_descriptors { descriptors }, | ||
m_predefinedCounterStyle { isPredefinedCounterStyle } | ||
{ | ||
} | ||
|
||
Ref<CSSCounterStyle> CSSCounterStyle::create(const CSSCounterStyleDescriptors& descriptors, bool isPredefinedCounterStyle) | ||
{ | ||
return adoptRef(*new CSSCounterStyle(descriptors, isPredefinedCounterStyle)); | ||
} | ||
|
||
Ref<CSSCounterStyle> CSSCounterStyle::createCounterStyleDecimal() | ||
{ | ||
Vector<CSSCounterStyleDescriptors::Symbol> symbols { "0"_s, "1"_s, "2"_s, "3"_s, "4"_s, "5"_s, "6"_s, "7"_s, "8"_s, "9"_s }; | ||
CSSCounterStyleDescriptors descriptors { | ||
.m_name = "decimal"_s, | ||
.m_system = CSSCounterStyleDescriptors::System::Numeric, | ||
.m_negativeSymbols = { }, | ||
.m_prefix = { }, | ||
.m_suffix = { }, | ||
.m_ranges = { }, | ||
.m_pad = { }, | ||
.m_fallbackName = { }, | ||
.m_symbols = WTFMove(symbols), | ||
.m_additiveSymbols = { }, | ||
.m_speakAs = CSSCounterStyleDescriptors::SpeakAs::Auto, | ||
.m_extendsName = { }, | ||
.m_fixedSystemFirstSymbolValue = 0, | ||
.m_explicitlySetDescriptors = { } | ||
}; | ||
return adoptRef(*new CSSCounterStyle(descriptors, true)); | ||
} | ||
|
||
void CSSCounterStyle::setFallbackReference(RefPtr<CSSCounterStyle>&& fallback) | ||
{ | ||
m_fallbackReference = WeakPtr { fallback }; | ||
} | ||
|
||
// The counter's system value is promoted to the value of the counter we are extending. | ||
void CSSCounterStyle::extendAndResolve(const CSSCounterStyle& extendedCounterStyle) | ||
{ | ||
m_isExtendedUnresolved = false; | ||
|
||
setSystem(extendedCounterStyle.system()); | ||
|
||
if (!explicitlySetDescriptors().contains(CSSCounterStyleDescriptors::ExplicitlySetDescriptors::Negative)) | ||
setNegative(extendedCounterStyle.negative()); | ||
if (!explicitlySetDescriptors().contains(CSSCounterStyleDescriptors::ExplicitlySetDescriptors::Prefix)) | ||
setPrefix(extendedCounterStyle.prefix()); | ||
if (!explicitlySetDescriptors().contains(CSSCounterStyleDescriptors::ExplicitlySetDescriptors::Suffix)) | ||
setSuffix(extendedCounterStyle.suffix()); | ||
if (!explicitlySetDescriptors().contains(CSSCounterStyleDescriptors::ExplicitlySetDescriptors::Range)) | ||
setRanges(extendedCounterStyle.ranges()); | ||
if (!explicitlySetDescriptors().contains(CSSCounterStyleDescriptors::ExplicitlySetDescriptors::Pad)) | ||
setPad(extendedCounterStyle.pad()); | ||
if (!explicitlySetDescriptors().contains(CSSCounterStyleDescriptors::ExplicitlySetDescriptors::Fallback)) { | ||
setFallbackName(extendedCounterStyle.fallbackName()); | ||
m_fallbackReference = extendedCounterStyle.m_fallbackReference; | ||
} | ||
if (!explicitlySetDescriptors().contains(CSSCounterStyleDescriptors::ExplicitlySetDescriptors::Symbols)) | ||
setSymbols(extendedCounterStyle.symbols()); | ||
if (!explicitlySetDescriptors().contains(CSSCounterStyleDescriptors::ExplicitlySetDescriptors::AdditiveSymbols)) | ||
setAdditiveSymbols(extendedCounterStyle.additiveSymbols()); | ||
if (!explicitlySetDescriptors().contains(CSSCounterStyleDescriptors::ExplicitlySetDescriptors::SpeakAs)) | ||
setSpeakAs(extendedCounterStyle.speakAs()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Copyright (C) 2022 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "CSSCounterStyleDescriptors.h" | ||
#include <wtf/Forward.h> | ||
#include <wtf/text/AtomString.h> | ||
|
||
namespace WebCore { | ||
|
||
class StyleRuleCounterStyle; | ||
|
||
class CSSCounterStyle : public RefCounted<CSSCounterStyle>, public CanMakeWeakPtr<CSSCounterStyle> { | ||
public: | ||
static Ref<CSSCounterStyle> create(const CSSCounterStyleDescriptors&, bool isPredefinedCounterStyle); | ||
static Ref<CSSCounterStyle> createCounterStyleDecimal(); | ||
|
||
bool operator==(const CSSCounterStyle& other) const | ||
{ | ||
return m_descriptors == other.m_descriptors | ||
&& m_predefinedCounterStyle == other.m_predefinedCounterStyle; | ||
} | ||
|
||
String text(int); | ||
const CSSCounterStyleDescriptors::Name& name() const { return m_descriptors.m_name; } | ||
CSSCounterStyleDescriptors::System system() const { return m_descriptors.m_system; } | ||
const CSSCounterStyleDescriptors::NegativeSymbols& negative() const { return m_descriptors.m_negativeSymbols; } | ||
const CSSCounterStyleDescriptors::Symbol& prefix() const { return m_descriptors.m_prefix; } | ||
const CSSCounterStyleDescriptors::Symbol& suffix() const { return m_descriptors.m_suffix; } | ||
const CSSCounterStyleDescriptors::Ranges& ranges() const { return m_descriptors.m_ranges; } | ||
const CSSCounterStyleDescriptors::Pad& pad() const { return m_descriptors.m_pad; } | ||
const CSSCounterStyleDescriptors::Name& fallbackName() const { return m_descriptors.m_fallbackName; } | ||
const Vector<CSSCounterStyleDescriptors::Symbol>& symbols() const { return m_descriptors.m_symbols; } | ||
const CSSCounterStyleDescriptors::AdditiveSymbols& additiveSymbols() const { return m_descriptors.m_additiveSymbols; } | ||
CSSCounterStyleDescriptors::SpeakAs speakAs() const { return m_descriptors.m_speakAs; } | ||
const CSSCounterStyleDescriptors::Name extendsName() const { return m_descriptors.m_extendsName; } | ||
int firstSymbolValueForFixedSystem() const { return m_descriptors.m_fixedSystemFirstSymbolValue; } | ||
const OptionSet<CSSCounterStyleDescriptors::ExplicitlySetDescriptors>& explicitlySetDescriptors() const { return m_descriptors.m_explicitlySetDescriptors; } | ||
|
||
void setSystem(CSSCounterStyleDescriptors::System system) { m_descriptors.m_system = system; } | ||
void setNegative(const CSSCounterStyleDescriptors::NegativeSymbols& negative) { m_descriptors.m_negativeSymbols = negative; } | ||
void setPrefix(const CSSCounterStyleDescriptors::Symbol& prefix) { m_descriptors.m_prefix = prefix; } | ||
void setSuffix(const CSSCounterStyleDescriptors::Symbol& suffix) { m_descriptors.m_suffix = suffix; } | ||
void setRanges(const CSSCounterStyleDescriptors::Ranges& ranges) { m_descriptors.m_ranges = ranges; } | ||
void setPad(const CSSCounterStyleDescriptors::Pad& pad) { m_descriptors.m_pad = pad; } | ||
void setFallbackName(const CSSCounterStyleDescriptors::Name& fallbackName) { m_descriptors.m_fallbackName = fallbackName; } | ||
void setSymbols(const Vector<CSSCounterStyleDescriptors::Symbol>& symbols) { m_descriptors.m_symbols = symbols; } | ||
void setAdditiveSymbols(const CSSCounterStyleDescriptors::AdditiveSymbols& additiveSymbols) { m_descriptors.m_additiveSymbols = additiveSymbols; } | ||
void setSpeakAs(CSSCounterStyleDescriptors::SpeakAs speakAs) { m_descriptors.m_speakAs = speakAs; } | ||
|
||
void setFallbackReference(RefPtr<CSSCounterStyle>&&); | ||
bool isFallbackUnresolved() { return !m_fallbackReference; } | ||
bool isExtendsUnresolved() { return m_isExtendedUnresolved; }; | ||
bool isExtendsSystem() const { return system() == CSSCounterStyleDescriptors::System::Extends; } | ||
void extendAndResolve(const CSSCounterStyle&); | ||
private: | ||
CSSCounterStyle(const CSSCounterStyleDescriptors&, bool isPredefinedCounterStyle); | ||
|
||
// https://www.w3.org/TR/css-counter-styles-3/#counter-style-range | ||
bool isInRange(int) const; | ||
// https://www.w3.org/TR/css-counter-styles-3/#counter-style-negative | ||
bool usesNegativeSign(); | ||
bool shouldApplyNegativeSymbols(int); | ||
// https://www.w3.org/TR/css-counter-styles-3/#counter-style-fallback | ||
Ref<CSSCounterStyle> fallback(); | ||
// Generates a CounterStyle object as it was defined by a 'decimal' descriptor. It is used as a last-resource in case we can't resolve fallback references. | ||
void applyPadSymbols(String&); | ||
void applyNegativeSymbols(String&); | ||
// Initial text representation for the counter, before applying pad and/or negative symbols. Suffix and Prefix are also not considered as described by https://www.w3.org/TR/css-counter-styles-3/#counter-styles. | ||
String initialRepresentation(int); | ||
|
||
String counterForSystemCyclic(int); | ||
String counterForSystemFixed(int); | ||
String counterForSystemSymbolic(int); | ||
String counterForSystemAlphabetic(int); | ||
String counterForSystemNumeric(int); | ||
String counterForSystemAdditive(int); | ||
|
||
bool isPredefinedCounterStyle() const { return m_predefinedCounterStyle; } | ||
bool isAutoRange() const { return ranges().isEmpty(); } | ||
|
||
// Fixed and Extends system can/must have extra data in the system descriptor (https://www.w3.org/TR/css-counter-styles-3/#fixed-system and https://www.w3.org/TR/css-counter-styles-3/#extends-system). | ||
void extractDataFromSystemDescriptor(const StyleRuleCounterStyle&); | ||
|
||
CSSCounterStyleDescriptors m_descriptors; | ||
bool m_predefinedCounterStyle { false }; | ||
CSSCounterStyleDescriptors::Name m_fallbackName; | ||
WeakPtr<const CSSCounterStyle> m_fallbackReference { nullptr }; | ||
WeakPtr<const CSSCounterStyle> m_extendsReference { nullptr }; | ||
bool m_isFallingBack { false }; | ||
bool m_isExtendedUnresolved { true }; | ||
}; | ||
} // namespace WebCore |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are declared but not defined. It would be nicer to at least add stubs.