2008-01-03 14:30:02 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 14:30:02 +00:00
|
|
|
|
2012-03-26 11:58:59 +00:00
|
|
|
// Keep in (case-insensitive) order:
|
|
|
|
#include "gfxRect.h"
|
2012-05-17 04:05:09 +00:00
|
|
|
#include "nsSVGEffects.h"
|
2008-01-03 14:30:02 +00:00
|
|
|
#include "nsSVGGFrame.h"
|
2013-01-06 06:25:54 +00:00
|
|
|
#include "mozilla/dom/SVGSwitchElement.h"
|
2012-03-18 10:32:02 +00:00
|
|
|
#include "nsSVGUtils.h"
|
2008-01-03 14:30:02 +00:00
|
|
|
|
2013-12-30 06:50:07 +00:00
|
|
|
using namespace mozilla::gfx;
|
2017-03-08 04:07:00 +00:00
|
|
|
using namespace mozilla::image;
|
2013-12-30 06:50:07 +00:00
|
|
|
|
2017-04-30 15:30:08 +00:00
|
|
|
class nsSVGSwitchFrame final : public nsSVGGFrame
|
2008-01-03 14:30:02 +00:00
|
|
|
{
|
|
|
|
friend nsIFrame*
|
2009-01-19 18:31:34 +00:00
|
|
|
NS_NewSVGSwitchFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
2008-01-03 14:30:02 +00:00
|
|
|
protected:
|
2016-04-18 07:43:07 +00:00
|
|
|
explicit nsSVGSwitchFrame(nsStyleContext* aContext)
|
2017-05-26 10:11:11 +00:00
|
|
|
: nsSVGGFrame(aContext, kClassID)
|
2017-04-30 15:30:08 +00:00
|
|
|
{}
|
2008-01-03 14:30:02 +00:00
|
|
|
|
|
|
|
public:
|
2017-05-26 10:11:11 +00:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(nsSVGSwitchFrame)
|
2009-09-12 16:49:24 +00:00
|
|
|
|
2009-01-19 18:31:34 +00:00
|
|
|
#ifdef DEBUG
|
2014-05-24 22:20:40 +00:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsIFrame* aPrevInFlow) override;
|
2009-01-19 18:31:34 +00:00
|
|
|
#endif
|
|
|
|
|
2014-01-05 23:31:14 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override
|
2008-01-03 14:30:02 +00:00
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGSwitch"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
2008-07-13 11:30:48 +00:00
|
|
|
|
2013-02-14 11:12:27 +00:00
|
|
|
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
2015-03-21 16:28:04 +00:00
|
|
|
const nsDisplayListSet& aLists) override;
|
2012-07-20 18:12:29 +00:00
|
|
|
|
2017-02-09 18:24:31 +00:00
|
|
|
// nsSVGDisplayableFrame interface:
|
2017-05-18 20:03:41 +00:00
|
|
|
virtual void PaintSVG(gfxContext& aContext,
|
|
|
|
const gfxMatrix& aTransform,
|
|
|
|
imgDrawingParams& aPackage,
|
|
|
|
const nsIntRect* aDirtyRect = nullptr) override;
|
2015-03-21 16:28:04 +00:00
|
|
|
nsIFrame* GetFrameForPoint(const gfxPoint& aPoint) override;
|
|
|
|
virtual void ReflowSVG() override;
|
2013-12-30 06:50:07 +00:00
|
|
|
virtual SVGBBox GetBBoxContribution(const Matrix &aToBBoxUserspace,
|
2015-03-21 16:28:04 +00:00
|
|
|
uint32_t aFlags) override;
|
2008-07-13 11:30:48 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsIFrame *GetActiveChildFrame();
|
2008-01-03 14:30:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsIFrame*
|
2009-01-19 18:31:34 +00:00
|
|
|
NS_NewSVGSwitchFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2017-07-06 12:00:35 +00:00
|
|
|
{
|
2009-01-19 18:31:34 +00:00
|
|
|
return new (aPresShell) nsSVGSwitchFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGSwitchFrame)
|
|
|
|
|
2009-01-19 18:31:34 +00:00
|
|
|
#ifdef DEBUG
|
2013-03-20 01:47:48 +00:00
|
|
|
void
|
2014-05-24 22:20:40 +00:00
|
|
|
nsSVGSwitchFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2009-01-19 18:31:34 +00:00
|
|
|
{
|
2015-03-03 11:08:59 +00:00
|
|
|
NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::svgSwitch),
|
2013-03-20 16:50:36 +00:00
|
|
|
"Content is not an SVG switch");
|
2008-01-03 14:30:02 +00:00
|
|
|
|
2016-04-18 07:43:07 +00:00
|
|
|
nsSVGGFrame::Init(aContent, aParent, aPrevInFlow);
|
2008-01-03 14:30:02 +00:00
|
|
|
}
|
2009-01-19 18:31:34 +00:00
|
|
|
#endif /* DEBUG */
|
2008-01-03 14:30:02 +00:00
|
|
|
|
2013-02-14 11:12:27 +00:00
|
|
|
void
|
2012-07-20 18:12:29 +00:00
|
|
|
nsSVGSwitchFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
nsIFrame* kid = GetActiveChildFrame();
|
|
|
|
if (kid) {
|
2017-08-07 02:23:35 +00:00
|
|
|
BuildDisplayListForChild(aBuilder, kid, aLists);
|
2012-07-20 18:12:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 20:03:41 +00:00
|
|
|
void
|
2014-10-31 20:08:54 +00:00
|
|
|
nsSVGSwitchFrame::PaintSVG(gfxContext& aContext,
|
2014-08-29 19:42:07 +00:00
|
|
|
const gfxMatrix& aTransform,
|
2017-05-18 20:03:41 +00:00
|
|
|
imgDrawingParams& aImgParams,
|
|
|
|
const nsIntRect* aDirtyRect)
|
2008-07-13 11:30:48 +00:00
|
|
|
{
|
2012-07-20 18:12:29 +00:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListPaintingEnabled() ||
|
2013-07-12 07:13:07 +00:00
|
|
|
(mState & NS_FRAME_IS_NONDISPLAY),
|
2012-07-20 18:12:29 +00:00
|
|
|
"If display lists are enabled, only painting of non-display "
|
|
|
|
"SVG should take this code path");
|
|
|
|
|
2017-05-18 20:03:41 +00:00
|
|
|
if (StyleEffects()->mOpacity == 0.0){
|
|
|
|
return;
|
|
|
|
}
|
2008-07-13 11:30:48 +00:00
|
|
|
|
|
|
|
nsIFrame *kid = GetActiveChildFrame();
|
|
|
|
if (kid) {
|
2014-08-29 19:42:07 +00:00
|
|
|
gfxMatrix tm = aTransform;
|
2015-03-03 11:08:59 +00:00
|
|
|
if (kid->GetContent()->IsSVGElement()) {
|
2014-08-29 19:42:07 +00:00
|
|
|
tm = static_cast<nsSVGElement*>(kid->GetContent())->
|
2015-12-02 22:36:23 +00:00
|
|
|
PrependLocalTransformsTo(tm, eUserSpaceToParent);
|
2014-08-29 19:42:07 +00:00
|
|
|
}
|
2017-05-18 20:03:41 +00:00
|
|
|
nsSVGUtils::PaintFrameWithEffects(kid, aContext, tm, aImgParams, aDirtyRect);
|
2008-07-13 11:30:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-19 22:34:31 +00:00
|
|
|
nsIFrame*
|
2014-08-07 07:09:31 +00:00
|
|
|
nsSVGSwitchFrame::GetFrameForPoint(const gfxPoint& aPoint)
|
2008-07-13 11:30:48 +00:00
|
|
|
{
|
2012-07-20 18:12:29 +00:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListHitTestingEnabled() ||
|
2013-07-12 07:13:07 +00:00
|
|
|
(mState & NS_FRAME_IS_NONDISPLAY),
|
2012-07-20 18:12:29 +00:00
|
|
|
"If display lists are enabled, only hit-testing of non-display "
|
|
|
|
"SVG should take this code path");
|
|
|
|
|
2008-07-13 11:30:48 +00:00
|
|
|
nsIFrame *kid = GetActiveChildFrame();
|
2017-02-09 18:24:31 +00:00
|
|
|
nsSVGDisplayableFrame* svgFrame = do_QueryFrame(kid);
|
2014-03-25 15:36:49 +00:00
|
|
|
if (svgFrame) {
|
2014-08-07 07:09:31 +00:00
|
|
|
// Transform the point from our SVG user space to our child's.
|
|
|
|
gfxPoint point = aPoint;
|
|
|
|
gfxMatrix m =
|
2017-08-26 22:58:38 +00:00
|
|
|
static_cast<const nsSVGElement*>(GetContent())->
|
2015-12-02 22:36:23 +00:00
|
|
|
PrependLocalTransformsTo(gfxMatrix(), eChildToUserSpace);
|
2014-08-07 07:09:31 +00:00
|
|
|
m = static_cast<const nsSVGElement*>(kid->GetContent())->
|
2015-12-02 22:36:23 +00:00
|
|
|
PrependLocalTransformsTo(m, eUserSpaceToParent);
|
2014-08-07 07:09:31 +00:00
|
|
|
if (!m.IsIdentity()) {
|
|
|
|
if (!m.Invert()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-07-05 15:18:49 +00:00
|
|
|
point = m.TransformPoint(point);
|
2014-08-07 07:09:31 +00:00
|
|
|
}
|
|
|
|
return svgFrame->GetFrameForPoint(point);
|
2008-07-13 11:30:48 +00:00
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2008-07-13 11:30:48 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 04:05:09 +00:00
|
|
|
void
|
2012-07-22 00:01:44 +00:00
|
|
|
nsSVGSwitchFrame::ReflowSVG()
|
2012-05-17 04:05:09 +00:00
|
|
|
{
|
2012-07-22 00:01:44 +00:00
|
|
|
NS_ASSERTION(nsSVGUtils::OuterSVGIsCallingReflowSVG(this),
|
|
|
|
"This call is probably a wasteful mistake");
|
2012-05-17 04:05:09 +00:00
|
|
|
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(!(GetStateBits() & NS_FRAME_IS_NONDISPLAY),
|
|
|
|
"ReflowSVG mechanism not designed for this");
|
2012-05-17 04:05:09 +00:00
|
|
|
|
2012-07-22 00:01:44 +00:00
|
|
|
if (!nsSVGUtils::NeedsReflowSVG(this)) {
|
2012-05-17 04:05:09 +00: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 11:31:48 +00:00
|
|
|
bool isFirstReflow = (mState & NS_FRAME_FIRST_REFLOW);
|
|
|
|
|
2012-05-17 04:05:09 +00:00
|
|
|
bool outerSVGHasHadFirstReflow =
|
|
|
|
(GetParent()->GetStateBits() & NS_FRAME_FIRST_REFLOW) == 0;
|
|
|
|
|
|
|
|
if (outerSVGHasHadFirstReflow) {
|
|
|
|
mState &= ~NS_FRAME_FIRST_REFLOW; // tell our children
|
|
|
|
}
|
|
|
|
|
|
|
|
nsOverflowAreas overflowRects;
|
|
|
|
|
|
|
|
nsIFrame *child = GetActiveChildFrame();
|
2017-02-09 18:24:31 +00:00
|
|
|
nsSVGDisplayableFrame* svgChild = do_QueryFrame(child);
|
2014-03-25 15:36:49 +00:00
|
|
|
if (svgChild) {
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(!(child->GetStateBits() & NS_FRAME_IS_NONDISPLAY),
|
|
|
|
"Check for this explicitly in the |if|, then");
|
2014-03-25 15:36:49 +00: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);
|
2012-05-17 04:05:09 +00:00
|
|
|
}
|
|
|
|
|
2013-08-24 11:31:48 +00:00
|
|
|
if (isFirstReflow) {
|
2012-05-17 04:05:09 +00:00
|
|
|
// Make sure we have our filter property (if any) before calling
|
|
|
|
// FinishAndStoreOverflow (subsequent filter changes are handled off
|
|
|
|
// nsChangeHint_UpdateEffects):
|
|
|
|
nsSVGEffects::UpdateEffects(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
FinishAndStoreOverflow(overflowRects, mRect.Size());
|
|
|
|
|
|
|
|
// Remove state bits after FinishAndStoreOverflow so that it doesn't
|
|
|
|
// invalidate on first reflow:
|
|
|
|
mState &= ~(NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY |
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
}
|
|
|
|
|
2012-04-16 08:23:48 +00:00
|
|
|
SVGBBox
|
2013-12-30 06:50:07 +00:00
|
|
|
nsSVGSwitchFrame::GetBBoxContribution(const Matrix &aToBBoxUserspace,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aFlags)
|
2008-07-13 11:30:48 +00:00
|
|
|
{
|
2009-04-29 04:31:34 +00:00
|
|
|
nsIFrame* kid = GetActiveChildFrame();
|
2017-02-09 18:24:31 +00:00
|
|
|
nsSVGDisplayableFrame* svgKid = do_QueryFrame(kid);
|
2014-03-25 15:36:49 +00:00
|
|
|
if (svgKid) {
|
|
|
|
nsIContent *content = kid->GetContent();
|
|
|
|
gfxMatrix transform = ThebesMatrix(aToBBoxUserspace);
|
2015-03-03 11:08:59 +00:00
|
|
|
if (content->IsSVGElement()) {
|
2014-03-25 15:36:49 +00:00
|
|
|
transform = static_cast<nsSVGElement*>(content)->
|
|
|
|
PrependLocalTransformsTo(transform);
|
2009-06-17 21:29:55 +00:00
|
|
|
}
|
2014-03-25 15:36:49 +00:00
|
|
|
return svgKid->GetBBoxContribution(ToMatrix(transform), aFlags);
|
2008-07-13 11:30:48 +00:00
|
|
|
}
|
2012-04-16 08:23:48 +00:00
|
|
|
return SVGBBox();
|
2008-07-13 11:30:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame *
|
|
|
|
nsSVGSwitchFrame::GetActiveChildFrame()
|
|
|
|
{
|
|
|
|
nsIContent *activeChild =
|
2017-08-26 22:58:38 +00:00
|
|
|
static_cast<mozilla::dom::SVGSwitchElement*>(GetContent())->GetActiveChild();
|
2008-07-13 11:30:48 +00:00
|
|
|
|
|
|
|
if (activeChild) {
|
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid;
|
|
|
|
kid = kid->GetNextSibling()) {
|
|
|
|
|
|
|
|
if (activeChild == kid->GetContent()) {
|
|
|
|
return kid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2008-07-13 11:30:48 +00:00
|
|
|
}
|