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/. */
7 #include "FlexItemValues.h"
9 #include "mozilla/dom/FlexBinding.h"
10 #include "nsFlexContainerFrame.h"
15 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FlexItemValues
, mParent
, mNode
,
17 NS_IMPL_CYCLE_COLLECTING_ADDREF(FlexItemValues
)
18 NS_IMPL_CYCLE_COLLECTING_RELEASE(FlexItemValues
)
19 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FlexItemValues
)
20 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
21 NS_INTERFACE_MAP_ENTRY(nsISupports
)
25 * Utility function to convert a nscoord size to CSS pixel values, with
26 * graceful treatment of NS_UNCONSTRAINEDSIZE (which this function converts to
27 * the double "positive infinity" value).
29 * This function is suitable for converting quantities that are expected to
30 * sometimes legitimately (rather than arbitrarily/accidentally) contain the
31 * sentinel value NS_UNCONSTRAINEDSIZE -- e.g. to handle "max-width: none".
33 static double ToPossiblyUnconstrainedPixels(nscoord aSize
) {
34 if (aSize
== NS_UNCONSTRAINEDSIZE
) {
35 return std::numeric_limits
<double>::infinity();
37 return nsPresContext::AppUnitsToDoubleCSSPixels(aSize
);
40 FlexItemValues::FlexItemValues(FlexLineValues
* aParent
,
41 const ComputedFlexItemInfo
* aItem
)
44 "Should never be instantiated with a null ComputedFlexLineInfo.");
46 // Eagerly copy values from aItem, because we're not
47 // going to keep it around.
50 // Since mNode might be null, we associate the mFrameRect with
52 mFrameRect
= new DOMRectReadOnly(
53 mParent
, nsPresContext::AppUnitsToDoubleCSSPixels(aItem
->mFrameRect
.X()),
54 nsPresContext::AppUnitsToDoubleCSSPixels(aItem
->mFrameRect
.Y()),
55 nsPresContext::AppUnitsToDoubleCSSPixels(aItem
->mFrameRect
.Width()),
56 nsPresContext::AppUnitsToDoubleCSSPixels(aItem
->mFrameRect
.Height()));
58 // Convert app unit sizes to css pixel sizes.
60 nsPresContext::AppUnitsToDoubleCSSPixels(aItem
->mMainBaseSize
);
62 nsPresContext::AppUnitsToDoubleCSSPixels(aItem
->mMainDeltaSize
);
63 mMainMinSize
= nsPresContext::AppUnitsToDoubleCSSPixels(aItem
->mMainMinSize
);
64 mMainMaxSize
= ToPossiblyUnconstrainedPixels(aItem
->mMainMaxSize
);
66 nsPresContext::AppUnitsToDoubleCSSPixels(aItem
->mCrossMinSize
);
67 mCrossMaxSize
= ToPossiblyUnconstrainedPixels(aItem
->mCrossMaxSize
);
69 mClampState
= aItem
->mClampState
;
72 JSObject
* FlexItemValues::WrapObject(JSContext
* aCx
,
73 JS::Handle
<JSObject
*> aGivenProto
) {
74 return FlexItemValues_Binding::Wrap(aCx
, this, aGivenProto
);
77 nsINode
* FlexItemValues::GetNode() const { return mNode
; }
79 DOMRectReadOnly
* FlexItemValues::FrameRect() const { return mFrameRect
; }
81 double FlexItemValues::MainBaseSize() const { return mMainBaseSize
; }
83 double FlexItemValues::MainDeltaSize() const { return mMainDeltaSize
; }
85 double FlexItemValues::MainMinSize() const { return mMainMinSize
; }
87 double FlexItemValues::MainMaxSize() const { return mMainMaxSize
; }
89 double FlexItemValues::CrossMinSize() const { return mCrossMinSize
; }
91 double FlexItemValues::CrossMaxSize() const { return mCrossMaxSize
; }
93 FlexItemClampState
FlexItemValues::ClampState() const { return mClampState
; }
96 } // namespace mozilla