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 "FlexLineValues.h"
8
9 #include "Flex.h"
10 #include "FlexItemValues.h"
11 #include "mozilla/dom/FlexBinding.h"
12 #include "nsFlexContainerFrame.h"
13
14 namespace mozilla::dom {
15
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FlexLineValues,mParent,mItems)16 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FlexLineValues, mParent, mItems)
17 NS_IMPL_CYCLE_COLLECTING_ADDREF(FlexLineValues)
18 NS_IMPL_CYCLE_COLLECTING_RELEASE(FlexLineValues)
19 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FlexLineValues)
20 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
21 NS_INTERFACE_MAP_ENTRY(nsISupports)
22 NS_INTERFACE_MAP_END
23
24 FlexLineValues::FlexLineValues(Flex* aParent, const ComputedFlexLineInfo* aLine)
25 : mParent(aParent) {
26 MOZ_ASSERT(aLine,
27 "Should never be instantiated with a null ComputedFlexLineInfo.");
28
29 // Eagerly copy values from aLine, because we're not
30 // going to keep it around.
31 mGrowthState = aLine->mGrowthState;
32
33 // Convert all the app unit values into css pixels.
34 mCrossStart = nsPresContext::AppUnitsToDoubleCSSPixels(aLine->mCrossStart);
35 mCrossSize = nsPresContext::AppUnitsToDoubleCSSPixels(aLine->mCrossSize);
36 mFirstBaselineOffset =
37 nsPresContext::AppUnitsToDoubleCSSPixels(aLine->mFirstBaselineOffset);
38 mLastBaselineOffset =
39 nsPresContext::AppUnitsToDoubleCSSPixels(aLine->mLastBaselineOffset);
40
41 mItems.SetLength(aLine->mItems.Length());
42 uint32_t index = 0;
43 for (auto&& i : aLine->mItems) {
44 FlexItemValues* item = new FlexItemValues(this, &i);
45 mItems.ElementAt(index) = item;
46 index++;
47 }
48 }
49
WrapObject(JSContext * aCx,JS::Handle<JSObject * > aGivenProto)50 JSObject* FlexLineValues::WrapObject(JSContext* aCx,
51 JS::Handle<JSObject*> aGivenProto) {
52 return FlexLineValues_Binding::Wrap(aCx, this, aGivenProto);
53 }
54
GrowthState() const55 FlexLineGrowthState FlexLineValues::GrowthState() const { return mGrowthState; }
56
CrossStart() const57 double FlexLineValues::CrossStart() const { return mCrossStart; }
58
CrossSize() const59 double FlexLineValues::CrossSize() const { return mCrossSize; }
60
FirstBaselineOffset() const61 double FlexLineValues::FirstBaselineOffset() const {
62 return mFirstBaselineOffset;
63 }
64
LastBaselineOffset() const65 double FlexLineValues::LastBaselineOffset() const {
66 return mLastBaselineOffset;
67 }
68
GetItems(nsTArray<RefPtr<FlexItemValues>> & aResult)69 void FlexLineValues::GetItems(nsTArray<RefPtr<FlexItemValues>>& aResult) {
70 aResult.AppendElements(mItems);
71 }
72
73 } // namespace mozilla::dom
74