Blame layout/svg/nsSVGIntegrationUtils.h

Packit f0b94e
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
Packit f0b94e
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
Packit f0b94e
/* This Source Code Form is subject to the terms of the Mozilla Public
Packit f0b94e
 * License, v. 2.0. If a copy of the MPL was not distributed with this
Packit f0b94e
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Packit f0b94e
Packit f0b94e
#ifndef NSSVGINTEGRATIONUTILS_H_
Packit f0b94e
#define NSSVGINTEGRATIONUTILS_H_
Packit f0b94e
Packit f0b94e
#include "ImgDrawResult.h"
Packit f0b94e
#include "gfxMatrix.h"
Packit f0b94e
#include "gfxRect.h"
Packit f0b94e
#include "nsRegionFwd.h"
Packit f0b94e
#include "mozilla/gfx/Rect.h"
Packit f0b94e
Packit f0b94e
class gfxContext;
Packit f0b94e
class gfxDrawable;
Packit f0b94e
class nsDisplayList;
Packit f0b94e
class nsDisplayListBuilder;
Packit f0b94e
class nsIFrame;
Packit f0b94e
Packit f0b94e
struct nsRect;
Packit f0b94e
Packit f0b94e
namespace mozilla {
Packit f0b94e
namespace gfx {
Packit f0b94e
class DrawTarget;
Packit f0b94e
}  // namespace gfx
Packit f0b94e
namespace layers {
Packit f0b94e
class LayerManager;
Packit f0b94e
}  // namespace layers
Packit f0b94e
}  // namespace mozilla
Packit f0b94e
Packit f0b94e
struct nsPoint;
Packit f0b94e
struct nsSize;
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * Integration of SVG effects (clipPath clipping, masking and filters) into
Packit f0b94e
 * regular display list based painting and hit-testing.
Packit f0b94e
 */
