Пример #1
0
static void
ComputeRectsForInsetBoxShadow(gfxIntSize aBlurRadius,
                              gfxIntSize aSpreadRadius,
                              const Rect& aDestRect,
                              const Rect& aShadowClipRect,
                              Rect& aOutOuterRect,
                              Rect& aOutInnerRect,
                              Margin& aOutPathMargins)
{
  gfxIntSize marginSize = aBlurRadius + aSpreadRadius;
  // The sizes we're given for aBlurRadius/aSpreadRadius are radius'.
  // We actually want to paint the whole blur, so we need the diameter.
  // We render both the outer / inner blur portions of a blur,
  // Then we clip out the outer portion later.
  aOutPathMargins.SizeTo(marginSize.height, marginSize.width, marginSize.height, marginSize.width);
  aOutPathMargins += aOutPathMargins;

  aOutOuterRect.x = 0;
  aOutInnerRect.x = marginSize.width;

  aOutOuterRect.y = 0;
  aOutInnerRect.y = marginSize.height;

  // + 1 for the middle edges so we can sample them
  aOutInnerRect.width = aOutPathMargins.LeftRight() + 1;
  aOutInnerRect.height = aOutPathMargins.TopBottom() + 1;

  // The outer path rect needs to be 1 blur radius past the inner edges
  aOutOuterRect.width = aOutInnerRect.XMost() + marginSize.width;
  aOutOuterRect.height = aOutInnerRect.YMost() + marginSize.height;

  if ((aOutOuterRect.width >= aDestRect.width) ||
      (aOutOuterRect.height >= aDestRect.height) ||
      (aOutInnerRect.width >= aShadowClipRect.width) ||
      (aOutInnerRect.height >= aShadowClipRect.height))
  {
    aOutOuterRect.width = aDestRect.width;
    aOutOuterRect.height = aDestRect.height;
    aOutInnerRect.width = aShadowClipRect.width;
    aOutInnerRect.height = aShadowClipRect.height;
    aOutPathMargins.SizeTo(0, 0, 0, 0);
  }
}
Пример #2
0
/***
 * We create our minimal rect with 2 rects.
 * The first is the inside whitespace rect, that is "cut out"
 * from the box. This is (1). This must be the size
 * of the blur radius + corner radius so we can have a big enough
 * inside cut.
 *
 * The second (2) is one blur radius surrounding the inner
 * frame of (1). This is the amount of blur space required
 * to get a proper blend.
 *
 * B = one blur size
 * W = one blur + corner radii - known as inner margin
 * ___________________________________
 * |                                |
 * |          |             |       |
 * |      (2) |    (1)      |  (2)  |
 * |       B  |     W       |   B   |
 * |          |             |       |
 * |          |             |       |
 * |          |                     |
 * |________________________________|
 */
static void GetBlurMargins(const RectCornerRadii* aInnerClipRadii,
                           const IntSize& aBlurRadius,
                           Margin& aOutBlurMargin,
                           Margin& aOutInnerMargin)
{
  Size cornerSize(0, 0);
  if (aInnerClipRadii) {
    const RectCornerRadii& corners = *aInnerClipRadii;
    NS_FOR_CSS_FULL_CORNERS(i) {
      cornerSize.width = std::max(cornerSize.width, corners[i].width);
      cornerSize.height = std::max(cornerSize.height, corners[i].height);
    }
  }

  // Only the inside whitespace size cares about the border radius size.
  // Outer sizes only care about blur.
  IntSize margin = IntSize::Ceil(cornerSize) + aBlurRadius;

  aOutInnerMargin.SizeTo(margin.height, margin.width,
                         margin.height, margin.width);
  aOutBlurMargin.SizeTo(aBlurRadius.height, aBlurRadius.width,
                        aBlurRadius.height, aBlurRadius.width);
}