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/. */
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#ifndef LAYOUT_SVG_SVGGEOMETRYFRAME_H_
|
|
|
|
#define LAYOUT_SVG_SVGGEOMETRYFRAME_H_
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2012-09-14 20:10:08 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2020-07-09 21:34:54 +03:00
|
|
|
#include "mozilla/ISVGDisplayableFrame.h"
|
2012-03-20 16:15:55 +04:00
|
|
|
#include "gfxMatrix.h"
|
|
|
|
#include "gfxRect.h"
|
2020-05-15 21:49:52 +03:00
|
|
|
#include "nsDisplayList.h"
|
2020-07-07 01:38:11 +03:00
|
|
|
#include "nsIFrame.h"
|
2012-03-20 16:15:55 +04:00
|
|
|
#include "nsLiteralString.h"
|
|
|
|
#include "nsQueryFrame.h"
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2014-09-30 21:08:13 +04:00
|
|
|
namespace mozilla {
|
2020-06-24 01:59:34 +03:00
|
|
|
|
|
|
|
class DisplaySVGGeometry;
|
|
|
|
class PresShell;
|
2016-12-18 14:11:47 +03:00
|
|
|
class SVGGeometryFrame;
|
2018-08-13 15:03:35 +03:00
|
|
|
class SVGMarkerObserver;
|
2020-06-24 01:59:34 +03:00
|
|
|
|
2014-09-30 21:08:13 +04:00
|
|
|
namespace gfx {
|
|
|
|
class DrawTarget;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
2020-06-24 01:59:34 +03:00
|
|
|
|
2020-07-09 04:33:33 +03:00
|
|
|
namespace image {
|
|
|
|
struct imgDrawingParams;
|
|
|
|
} // namespace image
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2014-09-30 21:08:13 +04:00
|
|
|
|
2012-03-20 16:15:55 +04:00
|
|
|
class gfxContext;
|
2017-10-03 01:05:19 +03:00
|
|
|
class nsAtom;
|
2012-03-20 16:15:55 +04:00
|
|
|
class nsIFrame;
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2013-09-07 06:15:49 +04:00
|
|
|
struct nsRect;
|
2012-03-20 16:15:55 +04:00
|
|
|
|
2019-04-16 10:24:49 +03:00
|
|
|
nsIFrame* NS_NewSVGGeometryFrame(mozilla::PresShell* aPresShell,
|
2018-03-22 21:20:41 +03:00
|
|
|
mozilla::ComputedStyle* aStyle);
|
2016-12-18 14:11:47 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2020-07-09 21:34:54 +03:00
|
|
|
class SVGGeometryFrame : public nsIFrame, public ISVGDisplayableFrame {
|
2020-07-15 13:37:55 +03:00
|
|
|
using DrawTarget = gfx::DrawTarget;
|
2014-09-30 21:08:13 +04:00
|
|
|
|
2019-04-16 10:24:49 +03:00
|
|
|
friend nsIFrame* ::NS_NewSVGGeometryFrame(mozilla::PresShell* aPresShell,
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* aStyle);
|
2012-07-20 22:12:29 +04:00
|
|
|
|
2020-06-24 01:59:34 +03:00
|
|
|
friend class DisplaySVGGeometry;
|
2012-07-20 22:12:29 +04:00
|
|
|
|
2007-07-24 13:05:37 +04:00
|
|
|
protected:
|
2019-02-05 19:45:54 +03:00
|
|
|
SVGGeometryFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
|
|
|
|
nsIFrame::ClassID aID = kClassID)
|
2020-07-07 01:29:42 +03:00
|
|
|
: nsIFrame(aStyle, aPresContext, aID) {
|
2014-01-04 12:29:02 +04:00
|
|
|
AddStateBits(NS_FRAME_SVG_LAYOUT | NS_FRAME_MAY_BE_TRANSFORMED);
|
2012-05-17 08:05:09 +04:00
|
|
|
}
|
2006-06-21 19:42:28 +04:00
|
|
|
|
2007-07-24 13:05:37 +04:00
|
|
|
public:
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_DECL_QUERYFRAME
|
2017-05-26 13:11:11 +03:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(SVGGeometryFrame)
|
2001-12-12 10:59:31 +03:00
|
|
|
|
|
|
|
// nsIFrame interface:
|
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;
|
2014-01-04 12:29:02 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool IsFrameOfType(uint32_t aFlags) const override {
|
2018-08-08 01:02:07 +03:00
|
|
|
if (aFlags & eSupportsContainLayoutAndPaint) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-07 01:29:42 +03:00
|
|
|
return nsIFrame::IsFrameOfType(aFlags & ~nsIFrame::eSVG);
|
2014-01-04 12:29:02 +04:00
|
|
|
}
|
|
|
|
|
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;
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
virtual void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override;
|
2013-08-14 13:51:00 +04:00
|
|
|
|
2013-12-30 10:50:17 +04:00
|
|
|
virtual bool IsSVGTransformed(
|
|
|
|
Matrix* aOwnTransforms = nullptr,
|
2015-03-21 19:28:04 +03:00
|
|
|
Matrix* aFromParentTransforms = nullptr) const override;
|
2012-05-17 08:05:09 +04: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 {
|
2016-12-18 14:11:47 +03:00
|
|
|
return MakeFrameName(u"SVGGeometry"_ns, aResult);
|
2005-04-01 23:56:08 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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 22:12:29 +04:00
|
|
|
|
2016-12-18 14:11:47 +03:00
|
|
|
// SVGGeometryFrame methods
|
2014-09-08 15:28:50 +04:00
|
|
|
gfxMatrix GetCanvasTM();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2022-02-22 00:57:03 +03:00
|
|
|
bool IsInvisible() const;
|
|
|
|
|
2005-04-01 23:56:08 +04:00
|
|
|
protected:
|
2020-07-09 21:34:54 +03:00
|
|
|
// ISVGDisplayableFrame interface:
|
2017-05-18 23:03:41 +03:00
|
|
|
virtual void PaintSVG(gfxContext& aContext, const gfxMatrix& aTransform,
|
|
|
|
imgDrawingParams& aImgParams,
|
|
|
|
const nsIntRect* aDirtyRect = nullptr) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsIFrame* GetFrameForPoint(const gfxPoint& aPoint) override;
|
|
|
|
virtual void ReflowSVG() override;
|
|
|
|
virtual void NotifySVGChanged(uint32_t aFlags) override;
|
2013-12-30 10:50:17 +04:00
|
|
|
virtual SVGBBox GetBBoxContribution(const Matrix& aToBBoxUserspace,
|
2015-03-21 19:28:04 +03:00
|
|
|
uint32_t aFlags) override;
|
|
|
|
virtual bool IsDisplayContainer() override { return false; }
|
2006-06-29 02:04:48 +04:00
|
|
|
|
2014-01-04 12:29:02 +04:00
|
|
|
/**
|
|
|
|
* This function returns a set of bit flags indicating which parts of the
|
|
|
|
* element (fill, stroke, bounds) should intercept pointer events. It takes
|
|
|
|
* into account the type of element and the value of the 'pointer-events'
|
|
|
|
* property on the element.
|
|
|
|
*/
|
|
|
|
virtual uint16_t GetHitTestFlags();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2006-06-21 19:42:28 +04:00
|
|
|
private:
|
2013-01-13 03:27:53 +04:00
|
|
|
enum { eRenderFill = 1, eRenderStroke = 2 };
|
2017-05-18 23:03:41 +03:00
|
|
|
void Render(gfxContext* aContext, uint32_t aRenderComponents,
|
|
|
|
const gfxMatrix& aTransform, imgDrawingParams& aImgParams);
|
2014-08-29 23:42:07 +04:00
|
|
|
|
2020-05-15 21:49:52 +03:00
|
|
|
virtual bool CreateWebRenderCommands(
|
|
|
|
mozilla::wr::DisplayListBuilder& aBuilder,
|
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
|
|
|
const mozilla::layers::StackingContextHelper& aSc,
|
|
|
|
mozilla::layers::RenderRootStateManager* aManager,
|
2020-06-24 01:59:34 +03:00
|
|
|
nsDisplayListBuilder* aDisplayListBuilder, DisplaySVGGeometry* aItem,
|
2022-02-23 16:37:39 +03:00
|
|
|
bool aDryRun);
|
2014-08-29 23:42:07 +04:00
|
|
|
/**
|
|
|
|
* @param aMatrix The transform that must be multiplied onto aContext to
|
|
|
|
* establish this frame's SVG user space.
|
|
|
|
*/
|
2019-04-27 10:57:50 +03:00
|
|
|
void PaintMarkers(gfxContext& aContext, const gfxMatrix& aTransform,
|
2017-05-18 23:03:41 +03:00
|
|
|
imgDrawingParams& aImgParams);
|
2020-10-03 07:32:21 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the stroke width that markers should use, accounting for
|
|
|
|
* non-scaling stroke.
|
|
|
|
*/
|
|
|
|
float GetStrokeWidthForMarkers();
|
2001-12-12 10:59:31 +03:00
|
|
|
};
|
2020-05-15 21:49:52 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Display list item:
|
|
|
|
|
2020-06-24 01:59:34 +03:00
|
|
|
class DisplaySVGGeometry final : public nsPaintedDisplayItem {
|
2020-07-15 13:37:55 +03:00
|
|
|
using imgDrawingParams = image::imgDrawingParams;
|
2020-05-15 21:49:52 +03:00
|
|
|
|
|
|
|
public:
|
2020-06-24 01:59:34 +03:00
|
|
|
DisplaySVGGeometry(nsDisplayListBuilder* aBuilder, SVGGeometryFrame* aFrame)
|
2020-05-15 21:49:52 +03:00
|
|
|
: nsPaintedDisplayItem(aBuilder, aFrame) {
|
2020-06-24 01:59:34 +03:00
|
|
|
MOZ_COUNT_CTOR(DisplaySVGGeometry);
|
2020-05-15 21:49:52 +03:00
|
|
|
MOZ_ASSERT(aFrame, "Must have a frame!");
|
|
|
|
}
|
2021-07-19 14:28:20 +03:00
|
|
|
|
|
|
|
MOZ_COUNTED_DTOR_OVERRIDE(DisplaySVGGeometry)
|
2020-05-15 21:49:52 +03:00
|
|
|
|
2020-06-24 01:59:34 +03:00
|
|
|
NS_DISPLAY_DECL_NAME("DisplaySVGGeometry", TYPE_SVG_GEOMETRY)
|
2020-05-15 21:49:52 +03:00
|
|
|
|
|
|
|
virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState,
|
|
|
|
nsTArray<nsIFrame*>* aOutFrames) override;
|
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
|
|
|
|
|
|
|
|
nsDisplayItemGeometry* AllocateGeometry(
|
|
|
|
nsDisplayListBuilder* aBuilder) override {
|
|
|
|
return new nsDisplayItemGenericImageGeometry(this, aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
|
|
nsRegion* aInvalidRegion) const override;
|
|
|
|
|
|
|
|
// Whether this part of the SVG should be natively handled by webrender,
|
|
|
|
// potentially becoming an "active layer" inside a blob image.
|
|
|
|
bool ShouldBeActive(mozilla::wr::DisplayListBuilder& aBuilder,
|
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
|
|
|
const mozilla::layers::StackingContextHelper& aSc,
|
|
|
|
mozilla::layers::RenderRootStateManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder) {
|
|
|
|
// We delegate this question to the parent frame to take advantage of
|
|
|
|
// the SVGGeometryFrame inheritance hierarchy which provides actual
|
|
|
|
// implementation details. The dryRun flag prevents serious side-effects.
|
|
|
|
auto* frame = static_cast<SVGGeometryFrame*>(mFrame);
|
|
|
|
return frame->CreateWebRenderCommands(aBuilder, aResources, aSc, aManager,
|
|
|
|
aDisplayListBuilder, this,
|
|
|
|
/*aDryRun=*/true);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool CreateWebRenderCommands(
|
|
|
|
mozilla::wr::DisplayListBuilder& aBuilder,
|
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
|
|
|
const mozilla::layers::StackingContextHelper& aSc,
|
|
|
|
mozilla::layers::RenderRootStateManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder) override {
|
|
|
|
// We delegate this question to the parent frame to take advantage of
|
|
|
|
// the SVGGeometryFrame inheritance hierarchy which provides actual
|
|
|
|
// implementation details.
|
|
|
|
auto* frame = static_cast<SVGGeometryFrame*>(mFrame);
|
|
|
|
bool result = frame->CreateWebRenderCommands(aBuilder, aResources, aSc,
|
|
|
|
aManager, aDisplayListBuilder,
|
|
|
|
this, /*aDryRun=*/false);
|
|
|
|
MOZ_ASSERT(result, "ShouldBeActive inconsistent with CreateWRCommands?");
|
|
|
|
return result;
|
|
|
|
}
|
2022-02-22 00:57:03 +03:00
|
|
|
|
|
|
|
bool IsInvisible() const override {
|
|
|
|
auto* frame = static_cast<SVGGeometryFrame*>(mFrame);
|
|
|
|
return frame->IsInvisible();
|
|
|
|
}
|
2020-05-15 21:49:52 +03:00
|
|
|
};
|
2021-07-19 14:28:20 +03:00
|
|
|
|
2016-12-18 14:11:47 +03:00
|
|
|
} // namespace mozilla
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#endif // LAYOUT_SVG_SVGGEOMETRYFRAME_H_
|