1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/svg/nsSVGIntegrationUtils.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,173 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef NSSVGINTEGRATIONUTILS_H_ 1.10 +#define NSSVGINTEGRATIONUTILS_H_ 1.11 + 1.12 +#include "gfxMatrix.h" 1.13 +#include "GraphicsFilter.h" 1.14 +#include "gfxRect.h" 1.15 +#include "nsAutoPtr.h" 1.16 + 1.17 +class gfxDrawable; 1.18 +class nsDisplayList; 1.19 +class nsDisplayListBuilder; 1.20 +class nsIFrame; 1.21 +class nsRenderingContext; 1.22 +class nsIntRegion; 1.23 + 1.24 +struct nsRect; 1.25 +struct nsIntRect; 1.26 + 1.27 +namespace mozilla { 1.28 +namespace layers { 1.29 +class LayerManager; 1.30 +} 1.31 +} 1.32 + 1.33 +struct nsPoint; 1.34 +struct nsSize; 1.35 + 1.36 +/** 1.37 + * Integration of SVG effects (clipPath clipping, masking and filters) into 1.38 + * regular display list based painting and hit-testing. 1.39 + */ 1.40 +class nsSVGIntegrationUtils MOZ_FINAL 1.41 +{ 1.42 +public: 1.43 + /** 1.44 + * Returns true if SVG effects are currently applied to this frame. 1.45 + */ 1.46 + static bool 1.47 + UsingEffectsForFrame(const nsIFrame* aFrame); 1.48 + 1.49 + /** 1.50 + * Returns the size of the union of the border-box rects of all of 1.51 + * aNonSVGFrame's continuations. 1.52 + */ 1.53 + static nsSize 1.54 + GetContinuationUnionSize(nsIFrame* aNonSVGFrame); 1.55 + 1.56 + /** 1.57 + * When SVG effects need to resolve percentage, userSpaceOnUse lengths, they 1.58 + * need a coordinate context to resolve them against. This method provides 1.59 + * that coordinate context for non-SVG frames with SVG effects applied to 1.60 + * them. The gfxSize returned is the size of the union of all of the given 1.61 + * frame's continuations' border boxes, converted to SVG user units (equal to 1.62 + * CSS px units), as required by the SVG code. 1.63 + */ 1.64 + static mozilla::gfx::Size 1.65 + GetSVGCoordContextForNonSVGFrame(nsIFrame* aNonSVGFrame); 1.66 + 1.67 + /** 1.68 + * SVG effects such as SVG filters, masking and clipPath may require an SVG 1.69 + * "bbox" for the element they're being applied to in order to make decisions 1.70 + * about positioning, and to resolve various lengths against. This method 1.71 + * provides the "bbox" for non-SVG frames. The bbox returned is in CSS px 1.72 + * units, and is the union of all aNonSVGFrame's continuations' overflow 1.73 + * areas, relative to the top-left of the union of all aNonSVGFrame's 1.74 + * continuations' border box rects. 1.75 + */ 1.76 + static gfxRect 1.77 + GetSVGBBoxForNonSVGFrame(nsIFrame* aNonSVGFrame); 1.78 + 1.79 + /** 1.80 + * Used to adjust a frame's pre-effects visual overflow rect to take account 1.81 + * of SVG effects. 1.82 + * 1.83 + * XXX This method will not do the right thing for frames with continuations. 1.84 + * It really needs all the continuations to have been reflowed before being 1.85 + * called, but we currently call it on each continuation as its overflow 1.86 + * rects are set during the reflow of each particular continuation. Gecko's 1.87 + * current reflow architecture does not allow us to set the overflow rects 1.88 + * for a whole chain of continuations for a given element at the point when 1.89 + * the last continuation is reflowed. See: 1.90 + * http://groups.google.com/group/mozilla.dev.tech.layout/msg/6b179066f3051f65 1.91 + */ 1.92 + static nsRect 1.93 + ComputePostEffectsVisualOverflowRect(nsIFrame* aFrame, 1.94 + const nsRect& aPreEffectsOverflowRect); 1.95 + 1.96 + /** 1.97 + * Used to adjust the area of a frame that needs to be invalidated to take 1.98 + * account of SVG effects. 1.99 + * 1.100 + * @param aFrame The effects frame. 1.101 + * @param aToReferenceFrame The offset (in app units) from aFrame to its 1.102 + * reference display item. 1.103 + * @param aInvalidRegion The pre-effects invalid region in pixels relative to 1.104 + * the reference display item. 1.105 + * @return The post-effects invalid rect in pixels relative to the reference 1.106 + * display item. 1.107 + */ 1.108 + static nsIntRegion 1.109 + AdjustInvalidAreaForSVGEffects(nsIFrame* aFrame, const nsPoint& aToReferenceFrame, 1.110 + const nsIntRegion& aInvalidRegion); 1.111 + 1.112 + /** 1.113 + * Figure out which area of the source is needed given an area to 1.114 + * repaint 1.115 + */ 1.116 + static nsRect 1.117 + GetRequiredSourceForInvalidArea(nsIFrame* aFrame, const nsRect& aDamageRect); 1.118 + 1.119 + /** 1.120 + * Returns true if the given point is not clipped out by effects. 1.121 + * @param aPt in appunits relative to aFrame 1.122 + */ 1.123 + static bool 1.124 + HitTestFrameForEffects(nsIFrame* aFrame, const nsPoint& aPt); 1.125 + 1.126 + /** 1.127 + * Paint non-SVG frame with SVG effects. 1.128 + */ 1.129 + static void 1.130 + PaintFramesWithEffects(nsRenderingContext* aCtx, 1.131 + nsIFrame* aFrame, const nsRect& aDirtyRect, 1.132 + nsDisplayListBuilder* aBuilder, 1.133 + mozilla::layers::LayerManager* aManager); 1.134 + 1.135 + /** 1.136 + * SVG frames expect to paint in SVG user units, which are equal to CSS px 1.137 + * units. This method provides a transform matrix to multiply onto a 1.138 + * gfxContext's current transform to convert the context's current units from 1.139 + * its usual dev pixels to SVG user units/CSS px to keep the SVG code happy. 1.140 + */ 1.141 + static gfxMatrix 1.142 + GetCSSPxToDevPxMatrix(nsIFrame* aNonSVGFrame); 1.143 + 1.144 + /** 1.145 + * @param aRenderingContext the target rendering context in which the paint 1.146 + * server will be rendered 1.147 + * @param aTarget the target frame onto which the paint server will be 1.148 + * rendered 1.149 + * @param aPaintServer a first-continuation frame to use as the source 1.150 + * @param aFilter a filter to be applied when scaling 1.151 + * @param aDest the area the paint server image should be mapped to 1.152 + * @param aFill the area to be filled with copies of the paint server image 1.153 + * @param aAnchor a point in aFill which we will ensure is pixel-aligned in 1.154 + * the output 1.155 + * @param aDirty pixels outside this area may be skipped 1.156 + * @param aPaintServerSize the size that would be filled when using 1.157 + * background-repeat:no-repeat and background-size:auto. For normal background 1.158 + * images, this would be the intrinsic size of the image; for gradients and 1.159 + * patterns this would be the whole target frame fill area. 1.160 + * @param aFlags pass FLAG_SYNC_DECODE_IMAGES and any images in the paint 1.161 + * server will be decoding synchronously if they are not decoded already. 1.162 + */ 1.163 + enum { 1.164 + FLAG_SYNC_DECODE_IMAGES = 0x01, 1.165 + }; 1.166 + 1.167 + static already_AddRefed<gfxDrawable> 1.168 + DrawableFromPaintServer(nsIFrame* aFrame, 1.169 + nsIFrame* aTarget, 1.170 + const nsSize& aPaintServerSize, 1.171 + const gfxIntSize& aRenderSize, 1.172 + const gfxMatrix& aContextMatrix, 1.173 + uint32_t aFlags); 1.174 +}; 1.175 + 1.176 +#endif /*NSSVGINTEGRATIONUTILS_H_*/