2013-02-03 09:42:39 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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 "nsNetUtil.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();
|
|
|
|
nsCOMPtr<nsIDocument> oldComposedDoc = GetComposedDoc();
|
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
|
|
|
|
|
|
|
if (GetContainingShadow() && !oldComposedDoc) {
|
|
|
|
// The style is in a shadow tree and was already not
|
|
|
|
// in the composed document. Thus the sheet does not
|
|
|
|
// need to be updated.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-02 02:26:12 -08:00
|
|
|
UpdateStyleSheetInternal(oldDoc, oldShadow);
|
2013-02-03 09:42:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLStyleElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
|
|
|
bool aNotify)
|
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix,
|
|
|
|
aValue, aNotify);
|
|
|
|
if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
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) {
|
|
|
|
UpdateStyleSheetScopedness(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HTMLStyleElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
|
|
|
|
bool aNotify)
|
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aAttribute,
|
|
|
|
aNotify);
|
|
|
|
if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::title ||
|
|
|
|
aAttribute == nsGkAtoms::media ||
|
|
|
|
aAttribute == nsGkAtoms::type) {
|
2013-12-02 02:26:12 -08:00
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr, true);
|
2013-02-03 09:42:39 -08:00
|
|
|
} else if (aAttribute == nsGkAtoms::scoped) {
|
|
|
|
UpdateStyleSheetScopedness(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-10-08 12:25:01 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleElement::GetInnerHTML(nsAString& aInnerHTML)
|
2013-02-03 09:42:39 -08:00
|
|
|
{
|
2014-03-19 10:05:03 -07:00
|
|
|
if (!nsContentUtils::GetNodeTextContent(this, false, aInnerHTML)) {
|
|
|
|
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*
|
2014-04-08 15:27:17 -07:00
|
|
|
HTMLStyleElement::WrapNode(JSContext *aCx)
|
2013-02-03 09:42:40 -08:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return HTMLStyleElementBinding::Wrap(aCx, this);
|
2013-02-03 09:42:40 -08:00
|
|
|
}
|
|
|
|
|
2013-02-03 09:42:39 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|