2001-11-07 07:06:31 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2001-11-07 07:06:31 +00:00
|
|
|
|
2006-03-25 05:47:31 +00:00
|
|
|
/* DOM object for element.style */
|
|
|
|
|
2001-11-07 07:06:31 +00:00
|
|
|
#include "nsDOMCSSAttrDeclaration.h"
|
2010-08-27 07:03:36 +00:00
|
|
|
|
2010-06-28 22:49:35 +00:00
|
|
|
#include "mozilla/css/Declaration.h"
|
2011-03-11 02:48:57 +00:00
|
|
|
#include "mozilla/css/StyleRule.h"
|
2016-12-01 18:40:04 +00:00
|
|
|
#include "mozilla/DeclarationBlock.h"
|
|
|
|
#include "mozilla/DeclarationBlockInlines.h"
|
2010-08-27 07:03:36 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2017-02-24 11:06:07 +00:00
|
|
|
#include "mozilla/InternalMutationEvent.h"
|
2016-12-01 18:40:04 +00:00
|
|
|
#include "mozilla/ServoDeclarationBlock.h"
|
2017-02-24 11:06:07 +00:00
|
|
|
#include "nsContentUtils.h"
|
2001-11-07 07:06:31 +00:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMMutationEvent.h"
|
2010-08-27 07:03:36 +00:00
|
|
|
#include "nsIURI.h"
|
2010-02-24 04:37:47 +00:00
|
|
|
#include "nsNodeUtils.h"
|
2012-08-06 02:55:18 +00:00
|
|
|
#include "nsWrapperCacheInlines.h"
|
2013-09-04 11:47:23 +00:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "ActiveLayerTracker.h"
|
2001-11-07 07:06:31 +00:00
|
|
|
|
2013-09-04 11:47:23 +00:00
|
|
|
using namespace mozilla;
|
2010-06-28 22:49:35 +00:00
|
|
|
|
2011-11-05 10:32:52 +00:00
|
|
|
nsDOMCSSAttributeDeclaration::nsDOMCSSAttributeDeclaration(dom::Element* aElement,
|
|
|
|
bool aIsSMILOverride)
|
2010-08-27 07:03:36 +00:00
|
|
|
: mElement(aElement)
|
2009-09-03 00:28:37 +00:00
|
|
|
, mIsSMILOverride(aIsSMILOverride)
|
2001-11-07 07:06:31 +00:00
|
|
|
{
|
2010-08-27 07:03:36 +00:00
|
|
|
NS_ASSERTION(aElement, "Inline style for a NULL element?");
|
2001-11-07 07:06:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMCSSAttributeDeclaration::~nsDOMCSSAttributeDeclaration()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-29 08:57:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsDOMCSSAttributeDeclaration, mElement)
|
2009-07-13 11:14:57 +00:00
|
|
|
|
2012-08-06 02:16:30 +00:00
|
|
|
// mElement holds a strong ref to us, so if it's going to be
|
|
|
|
// skipped, the attribute declaration can't be part of a garbage
|
|
|
|
// cycle.
|
2012-02-16 16:45:19 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsDOMCSSAttributeDeclaration)
|
2012-11-14 22:10:08 +00:00
|
|
|
if (tmp->mElement && Element::CanSkip(tmp->mElement, true)) {
|
2012-08-06 02:16:30 +00:00
|
|
|
if (tmp->PreservingWrapper()) {
|
2017-01-25 01:33:54 +00:00
|
|
|
tmp->MarkWrapperLive();
|
2012-08-06 02:16:30 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2017-01-25 01:38:58 +00:00
|
|
|
return tmp->HasKnownLiveWrapper();
|
2012-02-16 16:45:19 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(nsDOMCSSAttributeDeclaration)
|
2017-01-25 01:38:58 +00:00
|
|
|
return tmp->HasKnownLiveWrapper() ||
|
2012-11-14 22:10:08 +00:00
|
|
|
(tmp->mElement && Element::CanSkipInCC(tmp->mElement));
|
2012-02-16 16:45:19 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(nsDOMCSSAttributeDeclaration)
|
2017-01-25 01:38:58 +00:00
|
|
|
return tmp->HasKnownLiveWrapper() ||
|
2012-11-14 22:10:08 +00:00
|
|
|
(tmp->mElement && Element::CanSkipThis(tmp->mElement));
|
2012-02-16 16:45:19 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
|
|
|
|
|
2012-08-06 02:16:30 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMCSSAttributeDeclaration)
|
2009-07-13 11:14:57 +00:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_IMPL_QUERY_TAIL_INHERITING(nsDOMCSSDeclaration)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMCSSAttributeDeclaration)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMCSSAttributeDeclaration)
|
2001-11-07 07:06:31 +00:00
|
|
|
|
2003-03-06 19:07:22 +00:00
|
|
|
nsresult
|
2016-11-03 03:41:02 +00:00
|
|
|
nsDOMCSSAttributeDeclaration::SetCSSDeclaration(DeclarationBlock* aDecl)
|
2003-03-06 19:07:22 +00:00
|
|
|
{
|
2010-08-27 07:03:36 +00:00
|
|
|
NS_ASSERTION(mElement, "Must have Element to set the declaration!");
|
2016-11-03 03:41:02 +00:00
|
|
|
return mIsSMILOverride
|
2016-11-03 03:41:02 +00:00
|
|
|
? mElement->SetSMILOverrideStyleDeclaration(aDecl, true)
|
2016-11-03 03:41:02 +00:00
|
|
|
: mElement->SetInlineStyleDeclaration(aDecl, nullptr, true);
|
2003-03-06 19:07:22 +00:00
|
|
|
}
|
|
|
|
|
2009-12-11 16:13:19 +00:00
|
|
|
nsIDocument*
|
|
|
|
nsDOMCSSAttributeDeclaration::DocToUpdate()
|
|
|
|
{
|
2016-03-31 11:46:32 +00:00
|
|
|
// We need OwnerDoc() rather than GetUncomposedDoc() because it might
|
2010-08-27 07:03:36 +00:00
|
|
|
// be the BeginUpdate call that inserts mElement into the document.
|
2011-10-18 10:53:36 +00:00
|
|
|
return mElement->OwnerDoc();
|
2009-12-11 16:13:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-03 03:41:02 +00:00
|
|
|
DeclarationBlock*
|
2015-04-10 00:41:35 +00:00
|
|
|
nsDOMCSSAttributeDeclaration::GetCSSDeclaration(Operation aOperation)
|
2001-11-07 07:06:31 +00:00
|
|
|
{
|
2010-08-27 07:03:36 +00:00
|
|
|
if (!mElement)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2001-11-07 07:06:31 +00:00
|
|
|
|
2016-11-03 03:41:02 +00:00
|
|
|
DeclarationBlock* declaration;
|
2016-10-18 04:29:03 +00:00
|
|
|
if (mIsSMILOverride) {
|
2015-11-09 07:57:16 +00:00
|
|
|
declaration = mElement->GetSMILOverrideStyleDeclaration();
|
2016-10-18 04:29:03 +00:00
|
|
|
} else {
|
2016-11-03 03:41:02 +00:00
|
|
|
declaration = mElement->GetInlineStyleDeclaration();
|
2016-10-18 04:29:03 +00:00
|
|
|
}
|
2010-07-23 18:00:34 +00:00
|
|
|
|
2015-04-10 00:41:35 +00:00
|
|
|
// Notify observers that our style="" attribute is going to change
|
|
|
|
// unless:
|
|
|
|
// * this is a declaration that holds SMIL animation values (which
|
|
|
|
// aren't reflected in the DOM style="" attribute), or
|
|
|
|
// * we're getting the declaration for reading, or
|
|
|
|
// * we're getting it for property removal but we don't currently have
|
|
|
|
// a declaration.
|
|
|
|
|
|
|
|
// XXXbz this is a bit of a hack, especially doing it before the
|
|
|
|
// BeginUpdate(), but this is a good chokepoint where we know we
|
|
|
|
// plan to modify the CSSDeclaration, so need to notify
|
|
|
|
// AttributeWillChange if this is inline style.
|
|
|
|
if (!mIsSMILOverride &&
|
|
|
|
((aOperation == eOperation_Modify) ||
|
2015-11-09 07:57:16 +00:00
|
|
|
(aOperation == eOperation_RemoveProperty && declaration))) {
|
2015-04-10 00:41:35 +00:00
|
|
|
nsNodeUtils::AttributeWillChange(mElement, kNameSpaceID_None,
|
|
|
|
nsGkAtoms::style,
|
2015-07-22 03:53:35 +00:00
|
|
|
nsIDOMMutationEvent::MODIFICATION,
|
|
|
|
nullptr);
|
2015-04-10 00:41:35 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 07:57:16 +00:00
|
|
|
if (declaration) {
|
2017-02-24 11:06:07 +00:00
|
|
|
if (aOperation != eOperation_Read &&
|
|
|
|
nsContentUtils::HasMutationListeners(
|
|
|
|
mElement, NS_EVENT_BITS_MUTATION_ATTRMODIFIED, mElement)) {
|
|
|
|
// If there is any mutation listener on the element, we need to
|
|
|
|
// ensure that any change would create a new declaration so that
|
|
|
|
// nsStyledElement::SetInlineStyleDeclaration can generate the
|
|
|
|
// correct old value.
|
|
|
|
declaration->SetImmutable();
|
|
|
|
}
|
2015-11-09 07:57:16 +00:00
|
|
|
return declaration;
|
2010-07-23 18:00:34 +00:00
|
|
|
}
|
2015-04-10 00:41:35 +00:00
|
|
|
|
|
|
|
if (aOperation != eOperation_Modify) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-23 18:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cannot fail
|
2016-11-03 03:41:02 +00:00
|
|
|
RefPtr<DeclarationBlock> decl;
|
|
|
|
if (mElement->IsStyledByServo()) {
|
|
|
|
decl = new ServoDeclarationBlock();
|
|
|
|
} else {
|
|
|
|
decl = new css::Declaration();
|
|
|
|
decl->AsGecko()->InitializeEmpty();
|
|
|
|
}
|
2010-07-23 18:00:34 +00:00
|
|
|
|
|
|
|
// this *can* fail (inside SetAttrAndNotify, at least).
|
|
|
|
nsresult rv;
|
2016-11-03 03:41:02 +00:00
|
|
|
if (mIsSMILOverride) {
|
2015-11-09 07:57:16 +00:00
|
|
|
rv = mElement->SetSMILOverrideStyleDeclaration(decl, false);
|
2016-11-03 03:41:02 +00:00
|
|
|
} else {
|
2015-11-09 07:57:16 +00:00
|
|
|
rv = mElement->SetInlineStyleDeclaration(decl, nullptr, false);
|
2016-11-03 03:41:02 +00:00
|
|
|
}
|
2010-07-23 18:00:34 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr; // the decl will be destroyed along with the style rule
|
2001-11-07 07:06:31 +00:00
|
|
|
}
|
|
|
|
|
2010-07-23 18:00:34 +00:00
|
|
|
return decl;
|
2001-11-07 07:06:31 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 20:53:49 +00:00
|
|
|
void
|
|
|
|
nsDOMCSSAttributeDeclaration::GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv)
|
2001-11-07 07:06:31 +00:00
|
|
|
{
|
2010-08-27 07:03:36 +00:00
|
|
|
NS_ASSERTION(mElement, "Something is severely broken -- there should be an Element here!");
|
2003-09-27 04:18:26 +00:00
|
|
|
|
2011-10-18 10:53:36 +00:00
|
|
|
nsIDocument* doc = mElement->OwnerDoc();
|
2011-04-27 20:53:49 +00:00
|
|
|
aCSSParseEnv.mSheetURI = doc->GetDocumentURI();
|
2017-03-10 07:04:34 +00:00
|
|
|
aCSSParseEnv.mBaseURI = mElement->GetBaseURIForStyleAttr();
|
2011-04-27 20:53:49 +00:00
|
|
|
aCSSParseEnv.mPrincipal = mElement->NodePrincipal();
|
|
|
|
aCSSParseEnv.mCSSLoader = doc->CSSLoader();
|
2001-11-07 07:06:31 +00:00
|
|
|
}
|
|
|
|
|
2017-05-11 16:06:43 +00:00
|
|
|
nsDOMCSSDeclaration::ServoCSSParsingEnvironment
|
|
|
|
nsDOMCSSAttributeDeclaration::GetServoCSSParsingEnvironment() const
|
2017-04-04 06:09:20 +00:00
|
|
|
{
|
2017-05-21 13:06:27 +00:00
|
|
|
return {
|
|
|
|
mElement->GetURLDataForStyleAttr(),
|
|
|
|
mElement->OwnerDoc()->GetCompatibilityMode(),
|
|
|
|
};
|
2017-04-04 06:09:20 +00:00
|
|
|
}
|
|
|
|
|
2003-06-24 06:20:18 +00:00
|
|
|
NS_IMETHODIMP
|
2003-06-24 05:40:37 +00:00
|
|
|
nsDOMCSSAttributeDeclaration::GetParentRule(nsIDOMCSSRule **aParent)
|
2001-11-07 07:06:31 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
*aParent = nullptr;
|
2001-11-07 07:06:31 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-27 07:03:36 +00:00
|
|
|
/* virtual */ nsINode*
|
|
|
|
nsDOMCSSAttributeDeclaration::GetParentObject()
|
|
|
|
{
|
|
|
|
return mElement;
|
|
|
|
}
|
2013-09-04 11:47:23 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-08-17 01:37:48 +00:00
|
|
|
nsDOMCSSAttributeDeclaration::SetPropertyValue(const nsCSSPropertyID aPropID,
|
2013-09-04 11:47:23 +00:00
|
|
|
const nsAString& aValue)
|
|
|
|
{
|
|
|
|
// Scripted modifications to style.opacity or style.transform
|
|
|
|
// could immediately force us into the animated state if heuristics suggest
|
|
|
|
// this is scripted animation.
|
2016-04-21 03:34:46 +00:00
|
|
|
// FIXME: This is missing the margin shorthand and the logical versions of
|
|
|
|
// the margin properties, see bug 1266287.
|
2013-09-10 00:08:41 +00:00
|
|
|
if (aPropID == eCSSProperty_opacity || aPropID == eCSSProperty_transform ||
|
|
|
|
aPropID == eCSSProperty_left || aPropID == eCSSProperty_top ||
|
2013-09-10 00:08:42 +00:00
|
|
|
aPropID == eCSSProperty_right || aPropID == eCSSProperty_bottom ||
|
|
|
|
aPropID == eCSSProperty_margin_left || aPropID == eCSSProperty_margin_top ||
|
2015-10-22 20:45:14 +00:00
|
|
|
aPropID == eCSSProperty_margin_right || aPropID == eCSSProperty_margin_bottom ||
|
2016-04-21 03:34:46 +00:00
|
|
|
aPropID == eCSSProperty_background_position_x ||
|
|
|
|
aPropID == eCSSProperty_background_position_y ||
|
2015-10-22 20:45:14 +00:00
|
|
|
aPropID == eCSSProperty_background_position) {
|
2013-09-04 11:47:23 +00:00
|
|
|
nsIFrame* frame = mElement->GetPrimaryFrame();
|
|
|
|
if (frame) {
|
2016-02-12 14:38:50 +00:00
|
|
|
ActiveLayerTracker::NotifyInlineStyleRuleModified(frame, aPropID, aValue, this);
|
2013-09-04 11:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsDOMCSSDeclaration::SetPropertyValue(aPropID, aValue);
|
|
|
|
}
|