2017-11-16 00:20:35 +03:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
2018-10-17 23:22:26 +03:00
|
|
|
#include "FlexItemValues.h"
|
2017-11-16 00:20:35 +03:00
|
|
|
|
|
|
|
#include "mozilla/dom/FlexBinding.h"
|
2017-10-18 02:27:35 +03:00
|
|
|
#include "nsFlexContainerFrame.h"
|
2017-11-16 00:20:35 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2018-11-17 03:56:51 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FlexItemValues, mParent, mNode,
|
|
|
|
mFrameRect)
|
2018-10-17 23:22:26 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(FlexItemValues)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(FlexItemValues)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FlexItemValues)
|
2017-11-16 00:20:35 +03:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2018-07-28 00:38:46 +03:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2018-10-17 23:22:26 +03:00
|
|
|
FlexItemValues::FlexItemValues(FlexLineValues* aParent,
|
|
|
|
const ComputedFlexItemInfo* aItem)
|
2017-11-16 00:20:35 +03:00
|
|
|
: mParent(aParent) {
|
2017-10-18 02:27:35 +03:00
|
|
|
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;
|
|
|
|
|
2018-11-17 03:56:51 +03:00
|
|
|
// 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()));
|
|
|
|
|
2017-10-18 02:27:35 +03:00
|
|
|
// Convert app unit sizes to css pixel sizes.
|
|
|
|
mMainBaseSize =
|
|
|
|
nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mMainBaseSize);
|
|
|
|
mMainDeltaSize =
|
|
|
|
nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mMainDeltaSize);
|
|
|
|
mMainMinSize = nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mMainMinSize);
|
2018-07-28 00:38:46 +03:00
|
|
|
mMainMaxSize = ToPossiblyUnconstrainedPixels(aItem->mMainMaxSize);
|
2017-10-18 02:27:35 +03:00
|
|
|
mCrossMinSize =
|
|
|
|
nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mCrossMinSize);
|
2018-07-28 00:38:46 +03:00
|
|
|
mCrossMaxSize = ToPossiblyUnconstrainedPixels(aItem->mCrossMaxSize);
|
2018-10-25 02:46:16 +03:00
|
|
|
|
2018-10-25 02:47:23 +03:00
|
|
|
mClampState = aItem->mClampState;
|
2017-11-16 00:20:35 +03:00
|
|
|
}
|
|
|
|
|
2018-10-17 23:22:26 +03:00
|
|
|
JSObject* FlexItemValues::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
|
|
|
return FlexItemValues_Binding::Wrap(aCx, this, aGivenProto);
|
2017-11-16 00:20:35 +03:00
|
|
|
}
|
|
|
|
|
2018-10-17 23:22:26 +03:00
|
|
|
nsINode* FlexItemValues::GetNode() const { return mNode; }
|
2017-11-16 00:20:35 +03:00
|
|
|
|
2018-11-17 03:56:51 +03:00
|
|
|
DOMRectReadOnly* FlexItemValues::FrameRect() const { return mFrameRect; }
|
|
|
|
|
2018-10-17 23:22:26 +03:00
|
|
|
double FlexItemValues::MainBaseSize() const { return mMainBaseSize; }
|
2017-11-16 00:20:35 +03:00
|
|
|
|
2018-10-17 23:22:26 +03:00
|
|
|
double FlexItemValues::MainDeltaSize() const { return mMainDeltaSize; }
|
2017-11-16 00:20:35 +03:00
|
|
|
|
2018-10-17 23:22:26 +03:00
|
|
|
double FlexItemValues::MainMinSize() const { return mMainMinSize; }
|
2017-11-16 00:20:35 +03:00
|
|
|
|
2018-10-17 23:22:26 +03:00
|
|
|
double FlexItemValues::MainMaxSize() const { return mMainMaxSize; }
|
2017-11-16 00:20:35 +03:00
|
|
|
|
2018-10-17 23:22:26 +03:00
|
|
|
double FlexItemValues::CrossMinSize() const { return mCrossMinSize; }
|
2017-11-16 00:20:35 +03:00
|
|
|
|
2018-10-17 23:22:26 +03:00
|
|
|
double FlexItemValues::CrossMaxSize() const { return mCrossMaxSize; }
|
2017-11-16 00:20:35 +03:00
|
|
|
|
2018-10-25 02:46:16 +03:00
|
|
|
FlexItemClampState FlexItemValues::ClampState() const { return mClampState; }
|
|
|
|
|
2017-11-16 00:20:35 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|