diff options
author | Moonchild <moonchild@palemoon.org> | 2023-10-14 14:16:26 +0200 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2023-10-14 14:16:26 +0200 |
commit | 4df8e7664af00cc7d12edbd1b75be95f1a10cc8a (patch) | |
tree | a30a7c88822effa6f85ec110a910e6992d333a52 | |
parent | cdfd243b5ab6848fe169e6aef426d953b296ffbd (diff) | |
download | uxp-4df8e7664af00cc7d12edbd1b75be95f1a10cc8a.tar.gz |
Issue #2340 - Return an array (actually frozen sequence) for {border|content}BoxSize
Resolves #2340
-rw-r--r-- | dom/base/ResizeObserver.cpp | 24 | ||||
-rw-r--r-- | dom/base/ResizeObserver.h | 10 | ||||
-rw-r--r-- | dom/webidl/ResizeObserver.webidl | 8 |
3 files changed, 33 insertions, 9 deletions
diff --git a/dom/base/ResizeObserver.cpp b/dom/base/ResizeObserver.cpp index 51fd603217..ca25c06e43 100644 --- a/dom/base/ResizeObserver.cpp +++ b/dom/base/ResizeObserver.cpp @@ -303,6 +303,30 @@ ResizeObserverEntry::Constructor(const GlobalObject& aGlobal, return observerEntry.forget(); } +void ResizeObserverEntry::GetBorderBoxSize( + nsTArray<RefPtr<ResizeObserverSize>>& aRetVal) const { + // In the resize-observer-1 spec, there will only be a single + // ResizeObserverSize returned in the FrozenArray. + // + // Note: the usage of FrozenArray is to support elements that have multiple + // fragments, which occur in multi-column scenarios. See: + // https://drafts.csswg.org/resize-observer/#resize-observer-entry-interface + aRetVal.Clear(); + aRetVal.AppendElement(mBorderBoxSize); +} + +void ResizeObserverEntry::GetContentBoxSize( + nsTArray<RefPtr<ResizeObserverSize>>& aRetVal) const { + // In the resize-observer-1 spec, there will only be a single + // ResizeObserverSize returned in the FrozenArray. + // + // Note: the usage of FrozenArray is to support elements that have multiple + // fragments, which occur in multi-column scenarios. + // https://drafts.csswg.org/resize-observer/#resize-observer-entry-interface + aRetVal.Clear(); + aRetVal.AppendElement(mContentBoxSize); +} + void ResizeObserverEntry::SetBorderBoxSize(const nsSize& aSize) { nsIFrame* frame = mTarget->GetPrimaryFrame(); diff --git a/dom/base/ResizeObserver.h b/dom/base/ResizeObserver.h index 56675693ce..ca87a080b4 100644 --- a/dom/base/ResizeObserver.h +++ b/dom/base/ResizeObserver.h @@ -163,14 +163,10 @@ public: /** * Returns target's logical border-box size and content-box size as - * ResizeObserverSize. + * a ResizeObserverSize array. */ - ResizeObserverSize* BorderBoxSize() const { - return mBorderBoxSize; - } - ResizeObserverSize* ContentBoxSize() const { - return mContentBoxSize; - } + void GetBorderBoxSize(nsTArray<RefPtr<ResizeObserverSize>>& aRetVal) const; + void GetContentBoxSize(nsTArray<RefPtr<ResizeObserverSize>>& aRetVal) const; // Set borderBoxSize. void SetBorderBoxSize(const nsSize& aSize); diff --git a/dom/webidl/ResizeObserver.webidl b/dom/webidl/ResizeObserver.webidl index d764af7cbd..c1286d66a7 100644 --- a/dom/webidl/ResizeObserver.webidl +++ b/dom/webidl/ResizeObserver.webidl @@ -34,8 +34,12 @@ callback ResizeObserverCallback = void (sequence<ResizeObserverEntry> entries, R interface ResizeObserverEntry {
readonly attribute Element target;
readonly attribute DOMRectReadOnly? contentRect;
- readonly attribute ResizeObserverSize borderBoxSize;
- readonly attribute ResizeObserverSize contentBoxSize;
+ // We are using a [Pure, Cached, Frozen] sequence since `FrozenArray` is not implemented in webidl.
+ // This is functionally similar enough. As of #2340 Mozilla has not implemented this yet, either.
+ [Frozen, Cached, Pure]
+ readonly attribute sequence<ResizeObserverSize> borderBoxSize;
+ [Frozen, Cached, Pure]
+ readonly attribute sequence<ResizeObserverSize> contentBoxSize;
};
[Pref="layout.css.resizeobserver.enabled"]
|