diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 2d744434a271..31fc077ef723 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -2522,7 +2522,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(Document) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOnloadBlocker) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLazyLoadImageObserver) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLazyLoadImageObserverViewport) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLastRememberedSizeObserver) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMImplementation) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mImageMaps) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOrientationPendingPromise) @@ -2642,7 +2641,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Document) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDisplayDocument) NS_IMPL_CYCLE_COLLECTION_UNLINK(mLazyLoadImageObserver) NS_IMPL_CYCLE_COLLECTION_UNLINK(mLazyLoadImageObserverViewport) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mLastRememberedSizeObserver) NS_IMPL_CYCLE_COLLECTION_UNLINK(mFontFaceSet) NS_IMPL_CYCLE_COLLECTION_UNLINK(mReadyForIdle) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocumentL10n) @@ -15792,27 +15790,6 @@ void Document::IncLazyLoadImageReachViewport(bool aLoading) { } } -ResizeObserver& Document::EnsureLastRememberedSizeObserver() { - if (!mLastRememberedSizeObserver) { - mLastRememberedSizeObserver = - ResizeObserver::CreateLastRememberedSizeObserver(*this); - } - return *mLastRememberedSizeObserver; -} - -void Document::ObserveForLastRememberedSize(Element& aElement) { - // Options are initialized with ResizeObserverBoxOptions::Content_box by - // default, which is what we want. - static ResizeObserverOptions options; - EnsureLastRememberedSizeObserver().Observe(aElement, options); -} - -void Document::UnobserveForLastRememberedSize(Element& aElement) { - if (mLastRememberedSizeObserver) { - mLastRememberedSizeObserver->Unobserve(aElement); - } -} - void Document::NotifyLayerManagerRecreated() { NotifyActivityChanged(); EnumerateSubDocuments([](Document& aSubDoc) { diff --git a/dom/base/Document.h b/dom/base/Document.h index 41a5ece69fc8..94ee97b9b51b 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -3755,13 +3755,6 @@ class Document : public nsINode, void IncLazyLoadImageStarted() { ++mLazyLoadImageStarted; } void IncLazyLoadImageReachViewport(bool aLoading); - ResizeObserver* GetLastRememberedSizeObserver() { - return mLastRememberedSizeObserver; - } - ResizeObserver& EnsureLastRememberedSizeObserver(); - void ObserveForLastRememberedSize(Element&); - void UnobserveForLastRememberedSize(Element&); - // Dispatch a runnable related to the document. nsresult Dispatch(TaskCategory aCategory, already_AddRefed&& aRunnable) final; @@ -5127,10 +5120,6 @@ class Document : public nsINode, // Used to measure how effective the lazyload thresholds are. RefPtr mLazyLoadImageObserverViewport; - // ResizeObserver for storing and removing the last remembered size. - // @see {@link https://drafts.csswg.org/css-sizing-4/#last-remembered} - RefPtr mLastRememberedSizeObserver; - // Stack of top layer elements. nsTArray mTopLayer; diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 0c63fb51985e..29a03a193f3a 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -482,26 +482,6 @@ void Element::SetShadowRoot(ShadowRoot* aShadowRoot) { slots->mShadowRoot = aShadowRoot; } -void Element::SetLastRememberedBSize(float aBSize) { - ExtendedDOMSlots()->mLastRememberedBSize = Some(aBSize); -} - -void Element::SetLastRememberedISize(float aISize) { - ExtendedDOMSlots()->mLastRememberedISize = Some(aISize); -} - -void Element::RemoveLastRememberedBSize() { - if (nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots()) { - slots->mLastRememberedBSize.reset(); - } -} - -void Element::RemoveLastRememberedISize() { - if (nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots()) { - slots->mLastRememberedISize.reset(); - } -} - void Element::Blur(mozilla::ErrorResult& aError) { if (!ShouldBlur(this)) { return; diff --git a/dom/base/Element.h b/dom/base/Element.h index 88cb069fdfa2..bd4c2bb35984 100644 --- a/dom/base/Element.h +++ b/dom/base/Element.h @@ -298,11 +298,6 @@ class Element : public FragmentOrElement { */ void SetShadowRoot(ShadowRoot* aShadowRoot); - void SetLastRememberedBSize(float aBSize); - void SetLastRememberedISize(float aISize); - void RemoveLastRememberedBSize(); - void RemoveLastRememberedISize(); - /** * Make focus on this element. */ @@ -1316,21 +1311,6 @@ class Element : public FragmentOrElement { return slots ? slots->mShadowRoot.get() : nullptr; } - const Maybe GetLastRememberedBSize() const { - const nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots(); - return slots ? slots->mLastRememberedBSize : Nothing(); - } - const Maybe GetLastRememberedISize() const { - const nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots(); - return slots ? slots->mLastRememberedISize : Nothing(); - } - bool HasLastRememberedBSize() const { - return GetLastRememberedBSize().isSome(); - } - bool HasLastRememberedISize() const { - return GetLastRememberedISize().isSome(); - } - private: // DO NOT USE THIS FUNCTION directly in C++. This function is supposed to be // called from JS. Use PresShell::ScrollContentIntoView instead. diff --git a/dom/base/FragmentOrElement.h b/dom/base/FragmentOrElement.h index b3b1fbef01da..512e7022826e 100644 --- a/dom/base/FragmentOrElement.h +++ b/dom/base/FragmentOrElement.h @@ -197,13 +197,6 @@ class FragmentOrElement : public nsIContent { * Web components custom element data. */ UniquePtr mCustomElementData; - - /** - * Last remembered size (in CSS pixels) for the element. - * @see {@link https://drafts.csswg.org/css-sizing-4/#last-remembered} - */ - Maybe mLastRememberedBSize; - Maybe mLastRememberedISize; }; class nsDOMSlots : public nsIContent::nsContentSlots { diff --git a/dom/base/ResizeObserver.cpp b/dom/base/ResizeObserver.cpp index 477aa2828a91..b1a11915b0fd 100644 --- a/dom/base/ResizeObserver.cpp +++ b/dom/base/ResizeObserver.cpp @@ -202,23 +202,14 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(ResizeObserver) NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(ResizeObserver) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ResizeObserver) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner, mDocument, mActiveTargets, - mObservationMap); - if (tmp->mCallback.is>()) { - ImplCycleCollectionTraverse( - cb, tmp->mCallback.as>(), "mCallback", - 0); - } + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner, mDocument, mCallback, + mActiveTargets, mObservationMap); NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ResizeObserver) tmp->Disconnect(); - NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner, mDocument, mActiveTargets, + NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner, mDocument, mCallback, mActiveTargets, mObservationMap); - if (tmp->mCallback.is>()) { - ImplCycleCollectionUnlink( - tmp->mCallback.as>()); - } NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER NS_IMPL_CYCLE_COLLECTION_UNLINK_END @@ -229,14 +220,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ResizeObserver) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END -ResizeObserver::ResizeObserver(Document& aDocument, NativeCallback aCallback) - : mOwner(aDocument.GetInnerWindow()), - mDocument(&aDocument), - mCallback(aCallback) { - MOZ_ASSERT(mOwner, "Need a non-null owner window"); - MOZ_ASSERT(mDocument == mOwner->GetExtantDoc()); -} - already_AddRefed ResizeObserver::Constructor( const GlobalObject& aGlobal, ResizeObserverCallback& aCb, ErrorResult& aRv) { @@ -295,18 +278,6 @@ void ResizeObserver::Observe(Element& aTarget, observation = new ResizeObservation(aTarget, *this, aOptions.mBox, frame ? frame->GetWritingMode() : WritingMode()); - if (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 - // mLastReportedSize to an invalid size to ensure IsActive() is true - // for the current element size. - // See https://github.com/w3c/csswg-drafts/issues/3664 about doing this in - // the general case, then we won't need this hack for the last remembered - // size, and will have consistency with IntersectionObserver. - observation->UpdateLastReportedSize(gfx::Size(-1, -1)); - MOZ_ASSERT(observation->IsActive()); - } mObservationList.insertBack(observation); // Per the spec, we need to trigger notification in event loop that @@ -412,13 +383,8 @@ uint32_t ResizeObserver::BroadcastActiveObservations() { } } - if (mCallback.is>()) { - RefPtr callback( - mCallback.as>()); - callback->Call(this, entries, *this); - } else { - mCallback.as()(entries, *this); - } + RefPtr callback(mCallback); + callback->Call(this, entries, *this); mActiveTargets.Clear(); mHasSkippedTargets = false; @@ -503,17 +469,6 @@ void ResizeObserverEntry::SetDevicePixelContentSize(const gfx::Size& aSize) { mDevicePixelContentBoxSize = new ResizeObserverSize(mOwner, aSize, wm); } -static void LastRememberedSizeCallback( - const Sequence>& aEntries, - ResizeObserver& aObserver) { - // TODO. -} - -/* static */ already_AddRefed -ResizeObserver::CreateLastRememberedSizeObserver(Document& aDocument) { - return do_AddRef(new ResizeObserver(aDocument, LastRememberedSizeCallback)); -} - NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(ResizeObserverSize, mOwner) NS_IMPL_CYCLE_COLLECTING_ADDREF(ResizeObserverSize) NS_IMPL_CYCLE_COLLECTING_RELEASE(ResizeObserverSize) diff --git a/dom/base/ResizeObserver.h b/dom/base/ResizeObserver.h index f9e07d68fc33..de7e8d593c8a 100644 --- a/dom/base/ResizeObserver.h +++ b/dom/base/ResizeObserver.h @@ -115,19 +115,13 @@ class ResizeObservation final : public LinkedListElement { * https://drafts.csswg.org/resize-observer/#api */ class ResizeObserver final : public nsISupports, public nsWrapperCache { - using NativeCallback = void (*)( - const Sequence>&, ResizeObserver&); - ResizeObserver(Document& aDocument, NativeCallback aCallback); - public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ResizeObserver) ResizeObserver(nsCOMPtr&& aOwner, Document* aDocument, ResizeObserverCallback& aCb) - : mOwner(std::move(aOwner)), - mDocument(aDocument), - mCallback(RefPtr(&aCb)) { + : mOwner(std::move(aOwner)), mDocument(aDocument), mCallback(&aCb) { MOZ_ASSERT(mOwner, "Need a non-null owner window"); MOZ_ASSERT(mDocument, "Need a non-null doc"); MOZ_ASSERT(mDocument == mOwner->GetExtantDoc()); @@ -180,22 +174,19 @@ class ResizeObserver final : public nsISupports, public nsWrapperCache { */ MOZ_CAN_RUN_SCRIPT uint32_t BroadcastActiveObservations(); - static already_AddRefed CreateLastRememberedSizeObserver( - Document&); - protected: ~ResizeObserver() { Disconnect(); } nsCOMPtr mOwner; // The window's document at the time of ResizeObserver creation. RefPtr mDocument; - Variant, NativeCallback> mCallback; + RefPtr mCallback; nsTArray> mActiveTargets; // The spec uses a list to store the skipped targets. However, it seems what // we want is to check if there are any skipped targets (i.e. existence). // Therefore, we use a boolean value to represent the existence of skipped // targets. - bool mHasSkippedTargets = false; + bool mHasSkippedTargets; // Combination of HashTable and LinkedList so we can iterate through // the elements of HashTable in order of insertion time, so we can deliver @@ -291,8 +282,8 @@ class ResizeObserverSize final : public nsISupports, public nsWrapperCache { return ResizeObserverSize_Binding::Wrap(aCx, this, aGivenProto); } - float InlineSize() const { return mSize.ISize(); } - float BlockSize() const { return mSize.BSize(); } + double InlineSize() const { return mSize.ISize(); } + double BlockSize() const { return mSize.BSize(); } protected: ~ResizeObserverSize() = default; diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index 3e3b480babc8..6f45e0c24f33 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -1319,16 +1319,6 @@ nsChangeHint nsStylePosition::CalcDifference( return hint; } -const StyleContainIntrinsicSize& nsStylePosition::ContainIntrinsicBSize( - const WritingMode& aWM) const { - return aWM.IsVertical() ? mContainIntrinsicWidth : mContainIntrinsicHeight; -} - -const StyleContainIntrinsicSize& nsStylePosition::ContainIntrinsicISize( - const WritingMode& aWM) const { - return aWM.IsVertical() ? mContainIntrinsicHeight : mContainIntrinsicWidth; -} - StyleAlignSelf nsStylePosition::UsedAlignSelf( const ComputedStyle* aParent) const { if (mAlignSelf._0 != StyleAlignFlags::AUTO) { @@ -3594,24 +3584,8 @@ nscoord StyleCalcNode::Resolve(nscoord aBasis, return ResolveInternal(aBasis, aRounder); } -static bool CanUseLastRememberedSize(const nsIFrame& aFrame) { - switch (aFrame.StyleDisplay()->mContentVisibility) { - case StyleContentVisibility::Visible: - return false; - case StyleContentVisibility::Auto: - // TODO: return true if the element skips its contents, i.e. if it's not - // relevant to the user. - return false; - case StyleContentVisibility::Hidden: - return true; - } - MOZ_ASSERT_UNREACHABLE("Unknown content-visibility value"); - return false; -} - static nscoord Resolve(const StyleContainIntrinsicSize& aSize, - nscoord aNoneValue, const nsIFrame& aFrame, - LogicalAxis aAxis) { + nscoord aNoneValue) { if (aSize.IsNone()) { return aNoneValue; } @@ -3619,50 +3593,29 @@ static nscoord Resolve(const StyleContainIntrinsicSize& aSize, return aSize.AsLength().ToAppUnits(); } MOZ_ASSERT(aSize.IsAutoLength()); - if (const auto* element = Element::FromNodeOrNull(aFrame.GetContent())) { - Maybe lastSize = aAxis == eLogicalAxisBlock - ? element->GetLastRememberedBSize() - : element->GetLastRememberedISize(); - if (lastSize && CanUseLastRememberedSize(aFrame)) { - return CSSPixel::ToAppUnits(*lastSize); - } - } + // TODO: use last remembered size if possible. return aSize.AsAutoLength().ToAppUnits(); } -Maybe ContainSizeAxes::ContainIntrinsicBSize( - const nsIFrame& aFrame, nscoord aNoneValue) const { - if (!mBContained) { - return Nothing(); - } - const StyleContainIntrinsicSize& bSize = - aFrame.StylePosition()->ContainIntrinsicBSize(aFrame.GetWritingMode()); - return Some(Resolve(bSize, aNoneValue, aFrame, eLogicalAxisBlock)); -} - -Maybe ContainSizeAxes::ContainIntrinsicISize( - const nsIFrame& aFrame, nscoord aNoneValue) const { - if (!mIContained) { - return Nothing(); - } - const StyleContainIntrinsicSize& iSize = - aFrame.StylePosition()->ContainIntrinsicISize(aFrame.GetWritingMode()); - return Some(Resolve(iSize, aNoneValue, aFrame, eLogicalAxisInline)); -} - nsSize ContainSizeAxes::ContainSize(const nsSize& aUncontainedSize, const nsIFrame& aFrame) const { if (!IsAny()) { return aUncontainedSize; } - if (aFrame.GetWritingMode().IsVertical()) { - return nsSize( - ContainIntrinsicBSize(aFrame).valueOr(aUncontainedSize.Width()), - ContainIntrinsicISize(aFrame).valueOr(aUncontainedSize.Height())); + const nsStylePosition* stylePos = aFrame.StylePosition(); + if (IsBoth()) { + return nsSize(Resolve(stylePos->mContainIntrinsicWidth, 0), + Resolve(stylePos->mContainIntrinsicHeight, 0)); } - return nsSize( - ContainIntrinsicISize(aFrame).valueOr(aUncontainedSize.Width()), - ContainIntrinsicBSize(aFrame).valueOr(aUncontainedSize.Height())); + // At this point, we know that precisely one of our dimensions is contained. + const bool containsWidth = + aFrame.GetWritingMode().IsVertical() ? mBContained : mIContained; + if (containsWidth) { + return nsSize(Resolve(stylePos->mContainIntrinsicWidth, 0), + aUncontainedSize.Height()); + } + return nsSize(aUncontainedSize.Width(), + Resolve(stylePos->mContainIntrinsicHeight, 0)); } IntrinsicSize ContainSizeAxes::ContainIntrinsicSize( @@ -3670,13 +3623,43 @@ IntrinsicSize ContainSizeAxes::ContainIntrinsicSize( if (!IsAny()) { return aUncontainedSize; } - IntrinsicSize result(aUncontainedSize); - const bool isVerticalWM = aFrame.GetWritingMode().IsVertical(); - if (Maybe containBSize = ContainIntrinsicBSize(aFrame)) { - (isVerticalWM ? result.width : result.height) = containBSize; + const nsStylePosition* stylePos = aFrame.StylePosition(); + if (IsBoth()) { + return IntrinsicSize(Resolve(stylePos->mContainIntrinsicWidth, 0), + Resolve(stylePos->mContainIntrinsicHeight, 0)); } - if (Maybe containISize = ContainIntrinsicISize(aFrame)) { - (isVerticalWM ? result.height : result.width) = containISize; + // At this point, we know that precisely one of our dimensions is contained. + const bool containsWidth = + aFrame.GetWritingMode().IsVertical() ? mBContained : mIContained; + IntrinsicSize result(aUncontainedSize); + if (containsWidth) { + result.width = Some(Resolve(stylePos->mContainIntrinsicWidth, 0)); + } else { + result.height = Some(Resolve(stylePos->mContainIntrinsicHeight, 0)); } return result; } + +Maybe ContainSizeAxes::ContainIntrinsicBSize( + const nsIFrame& aFrame, nscoord aNoneValue) const { + if (!mBContained) { + return Nothing(); + } + const nsStylePosition* stylePos = aFrame.StylePosition(); + return Some(Resolve(aFrame.GetWritingMode().IsVertical() + ? stylePos->mContainIntrinsicWidth + : stylePos->mContainIntrinsicHeight, + aNoneValue)); +} + +Maybe ContainSizeAxes::ContainIntrinsicISize( + const nsIFrame& aFrame, nscoord aNoneValue) const { + if (!mIContained) { + return Nothing(); + } + const nsStylePosition* stylePos = aFrame.StylePosition(); + return Some(Resolve(aFrame.GetWritingMode().IsVertical() + ? stylePos->mContainIntrinsicHeight + : stylePos->mContainIntrinsicWidth, + aNoneValue)); +} diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index a9f024e664f6..c062e750aa89 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -771,11 +771,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePosition { mOffset.Get(mozilla::eSideBottom).IsAuto()); } - const mozilla::StyleContainIntrinsicSize& ContainIntrinsicBSize( - const WritingMode& aWM) const; - const mozilla::StyleContainIntrinsicSize& ContainIntrinsicISize( - const WritingMode& aWM) const; - /** * Return the used value for 'align-self' given our parent ComputedStyle * (or null for the root).