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: */
|
2013-01-05 05:50:21 +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/. */
|
|
|
|
|
2013-01-09 03:25:47 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-01-05 05:50:21 +04:00
|
|
|
#include "mozilla/dom/SVGStyleElement.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "mozilla/dom/SVGStyleElementBinding.h"
|
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Style)
|
|
|
|
|
|
|
|
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
|
|
|
SVGStyleElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-01-05 05:50:21 +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 SVGStyleElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-01-05 05:50:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(SVGStyleElement, SVGStyleElementBase)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(SVGStyleElement, SVGStyleElementBase)
|
|
|
|
|
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(SVGStyleElement)
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(SVGStyleElement,
|
|
|
|
nsIStyleSheetLinkingElement,
|
|
|
|
nsIMutationObserver)
|
2013-05-21 23:59:27 +04:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(SVGStyleElementBase)
|
2013-01-05 05:50:21 +04:00
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(SVGStyleElement)
|
|
|
|
|
2013-01-05 05:50:21 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SVGStyleElement,
|
|
|
|
SVGStyleElementBase)
|
|
|
|
tmp->nsStyleLinkElement::Traverse(cb);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2013-01-05 05:50:21 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SVGStyleElement,
|
|
|
|
SVGStyleElementBase)
|
|
|
|
tmp->nsStyleLinkElement::Unlink();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
SVGStyleElement::SVGStyleElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-01-05 05:50:21 +04:00
|
|
|
: SVGStyleElementBase(aNodeInfo)
|
|
|
|
{
|
|
|
|
AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
|
2014-07-09 01:23:16 +04:00
|
|
|
SVGStyleElement::~SVGStyleElement()
|
|
|
|
{
|
|
|
|
}
|
2013-01-05 05:50:21 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMNode methods
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGStyleElement)
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SVGStyleElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
|
|
|
{
|
|
|
|
nsresult rv = SVGStyleElementBase::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
void (SVGStyleElement::*update)() = &SVGStyleElement::UpdateStyleSheetInternal;
|
2017-06-12 22:34:10 +03:00
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
NewRunnableMethod("dom::SVGStyleElement::BindToTree", this, update));
|
2013-01-05 05:50:21 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGStyleElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
|
|
|
{
|
2014-10-03 16:32:26 +04:00
|
|
|
nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc();
|
2014-06-12 05:15:22 +04:00
|
|
|
ShadowRoot* oldShadow = GetContainingShadow();
|
2013-01-05 05:50:21 +04:00
|
|
|
SVGStyleElementBase::UnbindFromTree(aDeep, aNullParent);
|
2013-12-02 14:26:12 +04:00
|
|
|
UpdateStyleSheetInternal(oldDoc, oldShadow);
|
2013-01-05 05:50:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SVGStyleElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
|
|
|
bool aNotify)
|
|
|
|
{
|
|
|
|
nsresult rv = SVGStyleElementBase::SetAttr(aNameSpaceID, aName, aPrefix,
|
|
|
|
aValue, aNotify);
|
2013-01-09 03:25:48 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aName == nsGkAtoms::title ||
|
|
|
|
aName == nsGkAtoms::media ||
|
|
|
|
aName == nsGkAtoms::type) {
|
2013-12-02 14:26:12 +04:00
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr, true);
|
2013-01-09 03:25:48 +04:00
|
|
|
} else if (aName == nsGkAtoms::scoped) {
|
|
|
|
UpdateStyleSheetScopedness(true);
|
|
|
|
}
|
2013-01-05 05:50:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SVGStyleElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
|
|
|
|
bool aNotify)
|
|
|
|
{
|
|
|
|
nsresult rv = SVGStyleElementBase::UnsetAttr(aNameSpaceID, aAttribute,
|
|
|
|
aNotify);
|
2013-01-09 03:25:48 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::title ||
|
|
|
|
aAttribute == nsGkAtoms::media ||
|
|
|
|
aAttribute == nsGkAtoms::type) {
|
2013-12-02 14:26:12 +04:00
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr, true);
|
2013-01-09 03:25:48 +04:00
|
|
|
} else if (aAttribute == nsGkAtoms::scoped) {
|
|
|
|
UpdateStyleSheetScopedness(false);
|
|
|
|
}
|
2013-01-05 05:50:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SVGStyleElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
|
|
|
{
|
|
|
|
if (aNamespaceID == kNameSpaceID_None &&
|
|
|
|
aAttribute == nsGkAtoms::crossorigin) {
|
|
|
|
ParseCORSValue(aValue, aResult);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SVGStyleElementBase::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
|
|
|
aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIMutationObserver methods
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGStyleElement::CharacterDataChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo)
|
|
|
|
{
|
|
|
|
ContentChanged(aContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGStyleElement::ContentAppended(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aFirstNewContent,
|
|
|
|
int32_t aNewIndexInContainer)
|
|
|
|
{
|
|
|
|
ContentChanged(aContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGStyleElement::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexInContainer)
|
|
|
|
{
|
|
|
|
ContentChanged(aChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGStyleElement::ContentRemoved(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexInContainer,
|
|
|
|
nsIContent* aPreviousSibling)
|
|
|
|
{
|
|
|
|
ContentChanged(aChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGStyleElement::ContentChanged(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (nsContentUtils::IsInSameAnonymousTree(this, aContent)) {
|
2013-12-02 14:26:12 +04:00
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr);
|
2013-01-05 05:50:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2013-02-03 00:23:19 +04:00
|
|
|
void
|
|
|
|
SVGStyleElement::GetXmlspace(nsAString & aXmlspace)
|
2013-01-05 05:50:21 +04:00
|
|
|
{
|
|
|
|
GetAttr(kNameSpaceID_XML, nsGkAtoms::space, aXmlspace);
|
|
|
|
}
|
2013-02-03 00:23:19 +04:00
|
|
|
|
2013-01-05 05:50:21 +04:00
|
|
|
void
|
|
|
|
SVGStyleElement::SetXmlspace(const nsAString & aXmlspace, ErrorResult& rv)
|
|
|
|
{
|
|
|
|
rv = SetAttr(kNameSpaceID_XML, nsGkAtoms::space, aXmlspace, true);
|
|
|
|
}
|
|
|
|
|
2013-02-03 00:23:19 +04:00
|
|
|
void
|
|
|
|
SVGStyleElement::GetMedia(nsAString & aMedia)
|
|
|
|
{
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia);
|
|
|
|
}
|
|
|
|
|
2013-01-08 12:36:21 +04:00
|
|
|
void
|
2013-01-09 03:25:48 +04:00
|
|
|
SVGStyleElement::SetMedia(const nsAString& aMedia, ErrorResult& rv)
|
2013-01-08 12:36:21 +04:00
|
|
|
{
|
2013-01-09 03:25:48 +04:00
|
|
|
rv = SetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia, true);
|
2013-01-08 12:36:21 +04:00
|
|
|
}
|
|
|
|
|
2013-01-09 03:25:48 +04:00
|
|
|
bool
|
|
|
|
SVGStyleElement::Scoped() const
|
2013-01-08 12:36:21 +04:00
|
|
|
{
|
2013-01-09 03:25:48 +04:00
|
|
|
return GetBoolAttr(nsGkAtoms::scoped);
|
2013-01-08 12:36:21 +04:00
|
|
|
}
|
2013-02-03 00:23:19 +04:00
|
|
|
|
2013-01-09 03:25:48 +04:00
|
|
|
void
|
|
|
|
SVGStyleElement::SetScoped(bool aScoped, ErrorResult& rv)
|
2013-01-08 12:36:21 +04:00
|
|
|
{
|
2013-01-09 03:25:48 +04:00
|
|
|
rv = SetBoolAttr(nsGkAtoms::scoped, aScoped);
|
2013-01-08 12:36:21 +04:00
|
|
|
}
|
2013-01-09 03:25:48 +04:00
|
|
|
|
2013-02-03 00:23:19 +04:00
|
|
|
void
|
|
|
|
SVGStyleElement::GetType(nsAString & aType)
|
|
|
|
{
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::type, aType);
|
|
|
|
}
|
|
|
|
|
2013-01-08 12:36:21 +04:00
|
|
|
void
|
2013-01-09 03:25:48 +04:00
|
|
|
SVGStyleElement::SetType(const nsAString& aType, ErrorResult& rv)
|
2013-01-08 12:36:21 +04:00
|
|
|
{
|
2013-01-09 03:25:48 +04:00
|
|
|
rv = SetAttr(kNameSpaceID_None, nsGkAtoms::type, aType, true);
|
2013-01-08 12:36:21 +04:00
|
|
|
}
|
|
|
|
|
2013-02-03 00:23:19 +04:00
|
|
|
void
|
|
|
|
SVGStyleElement::GetTitle(nsAString & aTitle)
|
|
|
|
{
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::title, aTitle);
|
|
|
|
}
|
|
|
|
|
2013-01-08 12:36:21 +04:00
|
|
|
void
|
2013-01-09 03:25:48 +04:00
|
|
|
SVGStyleElement::SetTitle(const nsAString& aTitle, ErrorResult& rv)
|
2013-01-08 12:36:21 +04:00
|
|
|
{
|
|
|
|
rv = SetAttr(kNameSpaceID_None, nsGkAtoms::title, aTitle, true);
|
|
|
|
}
|
2013-01-05 05:50:21 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsStyleLinkElement methods
|
|
|
|
|
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
SVGStyleElement::GetStyleSheetURL(bool* aIsInline)
|
|
|
|
{
|
|
|
|
*aIsInline = true;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGStyleElement::GetStyleSheetInfo(nsAString& aTitle,
|
|
|
|
nsAString& aType,
|
|
|
|
nsAString& aMedia,
|
2013-01-09 03:25:47 +04:00
|
|
|
bool* aIsScoped,
|
2013-01-05 05:50:21 +04:00
|
|
|
bool* aIsAlternate)
|
|
|
|
{
|
|
|
|
*aIsAlternate = false;
|
|
|
|
|
|
|
|
nsAutoString title;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::title, title);
|
|
|
|
title.CompressWhitespace();
|
|
|
|
aTitle.Assign(title);
|
|
|
|
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia);
|
|
|
|
// The SVG spec is formulated in terms of the CSS2 spec,
|
|
|
|
// which specifies that media queries are case insensitive.
|
|
|
|
nsContentUtils::ASCIIToLower(aMedia);
|
|
|
|
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::type, aType);
|
|
|
|
if (aType.IsEmpty()) {
|
|
|
|
aType.AssignLiteral("text/css");
|
|
|
|
}
|
|
|
|
|
2013-01-09 03:25:48 +04:00
|
|
|
*aIsScoped = HasAttr(kNameSpaceID_None, nsGkAtoms::scoped);
|
|
|
|
|
2013-01-05 05:50:21 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CORSMode
|
|
|
|
SVGStyleElement::GetCORSMode() const
|
|
|
|
{
|
|
|
|
return AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|