2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
2010-04-29 03:00:54 +04:00
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
#include "mozilla/dom/SVGMPathElement.h"
|
2010-04-29 03:00:54 +04:00
|
|
|
#include "nsDebug.h"
|
2013-01-06 13:32:02 +04:00
|
|
|
#include "mozilla/dom/SVGAnimateMotionElement.h"
|
2013-01-13 02:22:31 +04:00
|
|
|
#include "mozilla/dom/SVGPathElement.h"
|
2012-01-26 13:57:21 +04:00
|
|
|
#include "nsContentUtils.h"
|
2013-01-05 05:50:22 +04:00
|
|
|
#include "mozilla/dom/SVGMPathElementBinding.h"
|
2013-08-24 06:42:40 +04:00
|
|
|
#include "nsIURI.h"
|
2010-04-29 03:00:54 +04:00
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(MPath)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
JSObject* SVGMPathElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return SVGMPathElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-01-05 05:50:22 +04:00
|
|
|
}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::StringInfo SVGMPathElement::sStringInfo[2] = {
|
2018-03-29 12:45:24 +03:00
|
|
|
{nsGkAtoms::href, kNameSpaceID_None, false},
|
|
|
|
{nsGkAtoms::href, kNameSpaceID_XLink, false}};
|
2010-04-29 03:00:54 +04:00
|
|
|
|
2016-09-22 17:33:42 +03:00
|
|
|
// Cycle collection magic -- based on SVGUseElement
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(SVGMPathElement)
|
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SVGMPathElement,
|
|
|
|
SVGMPathElementBase)
|
2011-10-17 18:59:28 +04:00
|
|
|
tmp->UnlinkHrefTarget(false);
|
2010-04-29 03:00:54 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SVGMPathElement,
|
|
|
|
SVGMPathElementBase)
|
2017-09-12 16:37:10 +03:00
|
|
|
tmp->mPathTracker.Traverse(&cb);
|
2010-04-29 03:00:54 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
2017-09-01 02:29:22 +03:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(SVGMPathElement,
|
|
|
|
SVGMPathElementBase,
|
|
|
|
nsIMutationObserver)
|
2010-04-29 03:00:54 +04:00
|
|
|
|
|
|
|
// Constructor
|
2018-09-21 23:45:49 +03:00
|
|
|
SVGMPathElement::SVGMPathElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
|
|
: SVGMPathElementBase(std::move(aNodeInfo)), mPathTracker(this) {}
|
2010-04-29 03:00:54 +04:00
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
SVGMPathElement::~SVGMPathElement() { UnlinkHrefTarget(false); }
|
2010-04-29 03:00:54 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-05-30 05:58:49 +03:00
|
|
|
// nsINode methods
|
2010-04-29 03:00:54 +04:00
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGMPathElement)
|
2010-04-29 03:00:54 +04:00
|
|
|
|
2013-06-15 02:37:27 +04:00
|
|
|
already_AddRefed<SVGAnimatedString> SVGMPathElement::Href() {
|
2016-07-06 11:40:30 +03:00
|
|
|
return mStringAttributes[HREF].IsExplicitlySet()
|
|
|
|
? mStringAttributes[HREF].ToDOMAnimatedString(this)
|
|
|
|
: mStringAttributes[XLINK_HREF].ToDOMAnimatedString(this);
|
2013-01-05 05:50:22 +04:00
|
|
|
}
|
|
|
|
|
2010-04-29 03:00:54 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
nsresult SVGMPathElement::BindToTree(nsIDocument* aDocument,
|
|
|
|
nsIContent* aParent,
|
2018-07-31 21:18:38 +03:00
|
|
|
nsIContent* aBindingParent) {
|
2017-09-12 16:37:10 +03:00
|
|
|
MOZ_ASSERT(!mPathTracker.get(),
|
2015-02-10 01:34:50 +03:00
|
|
|
"Shouldn't have href-target yet (or it should've been cleared)");
|
2013-01-05 05:50:22 +04:00
|
|
|
nsresult rv =
|
|
|
|
SVGMPathElementBase::BindToTree(aDocument, aParent, aBindingParent);
|
2010-04-29 03:00:54 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (aDocument) {
|
|
|
|
const nsAttrValue* hrefAttrValue =
|
2016-07-06 11:40:30 +03:00
|
|
|
HasAttr(kNameSpaceID_None, nsGkAtoms::href)
|
2018-08-07 22:07:26 +03:00
|
|
|
? mAttrs.GetAttr(nsGkAtoms::href, kNameSpaceID_None)
|
|
|
|
: mAttrs.GetAttr(nsGkAtoms::href, kNameSpaceID_XLink);
|
2010-04-29 03:00:54 +04:00
|
|
|
if (hrefAttrValue) {
|
|
|
|
UpdateHrefTarget(aParent, hrefAttrValue->GetStringValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
void SVGMPathElement::UnbindFromTree(bool aDeep, bool aNullParent) {
|
2011-10-17 18:59:28 +04:00
|
|
|
UnlinkHrefTarget(true);
|
2013-01-05 05:50:22 +04:00
|
|
|
SVGMPathElementBase::UnbindFromTree(aDeep, aNullParent);
|
2010-04-29 03:00:54 +04:00
|
|
|
}
|
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
bool SVGMPathElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
2017-11-02 06:35:52 +03:00
|
|
|
const nsAString& aValue,
|
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2013-01-05 05:50:22 +04:00
|
|
|
nsAttrValue& aResult) {
|
2018-01-04 05:03:29 +03:00
|
|
|
bool returnVal = SVGMPathElementBase::ParseAttribute(
|
2017-11-02 06:35:52 +03:00
|
|
|
aNamespaceID, aAttribute, aValue, aMaybeScriptedPrincipal, aResult);
|
2016-07-06 11:40:30 +03:00
|
|
|
if ((aNamespaceID == kNameSpaceID_XLink ||
|
|
|
|
aNamespaceID == kNameSpaceID_None) &&
|
2010-04-29 03:00:54 +04:00
|
|
|
aAttribute == nsGkAtoms::href && IsInUncomposedDoc()) {
|
2016-07-06 11:40:30 +03:00
|
|
|
// Note: If we fail the IsInDoc call, it's ok -- we'll update the target
|
2010-04-29 03:00:54 +04:00
|
|
|
// on next BindToTree call.
|
2016-07-06 11:40:30 +03:00
|
|
|
|
|
|
|
// Note: "href" takes priority over xlink:href. So if "xlink:href" is being
|
|
|
|
// set here, we only let that update our target if "href" is *unset*.
|
|
|
|
if (aNamespaceID != kNameSpaceID_XLink ||
|
|
|
|
!mStringAttributes[HREF].IsExplicitlySet()) {
|
|
|
|
UpdateHrefTarget(GetParent(), aValue);
|
|
|
|
}
|
2010-04-29 03:00:54 +04:00
|
|
|
}
|
|
|
|
return returnVal;
|
|
|
|
}
|
|
|
|
|
2018-01-04 05:03:29 +03:00
|
|
|
nsresult SVGMPathElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue,
|
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
|
|
|
bool aNotify) {
|
|
|
|
if (!aValue && aName == nsGkAtoms::href) {
|
|
|
|
// href attr being removed.
|
2016-07-06 11:40:30 +03:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
UnlinkHrefTarget(true);
|
|
|
|
|
|
|
|
// After unsetting href, we may still have xlink:href, so we should
|
|
|
|
// try to add it back.
|
|
|
|
const nsAttrValue* xlinkHref =
|
2018-08-07 22:07:26 +03:00
|
|
|
mAttrs.GetAttr(nsGkAtoms::href, kNameSpaceID_XLink);
|
2016-07-06 11:40:30 +03:00
|
|
|
if (xlinkHref) {
|
|
|
|
UpdateHrefTarget(GetParent(), xlinkHref->GetStringValue());
|
|
|
|
}
|
2018-01-04 05:03:29 +03:00
|
|
|
} else if (aNamespaceID == kNameSpaceID_XLink &&
|
|
|
|
!HasAttr(kNameSpaceID_None, nsGkAtoms::href)) {
|
2016-07-06 11:40:30 +03:00
|
|
|
UnlinkHrefTarget(true);
|
2018-01-04 05:03:29 +03:00
|
|
|
} // else: we unset some random-namespace href attribute, or unset
|
|
|
|
// xlink:href but still have href attribute, so keep the target linking
|
|
|
|
// to href.
|
2010-04-29 03:00:54 +04:00
|
|
|
}
|
|
|
|
|
2018-01-04 05:03:29 +03:00
|
|
|
return SVGMPathElementBase::AfterSetAttr(
|
|
|
|
aNamespaceID, aName, aValue, aOldValue, aMaybeScriptedPrincipal, aNotify);
|
2010-04-29 03:00:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-21 11:58:14 +03:00
|
|
|
// SVGElement methods
|
2010-04-29 03:00:54 +04:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::StringAttributesInfo SVGMPathElement::GetStringInfo() {
|
2010-04-29 03:00:54 +04:00
|
|
|
return StringAttributesInfo(mStringAttributes, sStringInfo,
|
2011-10-11 09:50:08 +04:00
|
|
|
ArrayLength(sStringInfo));
|
2010-04-29 03:00:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIMutationObserver methods
|
|
|
|
|
2018-03-01 14:36:58 +03:00
|
|
|
void SVGMPathElement::AttributeChanged(Element* aElement, int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute, int32_t aModType,
|
2015-07-25 09:01:19 +03:00
|
|
|
const nsAttrValue* aOldValue) {
|
2010-04-29 03:00:54 +04:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::d) {
|
|
|
|
NotifyParentOfMpathChange(GetParent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Public helper methods
|
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
SVGPathElement* SVGMPathElement::GetReferencedPath() {
|
2016-07-06 11:40:30 +03:00
|
|
|
if (!HasAttr(kNameSpaceID_XLink, nsGkAtoms::href) &&
|
|
|
|
!HasAttr(kNameSpaceID_None, nsGkAtoms::href)) {
|
2017-09-12 16:37:10 +03:00
|
|
|
MOZ_ASSERT(!mPathTracker.get(),
|
2016-07-06 11:40:30 +03:00
|
|
|
"We shouldn't have a href target "
|
|
|
|
"if we don't have an xlink:href or href attribute");
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-04-29 03:00:54 +04:00
|
|
|
}
|
|
|
|
|
2017-09-12 16:37:10 +03:00
|
|
|
nsIContent* genericTarget = mPathTracker.get();
|
2015-03-03 14:08:59 +03:00
|
|
|
if (genericTarget && genericTarget->IsSVGElement(nsGkAtoms::path)) {
|
2013-01-13 02:22:31 +04:00
|
|
|
return static_cast<SVGPathElement*>(genericTarget);
|
2010-04-29 03:00:54 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-04-29 03:00:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Protected helper methods
|
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
void SVGMPathElement::UpdateHrefTarget(nsIContent* aParent,
|
|
|
|
const nsAString& aHrefStr) {
|
2010-04-29 03:00:54 +04:00
|
|
|
nsCOMPtr<nsIURI> targetURI;
|
|
|
|
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
|
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI), aHrefStr,
|
2011-10-18 14:53:36 +04:00
|
|
|
OwnerDoc(), baseURI);
|
2010-04-29 03:00:54 +04:00
|
|
|
|
|
|
|
// Stop observing old target (if any)
|
2017-09-12 16:37:10 +03:00
|
|
|
if (mPathTracker.get()) {
|
|
|
|
mPathTracker.get()->RemoveMutationObserver(this);
|
2010-04-29 03:00:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aParent) {
|
|
|
|
// Pass in |aParent| instead of |this| -- first argument is only used
|
2014-10-03 16:32:26 +04:00
|
|
|
// for a call to GetComposedDoc(), and |this| might not have a current
|
2010-04-29 03:00:54 +04:00
|
|
|
// document yet (if our caller is BindToTree).
|
2018-09-17 08:37:46 +03:00
|
|
|
// Bug 1415044 to investigate which referrer we should use
|
2018-10-29 13:42:14 +03:00
|
|
|
mPathTracker.ResetToURIFragmentID(aParent, targetURI,
|
|
|
|
OwnerDoc()->GetDocumentURI(),
|
|
|
|
OwnerDoc()->GetReferrerPolicy());
|
2010-04-29 03:00:54 +04:00
|
|
|
} else {
|
|
|
|
// if we don't have a parent, then there's no animateMotion element
|
|
|
|
// depending on our target, so there's no point tracking it right now.
|
2017-09-12 16:37:10 +03:00
|
|
|
mPathTracker.Unlink();
|
2010-04-29 03:00:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start observing new target (if any)
|
2017-09-12 16:37:10 +03:00
|
|
|
if (mPathTracker.get()) {
|
|
|
|
mPathTracker.get()->AddMutationObserver(this);
|
2010-04-29 03:00:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NotifyParentOfMpathChange(aParent);
|
|
|
|
}
|
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
void SVGMPathElement::UnlinkHrefTarget(bool aNotifyParent) {
|
2010-04-29 03:00:54 +04:00
|
|
|
// Stop observing old target (if any)
|
2017-09-12 16:37:10 +03:00
|
|
|
if (mPathTracker.get()) {
|
|
|
|
mPathTracker.get()->RemoveMutationObserver(this);
|
2010-04-29 03:00:54 +04:00
|
|
|
}
|
2017-09-12 16:37:10 +03:00
|
|
|
mPathTracker.Unlink();
|
2010-04-29 03:00:54 +04:00
|
|
|
|
|
|
|
if (aNotifyParent) {
|
|
|
|
NotifyParentOfMpathChange(GetParent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
void SVGMPathElement::NotifyParentOfMpathChange(nsIContent* aParent) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (aParent && aParent->IsSVGElement(nsGkAtoms::animateMotion)) {
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGAnimateMotionElement* animateMotionParent =
|
|
|
|
static_cast<SVGAnimateMotionElement*>(aParent);
|
2010-04-29 03:00:54 +04:00
|
|
|
|
|
|
|
animateMotionParent->MpathChanged();
|
|
|
|
AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
}
|
2013-01-05 05:50:22 +04:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|