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"
|
2020-06-27 08:39:42 +03:00
|
|
|
#include "SVGGFrame.h"
|
2019-04-16 10:24:49 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2020-07-09 04:33:33 +03:00
|
|
|
#include "mozilla/SVGContainerFrame.h"
|
|
|
|
#include "mozilla/SVGObserverUtils.h"
|
|
|
|
#include "mozilla/SVGTextFrame.h"
|
2020-07-11 05:20:20 +03:00
|
|
|
#include "mozilla/SVGUtils.h"
|
2013-01-06 10:25:54 +04:00
|
|
|
#include "mozilla/dom/SVGSwitchElement.h"
|
2008-01-03 17:30:02 +03:00
|
|
|
|
2019-10-23 11:16:45 +03:00
|
|
|
using namespace mozilla::dom;
|
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
|
|
|
|
2020-07-09 04:33:33 +03:00
|
|
|
nsIFrame* NS_NewSVGSwitchFrame(mozilla::PresShell* aPresShell,
|
|
|
|
mozilla::ComputedStyle* aStyle);
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class SVGSwitchFrame final : public SVGGFrame {
|
|
|
|
friend nsIFrame* ::NS_NewSVGSwitchFrame(mozilla::PresShell* aPresShell,
|
|
|
|
ComputedStyle* aStyle);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-01-03 17:30:02 +03:00
|
|
|
protected:
|
2020-07-09 04:33:33 +03:00
|
|
|
explicit SVGSwitchFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
|
2020-06-27 08:39:42 +03:00
|
|
|
: SVGGFrame(aStyle, aPresContext, kClassID) {}
|
2008-01-03 17:30:02 +03:00
|
|
|
|
|
|
|
public:
|
2020-07-09 04:33:33 +03:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(SVGSwitchFrame)
|
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 {
|
2020-07-01 11:29:29 +03:00
|
|
|
return MakeFrameName(u"SVGSwitch"_ns, aResult);
|
2008-01-03 17:30:02 +03:00
|
|
|
}
|
|
|
|
#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
|
|
|
|
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,
|
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
|
|
|
};
|
|
|
|
|
2020-07-09 04:33:33 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2008-01-03 17:30:02 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2020-07-11 05:20:20 +03:00
|
|
|
nsIFrame* NS_NewSVGSwitchFrame(mozilla::PresShell* aPresShell,
|
|
|
|
mozilla::ComputedStyle* aStyle) {
|
2019-02-05 19:45:54 +03:00
|
|
|
return new (aPresShell)
|
2020-07-09 04:33:33 +03:00
|
|
|
mozilla::SVGSwitchFrame(aStyle, aPresShell->GetPresContext());
|
2009-01-19 21:31:34 +03:00
|
|
|
}
|
|
|
|
|
2020-07-09 04:33:33 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(SVGSwitchFrame)
|
2009-09-12 20:49:24 +04:00
|
|
|
|
2009-01-19 21:31:34 +03:00
|
|
|
#ifdef DEBUG
|
2020-07-09 04:33:33 +03:00
|
|
|
void SVGSwitchFrame::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
|
|
|
|
2020-06-27 08:39:42 +03:00
|
|
|
SVGGFrame::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
|
|
|
|
2020-07-09 04:33:33 +03:00
|
|
|
void SVGSwitchFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayListSet& aLists) {
|
2012-07-20 22:12:29 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-09 04:33:33 +03:00
|
|
|
void SVGSwitchFrame::PaintSVG(gfxContext& aContext, const gfxMatrix& aTransform,
|
|
|
|
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()) {
|
2020-07-11 05:20:20 +03:00
|
|
|
tm = SVGUtils::GetTransformMatrixInUserSpace(kid) * tm;
|
2014-08-29 23:42:07 +04:00
|
|
|
}
|
2020-07-11 05:20:20 +03:00
|
|
|
SVGUtils::PaintFrameWithEffects(kid, aContext, tm, aImgParams, aDirtyRect);
|
2008-07-13 15:30:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-09 04:33:33 +03:00
|
|
|
nsIFrame* SVGSwitchFrame::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();
|
2020-07-09 21:34:54 +03:00
|
|
|
ISVGDisplayableFrame* 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);
|
|
|
|
}
|
|
|
|
|
2020-07-09 04:33:33 +03:00
|
|
|
void SVGSwitchFrame::AlwaysReflowSVGTextFrameDoForOneKid(nsIFrame* aKid) {
|
2020-07-09 21:29:15 +03:00
|
|
|
if (!aKid->IsSubtreeDirty()) {
|
2019-03-22 00:17:18 +03:00
|
|
|
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.
|
2020-07-09 04:33:33 +03:00
|
|
|
SVGContainerFrame::ReflowSVGNonDisplayText(aKid);
|
2019-03-22 00:17:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-09 04:33:33 +03:00
|
|
|
void SVGSwitchFrame::ReflowAllSVGTextFramesInsideNonActiveChildren(
|
2019-03-22 00:17:18 +03:00
|
|
|
nsIFrame* aActiveChild) {
|
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid; kid = kid->GetNextSibling()) {
|
|
|
|
if (aActiveChild == kid) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
AlwaysReflowSVGTextFrameDoForOneKid(kid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-09 04:33:33 +03:00
|
|
|
void SVGSwitchFrame::ReflowSVG() {
|
2020-07-11 05:20:20 +03:00
|
|
|
NS_ASSERTION(SVGUtils::OuterSVGIsCallingReflowSVG(this),
|
2012-07-22 04:01:44 +04:00
|
|
|
"This call is probably a wasteful mistake");
|
2012-05-17 08:05:09 +04:00
|
|
|
|
2020-06-27 17:23:36 +03:00
|
|
|
MOZ_ASSERT(!HasAnyStateBits(NS_FRAME_IS_NONDISPLAY),
|
2015-02-10 01:34:50 +03:00
|
|
|
"ReflowSVG mechanism not designed for this");
|
2012-05-17 08:05:09 +04:00
|
|
|
|
2020-07-11 05:20:20 +03:00
|
|
|
if (!SVGUtils::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 =
|
2020-06-27 17:23:36 +03:00
|
|
|
!GetParent()->HasAnyStateBits(NS_FRAME_FIRST_REFLOW);
|
2012-05-17 08:05:09 +04:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-07-09 21:34:54 +03:00
|
|
|
ISVGDisplayableFrame* svgChild = do_QueryFrame(child);
|
2014-03-25 19:36:49 +04:00
|
|
|
if (svgChild) {
|
2020-06-27 17:23:36 +03:00
|
|
|
MOZ_ASSERT(!child->HasAnyStateBits(NS_FRAME_IS_NONDISPLAY),
|
2015-02-10 01:34:50 +03:00
|
|
|
"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)) {
|
2020-10-22 11:28:45 +03:00
|
|
|
MOZ_ASSERT(child->HasAnyStateBits(NS_FRAME_IS_NONDISPLAY) ||
|
|
|
|
!child->IsFrameOfType(nsIFrame::eSVG),
|
2019-04-02 09:08:23 +03:00
|
|
|
"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
|
|
|
}
|
|
|
|
|
2020-07-09 04:33:33 +03:00
|
|
|
SVGBBox SVGSwitchFrame::GetBBoxContribution(const Matrix& aToBBoxUserspace,
|
|
|
|
uint32_t aFlags) {
|
2009-04-29 08:31:34 +04:00
|
|
|
nsIFrame* kid = GetActiveChildFrame();
|
2020-07-09 21:34:54 +03:00
|
|
|
ISVGDisplayableFrame* 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) *
|
2020-07-11 05:20:20 +03:00
|
|
|
SVGUtils::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
|
|
|
}
|
|
|
|
|
2020-07-09 04:33:33 +03:00
|
|
|
nsIFrame* SVGSwitchFrame::GetActiveChildFrame() {
|
2008-07-13 15:30:48 +04:00
|
|
|
nsIContent* activeChild =
|
2020-07-09 04:33:33 +03:00
|
|
|
static_cast<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
|
|
|
}
|
2020-07-09 04:33:33 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|