Advertisement
Guest User

firefox 37.0.2 nsLayoutUtils

a guest
Sep 20th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.82 KB | None | 0 0
  1. static nsSize
  2. ComputeConcreteObjectSize(const nsSize& aConstraintSize,
  3.                           const IntrinsicSize& aIntrinsicSize,
  4.                           const nsSize& aIntrinsicRatio,
  5.                           uint8_t aObjectFit)
  6. {
  7.   // Handle default behavior (filling the container) w/ fast early return.
  8.   // (Also: if there's no valid intrinsic ratio, then we have the "fill"
  9.   // behavior & just use the constraint size.)
  10.   if (MOZ_LIKELY(aObjectFit == NS_STYLE_OBJECT_FIT_FILL) ||
  11.       aIntrinsicRatio.width == 0 ||
  12.       aIntrinsicRatio.height == 0) {
  13.     return aConstraintSize;
  14.   }
  15.  
  16.   Maybe<nsSize> noneSize;
  17.   Maybe<nsSize> constrainedSize;
  18.   Maybe<nsImageRenderer::FitType> fitType;
  19.  
  20.   switch (aObjectFit) {
  21.     case NS_STYLE_OBJECT_FIT_NONE:
  22.       noneSize.emplace(ComputeObjectFitNoneSize(aConstraintSize, aIntrinsicSize,
  23.                                          aIntrinsicRatio));
  24.       if (noneSize)
  25.         return *noneSize;
  26.       fitType.emplace(nsImageRenderer::CONTAIN);
  27.  
  28.     case NS_STYLE_OBJECT_FIT_SCALE_DOWN:
  29.       fitType.emplace(nsImageRenderer::CONTAIN);
  30.       constrainedSize->width =
  31.         std::min(constrainedSize->width, noneSize->width);
  32.       constrainedSize->height =
  33.         std::min(constrainedSize->height, noneSize->height);
  34.  
  35.     case NS_STYLE_OBJECT_FIT_COVER:
  36.       fitType.emplace(nsImageRenderer::COVER);
  37.  
  38.     case NS_STYLE_OBJECT_FIT_CONTAIN:
  39.       fitType.emplace(nsImageRenderer::CONTAIN);
  40.   }
  41.   constrainedSize.emplace(nsImageRenderer::ComputeConstrainedSize(aConstraintSize,
  42.                                          aIntrinsicRatio, *fitType));
  43.  
  44.   if (constrainedSize) {
  45.     return *constrainedSize;
  46.   } else {
  47.     MOZ_ASSERT_UNREACHABLE("Unexpected enum value for 'object-fit'");
  48.     return aConstraintSize; // fall back to (default) 'fill' behavior
  49.   }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement