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 {
|
|
|
|
|
|
|
|
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 17:13:33 +03:00
|
|
|
SVGMPathElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-01-05 05:50:22 +04: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 17:13:33 +03:00
|
|
|
return SVGMPathElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-01-05 05:50:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::StringInfo SVGMPathElement::sStringInfo[1] =
|
2010-04-29 03:00:54 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
{ &nsGkAtoms::href, kNameSpaceID_XLink, false }
|
2010-04-29 03:00:54 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Cycle collection magic -- based on nsSVGUseElement
|
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)
|
2010-04-29 03:00:54 +04:00
|
|
|
tmp->mHrefTarget.Traverse(&cb);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(SVGMPathElement,SVGMPathElementBase)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(SVGMPathElement,SVGMPathElementBase)
|
2010-04-29 03:00:54 +04:00
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(SVGMPathElement)
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(SVGMPathElement, nsIDOMNode, nsIDOMElement,
|
|
|
|
nsIDOMSVGElement,
|
|
|
|
nsIMutationObserver)
|
2013-05-21 23:59:27 +04:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(SVGMPathElementBase)
|
2010-04-29 03:00:54 +04:00
|
|
|
|
|
|
|
// Constructor
|
2014-06-20 06:01:40 +04:00
|
|
|
SVGMPathElement::SVGMPathElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-01-05 05:50:22 +04:00
|
|
|
: SVGMPathElementBase(aNodeInfo),
|
2015-01-07 08:39:46 +03:00
|
|
|
mHrefTarget(this)
|
2010-04-29 03:00:54 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-05 05:50:22 +04:00
|
|
|
SVGMPathElement::~SVGMPathElement()
|
2010-04-29 03:00:54 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
UnlinkHrefTarget(false);
|
2010-04-29 03:00:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMNode methods
|
|
|
|
|
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>
|
2013-01-05 05:50:22 +04:00
|
|
|
SVGMPathElement::Href()
|
|
|
|
{
|
2013-02-07 12:08:56 +04:00
|
|
|
return mStringAttributes[HREF].ToDOMAnimatedString(this);
|
2013-01-05 05:50:22 +04:00
|
|
|
}
|
|
|
|
|
2010-04-29 03:00:54 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
|
|
|
nsresult
|
2013-01-05 05:50:22 +04:00
|
|
|
SVGMPathElement::BindToTree(nsIDocument* aDocument,
|
|
|
|
nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2010-04-29 03:00:54 +04:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mHrefTarget.get(),
|
|
|
|
"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,
|
|
|
|
aCompileEventHandlers);
|
2010-04-29 03:00:54 +04: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-05 05:50:22 +04:00
|
|
|
SVGMPathElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2010-04-29 03:00:54 +04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-01-05 05:50:22 +04:00
|
|
|
SVGMPathElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
2010-04-29 03:00:54 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool returnVal =
|
2013-01-05 05:50:22 +04:00
|
|
|
SVGMPathElementBase::ParseAttribute(aNamespaceID, aAttribute,
|
2010-04-29 03:00:54 +04: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-05 05:50:22 +04:00
|
|
|
SVGMPathElement::UnsetAttr(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute, bool aNotify)
|
2010-04-29 03:00:54 +04:00
|
|
|
{
|
2013-01-05 05:50:22 +04:00
|
|
|
nsresult rv = SVGMPathElementBase::UnsetAttr(aNamespaceID, aAttribute,
|
|
|
|
aNotify);
|
2010-04-29 03:00:54 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (aNamespaceID == kNameSpaceID_XLink &&
|
|
|
|
aAttribute == nsGkAtoms::href) {
|
2011-10-17 18:59:28 +04:00
|
|
|
UnlinkHrefTarget(true);
|
2010-04-29 03:00:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGElement methods
|
|
|
|
|
|
|
|
nsSVGElement::StringAttributesInfo
|
2013-01-05 05:50:22 +04:00
|
|
|
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
|
|
|
|
|
|
|
|
void
|
2013-01-05 05:50:22 +04:00
|
|
|
SVGMPathElement::AttributeChanged(nsIDocument* aDocument,
|
|
|
|
Element* aElement,
|
|
|
|
int32_t aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
2015-07-25 09:01:19 +03:00
|
|
|
int32_t aModType,
|
|
|
|
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-13 02:22:31 +04:00
|
|
|
SVGPathElement*
|
2013-01-05 05:50:22 +04:00
|
|
|
SVGMPathElement::GetReferencedPath()
|
2010-04-29 03:00:54 +04:00
|
|
|
{
|
|
|
|
if (!HasAttr(kNameSpaceID_XLink, nsGkAtoms::href)) {
|
2015-02-10 01:34:50 +03: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 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-04-29 03:00:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* genericTarget = mHrefTarget.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
|
|
|
|
|
|
|
|
void
|
2013-01-05 05:50:22 +04:00
|
|
|
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),
|
2011-10-18 14:53:36 +04:00
|
|
|
aHrefStr, OwnerDoc(), baseURI);
|
2010-04-29 03:00:54 +04: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 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).
|
|
|
|
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-05 05:50:22 +04:00
|
|
|
SVGMPathElement::UnlinkHrefTarget(bool aNotifyParent)
|
2010-04-29 03:00:54 +04:00
|
|
|
{
|
|
|
|
// Stop observing old target (if any)
|
|
|
|
if (mHrefTarget.get()) {
|
|
|
|
mHrefTarget.get()->RemoveMutationObserver(this);
|
|
|
|
}
|
|
|
|
mHrefTarget.Unlink();
|
|
|
|
|
|
|
|
if (aNotifyParent) {
|
|
|
|
NotifyParentOfMpathChange(GetParent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-05 05:50:22 +04:00
|
|
|
SVGMPathElement::NotifyParentOfMpathChange(nsIContent* aParent)
|
2010-04-29 03:00:54 +04:00
|
|
|
{
|
2015-03-03 14:08:59 +03:00
|
|
|
if (aParent && aParent->IsSVGElement(nsGkAtoms::animateMotion)) {
|
2010-04-29 03:00:54 +04:00
|
|
|
|
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
|
|
|
|
|