michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef NSSVGINTEGRATIONUTILS_H_ michael@0: #define NSSVGINTEGRATIONUTILS_H_ michael@0: michael@0: #include "gfxMatrix.h" michael@0: #include "GraphicsFilter.h" michael@0: #include "gfxRect.h" michael@0: #include "nsAutoPtr.h" michael@0: michael@0: class gfxDrawable; michael@0: class nsDisplayList; michael@0: class nsDisplayListBuilder; michael@0: class nsIFrame; michael@0: class nsRenderingContext; michael@0: class nsIntRegion; michael@0: michael@0: struct nsRect; michael@0: struct nsIntRect; michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: class LayerManager; michael@0: } michael@0: } michael@0: michael@0: struct nsPoint; michael@0: struct nsSize; michael@0: michael@0: /** michael@0: * Integration of SVG effects (clipPath clipping, masking and filters) into michael@0: * regular display list based painting and hit-testing. michael@0: */ michael@0: class nsSVGIntegrationUtils MOZ_FINAL michael@0: { michael@0: public: michael@0: /** michael@0: * Returns true if SVG effects are currently applied to this frame. michael@0: */ michael@0: static bool michael@0: UsingEffectsForFrame(const nsIFrame* aFrame); michael@0: michael@0: /** michael@0: * Returns the size of the union of the border-box rects of all of michael@0: * aNonSVGFrame's continuations. michael@0: */ michael@0: static nsSize michael@0: GetContinuationUnionSize(nsIFrame* aNonSVGFrame); michael@0: michael@0: /** michael@0: * When SVG effects need to resolve percentage, userSpaceOnUse lengths, they michael@0: * need a coordinate context to resolve them against. This method provides michael@0: * that coordinate context for non-SVG frames with SVG effects applied to michael@0: * them. The gfxSize returned is the size of the union of all of the given michael@0: * frame's continuations' border boxes, converted to SVG user units (equal to michael@0: * CSS px units), as required by the SVG code. michael@0: */ michael@0: static mozilla::gfx::Size michael@0: GetSVGCoordContextForNonSVGFrame(nsIFrame* aNonSVGFrame); michael@0: michael@0: /** michael@0: * SVG effects such as SVG filters, masking and clipPath may require an SVG michael@0: * "bbox" for the element they're being applied to in order to make decisions michael@0: * about positioning, and to resolve various lengths against. This method michael@0: * provides the "bbox" for non-SVG frames. The bbox returned is in CSS px michael@0: * units, and is the union of all aNonSVGFrame's continuations' overflow michael@0: * areas, relative to the top-left of the union of all aNonSVGFrame's michael@0: * continuations' border box rects. michael@0: */ michael@0: static gfxRect michael@0: GetSVGBBoxForNonSVGFrame(nsIFrame* aNonSVGFrame); michael@0: michael@0: /** michael@0: * Used to adjust a frame's pre-effects visual overflow rect to take account michael@0: * of SVG effects. michael@0: * michael@0: * XXX This method will not do the right thing for frames with continuations. michael@0: * It really needs all the continuations to have been reflowed before being michael@0: * called, but we currently call it on each continuation as its overflow michael@0: * rects are set during the reflow of each particular continuation. Gecko's michael@0: * current reflow architecture does not allow us to set the overflow rects michael@0: * for a whole chain of continuations for a given element at the point when michael@0: * the last continuation is reflowed. See: michael@0: * http://groups.google.com/group/mozilla.dev.tech.layout/msg/6b179066f3051f65 michael@0: */ michael@0: static nsRect michael@0: ComputePostEffectsVisualOverflowRect(nsIFrame* aFrame, michael@0: const nsRect& aPreEffectsOverflowRect); michael@0: michael@0: /** michael@0: * Used to adjust the area of a frame that needs to be invalidated to take michael@0: * account of SVG effects. michael@0: * michael@0: * @param aFrame The effects frame. michael@0: * @param aToReferenceFrame The offset (in app units) from aFrame to its michael@0: * reference display item. michael@0: * @param aInvalidRegion The pre-effects invalid region in pixels relative to michael@0: * the reference display item. michael@0: * @return The post-effects invalid rect in pixels relative to the reference michael@0: * display item. michael@0: */ michael@0: static nsIntRegion michael@0: AdjustInvalidAreaForSVGEffects(nsIFrame* aFrame, const nsPoint& aToReferenceFrame, michael@0: const nsIntRegion& aInvalidRegion); michael@0: michael@0: /** michael@0: * Figure out which area of the source is needed given an area to michael@0: * repaint michael@0: */ michael@0: static nsRect michael@0: GetRequiredSourceForInvalidArea(nsIFrame* aFrame, const nsRect& aDamageRect); michael@0: michael@0: /** michael@0: * Returns true if the given point is not clipped out by effects. michael@0: * @param aPt in appunits relative to aFrame michael@0: */ michael@0: static bool michael@0: HitTestFrameForEffects(nsIFrame* aFrame, const nsPoint& aPt); michael@0: michael@0: /** michael@0: * Paint non-SVG frame with SVG effects. michael@0: */ michael@0: static void michael@0: PaintFramesWithEffects(nsRenderingContext* aCtx, michael@0: nsIFrame* aFrame, const nsRect& aDirtyRect, michael@0: nsDisplayListBuilder* aBuilder, michael@0: mozilla::layers::LayerManager* aManager); michael@0: michael@0: /** michael@0: * SVG frames expect to paint in SVG user units, which are equal to CSS px michael@0: * units. This method provides a transform matrix to multiply onto a michael@0: * gfxContext's current transform to convert the context's current units from michael@0: * its usual dev pixels to SVG user units/CSS px to keep the SVG code happy. michael@0: */ michael@0: static gfxMatrix michael@0: GetCSSPxToDevPxMatrix(nsIFrame* aNonSVGFrame); michael@0: michael@0: /** michael@0: * @param aRenderingContext the target rendering context in which the paint michael@0: * server will be rendered michael@0: * @param aTarget the target frame onto which the paint server will be michael@0: * rendered michael@0: * @param aPaintServer a first-continuation frame to use as the source michael@0: * @param aFilter a filter to be applied when scaling michael@0: * @param aDest the area the paint server image should be mapped to michael@0: * @param aFill the area to be filled with copies of the paint server image michael@0: * @param aAnchor a point in aFill which we will ensure is pixel-aligned in michael@0: * the output michael@0: * @param aDirty pixels outside this area may be skipped michael@0: * @param aPaintServerSize the size that would be filled when using michael@0: * background-repeat:no-repeat and background-size:auto. For normal background michael@0: * images, this would be the intrinsic size of the image; for gradients and michael@0: * patterns this would be the whole target frame fill area. michael@0: * @param aFlags pass FLAG_SYNC_DECODE_IMAGES and any images in the paint michael@0: * server will be decoding synchronously if they are not decoded already. michael@0: */ michael@0: enum { michael@0: FLAG_SYNC_DECODE_IMAGES = 0x01, michael@0: }; michael@0: michael@0: static already_AddRefed michael@0: DrawableFromPaintServer(nsIFrame* aFrame, michael@0: nsIFrame* aTarget, michael@0: const nsSize& aPaintServerSize, michael@0: const gfxIntSize& aRenderSize, michael@0: const gfxMatrix& aContextMatrix, michael@0: uint32_t aFlags); michael@0: }; michael@0: michael@0: #endif /*NSSVGINTEGRATIONUTILS_H_*/