Bug 1785305: Set Resize Observer's last reported size to -1x-1 initially. r=emilio

It used to be 0x0, but changed per the CSSWG resolution:
https://github.com/w3c/csswg-drafts/issues/3664
Sits behind pref `dom.resize_observer.last_reported_size_invalid`.

Differential Revision: https://phabricator.services.mozilla.com/D155710
This commit is contained in:
David Shin 2022-08-30 17:05:56 +00:00
Родитель 17dc8833aa
Коммит feca6731ff
6 изменённых файлов: 56 добавлений и 23 удалений

Просмотреть файл

@ -168,7 +168,13 @@ ResizeObservation::ResizeObservation(Element& aTarget,
ResizeObserver& aObserver,
ResizeObserverBoxOptions aBox,
WritingMode aWm)
: mTarget(&aTarget), mObserver(&aObserver), mObservedBox(aBox) {
: mTarget(&aTarget),
mObserver(&aObserver),
mObservedBox(aBox),
mLastReportedSize(
aWm, StaticPrefs::dom_resize_observer_last_reported_size_invalid()
? gfx::Size(-1, -1)
: gfx::Size()) {
aTarget.BindObject(mObserver);
}
@ -295,7 +301,8 @@ void ResizeObserver::Observe(Element& aTarget,
observation =
new ResizeObservation(aTarget, *this, aOptions.mBox,
frame ? frame->GetWritingMode() : WritingMode());
if (this == mDocument->GetLastRememberedSizeObserver()) {
if (!StaticPrefs::dom_resize_observer_last_reported_size_invalid() &&
this == mDocument->GetLastRememberedSizeObserver()) {
// Resize observations are initialized with a (0, 0) mLastReportedSize,
// this means that the callback won't be called if the element is 0x0.
// But we need it called for handling the last remembered size, so set

Просмотреть файл

@ -105,8 +105,6 @@ class ResizeObservation final : public LinkedListElement<ResizeObservation> {
// The latest recorded of observed target.
// This will be CSS pixels for border-box/content-box, or device pixels for
// device-pixel-content-box.
// Note: We use default constructor for this because we want to start with a
// (0, 0) size, per the spec.
LogicalPixelSize mLastReportedSize;
};

Просмотреть файл

@ -4581,6 +4581,13 @@
value: 5
mirror: always
# Initialize Resize Observer's last reported size to -1x-1, and not 0x0,
# as per CSSWG resolution: https://github.com/w3c/csswg-drafts/issues/3664
- name: dom.resize_observer.last_reported_size_invalid
type: bool
value: true
mirror: always
#---------------------------------------------------------------------------
# Prefs starting with "editor"
#---------------------------------------------------------------------------

Просмотреть файл

@ -194,19 +194,29 @@ function test5() {
function test6() {
let helper = new ResizeTestHelper(
"test6: inline element does not notify",
"test6: inline element notifies once with 0x0.",
[
{
setup: observer => {
observer.observe(inline);
observer.observe(t1);
t1.style.width = "66px";
},
notify: (entries, observer) => {
assert_equals(entries.length, 1, "observing inline element triggers notification");
assert_equals(entries[0].target, inline, "observing inline element triggers notification");
assert_equals(entries[0].contentRect.width, 0);
assert_equals(entries[0].contentRect.height, 0);
return true; // Delay next step
}
},
{
setup: observer => {
inline.style.width = "66px";
},
notify: (entries, observer) => {
assert_equals(entries.length, 1, "inline elements must not trigger notifications");
assert_equals(entries[0].target, t1, "inline elements must not trigger notifications");
return true; // Delay next step
assert_unreached("resizing inline element should not cause resize notifications");
},
timeout: () => {
// expected
}
},
{ // "inline element that becomes block should notify",
@ -214,7 +224,8 @@ function test6() {
inline.style.display = "block";
},
notify: (entries, observer) => {
assert_equals(entries[0].target, inline);
assert_equals(entries.length, 1, "inline element becoming a non-zero sized block triggers a notification");
assert_equals(entries[0].target, inline, "inline element becoming a non-zero sized block triggers a notification");
}
}
]);

Просмотреть файл

@ -719,16 +719,26 @@ function test16() {
let helper = new ResizeTestHelper(
// See: https://drafts.csswg.org/resize-observer/#intro.
"test16: observations do not fire for non-replaced inline elements",
"test16: observations fire once with 0x0 size for non-replaced inline elements",
[
{
setup: observer => {
observer.observe(t);
},
notify: entries => {
assert_unreached("No observation should fire for non box element")
},
timeout: () => {}
assert_equals(entries.length, 1, "1 pending notification");
assert_equals(entries[0].target, t, "target is t");
assert_equals(entries[0].contentRect.width, 0, "target width");
assert_equals(entries[0].contentRect.height, 0, "target height");
assert_equals(entries[0].contentBoxSize[0].inlineSize, 0,
"target content-box inline size");
assert_equals(entries[0].contentBoxSize[0].blockSize, 0,
"target content-box block size");
assert_equals(entries[0].borderBoxSize[0].inlineSize, 0,
"target border-box inline size");
assert_equals(entries[0].borderBoxSize[0].blockSize, 0,
"target border-box block size");
}
}
]);

Просмотреть файл

@ -345,10 +345,10 @@ function test11() {
observer.observe(view);
},
notify: (entries, observer) => {
assert_unreached("no entries should be observed on <view> Element");
},
timeout: () => {
// expected
assert_equals(entries.length, 1);
assert_equals(entries[0].target, view);
assert_equals(entries[0].contentRect.width, 0);
assert_equals(entries[0].contentRect.height, 0);
}
},
{
@ -356,10 +356,10 @@ function test11() {
observer.observe(stop);
},
notify: (entries, observer) => {
assert_unreached("no entries should be observed on <stop> Element");
},
timeout: () => {
// expected
assert_equals(entries.length, 1);
assert_equals(entries[0].target, stop);
assert_equals(entries[0].contentRect.width, 0);
assert_equals(entries[0].contentRect.height, 0);
}
},
]);