Bug 226810

Summary: Parse attributes' HTML length values by HTMLDimension
Product: WebKit Reporter: cathiechen <cathiechen>
Component: DOMAssignee: cathiechen <cathiechen>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, changseok, darin, esprehn+autocc, ews-watchlist, gyuyoung.kim, koivisto, rbuis, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=226469
Attachments:
Description Flags
Patch
none
Patch none

Description cathiechen 2021-06-09 02:52:52 PDT
`addHTMLLengthToStyle()` is using CSS parser to get the values. We should reuse `parseHTMLDimension()` here.
Comment 1 cathiechen 2021-06-10 04:08:23 PDT
Created attachment 431060 [details]
Patch
Comment 2 cathiechen 2021-06-10 07:25:21 PDT
Comment on attachment 431060 [details]
Patch

Hi,
I think this patch is ready for review now:)
It applies HTMLDimension to other length parsing scenarios.
Please take a look, thanks!
Comment 3 Darin Adler 2021-06-10 14:07:24 PDT
Comment on attachment 431060 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=431060&action=review

> Source/WebCore/html/HTMLElement.cpp:1019
> +void HTMLElement::addHTMLLengthToStyleWithConfigs(MutableStyleProperties& style, CSSPropertyID propertyID, const String& value, AllowPercentage allowPercentage, UseCSSPXAsUnitType useCSSPX, IsMultiLength isMultiLengh)

Typo here in isMultiLengh

Not thrilled with the word "configs" here. I think the function name doesn’t have to change just because we have three more arguments; it can just be an overload. Think of the arguments as having default values.

> Source/WebCore/html/HTMLElement.h:155
> +    enum class AllowPercentage : bool { No, Yes };
> +    enum class UseCSSPXAsUnitType : bool { No, Yes };
> +    enum class IsMultiLength : bool { No, Yes };
> +    void addHTMLLengthToStyleWithConfigs(MutableStyleProperties&, CSSPropertyID, const String& value, AllowPercentage, UseCSSPXAsUnitType, IsMultiLength);

These all can and should be private instead of protected. Also not sure that these options are best represented as three separate booleans, but if we make that private it’s easy to change it later.

This function should take a StringView, not a const String&.

> Source/WebCore/html/HTMLElement.h:159
>      void addHTMLLengthToStyle(MutableStyleProperties&, CSSPropertyID, const String& value);
> +    void addHTMLMultiLengthToStyle(MutableStyleProperties&, CSSPropertyID, const String& value);
> +    void addHTMLPixelsToStyle(MutableStyleProperties&, CSSPropertyID, const String& value);
> +    void addHTMLNumberToStyle(MutableStyleProperties&, CSSPropertyID, const String& value);

These functions should take StringView, not const String&.
Comment 4 cathiechen 2021-06-11 08:23:35 PDT
Comment on attachment 431060 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=431060&action=review

Hi Darin,
Thanks for the review!

>> Source/WebCore/html/HTMLElement.cpp:1019
>> +void HTMLElement::addHTMLLengthToStyleWithConfigs(MutableStyleProperties& style, CSSPropertyID propertyID, const String& value, AllowPercentage allowPercentage, UseCSSPXAsUnitType useCSSPX, IsMultiLength isMultiLengh)
> 
> Typo here in isMultiLengh
> 
> Not thrilled with the word "configs" here. I think the function name doesn’t have to change just because we have three more arguments; it can just be an overload. Think of the arguments as having default values.

Got it! Done, thanks!

>> Source/WebCore/html/HTMLElement.h:155
>> +    void addHTMLLengthToStyleWithConfigs(MutableStyleProperties&, CSSPropertyID, const String& value, AllowPercentage, UseCSSPXAsUnitType, IsMultiLength);
> 
> These all can and should be private instead of protected. Also not sure that these options are best represented as three separate booleans, but if we make that private it’s easy to change it later.
> 
> This function should take a StringView, not a const String&.

Done!

>> Source/WebCore/html/HTMLElement.h:159
>> +    void addHTMLNumberToStyle(MutableStyleProperties&, CSSPropertyID, const String& value);
> 
> These functions should take StringView, not const String&.

Ah, done, thanks!
Comment 5 cathiechen 2021-06-11 08:37:33 PDT
Created attachment 431198 [details]
Patch
Comment 6 EWS 2021-06-11 10:41:25 PDT
Committed r278765 (238725@main): <https://commits.webkit.org/238725@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 431198 [details].
Comment 7 Radar WebKit Bug Importer 2021-06-11 10:42:20 PDT
<rdar://problem/79205778>