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
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#ifndef LAYOUT_SVG_SVGCLIPPATHFRAME_H_
|
|
|
|
#define LAYOUT_SVG_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"
|
2020-07-09 04:33:33 +03:00
|
|
|
#include "mozilla/SVGContainerFrame.h"
|
2005-01-25 06:55:03 +03:00
|
|
|
|
2014-10-31 23:08:53 +03:00
|
|
|
class gfxContext;
|
2012-03-02 12:28:59 +04:00
|
|
|
|
2019-04-16 10:24:49 +03:00
|
|
|
namespace mozilla {
|
2020-07-09 21:34:54 +03:00
|
|
|
class ISVGDisplayableFrame;
|
2019-04-16 10:24:49 +03:00
|
|
|
class PresShell;
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
nsIFrame* NS_NewSVGClipPathFrame(mozilla::PresShell* aPresShell,
|
|
|
|
mozilla::ComputedStyle* aStyle);
|
2016-01-26 20:27:44 +03:00
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2020-07-09 04:33:33 +03:00
|
|
|
class SVGClipPathFrame final : public SVGContainerFrame {
|
2020-07-07 16:49:30 +03:00
|
|
|
friend nsIFrame* ::NS_NewSVGClipPathFrame(mozilla::PresShell* aPresShell,
|
|
|
|
ComputedStyle* aStyle);
|
|
|
|
|
2020-07-15 13:37:55 +03:00
|
|
|
using Matrix = gfx::Matrix;
|
|
|
|
using SourceSurface = gfx::SourceSurface;
|
|
|
|
using imgDrawingParams = image::imgDrawingParams;
|
2016-01-26 20:27:44 +03:00
|
|
|
|
2007-09-07 13:30:51 +04:00
|
|
|
protected:
|
2020-07-07 16:49:30 +03:00
|
|
|
explicit SVGClipPathFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
|
2020-07-09 04:33:33 +03:00
|
|
|
: SVGContainerFrame(aStyle, aPresContext, kClassID),
|
2019-02-05 19:45:54 +03:00
|
|
|
mIsBeingProcessed(false) {
|
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:
|
2020-07-07 16:49:30 +03:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(SVGClipPathFrame)
|
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
|
|
|
|
2019-04-23 02:59:38 +03:00
|
|
|
virtual bool IsSVGTransformed(Matrix* aOwnTransforms,
|
|
|
|
Matrix* aFromParentTransforms) const override;
|
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
// SVGClipPathFrame 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 [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> GetClipMask(
|
2016-11-23 19:08:13 +03:00
|
|
|
gfxContext& aReferenceContext, nsIFrame* aClippedFrame,
|
2019-06-21 12:51:00 +03:00
|
|
|
const gfxMatrix& aMatrix, SourceSurface* aExtraMask = nullptr,
|
2016-11-23 19:08:13 +03:00
|
|
|
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 [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.
|
|
|
|
*/
|
|
|
|
void PaintClipMask(gfxContext& aMaskContext, nsIFrame* aClippedFrame,
|
2019-06-21 12:51:00 +03:00
|
|
|
const gfxMatrix& aMatrix, SourceSurface* aExtraMask,
|
2016-11-17 09:50:35 +03:00
|
|
|
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.
|
2020-07-09 21:34:54 +03:00
|
|
|
bool IsTrivial(ISVGDisplayableFrame** 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, 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 {
|
2020-07-01 11:29:29 +03:00
|
|
|
return MakeFrameName(u"SVGClipPath"_ns, aResult);
|
2006-07-21 18:58:57 +04:00
|
|
|
}
|
|
|
|
#endif
|
2006-01-20 20:00:43 +03:00
|
|
|
|
2017-04-30 18:30:08 +03:00
|
|
|
SVGBBox GetBBoxForClipPathFrame(const SVGBBox& aBBox,
|
2018-05-12 01:55:30 +03:00
|
|
|
const gfxMatrix& aMatrix, uint32_t aFlags);
|
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:
|
2020-07-09 04:33:33 +03:00
|
|
|
// SVGContainerFrame methods:
|
2016-01-28 12:30:47 +03:00
|
|
|
virtual gfxMatrix GetCanvasTM() override;
|
|
|
|
|
2016-11-29 22:41:16 +03:00
|
|
|
already_AddRefed<DrawTarget> CreateClipMask(gfxContext& aReferenceContext,
|
2020-07-07 16:49:30 +03:00
|
|
|
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,
|
2019-03-19 04:18:21 +03:00
|
|
|
gfxContext& aTarget);
|
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
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#endif // LAYOUT_SVG_SVGCLIPPATHFRAME_H_
|