Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 66b28324b8b97037caca3b9f1c9d2f724abaaf7d
https://github.com/WebKit/WebKit/commit/66b28324b8b97037caca3b9f1c9d2f724abaaf7d
Author: Darin Adler <[email protected]>
Date: 2023-01-23 (Mon, 23 Jan 2023)
Changed paths:
M Source/WebCore/css/CSSProperties.json
M Source/WebCore/css/StyleProperties.cpp
M Source/WebCore/css/StyleProperties.h
M Source/WebCore/css/StylePropertyShorthand.h
M Source/WebCore/css/parser/CSSPropertyParser.cpp
Log Message:
-----------
Factor out shorthand serialization into its own class
https://bugs.webkit.org/show_bug.cgi?id=250953
rdar://problem/104517006
Reviewed by Oriol Brufau.
Factoring out shorthand serialization into a separate class and breaking it out
of StyleProperties
has a few benefits:
- Moves details of shorthand serialization out of StyleProperties.h; these are
no longer private
members of StyleProperties class.
- Reorganizes shorthand serialization so longhand property values are gathered
during the common
checks. This means we won't repeatedly search style properties for the same
properties.
- Prepares for moving shorthand serialization into a separate file, making
StyleProperties.cpp
a more manageable size.
- Prepares for sharing shorthand serialization with computed style. We don't
need to repeat all
this logic twice the way we do today. However, computed style has a WebKit-only
feature where it
will produce CSS values for shorthands; we have to decide whether to remove
that entirely or at
least remove if for most shorthand properties. Shorthands don't need to be
expressible as CSS
values; they are a parsing and serialization format and don't have a specified
object model.
Also made a small number of other minor improvements to StyleProperties.
* Source/WebCore/css/CSSProperties.json: Reordered the longhands in border,
border-block, and
border-inline so they are in serialization order: width, style, color. The new
serialization code
depends on this, and it's also a logical order.
* Source/WebCore/css/StyleProperties.cpp: Updated the maxShorthandLength
constant, which was
incorrect. It's still a good idea to generate it and we should do that in a
future change.
(WebCore::isCSSWideValueKeyword): Deleted.
(WebCore::isValueIDIncludingList): Removed an unused overload.
(WebCore::serializeLonghandValue): Renamed from
textExpandingInitialValuePlaceholder and moved
the special logic for opacity properties in here. Also added an overload that
takes a pointer.
(WebCore::ShorthandSerializer::commonSerializationChecks): Renamed from
SyleProperties::commonShorthandChecks. Assert length is not zero since
ShorthandSerializer must
only be used for shorthands. Use a boolean return value instead of using empty
string and null
string to express the two different outcomes. Store all the values in
m_longhandValues as we check
them. Also added the m_gridTemplateAreasWasSetFromShorthand logic.
(WebCore::StyleProperties::serializeLonghandValue const): Added. Uses
serializeLonghandValue and
getPropertyCSSValue.
(WebCore::StyleProperties::serializeShorthandValue const): Added. Uses
ShorthandSerializer.
(WebCore::StyleProperties::getPropertyValue const): Use serializeLonghandValue
and
serializeShorthandValue.
(WebCore::ShorthandSerializer::ShorthandSerializer): Added.
(WebCore::ShorthandSerializer::longhandProperty const): Added.
(WebCore::ShorthandSerializer::longhandValue const): Added.
(WebCore::ShorthandSerializer::serializeValue): Added.
(WebCore::ShorthandSerializer::isInitialValue): Added.
(WebCore::ShorthandSerializer::longhandIndex const): Added.
(WebCore::ShorthandSerializer::longhandValueID const): Added.
(WebCore::ShorthandSerializer::serializeLonghandValue const): Added.
(WebCore::ShorthandSerializer::serialize): Added. Moved the large switch
statment from
StyleProperties::getPropertyValue in here. Besides name changes, changed
serialization specifics:
for "all", don't try to find a common value, since the only ones are the
CSS-wide keywords already
handled by the common serialization checks. For border, border-block, and
border-inline, pass in
the size of each section of the shorthand, allowing us to simplify the shared
code. For container,
use serializeLonghandsOmittingTrailingInitialValue. For flex and
perspective-origin, use
serializeLonghands. for transform-origin, use
serializeLonghandsOmittingTrailingInitialValue.
(WebCore::StyleProperties::propertyAsColor const): Use serializeLonghandValue.
(WebCore::ShorthandSerializer::serializeFont const): Get longhand values by
index. Use makeString.
(WebCore::ShorthandSerializer::serializeOffset const): Ditto.
(WebCore::ShorthandSerializer::serializeFontVariant const): Use
serializeLonghandsOmittingInitialValues after doing some additional needed
checks.
(WebCore::ShorthandSerializer::serializeFontSynthesis const): Get longhand
values by index.
Use ASCII literals instead of StringBuilder.
(WebCore::ShorthandSerializer::serializePair const): Get longhand values by
index.
(WebCore::ShorthandSerializer::serializeQuad const): Ditto.
(WebCore::LayerValues::serialize const): Use serializeLonghandValue.
(WebCore::ShorthandSerializer::serializeLayered const): Get longhand values by
index.
(WebCore::ShorthandSerializer::serializeGridTemplate const): Ditto.
(WebCore::gridAutoFlowContains): Argument type is now CSSValue&.
(WebCore::ShorthandSerializer::serializeGrid const): Get longhand values by
index. Use makeString.
(WebCore::ShorthandSerializer::serializeGridRowColumn const): Use
serializeLonghands.
(WebCore::ShorthandSerializer::serializeGridArea const): Ditto.
(WebCore::ShorthandSerializer::serializeLonghands const): Added. This is like
StyleProperties::getShorthandValue was, but does not omit initial values and is
more versatile
since it can be used to serialize only some properties up to a limit. Also use
makeString for
common short lengths.
(WebCore::ShorthandSerializer::serializeLonghandsOmittingInitialValues const):
This is the new
name for StyleProperties::getShorthandValue.
(WebCore::ShorthandSerializer::serializeLonghandsOmittingTrailingInitialValue
const): Added.
Convenient for cases where the last value is optional, but other values are not.
(WebCore::ShorthandSerializer::serializeCommonValue const): Removed unneeded
code to handle
missing longhands; that's checked by commonSerializationChecks. Refactored into
two functions,
so this can be used on a subset of the shorthand or the whole thing.
(WebCore::ShorthandSerializer::serializeBorderImage const): Get longhand values
by index.
(WebCore::ShorthandSerializer::serializeBorderRadius const): Ditto.
(WebCore::ShorthandSerializer::serializeBorder const): Use a new approach where
we serialize
these border-related shorthands by section. Get longhand values by index. Use
serializeCommonValue and subsequentLonghandsHaveInitialValues.
(WebCore::ShorthandSerializer::serializeBreakInside const): Use longhandValueID.
(WebCore::ShorthandSerializer::serializePageBreak const): Ditto.
(WebCore::ShorthandSerializer::serializeColumnBreak const): Ditto.
(WebCore::ShorthandSerializer::subsequentLonghandsHaveInitialValues const):
Replaces
hasAllInitialValues.
(WebCore::MutableStyleProperties::removeShorthandProperty): Added a returnText
argument so we can
implement the return value for shorthands here. Still using a FIXME for this
for now, we'll make
that change separately.
(WebCore::MutableStyleProperties::removePropertyAtIndex): Added. Helps factor
out common
code and give us slightly better efficiency. Also use null string to mean no
result rather
than empty string.
(WebCore::MutableStyleProperties::removeLonghandProperty): Added. Calls
findPropertyIndex and
removePropertyAtIndex.
(WebCore::MutableStyleProperties::removeProperty): Call removeShorthandProperty
and
removeLonghandProperty.
(WebCore::MutableStyleProperties::removeCustomProperty): Call
removePropertyAtIndex.
(WebCore::MutableStyleProperties::setProperty): Removed the unneeded overload
for the case where
the property's value is a property ID. Removed the unneeded call to
removeShorthandProperty
in the overload that takes a CSSProperty that is never called for shorthands,
adding an
assertion to check that invariant.
(WebCore::StyleProperties::asTextInternal const): Use serializeShorthandValue
and
serializeLonghandValue.
(WebCore::MutableStyleProperties::removePropertiesInSet): Use the HashSet::add
function that
takes iterators.
(WebCore::ImmutableStyleProperties::findCustomPropertyIndex const): Take a
StringView instead
of a const String&.
(WebCore::MutableStyleProperties::findCustomPropertyIndex const): Ditto.
(WebCore::MutableStyleProperties::findCSSPropertyWithID): Use nullptr.
(WebCore::MutableStyleProperties::findCustomCSSPropertyWithName): Ditto.
(WebCore::StyleProperties::PropertyReference::cssText const): Use
serializeLonghandValue.
* Source/WebCore/css/StyleProperties.h: Made findPropertyIndex and
findCustomPropertyIndex
public in StyleProperties. There are other functions that work based on the
index in the
interface. Doing this allows ShorthandSerializer to work using only public
functions.
Initialize m_arraySize to 0. Removed unneeded default constructor, most private
functions,
and friend relationship with PropertySetCSSStyleDeclaration. Updated
MutableStyleProperties
functions for changes above.
* Source/WebCore/css/StylePropertyShorthand.h: Removed unneeded
fontShorthandSubpropertiesResetToInitialValues; we now base this on
CSSProperties.json.
Added functions mentioned above.
* Source/WebCore/css/parser/CSSPropertyParser.cpp:
(WebCore::CSSPropertyParser::consumeFont): Set to initial values intead of
explicitly
allocating CSSValueNormal. This may be slightly more efficient and it's
consistent with
other property parsing. Set all properties in a loop, takes care of the
properties
reset to initial values without fontShorthandSubpropertiesResetToInitialValues.
Canonical link: https://commits.webkit.org/259211@main
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes