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/. */
9 #include "FlexLineValues.h"
10 #include "mozilla/dom/Element.h"
11 #include "mozilla/dom/FlexBinding.h"
12 #include "nsFlexContainerFrame.h"
14 namespace mozilla::dom
{
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
)
24 Flex::Flex(Element
* aParent
, nsFlexContainerFrame
* aFrame
) : mParent(aParent
) {
26 "Should never be instantiated with a null nsFlexContainerFrame");
28 // Eagerly create property values from aFrame, because we're not
29 // going to keep it around.
30 const ComputedFlexContainerInfo
* containerInfo
=
31 aFrame
->GetFlexContainerInfo();
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
;
39 mLines
.SetLength(containerInfo
->mLines
.Length());
41 for (auto&& l
: containerInfo
->mLines
) {
42 FlexLineValues
* line
= new FlexLineValues(this, &l
);
43 mLines
.ElementAt(index
) = line
;
47 mMainAxisDirection
= containerInfo
->mMainAxisDirection
;
48 mCrossAxisDirection
= containerInfo
->mCrossAxisDirection
;
51 JSObject
* Flex::WrapObject(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) {
52 return Flex_Binding::Wrap(aCx
, this, aGivenProto
);
55 void Flex::GetLines(nsTArray
<RefPtr
<FlexLineValues
>>& aResult
) {
56 aResult
.AppendElements(mLines
);
59 FlexPhysicalDirection
Flex::MainAxisDirection() const {
60 return mMainAxisDirection
;
63 FlexPhysicalDirection
Flex::CrossAxisDirection() const {
64 return mCrossAxisDirection
;
67 } // namespace mozilla::dom