Bug 238661 - Web Inspector: Use computedStyleMap() instead of deprecated getPropertyCSSValue()
Summary: Web Inspector: Use computedStyleMap() instead of deprecated getPropertyCSSVal...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-04-01 02:43 PDT by Carlos Garcia Campos
Modified: 2022-04-08 03:36 PDT (History)
7 users (show)

See Also:


Attachments
Patch (5.66 KB, patch)
2022-04-01 02:45 PDT, Carlos Garcia Campos
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (6.41 KB, patch)
2022-04-07 04:58 PDT, Carlos Garcia Campos
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Garcia Campos 2022-04-01 02:43:40 PDT
.
Comment 1 Carlos Garcia Campos 2022-04-01 02:45:29 PDT
Created attachment 456340 [details]
Patch
Comment 2 Carlos Garcia Campos 2022-04-05 06:46:06 PDT
Ping reviewers.
Comment 3 Devin Rousso 2022-04-05 11:40:46 PDT
Comment on attachment 456340 [details]
Patch

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

Can you please add a comment in the ChangeLog explaining why this is desired/necessary?

> Source/WebKit/WebProcess/Inspector/WebInspectorUI.cpp:65
> +    page.corePage()->settings().setCSSTypedOMEnabled(true);

Since this is not something enabled by default, we should ensure that the frontend doesn't break if this is disabled.  Could we create a helper function that still uses the old behavior if this isn't enabled?  Something like:
```
Object.defineProperty(Element.prototype, "getComputedCSSPropertyNumberValue", {
    value(property) {
        let result = undefined;
        result ??= this.computedStyleMap?.().get(property)?.value;
        result ??= window.getComputedStyle(this).getPropertyCSSValue(property)?.getFloatValue(CSSPrimitiveValue.CSS_PX);
        return result;   
    },
});
```
Comment 4 Carlos Garcia Campos 2022-04-06 00:17:46 PDT
Comment on attachment 456340 [details]
Patch

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

>> Source/WebKit/WebProcess/Inspector/WebInspectorUI.cpp:65
>> +    page.corePage()->settings().setCSSTypedOMEnabled(true);
> 
> Since this is not something enabled by default, we should ensure that the frontend doesn't break if this is disabled.  Could we create a helper function that still uses the old behavior if this isn't enabled?  Something like:
> ```
> Object.defineProperty(Element.prototype, "getComputedCSSPropertyNumberValue", {
>     value(property) {
>         let result = undefined;
>         result ??= this.computedStyleMap?.().get(property)?.value;
>         result ??= window.getComputedStyle(this).getPropertyCSSValue(property)?.getFloatValue(CSSPrimitiveValue.CSS_PX);
>         return result;   
>     },
> });
> ```

Doesn't the setting ensure it's always enabled in the inspector frontend? or do you mean adding the helper instead of changing the setting?
Comment 5 Devin Rousso 2022-04-06 00:44:43 PDT
Comment on attachment 456340 [details]
Patch

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

>>> Source/WebKit/WebProcess/Inspector/WebInspectorUI.cpp:65
>>> +    page.corePage()->settings().setCSSTypedOMEnabled(true);
>> 
>> Since this is not something enabled by default, we should ensure that the frontend doesn't break if this is disabled.  Could we create a helper function that still uses the old behavior if this isn't enabled?  Something like:
>> ```
>> Object.defineProperty(Element.prototype, "getComputedCSSPropertyNumberValue", {
>>     value(property) {
>>         let result = undefined;
>>         result ??= this.computedStyleMap?.().get(property)?.value;
>>         result ??= window.getComputedStyle(this).getPropertyCSSValue(property)?.getFloatValue(CSSPrimitiveValue.CSS_PX);
>>         return result;   
>>     },
>> });
>> ```
> 
> Doesn't the setting ensure it's always enabled in the inspector frontend? or do you mean adding the helper instead of changing the setting?

