diff --git a/dom/chrome-webidl/Flex.webidl b/dom/chrome-webidl/Flex.webidl index 25092bb5b81d7..ed14a4ea59dad 100644 --- a/dom/chrome-webidl/Flex.webidl +++ b/dom/chrome-webidl/Flex.webidl @@ -83,6 +83,7 @@ enum FlexItemClampState { interface FlexItemValues { readonly attribute Node? node; + readonly attribute DOMRectReadOnly frameRect; readonly attribute double mainBaseSize; readonly attribute double mainDeltaSize; readonly attribute double mainMinSize; diff --git a/dom/flex/FlexItemValues.cpp b/dom/flex/FlexItemValues.cpp index f961846b41b5e..84088703a08c7 100644 --- a/dom/flex/FlexItemValues.cpp +++ b/dom/flex/FlexItemValues.cpp @@ -12,7 +12,8 @@ namespace mozilla { namespace dom { -NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FlexItemValues, mParent) +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FlexItemValues, mParent, mNode, + mFrameRect) NS_IMPL_CYCLE_COLLECTING_ADDREF(FlexItemValues) NS_IMPL_CYCLE_COLLECTING_RELEASE(FlexItemValues) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FlexItemValues) @@ -49,6 +50,14 @@ FlexItemValues::FlexItemValues(FlexLineValues* aParent, // going to keep it around. mNode = aItem->mNode; + // Since mNode might be null, we associate the mFrameRect with + // our parent. + mFrameRect = new DOMRectReadOnly(mParent, + nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.X()), + nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.Y()), + nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.Width()), + nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.Height())); + // Convert app unit sizes to css pixel sizes. mMainBaseSize = nsPresContext::AppUnitsToDoubleCSSPixels( aItem->mMainBaseSize); @@ -76,6 +85,12 @@ FlexItemValues::GetNode() const return mNode; } +DOMRectReadOnly* +FlexItemValues::FrameRect() const +{ + return mFrameRect; +} + double FlexItemValues::MainBaseSize() const { diff --git a/dom/flex/FlexItemValues.h b/dom/flex/FlexItemValues.h index 7b5c78429df68..7d1f5977b1bdc 100644 --- a/dom/flex/FlexItemValues.h +++ b/dom/flex/FlexItemValues.h @@ -39,6 +39,7 @@ class FlexItemValues : public nsISupports } nsINode* GetNode() const; + DOMRectReadOnly* FrameRect() const; double MainBaseSize() const; double MainDeltaSize() const; double MainMinSize() const; @@ -50,6 +51,7 @@ class FlexItemValues : public nsISupports protected: RefPtr mParent; RefPtr mNode; + RefPtr mFrameRect; // These sizes are all CSS pixel units. double mMainBaseSize; diff --git a/layout/generic/nsFlexContainerFrame.cpp b/layout/generic/nsFlexContainerFrame.cpp index 4add9657ea859..8f72fab1c2bbd 100644 --- a/layout/generic/nsFlexContainerFrame.cpp +++ b/layout/generic/nsFlexContainerFrame.cpp @@ -4849,14 +4849,9 @@ nsFlexContainerFrame::DoFlexLayout(nsPresContext* aPresContext, itemInfo->mNode = content; - // mMainBaseSize and itemInfo->mMainDeltaSize will - // be filled out in ResolveFlexibleLengths(). - - // Other FlexItem properties can be captured now. - itemInfo->mMainMinSize = item->GetMainMinSize(); - itemInfo->mMainMaxSize = item->GetMainMaxSize(); - itemInfo->mCrossMinSize = item->GetCrossMinSize(); - itemInfo->mCrossMaxSize = item->GetCrossMaxSize(); + // itemInfo->mMainBaseSize and mMainDeltaSize will be filled out + // in ResolveFlexibleLengths(). Other measurements will be captured + // at the end of this function. } } } @@ -5261,7 +5256,7 @@ nsFlexContainerFrame::DoFlexLayout(nsPresContext* aPresContext, NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize) - // Finally update our line sizing values in our containerInfo. + // Finally update our line and item measurements in our containerInfo. if (MOZ_UNLIKELY(containerInfo)) { lineIndex = 0; for (const FlexLine* line = lines.getFirst(); line; @@ -5271,6 +5266,17 @@ nsFlexContainerFrame::DoFlexLayout(nsPresContext* aPresContext, lineInfo.mCrossSize = line->GetLineCrossSize(); lineInfo.mFirstBaselineOffset = line->GetFirstBaselineOffset(); lineInfo.mLastBaselineOffset = line->GetLastBaselineOffset(); + + uint32_t itemIndex = 0; + for (const FlexItem* item = line->GetFirstItem(); item; + item = item->getNext(), ++itemIndex) { + ComputedFlexItemInfo& itemInfo = lineInfo.mItems[itemIndex]; + itemInfo.mFrameRect = item->Frame()->GetRect(); + itemInfo.mMainMinSize = item->GetMainMinSize(); + itemInfo.mMainMaxSize = item->GetMainMaxSize(); + itemInfo.mCrossMinSize = item->GetCrossMinSize(); + itemInfo.mCrossMaxSize = item->GetCrossMaxSize(); + } } } } diff --git a/layout/generic/nsFlexContainerFrame.h b/layout/generic/nsFlexContainerFrame.h index 9bf1d820977b8..20e9c3ae3a2e2 100644 --- a/layout/generic/nsFlexContainerFrame.h +++ b/layout/generic/nsFlexContainerFrame.h @@ -33,6 +33,7 @@ nsContainerFrame* NS_NewFlexContainerFrame(nsIPresShell* aPresShell, struct ComputedFlexItemInfo { nsCOMPtr mNode; + nsRect mFrameRect; /** * mMainBaseSize is a measure of the size of the item in the main * axis before the flex sizing algorithm is applied. In the spec,