2015-05-03 12:32:37 -07: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-02-03 09:42:39 -08: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/. */
|
|
|
|
#include "mozilla/dom/HTMLStyleElement.h"
|
2013-02-03 09:42:40 -08:00
|
|
|
#include "mozilla/dom/HTMLStyleElementBinding.h"
|
2013-02-03 09:42:39 -08:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIDOMStyleSheet.h"
|
|
|
|
#include "nsIStyleSheet.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsStubMutationObserver.h"
|
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Style)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
HTMLStyleElement::HTMLStyleElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-02-03 09:42:39 -08:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
|
|
|
{
|
|
|
|
AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLStyleElement::~HTMLStyleElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLStyleElement)
|
|
|
|
|
2013-02-03 09:42:39 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLStyleElement,
|
|
|
|
nsGenericHTMLElement)
|
|
|
|
tmp->nsStyleLinkElement::Traverse(cb);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2013-08-01 18:29:05 -07:00
|
|
|
|
2013-02-03 09:42:39 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLStyleElement,
|
|
|
|
nsGenericHTMLElement)
|
|
|
|
tmp->nsStyleLinkElement::Unlink();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLStyleElement, Element)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HTMLStyleElement, Element)
|
|
|
|
|
|
|
|
|
|
|
|
// QueryInterface implementation for HTMLStyleElement
|
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLStyleElement)
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(HTMLStyleElement,
|
|
|
|
nsIDOMHTMLStyleElement,
|
|
|
|
nsIStyleSheetLinkingElement,
|
|
|
|
nsIMutationObserver)
|
2013-08-07 13:23:08 -07:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(nsGenericHTMLElement)
|
2013-02-03 09:42:39 -08:00
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLStyleElement)
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-03-17 07:42:59 -07:00
|
|
|
HTMLStyleElement::GetMozDisabled(bool* aDisabled)
|
2013-02-03 09:42:39 -08:00
|
|
|
{
|
2013-02-03 09:42:40 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aDisabled);
|
|
|
|
|
|
|
|
*aDisabled = Disabled();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HTMLStyleElement::Disabled()
|
|
|
|
{
|
2014-06-20 03:32:49 -07:00
|
|
|
CSSStyleSheet* ss = GetSheet();
|
2013-03-17 07:42:59 -07:00
|
|
|
return ss && ss->Disabled();
|
2013-02-03 09:42:39 -08:00
|
|
|
}
|
|
|
|
|
2013-02-03 09:42:40 -08:00
|
|
|
NS_IMETHODIMP
|
2013-03-17 07:42:59 -07:00
|
|
|
HTMLStyleElement::SetMozDisabled(bool aDisabled)
|
2013-02-03 09:42:39 -08:00
|
|
|
{
|
2013-03-17 07:42:59 -07:00
|
|
|
SetDisabled(aDisabled);
|
|
|
|
return NS_OK;
|
2013-02-03 09:42:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-03-17 07:42:59 -07:00
|
|
|
HTMLStyleElement::SetDisabled(bool aDisabled)
|
2013-02-03 09:42:40 -08:00
|
|
|
{
|
2014-06-20 03:32:49 -07:00
|
|
|
CSSStyleSheet* ss = GetSheet();
|
2013-03-17 07:42:59 -07:00
|
|
|
if (ss) {
|
|
|
|
ss->SetDisabled(aDisabled);
|
2013-02-03 09:42:40 -08:00
|
|
|
}
|
2013-02-03 09:42:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLStyleElement, Media, media)
|
|
|
|
NS_IMPL_BOOL_ATTR(HTMLStyleElement, Scoped, scoped)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLStyleElement, Type, type)
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLStyleElement::CharacterDataChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo)
|
|
|
|
{
|
|
|
|
ContentChanged(aContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLStyleElement::ContentAppended(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aFirstNewContent,
|
|
|
|
int32_t aNewIndexInContainer)
|
|
|
|
{
|
|
|
|
ContentChanged(aContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLStyleElement::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexInContainer)
|
|
|
|
{
|
|
|
|
ContentChanged(aChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLStyleElement::ContentRemoved(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexInContainer,
|
|
|
|
nsIContent* aPreviousSibling)
|
|
|
|
{
|
|
|
|
ContentChanged(aChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLStyleElement::ContentChanged(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (nsContentUtils::IsInSameAnonymousTree(this, aContent)) {
|
2013-12-02 02:26:12 -08:00
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr);
|
2013-02-03 09:42:39 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLStyleElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
void (HTMLStyleElement::*update)() = &HTMLStyleElement::UpdateStyleSheetInternal;
|
|
|
|
nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, update));
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLStyleElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
|
|
|
{
|
2014-09-26 15:07:40 -07:00
|
|
|
nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc();
|
2013-12-02 02:26:12 -08:00
|
|
|
ShadowRoot* oldShadow = GetContainingShadow();
|
2014-09-26 15:07:40 -07:00
|
|
|
|
2013-02-03 09:42:39 -08:00
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
2014-09-26 15:07:40 -07:00
|
|
|
|
2015-02-09 10:01:23 -08:00
|
|
|
if (oldShadow && GetContainingShadow()) {
|
|
|
|
// The style is in a shadow tree and is still in the
|
|
|
|
// shadow tree. Thus the sheets in the shadow DOM
|
|
|
|
// do not need to be updated.
|
2014-09-26 15:07:40 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-02 02:26:12 -08:00
|
|
|
UpdateStyleSheetInternal(oldDoc, oldShadow);
|
2013-02-03 09:42:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2015-09-22 18:19:49 -07:00
|
|
|
HTMLStyleElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue, bool aNotify)
|
2013-02-03 09:42:39 -08:00
|
|
|
{
|
2015-09-22 18:19:49 -07:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
2013-02-03 09:42:39 -08:00
|
|
|
if (aName == nsGkAtoms::title ||
|
|
|
|
aName == nsGkAtoms::media ||
|
|
|
|
aName == nsGkAtoms::type) {
|
2013-12-02 02:26:12 -08:00
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr, true);
|
2013-02-03 09:42:39 -08:00
|
|
|
} else if (aName == nsGkAtoms::scoped) {
|
2015-09-22 18:19:49 -07:00
|
|
|
bool isScoped = aValue;
|
|
|
|
UpdateStyleSheetScopedness(isScoped);
|
2013-02-03 09:42:39 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-22 18:19:49 -07:00
|
|
|
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
|
|
|
|
aNotify);
|
2013-02-03 09:42:39 -08:00
|
|
|
}
|
|
|
|
|
2013-10-08 12:25:01 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleElement::GetInnerHTML(nsAString& aInnerHTML)
|
2013-02-03 09:42:39 -08:00
|
|
|
{
|
2015-05-22 11:16:20 -07:00
|
|
|
if (!nsContentUtils::GetNodeTextContent(this, false, aInnerHTML, fallible)) {
|
2014-03-19 10:05:03 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2013-10-08 12:25:01 -07:00
|
|
|
return NS_OK;
|
2013-02-03 09:42:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLStyleElement::SetInnerHTML(const nsAString& aInnerHTML,
|
|
|
|
ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetEnableUpdates(false);
|
|
|
|
|
|
|
|
aError = nsContentUtils::SetNodeTextContent(this, aInnerHTML, true);
|
|
|
|
|
|
|
|
SetEnableUpdates(true);
|
|
|
|
|
2013-12-02 02:26:12 -08:00
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr);
|
2013-02-03 09:42:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
HTMLStyleElement::GetStyleSheetURL(bool* aIsInline)
|
|
|
|
{
|
|
|
|
*aIsInline = true;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLStyleElement::GetStyleSheetInfo(nsAString& aTitle,
|
|
|
|
nsAString& aType,
|
|
|
|
nsAString& aMedia,
|
|
|
|
bool* aIsScoped,
|
|
|
|
bool* aIsAlternate)
|
|
|
|
{
|
|
|
|
aTitle.Truncate();
|
|
|
|
aType.Truncate();
|
|
|
|
aMedia.Truncate();
|
|
|
|
*aIsAlternate = false;
|
|
|
|
|
|
|
|
nsAutoString title;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::title, title);
|
|
|
|
title.CompressWhitespace();
|
|
|
|
aTitle.Assign(title);
|
|
|
|
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia);
|
|
|
|
// The HTML5 spec is formulated in terms of the CSSOM spec, which specifies
|
|
|
|
// that media queries should be ASCII lowercased during serialization.
|
|
|
|
nsContentUtils::ASCIIToLower(aMedia);
|
|
|
|
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::type, aType);
|
|
|
|
|
|
|
|
*aIsScoped = HasAttr(kNameSpaceID_None, nsGkAtoms::scoped);
|
|
|
|
|
|
|
|
nsAutoString mimeType;
|
|
|
|
nsAutoString notUsed;
|
|
|
|
nsContentUtils::SplitMimeType(aType, mimeType, notUsed);
|
|
|
|
if (!mimeType.IsEmpty() && !mimeType.LowerCaseEqualsLiteral("text/css")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get here we assume that we're loading a css file, so set the
|
|
|
|
// type to 'text/css'
|
|
|
|
aType.AssignLiteral("text/css");
|
|
|
|
}
|
|
|
|
|
2013-02-03 09:42:40 -08:00
|
|
|
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
|
|
|
HTMLStyleElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-03 09:42:40 -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 HTMLStyleElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-03 09:42:40 -08:00
|
|
|
}
|
|
|
|
|
2013-02-03 09:42:39 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|