Bug 1803094 Comment 8 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

(In reply to Emilio Cobos Álvarez (:emilio) from comment #7)
> Shouldn't changing the resolution trigger the media feature change as well?

I may be wrong. It may not be caused by a different resolution. I tried to debug more:

I just realize the image select algorithm use [`ResponsiveImageSelector::ComputeFinalWidthForCurrentViewport()`](https://searchfox.org/mozilla-central/rev/9b8ebf06145feeccf34dc126cf45b07e86556392/dom/base/ResponsiveImageSelector.cpp#415-416) to get the computed width from the styleset and use this value to select the image.

So in the current implementation, our sync call of [`mDocument->NotifyMediaFeatureValuesChanged()`](https://searchfox.org/mozilla-central/rev/9b8ebf06145feeccf34dc126cf45b07e86556392/layout/base/nsPresContext.cpp#1887) in `nsPresContext::MediaFeatureValuesChanged()` happens just when creating a new preshell. And I notice its [`computedWidth`](https://searchfox.org/mozilla-central/rev/9b8ebf06145feeccf34dc126cf45b07e86556392/dom/base/ResponsiveImageSelector.cpp#359-360) is `0` at this moment, per my attached test case. So the image select algorithm uses an incorrect candidate density.

If we call `mDocument->NotifyMediaFeatureValuesChanged()` in `nsPresContext::FlushPendingMediaFeatureValuesChanged()` (just like what our previous implementation did), its `effectWidth` is a valid value (e.g. 720 in my attached test case), so the candidate density is correct and we choose the correct source.
(In reply to Emilio Cobos Álvarez (:emilio) from comment #7)
> Shouldn't changing the resolution trigger the media feature change as well?

I may be wrong. It may not be caused by a different resolution. I tried to debug more:

I just realize the image select algorithm use [`ResponsiveImageSelector::ComputeFinalWidthForCurrentViewport()`](https://searchfox.org/mozilla-central/rev/9b8ebf06145feeccf34dc126cf45b07e86556392/dom/base/ResponsiveImageSelector.cpp#415-416) to get the computed width from the styleset and use this value to select the image.

So in the current implementation, our sync call of [`mDocument->NotifyMediaFeatureValuesChanged()`](https://searchfox.org/mozilla-central/rev/9b8ebf06145feeccf34dc126cf45b07e86556392/layout/base/nsPresContext.cpp#1887) in `nsPresContext::MediaFeatureValuesChanged()` happens just when creating a new preshell. And I notice its [`computedWidth`](https://searchfox.org/mozilla-central/rev/9b8ebf06145feeccf34dc126cf45b07e86556392/dom/base/ResponsiveImageSelector.cpp#359-360) is `0` at this moment, per my attached test case. So the image select algorithm uses an incorrect candidate density.

If we call `mDocument->NotifyMediaFeatureValuesChanged()` in `nsPresContext::FlushPendingMediaFeatureValuesChanged()` (just like what our previous implementation did), its `computedWidth` is a valid value (e.g. 720 in my attached test case), so the candidate density is correct and we choose the correct source.

Back to Bug 1803094 Comment 8