2007-03-22 10:30:00 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Keep in (case-insensitive) order:
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIAnonymousContentCreator.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGGFrame.h"
|
2013-01-16 12:50:58 -08:00
|
|
|
#include "mozilla/dom/SVGUseElement.h"
|
2012-09-05 13:49:53 -07:00
|
|
|
#include "nsContentList.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
typedef nsSVGGFrame nsSVGUseFrameBase;
|
|
|
|
|
2013-01-16 12:50:58 -08:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsSVGUseFrame : public nsSVGUseFrameBase,
|
|
|
|
public nsIAnonymousContentCreator
|
|
|
|
{
|
|
|
|
friend nsIFrame*
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_NewSVGUseFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
protected:
|
2012-03-03 01:21:09 -08:00
|
|
|
nsSVGUseFrame(nsStyleContext* aContext) :
|
|
|
|
nsSVGUseFrameBase(aContext),
|
|
|
|
mHasValidDimensions(true)
|
|
|
|
{}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-09 08:35:24 -08:00
|
|
|
public:
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_DECL_QUERYFRAME
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
2009-01-12 11:20:59 -08:00
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIFrame interface:
|
2013-03-19 18:47:48 -07:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
|
2009-01-19 10:31:34 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD AttributeChanged(int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-23 21:21:15 -08:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the "type" of the frame
|
|
|
|
*
|
|
|
|
* @see nsGkAtoms::svgUseFrame
|
|
|
|
*/
|
|
|
|
virtual nsIAtom* GetType() const;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool IsLeaf() const;
|
2009-03-04 04:55:28 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGUse"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-02-01 08:25:44 -08:00
|
|
|
// nsISVGChildFrame interface:
|
2012-07-21 17:01:44 -07:00
|
|
|
virtual void ReflowSVG();
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual void NotifySVGChanged(uint32_t aFlags);
|
2012-02-01 08:25:44 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIAnonymousContentCreator
|
2011-05-06 13:04:44 -07:00
|
|
|
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements);
|
2010-10-15 08:34:35 -07:00
|
|
|
virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFilter);
|
2012-03-03 01:21:09 -08:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool mHasValidDimensions;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsIFrame*
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_NewSVGUseFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return new (aPresShell) nsSVGUseFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGUseFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom *
|
|
|
|
nsSVGUseFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgUseFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2009-01-12 11:20:59 -08:00
|
|
|
// nsQueryFrame methods
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_HEAD(nsSVGUseFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsSVGUseFrameBase)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods:
|
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2009-01-19 10:31:34 -08:00
|
|
|
nsSVGUseFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2013-01-07 19:22:41 -08:00
|
|
|
NS_ASSERTION(aContent->IsSVG(nsGkAtoms::use),
|
|
|
|
"Content is not an SVG use!");
|
2012-03-03 01:21:09 -08:00
|
|
|
|
|
|
|
mHasValidDimensions =
|
2013-01-16 12:50:58 -08:00
|
|
|
static_cast<SVGUseElement*>(aContent)->HasValidDimensions();
|
2009-01-19 10:31:34 -08:00
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
nsSVGUseFrameBase::Init(aContent, aParent, aPrevInFlow);
|
2009-01-19 10:31:34 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGUseFrame::AttributeChanged(int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-01-16 12:50:58 -08:00
|
|
|
SVGUseElement *useElement = static_cast<SVGUseElement*>(mContent);
|
2012-06-23 09:36:46 -07:00
|
|
|
|
2011-10-07 23:32:44 -07:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::x ||
|
|
|
|
aAttribute == nsGkAtoms::y) {
|
|
|
|
// make sure our cached transform matrix gets (lazily) updated
|
2012-07-30 07:20:58 -07:00
|
|
|
mCanvasTM = nullptr;
|
2012-11-28 01:42:13 -08:00
|
|
|
nsSVGUtils::InvalidateBounds(this, false);
|
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2011-10-07 23:32:44 -07:00
|
|
|
nsSVGUtils::NotifyChildrenOfSVGChange(this, TRANSFORM_CHANGED);
|
|
|
|
} else if (aAttribute == nsGkAtoms::width ||
|
|
|
|
aAttribute == nsGkAtoms::height) {
|
2012-06-23 09:36:46 -07:00
|
|
|
bool invalidate = false;
|
|
|
|
if (mHasValidDimensions != useElement->HasValidDimensions()) {
|
2012-03-03 01:21:09 -08:00
|
|
|
mHasValidDimensions = !mHasValidDimensions;
|
2012-06-23 09:36:46 -07:00
|
|
|
invalidate = true;
|
|
|
|
}
|
|
|
|
if (useElement->OurWidthAndHeightAreUsed()) {
|
|
|
|
invalidate = true;
|
|
|
|
useElement->SyncWidthOrHeight(aAttribute);
|
|
|
|
}
|
|
|
|
if (invalidate) {
|
2012-11-28 01:42:13 -08:00
|
|
|
nsSVGUtils::InvalidateBounds(this, false);
|
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2012-03-03 01:21:09 -08:00
|
|
|
}
|
2011-10-07 23:32:44 -07:00
|
|
|
}
|
|
|
|
} else if (aNameSpaceID == kNameSpaceID_XLink &&
|
|
|
|
aAttribute == nsGkAtoms::href) {
|
|
|
|
// we're changing our nature, clear out the clone information
|
2012-11-28 01:42:13 -08:00
|
|
|
nsSVGUtils::InvalidateBounds(this, false);
|
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2012-07-30 07:20:58 -07:00
|
|
|
useElement->mOriginal = nullptr;
|
2012-06-23 09:36:46 -07:00
|
|
|
useElement->UnlinkSource();
|
|
|
|
useElement->TriggerReclone();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsSVGUseFrameBase::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsSVGUseFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-01-16 12:50:58 -08:00
|
|
|
nsRefPtr<SVGUseElement> use = static_cast<SVGUseElement*>(mContent);
|
2009-12-23 21:21:15 -08:00
|
|
|
nsSVGUseFrameBase::DestroyFrom(aDestructRoot);
|
2007-06-18 08:30:57 -07:00
|
|
|
use->DestroyAnonymousContent();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-03-04 04:55:28 -08:00
|
|
|
nsSVGUseFrame::IsLeaf() const
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-03-04 04:55:28 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2012-02-01 08:25:44 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGChildFrame methods
|
|
|
|
|
2012-05-16 21:05:09 -07:00
|
|
|
void
|
2012-07-21 17:01:44 -07:00
|
|
|
nsSVGUseFrame::ReflowSVG()
|
2012-05-16 21:05:09 -07:00
|
|
|
{
|
|
|
|
// We only handle x/y offset here, since any width/height that is in force is
|
|
|
|
// handled by the nsSVGOuterSVGFrame for the anonymous <svg> that will be
|
|
|
|
// created for that purpose.
|
|
|
|
float x, y;
|
2013-01-16 12:50:58 -08:00
|
|
|
static_cast<SVGUseElement*>(mContent)->
|
2012-07-30 07:20:58 -07:00
|
|
|
GetAnimatedLengthValues(&x, &y, nullptr);
|
2012-05-16 21:05:09 -07:00
|
|
|
mRect.MoveTo(nsLayoutUtils::RoundGfxRectToAppRect(
|
|
|
|
gfxRect(x, y, 0.0, 0.0),
|
|
|
|
PresContext()->AppUnitsPerCSSPixel()).TopLeft());
|
2012-07-21 17:01:44 -07:00
|
|
|
nsSVGUseFrameBase::ReflowSVG();
|
2012-05-16 21:05:09 -07:00
|
|
|
}
|
|
|
|
|
2012-02-01 08:25:44 -08:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGUseFrame::NotifySVGChanged(uint32_t aFlags)
|
2012-02-01 08:25:44 -08:00
|
|
|
{
|
|
|
|
if (aFlags & COORD_CONTEXT_CHANGED &&
|
|
|
|
!(aFlags & TRANSFORM_CHANGED)) {
|
|
|
|
// Coordinate context changes affect mCanvasTM if we have a
|
|
|
|
// percentage 'x' or 'y'
|
2013-01-16 12:50:58 -08:00
|
|
|
SVGUseElement *use = static_cast<SVGUseElement*>(mContent);
|
2013-01-16 12:50:59 -08:00
|
|
|
if (use->mLengthAttributes[SVGUseElement::ATTR_X].IsPercentage() ||
|
|
|
|
use->mLengthAttributes[SVGUseElement::ATTR_Y].IsPercentage()) {
|
2012-02-01 08:25:44 -08:00
|
|
|
aFlags |= TRANSFORM_CHANGED;
|
2012-06-23 09:36:46 -07:00
|
|
|
// Ancestor changes can't affect how we render from the perspective of
|
|
|
|
// any rendering observers that we may have, so we don't need to
|
|
|
|
// invalidate them. We also don't need to invalidate ourself, since our
|
|
|
|
// changed ancestor will have invalidated its entire area, which includes
|
|
|
|
// our area.
|
|
|
|
// For perf reasons we call this before calling NotifySVGChanged() below.
|
2012-07-21 17:01:44 -07:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2012-02-01 08:25:44 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-19 06:50:07 -07:00
|
|
|
// We don't remove the TRANSFORM_CHANGED flag here if we have a viewBox or
|
|
|
|
// non-percentage width/height, since if they're set then they are cloned to
|
|
|
|
// an anonymous child <svg>, and its nsSVGInnerSVGFrame will do that.
|
|
|
|
|
2012-02-01 08:25:44 -08:00
|
|
|
nsSVGUseFrameBase::NotifySVGChanged(aFlags);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIAnonymousContentCreator methods:
|
|
|
|
|
|
|
|
nsresult
|
2011-05-06 13:04:44 -07:00
|
|
|
nsSVGUseFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-01-16 12:50:58 -08:00
|
|
|
SVGUseElement *use = static_cast<SVGUseElement*>(mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIContent* clone = use->CreateAnonymousContent();
|
|
|
|
if (!clone)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
if (!aElements.AppendElement(clone))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-02-11 09:34:01 -08:00
|
|
|
|
|
|
|
void
|
2010-10-15 08:34:35 -07:00
|
|
|
nsSVGUseFrame::AppendAnonymousContentTo(nsBaseContentList& aElements,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFilter)
|
2010-02-11 09:34:01 -08:00
|
|
|
{
|
2013-01-16 12:50:58 -08:00
|
|
|
SVGUseElement *use = static_cast<SVGUseElement*>(mContent);
|
2010-02-11 09:34:01 -08:00
|
|
|
nsIContent* clone = use->GetAnonymousContent();
|
|
|
|
aElements.MaybeAppendElement(clone);
|
|
|
|
}
|