diff --git a/dom/flex/Flex.cpp b/dom/flex/Flex.cpp index 013a3565b039..bc690e2067c7 100644 --- a/dom/flex/Flex.cpp +++ b/dom/flex/Flex.cpp @@ -28,7 +28,19 @@ Flex::Flex(Element* aParent, MOZ_ASSERT(aFrame, "Should never be instantiated with a null nsFlexContainerFrame"); - // Eagerly create mLines. + // Eagerly create property values from aFrame, because we're not + // going to keep it around. + const ComputedFlexContainerInfo* containerInfo = + aFrame->GetFlexContainerInfo(); + MOZ_ASSERT(containerInfo, "Should only be passed a frame with info."); + + mLines.SetLength(containerInfo->mLines.Length()); + uint32_t index = 0; + for (auto&& l : containerInfo->mLines) { + FlexLine* line = new FlexLine(this, &l); + mLines.ElementAt(index) = line; + index++; + } } JSObject* diff --git a/dom/flex/FlexItem.cpp b/dom/flex/FlexItem.cpp index d3c7f536e852..73f737fd73b2 100644 --- a/dom/flex/FlexItem.cpp +++ b/dom/flex/FlexItem.cpp @@ -7,6 +7,7 @@ #include "FlexItem.h" #include "mozilla/dom/FlexBinding.h" +#include "nsFlexContainerFrame.h" namespace mozilla { namespace dom { @@ -19,9 +20,30 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FlexItem) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END -FlexItem::FlexItem(FlexLine* aParent) +FlexItem::FlexItem(FlexLine* aParent, + const ComputedFlexItemInfo* aItem) : mParent(aParent) { + MOZ_ASSERT(aItem, + "Should never be instantiated with a null ComputedFlexLineInfo."); + + // Eagerly copy values from aItem, because we're not + // going to keep it around. + mNode = aItem->mNode; + + // Convert app unit sizes to css pixel sizes. + mMainBaseSize = nsPresContext::AppUnitsToDoubleCSSPixels( + aItem->mMainBaseSize); + mMainDeltaSize = nsPresContext::AppUnitsToDoubleCSSPixels( + aItem->mMainDeltaSize); + mMainMinSize = nsPresContext::AppUnitsToDoubleCSSPixels( + aItem->mMainMinSize); + mMainMaxSize = nsPresContext::AppUnitsToDoubleCSSPixels( + aItem->mMainMaxSize); + mCrossMinSize = nsPresContext::AppUnitsToDoubleCSSPixels( + aItem->mCrossMinSize); + mCrossMaxSize = nsPresContext::AppUnitsToDoubleCSSPixels( + aItem->mCrossMaxSize); } JSObject* @@ -33,43 +55,43 @@ FlexItem::WrapObject(JSContext* aCx, JS::Handle aGivenProto) nsINode* FlexItem::GetNode() const { - return nullptr; + return mNode; } double FlexItem::MainBaseSize() const { - return 0; + return mMainBaseSize; } double FlexItem::MainDeltaSize() const { - return 0; + return mMainDeltaSize; } double FlexItem::MainMinSize() const { - return 0; + return mMainMinSize; } double FlexItem::MainMaxSize() const { - return 0; + return mMainMaxSize; } double FlexItem::CrossMinSize() const { - return 0; + return mCrossMinSize; } double FlexItem::CrossMaxSize() const { - return 0; + return mCrossMaxSize; } } // namespace dom diff --git a/dom/flex/FlexItem.h b/dom/flex/FlexItem.h index a31080ccbbe0..4bb402e3e130 100644 --- a/dom/flex/FlexItem.h +++ b/dom/flex/FlexItem.h @@ -11,6 +11,8 @@ #include "nsISupports.h" #include "nsWrapperCache.h" +struct ComputedFlexItemInfo; + namespace mozilla { namespace dom { @@ -20,7 +22,8 @@ class FlexItem : public nsISupports , public nsWrapperCache { public: - explicit FlexItem(FlexLine* aParent); + explicit FlexItem(FlexLine* aParent, + const ComputedFlexItemInfo* aItem); protected: virtual ~FlexItem() = default; @@ -45,6 +48,15 @@ public: protected: RefPtr mParent; + RefPtr mNode; + + // These sizes are all CSS pixel units. + double mMainBaseSize; + double mMainDeltaSize; + double mMainMinSize; + double mMainMaxSize; + double mCrossMinSize; + double mCrossMaxSize; }; } // namespace dom diff --git a/dom/flex/FlexLine.cpp b/dom/flex/FlexLine.cpp index e5ddd402b2e7..01bbf8297b67 100644 --- a/dom/flex/FlexLine.cpp +++ b/dom/flex/FlexLine.cpp @@ -8,6 +8,7 @@ #include "FlexItem.h" #include "mozilla/dom/FlexBinding.h" +#include "nsFlexContainerFrame.h" namespace mozilla { namespace dom { @@ -20,9 +21,43 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FlexLine) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END -FlexLine::FlexLine(Flex* aParent) +FlexLine::FlexLine(Flex* aParent, + const ComputedFlexLineInfo* aLine) : mParent(aParent) { + MOZ_ASSERT(aLine, + "Should never be instantiated with a null ComputedFlexLineInfo."); + + // Eagerly copy values from aLine, because we're not + // going to keep it around. + switch (aLine->mGrowthState) { + case ComputedFlexLineInfo::GrowthState::SHRINKING: + mGrowthState = FlexLineGrowthState::Shrinking; + break; + + case ComputedFlexLineInfo::GrowthState::GROWING: + mGrowthState = FlexLineGrowthState::Growing; + break; + + default: + mGrowthState = FlexLineGrowthState::Unchanged; + }; + + // Convert all the app unit values into css pixels. + mCrossSize = nsPresContext::AppUnitsToDoubleCSSPixels( + aLine->mCrossSize); + mFirstBaselineOffset = nsPresContext::AppUnitsToDoubleCSSPixels( + aLine->mFirstBaselineOffset); + mLastBaselineOffset = nsPresContext::AppUnitsToDoubleCSSPixels( + aLine->mLastBaselineOffset); + + mItems.SetLength(aLine->mItems.Length()); + uint32_t index = 0; + for (auto&& i : aLine->mItems) { + FlexItem* item = new FlexItem(this, &i); + mItems.ElementAt(index) = item; + index++; + } } JSObject* @@ -34,25 +69,25 @@ FlexLine::WrapObject(JSContext* aCx, JS::Handle aGivenProto) FlexLineGrowthState FlexLine::GrowthState() const { - return FlexLineGrowthState::Unchanged; + return mGrowthState; } double FlexLine::CrossSize() const { - return 0; + return mCrossSize; } double FlexLine::FirstBaselineOffset() const { - return 0; + return mFirstBaselineOffset; } double FlexLine::LastBaselineOffset() const { - return 0; + return mLastBaselineOffset; } void diff --git a/dom/flex/FlexLine.h b/dom/flex/FlexLine.h index e3c6b52f03f2..fbea3c0f6241 100644 --- a/dom/flex/FlexLine.h +++ b/dom/flex/FlexLine.h @@ -11,6 +11,8 @@ #include "nsISupports.h" #include "nsWrapperCache.h" +struct ComputedFlexLineInfo; + namespace mozilla { namespace dom { @@ -21,7 +23,8 @@ class FlexLine : public nsISupports , public nsWrapperCache { public: - explicit FlexLine(Flex* aParent); + explicit FlexLine(Flex* aParent, + const ComputedFlexLineInfo* aLine); protected: virtual ~FlexLine() = default; @@ -45,6 +48,12 @@ public: protected: RefPtr mParent; + + FlexLineGrowthState mGrowthState; + double mCrossSize; + double mFirstBaselineOffset; + double mLastBaselineOffset; + nsTArray> mItems; };