Packit f0b94e
class nsSVGIntegrationUtils final {
Packit f0b94e
  typedef mozilla::gfx::DrawTarget DrawTarget;
Packit f0b94e
  typedef mozilla::gfx::IntRect IntRect;
Packit f0b94e
  typedef mozilla::image::imgDrawingParams imgDrawingParams;
Packit f0b94e
Packit f0b94e
 public:
Packit f0b94e
  /**
Packit f0b94e
   * Returns true if SVG effects are currently applied to this frame.
Packit f0b94e
   */
Packit f0b94e
  static bool UsingEffectsForFrame(const nsIFrame* aFrame);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Returns true if mask or clippath are currently applied to this frame.
Packit f0b94e
   */
Packit f0b94e
  static bool UsingMaskOrClipPathForFrame(const nsIFrame* aFrame);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Returns the size of the union of the border-box rects of all of
Packit f0b94e
   * aNonSVGFrame's continuations.
Packit f0b94e
   */
Packit f0b94e
  static nsSize GetContinuationUnionSize(nsIFrame* aNonSVGFrame);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * When SVG effects need to resolve percentage, userSpaceOnUse lengths, they
Packit f0b94e
   * need a coordinate context to resolve them against. This method provides
Packit f0b94e
   * that coordinate context for non-SVG frames with SVG effects applied to
Packit f0b94e
   * them. The gfxSize returned is the size of the union of all of the given
Packit f0b94e
   * frame's continuations' border boxes, converted to SVG user units (equal to
Packit f0b94e
   * CSS px units), as required by the SVG code.
Packit f0b94e
   */
Packit f0b94e
  static mozilla::gfx::Size GetSVGCoordContextForNonSVGFrame(
Packit f0b94e
      nsIFrame* aNonSVGFrame);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * SVG effects such as SVG filters, masking and clipPath may require an SVG
Packit f0b94e
   * "bbox" for the element they're being applied to in order to make decisions
Packit f0b94e
   * about positioning, and to resolve various lengths against. This method
Packit f0b94e
   * provides the "bbox" for non-SVG frames. The bbox returned is in CSS px
Packit f0b94e
   * units, and aUnionContinuations decide whether bbox contains the area of
Packit f0b94e
   * current frame only or the union of all aNonSVGFrame's continuations'
Packit f0b94e
   * overflow areas, relative to the top-left of the union of all aNonSVGFrame's
Packit f0b94e
   * continuations' border box rects.
Packit f0b94e
   */
Packit f0b94e
  static gfxRect GetSVGBBoxForNonSVGFrame(nsIFrame* aNonSVGFrame,
Packit f0b94e
                                          bool aUnionContinuations);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Used to adjust a frame's pre-effects visual overflow rect to take account
Packit f0b94e
   * of SVG effects.
Packit f0b94e
   *
Packit f0b94e
   * XXX This method will not do the right thing for frames with continuations.
Packit f0b94e
   * It really needs all the continuations to have been reflowed before being
Packit f0b94e
   * called, but we currently call it on each continuation as its overflow
Packit f0b94e
   * rects are set during the reflow of each particular continuation. Gecko's
Packit f0b94e
   * current reflow architecture does not allow us to set the overflow rects
Packit f0b94e
   * for a whole chain of continuations for a given element at the point when
Packit f0b94e
   * the last continuation is reflowed. See:
Packit f0b94e
   * http://groups.google.com/group/mozilla.dev.tech.layout/msg/6b179066f3051f65
Packit f0b94e
   */
Packit f0b94e
  static nsRect ComputePostEffectsVisualOverflowRect(
Packit f0b94e
      nsIFrame* aFrame, const nsRect& aPreEffectsOverflowRect);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Used to adjust the area of a frame that needs to be invalidated to take
Packit f0b94e
   * account of SVG effects.
Packit f0b94e
   *
Packit f0b94e
   * @param aFrame The effects frame.
Packit f0b94e
   * @param aToReferenceFrame The offset (in app units) from aFrame to its
Packit f0b94e
   * reference display item.
Packit f0b94e
   * @param aInvalidRegion The pre-effects invalid region in pixels relative to
Packit f0b94e
   * the reference display item.
Packit f0b94e
   * @return The post-effects invalid rect in pixels relative to the reference
Packit f0b94e
   * display item.
Packit f0b94e
   */
Packit f0b94e
  static nsIntRegion AdjustInvalidAreaForSVGEffects(
Packit f0b94e
      nsIFrame* aFrame, const nsPoint& aToReferenceFrame,
Packit f0b94e
      const nsIntRegion& aInvalidRegion);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Figure out which area of the source is needed given an area to
Packit f0b94e
   * repaint
Packit f0b94e
   */
Packit f0b94e
  static nsRect GetRequiredSourceForInvalidArea(nsIFrame* aFrame,
Packit f0b94e
                                                const nsRect& aDamageRect);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Returns true if the given point is not clipped out by effects.
Packit f0b94e
   * @param aPt in appunits relative to aFrame
Packit f0b94e
   */
Packit f0b94e
  static bool HitTestFrameForEffects(nsIFrame* aFrame, const nsPoint& aPt);
Packit f0b94e
Packit f0b94e
  struct MOZ_STACK_CLASS PaintFramesParams {
Packit f0b94e
    gfxContext& ctx;
Packit f0b94e
    nsIFrame* frame;
Packit f0b94e
    const nsRect& dirtyRect;
Packit f0b94e
    const nsRect& borderArea;
Packit f0b94e
    nsDisplayListBuilder* builder;
Packit f0b94e
    mozilla::layers::LayerManager* layerManager;
Packit f0b94e
    bool handleOpacity;  // If true, PaintMaskAndClipPath/ PaintFilter should
Packit f0b94e
                         // apply css opacity.
Packit f0b94e
    IntRect maskRect;
Packit f0b94e
    imgDrawingParams& imgParams;
Packit f0b94e
Packit f0b94e
    explicit PaintFramesParams(gfxContext& aCtx, nsIFrame* aFrame,
Packit f0b94e
                               const nsRect& aDirtyRect,
Packit f0b94e
                               const nsRect& aBorderArea,
Packit f0b94e
                               nsDisplayListBuilder* aBuilder,
Packit f0b94e
                               mozilla::layers::LayerManager* aLayerManager,
Packit f0b94e
                               bool aHandleOpacity,
Packit f0b94e
                               imgDrawingParams& aImgParams)
Packit f0b94e
        : ctx(aCtx),
Packit f0b94e
          frame(aFrame),
Packit f0b94e
          dirtyRect(aDirtyRect),
Packit f0b94e
          borderArea(aBorderArea),
Packit f0b94e
          builder(aBuilder),
Packit f0b94e
          layerManager(aLayerManager),
Packit f0b94e
          handleOpacity(aHandleOpacity),
Packit f0b94e
          imgParams(aImgParams) {}
Packit f0b94e
  };
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Paint non-SVG frame with mask, clipPath and opacity effect.
Packit f0b94e
   */
Packit f0b94e
  static void PaintMaskAndClipPath(const PaintFramesParams& aParams);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Paint mask of non-SVG frame onto a given context, aParams.ctx.
Packit f0b94e
   * aParams.ctx must contain an A8 surface.
Packit f0b94e
   */
Packit f0b94e
  static void PaintMask(const PaintFramesParams& aParams);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Return true if all the mask resource of aFrame are ready.
Packit f0b94e
   */
Packit f0b94e
  static bool IsMaskResourceReady(nsIFrame* aFrame);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Paint non-SVG frame with filter and opacity effect.
Packit f0b94e
   */
Packit f0b94e
  static void PaintFilter(const PaintFramesParams& aParams);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * @param aRenderingContext the target rendering context in which the paint
Packit f0b94e
   * server will be rendered
Packit f0b94e
   * @param aTarget the target frame onto which the paint server will be
Packit f0b94e
   * rendered
Packit f0b94e
   * @param aPaintServer a first-continuation frame to use as the source
Packit f0b94e
   * @param aFilter a filter to be applied when scaling
Packit f0b94e
   * @param aDest the area the paint server image should be mapped to
Packit f0b94e
   * @param aFill the area to be filled with copies of the paint server image
Packit f0b94e
   * @param aAnchor a point in aFill which we will ensure is pixel-aligned in
Packit f0b94e
   * the output
Packit f0b94e
   * @param aDirty pixels outside this area may be skipped
Packit f0b94e
   * @param aPaintServerSize the size that would be filled when using
Packit f0b94e
   * background-repeat:no-repeat and background-size:auto. For normal background
Packit f0b94e
   * images, this would be the intrinsic size of the image; for gradients and
Packit f0b94e
   * patterns this would be the whole target frame fill area.
Packit f0b94e
   * @param aFlags pass FLAG_SYNC_DECODE_IMAGES and any images in the paint
Packit f0b94e
   * server will be decoding synchronously if they are not decoded already.
Packit f0b94e
   */
Packit f0b94e
  enum {
Packit f0b94e
    FLAG_SYNC_DECODE_IMAGES = 0x01,
Packit f0b94e
  };
Packit f0b94e
Packit f0b94e
  static already_AddRefed<gfxDrawable> DrawableFromPaintServer(
Packit f0b94e
      nsIFrame* aFrame, nsIFrame* aTarget, const nsSize& aPaintServerSize,
Packit f0b94e
      const mozilla::gfx::IntSize& aRenderSize, const DrawTarget* aDrawTarget,
Packit f0b94e
      const gfxMatrix& aContextMatrix, uint32_t aFlags);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * For non-SVG frames, this gives the offset to the frame's "user space".
Packit f0b94e
   * For SVG frames, this returns a zero offset.
Packit f0b94e
   */
Packit f0b94e
  static nsPoint GetOffsetToBoundingBox(nsIFrame* aFrame);
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
#endif /*NSSVGINTEGRATIONUTILS_H_*/