Flex.cpp (2237B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "Flex.h" 8 9 #include "FlexLineValues.h" 10 #include "mozilla/dom/Element.h" 11 #include "mozilla/dom/FlexBinding.h" 12 #include "nsFlexContainerFrame.h" 13 14 namespace mozilla::dom { 15 16 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Flex, mParent, mLines) 17 NS_IMPL_CYCLE_COLLECTING_ADDREF(Flex) 18 NS_IMPL_CYCLE_COLLECTING_RELEASE(Flex) 19 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Flex) 20 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY 21 NS_INTERFACE_MAP_ENTRY(nsISupports) 22 NS_INTERFACE_MAP_END 23 24 Flex::Flex(Element* aParent, nsFlexContainerFrame* aFrame) : mParent(aParent) { 25 MOZ_ASSERT(aFrame, 26 "Should never be instantiated with a null nsFlexContainerFrame"); 27 28 // Eagerly create property values from aFrame, because we're not 29 // going to keep it around. 30 const ComputedFlexContainerInfo* containerInfo = 31 aFrame->GetFlexContainerInfo(); 32 if (!containerInfo) { 33 // It's weird but possible to fail to get a ComputedFlexContainerInfo 34 // structure. Assign sensible default values. 35 mMainAxisDirection = FlexPhysicalDirection::Horizontal_lr; 36 mCrossAxisDirection = FlexPhysicalDirection::Vertical_tb; 37 return; 38 } 39 mLines.SetLength(containerInfo->mLines.Length()); 40 uint32_t index = 0; 41 for (auto&& l : containerInfo->mLines) { 42 FlexLineValues* line = new FlexLineValues(this, &l); 43 mLines.ElementAt(index) = line; 44 index++; 45 } 46 47 mMainAxisDirection = containerInfo->mMainAxisDirection; 48 mCrossAxisDirection = containerInfo->mCrossAxisDirection; 49 } 50 51 JSObject* Flex::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) { 52 return Flex_Binding::Wrap(aCx, this, aGivenProto); 53 } 54 55 void Flex::GetLines(nsTArray<RefPtr<FlexLineValues>>& aResult) { 56 aResult.AppendElements(mLines); 57 } 58 59 FlexPhysicalDirection Flex::MainAxisDirection() const { 60 return mMainAxisDirection; 61 } 62 63 FlexPhysicalDirection Flex::CrossAxisDirection() const { 64 return mCrossAxisDirection; 65 } 66 67 } // namespace mozilla::dom