Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static nsSize
- ComputeConcreteObjectSize(const nsSize& aConstraintSize,
- const IntrinsicSize& aIntrinsicSize,
- const nsSize& aIntrinsicRatio,
- uint8_t aObjectFit)
- {
- // Handle default behavior (filling the container) w/ fast early return.
- // (Also: if there's no valid intrinsic ratio, then we have the "fill"
- // behavior & just use the constraint size.)
- if (MOZ_LIKELY(aObjectFit == NS_STYLE_OBJECT_FIT_FILL) ||
- aIntrinsicRatio.width == 0 ||
- aIntrinsicRatio.height == 0) {
- return aConstraintSize;
- }
- Maybe<nsSize> noneSize;
- Maybe<nsSize> constrainedSize;
- Maybe<nsImageRenderer::FitType> fitType;
- switch (aObjectFit) {
- case NS_STYLE_OBJECT_FIT_NONE:
- noneSize.emplace(ComputeObjectFitNoneSize(aConstraintSize, aIntrinsicSize,
- aIntrinsicRatio));
- if (noneSize)
- return *noneSize;
- fitType.emplace(nsImageRenderer::CONTAIN);
- case NS_STYLE_OBJECT_FIT_SCALE_DOWN:
- fitType.emplace(nsImageRenderer::CONTAIN);
- constrainedSize->width =
- std::min(constrainedSize->width, noneSize->width);
- constrainedSize->height =
- std::min(constrainedSize->height, noneSize->height);
- case NS_STYLE_OBJECT_FIT_COVER:
- fitType.emplace(nsImageRenderer::COVER);
- case NS_STYLE_OBJECT_FIT_CONTAIN:
- fitType.emplace(nsImageRenderer::CONTAIN);
- }
- constrainedSize.emplace(nsImageRenderer::ComputeConstrainedSize(aConstraintSize,
- aIntrinsicRatio, *fitType));
- if (constrainedSize) {
- return *constrainedSize;
- } else {
- MOZ_ASSERT_UNREACHABLE("Unexpected enum value for 'object-fit'");
- return aConstraintSize; // fall back to (default) 'fill' behavior
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement