2010-04-28 16:00:54 -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/. */
|
2010-04-28 16:00:54 -07:00
|
|
|
|
2013-12-08 18:52:54 -08:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-10 22:50:08 -07:00
|
|
|
|
2013-01-04 17:50:22 -08:00
|
|
|
#include "mozilla/dom/SVGMPathElement.h"
|
2010-04-28 16:00:54 -07:00
|
|
|
#include "nsDebug.h"
|
2013-01-06 01:32:02 -08:00
|
|
|
#include "mozilla/dom/SVGAnimateMotionElement.h"
|
2013-01-12 14:22:31 -08:00
|
|
|
#include "mozilla/dom/SVGPathElement.h"
|
2012-01-26 01:57:21 -08:00
|
|
|
#include "nsContentUtils.h"
|
2013-01-04 17:50:22 -08:00
|
|
|
#include "mozilla/dom/SVGMPathElementBinding.h"
|
2013-08-23 19:42:40 -07:00
|
|
|
#include "nsIURI.h"
|
2010-04-28 16:00:54 -07:00
|
|
|
|
2013-01-04 17:50:22 -08:00
|
|
|
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(MPath)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
JSObject*
|
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 07:13:33 -07:00
|
|
|
SVGMPathElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-01-04 17:50:22 -08:00
|
|
|
{
|
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 07:13:33 -07:00
|
|
|
return SVGMPathElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-01-04 17:50:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::StringInfo SVGMPathElement::sStringInfo[1] =
|
2010-04-28 16:00:54 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
{ &nsGkAtoms::href, kNameSpaceID_XLink, false }
|
2010-04-28 16:00:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// Cycle collection magic -- based on nsSVGUseElement
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(SVGMPathElement)
|
|
|
|
|
2013-01-04 17:50:22 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SVGMPathElement,
|
|
|
|
SVGMPathElementBase)
|
2011-10-17 07:59:28 -07:00
|
|
|
tmp->UnlinkHrefTarget(false);
|
2010-04-28 16:00:54 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2013-01-04 17:50:22 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SVGMPathElement,
|
|
|
|
SVGMPathElementBase)
|
2010-04-28 16:00:54 -07:00
|
|
|
tmp->mHrefTarget.Traverse(&cb);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
2013-01-04 17:50:22 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(SVGMPathElement,SVGMPathElementBase)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(SVGMPathElement,SVGMPathElementBase)
|
2010-04-28 16:00:54 -07:00
|
|
|
|
2013-01-04 17:50:22 -08:00
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(SVGMPathElement)
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(SVGMPathElement, nsIDOMNode, nsIDOMElement,
|
|
|
|
nsIDOMSVGElement,
|
|
|
|
nsIMutationObserver)
|
2013-05-21 12:59:27 -07:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(SVGMPathElementBase)
|
2010-04-28 16:00:54 -07:00
|
|
|
|
|
|
|
// Constructor
|
2014-06-19 19:01:40 -07:00
|
|
|
SVGMPathElement::SVGMPathElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-01-04 17:50:22 -08:00
|
|
|
: SVGMPathElementBase(aNodeInfo),
|
2015-01-06 21:39:46 -08:00
|
|
|
mHrefTarget(this)
|
2010-04-28 16:00:54 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-04 17:50:22 -08:00
|
|
|
SVGMPathElement::~SVGMPathElement()
|
2010-04-28 16:00:54 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
UnlinkHrefTarget(false);
|
2010-04-28 16:00:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMNode methods
|
|
|
|
|
2013-01-04 17:50:22 -08:00
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGMPathElement)
|
2010-04-28 16:00:54 -07:00
|
|
|
|
2013-06-14 15:37:27 -07:00
|
|
|
already_AddRefed<SVGAnimatedString>
|
2013-01-04 17:50:22 -08:00
|
|
|
SVGMPathElement::Href()
|
|
|
|
{
|
2013-02-07 00:08:56 -08:00
|
|
|
return mStringAttributes[HREF].ToDOMAnimatedString(this);
|
2013-01-04 17:50:22 -08:00
|
|
|
}
|
|
|
|
|
2010-04-28 16:00:54 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
|
|
|
nsresult
|
2013-01-04 17:50:22 -08:00
|
|
|
SVGMPathElement::BindToTree(nsIDocument* aDocument,
|
|
|
|
nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2010-04-28 16:00:54 -07:00
|
|
|
{
|
2015-02-09 14:34:50 -08:00
|
|
|
MOZ_ASSERT(!mHrefTarget.get(),
|
|
|
|
"Shouldn't have href-target yet (or it should've been cleared)");
|
2013-01-04 17:50:22 -08:00
|
|
|
nsresult rv = SVGMPathElementBase::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
2010-04-28 16:00:54 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
|
|
|
|
if (aDocument) {
|
|
|
|
const nsAttrValue* hrefAttrValue =
|
|
|
|
mAttrsAndChildren.GetAttr(nsGkAtoms::href, kNameSpaceID_XLink);
|
|
|
|
if (hrefAttrValue) {
|
|
|
|
UpdateHrefTarget(aParent, hrefAttrValue->GetStringValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-04 17:50:22 -08:00
|
|
|
SVGMPathElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2010-04-28 16:00:54 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
UnlinkHrefTarget(true);
|
2013-01-04 17:50:22 -08:00
|
|
|
SVGMPathElementBase::UnbindFromTree(aDeep, aNullParent);
|
2010-04-28 16:00:54 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-01-04 17:50:22 -08:00
|
|
|
SVGMPathElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
2010-04-28 16:00:54 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool returnVal =
|
2013-01-04 17:50:22 -08:00
|
|
|
SVGMPathElementBase::ParseAttribute(aNamespaceID, aAttribute,
|
2010-04-28 16:00:54 -07:00
|
|
|
aValue, aResult);
|
|
|
|
if (aNamespaceID == kNameSpaceID_XLink &&
|
|
|
|
aAttribute == nsGkAtoms::href &&
|
|
|
|
IsInDoc()) {
|
|
|
|
// NOTE: If we fail the IsInDoc call, it's ok -- we'll update the target
|
|
|
|
// on next BindToTree call.
|
|
|
|
UpdateHrefTarget(GetParent(), aValue);
|
|
|
|
}
|
|
|
|
return returnVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-01-04 17:50:22 -08:00
|
|
|
SVGMPathElement::UnsetAttr(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute, bool aNotify)
|
2010-04-28 16:00:54 -07:00
|
|
|
{
|
2013-01-04 17:50:22 -08:00
|
|
|
nsresult rv = SVGMPathElementBase::UnsetAttr(aNamespaceID, aAttribute,
|
|
|
|
aNotify);
|
2010-04-28 16:00:54 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (aNamespaceID == kNameSpaceID_XLink &&
|
|
|
|
aAttribute == nsGkAtoms::href) {
|
2011-10-17 07:59:28 -07:00
|
|
|
UnlinkHrefTarget(true);
|
2010-04-28 16:00:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGElement methods
|
|
|
|
|
|
|
|
nsSVGElement::StringAttributesInfo
|
2013-01-04 17:50:22 -08:00
|
|
|
SVGMPathElement::GetStringInfo()
|
2010-04-28 16:00:54 -07:00
|
|
|
{
|
|
|
|
return StringAttributesInfo(mStringAttributes, sStringInfo,
|
2011-10-10 22:50:08 -07:00
|
|
|
ArrayLength(sStringInfo));
|
2010-04-28 16:00:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIMutationObserver methods
|
|
|
|
|
|
|
|
void
|
2013-01-04 17:50:22 -08:00
|
|
|
SVGMPathElement::AttributeChanged(nsIDocument* aDocument,
|
|
|
|
Element* aElement,
|
|
|
|
int32_t aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
int32_t aModType)
|
2010-04-28 16:00:54 -07:00
|
|
|
{
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::d) {
|
|
|
|
NotifyParentOfMpathChange(GetParent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Public helper methods
|
|
|
|
|
2013-01-12 14:22:31 -08:00
|
|
|
SVGPathElement*
|
2013-01-04 17:50:22 -08:00
|
|
|
SVGMPathElement::GetReferencedPath()
|
2010-04-28 16:00:54 -07:00
|
|
|
{
|
|
|
|
if (!HasAttr(kNameSpaceID_XLink, nsGkAtoms::href)) {
|
2015-02-09 14:34:50 -08:00
|
|
|
MOZ_ASSERT(!mHrefTarget.get(),
|
|
|
|
"We shouldn't have an xlink:href target "
|
|
|
|
"if we don't have an xlink:href attribute");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-04-28 16:00:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* genericTarget = mHrefTarget.get();
|
2015-03-03 03:08:59 -08:00
|
|
|
if (genericTarget && genericTarget->IsSVGElement(nsGkAtoms::path)) {
|
2013-01-12 14:22:31 -08:00
|
|
|
return static_cast<SVGPathElement*>(genericTarget);
|
2010-04-28 16:00:54 -07:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-04-28 16:00:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Protected helper methods
|
|
|
|
|
|
|
|
void
|
2013-01-04 17:50:22 -08:00
|
|
|
SVGMPathElement::UpdateHrefTarget(nsIContent* aParent,
|
|
|
|
const nsAString& aHrefStr)
|
2010-04-28 16:00:54 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> targetURI;
|
|
|
|
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
|
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI),
|
2011-10-18 03:53:36 -07:00
|
|
|
aHrefStr, OwnerDoc(), baseURI);
|
2010-04-28 16:00:54 -07:00
|
|
|
|
|
|
|
// Stop observing old target (if any)
|
|
|
|
if (mHrefTarget.get()) {
|
|
|
|
mHrefTarget.get()->RemoveMutationObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aParent) {
|
|
|
|
// Pass in |aParent| instead of |this| -- first argument is only used
|
2014-10-03 05:32:26 -07:00
|
|
|
// for a call to GetComposedDoc(), and |this| might not have a current
|
2010-04-28 16:00:54 -07:00
|
|
|
// document yet (if our caller is BindToTree).
|
|
|
|
mHrefTarget.Reset(aParent, targetURI);
|
|
|
|
} 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.
|
|
|
|
mHrefTarget.Unlink();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start observing new target (if any)
|
|
|
|
if (mHrefTarget.get()) {
|
|
|
|
mHrefTarget.get()->AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
NotifyParentOfMpathChange(aParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-04 17:50:22 -08:00
|
|
|
SVGMPathElement::UnlinkHrefTarget(bool aNotifyParent)
|
2010-04-28 16:00:54 -07:00
|
|
|
{
|
|
|
|
// Stop observing old target (if any)
|
|
|
|
if (mHrefTarget.get()) {
|
|
|
|
mHrefTarget.get()->RemoveMutationObserver(this);
|
|
|
|
}
|
|
|
|
mHrefTarget.Unlink();
|
|
|
|
|
|
|
|
if (aNotifyParent) {
|
|
|
|
NotifyParentOfMpathChange(GetParent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-04 17:50:22 -08:00
|
|
|
SVGMPathElement::NotifyParentOfMpathChange(nsIContent* aParent)
|
2010-04-28 16:00:54 -07:00
|
|
|
{
|
2015-03-03 03:08:59 -08:00
|
|
|
if (aParent && aParent->IsSVGElement(nsGkAtoms::animateMotion)) {
|
2010-04-28 16:00:54 -07:00
|
|
|
|
2013-01-06 01:32:02 -08:00
|
|
|
SVGAnimateMotionElement* animateMotionParent =
|
|
|
|
static_cast<SVGAnimateMotionElement*>(aParent);
|
2010-04-28 16:00:54 -07:00
|
|
|
|
|
|
|
animateMotionParent->MpathChanged();
|
|
|
|
AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
}
|
2013-01-04 17:50:22 -08:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|