2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-01-25 06:55:03 +03:00
|
|
|
|
2006-01-20 20:00:43 +03:00
|
|
|
#ifndef __NS_SVGCLIPPATHFRAME_H__
|
|
|
|
#define __NS_SVGCLIPPATHFRAME_H__
|
2005-01-25 06:55:03 +03:00
|
|
|
|
2012-03-20 16:15:55 +04:00
|
|
|
#include "gfxMatrix.h"
|
2016-03-09 13:26:48 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
2006-07-21 18:58:57 +04:00
|
|
|
#include "nsSVGContainerFrame.h"
|
2012-03-18 14:32:02 +04:00
|
|
|
#include "nsSVGUtils.h"
|
2005-01-25 06:55:03 +03:00
|
|
|
|
2014-10-31 23:08:53 +03:00
|
|
|
class gfxContext;
|
2017-02-09 21:24:31 +03:00
|
|
|
class nsSVGDisplayableFrame;
|
2012-03-02 12:28:59 +04:00
|
|
|
|
2017-04-30 18:30:08 +03:00
|
|
|
class nsSVGClipPathFrame final : public nsSVGContainerFrame
|
2006-07-21 18:58:57 +04:00
|
|
|
{
|
|
|
|
friend nsIFrame*
|
2009-01-19 21:31:34 +03:00
|
|
|
NS_NewSVGClipPathFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
2016-01-26 20:27:44 +03:00
|
|
|
|
|
|
|
typedef mozilla::gfx::Matrix Matrix;
|
|
|
|
typedef mozilla::gfx::SourceSurface SourceSurface;
|
2017-05-18 23:03:45 +03:00
|
|
|
typedef mozilla::image::imgDrawingParams imgDrawingParams;
|
2016-01-26 20:27:44 +03:00
|
|
|
|
2007-09-07 13:30:51 +04:00
|
|
|
protected:
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit nsSVGClipPathFrame(nsStyleContext* aContext)
|
2017-05-26 13:11:11 +03:00
|
|
|
: nsSVGContainerFrame(aContext, kClassID)
|
2017-02-17 16:15:18 +03:00
|
|
|
, mIsBeingProcessed(false)
|
2012-03-10 23:28:06 +04:00
|
|
|
{
|
2013-07-12 11:13:07 +04:00
|
|
|
AddStateBits(NS_FRAME_IS_NONDISPLAY);
|
2012-03-10 23:28:06 +04:00
|
|
|
}
|
2006-07-21 18:58:57 +04:00
|
|
|
|
2007-09-07 13:30:51 +04:00
|
|
|
public:
|
2017-05-26 13:11:11 +03:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(nsSVGClipPathFrame)
|
2009-09-12 20:49:24 +04:00
|
|
|
|
2012-07-20 20:41:29 +04:00
|
|
|
// nsIFrame methods:
|
2013-02-14 15:12:27 +04:00
|
|
|
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
2015-03-21 19:28:04 +03:00
|
|
|
const nsDisplayListSet& aLists) override {}
|
2012-07-20 20:41:29 +04:00
|
|
|
|
2006-07-21 18:58:57 +04:00
|
|
|
// nsSVGClipPathFrame methods:
|
2014-08-13 16:36:32 +04:00
|
|
|
|
|
|
|
/**
|
2016-01-26 20:27:44 +03:00
|
|
|
* Applies the clipPath by pushing a clip path onto the DrawTarget.
|
|
|
|
*
|
|
|
|
* This method must only be used if IsTrivial() returns true, otherwise use
|
|
|
|
* GetClipMask.
|
2014-08-13 16:36:32 +04:00
|
|
|
*
|
2016-01-26 20:27:44 +03:00
|
|
|
* @param aContext The context that the clip path is to be applied to.
|
|
|
|
* @param aClippedFrame The/an nsIFrame of the element that references this
|
|
|
|
* clipPath that is currently being processed.
|
|
|
|
* @param aMatrix The transform from aClippedFrame's user space to aContext's
|
|
|
|
* current transform.
|
2014-08-13 16:36:32 +04:00
|
|
|
*/
|
2016-01-26 20:27:44 +03:00
|
|
|
void ApplyClipPath(gfxContext& aContext,
|
|
|
|
nsIFrame* aClippedFrame,
|
|
|
|
const gfxMatrix &aMatrix);
|
2005-01-25 06:55:03 +03:00
|
|
|
|
2015-11-11 18:15:39 +03:00
|
|
|
/**
|
2016-01-26 20:27:44 +03:00
|
|
|
* Returns an alpha mask surface containing the clipping geometry.
|
|
|
|
*
|
|
|
|
* This method must only be used if IsTrivial() returns false, otherwise use
|
|
|
|
* ApplyClipPath.
|
|
|
|
*
|
|
|
|
* @param aReferenceContext Used to determine the backend for and size of the
|
|
|
|
* returned SourceSurface, the size being limited to the device space clip
|
|
|
|
* extents on the context.
|
|
|
|
* @param aClippedFrame The/an nsIFrame of the element that references this
|
|
|
|
* clipPath that is currently being processed.
|
|
|
|
* @param aMatrix The transform from aClippedFrame's user space to aContext's
|
|
|
|
* current transform.
|
|
|
|
* @param [out] aMaskTransform The transform to use with the returned
|
|
|
|
* surface.
|
|
|
|
* @param [in, optional] aExtraMask An extra surface that the returned
|
|
|
|
* surface should be masked with.
|
|
|
|
* @param [in, optional] aExtraMasksTransform The transform to use with
|
|
|
|
* aExtraMask. Should be passed when aExtraMask is passed.
|
2015-11-11 18:15:39 +03:00
|
|
|
*/
|
2017-05-18 23:03:45 +03:00
|
|
|
already_AddRefed<SourceSurface>
|
2016-11-23 19:08:13 +03:00
|
|
|
GetClipMask(gfxContext& aReferenceContext, nsIFrame* aClippedFrame,
|
|
|
|
const gfxMatrix& aMatrix, Matrix* aMaskTransform,
|
|
|
|
SourceSurface* aExtraMask = nullptr,
|
|
|
|
const Matrix& aExtraMasksTransform = Matrix());
|
2015-11-11 18:15:39 +03:00
|
|
|
|
2016-11-17 09:50:35 +03:00
|
|
|
/**
|
|
|
|
* Paint mask directly onto a given context(aMaskContext).
|
|
|
|
*
|
|
|
|
* @param aMaskContext The target of mask been painting on.
|
|
|
|
* @param aClippedFrame The/an nsIFrame of the element that references this
|
|
|
|
* clipPath that is currently being processed.
|
|
|
|
* @param aMatrix The transform from aClippedFrame's user space to
|
|
|
|
* current transform.
|
|
|
|
* @param [out] aMaskTransform The transform to use with the returned
|
|
|
|
* surface.
|
|
|
|
* @param [in, optional] aExtraMask An extra surface that the returned
|
|
|
|
* surface should be masked with.
|
|
|
|
* @param [in, optional] aExtraMasksTransform The transform to use with
|
|
|
|
* aExtraMask. Should be passed when aExtraMask is passed.
|
|
|
|
*/
|
2017-05-18 23:03:45 +03:00
|
|
|
void
|
2016-11-17 09:50:35 +03:00
|
|
|
PaintClipMask(gfxContext& aMaskContext, nsIFrame* aClippedFrame,
|
|
|
|
const gfxMatrix& aMatrix, Matrix* aMaskTransform,
|
|
|
|
SourceSurface* aExtraMask, const Matrix& aExtraMasksTransform);
|
|
|
|
|
2014-08-07 11:09:31 +04:00
|
|
|
/**
|
|
|
|
* aPoint is expected to be in aClippedFrame's SVG user space.
|
|
|
|
*/
|
|
|
|
bool PointIsInsideClipPath(nsIFrame* aClippedFrame, const gfxPoint &aPoint);
|
2005-01-25 06:55:03 +03:00
|
|
|
|
2006-01-20 20:00:43 +03:00
|
|
|
// Check if this clipPath is made up of more than one geometry object.
|
|
|
|
// If so, the clipping API in cairo isn't enough and we need to use
|
|
|
|
// mask based clipping.
|
2017-02-09 21:24:31 +03:00
|
|
|
bool IsTrivial(nsSVGDisplayableFrame **aSingleChild = nullptr);
|
2005-01-25 06:55:03 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsValid();
|
2010-03-02 12:31:07 +03:00
|
|
|
|
2010-03-24 19:54:48 +03:00
|
|
|
// nsIFrame interface:
|
2014-02-18 11:47:48 +04:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute,
|
2015-03-21 19:28:04 +03:00
|
|
|
int32_t aModType) override;
|
2010-03-24 19:54:48 +03:00
|
|
|
|
2014-05-25 02:20:40 +04:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsIFrame* aPrevInFlow) override;
|
2009-01-19 21:31:34 +03:00
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override
|
2006-07-21 18:58:57 +04:00
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGClipPath"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
2006-01-20 20:00:43 +03:00
|
|
|
|
2017-04-30 18:30:08 +03:00
|
|
|
SVGBBox GetBBoxForClipPathFrame(const SVGBBox& aBBox,
|
|
|
|
const gfxMatrix& aMatrix);
|
2014-05-13 05:24:35 +04:00
|
|
|
|
2014-08-07 11:09:31 +04:00
|
|
|
/**
|
|
|
|
* If the clipPath element transforms its children due to
|
|
|
|
* clipPathUnits="objectBoundingBox" being set on it and/or due to the
|
|
|
|
* 'transform' attribute being set on it, this function returns the resulting
|
|
|
|
* transform.
|
|
|
|
*/
|
|
|
|
gfxMatrix GetClipPathTransform(nsIFrame* aClippedFrame);
|
|
|
|
|
2016-01-28 12:30:47 +03:00
|
|
|
private:
|
|
|
|
|
|
|
|
// nsSVGContainerFrame methods:
|
|
|
|
virtual gfxMatrix GetCanvasTM() override;
|
|
|
|
|
2016-11-29 22:41:16 +03:00
|
|
|
already_AddRefed<DrawTarget> CreateClipMask(gfxContext& aReferenceContext,
|
|
|
|
mozilla::gfx::IntPoint& aOffset);
|
2016-11-17 09:50:35 +03:00
|
|
|
|
2017-05-18 23:03:41 +03:00
|
|
|
void PaintFrameIntoMask(nsIFrame *aFrame, nsIFrame* aClippedFrame,
|
|
|
|
gfxContext& aTarget, const gfxMatrix& aMatrix);
|
2016-11-16 11:58:59 +03:00
|
|
|
|
2016-01-28 12:30:47 +03:00
|
|
|
// Set, during a GetClipMask() call, to the transform that still needs to be
|
|
|
|
// concatenated to the transform of the DrawTarget that was passed to
|
|
|
|
// GetClipMask in order to establish the coordinate space that the clipPath
|
|
|
|
// establishes for its contents (i.e. including applying 'clipPathUnits' and
|
|
|
|
// any 'transform' attribute set on the clipPath) specifically for clipping
|
|
|
|
// the frame that was passed to GetClipMask at that moment in time. This is
|
|
|
|
// set so that if our GetCanvasTM method is called while GetClipMask is
|
|
|
|
// painting its children, the returned matrix will include the transforms
|
|
|
|
// that should be used when creating the mask for the frame passed to
|
|
|
|
// GetClipMask.
|
|
|
|
//
|
|
|
|
// Note: The removal of GetCanvasTM is nearly complete, so our GetCanvasTM
|
|
|
|
// may not even be called soon/any more.
|
2014-08-13 16:34:52 +04:00
|
|
|
gfxMatrix mMatrixForChildren;
|
2006-07-21 18:58:57 +04:00
|
|
|
|
2017-02-17 16:15:18 +03:00
|
|
|
// Flag used to indicate whether a methods that may reenter due to
|
|
|
|
// following a reference to another instance is currently executing.
|
|
|
|
bool mIsBeingProcessed;
|
2006-07-21 18:58:57 +04:00
|
|
|
};
|
2005-11-11 17:36:26 +03:00
|
|
|
|
2006-01-20 20:00:43 +03:00
|
|
|
#endif
|