2008-01-03 06:30:02 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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 06:30:02 -08:00
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Keep in (case-insensitive) order:
|
|
|
|
#include "gfxMatrix.h"
|
|
|
|
#include "gfxRect.h"
|
2012-05-16 21:05:09 -07:00
|
|
|
#include "nsSVGEffects.h"
|
2008-01-03 06:30:02 -08:00
|
|
|
#include "nsSVGGFrame.h"
|
2008-07-13 04:30:48 -07:00
|
|
|
#include "nsSVGSwitchElement.h"
|
2012-03-18 03:32:02 -07:00
|
|
|
#include "nsSVGUtils.h"
|
2008-01-03 06:30:02 -08:00
|
|
|
|
2012-03-02 00:28:59 -08:00
|
|
|
class nsRenderingContext;
|
|
|
|
|
2008-07-13 04:30:48 -07:00
|
|
|
typedef nsSVGGFrame nsSVGSwitchFrameBase;
|
2008-01-03 06:30:02 -08:00
|
|
|
|
2008-07-13 04:30:48 -07:00
|
|
|
class nsSVGSwitchFrame : public nsSVGSwitchFrameBase
|
2008-01-03 06:30:02 -08:00
|
|
|
{
|
|
|
|
friend nsIFrame*
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_NewSVGSwitchFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
2008-01-03 06:30:02 -08:00
|
|
|
protected:
|
|
|
|
nsSVGSwitchFrame(nsStyleContext* aContext) :
|
2008-07-13 04:30:48 -07:00
|
|
|
nsSVGSwitchFrameBase(aContext) {}
|
2008-01-03 06:30:02 -08:00
|
|
|
|
|
|
|
public:
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
2009-01-19 10:31:34 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow);
|
|
|
|
#endif
|
|
|
|
|
2008-01-03 06:30:02 -08:00
|
|
|
/**
|
|
|
|
* Get the "type" of the frame
|
|
|
|
*
|
|
|
|
* @see nsGkAtoms::svgSwitchFrame
|
|
|
|
*/
|
|
|
|
virtual nsIAtom* GetType() const;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGSwitch"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
2008-07-13 04:30:48 -07:00
|
|
|
|
|
|
|
// nsISVGChildFrame interface:
|
2012-03-02 00:28:59 -08:00
|
|
|
NS_IMETHOD PaintSVG(nsRenderingContext* aContext, const nsIntRect *aDirtyRect);
|
2008-08-25 02:23:54 -07:00
|
|
|
NS_IMETHODIMP_(nsIFrame*) GetFrameForPoint(const nsPoint &aPoint);
|
2008-07-13 04:30:48 -07:00
|
|
|
NS_IMETHODIMP_(nsRect) GetCoveredRegion();
|
2012-05-16 21:05:09 -07:00
|
|
|
virtual void UpdateBounds();
|
2012-04-16 01:23:48 -07:00
|
|
|
virtual SVGBBox GetBBoxContribution(const gfxMatrix &aToBBoxUserspace,
|
2011-09-30 02:25:37 -07:00
|
|
|
PRUint32 aFlags);
|
2008-07-13 04:30:48 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsIFrame *GetActiveChildFrame();
|
2008-01-03 06:30:02 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsIFrame*
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_NewSVGSwitchFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2008-01-03 06:30:02 -08:00
|
|
|
{
|
2009-01-19 10:31:34 -08:00
|
|
|
return new (aPresShell) nsSVGSwitchFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGSwitchFrame)
|
|
|
|
|
2009-01-19 10:31:34 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGSwitchFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2008-01-03 06:30:02 -08:00
|
|
|
nsCOMPtr<nsIDOMSVGSwitchElement> svgSwitch = do_QueryInterface(aContent);
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_ASSERTION(svgSwitch, "Content is not an SVG switch\n");
|
2008-01-03 06:30:02 -08:00
|
|
|
|
2009-01-19 10:31:34 -08:00
|
|
|
return nsSVGSwitchFrameBase::Init(aContent, aParent, aPrevInFlow);
|
2008-01-03 06:30:02 -08:00
|
|
|
}
|
2009-01-19 10:31:34 -08:00
|
|
|
#endif /* DEBUG */
|
2008-01-03 06:30:02 -08:00
|
|
|
|
|
|
|
nsIAtom *
|
|
|
|
nsSVGSwitchFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgSwitchFrame;
|
|
|
|
}
|
2008-07-13 04:30:48 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-03-02 00:28:59 -08:00
|
|
|
nsSVGSwitchFrame::PaintSVG(nsRenderingContext* aContext,
|
2008-10-20 01:42:03 -07:00
|
|
|
const nsIntRect *aDirtyRect)
|
2008-07-13 04:30:48 -07:00
|
|
|
{
|
|
|
|
const nsStyleDisplay *display = mStyleContext->GetStyleDisplay();
|
|
|
|
if (display->mOpacity == 0.0)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsIFrame *kid = GetActiveChildFrame();
|
|
|
|
if (kid) {
|
2008-10-20 01:42:03 -07:00
|
|
|
nsSVGUtils::PaintFrameWithEffects(aContext, aDirtyRect, kid);
|
2008-07-13 04:30:48 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
NS_IMETHODIMP_(nsIFrame*)
|
|
|
|
nsSVGSwitchFrame::GetFrameForPoint(const nsPoint &aPoint)
|
2008-07-13 04:30:48 -07:00
|
|
|
{
|
|
|
|
nsIFrame *kid = GetActiveChildFrame();
|
|
|
|
if (kid) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsISVGChildFrame* svgFrame = do_QueryFrame(kid);
|
2008-07-13 04:30:48 -07:00
|
|
|
if (svgFrame) {
|
2008-08-25 02:23:54 -07:00
|
|
|
return svgFrame->GetFrameForPoint(aPoint);
|
2008-07-13 04:30:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
return nsnull;
|
2008-07-13 04:30:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsRect)
|
|
|
|
nsSVGSwitchFrame::GetCoveredRegion()
|
|
|
|
{
|
|
|
|
nsRect rect;
|
|
|
|
|
|
|
|
nsIFrame *kid = GetActiveChildFrame();
|
|
|
|
if (kid) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsISVGChildFrame* child = do_QueryFrame(kid);
|
2008-07-13 04:30:48 -07:00
|
|
|
if (child) {
|
|
|
|
rect = child->GetCoveredRegion();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2012-05-16 21:05:09 -07:00
|
|
|
void
|
|
|
|
nsSVGSwitchFrame::UpdateBounds()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(nsSVGUtils::OuterSVGIsCallingUpdateBounds(this),
|
|
|
|
"This call is probaby a wasteful mistake");
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(!(GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD),
|
|
|
|
"UpdateBounds mechanism not designed for this");
|
|
|
|
|
|
|
|
if (!nsSVGUtils::NeedsUpdatedBounds(this)) {
|
|
|
|
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.
|
|
|
|
|
|
|
|
bool outerSVGHasHadFirstReflow =
|
|
|
|
(GetParent()->GetStateBits() & NS_FRAME_FIRST_REFLOW) == 0;
|
|
|
|
|
|
|
|
if (outerSVGHasHadFirstReflow) {
|
|
|
|
mState &= ~NS_FRAME_FIRST_REFLOW; // tell our children
|
|
|
|
}
|
|
|
|
|
|
|
|
nsOverflowAreas overflowRects;
|
|
|
|
|
|
|
|
nsIFrame *child = GetActiveChildFrame();
|
|
|
|
if (child) {
|
|
|
|
nsISVGChildFrame* svgChild = do_QueryFrame(child);
|
|
|
|
if (svgChild) {
|
|
|
|
NS_ABORT_IF_FALSE(!(child->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD),
|
|
|
|
"Check for this explicitly in the |if|, then");
|
|
|
|
svgChild->UpdateBounds();
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mState & NS_FRAME_FIRST_REFLOW) {
|
|
|
|
// Make sure we have our filter property (if any) before calling
|
|
|
|
// FinishAndStoreOverflow (subsequent filter changes are handled off
|
|
|
|
// nsChangeHint_UpdateEffects):
|
|
|
|
nsSVGEffects::UpdateEffects(this);
|
|
|
|
}
|
|
|
|
|
2012-07-07 23:29:57 -07:00
|
|
|
// We only invalidate if we are dirty, if our outer-<svg> has already had its
|
|
|
|
// initial reflow (since if it hasn't, its entire area will be invalidated
|
|
|
|
// when it gets that initial reflow), and if our parent is not dirty (since
|
|
|
|
// if it is, then it will invalidate its entire new area, which will include
|
|
|
|
// our new area).
|
|
|
|
bool invalidate = (mState & NS_FRAME_IS_DIRTY) &&
|
|
|
|
!(GetParent()->GetStateBits() &
|
|
|
|
(NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY));
|
|
|
|
|
2012-05-16 21:05:09 -07:00
|
|
|
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-07-07 23:29:57 -07:00
|
|
|
if (invalidate) {
|
2012-06-23 09:36:46 -07:00
|
|
|
// XXXSDL Let FinishAndStoreOverflow do this.
|
|
|
|
nsSVGUtils::InvalidateBounds(this, true);
|
|
|
|
}
|
2012-05-16 21:05:09 -07:00
|
|
|
}
|
|
|
|
|
2012-04-16 01:23:48 -07:00
|
|
|
SVGBBox
|
2011-09-30 02:25:37 -07:00
|
|
|
nsSVGSwitchFrame::GetBBoxContribution(const gfxMatrix &aToBBoxUserspace,
|
|
|
|
PRUint32 aFlags)
|
2008-07-13 04:30:48 -07:00
|
|
|
{
|
2009-04-28 21:31:34 -07:00
|
|
|
nsIFrame* kid = GetActiveChildFrame();
|
2012-04-16 01:23:48 -07:00
|
|
|
if (kid) {
|
|
|
|
nsISVGChildFrame* svgKid = do_QueryFrame(kid);
|
|
|
|
if (svgKid) {
|
|
|
|
nsIContent *content = kid->GetContent();
|
|
|
|
gfxMatrix transform = aToBBoxUserspace;
|
|
|
|
if (content->IsSVG()) {
|
|
|
|
transform = static_cast<nsSVGElement*>(content)->
|
|
|
|
PrependLocalTransformsTo(aToBBoxUserspace);
|
|
|
|
}
|
|
|
|
return svgKid->GetBBoxContribution(transform, aFlags);
|
2009-06-17 14:29:55 -07:00
|
|
|
}
|
2008-07-13 04:30:48 -07:00
|
|
|
}
|
2012-04-16 01:23:48 -07:00
|
|
|
return SVGBBox();
|
2008-07-13 04:30:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame *
|
|
|
|
nsSVGSwitchFrame::GetActiveChildFrame()
|
|
|
|
{
|
|
|
|
nsIContent *activeChild =
|
|
|
|
static_cast<nsSVGSwitchElement*>(mContent)->GetActiveChild();
|
|
|
|
|
|
|
|
if (activeChild) {
|
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid;
|
|
|
|
kid = kid->GetNextSibling()) {
|
|
|
|
|
|
|
|
if (activeChild == kid->GetContent()) {
|
|
|
|
return kid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|