Oh sorry I wasn't entirely clear.  This relies on *both* the setting and `ENABLE_CSS_TYPED_OM`.  I was more concerned with about if `ENABLE_CSS_TYPED_OM` is not enabled (for whatever reason).  If/When the build flag is removed, then we can remove the fallback code.
Comment 6 Carlos Garcia Campos 2022-04-06 01:03:59 PDT
(In reply to Devin Rousso from comment #5)
> Comment on attachment 456340 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=456340&action=review
> 
> >>> Source/WebKit/WebProcess/Inspector/WebInspectorUI.cpp:65
> >>> +    page.corePage()->settings().setCSSTypedOMEnabled(true);
> >> 
> >> Since this is not something enabled by default, we should ensure that the frontend doesn't break if this is disabled.  Could we create a helper function that still uses the old behavior if this isn't enabled?  Something like:
> >> ```
> >> Object.defineProperty(Element.prototype, "getComputedCSSPropertyNumberValue", {
> >>     value(property) {
> >>         let result = undefined;
> >>         result ??= this.computedStyleMap?.().get(property)?.value;
> >>         result ??= window.getComputedStyle(this).getPropertyCSSValue(property)?.getFloatValue(CSSPrimitiveValue.CSS_PX);
> >>         return result;   
> >>     },
> >> });
> >> ```
> > 
> > Doesn't the setting ensure it's always enabled in the inspector frontend? or do you mean adding the helper instead of changing the setting?
> 
> Oh sorry I wasn't entirely clear.  This relies on *both* the setting and
> `ENABLE_CSS_TYPED_OM`.  I was more concerned with about if
> `ENABLE_CSS_TYPED_OM` is not enabled (for whatever reason).  If/When the
> build flag is removed, then we can remove the fallback code.

I'm not familiar with xcode build system, but I think CSS_TYPED_OM is enabled unconditionally in PlatformEnableCocoa.h (or can that be overridden with xcode magic?). And I enabled it by default for GTK and WPE ports too.
Comment 7 Devin Rousso 2022-04-06 12:56:26 PDT
Comment on attachment 456340 [details]
Patch

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

>>>>> Source/WebKit/WebProcess/Inspector/WebInspectorUI.cpp:65
>>>>> +    page.corePage()->settings().setCSSTypedOMEnabled(true);
>>>> 
>>>> Since this is not something enabled by default, we should ensure that the frontend doesn't break if this is disabled.  Could we create a helper function that still uses the old behavior if this isn't enabled?  Something like:
>>>> ```
>>>> Object.defineProperty(Element.prototype, "getComputedCSSPropertyNumberValue", {
>>>>     value(property) {
>>>>         let result = undefined;
>>>>         result ??= this.computedStyleMap?.().get(property)?.value;
>>>>         result ??= window.getComputedStyle(this).getPropertyCSSValue(property)?.getFloatValue(CSSPrimitiveValue.CSS_PX);
>>>>         return result;   
>>>>     },
>>>> });
>>>> ```
>>> 
>>> Doesn't the setting ensure it's always enabled in the inspector frontend? or do you mean adding the helper instead of changing the setting?
>> 
>> Oh sorry I wasn't entirely clear.  This relies on *both* the setting and `ENABLE_CSS_TYPED_OM`.  I was more concerned with about if `ENABLE_CSS_TYPED_OM` is not enabled (for whatever reason).  If/When the build flag is removed, then we can remove the fallback code.
> 
> I'm not familiar with xcode build system, but I think CSS_TYPED_OM is enabled unconditionally in PlatformEnableCocoa.h (or can that be overridden with xcode magic?). And I enabled it by default for GTK and WPE ports too.

Yes, but on cocoa platforms that's predicated by `#if !defined(ENABLE_CSS_TYPED_OM)`.  I admit it's probably unlikely that some build system would override this, but in the off chance that something does I'd hate for Web Inspector to be broken in that situation.  We do something similar for other things that are guarded by flags (e.g. `WebGLRenderingContext`, `indexedDB`, etc.), just in case :)
Comment 8 Carlos Garcia Campos 2022-04-07 04:58:22 PDT
Created attachment 456910 [details]
Patch
Comment 9 Devin Rousso 2022-04-07 12:16:43 PDT
Comment on attachment 456910 [details]
Patch

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

r=me, thanks!

> Source/WebInspectorUI/ChangeLog:8
> +        * UserInterface/Base/Utilities.js:

Can you add some explanation as to why this change is needed/desired?  Would be helpful for future engineers who may encounter this change and wonder why it was made :)
Comment 10 Radar WebKit Bug Importer 2022-04-08 02:44:14 PDT
<rdar://problem/91472876>
Comment 11 Carlos Garcia Campos 2022-04-08 03:23:56 PDT
Committed r292597 (249430@trunk): <https://commits.webkit.org/249430@trunk>