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-02-03 21:42:39 +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/. */
|
|
|
|
#include "mozilla/dom/HTMLStyleElement.h"
|
2013-02-03 21:42:40 +04:00
|
|
|
#include "mozilla/dom/HTMLStyleElementBinding.h"
|
2013-02-03 21:42:39 +04:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIDOMStyleSheet.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-20 06:01:40 +04:00
|
|
|
HTMLStyleElement::HTMLStyleElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-02-03 21:42:39 +04:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
|
|
|
{
|
|
|
|
AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLStyleElement::~HTMLStyleElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLStyleElement)
|
|
|
|
|
2013-02-03 21:42:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLStyleElement,
|
|
|
|
nsGenericHTMLElement)
|
|
|
|
tmp->nsStyleLinkElement::Traverse(cb);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2013-02-03 21:42:39 +04: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 11:06:00 +04:00
|
|
|
NS_INTERFACE_TABLE_INHERITED(HTMLStyleElement,
|
|
|
|
nsIDOMHTMLStyleElement,
|
|
|
|
nsIStyleSheetLinkingElement,
|
|
|
|
nsIMutationObserver)
|
2013-08-08 00:23:08 +04:00
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(nsGenericHTMLElement)
|
2013-02-03 21:42:39 +04:00
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLStyleElement)
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-03-17 18:42:59 +04:00
|
|
|
HTMLStyleElement::GetMozDisabled(bool* aDisabled)
|
2013-02-03 21:42:39 +04:00
|
|
|
{
|
2013-02-03 21:42:40 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aDisabled);
|
|
|
|
|
|
|
|
*aDisabled = Disabled();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HTMLStyleElement::Disabled()
|
|
|
|
{
|
2016-10-14 14:25:38 +03:00
|
|
|
StyleSheet* ss = GetSheet();
|
2013-03-17 18:42:59 +04:00
|
|
|
return ss && ss->Disabled();
|
2013-02-03 21:42:39 +04:00
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:40 +04:00
|
|
|
NS_IMETHODIMP
|
2013-03-17 18:42:59 +04:00
|
|
|
HTMLStyleElement::SetMozDisabled(bool aDisabled)
|
2013-02-03 21:42:39 +04:00
|
|
|
{
|
2013-03-17 18:42:59 +04:00
|
|
|
SetDisabled(aDisabled);
|
|
|
|
return NS_OK;
|
2013-02-03 21:42:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-03-17 18:42:59 +04:00
|
|
|
HTMLStyleElement::SetDisabled(bool aDisabled)
|
2013-02-03 21:42:40 +04:00
|
|
|
{
|
2016-10-14 14:25:38 +03:00
|
|
|
if (StyleSheet* ss = GetSheet()) {
|
2013-03-17 18:42:59 +04:00
|
|
|
ss->SetDisabled(aDisabled);
|
2013-02-03 21:42:40 +04:00
|
|
|
}
|
2013-02-03 21:42:39 +04: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 14:26:12 +04:00
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr);
|
2013-02-03 21:42:39 +04: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;
|
2017-06-12 22:34:10 +03:00
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
NewRunnableMethod("dom::HTMLStyleElement::BindToTree", this, update));
|
2013-02-03 21:42:39 +04:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
return rv;
|
2013-02-03 21:42:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLStyleElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
|
|
|
{
|
2014-09-27 02:07:40 +04:00
|
|
|
nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc();
|
2013-12-02 14:26:12 +04:00
|
|
|
ShadowRoot* oldShadow = GetContainingShadow();
|
2014-09-27 02:07:40 +04:00
|
|
|
|
2013-02-03 21:42:39 +04:00
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
2014-09-27 02:07:40 +04:00
|
|
|
|
2015-02-09 21:01:23 +03: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-27 02:07:40 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
UpdateStyleSheetInternal(oldDoc, oldShadow);
|
2013-02-03 21:42:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2015-09-23 04:19:49 +03:00
|
|
|
HTMLStyleElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2017-05-19 00:09:01 +03:00
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue, bool aNotify)
|
2013-02-03 21:42:39 +04:00
|
|
|
{
|
2015-09-23 04:19:49 +03:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
2013-02-03 21:42:39 +04:00
|
|
|
if (aName == nsGkAtoms::title ||
|
|
|
|
aName == nsGkAtoms::media ||
|
|
|
|
aName == nsGkAtoms::type) {
|
2013-12-02 14:26:12 +04:00
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr, true);
|
2017-06-21 04:25:43 +03:00
|
|
|
} else if (aName == nsGkAtoms::scoped &&
|
|
|
|
OwnerDoc()->IsScopedStyleEnabled()) {
|
2015-09-23 04:19:49 +03:00
|
|
|
bool isScoped = aValue;
|
|
|
|
UpdateStyleSheetScopedness(isScoped);
|
2013-02-03 21:42:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-23 04:19:49 +03:00
|
|
|
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
|
2017-05-19 00:09:01 +03:00
|
|
|
aOldValue, aNotify);
|
2013-02-03 21:42:39 +04:00
|
|
|
}
|
|
|
|
|
2013-10-08 23:25:01 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleElement::GetInnerHTML(nsAString& aInnerHTML)
|
2013-02-03 21:42:39 +04:00
|
|
|
{
|
2015-05-22 21:16:20 +03:00
|
|
|
if (!nsContentUtils::GetNodeTextContent(this, false, aInnerHTML, fallible)) {
|
2014-03-19 21:05:03 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2013-10-08 23:25:01 +04:00
|
|
|
return NS_OK;
|
2013-02-03 21:42:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HTMLStyleElement::SetInnerHTML(const nsAString& aInnerHTML,
|
|
|
|
ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SetEnableUpdates(false);
|
|
|
|
|
|
|
|
aError = nsContentUtils::SetNodeTextContent(this, aInnerHTML, true);
|
|
|
|
|
|
|
|
SetEnableUpdates(true);
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr);
|
2013-02-03 21:42:39 +04: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);
|
|
|
|
|
2017-06-21 04:25:43 +03:00
|
|
|
*aIsScoped = HasAttr(kNameSpaceID_None, nsGkAtoms::scoped) &&
|
|
|
|
OwnerDoc()->IsScopedStyleEnabled();
|
2013-02-03 21:42:39 +04:00
|
|
|
|
|
|
|
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 21:42:40 +04: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 17:13:33 +03:00
|
|
|
HTMLStyleElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-03 21:42:40 +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 HTMLStyleElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-03 21:42:40 +04:00
|
|
|
}
|
|
|
|
|
2013-02-03 21:42:39 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|