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
|
|
|
|
2013-12-09 02:52:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2013-01-16 20:50:58 +00:00
|
|
|
#include "mozilla/dom/SVGUseElement.h"
|
2013-01-16 20:50:59 +00:00
|
|
|
#include "mozilla/dom/SVGUseElementBinding.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2013-01-09 23:02:45 +00:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
2004-11-23 13:51:57 +00:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPresShell.h"
|
2010-08-24 07:05:56 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2011-08-11 13:29:50 +00:00
|
|
|
#include "nsContentUtils.h"
|
2013-08-24 02:42:40 +00:00
|
|
|
#include "nsIURI.h"
|
2010-08-24 07:05:56 +00:00
|
|
|
|
2013-01-16 20:50:58 +00:00
|
|
|
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Use)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2004-11-23 13:51:57 +00:00
|
|
|
|
2013-01-16 20:50:59 +00:00
|
|
|
JSObject*
|
2014-04-08 22:27:17 +00:00
|
|
|
SVGUseElement::WrapNode(JSContext *aCx)
|
2013-01-16 20:50:59 +00:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return SVGUseElementBinding::Wrap(aCx, this);
|
2013-01-16 20:50:59 +00:00
|
|
|
}
|
|
|
|
|
2004-11-23 13:51:57 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// implementation
|
|
|
|
|
2013-01-16 20:50:58 +00:00
|
|
|
nsSVGElement::LengthInfo SVGUseElement::sLengthInfo[4] =
|
2006-04-14 15:09:39 +00:00
|
|
|
{
|
2012-09-22 19:26:05 +00:00
|
|
|
{ &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
|
|
|
|
{ &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
|
|
|
|
{ &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
|
|
|
|
{ &nsGkAtoms::height, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
|
2006-04-14 15:09:39 +00:00
|
|
|
};
|
2004-11-23 13:51:57 +00:00
|
|
|
|
2013-01-16 20:50:58 +00:00
|
|
|
nsSVGElement::StringInfo SVGUseElement::sStringInfo[1] =
|
2008-06-14 09:01:02 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
{ &nsGkAtoms::href, kNameSpaceID_XLink, true }
|
2008-06-14 09:01:02 +00:00
|
|
|
};
|
|
|
|
|
2004-11-23 13:51:57 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(SVGUseElement)
|
|
|
|
|
2013-01-16 20:50:58 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SVGUseElement,
|
|
|
|
SVGUseElementBase)
|
2008-04-11 17:29:06 +00:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOriginal)
|
2007-11-30 18:41:10 +00:00
|
|
|
tmp->DestroyAnonymousContent();
|
2008-06-25 22:41:04 +00:00
|
|
|
tmp->UnlinkSource();
|
2007-11-30 18:41:10 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2013-01-16 20:50:58 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SVGUseElement,
|
|
|
|
SVGUseElementBase)
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOriginal)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mClone)
|
2008-06-25 22:41:04 +00:00
|
|
|
tmp->mSource.Traverse(&cb);
|
2007-11-30 18:41:10 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2013-01-16 20:50:58 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(SVGUseElement,SVGUseElementBase)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(SVGUseElement,SVGUseElementBase)
|
2010-01-12 13:08:43 +00:00
|
|
|
|
2013-01-16 20:50:58 +00:00
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(SVGUseElement)
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(SVGUseElement, nsIMutationObserver)
|
2013-05-21 19:59:27 +00:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(SVGUseElementBase)
|
2004-11-23 13:51:57 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
SVGUseElement::SVGUseElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2015-01-07 05:39:46 +00:00
|
|
|
: SVGUseElementBase(aNodeInfo), mSource(this)
|
2004-11-23 13:51:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::~SVGUseElement()
|
2004-11-23 13:51:57 +00:00
|
|
|
{
|
2008-06-25 22:41:04 +00:00
|
|
|
UnlinkSource();
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMNode methods
|
|
|
|
|
2005-09-20 17:07:14 +00:00
|
|
|
nsresult
|
2014-06-20 02:01:40 +00:00
|
|
|
SVGUseElement::Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const
|
2005-09-20 15:40:57 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aResult = nullptr;
|
2014-06-20 02:01:40 +00:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo> ni = nsRefPtr<mozilla::dom::NodeInfo>(aNodeInfo).forget();
|
2014-03-15 19:00:17 +00:00
|
|
|
SVGUseElement *it = new SVGUseElement(ni);
|
2005-09-20 15:40:57 +00:00
|
|
|
|
2006-09-05 10:22:54 +00:00
|
|
|
nsCOMPtr<nsINode> kungFuDeathGrip(it);
|
2012-07-27 14:03:08 +00:00
|
|
|
nsresult rv1 = it->Init();
|
2013-01-16 20:50:58 +00:00
|
|
|
nsresult rv2 = const_cast<SVGUseElement*>(this)->CopyInnerTo(it);
|
2005-09-20 15:40:57 +00:00
|
|
|
|
2013-01-16 20:50:58 +00:00
|
|
|
// SVGUseElement specific portion - record who we cloned from
|
|
|
|
it->mOriginal = const_cast<SVGUseElement*>(this);
|
2005-09-20 15:40:57 +00:00
|
|
|
|
2012-07-27 14:03:08 +00:00
|
|
|
if (NS_SUCCEEDED(rv1) && NS_SUCCEEDED(rv2)) {
|
2005-09-20 15:40:57 +00:00
|
|
|
kungFuDeathGrip.swap(*aResult);
|
|
|
|
}
|
|
|
|
|
2012-07-27 14:03:08 +00:00
|
|
|
return NS_FAILED(rv1) ? rv1 : rv2;
|
2005-09-20 15:40:57 +00:00
|
|
|
}
|
|
|
|
|
2013-06-14 22:37:27 +00:00
|
|
|
already_AddRefed<SVGAnimatedString>
|
2013-01-16 20:50:59 +00:00
|
|
|
SVGUseElement::Href()
|
|
|
|
{
|
2013-06-14 22:37:27 +00:00
|
|
|
return mStringAttributes[HREF].ToDOMAnimatedString(this);
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2013-01-16 20:50:59 +00:00
|
|
|
|
2013-01-19 20:56:00 +00:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-16 20:50:59 +00:00
|
|
|
SVGUseElement::X()
|
|
|
|
{
|
|
|
|
return mLengthAttributes[ATTR_X].ToDOMAnimatedLength(this);
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
2013-01-19 20:56:00 +00:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-16 20:50:59 +00:00
|
|
|
SVGUseElement::Y()
|
|
|
|
{
|
|
|
|
return mLengthAttributes[ATTR_Y].ToDOMAnimatedLength(this);
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
2013-01-19 20:56:00 +00:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-16 20:50:59 +00:00
|
|
|
SVGUseElement::Width()
|
|
|
|
{
|
|
|
|
return mLengthAttributes[ATTR_WIDTH].ToDOMAnimatedLength(this);
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
2013-01-19 20:56:00 +00:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-16 20:50:59 +00:00
|
|
|
SVGUseElement::Height()
|
|
|
|
{
|
|
|
|
return mLengthAttributes[ATTR_HEIGHT].ToDOMAnimatedLength(this);
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2006-07-11 19:41:11 +00:00
|
|
|
// nsIMutationObserver methods
|
2004-11-23 13:51:57 +00:00
|
|
|
|
2006-07-11 19:41:11 +00:00
|
|
|
void
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::CharacterDataChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent *aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo)
|
2004-11-23 13:51:57 +00:00
|
|
|
{
|
2007-06-06 20:01:56 +00:00
|
|
|
if (nsContentUtils::IsInSameAnonymousTree(this, aContent)) {
|
|
|
|
TriggerReclone();
|
|
|
|
}
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
2006-07-11 19:41:11 +00:00
|
|
|
void
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::AttributeChanged(nsIDocument* aDocument,
|
|
|
|
Element* aElement,
|
|
|
|
int32_t aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
int32_t aModType)
|
2004-11-23 13:51:57 +00:00
|
|
|
{
|
2010-08-24 07:05:56 +00:00
|
|
|
if (nsContentUtils::IsInSameAnonymousTree(this, aElement)) {
|
2007-06-06 20:01:56 +00:00
|
|
|
TriggerReclone();
|
|
|
|
}
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
2006-07-11 19:41:11 +00:00
|
|
|
void
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::ContentAppended(nsIDocument *aDocument,
|
|
|
|
nsIContent *aContainer,
|
|
|
|
nsIContent *aFirstNewContent,
|
|
|
|
int32_t aNewIndexInContainer)
|
2004-11-23 13:51:57 +00:00
|
|
|
{
|
2007-06-06 20:01:56 +00:00
|
|
|
if (nsContentUtils::IsInSameAnonymousTree(this, aContainer)) {
|
|
|
|
TriggerReclone();
|
|
|
|
}
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
2006-07-11 19:41:11 +00:00
|
|
|
void
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::ContentInserted(nsIDocument *aDocument,
|
|
|
|
nsIContent *aContainer,
|
|
|
|
nsIContent *aChild,
|
|
|
|
int32_t aIndexInContainer)
|
2004-11-23 13:51:57 +00:00
|
|
|
{
|
2007-06-06 20:01:56 +00:00
|
|
|
if (nsContentUtils::IsInSameAnonymousTree(this, aChild)) {
|
|
|
|
TriggerReclone();
|
|
|
|
}
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
2006-07-11 19:41:11 +00:00
|
|
|
void
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::ContentRemoved(nsIDocument *aDocument,
|
|
|
|
nsIContent *aContainer,
|
|
|
|
nsIContent *aChild,
|
|
|
|
int32_t aIndexInContainer,
|
|
|
|
nsIContent *aPreviousSibling)
|
2004-11-23 13:51:57 +00:00
|
|
|
{
|
2007-06-06 20:01:56 +00:00
|
|
|
if (nsContentUtils::IsInSameAnonymousTree(this, aChild)) {
|
|
|
|
TriggerReclone();
|
|
|
|
}
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
2006-07-11 19:41:11 +00:00
|
|
|
void
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::NodeWillBeDestroyed(const nsINode *aNode)
|
2004-11-23 13:51:57 +00:00
|
|
|
{
|
2010-07-21 15:33:32 +00:00
|
|
|
nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this);
|
2008-06-25 22:41:04 +00:00
|
|
|
UnlinkSource();
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2007-02-18 17:34:09 +00:00
|
|
|
nsIContent*
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::CreateAnonymousContent()
|
2004-11-23 13:51:57 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
mClone = nullptr;
|
2005-01-19 20:54:26 +00:00
|
|
|
|
2008-06-25 22:41:04 +00:00
|
|
|
if (mSource.get()) {
|
|
|
|
mSource.get()->RemoveMutationObserver(this);
|
|
|
|
}
|
2006-07-11 19:41:11 +00:00
|
|
|
|
2008-06-25 22:41:04 +00:00
|
|
|
LookupHref();
|
|
|
|
nsIContent* targetContent = mSource.get();
|
2012-02-02 20:50:50 +00:00
|
|
|
if (!targetContent || !targetContent->IsSVG())
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2004-11-23 13:51:57 +00:00
|
|
|
|
|
|
|
// make sure target is valid type for <use>
|
|
|
|
// QIable nsSVGGraphicsElement would eliminate enumerating all elements
|
|
|
|
nsIAtom *tag = targetContent->Tag();
|
2006-12-26 17:47:52 +00:00
|
|
|
if (tag != nsGkAtoms::svg &&
|
|
|
|
tag != nsGkAtoms::symbol &&
|
|
|
|
tag != nsGkAtoms::g &&
|
|
|
|
tag != nsGkAtoms::path &&
|
|
|
|
tag != nsGkAtoms::text &&
|
|
|
|
tag != nsGkAtoms::rect &&
|
|
|
|
tag != nsGkAtoms::circle &&
|
|
|
|
tag != nsGkAtoms::ellipse &&
|
|
|
|
tag != nsGkAtoms::line &&
|
|
|
|
tag != nsGkAtoms::polyline &&
|
|
|
|
tag != nsGkAtoms::polygon &&
|
|
|
|
tag != nsGkAtoms::image &&
|
|
|
|
tag != nsGkAtoms::use)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2004-11-23 13:51:57 +00:00
|
|
|
|
2005-01-19 20:52:43 +00:00
|
|
|
// circular loop detection
|
2005-09-20 15:40:57 +00:00
|
|
|
|
|
|
|
// check 1 - check if we're a document descendent of the target
|
2005-01-19 20:52:43 +00:00
|
|
|
if (nsContentUtils::ContentIsDescendantOf(this, targetContent))
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2005-09-20 15:40:57 +00:00
|
|
|
|
|
|
|
// check 2 - check if we're a clone, and if we already exist in the hierarchy
|
2012-03-03 09:21:09 +00:00
|
|
|
if (GetParent() && mOriginal) {
|
|
|
|
for (nsCOMPtr<nsIContent> content = GetParent();
|
2005-09-20 15:40:57 +00:00
|
|
|
content;
|
|
|
|
content = content->GetParent()) {
|
2013-02-08 19:55:51 +00:00
|
|
|
if (content->IsSVG(nsGkAtoms::use) &&
|
|
|
|
static_cast<SVGUseElement*>(content.get())->mOriginal == mOriginal) {
|
|
|
|
return nullptr;
|
2005-09-20 15:40:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-01-19 20:52:43 +00:00
|
|
|
|
2012-10-09 12:31:24 +00:00
|
|
|
nsCOMPtr<nsINode> newnode;
|
2006-09-05 10:22:54 +00:00
|
|
|
nsCOMArray<nsINode> unused;
|
2008-09-28 19:16:15 +00:00
|
|
|
nsNodeInfoManager* nodeInfoManager =
|
2011-10-18 10:53:36 +00:00
|
|
|
targetContent->OwnerDoc() == OwnerDoc() ?
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr : OwnerDoc()->NodeInfoManager();
|
2011-10-17 14:59:28 +00:00
|
|
|
nsNodeUtils::Clone(targetContent, true, nodeInfoManager, unused,
|
2006-09-05 10:22:54 +00:00
|
|
|
getter_AddRefs(newnode));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> newcontent = do_QueryInterface(newnode);
|
2004-11-23 13:51:57 +00:00
|
|
|
|
2006-07-11 19:41:11 +00:00
|
|
|
if (!newcontent)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2006-07-11 19:41:11 +00:00
|
|
|
|
2013-02-08 19:55:07 +00:00
|
|
|
if (newcontent->IsSVG(nsGkAtoms::symbol)) {
|
2014-10-03 12:32:26 +00:00
|
|
|
nsIDocument *document = GetComposedDoc();
|
2004-11-23 13:51:57 +00:00
|
|
|
if (!document)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2004-11-23 13:51:57 +00:00
|
|
|
|
|
|
|
nsNodeInfoManager *nodeInfoManager = document->NodeInfoManager();
|
|
|
|
if (!nodeInfoManager)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2004-11-23 13:51:57 +00:00
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
nsRefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2012-07-30 14:20:58 +00:00
|
|
|
nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::svg, nullptr,
|
2011-06-14 07:56:49 +00:00
|
|
|
kNameSpaceID_SVG,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2004-11-23 13:51:57 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> svgNode;
|
2010-10-25 12:17:38 +00:00
|
|
|
NS_NewSVGSVGElement(getter_AddRefs(svgNode), nodeInfo.forget(),
|
|
|
|
NOT_FROM_PARSER);
|
2004-11-23 13:51:57 +00:00
|
|
|
|
|
|
|
if (!svgNode)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2004-11-23 13:51:57 +00:00
|
|
|
|
|
|
|
// copy attributes
|
2005-12-28 21:52:39 +00:00
|
|
|
const nsAttrName* name;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t i;
|
2005-12-28 21:52:39 +00:00
|
|
|
for (i = 0; (name = newcontent->GetAttrNameAt(i)); i++) {
|
2004-11-23 13:51:57 +00:00
|
|
|
nsAutoString value;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t nsID = name->NamespaceID();
|
2005-12-28 21:52:39 +00:00
|
|
|
nsIAtom* lname = name->LocalName();
|
2004-11-23 13:51:57 +00:00
|
|
|
|
2005-12-28 21:52:39 +00:00
|
|
|
newcontent->GetAttr(nsID, lname, value);
|
2011-10-17 14:59:28 +00:00
|
|
|
svgNode->SetAttr(nsID, lname, name->GetPrefix(), value, false);
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// move the children over
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t num = newcontent->GetChildCount();
|
2004-11-26 06:05:52 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2011-09-27 07:54:58 +00:00
|
|
|
nsCOMPtr<nsIContent> child = newcontent->GetFirstChild();
|
2011-10-17 14:59:28 +00:00
|
|
|
newcontent->RemoveChildAt(0, false);
|
|
|
|
svgNode->InsertChildAt(child, i, true);
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
newcontent = svgNode;
|
|
|
|
}
|
|
|
|
|
2013-02-08 19:55:07 +00:00
|
|
|
if (newcontent->IsSVG() && (newcontent->Tag() == nsGkAtoms::svg ||
|
|
|
|
newcontent->Tag() == nsGkAtoms::symbol)) {
|
2011-06-20 20:15:42 +00:00
|
|
|
nsSVGElement *newElement = static_cast<nsSVGElement*>(newcontent.get());
|
2004-11-23 13:51:57 +00:00
|
|
|
|
2013-01-16 20:50:59 +00:00
|
|
|
if (mLengthAttributes[ATTR_WIDTH].IsExplicitlySet())
|
|
|
|
newElement->SetLength(nsGkAtoms::width, mLengthAttributes[ATTR_WIDTH]);
|
|
|
|
if (mLengthAttributes[ATTR_HEIGHT].IsExplicitlySet())
|
|
|
|
newElement->SetLength(nsGkAtoms::height, mLengthAttributes[ATTR_HEIGHT]);
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
2008-09-28 19:18:04 +00:00
|
|
|
// Set up its base URI correctly
|
|
|
|
nsCOMPtr<nsIURI> baseURI = targetContent->GetBaseURI();
|
|
|
|
if (!baseURI)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2012-02-02 20:50:50 +00:00
|
|
|
newcontent->SetExplicitBaseURI(baseURI);
|
2008-09-28 19:18:04 +00:00
|
|
|
|
2008-06-25 22:41:04 +00:00
|
|
|
targetContent->AddMutationObserver(this);
|
2005-01-19 20:54:26 +00:00
|
|
|
mClone = newcontent;
|
2007-02-18 17:34:09 +00:00
|
|
|
return mClone;
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
2007-02-18 17:34:09 +00:00
|
|
|
void
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::DestroyAnonymousContent()
|
2004-11-23 13:51:57 +00:00
|
|
|
{
|
2007-02-18 17:34:09 +00:00
|
|
|
nsContentUtils::DestroyAnonymousContent(&mClone);
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
2012-06-23 16:36:46 +00:00
|
|
|
bool
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::OurWidthAndHeightAreUsed() const
|
2012-06-23 16:36:46 +00:00
|
|
|
{
|
2013-02-08 19:55:07 +00:00
|
|
|
return mClone && mClone->IsSVG() && (mClone->Tag() == nsGkAtoms::svg ||
|
|
|
|
mClone->Tag() == nsGkAtoms::symbol);
|
2012-06-23 16:36:46 +00:00
|
|
|
}
|
|
|
|
|
2004-11-23 13:51:57 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// implementation helpers
|
|
|
|
|
2006-04-14 15:09:39 +00:00
|
|
|
void
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::SyncWidthOrHeight(nsIAtom* aName)
|
2006-04-14 15:09:39 +00:00
|
|
|
{
|
2011-10-08 06:32:44 +00:00
|
|
|
NS_ASSERTION(aName == nsGkAtoms::width || aName == nsGkAtoms::height,
|
|
|
|
"The clue is in the function name");
|
2012-06-23 16:36:46 +00:00
|
|
|
NS_ASSERTION(OurWidthAndHeightAreUsed(), "Don't call this");
|
2011-10-08 06:32:44 +00:00
|
|
|
|
2013-02-08 19:55:07 +00:00
|
|
|
if (OurWidthAndHeightAreUsed()) {
|
2012-03-03 09:21:09 +00:00
|
|
|
nsSVGElement *target = static_cast<nsSVGElement*>(mClone.get());
|
2013-01-16 20:50:59 +00:00
|
|
|
uint32_t index = *sLengthInfo[ATTR_WIDTH].mName == aName ? ATTR_WIDTH : ATTR_HEIGHT;
|
2012-03-03 09:21:09 +00:00
|
|
|
|
|
|
|
if (mLengthAttributes[index].IsExplicitlySet()) {
|
|
|
|
target->SetLength(aName, mLengthAttributes[index]);
|
|
|
|
return;
|
2006-04-14 15:09:39 +00:00
|
|
|
}
|
2013-02-08 19:55:07 +00:00
|
|
|
if (mClone->Tag() == nsGkAtoms::svg) {
|
2012-03-03 09:21:09 +00:00
|
|
|
// Our width/height attribute is now no longer explicitly set, so we
|
|
|
|
// need to revert the clone's width/height to the width/height of the
|
|
|
|
// content that's being cloned.
|
2012-03-07 10:50:36 +00:00
|
|
|
TriggerReclone();
|
2012-03-03 09:21:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Our width/height attribute is now no longer explicitly set, so we
|
|
|
|
// need to set the value to 100%
|
|
|
|
nsSVGLength2 length;
|
2012-09-22 19:26:05 +00:00
|
|
|
length.Init(SVGContentUtils::XY, 0xff,
|
2012-03-03 09:21:09 +00:00
|
|
|
100, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE);
|
|
|
|
target->SetLength(aName, length);
|
|
|
|
return;
|
2006-04-14 15:09:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-25 22:41:04 +00:00
|
|
|
void
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::LookupHref()
|
2004-11-23 13:51:57 +00:00
|
|
|
{
|
2009-01-22 00:56:51 +00:00
|
|
|
nsAutoString href;
|
|
|
|
mStringAttributes[HREF].GetAnimValue(href, this);
|
2004-12-02 19:58:19 +00:00
|
|
|
if (href.IsEmpty())
|
2008-06-25 22:41:04 +00:00
|
|
|
return;
|
2004-11-23 13:51:57 +00:00
|
|
|
|
2008-09-28 19:16:15 +00:00
|
|
|
nsCOMPtr<nsIURI> targetURI;
|
|
|
|
nsCOMPtr<nsIURI> baseURI = mOriginal ? mOriginal->GetBaseURI() : GetBaseURI();
|
2006-07-11 19:41:11 +00:00
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI), href,
|
2014-10-03 12:32:26 +00:00
|
|
|
GetComposedDoc(), baseURI);
|
2004-11-23 13:51:57 +00:00
|
|
|
|
2008-06-25 22:41:04 +00:00
|
|
|
mSource.Reset(this, targetURI);
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::TriggerReclone()
|
2004-11-23 13:51:57 +00:00
|
|
|
{
|
2014-10-03 12:32:26 +00:00
|
|
|
nsIDocument *doc = GetComposedDoc();
|
2010-06-25 13:59:57 +00:00
|
|
|
if (!doc)
|
|
|
|
return;
|
|
|
|
nsIPresShell *presShell = doc->GetShell();
|
|
|
|
if (!presShell)
|
|
|
|
return;
|
2008-06-25 22:41:04 +00:00
|
|
|
presShell->PostRecreateFramesFor(this);
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::UnlinkSource()
|
2004-11-23 13:51:57 +00:00
|
|
|
{
|
2008-06-25 22:41:04 +00:00
|
|
|
if (mSource.get()) {
|
|
|
|
mSource.get()->RemoveMutationObserver(this);
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
2008-06-25 22:41:04 +00:00
|
|
|
mSource.Unlink();
|
2004-11-23 13:51:57 +00:00
|
|
|
}
|
2006-04-14 15:09:39 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGElement methods
|
|
|
|
|
2013-12-26 20:13:57 +00:00
|
|
|
/* virtual */ gfxMatrix
|
|
|
|
SVGUseElement::PrependLocalTransformsTo(const gfxMatrix &aMatrix,
|
2013-01-16 20:50:58 +00:00
|
|
|
TransformTypes aWhich) const
|
2009-04-29 04:31:34 +00:00
|
|
|
{
|
2012-02-17 08:12:47 +00:00
|
|
|
// 'transform' attribute:
|
2013-12-26 20:13:57 +00:00
|
|
|
gfxMatrix fromUserSpace =
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElementBase::PrependLocalTransformsTo(aMatrix, aWhich);
|
2012-02-17 08:12:47 +00:00
|
|
|
if (aWhich == eUserSpaceToParent) {
|
|
|
|
return fromUserSpace;
|
|
|
|
}
|
|
|
|
// our 'x' and 'y' attributes:
|
2009-04-29 04:31:34 +00:00
|
|
|
float x, y;
|
2013-01-16 20:50:58 +00:00
|
|
|
const_cast<SVGUseElement*>(this)->GetAnimatedLengthValues(&x, &y, nullptr);
|
2014-09-10 13:26:12 +00:00
|
|
|
gfxMatrix toUserSpace = gfxMatrix::Translation(x, y);
|
2012-02-17 08:12:47 +00:00
|
|
|
if (aWhich == eChildToUserSpace) {
|
2014-08-19 08:31:19 +00:00
|
|
|
return toUserSpace * aMatrix;
|
2012-02-17 08:12:47 +00:00
|
|
|
}
|
|
|
|
NS_ABORT_IF_FALSE(aWhich == eAllTransforms, "Unknown TransformTypes");
|
|
|
|
return toUserSpace * fromUserSpace;
|
2009-04-29 04:31:34 +00:00
|
|
|
}
|
|
|
|
|
2012-03-03 09:21:09 +00:00
|
|
|
/* virtual */ bool
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::HasValidDimensions() const
|
2012-03-03 09:21:09 +00:00
|
|
|
{
|
2013-01-16 20:50:59 +00:00
|
|
|
return (!mLengthAttributes[ATTR_WIDTH].IsExplicitlySet() ||
|
|
|
|
mLengthAttributes[ATTR_WIDTH].GetAnimValInSpecifiedUnits() > 0) &&
|
|
|
|
(!mLengthAttributes[ATTR_HEIGHT].IsExplicitlySet() ||
|
|
|
|
mLengthAttributes[ATTR_HEIGHT].GetAnimValInSpecifiedUnits() > 0);
|
2012-03-03 09:21:09 +00:00
|
|
|
}
|
|
|
|
|
2006-04-14 15:09:39 +00:00
|
|
|
nsSVGElement::LengthAttributesInfo
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::GetLengthInfo()
|
2006-04-14 15:09:39 +00:00
|
|
|
{
|
|
|
|
return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
|
2011-10-11 05:50:08 +00:00
|
|
|
ArrayLength(sLengthInfo));
|
2006-04-14 15:09:39 +00:00
|
|
|
}
|
2006-10-19 23:48:12 +00:00
|
|
|
|
2008-06-14 09:01:02 +00:00
|
|
|
nsSVGElement::StringAttributesInfo
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::GetStringInfo()
|
2008-06-14 09:01:02 +00:00
|
|
|
{
|
|
|
|
return StringAttributesInfo(mStringAttributes, sStringInfo,
|
2011-10-11 05:50:08 +00:00
|
|
|
ArrayLength(sStringInfo));
|
2008-06-14 09:01:02 +00:00
|
|
|
}
|
|
|
|
|
2006-10-19 23:48:12 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElement::IsAttributeMapped(const nsIAtom* name) const
|
2006-10-19 23:48:12 +00:00
|
|
|
{
|
|
|
|
static const MappedAttributeEntry* const map[] = {
|
2007-01-19 15:20:11 +00:00
|
|
|
sFEFloodMap,
|
2007-01-30 13:19:55 +00:00
|
|
|
sFiltersMap,
|
2006-10-19 23:48:12 +00:00
|
|
|
sFontSpecificationMap,
|
|
|
|
sGradientStopMap,
|
2007-07-26 06:57:42 +00:00
|
|
|
sLightingEffectsMap,
|
2006-10-19 23:48:12 +00:00
|
|
|
sMarkersMap,
|
|
|
|
sTextContentElementsMap,
|
2007-01-19 15:20:11 +00:00
|
|
|
sViewportsMap
|
2006-10-19 23:48:12 +00:00
|
|
|
};
|
|
|
|
|
2011-12-18 10:09:27 +00:00
|
|
|
return FindAttributeDependence(name, map) ||
|
2013-01-16 20:50:58 +00:00
|
|
|
SVGUseElementBase::IsAttributeMapped(name);
|
2006-10-19 23:48:12 +00:00
|
|
|
}
|
2009-01-22 00:56:51 +00:00
|
|
|
|
2013-01-16 20:50:58 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|