2008-01-03 17:30:02 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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"
|
2012-05-17 08:05:09 +04:00
|
|
|
#include "nsSVGEffects.h"
|
2008-01-03 17:30:02 +03:00
|
|
|
#include "nsSVGGFrame.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"
|
2008-01-03 17:30:02 +03:00
|
|
|
|
2013-12-30 10:50:07 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2008-07-13 15:30:48 +04:00
|
|
|
typedef nsSVGGFrame nsSVGSwitchFrameBase;
|
2008-01-03 17:30:02 +03:00
|
|
|
|
2008-07-13 15:30:48 +04:00
|
|
|
class nsSVGSwitchFrame : public nsSVGSwitchFrameBase
|
2008-01-03 17:30:02 +03:00
|
|
|
{
|
|
|
|
friend nsIFrame*
|
2009-01-19 21:31:34 +03:00
|
|
|
NS_NewSVGSwitchFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
2008-01-03 17:30:02 +03:00
|
|
|
protected:
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit nsSVGSwitchFrame(nsStyleContext* aContext) :
|
2008-07-13 15:30:48 +04:00
|
|
|
nsSVGSwitchFrameBase(aContext) {}
|
2008-01-03 17:30:02 +03:00
|
|
|
|
|
|
|
public:
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
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,
|
|
|
|
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
|
2009-01-19 21:31:34 +03:00
|
|
|
#endif
|
|
|
|
|
2008-01-03 17:30:02 +03:00
|
|
|
/**
|
|
|
|
* Get the "type" of the frame
|
|
|
|
*
|
|
|
|
* @see nsGkAtoms::svgSwitchFrame
|
|
|
|
*/
|
2014-02-24 18:41:56 +04:00
|
|
|
virtual nsIAtom* GetType() const MOZ_OVERRIDE;
|
2008-01-03 17:30:02 +03:00
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-24 18:41:56 +04:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const MOZ_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,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists) MOZ_OVERRIDE;
|
2012-07-20 22:12:29 +04:00
|
|
|
|
2008-07-13 15:30:48 +04:00
|
|
|
// nsISVGChildFrame interface:
|
2014-10-31 23:08:54 +03:00
|
|
|
virtual nsresult PaintSVG(gfxContext& aContext,
|
2014-08-29 23:42:07 +04:00
|
|
|
const gfxMatrix& aTransform,
|
|
|
|
const nsIntRect* aDirtyRect = nullptr) MOZ_OVERRIDE;
|
2014-08-07 11:09:31 +04:00
|
|
|
nsIFrame* GetFrameForPoint(const gfxPoint& aPoint) MOZ_OVERRIDE;
|
2014-02-24 18:41:56 +04:00
|
|
|
nsRect GetCoveredRegion() MOZ_OVERRIDE;
|
|
|
|
virtual void ReflowSVG() MOZ_OVERRIDE;
|
2013-12-30 10:50:07 +04:00
|
|
|
virtual SVGBBox GetBBoxContribution(const Matrix &aToBBoxUserspace,
|
2014-02-24 18:41:56 +04:00
|
|
|
uint32_t aFlags) MOZ_OVERRIDE;
|
2008-07-13 15:30:48 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsIFrame *GetActiveChildFrame();
|
2008-01-03 17:30:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsIFrame*
|
2009-01-19 21:31:34 +03:00
|
|
|
NS_NewSVGSwitchFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2008-01-03 17:30:02 +03:00
|
|
|
{
|
2009-01-19 21:31:34 +03:00
|
|
|
return new (aPresShell) nsSVGSwitchFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGSwitchFrame)
|
|
|
|
|
2009-01-19 21:31:34 +03:00
|
|
|
#ifdef DEBUG
|
2013-03-20 05:47:48 +04:00
|
|
|
void
|
2014-05-25 02:20:40 +04:00
|
|
|
nsSVGSwitchFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2009-01-19 21:31:34 +03:00
|
|
|
{
|
2013-01-08 07:22:41 +04:00
|
|
|
NS_ASSERTION(aContent->IsSVG(nsGkAtoms::svgSwitch),
|
2013-03-20 20:50:36 +04:00
|
|
|
"Content is not an SVG switch");
|
2008-01-03 17:30:02 +03:00
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
nsSVGSwitchFrameBase::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
|
|
|
|
|
|
|
nsIAtom *
|
|
|
|
nsSVGSwitchFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgSwitchFrame;
|
|
|
|
}
|
2008-07-13 15:30:48 +04:00
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
void
|
2012-07-20 22:12:29 +04:00
|
|
|
nsSVGSwitchFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
nsIFrame* kid = GetActiveChildFrame();
|
|
|
|
if (kid) {
|
2013-02-14 15:08:08 +04:00
|
|
|
BuildDisplayListForChild(aBuilder, kid, aDirtyRect, aLists);
|
2012-07-20 22:12:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-20 02:34:31 +04:00
|
|
|
nsresult
|
2014-10-31 23:08:54 +03:00
|
|
|
nsSVGSwitchFrame::PaintSVG(gfxContext& aContext,
|
2014-08-29 23:42:07 +04:00
|
|
|
const gfxMatrix& aTransform,
|
|
|
|
const nsIntRect* aDirtyRect)
|
2008-07-13 15:30:48 +04:00
|
|
|
{
|
2012-07-20 22:12:29 +04:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListPaintingEnabled() ||
|
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 painting of non-display "
|
|
|
|
"SVG should take this code path");
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
if (StyleDisplay()->mOpacity == 0.0)
|
2008-07-13 15:30:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsIFrame *kid = GetActiveChildFrame();
|
|
|
|
if (kid) {
|
2014-08-29 23:42:07 +04:00
|
|
|
gfxMatrix tm = aTransform;
|
|
|
|
if (kid->GetContent()->IsSVG()) {
|
|
|
|
tm = static_cast<nsSVGElement*>(kid->GetContent())->
|
|
|
|
PrependLocalTransformsTo(tm, nsSVGElement::eUserSpaceToParent);
|
|
|
|
}
|
2014-10-31 23:08:54 +03:00
|
|
|
nsSVGUtils::PaintFrameWithEffects(kid, aContext, tm, aDirtyRect);
|
2008-07-13 15:30:48 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-20 02:34:31 +04:00
|
|
|
nsIFrame*
|
2014-08-07 11:09:31 +04:00
|
|
|
nsSVGSwitchFrame::GetFrameForPoint(const gfxPoint& aPoint)
|
2008-07-13 15:30:48 +04:00
|
|
|
{
|
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();
|
2014-03-25 19:36:49 +04:00
|
|
|
nsISVGChildFrame* svgFrame = do_QueryFrame(kid);
|
|
|
|
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 =
|
|
|
|
static_cast<const nsSVGElement*>(mContent)->
|
|
|
|
PrependLocalTransformsTo(gfxMatrix(), nsSVGElement::eChildToUserSpace);
|
|
|
|
m = static_cast<const nsSVGElement*>(kid->GetContent())->
|
|
|
|
PrependLocalTransformsTo(m, nsSVGElement::eUserSpaceToParent);
|
|
|
|
if (!m.IsIdentity()) {
|
|
|
|
if (!m.Invert()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
point = m.Transform(point);
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-02-20 02:34:31 +04:00
|
|
|
nsRect
|
2008-07-13 15:30:48 +04:00
|
|
|
nsSVGSwitchFrame::GetCoveredRegion()
|
|
|
|
{
|
|
|
|
nsRect rect;
|
|
|
|
|
|
|
|
nsIFrame *kid = GetActiveChildFrame();
|
2014-03-25 19:36:49 +04:00
|
|
|
nsISVGChildFrame* child = do_QueryFrame(kid);
|
|
|
|
if (child) {
|
|
|
|
rect = child->GetCoveredRegion();
|
2008-07-13 15:30:48 +04:00
|
|
|
}
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2012-05-17 08:05:09 +04:00
|
|
|
void
|
2012-07-22 04:01:44 +04:00
|
|
|
nsSVGSwitchFrame::ReflowSVG()
|
2012-05-17 08:05:09 +04:00
|
|
|
{
|
2012-07-22 04:01:44 +04:00
|
|
|
NS_ASSERTION(nsSVGUtils::OuterSVGIsCallingReflowSVG(this),
|
|
|
|
"This call is probably a wasteful mistake");
|
2012-05-17 08:05:09 +04:00
|
|
|
|
2013-07-12 11:13:07 +04:00
|
|
|
NS_ABORT_IF_FALSE(!(GetStateBits() & NS_FRAME_IS_NONDISPLAY),
|
2012-07-22 04:01:44 +04:00
|
|
|
"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) {
|
|
|
|
mState &= ~NS_FRAME_FIRST_REFLOW; // tell our children
|
|
|
|
}
|
|
|
|
|
|
|
|
nsOverflowAreas overflowRects;
|
|
|
|
|
|
|
|
nsIFrame *child = GetActiveChildFrame();
|
2014-03-25 19:36:49 +04:00
|
|
|
nsISVGChildFrame* svgChild = do_QueryFrame(child);
|
|
|
|
if (svgChild) {
|
|
|
|
NS_ABORT_IF_FALSE(!(child->GetStateBits() & NS_FRAME_IS_NONDISPLAY),
|
|
|
|
"Check for this explicitly in the |if|, then");
|
|
|
|
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 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):
|
|
|
|
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 12:23:48 +04:00
|
|
|
SVGBBox
|
2013-12-30 10:50:07 +04:00
|
|
|
nsSVGSwitchFrame::GetBBoxContribution(const Matrix &aToBBoxUserspace,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags)
|
2008-07-13 15:30:48 +04:00
|
|
|
{
|
2009-04-29 08:31:34 +04:00
|
|
|
nsIFrame* kid = GetActiveChildFrame();
|
2014-03-25 19:36:49 +04:00
|
|
|
nsISVGChildFrame* svgKid = do_QueryFrame(kid);
|
|
|
|
if (svgKid) {
|
|
|
|
nsIContent *content = kid->GetContent();
|
|
|
|
gfxMatrix transform = ThebesMatrix(aToBBoxUserspace);
|
|
|
|
if (content->IsSVG()) {
|
|
|
|
transform = static_cast<nsSVGElement*>(content)->
|
|
|
|
PrependLocalTransformsTo(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 =
|
2013-01-06 10:25:54 +04:00
|
|
|
static_cast<mozilla::dom::SVGSwitchElement*>(mContent)->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
|
|
|
}
|