2016-11-23 02:26:20 +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: */
|
|
|
|
/* 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/. */
|
|
|
|
|
2018-06-04 16:35:50 +03:00
|
|
|
#ifndef mozilla_CSSStyleRule_h
|
|
|
|
#define mozilla_CSSStyleRule_h
|
2016-11-23 02:26:20 +03:00
|
|
|
|
2017-01-13 18:41:03 +03:00
|
|
|
#include "mozilla/BindingStyleRule.h"
|
2016-11-23 02:26:20 +03:00
|
|
|
#include "mozilla/ServoBindingTypes.h"
|
2017-06-19 08:45:43 +03:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2016-11-23 02:26:20 +03:00
|
|
|
|
2016-11-23 02:26:20 +03:00
|
|
|
#include "nsDOMCSSDeclaration.h"
|
2016-11-23 02:26:20 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2018-06-04 16:35:50 +03:00
|
|
|
class DeclarationBlock;
|
|
|
|
|
2017-11-27 11:10:27 +03:00
|
|
|
namespace dom {
|
|
|
|
class DocGroup;
|
2018-06-04 16:35:50 +03:00
|
|
|
class CSSStyleRule;
|
2017-11-27 11:10:27 +03:00
|
|
|
|
2018-06-04 16:35:50 +03:00
|
|
|
class CSSStyleRuleDeclaration final : public nsDOMCSSDeclaration
|
2016-11-23 02:26:20 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
css::Rule* GetParentRule() final;
|
|
|
|
nsINode* GetParentObject() final;
|
2016-11-23 02:26:20 +03:00
|
|
|
|
|
|
|
protected:
|
Bug 1428246 - The attributeChangedCallback is fired twice for the *first* style attribute change, r=peterv
The idea with this patch is that style code will first call
InlineStyleDeclarationWillChange before style declaration has changed, and SetInlineStyleDeclaration once it has changed.
In order to be able to report old attribute value, InlineStyleDeclarationWillChange reads the value and also calls AttributeWillChange (so that DOMMutationObserser can grab the old value). Later SetInlineStyleDeclaration passes the old value to
SetAttrAndNotify so that mutation events and attributeChanged callbacks are handled correctly.
Because of performance, declaration can't be cloned for reading the old value. And that is why the recently-added callback is used to detect when declaration is about to change (bug 1466963 and followup bug 1468665).
To keep the expected existing behavior, even if declaration isn't changed, but just a new declaration was created (since there wasn't any), we need to still run all these
willchange/set calls. That is when the code has 'if (created)' checks.
Since there are several declaration implementation and only nsDOMCSSAttributeDeclaration needs the about-to-change callback, GetPropertyChangeClosure is the one to initialize the callback closure, and the struct which is then passes as data to the closure.
Apparently we lost mutation event testing on style attribute when the pref was added, so test_style_attr_listener.html is modified to test both pref values.
--HG--
extra : rebase_source : 9e605d43f22e650ac3912fbfb41abb8d5a2a0c8f
2018-06-26 12:54:00 +03:00
|
|
|
mozilla::DeclarationBlock* GetOrCreateCSSDeclaration(
|
|
|
|
Operation aOperation, mozilla::DeclarationBlock** aCreated) final;
|
|
|
|
nsresult SetCSSDeclaration(DeclarationBlock* aDecl,
|
|
|
|
MutationClosureData* aClosureData) final;
|
2018-02-06 09:46:57 +03:00
|
|
|
nsIDocument* DocToUpdate() final;
|
2018-05-14 19:22:20 +03:00
|
|
|
ParsingEnvironment
|
|
|
|
GetParsingEnvironment(nsIPrincipal* aSubjectPrincipal) const final;
|
2016-11-23 02:26:20 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
// For accessing the constructor.
|
2018-06-04 16:35:50 +03:00
|
|
|
friend class CSSStyleRule;
|
2016-11-23 02:26:20 +03:00
|
|
|
|
2018-06-04 16:35:50 +03:00
|
|
|
explicit CSSStyleRuleDeclaration(
|
2016-11-23 02:26:20 +03:00
|
|
|
already_AddRefed<RawServoDeclarationBlock> aDecls);
|
2018-06-04 16:35:50 +03:00
|
|
|
~CSSStyleRuleDeclaration();
|
2016-11-23 02:26:20 +03:00
|
|
|
|
2018-06-04 16:35:50 +03:00
|
|
|
inline CSSStyleRule* Rule();
|
|
|
|
inline const CSSStyleRule* Rule() const;
|
2016-11-23 02:26:20 +03:00
|
|
|
|
2018-05-30 19:15:25 +03:00
|
|
|
RefPtr<DeclarationBlock> mDecls;
|
2016-11-23 02:26:20 +03:00
|
|
|
};
|
|
|
|
|
2018-06-04 16:35:50 +03:00
|
|
|
class CSSStyleRule final : public BindingStyleRule
|
2018-06-29 05:56:09 +03:00
|
|
|
, public SupportsWeakPtr<CSSStyleRule>
|
2016-11-23 02:26:20 +03:00
|
|
|
{
|
|
|
|
public:
|
2018-06-04 16:35:50 +03:00
|
|
|
CSSStyleRule(already_AddRefed<RawServoStyleRule> aRawRule,
|
2018-06-29 05:56:09 +03:00
|
|
|
StyleSheet* aSheet,
|
|
|
|
css::Rule* aParentRule,
|
|
|
|
uint32_t aLine,
|
|
|
|
uint32_t aColumn);
|
2016-11-23 02:26:20 +03:00
|
|
|
|
2016-12-01 02:18:14 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2018-06-04 16:35:50 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(CSSStyleRule,
|
2016-11-23 02:26:20 +03:00
|
|
|
css::Rule)
|
2018-02-06 09:46:57 +03:00
|
|
|
bool IsCCLeaf() const final MOZ_MUST_OVERRIDE;
|
2016-11-23 02:26:20 +03:00
|
|
|
|
2018-06-04 16:35:50 +03:00
|
|
|
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(CSSStyleRule)
|
2017-06-19 08:45:43 +03:00
|
|
|
|
2017-06-07 18:48:49 +03:00
|
|
|
uint32_t GetSelectorCount() override;
|
|
|
|
nsresult GetSelectorText(uint32_t aSelectorIndex,
|
|
|
|
nsAString& aText) override;
|
|
|
|
nsresult GetSpecificity(uint32_t aSelectorIndex,
|
|
|
|
uint64_t* aSpecificity) override;
|
|
|
|
nsresult SelectorMatchesElement(dom::Element* aElement,
|
|
|
|
uint32_t aSelectorIndex,
|
|
|
|
const nsAString& aPseudo,
|
|
|
|
bool* aMatches) override;
|
2017-10-19 10:55:42 +03:00
|
|
|
NotNull<DeclarationBlock*> GetDeclarationBlock() const override;
|
2017-06-07 18:48:49 +03:00
|
|
|
|
2017-01-13 18:41:02 +03:00
|
|
|
// WebIDL interface
|
2018-06-26 00:20:54 +03:00
|
|
|
uint16_t Type() const final { return dom::CSSRule_Binding::STYLE_RULE; }
|
2018-02-06 09:46:57 +03:00
|
|
|
void GetCssText(nsAString& aCssText) const final;
|
|
|
|
void GetSelectorText(nsAString& aSelectorText) final;
|
|
|
|
void SetSelectorText(const nsAString& aSelectorText) final;
|
|
|
|
nsICSSDeclaration* Style() final;
|
2017-01-13 18:41:02 +03:00
|
|
|
|
2016-11-23 02:26:20 +03:00
|
|
|
RawServoStyleRule* Raw() const { return mRawRule; }
|
|
|
|
|
2016-11-23 02:26:20 +03:00
|
|
|
// Methods of mozilla::css::Rule
|
2018-02-06 09:46:57 +03:00
|
|
|
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final;
|
2016-11-23 02:26:20 +03:00
|
|
|
#ifdef DEBUG
|
2018-02-06 09:46:57 +03:00
|
|
|
void List(FILE* out = stdout, int32_t aIndent = 0) const final;
|
2016-11-23 02:26:20 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
2018-06-04 16:35:50 +03:00
|
|
|
~CSSStyleRule() {}
|
2016-11-23 02:26:20 +03:00
|
|
|
|
2016-11-23 02:26:20 +03:00
|
|
|
// For computing the offset of mDecls.
|
2018-06-04 16:35:50 +03:00
|
|
|
friend class CSSStyleRuleDeclaration;
|
2016-11-23 02:26:20 +03:00
|
|
|
|
2016-11-23 02:26:20 +03:00
|
|
|
RefPtr<RawServoStyleRule> mRawRule;
|
2018-06-04 16:35:50 +03:00
|
|
|
CSSStyleRuleDeclaration mDecls;
|
2016-11-23 02:26:20 +03:00
|
|
|
};
|
|
|
|
|
2018-06-04 16:35:50 +03:00
|
|
|
CSSStyleRule*
|
|
|
|
CSSStyleRuleDeclaration::Rule()
|
2016-11-23 02:26:20 +03:00
|
|
|
{
|
2018-06-04 16:35:50 +03:00
|
|
|
return reinterpret_cast<CSSStyleRule*>(
|
|
|
|
reinterpret_cast<uint8_t*>(this) - offsetof(CSSStyleRule, mDecls));
|
2017-04-04 09:07:44 +03:00
|
|
|
}
|
|
|
|
|
2018-06-04 16:35:50 +03:00
|
|
|
const CSSStyleRule*
|
|
|
|
CSSStyleRuleDeclaration::Rule() const
|
2017-04-04 09:07:44 +03:00
|
|
|
{
|
2018-06-04 16:35:50 +03:00
|
|
|
return reinterpret_cast<const CSSStyleRule*>(
|
|
|
|
reinterpret_cast<const uint8_t*>(this) - offsetof(CSSStyleRule, mDecls));
|
2016-11-23 02:26:20 +03:00
|
|
|
}
|
|
|
|
|
2018-06-04 16:35:50 +03:00
|
|
|
} // namespace dom
|
2016-11-23 02:26:20 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2018-06-04 16:35:50 +03:00
|
|
|
#endif // mozilla_CSSStyleRule_h
|