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
|
|
|
|
2018-01-30 22:48:26 +03:00
|
|
|
/**
|
|
|
|
* Method analogous to CSSStyleDeclaration::GetPropertyValue,
|
|
|
|
* which obeys all the same restrictions.
|
|
|
|
*/
|
|
|
|
virtual nsresult GetPropertyValue(const nsCSSPropertyID aPropID,
|
|
|
|
nsAString& aValue);
|
|
|
|
|
2018-01-30 22:48:26 +03:00
|
|
|
/**
|
|
|
|
* Method analogous to CSSStyleDeclaration::SetProperty. This
|
|
|
|
* method does NOT allow setting a priority (the priority will
|
|
|
|
* always be set to default priority).
|
|
|
|
*/
|
|
|
|
virtual nsresult SetPropertyValue(const nsCSSPropertyID aPropID,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsIPrincipal* aSubjectPrincipal);
|
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
// Require subclasses to implement |GetParentRule|.
|
|
|
|
//NS_DECL_NSIDOMCSSSTYLEDECLARATION
|
2018-01-30 22:48:26 +03:00
|
|
|
void GetCssText(nsAString & aCssText) override;
|
|
|
|
void SetCssText(const nsAString & aCssText,
|
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
|
|
|
mozilla::ErrorResult& aRv) 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;
|
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;
|
2018-01-30 22:48:27 +03:00
|
|
|
void GetPropertyPriority(const nsAString & propertyName,
|
|
|
|
nsAString & aPriority) override;
|
2017-11-04 07:44:03 +03:00
|
|
|
NS_IMETHOD SetProperty(const nsAString& propertyName,
|
|
|
|
const nsAString& value,
|
|
|
|
const nsAString& priority,
|
|
|
|
nsIPrincipal* aSubjectPrincipal) override;
|
2018-01-30 22:48:27 +03:00
|
|
|
uint32_t Length() 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_
|
2018-04-17 09:57:04 +03:00
|
|
|
#define CSS_PROP(id_, method_) \
|
2012-08-24 08:08:08 +04:00
|
|
|
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
|
2018-04-17 09:57:04 +03:00
|
|
|
#define CSS_PROP_LONGHAND(name_, id_, method_, ...) CSS_PROP(id_, method_)
|
|
|
|
#define CSS_PROP_SHORTHAND(name_, id_, method_, ...) CSS_PROP(id_, method_)
|
|
|
|
#define CSS_PROP_ALIAS(name_, aliasid_, id_, method_, ...) CSS_PROP(id_, method_)
|
|
|
|
#include "mozilla/ServoCSSPropList.h"
|
2012-08-24 08:08:08 +04:00
|
|
|
#undef CSS_PROP_ALIAS
|
|
|
|
#undef CSS_PROP_SHORTHAND
|
2018-04-17 09:57:04 +03:00
|
|
|
#undef CSS_PROP_LONGHAND
|
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
|
|
|
|
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
|
|
|
|
2018-05-03 18:41:48 +03:00
|
|
|
// An implementation for GetServoCSSParsingEnvironment for callers wrapping a
|
|
|
|
// css::Rule.
|
2017-05-11 19:06:43 +03:00
|
|
|
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:
|
2018-05-02 18:43:52 +03:00
|
|
|
template<typename ServoFunc>
|
2017-11-06 00:23:49 +03:00
|
|
|
inline nsresult ModifyDeclaration(nsIPrincipal* aSubjectPrincipal,
|
2018-05-02 18:43:52 +03:00
|
|
|
ServoFunc aServoFunc);
|
1998-09-25 04:51:45 +04:00
|
|
|
};
|
|
|
|
|
1998-10-06 05:39:33 +04:00
|
|
|
#endif // nsDOMCSSDeclaration_h___
|