2017-05-19 09:12:34 +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/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/CSSKeyframeRule.h"
|
|
|
|
|
2018-06-04 13:09:11 +03:00
|
|
|
#include "mozilla/DeclarationBlock.h"
|
2017-05-19 09:12:34 +03:00
|
|
|
#include "mozilla/dom/CSSKeyframeRuleBinding.h"
|
2018-06-04 13:09:11 +03:00
|
|
|
#include "nsDOMCSSDeclaration.h"
|
2017-05-19 09:12:34 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2018-06-04 13:09:11 +03:00
|
|
|
// -------------------------------------------
|
|
|
|
// CSSKeyframeDeclaration
|
|
|
|
//
|
|
|
|
|
|
|
|
class CSSKeyframeDeclaration : public nsDOMCSSDeclaration {
|
|
|
|
public:
|
|
|
|
explicit CSSKeyframeDeclaration(CSSKeyframeRule* aRule) : mRule(aRule) {
|
|
|
|
mDecls =
|
|
|
|
new DeclarationBlock(Servo_Keyframe_GetStyle(aRule->Raw()).Consume());
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(CSSKeyframeDeclaration,
|
|
|
|
nsICSSDeclaration)
|
|
|
|
|
|
|
|
css::Rule* GetParentRule() final { return mRule; }
|
|
|
|
|
|
|
|
void DropReference() {
|
|
|
|
mRule = nullptr;
|
|
|
|
mDecls->SetOwningRule(nullptr);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
DeclarationBlock* GetOrCreateCSSDeclaration(
|
|
|
|
Operation aOperation, DeclarationBlock** aCreated) final {
|
2018-06-04 13:09:11 +03:00
|
|
|
return mDecls;
|
|
|
|
}
|
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
|
|
|
nsresult SetCSSDeclaration(DeclarationBlock* aDecls,
|
|
|
|
MutationClosureData* aClosureData) final {
|
2018-06-04 13:09:11 +03:00
|
|
|
if (!mRule) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mRule->UpdateRule([this, aDecls]() {
|
|
|
|
if (mDecls != aDecls) {
|
|
|
|
mDecls->SetOwningRule(nullptr);
|
|
|
|
mDecls = aDecls;
|
|
|
|
mDecls->SetOwningRule(mRule);
|
|
|
|
Servo_Keyframe_SetStyle(mRule->Raw(), mDecls->Raw());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
ParsingEnvironment GetParsingEnvironment(
|
|
|
|
nsIPrincipal* aSubjectPrincipal) const final {
|
|
|
|
return GetParsingEnvironmentForRule(mRule);
|
|
|
|
}
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* DocToUpdate() final { return nullptr; }
|
2018-06-04 13:09:11 +03:00
|
|
|
|
|
|
|
nsINode* GetParentObject() final {
|
|
|
|
return mRule ? mRule->GetParentObject() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
// TODO we may want to add size of mDecls as well
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~CSSKeyframeDeclaration() {
|
|
|
|
MOZ_ASSERT(!mRule, "Backpointer should have been cleared");
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSKeyframeRule* mRule;
|
|
|
|
RefPtr<DeclarationBlock> mDecls;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(CSSKeyframeDeclaration)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(CSSKeyframeDeclaration)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(CSSKeyframeDeclaration)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSKeyframeDeclaration)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMCSSDeclaration)
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
// CSSKeyframeRule
|
|
|
|
//
|
|
|
|
|
|
|
|
CSSKeyframeRule::CSSKeyframeRule(already_AddRefed<RawServoKeyframe> aRaw,
|
2018-06-29 05:56:09 +03:00
|
|
|
StyleSheet* aSheet, css::Rule* aParentRule,
|
|
|
|
uint32_t aLine, uint32_t aColumn)
|
|
|
|
: css::Rule(aSheet, aParentRule, aLine, aColumn), mRaw(aRaw) {}
|
2018-06-04 13:09:11 +03:00
|
|
|
|
|
|
|
CSSKeyframeRule::~CSSKeyframeRule() {
|
|
|
|
if (mDeclaration) {
|
|
|
|
mDeclaration->DropReference();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(CSSKeyframeRule, css::Rule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(CSSKeyframeRule, css::Rule)
|
|
|
|
|
|
|
|
// QueryInterface implementation for nsCSSKeyframeRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSKeyframeRule)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(css::Rule)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(CSSKeyframeRule)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(CSSKeyframeRule, css::Rule)
|
|
|
|
if (tmp->mDeclaration) {
|
|
|
|
tmp->mDeclaration->DropReference();
|
|
|
|
tmp->mDeclaration = nullptr;
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CSSKeyframeRule, css::Rule)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDeclaration)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
bool CSSKeyframeRule::IsCCLeaf() const {
|
|
|
|
return Rule::IsCCLeaf() && !mDeclaration;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
void CSSKeyframeRule::List(FILE* out, int32_t aIndent) const {
|
2018-06-04 13:09:11 +03:00
|
|
|
nsAutoCString str;
|
|
|
|
for (int32_t i = 0; i < aIndent; i++) {
|
|
|
|
str.AppendLiteral(" ");
|
|
|
|
}
|
|
|
|
Servo_Keyframe_Debug(mRaw, &str);
|
|
|
|
fprintf_stderr(out, "%s\n", str.get());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template <typename Func>
|
|
|
|
void CSSKeyframeRule::UpdateRule(Func aCallback) {
|
2019-04-29 08:34:06 +03:00
|
|
|
if (IsReadOnly()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-04 13:09:11 +03:00
|
|
|
aCallback();
|
|
|
|
|
|
|
|
if (StyleSheet* sheet = GetStyleSheet()) {
|
|
|
|
sheet->RuleChanged(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSSKeyframeRule::GetKeyText(nsAString& aKeyText) {
|
|
|
|
Servo_Keyframe_GetKeyText(mRaw, &aKeyText);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSSKeyframeRule::SetKeyText(const nsAString& aKeyText) {
|
|
|
|
NS_ConvertUTF16toUTF8 keyText(aKeyText);
|
|
|
|
UpdateRule([this, &keyText]() { Servo_Keyframe_SetKeyText(mRaw, &keyText); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSSKeyframeRule::GetCssText(nsAString& aCssText) const {
|
|
|
|
Servo_Keyframe_GetCssText(mRaw, &aCssText);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsICSSDeclaration* CSSKeyframeRule::Style() {
|
|
|
|
if (!mDeclaration) {
|
|
|
|
mDeclaration = new CSSKeyframeDeclaration(this);
|
|
|
|
}
|
|
|
|
return mDeclaration;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CSSKeyframeRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
if (mDeclaration) {
|
|
|
|
n += mDeclaration->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* virtual */
|
|
|
|
JSObject* CSSKeyframeRule::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return CSSKeyframeRule_Binding::Wrap(aCx, this, aGivenProto);
|
2017-05-19 09:12:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|