Bug 1409083 Part 4: Actually set values for exposed Flex properties. draft
authorBrad Werth <bwerth@mozilla.com>
Tue, 17 Oct 2017 16:27:35 -0700
changeset 710143 8b60a2affbebd423a356dca7782ec0685e2ed540
parent 710142 49a7d68e3522d466e475c0c73a30abaa4c894d01
child 710144 51a51a6d32ab77523561c9fad8f67cf08e8da205
push id92753
push userbwerth@mozilla.com
push dateFri, 08 Dec 2017 18:49:19 +0000
bugs1409083
milestone59.0a1
Bug 1409083 Part 4: Actually set values for exposed Flex properties. MozReview-Commit-ID: HfSmwzzQYOh
dom/flex/Flex.cpp
dom/flex/FlexItem.cpp
dom/flex/FlexItem.h
dom/flex/FlexLine.cpp
dom/flex/FlexLine.h
--- a/dom/flex/Flex.cpp
+++ b/dom/flex/Flex.cpp
@@ -23,17 +23,29 @@ NS_INTERFACE_MAP_END
 
 Flex::Flex(Element* aParent,
            nsFlexContainerFrame* aFrame)
   : mParent(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*
 Flex::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return FlexBinding::Wrap(aCx, this, aGivenProto);
 }
 
--- a/dom/flex/FlexItem.cpp
+++ b/dom/flex/FlexItem.cpp
@@ -2,75 +2,97 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "FlexItem.h"
 
 #include "mozilla/dom/FlexBinding.h"
+#include "nsFlexContainerFrame.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FlexItem, mParent)
 NS_IMPL_CYCLE_COLLECTING_ADDREF(FlexItem)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(FlexItem)
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FlexItem)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   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*
 FlexItem::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return FlexItemBinding::Wrap(aCx, this, 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
 } // namespace mozilla
--- a/dom/flex/FlexItem.h
+++ b/dom/flex/FlexItem.h
@@ -6,26 +6,29 @@
 
 #ifndef mozilla_dom_FlexItem_h
 #define mozilla_dom_FlexItem_h
 
 #include "mozilla/dom/FlexBinding.h"
 #include "nsISupports.h"
 #include "nsWrapperCache.h"
 
+struct ComputedFlexItemInfo;
+
 namespace mozilla {
 namespace dom {
 
 class FlexLine;
 
 class FlexItem : public nsISupports
                , public nsWrapperCache
 {
 public:
-  explicit FlexItem(FlexLine* aParent);
+  explicit FlexItem(FlexLine* aParent,
+                    const ComputedFlexItemInfo* aItem);
 
 protected:
   virtual ~FlexItem() = default;
 
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FlexItem)
 
@@ -40,14 +43,23 @@ public:
   double MainDeltaSize() const;
   double MainMinSize() const;
   double MainMaxSize() const;
   double CrossMinSize() const;
   double CrossMaxSize() const;
 
 protected:
   RefPtr<FlexLine> mParent;
+  RefPtr<nsINode> mNode;
+
+  // These sizes are all CSS pixel units.
+  double mMainBaseSize;
+  double mMainDeltaSize;
+  double mMainMinSize;
+  double mMainMaxSize;
+  double mCrossMinSize;
+  double mCrossMaxSize;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif /* mozilla_dom_FlexItem_h */
--- a/dom/flex/FlexLine.cpp
+++ b/dom/flex/FlexLine.cpp
@@ -3,61 +3,96 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "FlexLine.h"
 
 #include "FlexItem.h"
 #include "mozilla/dom/FlexBinding.h"
+#include "nsFlexContainerFrame.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FlexLine, mParent, mItems)
 NS_IMPL_CYCLE_COLLECTING_ADDREF(FlexLine)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(FlexLine)
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FlexLine)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   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*
 FlexLine::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return FlexLineBinding::Wrap(aCx, this, 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
 FlexLine::GetItems(nsTArray<RefPtr<FlexItem>>& aResult)
 {
   aResult.AppendElements(mItems);
 }
 
--- a/dom/flex/FlexLine.h
+++ b/dom/flex/FlexLine.h
@@ -6,27 +6,30 @@
 
 #ifndef mozilla_dom_FlexLine_h
 #define mozilla_dom_FlexLine_h
 
 #include "mozilla/dom/FlexBinding.h"
 #include "nsISupports.h"
 #include "nsWrapperCache.h"
 
+struct ComputedFlexLineInfo;
+
 namespace mozilla {
 namespace dom {
 
 class Flex;
 class FlexItem;
 
 class FlexLine : public nsISupports
                , public nsWrapperCache
 {
 public:
-  explicit FlexLine(Flex* aParent);
+  explicit FlexLine(Flex* aParent,
+                    const ComputedFlexLineInfo* aLine);
 
 protected:
   virtual ~FlexLine() = default;
 
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FlexLine)
 
@@ -40,15 +43,21 @@ public:
   double CrossSize() const;
   double FirstBaselineOffset() const;
   double LastBaselineOffset() const;
 
   void GetItems(nsTArray<RefPtr<FlexItem>>& aResult);
 
 protected:
   RefPtr<Flex> mParent;
+
+  FlexLineGrowthState mGrowthState;
+  double mCrossSize;
+  double mFirstBaselineOffset;
+  double mLastBaselineOffset;
+
   nsTArray<RefPtr<FlexItem>> mItems;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif /* mozilla_dom_FlexLine_h */