2004-11-23 13:51:57 +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/. */
|
2004-11-23 13:51:57 +00:00
|
|
|
|
2012-03-26 11:58:59 +00:00
|
|
|
// Keep in (case-insensitive) order:
|
2004-11-23 13:51:57 +00:00
|
|
|
#include "nsIAnonymousContentCreator.h"
|
2012-03-26 11:58:59 +00:00
|
|
|
#include "nsSVGGFrame.h"
|
2007-02-18 17:34:09 +00:00
|
|
|
#include "nsSVGUseElement.h"
|
2012-09-05 20:49:53 +00:00
|
|
|
#include "nsContentList.h"
|
2004-11-23 13:51:57 +00:00
|
|
|
|
|
|
|
typedef nsSVGGFrame nsSVGUseFrameBase;
|
|
|
|
|
|
|
|
class nsSVGUseFrame : public nsSVGUseFrameBase,
|
|
|
|
public nsIAnonymousContentCreator
|
|
|
|
{
|
2005-11-11 02:36:29 +00:00
|
|
|
friend nsIFrame*
|
2009-01-19 18:31:34 +00:00
|
|
|
NS_NewSVGUseFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
2004-11-23 13:51:57 +00:00
|
|
|
|
|
|
|
protected:
|
2012-03-03 09:21:09 +00:00
|
|
|
nsSVGUseFrame(nsStyleContext* aContext) :
|
|
|
|
nsSVGUseFrameBase(aContext),
|
|
|
|
mHasValidDimensions(true)
|
|
|
|
{}
|
2004-11-23 13:51:57 +00:00
|
|
|
|
2009-01-09 16:35:24 +00:00
|
|
|
public:
|
2009-01-12 19:20:59 +00:00
|
|
|
NS_DECL_QUERYFRAME
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
2009-01-12 19:20:59 +00:00
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
|
2006-03-02 20:22:19 +00:00
|
|
|
// nsIFrame interface:
|
2009-01-19 18:31:34 +00:00
|
|
|
NS_IMETHOD Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHOD AttributeChanged(int32_t aNameSpaceID,
|
2006-03-02 20:22:19 +00:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aModType);
|
2004-11-23 13:51:57 +00:00
|
|
|
|
2009-12-24 05:21:15 +00:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot);
|
2007-02-18 17:34:09 +00:00
|
|
|
|
2005-04-01 19:56:08 +00:00
|
|
|
/**
|
|
|
|
* Get the "type" of the frame
|
|
|
|
*
|
2006-12-26 17:47:52 +00:00
|
|
|
* @see nsGkAtoms::svgUseFrame
|
2005-04-01 19:56:08 +00:00
|
|
|
*/
|
|
|
|
virtual nsIAtom* GetType() const;
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool IsLeaf() const;
|
2009-03-04 12:55:28 +00:00
|
|
|
|
2005-04-01 19:56:08 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGUse"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-02-01 16:25:44 +00:00
|
|
|
// nsISVGChildFrame interface:
|
2012-07-22 00:01:44 +00:00
|
|
|
virtual void ReflowSVG();
|
2012-08-22 15:56:38 +00:00
|
|
|
virtual void NotifySVGChanged(uint32_t aFlags);
|
2012-02-01 16:25:44 +00:00
|
|
|
|
2004-11-23 13:51:57 +00:00
|
|
|
// nsIAnonymousContentCreator
|
2011-05-06 20:04:44 +00:00
|
|
|
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements);
|
2010-10-15 15:34:35 +00:00
|
|
|
virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aFilter);
|
2012-03-03 09:21:09 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool mHasValidDimensions;
|
2004-11-23 13:51:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2005-11-11 02:36:29 +00:00
|
|
|
nsIFrame*
|
2009-01-19 18:31:34 +00:00
|
|
|
NS_NewSVGUseFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2004-11-23 13:51:57 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsSVGUseFrame(aContext);
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGUseFrame)
|
|
|
|
|
2005-04-01 19:56:08 +00:00
|
|
|
nsIAtom *
|
|
|
|
nsSVGUseFrame::GetType() const
|
|
|
|
{
|
2006-12-26 17:47:52 +00:00
|
|
|
return nsGkAtoms::svgUseFrame;
|
2005-04-01 19:56:08 +00:00
|
|
|
}
|
|
|
|
|
2004-11-23 13:51:57 +00:00
|
|
|
//----------------------------------------------------------------------
|
2009-01-12 19:20:59 +00:00
|
|
|
// nsQueryFrame methods
|
2004-11-23 13:51:57 +00:00
|
|
|
|
2009-01-12 19:20:59 +00:00
|
|
|
NS_QUERYFRAME_HEAD(nsSVGUseFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsSVGUseFrameBase)
|
2004-11-23 13:51:57 +00:00
|
|
|
|
2006-03-02 20:22:19 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods:
|
|
|
|
|
2009-01-19 18:31:34 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGUseFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2013-01-08 03:22:41 +00:00
|
|
|
NS_ASSERTION(aContent->IsSVG(nsGkAtoms::use),
|
|
|
|
"Content is not an SVG use!");
|
2012-03-03 09:21:09 +00:00
|
|
|
|
|
|
|
mHasValidDimensions =
|
|
|
|
static_cast<nsSVGUseElement*>(aContent)->HasValidDimensions();
|
2009-01-19 18:31:34 +00:00
|
|
|
|
|
|
|
return nsSVGUseFrameBase::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
}
|
|
|
|
|
2006-03-02 20:22:19 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsSVGUseFrame::AttributeChanged(int32_t aNameSpaceID,
|
2006-03-02 20:22:19 +00:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aModType)
|
2006-03-02 20:22:19 +00:00
|
|
|
{
|
2012-06-23 16:36:46 +00:00
|
|
|
nsSVGUseElement *useElement = static_cast<nsSVGUseElement*>(mContent);
|
|
|
|
|
2011-10-08 06:32:44 +00:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::x ||
|
|
|
|
aAttribute == nsGkAtoms::y) {
|
|
|
|
// make sure our cached transform matrix gets (lazily) updated
|
2012-07-30 14:20:58 +00:00
|
|
|
mCanvasTM = nullptr;
|
2012-11-28 09:42:13 +00:00
|
|
|
nsSVGUtils::InvalidateBounds(this, false);
|
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2011-10-08 06:32:44 +00:00
|
|
|
nsSVGUtils::NotifyChildrenOfSVGChange(this, TRANSFORM_CHANGED);
|
|
|
|
} else if (aAttribute == nsGkAtoms::width ||
|
|
|
|
aAttribute == nsGkAtoms::height) {
|
2012-06-23 16:36:46 +00:00
|
|
|
bool invalidate = false;
|
|
|
|
if (mHasValidDimensions != useElement->HasValidDimensions()) {
|
2012-03-03 09:21:09 +00:00
|
|
|
mHasValidDimensions = !mHasValidDimensions;
|
2012-06-23 16:36:46 +00:00
|
|
|
invalidate = true;
|
|
|
|
}
|
|
|
|
if (useElement->OurWidthAndHeightAreUsed()) {
|
|
|
|
invalidate = true;
|
|
|
|
useElement->SyncWidthOrHeight(aAttribute);
|
|
|
|
}
|
|
|
|
if (invalidate) {
|
2012-11-28 09:42:13 +00:00
|
|
|
nsSVGUtils::InvalidateBounds(this, false);
|
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2012-03-03 09:21:09 +00:00
|
|
|
}
|
2011-10-08 06:32:44 +00:00
|
|
|
}
|
|
|
|
} else if (aNameSpaceID == kNameSpaceID_XLink &&
|
|
|
|
aAttribute == nsGkAtoms::href) {
|
|
|
|
// we're changing our nature, clear out the clone information
|
2012-11-28 09:42:13 +00:00
|
|
|
nsSVGUtils::InvalidateBounds(this, false);
|
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2012-07-30 14:20:58 +00:00
|
|
|
useElement->mOriginal = nullptr;
|
2012-06-23 16:36:46 +00:00
|
|
|
useElement->UnlinkSource();
|
|
|
|
useElement->TriggerReclone();
|
2006-03-02 20:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsSVGUseFrameBase::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
|
|
|
}
|
|
|
|
|
2007-02-18 17:34:09 +00:00
|
|
|
void
|
2009-12-24 05:21:15 +00:00
|
|
|
nsSVGUseFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-02-18 17:34:09 +00:00
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
nsRefPtr<nsSVGUseElement> use = static_cast<nsSVGUseElement*>(mContent);
|
2009-12-24 05:21:15 +00:00
|
|
|
nsSVGUseFrameBase::DestroyFrom(aDestructRoot);
|
2007-06-18 15:30:57 +00:00
|
|
|
use->DestroyAnonymousContent();
|
2007-02-18 17:34:09 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-03-04 12:55:28 +00:00
|
|
|
nsSVGUseFrame::IsLeaf() const
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-03-04 12:55:28 +00:00
|
|
|
}
|
2006-03-02 20:22:19 +00:00
|
|
|
|
2004-11-23 13:51:57 +00:00
|
|
|
|
2012-02-01 16:25:44 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGChildFrame methods
|
|
|
|
|
2012-05-17 04:05:09 +00:00
|
|
|
void
|
2012-07-22 00:01:44 +00:00
|
|
|
nsSVGUseFrame::ReflowSVG()
|
2012-05-17 04:05:09 +00: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;
|
|
|
|
static_cast<nsSVGUseElement*>(mContent)->
|
2012-07-30 14:20:58 +00:00
|
|
|
GetAnimatedLengthValues(&x, &y, nullptr);
|
2012-05-17 04:05:09 +00:00
|
|
|
mRect.MoveTo(nsLayoutUtils::RoundGfxRectToAppRect(
|
|
|
|
gfxRect(x, y, 0.0, 0.0),
|
|
|
|
PresContext()->AppUnitsPerCSSPixel()).TopLeft());
|
2012-07-22 00:01:44 +00:00
|
|
|
nsSVGUseFrameBase::ReflowSVG();
|
2012-05-17 04:05:09 +00:00
|
|
|
}
|
|
|
|
|
2012-02-01 16:25:44 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsSVGUseFrame::NotifySVGChanged(uint32_t aFlags)
|
2012-02-01 16:25:44 +00:00
|
|
|
{
|
|
|
|
if (aFlags & COORD_CONTEXT_CHANGED &&
|
|
|
|
!(aFlags & TRANSFORM_CHANGED)) {
|
|
|
|
// Coordinate context changes affect mCanvasTM if we have a
|
|
|
|
// percentage 'x' or 'y'
|
|
|
|
nsSVGUseElement *use = static_cast<nsSVGUseElement*>(mContent);
|
|
|
|
if (use->mLengthAttributes[nsSVGUseElement::X].IsPercentage() ||
|
|
|
|
use->mLengthAttributes[nsSVGUseElement::Y].IsPercentage()) {
|
|
|
|
aFlags |= TRANSFORM_CHANGED;
|
2012-06-23 16:36:46 +00: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-22 00:01:44 +00:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2012-02-01 16:25:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-19 13:50:07 +00: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 16:25:44 +00:00
|
|
|
nsSVGUseFrameBase::NotifySVGChanged(aFlags);
|
|
|
|
}
|
|
|
|
|
2004-11-23 13:51:57 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIAnonymousContentCreator methods:
|
|
|
|
|
2007-02-18 17:34:09 +00:00
|
|
|
nsresult
|
2011-05-06 20:04:44 +00:00
|
|
|
nsSVGUseFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
2004-11-23 13:51:57 +00:00
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
nsSVGUseElement *use = static_cast<nsSVGUseElement*>(mContent);
|
2004-11-23 13:51:57 +00:00
|
|
|
|
2007-02-18 17:34:09 +00:00
|
|
|
nsIContent* clone = use->CreateAnonymousContent();
|
|
|
|
if (!clone)
|
2004-11-23 13:51:57 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2007-02-18 17:34:09 +00:00
|
|
|
if (!aElements.AppendElement(clone))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return NS_OK;
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
2010-02-11 17:34:01 +00:00
|
|
|
|
|
|
|
void
|
2010-10-15 15:34:35 +00:00
|
|
|
nsSVGUseFrame::AppendAnonymousContentTo(nsBaseContentList& aElements,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aFilter)
|
2010-02-11 17:34:01 +00:00
|
|
|
{
|
|
|
|
nsSVGUseElement *use = static_cast<nsSVGUseElement*>(mContent);
|
|
|
|
nsIContent* clone = use->GetAnonymousContent();
|
|
|
|
aElements.MaybeAppendElement(clone);
|
|
|
|
}
|