2017-10-27 17:33:53 +00: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 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/. */
|
2006-03-25 05:47:31 +00:00
|
|
|
|
|
|
|
/* base class for DOM objects for element.style and cssStyleRule.style */
|
|
|
|
|
1998-10-06 01:39:33 +00:00
|
|
|
#ifndef nsDOMCSSDeclaration_h___
|
2003-10-30 01:40:33 +00:00
|
|
|
#define nsDOMCSSDeclaration_h___
|
1998-09-25 00:51:45 +00:00
|
|
|
|
2004-06-08 01:32:29 +00:00
|
|
|
#include "nsICSSDeclaration.h"
|
2013-08-22 06:29:57 +00:00
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2017-05-19 06:12:34 +00:00
|
|
|
#include "mozilla/URLExtraData.h"
|
2014-05-09 15:23:14 +00:00
|
|
|
#include "nsIURI.h"
|
2009-09-18 13:09:55 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2017-05-19 06:12:34 +00:00
|
|
|
#include "nsCompatibility.h"
|
1998-09-25 00:51:45 +00:00
|
|
|
|
2007-05-03 01:15:53 +00:00
|
|
|
class nsIPrincipal;
|
2009-12-11 16:13:19 +00:00
|
|
|
class nsIDocument;
|
2014-03-07 17:14:26 +00:00
|
|
|
struct JSContext;
|
|
|
|
class JSObject;
|
1998-09-25 00:51:45 +00:00
|
|
|
|
2010-03-02 21:00:53 +00:00
|
|
|
namespace mozilla {
|
2016-11-03 03:41:02 +00:00
|
|
|
class DeclarationBlock;
|
2010-03-02 21:00:53 +00:00
|
|
|
namespace css {
|
|
|
|
class Loader;
|
2011-04-08 01:23:46 +00:00
|
|
|
class Rule;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
2010-03-02 21:00:53 +00:00
|
|
|
|
2012-10-30 21:14:06 +00:00
|
|
|
class nsDOMCSSDeclaration : public nsICSSDeclaration
|
1998-09-25 00:51:45 +00:00
|
|
|
{
|
|
|
|
public:
|
2003-09-24 03:34:27 +00:00
|
|
|
// Only implement QueryInterface; subclasses have the responsibility
|
|
|
|
// of implementing AddRef/Release.
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
|
1998-09-25 00:51:45 +00:00
|
|
|
|
2012-08-24 04:08:08 +00: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 16:28:04 +00:00
|
|
|
NS_IMETHOD_(MozExternalRefCountType) AddRef() override = 0;
|
|
|
|
NS_IMETHOD_(MozExternalRefCountType) Release() override = 0;
|
2012-08-24 04:08:08 +00:00
|
|
|
|
2018-01-30 19:48:26 +00:00
|
|
|
/**
|
|
|
|
* Method analogous to CSSStyleDeclaration::GetPropertyValue,
|
|
|
|
* which obeys all the same restrictions.
|
|
|
|
*/
|
|
|
|
virtual nsresult GetPropertyValue(const nsCSSPropertyID aPropID,
|
|
|
|
nsAString& aValue);
|
|
|
|
|
2018-01-30 19:48:26 +00: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 05:40:37 +00:00
|
|
|
// Require subclasses to implement |GetParentRule|.
|
|
|
|
//NS_DECL_NSIDOMCSSSTYLEDECLARATION
|
2018-01-30 19:48:26 +00:00
|
|
|
void GetCssText(nsAString & aCssText) override;
|
|
|
|
void SetCssText(const nsAString & aCssText,
|
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
|
|
|
mozilla::ErrorResult& aRv) override;
|
2003-06-24 05:40:37 +00:00
|
|
|
NS_IMETHOD GetPropertyValue(const nsAString & propertyName,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsAString & _retval) override;
|
2003-06-24 05:40:37 +00:00
|
|
|
NS_IMETHOD RemoveProperty(const nsAString & propertyName,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsAString & _retval) override;
|
2018-01-30 19:48:27 +00:00
|
|
|
void GetPropertyPriority(const nsAString & propertyName,
|
|
|
|
nsAString & aPriority) override;
|
2017-11-04 04:44:03 +00:00
|
|
|
NS_IMETHOD SetProperty(const nsAString& propertyName,
|
|
|
|
const nsAString& value,
|
|
|
|
const nsAString& priority,
|
|
|
|
nsIPrincipal* aSubjectPrincipal) override;
|
2018-01-30 19:48:27 +00:00
|
|
|
uint32_t Length() override;
|
1998-11-26 01:34:53 +00:00
|
|
|
|
2012-08-24 04:08:08 +00:00
|
|
|
// WebIDL interface for CSS2Properties
|
2013-03-25 16:24:21 +00:00
|
|
|
#define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_
|
2018-04-17 06:57:04 +00:00
|
|
|
#define CSS_PROP(id_, method_) \
|
2012-08-24 04:08:08 +00:00
|
|
|
void \
|
2017-12-05 21:03:18 +00:00
|
|
|
Get##method_(nsAString& aValue, mozilla::ErrorResult& rv) \
|
2012-08-24 04:08:08 +00:00
|
|
|
{ \
|
|
|
|
rv = GetPropertyValue(eCSSProperty_##id_, aValue); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void \
|
2017-12-20 22:43:18 +00:00
|
|
|
Set##method_(const nsAString& aValue, nsIPrincipal* aSubjectPrincipal, \
|
2017-11-04 04:44:03 +00:00
|
|
|
mozilla::ErrorResult& rv) \
|
2012-08-24 04:08:08 +00:00
|
|
|
{ \
|
2017-12-20 22:43:18 +00:00
|
|
|
rv = SetPropertyValue(eCSSProperty_##id_, aValue, aSubjectPrincipal); \
|
2012-08-24 04:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define CSS_PROP_LIST_EXCLUDE_INTERNAL
|
2018-04-17 06:57:04 +00: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 04:08:08 +00:00
|
|
|
#undef CSS_PROP_ALIAS
|
|
|
|
#undef CSS_PROP_SHORTHAND
|
2018-04-17 06:57:04 +00:00
|
|
|
#undef CSS_PROP_LONGHAND
|
2012-08-24 04:08:08 +00:00
|
|
|
#undef CSS_PROP_LIST_EXCLUDE_INTERNAL
|
|
|
|
#undef CSS_PROP
|
2013-03-25 16:24:21 +00:00
|
|
|
#undef CSS_PROP_PUBLIC_OR_PRIVATE
|
2012-08-24 04:08:08 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) override;
|
2012-08-24 04:08:08 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2012-08-24 04:08:09 +00:00
|
|
|
|
2017-12-01 09:35:47 +00:00
|
|
|
// Information needed to parse a declaration for Servo side.
|
|
|
|
// Put this in public so other Servo parsing functions can reuse this.
|
2018-05-14 16:22:20 +00:00
|
|
|
struct MOZ_STACK_CLASS ParsingEnvironment
|
2017-12-01 09:35:47 +00:00
|
|
|
{
|
|
|
|
RefPtr<mozilla::URLExtraData> mUrlExtraData;
|
|
|
|
nsCompatibility mCompatMode;
|
|
|
|
mozilla::css::Loader* mLoader;
|
|
|
|
|
2018-05-14 16:22:20 +00:00
|
|
|
ParsingEnvironment(mozilla::URLExtraData* aUrlData,
|
2017-12-01 09:35:47 +00:00
|
|
|
nsCompatibility aCompatMode,
|
|
|
|
mozilla::css::Loader* aLoader)
|
|
|
|
: mUrlExtraData(aUrlData)
|
|
|
|
, mCompatMode(aCompatMode)
|
|
|
|
, mLoader(aLoader)
|
|
|
|
{}
|
|
|
|
|
2018-05-14 16:22:20 +00:00
|
|
|
ParsingEnvironment(already_AddRefed<mozilla::URLExtraData> aUrlData,
|
2017-12-01 09:35:47 +00:00
|
|
|
nsCompatibility aCompatMode,
|
|
|
|
mozilla::css::Loader* aLoader)
|
|
|
|
: mUrlExtraData(aUrlData)
|
|
|
|
, mCompatMode(aCompatMode)
|
|
|
|
, mLoader(aLoader)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2003-06-18 01:59:57 +00:00
|
|
|
protected:
|
2015-04-10 00:41:35 +00: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 03:41:02 +00:00
|
|
|
virtual mozilla::DeclarationBlock* GetCSSDeclaration(Operation aOperation) = 0;
|
|
|
|
virtual nsresult SetCSSDeclaration(mozilla::DeclarationBlock* aDecl) = 0;
|
2009-12-11 16:13:19 +00:00
|
|
|
// Document that we must call BeginUpdate/EndUpdate on around the
|
2010-07-23 18:00:47 +00:00
|
|
|
// calls to SetCSSDeclaration and the style rule mutation that leads
|
2009-12-11 16:13:19 +00:00
|
|
|
// to it.
|
|
|
|
virtual nsIDocument* DocToUpdate() = 0;
|
2010-03-02 20:59:32 +00:00
|
|
|
|
2017-05-11 16:06:43 +00: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-05 21:23:49 +00:00
|
|
|
// If aSubjectPrincipal is passed, it should be the subject principal of the
|
|
|
|
// scripted caller that initiated the parser.
|
2018-05-14 16:22:20 +00:00
|
|
|
virtual ParsingEnvironment
|
|
|
|
GetParsingEnvironment(nsIPrincipal* aSubjectPrincipal = nullptr) const = 0;
|
2017-05-11 16:06:43 +00:00
|
|
|
|
2018-05-14 16:22:20 +00:00
|
|
|
// An implementation for GetParsingEnvironment for callers wrapping a
|
2018-05-03 15:41:48 +00:00
|
|
|
// css::Rule.
|
2018-05-14 16:22:20 +00:00
|
|
|
static ParsingEnvironment
|
|
|
|
GetParsingEnvironmentForRule(const mozilla::css::Rule* aRule);
|
2017-04-04 06:09:20 +00:00
|
|
|
|
2016-08-17 01:37:48 +00:00
|
|
|
nsresult ParsePropertyValue(const nsCSSPropertyID aPropID,
|
2010-04-02 06:07:40 +00:00
|
|
|
const nsAString& aPropValue,
|
2017-11-04 04:44:03 +00:00
|
|
|
bool aIsImportant,
|
|
|
|
nsIPrincipal* aSubjectPrincipal);
|
2004-06-08 01:32:29 +00:00
|
|
|
|
2013-12-12 02:09:46 +00:00
|
|
|
nsresult ParseCustomPropertyValue(const nsAString& aPropertyName,
|
|
|
|
const nsAString& aPropValue,
|
2017-11-04 04:44:03 +00:00
|
|
|
bool aIsImportant,
|
|
|
|
nsIPrincipal* aSubjectPrincipal);
|
2013-12-12 02:09:46 +00:00
|
|
|
|
2016-11-03 03:41:02 +00:00
|
|
|
nsresult RemovePropertyInternal(nsCSSPropertyID aPropID);
|
|
|
|
nsresult RemovePropertyInternal(const nsAString& aProperty);
|
|
|
|
|
1998-09-25 00:51:45 +00:00
|
|
|
protected:
|
1998-10-06 01:39:33 +00:00
|
|
|
virtual ~nsDOMCSSDeclaration();
|
2017-04-04 05:28:07 +00:00
|
|
|
|
|
|
|
private:
|
2018-05-02 15:43:52 +00:00
|
|
|
template<typename ServoFunc>
|
2017-11-05 21:23:49 +00:00
|
|
|
inline nsresult ModifyDeclaration(nsIPrincipal* aSubjectPrincipal,
|
2018-05-02 15:43:52 +00:00
|
|
|
ServoFunc aServoFunc);
|
1998-09-25 00:51:45 +00:00
|
|
|
};
|
|
|
|
|
1998-10-06 01:39:33 +00:00
|
|
|
#endif // nsDOMCSSDeclaration_h___
|