diff --git a/dom/base/ResizeObserver.cpp b/dom/base/ResizeObserver.cpp index 0b7bf9afe5cd..a1fb0ce6daf1 100644 --- a/dom/base/ResizeObserver.cpp +++ b/dom/base/ResizeObserver.cpp @@ -11,7 +11,6 @@ #include "mozilla/SVGUtils.h" #include "nsIContent.h" #include "nsIContentInlines.h" -#include "nsIScrollableFrame.h" #include namespace mozilla::dom { @@ -46,14 +45,6 @@ static uint32_t GetNodeDepth(nsINode* aNode) { return depth; } -static nsSize GetContentRectSize(const nsIFrame& aFrame) { - if (const nsIScrollableFrame* f = do_QueryFrame(&aFrame)) { - // We return the scrollport rect for compat with other UAs, see bug 1733042. - return f->GetScrollPortRect().Size(); - } - return aFrame.GetContentRectRelativeToSelf().Size(); -} - /** * Returns |aTarget|'s size in the form of gfx::Size (in pixels). * If the target is SVG, width and height are determined from bounding box. @@ -84,42 +75,47 @@ static gfx::Size CalculateBoxSize(Element* aTarget, const LayoutDeviceIntSize snappedSize = RoundedToInt(CSSSize::FromUnknownSize(size) * frame->PresContext()->CSSToDevPixelScale()); - return gfx::Size(snappedSize.ToUnknownSize()); + size = gfx::Size(snappedSize.ToUnknownSize()); + } + } else { + // Per the spec, non-replaced inline Elements will always have an empty + // content rect. Therefore, we always use the same trivially-empty size + // for non-replaced inline elements here, and their IsActive() will + // always return false. (So its observation won't be fired.) + if (!frame->IsFrameOfType(nsIFrame::eReplaced) && + frame->IsFrameOfType(nsIFrame::eLineParticipant)) { + return size; + } + + switch (aBox) { + case ResizeObserverBoxOptions::Border_box: + // GetSize() includes the content area, borders, and padding. + size = CSSPixel::FromAppUnits(frame->GetSize()).ToUnknownSize(); + break; + case ResizeObserverBoxOptions::Device_pixel_content_box: { + // This is a implementation-dependent for subpixel snapping algorithm. + // Gecko relys on LayoutDevicePixel to convert (and snap) the app units + // into device pixels in painting and gfx code, so here we simply + // convert it into dev pixels and round it. + // + // Note: This size must contain integer values. + // https://drafts.csswg.org/resize-observer/#dom-resizeobserverboxoptions-device-pixel-content-box + const LayoutDeviceIntSize snappedSize = + LayoutDevicePixel::FromAppUnitsRounded( + frame->GetContentRectRelativeToSelf().Size(), + frame->PresContext()->AppUnitsPerDevPixel()); + size = gfx::Size(snappedSize.ToUnknownSize()); + break; + } + case ResizeObserverBoxOptions::Content_box: + default: + size = + CSSPixel::FromAppUnits(frame->GetContentRectRelativeToSelf().Size()) + .ToUnknownSize(); } - return size; } - // Per the spec, non-replaced inline Elements will always have an empty - // content rect. Therefore, we always use the same trivially-empty size - // for non-replaced inline elements here, and their IsActive() will - // always return false. (So its observation won't be fired.) - if (!frame->IsFrameOfType(nsIFrame::eReplaced) && - frame->IsFrameOfType(nsIFrame::eLineParticipant)) { - return size; - } - - switch (aBox) { - case ResizeObserverBoxOptions::Border_box: - return CSSPixel::FromAppUnits(frame->GetSize()).ToUnknownSize(); - case ResizeObserverBoxOptions::Device_pixel_content_box: { - // This is a implementation-dependent for subpixel snapping algorithm. - // Gecko relies on LayoutDevicePixel to convert (and snap) the app units - // into device pixels in painting and gfx code, so here we simply - // convert it into dev pixels and round it. - // - // Note: This size must contain integer values. - // https://drafts.csswg.org/resize-observer/#dom-resizeobserverboxoptions-device-pixel-content-box - const LayoutDeviceIntSize snappedSize = - LayoutDevicePixel::FromAppUnitsRounded( - GetContentRectSize(*frame), - frame->PresContext()->AppUnitsPerDevPixel()); - return gfx::Size(snappedSize.ToUnknownSize()); - } - case ResizeObserverBoxOptions::Content_box: - default: - break; - } - return CSSPixel::FromAppUnits(GetContentRectSize(*frame)).ToUnknownSize(); + return size; } NS_IMPL_CYCLE_COLLECTION_CLASS(ResizeObservation) diff --git a/testing/web-platform/tests/resize-observer/scrollbars.html b/testing/web-platform/tests/resize-observer/scrollbars.html deleted file mode 100644 index 129e74e5cd96..000000000000 --- a/testing/web-platform/tests/resize-observer/scrollbars.html +++ /dev/null @@ -1,56 +0,0 @@ - -ResizeObserver content-box size and scrollbars - - - - -
-
-
-