diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/flex/FlexItemValues.cpp | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/flex/FlexItemValues.cpp')
-rw-r--r-- | dom/flex/FlexItemValues.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/dom/flex/FlexItemValues.cpp b/dom/flex/FlexItemValues.cpp new file mode 100644 index 0000000000..9a9be8412f --- /dev/null +++ b/dom/flex/FlexItemValues.cpp @@ -0,0 +1,96 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "FlexItemValues.h" + +#include "mozilla/dom/DOMRect.h" +#include "mozilla/dom/FlexBinding.h" +#include "mozilla/dom/FlexLineValues.h" +#include "nsFlexContainerFrame.h" + +namespace mozilla::dom { + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FlexItemValues, mParent, mNode, + mFrameRect) +NS_IMPL_CYCLE_COLLECTING_ADDREF(FlexItemValues) +NS_IMPL_CYCLE_COLLECTING_RELEASE(FlexItemValues) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FlexItemValues) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +/** + * Utility function to convert a nscoord size to CSS pixel values, with + * graceful treatment of NS_UNCONSTRAINEDSIZE (which this function converts to + * the double "positive infinity" value). + * + * This function is suitable for converting quantities that are expected to + * sometimes legitimately (rather than arbitrarily/accidentally) contain the + * sentinel value NS_UNCONSTRAINEDSIZE -- e.g. to handle "max-width: none". + */ +static double ToPossiblyUnconstrainedPixels(nscoord aSize) { + if (aSize == NS_UNCONSTRAINEDSIZE) { + return std::numeric_limits<double>::infinity(); + } + return nsPresContext::AppUnitsToDoubleCSSPixels(aSize); +} + +FlexItemValues::FlexItemValues(FlexLineValues* aParent, + const ComputedFlexItemInfo* aItem) + : mParent(aParent) { + MOZ_ASSERT(aItem, + "Should never be instantiated with a null ComputedFlexLineInfo."); + + // Eagerly copy values from aItem, because we're not + // going to keep it around. + mNode = aItem->mNode; + + // Since mNode might be null, we associate the mFrameRect with + // our parent. + mFrameRect = new DOMRectReadOnly( + mParent, nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.X()), + nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.Y()), + nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.Width()), + nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.Height())); + + // Convert app unit sizes to css pixel sizes. + mMainBaseSize = + nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mMainBaseSize); + mMainDeltaSize = + nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mMainDeltaSize); + mMainMinSize = nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mMainMinSize); + mMainMaxSize = ToPossiblyUnconstrainedPixels(aItem->mMainMaxSize); + mCrossMinSize = + nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mCrossMinSize); + mCrossMaxSize = ToPossiblyUnconstrainedPixels(aItem->mCrossMaxSize); + + mClampState = aItem->mClampState; +} + +JSObject* FlexItemValues::WrapObject(JSContext* aCx, + JS::Handle<JSObject*> aGivenProto) { + return FlexItemValues_Binding::Wrap(aCx, this, aGivenProto); +} + +nsINode* FlexItemValues::GetNode() const { return mNode; } + +DOMRectReadOnly* FlexItemValues::FrameRect() const { return mFrameRect; } + +double FlexItemValues::MainBaseSize() const { return mMainBaseSize; } + +double FlexItemValues::MainDeltaSize() const { return mMainDeltaSize; } + +double FlexItemValues::MainMinSize() const { return mMainMinSize; } + +double FlexItemValues::MainMaxSize() const { return mMainMaxSize; } + +double FlexItemValues::CrossMinSize() const { return mCrossMinSize; } + +double FlexItemValues::CrossMaxSize() const { return mCrossMaxSize; } + +FlexItemClampState FlexItemValues::ClampState() const { return mClampState; } + +} // namespace mozilla::dom |