2017-10-27 20:33:53 +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: */
|
2012-05-21 15:12:37 +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/. */
|
2006-03-25 08:47:31 +03:00
|
|
|
|
|
|
|
/* base class for DOM objects for element.style and cssStyleRule.style */
|
|
|
|
|
1998-10-06 05:39:33 +04:00
|
|
|
#ifndef nsDOMCSSDeclaration_h___
|
2003-10-30 04:40:33 +03:00
|
|
|
#define nsDOMCSSDeclaration_h___
|
1998-09-25 04:51:45 +04:00
|
|
|
|
2004-06-08 05:32:29 +04:00
|
|
|
#include "nsICSSDeclaration.h"
|
2013-08-22 10:29:57 +04:00
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2017-05-19 09:12:34 +03:00
|
|
|
#include "mozilla/URLExtraData.h"
|
2014-05-09 19:23:14 +04:00
|
|
|
#include "nsIURI.h"
|
2009-09-18 17:09:55 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2017-05-19 09:12:34 +03:00
|
|
|
#include "nsCompatibility.h"
|
1998-09-25 04:51:45 +04:00
|
|
|
|
2007-05-03 05:15:53 +04:00
|
|
|
class nsIPrincipal;
|
2009-12-11 19:13:19 +03:00
|
|
|
class nsIDocument;
|
2014-03-07 21:14:26 +04:00
|
|
|
struct JSContext;
|
|
|
|
class JSObject;
|
1998-09-25 04:51:45 +04:00
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
namespace mozilla {
|
2016-11-03 06:41:02 +03:00
|
|
|
class DeclarationBlock;
|
2010-03-03 00:00:53 +03:00
|
|
|
namespace css {
|
|
|
|
class Loader;
|
2011-04-08 05:23:46 +04:00
|
|
|
class Rule;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
2010-03-03 00:00:53 +03:00
|
|
|
|
2012-10-31 01:14:06 +04:00
|
|
|
class nsDOMCSSDeclaration : public nsICSSDeclaration
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
|
|
|
public:
|
2003-09-24 07:34:27 +04:00
|
|
|
// Only implement QueryInterface; subclasses have the responsibility
|
|
|
|
// of implementing AddRef/Release.
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
|
1998-09-25 04:51:45 +04:00
|
|
|
|
2012-08-24 08:08:08 +04:00
|
|
|
// Declare addref and release so they can be called on us, but don't
|
|
|
|
// implement them. Our subclasses must handle their own
|
|
|
|
// refcounting.
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD_(MozExternalRefCountType) AddRef() override = 0;
|
|
|
|
NS_IMETHOD_(MozExternalRefCountType) Release() override = 0;
|
2012-08-24 08:08:08 +04:00
|
|
|
|
2004-06-08 05:32:29 +04:00
|
|
|
NS_DECL_NSICSSDECLARATION
|
2012-08-24 08:08:08 +04:00
|
|
|
using nsICSSDeclaration::GetLength;
|
2004-06-08 05:32:29 +04:00
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
// Require subclasses to implement |GetParentRule|.
|
|
|
|
//NS_DECL_NSIDOMCSSSTYLEDECLARATION
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD GetCssText(nsAString & aCssText) override;
|
2017-11-04 07:44:03 +03:00
|
|
|
NS_IMETHOD SetCssText(const nsAString & aCssText,
|
|
|
|
nsIPrincipal* aSubjectPrincipal) override;
|
2003-06-24 09:40:37 +04:00
|
|
|
NS_IMETHOD GetPropertyValue(const nsAString & propertyName,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAString & _retval) override;
|
2012-10-01 20:49:41 +04:00
|
|
|
virtual already_AddRefed<mozilla::dom::CSSValue>
|
|
|
|
GetPropertyCSSValue(const nsAString & propertyName,
|
2015-03-21 19:28:04 +03:00
|
|
|
mozilla::ErrorResult& aRv) override;
|
2012-10-01 20:49:41 +04:00
|
|
|
using nsICSSDeclaration::GetPropertyCSSValue;
|
2003-06-24 09:40:37 +04:00
|
|
|
NS_IMETHOD RemoveProperty(const nsAString & propertyName,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAString & _retval) override;
|
2003-06-24 09:40:37 +04:00
|
|
|
NS_IMETHOD GetPropertyPriority(const nsAString & propertyName,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAString & _retval) override;
|
2017-11-04 07:44:03 +03:00
|
|
|
NS_IMETHOD SetProperty(const nsAString& propertyName,
|
|
|
|
const nsAString& value,
|
|
|
|
const nsAString& priority,
|
|
|
|
nsIPrincipal* aSubjectPrincipal) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD GetLength(uint32_t *aLength) override;
|
1998-11-26 04:34:53 +03:00
|
|
|
|
2012-08-24 08:08:08 +04:00
|
|
|
// WebIDL interface for CSS2Properties
|
2013-03-25 20:24:21 +04:00
|
|
|
#define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_
|
2012-08-24 08:08:08 +04:00
|
|
|
#define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, \
|
|
|
|
kwtable_, stylestruct_, stylestructoffset_, animtype_) \
|
|
|
|
void \
|
2017-12-06 00:03:18 +03:00
|
|
|
Get##method_(nsAString& aValue, mozilla::ErrorResult& rv) \
|
2012-08-24 08:08:08 +04:00
|
|
|
{ \
|
|
|
|
rv = GetPropertyValue(eCSSProperty_##id_, aValue); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void \
|
2017-12-21 01:43:18 +03:00
|
|
|
Set##method_(const nsAString& aValue, nsIPrincipal* aSubjectPrincipal, \
|
2017-11-04 07:44:03 +03:00
|
|
|
mozilla::ErrorResult& rv) \
|
2012-08-24 08:08:08 +04:00
|
|
|
{ \
|
2017-12-21 01:43:18 +03:00
|
|
|
rv = SetPropertyValue(eCSSProperty_##id_, aValue, aSubjectPrincipal); \
|
2012-08-24 08:08:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define CSS_PROP_LIST_EXCLUDE_INTERNAL
|
2015-01-17 07:16:01 +03:00
|
|
|
#define CSS_PROP_LIST_INCLUDE_LOGICAL
|
2012-08-24 08:08:08 +04:00
|
|
|
#define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, pref_) \
|
|
|
|
CSS_PROP(name_, id_, method_, flags_, pref_, X, X, X, X, X)
|
|
|
|
#include "nsCSSPropList.h"
|
|
|
|
|
2017-08-13 00:37:19 +03:00
|
|
|
#define CSS_PROP_ALIAS(aliasname_, aliasid_, propid_, aliasmethod_, pref_) \
|
2012-08-24 08:08:08 +04:00
|
|
|
CSS_PROP(X, propid_, aliasmethod_, X, pref_, X, X, X, X, X)
|
|
|
|
#include "nsCSSPropAliasList.h"
|
|
|
|
#undef CSS_PROP_ALIAS
|
|
|
|
|
|
|
|
#undef CSS_PROP_SHORTHAND
|
2015-01-17 07:16:01 +03:00
|
|
|
#undef CSS_PROP_LIST_INCLUDE_LOGICAL
|
2012-08-24 08:08:08 +04:00
|
|
|
#undef CSS_PROP_LIST_EXCLUDE_INTERNAL
|
|
|
|
#undef CSS_PROP
|
2013-03-25 20:24:21 +04:00
|
|
|
#undef CSS_PROP_PUBLIC_OR_PRIVATE
|
2012-08-24 08:08:08 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) override;
|
2012-08-24 08:08:08 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2012-08-24 08:08:09 +04:00
|
|
|
|
2017-12-01 12:35:47 +03:00
|
|
|
// Information needed to parse a declaration for Servo side.
|
|
|
|
// Put this in public so other Servo parsing functions can reuse this.
|
|
|
|
struct MOZ_STACK_CLASS ServoCSSParsingEnvironment
|
|
|
|
{
|
|
|
|
RefPtr<mozilla::URLExtraData> mUrlExtraData;
|
|
|
|
nsCompatibility mCompatMode;
|
|
|
|
mozilla::css::Loader* mLoader;
|
|
|
|
|
|
|
|
ServoCSSParsingEnvironment(mozilla::URLExtraData* aUrlData,
|
|
|
|
nsCompatibility aCompatMode,
|
|
|
|
mozilla::css::Loader* aLoader)
|
|
|
|
: mUrlExtraData(aUrlData)
|
|
|
|
, mCompatMode(aCompatMode)
|
|
|
|
, mLoader(aLoader)
|
|
|
|
{}
|
|
|
|
|
|
|
|
ServoCSSParsingEnvironment(already_AddRefed<mozilla::URLExtraData> aUrlData,
|
|
|
|
nsCompatibility aCompatMode,
|
|
|
|
mozilla::css::Loader* aLoader)
|
|
|
|
: mUrlExtraData(aUrlData)
|
|
|
|
, mCompatMode(aCompatMode)
|
|
|
|
, mLoader(aLoader)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2003-06-18 05:59:57 +04:00
|
|
|
protected:
|
2015-04-10 03:41:35 +03:00
|
|
|
// The reason for calling GetCSSDeclaration.
|
|
|
|
enum Operation {
|
|
|
|
// We are calling GetCSSDeclaration so that we can read from it. Does not
|
|
|
|
// allocate a new declaration if we don't have one yet; returns nullptr in
|
|
|
|
// this case.
|
|
|
|
eOperation_Read,
|
|
|
|
|
|
|
|
// We are calling GetCSSDeclaration so that we can set a property on it
|
|
|
|
// or re-parse the whole declaration. Allocates a new declaration if we
|
|
|
|
// don't have one yet and calls AttributeWillChange. A nullptr return value
|
|
|
|
// indicates an error allocating the declaration.
|
|
|
|
eOperation_Modify,
|
|
|
|
|
|
|
|
// We are calling GetCSSDeclaration so that we can remove a property from
|
|
|
|
// it. Does not allocates a new declaration if we don't have one yet;
|
|
|
|
// returns nullptr in this case. If we do have a declaration, calls
|
|
|
|
// AttributeWillChange.
|
|
|
|
eOperation_RemoveProperty
|
|
|
|
};
|
2016-11-03 06:41:02 +03:00
|
|
|
virtual mozilla::DeclarationBlock* GetCSSDeclaration(Operation aOperation) = 0;
|
|
|
|
virtual nsresult SetCSSDeclaration(mozilla::DeclarationBlock* aDecl) = 0;
|
2009-12-11 19:13:19 +03:00
|
|
|
// Document that we must call BeginUpdate/EndUpdate on around the
|
2010-07-23 22:00:47 +04:00
|
|
|
// calls to SetCSSDeclaration and the style rule mutation that leads
|
2009-12-11 19:13:19 +03:00
|
|
|
// to it.
|
|
|
|
virtual nsIDocument* DocToUpdate() = 0;
|
2010-03-02 23:59:32 +03:00
|
|
|
|
2011-04-28 00:53:49 +04:00
|
|
|
// Information neded to parse a declaration. We need the mSheetURI
|
|
|
|
// for error reporting, mBaseURI to resolve relative URIs,
|
|
|
|
// mPrincipal for subresource loads, and mCSSLoader for determining
|
|
|
|
// whether we're in quirks mode. mBaseURI needs to be a strong
|
|
|
|
// pointer because of xml:base possibly creating base URIs on the
|
|
|
|
// fly. This is why we don't use CSSParsingEnvironment as a return
|
|
|
|
// value, to avoid multiple-refcounting of mBaseURI.
|
|
|
|
struct CSSParsingEnvironment {
|
2015-06-16 15:23:00 +03:00
|
|
|
nsIURI* MOZ_UNSAFE_REF("user of CSSParsingEnviroment must hold an owning "
|
|
|
|
"reference; reference counting here has unacceptable "
|
|
|
|
"performance overhead (see bug 649163)") mSheetURI;
|
2011-04-28 00:53:49 +04:00
|
|
|
nsCOMPtr<nsIURI> mBaseURI;
|
2015-06-16 15:23:00 +03:00
|
|
|
nsIPrincipal* MOZ_UNSAFE_REF("user of CSSParsingEnviroment must hold an owning "
|
|
|
|
"reference; reference counting here has unacceptable "
|
|
|
|
"performance overhead (see bug 649163)") mPrincipal;
|
|
|
|
mozilla::css::Loader* MOZ_UNSAFE_REF("user of CSSParsingEnviroment must hold an owning "
|
|
|
|
"reference; reference counting here has unacceptable "
|
|
|
|
"performance overhead (see bug 649163)") mCSSLoader;
|
2011-04-28 00:53:49 +04:00
|
|
|
};
|
2015-06-16 15:23:00 +03:00
|
|
|
|
2011-04-28 00:53:49 +04:00
|
|
|
// On failure, mPrincipal should be set to null in aCSSParseEnv.
|
|
|
|
// If mPrincipal is null, the other members may not be set to
|
|
|
|
// anything meaningful.
|
2017-11-06 00:23:49 +03:00
|
|
|
// If aSubjectPrincipal is passed, it should be the subject principal of the
|
|
|
|
// scripted caller that initiated the parser.
|
|
|
|
virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv,
|
|
|
|
nsIPrincipal* aSubjectPrincipal = nullptr) = 0;
|
2003-06-18 05:59:57 +04:00
|
|
|
|
2017-05-11 19:06:43 +03:00
|
|
|
// mUrlExtraData returns URL data for parsing url values in
|
|
|
|
// CSS. Returns nullptr on failure. If mUrlExtraData is nullptr,
|
|
|
|
// mCompatMode may not be set to anything meaningful.
|
2017-11-06 00:23:49 +03:00
|
|
|
// If aSubjectPrincipal is passed, it should be the subject principal of the
|
|
|
|
// scripted caller that initiated the parser.
|
|
|
|
virtual ServoCSSParsingEnvironment
|
|
|
|
GetServoCSSParsingEnvironment(nsIPrincipal* aSubjectPrincipal = nullptr) const = 0;
|
2017-05-11 19:06:43 +03:00
|
|
|
|
2011-04-12 10:18:42 +04:00
|
|
|
// An implementation for GetCSSParsingEnvironment for callers wrapping
|
2011-04-08 05:23:46 +04:00
|
|
|
// an css::Rule.
|
|
|
|
static void GetCSSParsingEnvironmentForRule(mozilla::css::Rule* aRule,
|
2011-04-28 00:53:49 +04:00
|
|
|
CSSParsingEnvironment& aCSSParseEnv);
|
2011-04-12 10:18:42 +04:00
|
|
|
|
2017-05-11 19:06:43 +03:00
|
|
|
// An implementation for GetServoCSSParsingEnvironment for callers wrapping
|
|
|
|
// an css::Rule.
|
|
|
|
static ServoCSSParsingEnvironment
|
|
|
|
GetServoCSSParsingEnvironmentForRule(const mozilla::css::Rule* aRule);
|
2017-04-04 09:09:20 +03:00
|
|
|
|
2016-08-17 04:37:48 +03:00
|
|
|
nsresult ParsePropertyValue(const nsCSSPropertyID aPropID,
|
2010-04-02 10:07:40 +04:00
|
|
|
const nsAString& aPropValue,
|
2017-11-04 07:44:03 +03:00
|
|
|
bool aIsImportant,
|
|
|
|
nsIPrincipal* aSubjectPrincipal);
|
2004-06-08 05:32:29 +04:00
|
|
|
|
2013-12-12 06:09:46 +04:00
|
|
|
nsresult ParseCustomPropertyValue(const nsAString& aPropertyName,
|
|
|
|
const nsAString& aPropValue,
|
2017-11-04 07:44:03 +03:00
|
|
|
bool aIsImportant,
|
|
|
|
nsIPrincipal* aSubjectPrincipal);
|
2013-12-12 06:09:46 +04:00
|
|
|
|
2016-11-03 06:41:02 +03:00
|
|
|
nsresult RemovePropertyInternal(nsCSSPropertyID aPropID);
|
|
|
|
nsresult RemovePropertyInternal(const nsAString& aProperty);
|
|
|
|
|
1998-09-25 04:51:45 +04:00
|
|
|
protected:
|
1998-10-06 05:39:33 +04:00
|
|
|
virtual ~nsDOMCSSDeclaration();
|
2017-04-04 08:28:07 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
template<typename GeckoFunc, typename ServoFunc>
|
2017-11-06 00:23:49 +03:00
|
|
|
inline nsresult ModifyDeclaration(nsIPrincipal* aSubjectPrincipal,
|
|
|
|
GeckoFunc aGeckoFunc, ServoFunc aServoFunc);
|
1998-09-25 04:51:45 +04:00
|
|
|
};
|
|
|
|
|
1998-10-06 05:39:33 +04:00
|
|
|
#endif // nsDOMCSSDeclaration_h___
|