2017-04-01 03:14:49 +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/CSSPageRule.h"
|
|
|
|
#include "mozilla/dom/CSSPageRuleBinding.h"
|
|
|
|
|
2018-06-05 14:39:42 +03:00
|
|
|
#include "mozilla/DeclarationBlock.h"
|
|
|
|
#include "mozilla/ServoBindings.h"
|
|
|
|
|
2017-04-01 03:14:49 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2018-06-05 14:39:42 +03:00
|
|
|
// -- CSSPageRuleDeclaration ---------------------------------------
|
|
|
|
|
|
|
|
CSSPageRuleDeclaration::CSSPageRuleDeclaration(
|
|
|
|
already_AddRefed<RawServoDeclarationBlock> aDecls)
|
|
|
|
: mDecls(new DeclarationBlock(std::move(aDecls))) {}
|
|
|
|
|
|
|
|
CSSPageRuleDeclaration::~CSSPageRuleDeclaration() {
|
|
|
|
mDecls->SetOwningRule(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryInterface implementation for CSSPageRuleDeclaration
|
|
|
|
NS_INTERFACE_MAP_BEGIN(CSSPageRuleDeclaration)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
// We forward the cycle collection interfaces to Rule(), which is
|
|
|
|
// never null (in fact, we're part of that object!)
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsCycleCollectionISupports)) ||
|
|
|
|
aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) {
|
|
|
|
return Rule()->QueryInterface(aIID, aInstancePtr);
|
2018-12-20 22:32:51 +03:00
|
|
|
}
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMCSSDeclaration)
|
2018-06-05 14:39:42 +03:00
|
|
|
|
|
|
|
NS_IMPL_ADDREF_USING_AGGREGATOR(CSSPageRuleDeclaration, Rule())
|
|
|
|
NS_IMPL_RELEASE_USING_AGGREGATOR(CSSPageRuleDeclaration, Rule())
|
|
|
|
|
|
|
|
/* nsDOMCSSDeclaration implementation */
|
|
|
|
|
|
|
|
css::Rule* CSSPageRuleDeclaration::GetParentRule() { return Rule(); }
|
|
|
|
|
|
|
|
nsINode* CSSPageRuleDeclaration::GetParentObject() {
|
|
|
|
return Rule()->GetParentObject();
|
|
|
|
}
|
|
|
|
|
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* CSSPageRuleDeclaration::GetOrCreateCSSDeclaration(
|
|
|
|
Operation aOperation, DeclarationBlock * *aCreated) {
|
2018-06-05 14:39:42 +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 CSSPageRuleDeclaration::SetCSSDeclaration(
|
|
|
|
DeclarationBlock * aDecl, MutationClosureData * aClosureData) {
|
2018-06-05 14:39:42 +03:00
|
|
|
MOZ_ASSERT(aDecl, "must be non-null");
|
|
|
|
CSSPageRule* rule = Rule();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-06-05 14:39:42 +03:00
|
|
|
if (aDecl != mDecls) {
|
|
|
|
mDecls->SetOwningRule(nullptr);
|
|
|
|
RefPtr<DeclarationBlock> decls = aDecl;
|
|
|
|
Servo_PageRule_SetStyle(rule->Raw(), decls->Raw());
|
|
|
|
mDecls = decls.forget();
|
|
|
|
mDecls->SetOwningRule(rule);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-06-05 14:39:42 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument* CSSPageRuleDeclaration::DocToUpdate() { return nullptr; }
|
|
|
|
|
|
|
|
nsDOMCSSDeclaration::ParsingEnvironment
|
|
|
|
CSSPageRuleDeclaration::GetParsingEnvironment(nsIPrincipal *
|
|
|
|
aSubjectPrincipal) const {
|
|
|
|
return GetParsingEnvironmentForRule(Rule());
|
|
|
|
}
|
|
|
|
|
|
|
|
// -- CSSPageRule --------------------------------------------------
|
|
|
|
|
|
|
|
CSSPageRule::CSSPageRule(RefPtr<RawServoPageRule> aRawRule,
|
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),
|
2018-06-05 14:39:42 +03:00
|
|
|
mRawRule(std::move(aRawRule)),
|
|
|
|
mDecls(Servo_PageRule_GetStyle(mRawRule).Consume()) {}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(CSSPageRule, css::Rule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(CSSPageRule, css::Rule)
|
|
|
|
|
|
|
|
// QueryInterface implementation for PageRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSPageRule)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(css::Rule)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(CSSPageRule)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(CSSPageRule, css::Rule)
|
|
|
|
// Keep this in sync with IsCCLeaf.
|
|
|
|
|
|
|
|
// Trace the wrapper for our declaration. This just expands out
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use
|
|
|
|
// directly because the wrapper is on the declaration, not on us.
|
|
|
|
tmp->mDecls.TraceWrapper(aCallbacks, aClosure);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(CSSPageRule, css::Rule)
|
|
|
|
// Keep this in sync with IsCCLeaf.
|
|
|
|
|
|
|
|
// Unlink the wrapper for our declaraton. This just expands out
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use
|
|
|
|
// directly because the wrapper is on the declaration, not on us.
|
|
|
|
tmp->mDecls.ReleaseWrapper(static_cast<nsISupports*>(p));
|
|
|
|
tmp->mDecls.mDecls->SetOwningRule(nullptr);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CSSPageRule, css::Rule)
|
|
|
|
// Keep this in sync with IsCCLeaf.
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
bool CSSPageRule::IsCCLeaf() const {
|
|
|
|
if (!Rule::IsCCLeaf()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !mDecls.PreservingWrapper();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CSSPageRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
|
|
|
|
// TODO Implement this!
|
|
|
|
return aMallocSizeOf(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void CSSPageRule::List(FILE * out, int32_t aIndent) const {
|
|
|
|
nsAutoCString str;
|
|
|
|
for (int32_t i = 0; i < aIndent; i++) {
|
|
|
|
str.AppendLiteral(" ");
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-06-05 14:39:42 +03:00
|
|
|
Servo_PageRule_Debug(mRawRule, &str);
|
|
|
|
fprintf_stderr(out, "%s\n", str.get());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* CSSRule implementation */
|
|
|
|
|
|
|
|
void CSSPageRule::GetCssText(nsAString & aCssText) const {
|
|
|
|
Servo_PageRule_GetCssText(mRawRule, &aCssText);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* CSSPageRule implementation */
|
|
|
|
|
|
|
|
nsICSSDeclaration* CSSPageRule::Style() { return &mDecls; }
|
|
|
|
|
2017-04-01 03:14:49 +03:00
|
|
|
JSObject* CSSPageRule::WrapObject(JSContext * aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return CSSPageRule_Binding::Wrap(aCx, this, aGivenProto);
|
2017-04-01 03:14:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|