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/. */
|
2008-01-03 17:30:02 +03:00
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Keep in (case-insensitive) order:
|
|
|
|
#include "gfxRect.h"
|
2017-08-30 16:14:46 +03:00
|
|
|
#include "SVGObserverUtils.h"
|
2008-01-03 17:30:02 +03:00
|
|
|
#include "nsSVGGFrame.h"
|
2019-04-16 10:24:49 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2013-01-06 10:25:54 +04:00
|
|
|
#include "mozilla/dom/SVGSwitchElement.h"
|
2012-03-18 14:32:02 +04:00
|
|
|
#include "nsSVGUtils.h"
|
2019-03-22 00:17:18 +03:00
|
|
|
#include "SVGTextFrame.h"
|
|
|
|
#include "nsSVGContainerFrame.h"
|
2008-01-03 17:30:02 +03:00
|
|
|
|
2018-11-13 01:20:52 +03:00
|
|
|
using namespace mozilla;
|
2013-12-30 10:50:07 +04:00
|
|
|
using namespace mozilla::gfx;
|
2017-03-08 07:07:00 +03:00
|
|
|
using namespace mozilla::image;
|
2013-12-30 10:50:07 +04:00
|
|
|
|
2017-04-30 18:30:08 +03:00
|
|
|
class nsSVGSwitchFrame final : public nsSVGGFrame {
|
2019-04-16 10:24:49 +03:00
|
|
|
friend nsIFrame* NS_NewSVGSwitchFrame(mozilla::PresShell* aPresShell,
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* aStyle);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-01-03 17:30:02 +03:00
|
|
|
protected:
|
2019-02-05 19:45:54 +03:00
|
|
|
explicit nsSVGSwitchFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
|
|
|
|
: nsSVGGFrame(aStyle, aPresContext, kClassID) {}
|
2008-01-03 17:30:02 +03:00
|
|
|
|
|
|
|
public:
|
2017-05-26 13:11:11 +03:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(nsSVGSwitchFrame)
|
2009-09-12 20:49:24 +04:00
|
|
|
|
2009-01-19 21:31:34 +03:00
|
|
|
#ifdef DEBUG
|
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
|
|
|
#endif
|
|
|
|
|
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 {
|
2008-01-03 17:30:02 +03:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGSwitch"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
2008-07-13 15:30:48 +04:00
|
|
|
|
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
|
|
|
|
2017-02-09 21:24:31 +03:00
|
|
|
// nsSVGDisplayableFrame interface:
|
2017-05-18 23:03:41 +03:00
|
|
|
virtual void PaintSVG(gfxContext& aContext, const gfxMatrix& aTransform,
|
2019-04-27 10:57:50 +03:00
|
|
|
imgDrawingParams& aImgParams,
|
2017-05-18 23:03:41 +03:00
|
|
|
const nsIntRect* aDirtyRect = nullptr) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
nsIFrame* GetFrameForPoint(const gfxPoint& aPoint) override;
|
|
|
|
virtual void ReflowSVG() override;
|
2013-12-30 10:50:07 +04:00
|
|
|
virtual SVGBBox GetBBoxContribution(const Matrix& aToBBoxUserspace,
|
2015-03-21 19:28:04 +03:00
|
|
|
uint32_t aFlags) override;
|
2008-07-13 15:30:48 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsIFrame* GetActiveChildFrame();
|
2019-03-22 00:17:18 +03:00
|
|
|
void ReflowAllSVGTextFramesInsideNonActiveChildren(nsIFrame* aActiveChild);
|
|
|
|
static void AlwaysReflowSVGTextFrameDoForOneKid(nsIFrame* aKid);
|
2008-01-03 17:30:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2019-04-16 10:24:49 +03:00
|
|
|
nsIFrame* NS_NewSVGSwitchFrame(PresShell* aPresShell, ComputedStyle* aStyle) {
|
2019-02-05 19:45:54 +03:00
|
|
|
return new (aPresShell)
|
|
|
|
nsSVGSwitchFrame(aStyle, aPresShell->GetPresContext());
|
2009-01-19 21:31:34 +03:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGSwitchFrame)
|
|
|
|
|
2009-01-19 21:31:34 +03:00
|
|
|
#ifdef DEBUG
|
2014-05-25 02:20:40 +04:00
|
|
|
void nsSVGSwitchFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) {
|
2015-03-03 14:08:59 +03:00
|
|
|
NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::svgSwitch),
|
2013-03-20 20:50:36 +04:00
|
|
|
"Content is not an SVG switch");
|
2008-01-03 17:30:02 +03:00
|
|
|
|
2016-04-18 10:43:07 +03:00
|
|
|
nsSVGGFrame::Init(aContent, aParent, aPrevInFlow);
|
2008-01-03 17:30:02 +03:00
|
|
|
}
|
2009-01-19 21:31:34 +03:00
|
|
|
#endif /* DEBUG */
|
2008-01-03 17:30:02 +03:00
|
|
|
|
2012-07-20 22:12:29 +04:00
|
|
|
void nsSVGSwitchFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayListSet& aLists) {
|
|
|
|
nsIFrame* kid = GetActiveChildFrame();
|
|
|
|
if (kid) {
|
2017-08-07 05:23:35 +03:00
|
|
|
BuildDisplayListForChild(aBuilder, kid, aLists);
|
2012-07-20 22:12:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-31 23:08:54 +03:00
|
|
|
void nsSVGSwitchFrame::PaintSVG(gfxContext& aContext,
|
2014-08-29 23:42:07 +04:00
|
|
|
const gfxMatrix& aTransform,
|
2017-05-18 23:03:41 +03:00
|
|
|
imgDrawingParams& aImgParams,
|
|
|
|
const nsIntRect* aDirtyRect) {
|
2012-07-20 22:12:29 +04:00
|
|
|
NS_ASSERTION(
|
|
|
|
!NS_SVGDisplayListPaintingEnabled() || (mState & NS_FRAME_IS_NONDISPLAY),
|
|
|
|
"If display lists are enabled, only painting of non-display "
|
|
|
|
"SVG should take this code path");
|
|
|
|
|
2017-05-18 23:03:41 +03:00
|
|
|
if (StyleEffects()->mOpacity == 0.0) {
|
|
|
|
return;
|
|
|
|
}
|
2008-07-13 15:30:48 +04:00
|
|
|
|
|
|
|
nsIFrame* kid = GetActiveChildFrame();
|
|
|
|
if (kid) {
|
2014-08-29 23:42:07 +04:00
|
|
|
gfxMatrix tm = aTransform;
|
2015-03-03 14:08:59 +03:00
|
|
|
if (kid->GetContent()->IsSVGElement()) {
|
2019-04-27 10:22:53 +03:00
|
|
|
tm = nsSVGUtils::GetTransformMatrixInUserSpace(kid) * tm;
|
2014-08-29 23:42:07 +04:00
|
|
|
}
|
2017-05-18 23:03:41 +03:00
|
|
|
nsSVGUtils::PaintFrameWithEffects(kid, aContext, tm, aImgParams,
|
|
|
|
aDirtyRect);
|
2008-07-13 15:30:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 11:09:31 +04:00
|
|
|
nsIFrame* nsSVGSwitchFrame::GetFrameForPoint(const gfxPoint& aPoint) {
|
2012-07-20 22:12:29 +04:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListHitTestingEnabled() ||
|
2013-07-12 11:13:07 +04:00
|
|
|
(mState & NS_FRAME_IS_NONDISPLAY),
|
2012-07-20 22:12:29 +04:00
|
|
|
"If display lists are enabled, only hit-testing of non-display "
|
|
|
|
"SVG should take this code path");
|
|
|
|
|
2008-07-13 15:30:48 +04:00
|
|
|
nsIFrame* kid = GetActiveChildFrame();
|
2017-02-09 21:24:31 +03:00
|
|
|
nsSVGDisplayableFrame* svgFrame = do_QueryFrame(kid);
|
2014-03-25 19:36:49 +04:00
|
|
|
if (svgFrame) {
|
2014-08-07 11:09:31 +04:00
|
|
|
// Transform the point from our SVG user space to our child's.
|
|
|
|
gfxPoint point = aPoint;
|
|
|
|
gfxMatrix m =
|
2018-12-21 11:58:14 +03:00
|
|
|
static_cast<const SVGElement*>(GetContent())
|
2015-12-03 01:36:23 +03:00
|
|
|
->PrependLocalTransformsTo(gfxMatrix(), eChildToUserSpace);
|
2018-12-21 11:58:14 +03:00
|
|
|
m = static_cast<const SVGElement*>(kid->GetContent())
|
2015-12-03 01:36:23 +03:00
|
|
|
->PrependLocalTransformsTo(m, eUserSpaceToParent);
|
2014-08-07 11:09:31 +04:00
|
|
|
if (!m.IsIdentity()) {
|
|
|
|
if (!m.Invert()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-07-05 18:18:49 +03:00
|
|
|
point = m.TransformPoint(point);
|
2014-08-07 11:09:31 +04:00
|
|
|
}
|
|
|
|
return svgFrame->GetFrameForPoint(point);
|
2008-07-13 15:30:48 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-07-13 15:30:48 +04:00
|
|
|
}
|
|
|
|
|
2019-04-02 09:08:23 +03:00
|
|
|
static bool shouldReflowSVGTextFrameInside(nsIFrame* aFrame) {
|
|
|
|
return aFrame->IsFrameOfType(nsIFrame::eSVG | nsIFrame::eSVGContainer) ||
|
|
|
|
aFrame->IsSVGForeignObjectFrame() ||
|
|
|
|
!aFrame->IsFrameOfType(nsIFrame::eSVG);
|
|
|
|
}
|
|
|
|
|
2019-03-22 00:17:18 +03:00
|
|
|
void nsSVGSwitchFrame::AlwaysReflowSVGTextFrameDoForOneKid(nsIFrame* aKid) {
|
|
|
|
if (!NS_SUBTREE_DIRTY(aKid)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-02 09:08:23 +03:00
|
|
|
if (aKid->IsSVGTextFrame()) {
|
2019-03-22 00:17:18 +03:00
|
|
|
MOZ_ASSERT(!aKid->HasAnyStateBits(NS_FRAME_IS_NONDISPLAY),
|
|
|
|
"A non-display SVGTextFrame directly contained in a display "
|
|
|
|
"container?");
|
|
|
|
static_cast<SVGTextFrame*>(aKid)->ReflowSVG();
|
2019-04-02 09:08:23 +03:00
|
|
|
} else if (shouldReflowSVGTextFrameInside(aKid)) {
|
2019-03-22 00:17:18 +03:00
|
|
|
if (!aKid->HasAnyStateBits(NS_FRAME_IS_NONDISPLAY)) {
|
|
|
|
for (nsIFrame* kid : aKid->PrincipalChildList()) {
|
|
|
|
AlwaysReflowSVGTextFrameDoForOneKid(kid);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This child is in a nondisplay context, something like:
|
|
|
|
// <switch>
|
|
|
|
// ...
|
|
|
|
// <g><mask><text></text></mask></g>
|
|
|
|
// </switch>
|
|
|
|
// We should not call ReflowSVG on it.
|
|
|
|
nsSVGContainerFrame::ReflowSVGNonDisplayText(aKid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsSVGSwitchFrame::ReflowAllSVGTextFramesInsideNonActiveChildren(
|
|
|
|
nsIFrame* aActiveChild) {
|
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid; kid = kid->GetNextSibling()) {
|
|
|
|
if (aActiveChild == kid) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
AlwaysReflowSVGTextFrameDoForOneKid(kid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-22 04:01:44 +04:00
|
|
|
void nsSVGSwitchFrame::ReflowSVG() {
|
|
|
|
NS_ASSERTION(nsSVGUtils::OuterSVGIsCallingReflowSVG(this),
|
|
|
|
"This call is probably a wasteful mistake");
|
2012-05-17 08:05:09 +04:00
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!(GetStateBits() & NS_FRAME_IS_NONDISPLAY),
|
|
|
|
"ReflowSVG mechanism not designed for this");
|
2012-05-17 08:05:09 +04:00
|
|
|
|
2012-07-22 04:01:44 +04:00
|
|
|
if (!nsSVGUtils::NeedsReflowSVG(this)) {
|
2012-05-17 08:05:09 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the NS_FRAME_FIRST_REFLOW bit has been removed from our parent frame,
|
|
|
|
// then our outer-<svg> has previously had its initial reflow. In that case
|
|
|
|
// we need to make sure that that bit has been removed from ourself _before_
|
|
|
|
// recursing over our children to ensure that they know too. Otherwise, we
|
|
|
|
// need to remove it _after_ recursing over our children so that they know
|
|
|
|
// the initial reflow is currently underway.
|
|
|
|
|
2013-08-24 15:31:48 +04:00
|
|
|
bool isFirstReflow = (mState & NS_FRAME_FIRST_REFLOW);
|
|
|
|
|
2012-05-17 08:05:09 +04:00
|
|
|
bool outerSVGHasHadFirstReflow =
|
|
|
|
(GetParent()->GetStateBits() & NS_FRAME_FIRST_REFLOW) == 0;
|
|
|
|
|
|
|
|
if (outerSVGHasHadFirstReflow) {
|
2017-08-24 12:55:28 +03:00
|
|
|
RemoveStateBits(NS_FRAME_FIRST_REFLOW); // tell our children
|
2012-05-17 08:05:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsOverflowAreas overflowRects;
|
|
|
|
|
|
|
|
nsIFrame* child = GetActiveChildFrame();
|
2019-03-22 00:17:18 +03:00
|
|
|
ReflowAllSVGTextFramesInsideNonActiveChildren(child);
|
|
|
|
|
2017-02-09 21:24:31 +03:00
|
|
|
nsSVGDisplayableFrame* svgChild = do_QueryFrame(child);
|
2014-03-25 19:36:49 +04:00
|
|
|
if (svgChild) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!(child->GetStateBits() & NS_FRAME_IS_NONDISPLAY),
|
|
|
|
"Check for this explicitly in the |if|, then");
|
2014-03-25 19:36:49 +04:00
|
|
|
svgChild->ReflowSVG();
|
|
|
|
|
|
|
|
// We build up our child frame overflows here instead of using
|
|
|
|
// nsLayoutUtils::UnionChildOverflow since SVG frame's all use the same
|
|
|
|
// frame list, and we're iterating over that list now anyway.
|
|
|
|
ConsiderChildOverflow(overflowRects, child);
|
2019-04-02 09:08:23 +03:00
|
|
|
} else if (child && shouldReflowSVGTextFrameInside(child)) {
|
|
|
|
MOZ_ASSERT(child->HasAnyStateBits(NS_FRAME_IS_NONDISPLAY),
|
|
|
|
"Check for this explicitly in the |if|, then");
|
|
|
|
ReflowSVGNonDisplayText(child);
|
2012-05-17 08:05:09 +04:00
|
|
|
}
|
|
|
|
|
2013-08-24 15:31:48 +04:00
|
|
|
if (isFirstReflow) {
|
2012-05-17 08:05:09 +04:00
|
|
|
// Make sure we have our filter property (if any) before calling
|
|
|
|
// FinishAndStoreOverflow (subsequent filter changes are handled off
|
|
|
|
// nsChangeHint_UpdateEffects):
|
2017-08-30 17:58:31 +03:00
|
|
|
SVGObserverUtils::UpdateEffects(this);
|
2012-05-17 08:05:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
FinishAndStoreOverflow(overflowRects, mRect.Size());
|
|
|
|
|
|
|
|
// Remove state bits after FinishAndStoreOverflow so that it doesn't
|
|
|
|
// invalidate on first reflow:
|
2017-08-24 12:55:28 +03:00
|
|
|
RemoveStateBits(NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY |
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
2012-05-17 08:05:09 +04:00
|
|
|
}
|
|
|
|
|
2013-12-30 10:50:07 +04:00
|
|
|
SVGBBox nsSVGSwitchFrame::GetBBoxContribution(const Matrix& aToBBoxUserspace,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags) {
|
2009-04-29 08:31:34 +04:00
|
|
|
nsIFrame* kid = GetActiveChildFrame();
|
2017-02-09 21:24:31 +03:00
|
|
|
nsSVGDisplayableFrame* svgKid = do_QueryFrame(kid);
|
2014-03-25 19:36:49 +04:00
|
|
|
if (svgKid) {
|
|
|
|
nsIContent* content = kid->GetContent();
|
|
|
|
gfxMatrix transform = ThebesMatrix(aToBBoxUserspace);
|
2015-03-03 14:08:59 +03:00
|
|
|
if (content->IsSVGElement()) {
|
2018-12-21 11:58:14 +03:00
|
|
|
transform = static_cast<SVGElement*>(content)->PrependLocalTransformsTo(
|
2019-04-23 03:03:00 +03:00
|
|
|
{}, eChildToUserSpace) *
|
2019-04-27 10:22:53 +03:00
|
|
|
nsSVGUtils::GetTransformMatrixInUserSpace(kid) * transform;
|
2009-06-18 01:29:55 +04:00
|
|
|
}
|
2014-03-25 19:36:49 +04:00
|
|
|
return svgKid->GetBBoxContribution(ToMatrix(transform), aFlags);
|
2008-07-13 15:30:48 +04:00
|
|
|
}
|
2012-04-16 12:23:48 +04:00
|
|
|
return SVGBBox();
|
2008-07-13 15:30:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* nsSVGSwitchFrame::GetActiveChildFrame() {
|
|
|
|
nsIContent* activeChild =
|
2017-08-27 01:58:38 +03:00
|
|
|
static_cast<mozilla::dom::SVGSwitchElement*>(GetContent())
|
|
|
|
->GetActiveChild();
|
2008-07-13 15:30:48 +04:00
|
|
|
|
|
|
|
if (activeChild) {
|
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid;
|
|
|
|
kid = kid->GetNextSibling()) {
|
|
|
|
if (activeChild == kid->GetContent()) {
|
|
|
|
return kid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-07-13 15:30:48 +04:00
|
|
|
}
|