Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / dom / flex / FlexItemValues.cpp
blob9a9be8412fd21a04e8debe3dec44de7e59a5f43c
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/DOMRect.h"
10 #include "mozilla/dom/FlexBinding.h"
11 #include "mozilla/dom/FlexLineValues.h"
12 #include "nsFlexContainerFrame.h"
14 namespace mozilla::dom {
16 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FlexItemValues, mParent, mNode,
17 mFrameRect)
18 NS_IMPL_CYCLE_COLLECTING_ADDREF(FlexItemValues)
19 NS_IMPL_CYCLE_COLLECTING_RELEASE(FlexItemValues)
20 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FlexItemValues)
21 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
22 NS_INTERFACE_MAP_ENTRY(nsISupports)
23 NS_INTERFACE_MAP_END
25 /**
26 * Utility function to convert a nscoord size to CSS pixel values, with
27 * graceful treatment of NS_UNCONSTRAINEDSIZE (which this function converts to
28 * the double "positive infinity" value).
30 * This function is suitable for converting quantities that are expected to
31 * sometimes legitimately (rather than arbitrarily/accidentally) contain the
32 * sentinel value NS_UNCONSTRAINEDSIZE -- e.g. to handle "max-width: none".
34 static double ToPossiblyUnconstrainedPixels(nscoord aSize) {
35 if (aSize == NS_UNCONSTRAINEDSIZE) {
36 return std::numeric_limits<double>::infinity();
38 return nsPresContext::AppUnitsToDoubleCSSPixels(aSize);
41 FlexItemValues::FlexItemValues(FlexLineValues* aParent,
42 const ComputedFlexItemInfo* aItem)
43 : mParent(aParent) {
44 MOZ_ASSERT(aItem,
45 "Should never be instantiated with a null ComputedFlexLineInfo.");
47 // Eagerly copy values from aItem, because we're not
48 // going to keep it around.
49 mNode = aItem->mNode;
51 // Since mNode might be null, we associate the mFrameRect with
52 // our parent.
53 mFrameRect = new DOMRectReadOnly(
54 mParent, nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.X()),
55 nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.Y()),
56 nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.Width()),
57 nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.Height()));
59 // Convert app unit sizes to css pixel sizes.
60 mMainBaseSize =
61 nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mMainBaseSize);
62 mMainDeltaSize =
63 nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mMainDeltaSize);
64 mMainMinSize = nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mMainMinSize);
65 mMainMaxSize = ToPossiblyUnconstrainedPixels(aItem->mMainMaxSize);
66 mCrossMinSize =
67 nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mCrossMinSize);
68 mCrossMaxSize = ToPossiblyUnconstrainedPixels(aItem->mCrossMaxSize);
70 mClampState = aItem->mClampState;
73 JSObject* FlexItemValues::WrapObject(JSContext* aCx,
74 JS::Handle<JSObject*> aGivenProto) {
75 return FlexItemValues_Binding::Wrap(aCx, this, aGivenProto);
78 nsINode* FlexItemValues::GetNode() const { return mNode; }
80 DOMRectReadOnly* FlexItemValues::FrameRect() const { return mFrameRect; }
82 double FlexItemValues::MainBaseSize() const { return mMainBaseSize; }
84 double FlexItemValues::MainDeltaSize() const { return mMainDeltaSize; }
86 double FlexItemValues::MainMinSize() const { return mMainMinSize; }
88 double FlexItemValues::MainMaxSize() const { return mMainMaxSize; }
90 double FlexItemValues::CrossMinSize() const { return mCrossMinSize; }
92 double FlexItemValues::CrossMaxSize() const { return mCrossMaxSize; }
94 FlexItemClampState FlexItemValues::ClampState() const { return mClampState; }
96 } // namespace mozilla::dom