2016-02-24 10:01:10 +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/ServoStyleSet.h"
|
|
|
|
|
2017-04-08 01:49:44 +03:00
|
|
|
#include "gfxPlatformFontList.h"
|
2016-12-01 11:19:50 +03:00
|
|
|
#include "mozilla/DocumentStyleRootIterator.h"
|
2017-06-14 02:38:16 +03:00
|
|
|
#include "mozilla/ServoBindings.h"
|
2016-07-13 23:42:47 +03:00
|
|
|
#include "mozilla/ServoRestyleManager.h"
|
2017-03-18 09:15:09 +03:00
|
|
|
#include "mozilla/dom/AnonymousContent.h"
|
2016-08-12 00:12:49 +03:00
|
|
|
#include "mozilla/dom/ChildIterator.h"
|
2017-01-01 03:10:45 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "mozilla/dom/ElementInlines.h"
|
2017-05-07 17:36:47 +03:00
|
|
|
#include "mozilla/RestyleManagerInlines.h"
|
2016-02-24 10:01:10 +03:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2016-03-18 23:14:07 +03:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2017-04-14 04:28:25 +03:00
|
|
|
#include "nsCSSRuleProcessor.h"
|
2017-04-08 01:49:44 +03:00
|
|
|
#include "nsDeviceContext.h"
|
2017-01-20 02:56:53 +03:00
|
|
|
#include "nsHTMLStyleSheet.h"
|
2016-04-29 07:01:44 +03:00
|
|
|
#include "nsIDocumentInlines.h"
|
2016-07-28 06:03:49 +03:00
|
|
|
#include "nsPrintfCString.h"
|
2017-04-26 07:00:11 +03:00
|
|
|
#include "nsSMILAnimationController.h"
|
2016-03-18 23:14:07 +03:00
|
|
|
#include "nsStyleContext.h"
|
2016-02-26 04:51:02 +03:00
|
|
|
#include "nsStyleSet.h"
|
2017-05-26 17:29:10 +03:00
|
|
|
#include "gfxUserFontSet.h"
|
2016-02-24 10:01:10 +03:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
static inline uint64_t UniqueIDForSheet(ServoStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
// Servo tracks sheets by unique ID, and it's important that a given
|
|
|
|
// ServoStyleSheet has the same unique ID throughout its lifetime.
|
|
|
|
// Instead of tracking an arbitrary unique ID for each sheet,
|
|
|
|
// we use the sheet address as a unique ID.
|
|
|
|
return reinterpret_cast<uint64_t>(aSheet);
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSet::ServoStyleSet()
|
2016-03-18 23:14:07 +03:00
|
|
|
: mPresContext(nullptr)
|
2017-03-28 10:31:41 +03:00
|
|
|
, mAllowResolveStaleStyles(false)
|
2017-04-11 10:43:14 +03:00
|
|
|
, mAuthorStyleDisabled(false)
|
2017-05-15 19:02:59 +03:00
|
|
|
, mStylistState(StylistState::NotDirty)
|
2017-05-26 17:29:10 +03:00
|
|
|
, mUserFontSetUpdateGeneration(0)
|
2017-05-16 02:30:10 +03:00
|
|
|
, mNeedsRestyleAfterEnsureUniqueInner(false)
|
2016-02-24 10:01:12 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-03-08 08:18:39 +03:00
|
|
|
ServoStyleSet::~ServoStyleSet()
|
|
|
|
{
|
2017-05-24 03:02:51 +03:00
|
|
|
for (auto& sheetArray : mSheets) {
|
|
|
|
for (auto& sheet : sheetArray) {
|
|
|
|
sheet->DropStyleSet(this);
|
|
|
|
}
|
|
|
|
}
|
2017-03-08 08:18:39 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::Init(nsPresContext* aPresContext)
|
|
|
|
{
|
2016-03-18 23:14:07 +03:00
|
|
|
mPresContext = aPresContext;
|
2017-01-04 22:52:26 +03:00
|
|
|
mRawSet.reset(Servo_StyleSet_Init(aPresContext));
|
|
|
|
|
2017-04-08 01:49:44 +03:00
|
|
|
mPresContext->DeviceContext()->InitFontCache();
|
|
|
|
|
2017-01-04 22:52:26 +03:00
|
|
|
// Now that we have an mRawSet, go ahead and notify about whatever stylesheets
|
|
|
|
// we have so far.
|
2017-05-12 22:04:55 +03:00
|
|
|
for (auto& sheetArray : mSheets) {
|
|
|
|
for (auto& sheet : sheetArray) {
|
2017-01-04 22:52:26 +03:00
|
|
|
// There's no guarantee this will create a list on the servo side whose
|
|
|
|
// ordering matches the list that would have been created had all those
|
2017-05-02 02:46:41 +03:00
|
|
|
// sheets been appended/prepended/etc after we had mRawSet. That's okay
|
|
|
|
// because Servo only needs to maintain relative ordering within a sheet
|
|
|
|
// type, which this preserves.
|
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
MOZ_ASSERT(sheet->RawSheet(), "We should only append non-null raw sheets.");
|
2017-05-02 02:46:41 +03:00
|
|
|
Servo_StyleSet_AppendStyleSheet(mRawSet.get(),
|
2017-05-12 22:04:55 +03:00
|
|
|
sheet->RawSheet(),
|
|
|
|
UniqueIDForSheet(sheet));
|
2017-01-04 22:52:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No need to Servo_StyleSet_FlushStyleSheets because we just created the
|
|
|
|
// mRawSet, so there was nothing to flush.
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoStyleSet::BeginShutdown()
|
|
|
|
{
|
2017-03-18 09:15:09 +03:00
|
|
|
nsIDocument* doc = mPresContext->Document();
|
|
|
|
|
2016-11-18 11:54:10 +03:00
|
|
|
// It's important to do this before mRawSet is released, since that will cause
|
|
|
|
// a RuleTree GC, which needs to happen after we have dropped all of the
|
|
|
|
// document's strong references to RuleNodes. We also need to do it here,
|
|
|
|
// in BeginShutdown, and not in Shutdown, since Shutdown happens after the
|
|
|
|
// frame tree has been destroyed, but before the script runners that delete
|
|
|
|
// native anonymous content (which also could be holding on the RuleNodes)
|
|
|
|
// have run. By clearing style here, before the frame tree is destroyed,
|
|
|
|
// the AllChildrenIterator will find the anonymous content.
|
|
|
|
//
|
|
|
|
// Note that this is pretty bad for performance; we should find a way to
|
|
|
|
// get by with the ServoNodeDatas being dropped as part of the document
|
|
|
|
// going away.
|
2017-03-18 09:15:09 +03:00
|
|
|
DocumentStyleRootIterator iter(doc);
|
2016-12-01 11:19:50 +03:00
|
|
|
while (Element* root = iter.GetNextStyleRoot()) {
|
2016-11-18 11:54:10 +03:00
|
|
|
ServoRestyleManager::ClearServoDataFromSubtree(root);
|
|
|
|
}
|
2017-03-18 09:15:09 +03:00
|
|
|
|
|
|
|
// We can also have some cloned canvas custom content stored in the document
|
|
|
|
// (as done in nsCanvasFrame::DestroyFrom), due to bug 1348480, when we create
|
|
|
|
// the clone (wastefully) during PresShell destruction. Clear data from that
|
|
|
|
// clone.
|
|
|
|
for (RefPtr<AnonymousContent>& ac : doc->GetAnonymousContents()) {
|
|
|
|
ServoRestyleManager::ClearServoDataFromSubtree(ac->GetContentNode());
|
|
|
|
}
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoStyleSet::Shutdown()
|
|
|
|
{
|
2017-03-08 08:18:39 +03:00
|
|
|
// Make sure we drop our cached style contexts before the presshell arena
|
|
|
|
// starts going away.
|
|
|
|
ClearNonInheritingStyleContexts();
|
2016-01-27 05:02:04 +03:00
|
|
|
mRawSet = nullptr;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
2017-05-24 03:53:08 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::InvalidateStyleForCSSRuleChanges()
|
|
|
|
{
|
2017-05-25 20:50:03 +03:00
|
|
|
MOZ_ASSERT(StylistNeedsUpdate());
|
2017-05-26 18:46:31 +03:00
|
|
|
mPresContext->RestyleManager()->AsServo()->PostRestyleEventForCSSRuleChanges();
|
2017-05-24 03:53:08 +03:00
|
|
|
}
|
|
|
|
|
2017-06-02 18:55:55 +03:00
|
|
|
bool
|
|
|
|
ServoStyleSet::MediumFeaturesChanged() const
|
|
|
|
{
|
|
|
|
return Servo_StyleSet_MediumFeaturesChanged(mRawSet.get());
|
|
|
|
}
|
|
|
|
|
2017-04-06 05:22:36 +03:00
|
|
|
size_t
|
|
|
|
ServoStyleSet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mRawSet
|
|
|
|
// - mSheets
|
|
|
|
// - mNonInheritingStyleContexts
|
|
|
|
//
|
|
|
|
// The following members are not measured:
|
|
|
|
// - mPresContext, because it a non-owning pointer
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
bool
|
|
|
|
ServoStyleSet::GetAuthorStyleDisabled() const
|
|
|
|
{
|
2017-04-11 10:43:14 +03:00
|
|
|
return mAuthorStyleDisabled;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ServoStyleSet::SetAuthorStyleDisabled(bool aStyleDisabled)
|
|
|
|
{
|
2017-04-11 10:43:14 +03:00
|
|
|
if (mAuthorStyleDisabled == aStyleDisabled) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mAuthorStyleDisabled = aStyleDisabled;
|
2017-05-25 20:50:03 +03:00
|
|
|
ForceAllStyleDirty();
|
2017-04-11 10:43:14 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoStyleSet::BeginUpdate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ServoStyleSet::EndUpdate()
|
|
|
|
{
|
2016-02-24 10:01:12 +03:00
|
|
|
return NS_OK;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
ServoStyleSet::ResolveStyleFor(Element* aElement,
|
2016-11-02 09:11:24 +03:00
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
LazyComputeBehavior aMayCompute)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2016-04-29 07:04:16 +03:00
|
|
|
return GetContext(aElement, aParentContext, nullptr,
|
2017-01-06 00:12:53 +03:00
|
|
|
CSSPseudoElementType::NotPseudo, aMayCompute);
|
2016-04-29 07:04:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
ServoStyleSet::GetContext(nsIContent* aContent,
|
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
nsIAtom* aPseudoTag,
|
2016-11-02 09:11:24 +03:00
|
|
|
CSSPseudoElementType aPseudoType,
|
|
|
|
LazyComputeBehavior aMayCompute)
|
2016-04-29 07:04:16 +03:00
|
|
|
{
|
2016-11-02 09:11:24 +03:00
|
|
|
MOZ_ASSERT(aContent->IsElement());
|
|
|
|
Element* element = aContent->AsElement();
|
2016-12-28 10:49:12 +03:00
|
|
|
|
|
|
|
RefPtr<ServoComputedValues> computedValues;
|
|
|
|
if (aMayCompute == LazyComputeBehavior::Allow) {
|
2017-04-12 05:05:26 +03:00
|
|
|
PreTraverseSync();
|
2017-05-14 19:39:22 +03:00
|
|
|
computedValues =
|
|
|
|
ResolveStyleLazily(element, CSSPseudoElementType::NotPseudo);
|
2016-12-28 10:49:12 +03:00
|
|
|
} else {
|
2017-01-06 00:12:53 +03:00
|
|
|
computedValues = ResolveServoStyle(element);
|
2016-12-28 10:49:12 +03:00
|
|
|
}
|
|
|
|
|
2016-03-18 23:14:07 +03:00
|
|
|
MOZ_ASSERT(computedValues);
|
2017-01-29 06:59:00 +03:00
|
|
|
return GetContext(computedValues.forget(), aParentContext, aPseudoTag, aPseudoType,
|
|
|
|
element);
|
2016-04-29 03:56:37 +03:00
|
|
|
}
|
2016-03-18 23:14:07 +03:00
|
|
|
|
2016-04-29 03:56:37 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
ServoStyleSet::GetContext(already_AddRefed<ServoComputedValues> aComputedValues,
|
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
nsIAtom* aPseudoTag,
|
2017-01-29 06:59:00 +03:00
|
|
|
CSSPseudoElementType aPseudoType,
|
|
|
|
Element* aElementForAnimation)
|
2016-04-29 03:56:37 +03:00
|
|
|
{
|
2017-05-10 23:00:42 +03:00
|
|
|
bool isLink = false;
|
|
|
|
bool isVisitedLink = false;
|
|
|
|
// If we need visited styles for callers where `aElementForAnimation` is null,
|
|
|
|
// we can precompute these and pass them as flags, similar to nsStyleSet.cpp.
|
|
|
|
if (aElementForAnimation) {
|
|
|
|
isLink = nsCSSRuleProcessor::IsLink(aElementForAnimation);
|
|
|
|
isVisitedLink = nsCSSRuleProcessor::GetContentState(aElementForAnimation)
|
|
|
|
.HasState(NS_EVENT_STATE_VISITED);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ServoComputedValues> computedValues = Move(aComputedValues);
|
|
|
|
RefPtr<ServoComputedValues> visitedComputedValues =
|
|
|
|
Servo_ComputedValues_GetVisitedStyle(computedValues).Consume();
|
|
|
|
|
|
|
|
// If `visitedComputedValues` is non-null, then there was a relevant link and
|
|
|
|
// visited styles were computed. This corresponds to the cases where Gecko's
|
|
|
|
// style system produces `aVisitedRuleNode`.
|
|
|
|
// Set up `parentIfVisited` depending on whether our parent context has a
|
|
|
|
// a visited style. If it doesn't but we do have visited styles, use the
|
|
|
|
// regular parent context for visited.
|
|
|
|
nsStyleContext *parentIfVisited =
|
|
|
|
aParentContext ? aParentContext->GetStyleIfVisited() : nullptr;
|
|
|
|
if (!parentIfVisited) {
|
|
|
|
if (visitedComputedValues) {
|
|
|
|
parentIfVisited = aParentContext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The true visited state of the relevant link is used to decided whether
|
|
|
|
// visited styles should be consulted for all visited dependent properties.
|
|
|
|
bool relevantLinkVisited = isLink ? isVisitedLink :
|
|
|
|
(aParentContext && aParentContext->RelevantLinkVisited());
|
2016-03-18 23:14:07 +03:00
|
|
|
|
2017-05-10 23:00:42 +03:00
|
|
|
RefPtr<nsStyleContext> result =
|
|
|
|
NS_NewStyleContext(aParentContext, mPresContext, aPseudoTag, aPseudoType,
|
|
|
|
computedValues.forget());
|
|
|
|
|
|
|
|
if (visitedComputedValues) {
|
|
|
|
RefPtr<nsStyleContext> resultIfVisited =
|
|
|
|
NS_NewStyleContext(parentIfVisited, mPresContext, aPseudoTag, aPseudoType,
|
|
|
|
visitedComputedValues.forget());
|
|
|
|
resultIfVisited->SetIsStyleIfVisited();
|
|
|
|
result->SetStyleIfVisited(resultIfVisited.forget());
|
|
|
|
|
|
|
|
if (relevantLinkVisited) {
|
|
|
|
result->AddStyleBit(NS_STYLE_RELEVANT_LINK_VISITED);
|
|
|
|
}
|
|
|
|
}
|
2017-03-26 23:53:34 +03:00
|
|
|
|
|
|
|
// Set the body color on the pres context. See nsStyleSet::GetContext
|
|
|
|
if (aElementForAnimation &&
|
|
|
|
aElementForAnimation->IsHTMLElement(nsGkAtoms::body) &&
|
|
|
|
aPseudoType == CSSPseudoElementType::NotPseudo &&
|
|
|
|
mPresContext->CompatibilityMode() == eCompatibility_NavQuirks) {
|
|
|
|
nsIDocument* doc = aElementForAnimation->GetUncomposedDoc();
|
|
|
|
if (doc && doc->GetBodyElement() == aElementForAnimation) {
|
|
|
|
// Update the prescontext's body color
|
|
|
|
mPresContext->SetBodyTextColor(result->StyleColor()->mColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result.forget();
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
2017-05-07 17:36:47 +03:00
|
|
|
const ServoElementSnapshotTable&
|
|
|
|
ServoStyleSet::Snapshots()
|
|
|
|
{
|
|
|
|
return mPresContext->RestyleManager()->AsServo()->Snapshots();
|
|
|
|
}
|
|
|
|
|
2017-01-20 02:56:53 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::ResolveMappedAttrDeclarationBlocks()
|
|
|
|
{
|
|
|
|
if (nsHTMLStyleSheet* sheet = mPresContext->Document()->GetAttributeStyleSheet()) {
|
2017-04-08 17:42:43 +03:00
|
|
|
sheet->CalculateMappedServoDeclarations(mPresContext);
|
2017-01-20 02:56:53 +03:00
|
|
|
}
|
2017-02-23 04:19:04 +03:00
|
|
|
|
|
|
|
mPresContext->Document()->ResolveScheduledSVGPresAttrs();
|
2017-01-20 02:56:53 +03:00
|
|
|
}
|
|
|
|
|
2017-03-08 23:20:17 +03:00
|
|
|
void
|
2017-03-17 00:10:22 +03:00
|
|
|
ServoStyleSet::PreTraverseSync()
|
2017-03-08 23:20:17 +03:00
|
|
|
{
|
2017-01-20 02:56:53 +03:00
|
|
|
ResolveMappedAttrDeclarationBlocks();
|
2017-02-02 22:48:28 +03:00
|
|
|
|
2017-04-14 04:28:25 +03:00
|
|
|
nsCSSRuleProcessor::InitSystemMetrics();
|
|
|
|
|
2017-03-17 00:10:22 +03:00
|
|
|
// This is lazily computed and pseudo matching needs to access
|
|
|
|
// it so force computation early.
|
|
|
|
mPresContext->Document()->GetDocumentState();
|
2017-04-08 01:49:44 +03:00
|
|
|
|
|
|
|
// Ensure that the @font-face data is not stale
|
2017-05-26 17:29:10 +03:00
|
|
|
if (gfxUserFontSet* userFontSet = mPresContext->Document()->GetUserFontSet()) {
|
|
|
|
uint64_t generation = userFontSet->GetGeneration();
|
|
|
|
if (generation != mUserFontSetUpdateGeneration) {
|
|
|
|
mPresContext->DeviceContext()->UpdateFontCacheUserFonts(userFontSet);
|
|
|
|
mUserFontSetUpdateGeneration = generation;
|
|
|
|
}
|
|
|
|
}
|
2017-05-15 19:02:59 +03:00
|
|
|
|
|
|
|
UpdateStylistIfNeeded();
|
2017-05-20 22:47:36 +03:00
|
|
|
mPresContext->CacheAllLangs();
|
2017-03-17 00:10:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-05-19 11:16:41 +03:00
|
|
|
ServoStyleSet::PreTraverse(Element* aRoot,
|
|
|
|
EffectCompositor::AnimationRestyleType aRestyleType)
|
2017-03-17 00:10:22 +03:00
|
|
|
{
|
|
|
|
PreTraverseSync();
|
|
|
|
|
2017-03-08 23:20:17 +03:00
|
|
|
// Process animation stuff that we should avoid doing during the parallel
|
|
|
|
// traversal.
|
2017-04-26 07:00:11 +03:00
|
|
|
nsSMILAnimationController* smilController =
|
|
|
|
mPresContext->Document()->GetAnimationController();
|
2017-04-04 14:34:30 +03:00
|
|
|
if (aRoot) {
|
2017-05-19 11:16:41 +03:00
|
|
|
mPresContext->EffectCompositor()
|
|
|
|
->PreTraverseInSubtree(aRoot, aRestyleType);
|
2017-04-26 07:00:11 +03:00
|
|
|
if (smilController) {
|
|
|
|
smilController->PreTraverseInSubtree(aRoot);
|
|
|
|
}
|
2017-04-04 14:34:30 +03:00
|
|
|
} else {
|
2017-05-19 11:16:41 +03:00
|
|
|
mPresContext->EffectCompositor()->PreTraverse(aRestyleType);
|
2017-04-26 07:00:11 +03:00
|
|
|
if (smilController) {
|
|
|
|
smilController->PreTraverse();
|
|
|
|
}
|
2017-04-04 14:34:30 +03:00
|
|
|
}
|
2017-03-08 23:20:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-05-07 17:36:47 +03:00
|
|
|
ServoStyleSet::PrepareAndTraverseSubtree(
|
|
|
|
RawGeckoElementBorrowed aRoot,
|
|
|
|
TraversalRootBehavior aRootBehavior,
|
|
|
|
TraversalRestyleBehavior aRestyleBehavior)
|
2017-03-08 23:20:17 +03:00
|
|
|
{
|
2017-02-03 01:03:46 +03:00
|
|
|
// Get the Document's root element to ensure that the cache is valid before
|
|
|
|
// calling into the (potentially-parallel) Servo traversal, where a cache hit
|
|
|
|
// is necessary to avoid a data race when updating the cache.
|
|
|
|
mozilla::Unused << aRoot->OwnerDoc()->GetRootElement();
|
|
|
|
|
2017-05-15 19:02:59 +03:00
|
|
|
MOZ_ASSERT(!StylistNeedsUpdate());
|
2017-04-30 09:41:11 +03:00
|
|
|
AutoSetInServoTraversal guard(this);
|
2017-03-24 01:21:18 +03:00
|
|
|
|
2017-05-07 17:36:47 +03:00
|
|
|
const SnapshotTable& snapshots = Snapshots();
|
|
|
|
|
2017-03-24 01:21:18 +03:00
|
|
|
bool isInitial = !aRoot->HasServoData();
|
2017-04-04 14:34:30 +03:00
|
|
|
bool forReconstruct =
|
|
|
|
aRestyleBehavior == TraversalRestyleBehavior::ForReconstruct;
|
2017-05-19 11:16:41 +03:00
|
|
|
bool forAnimationOnly =
|
|
|
|
aRestyleBehavior == TraversalRestyleBehavior::ForAnimationOnly;
|
2017-06-13 06:51:15 +03:00
|
|
|
#ifdef DEBUG
|
2017-06-11 14:11:08 +03:00
|
|
|
bool forNewlyBoundElement =
|
|
|
|
aRestyleBehavior == TraversalRestyleBehavior::ForNewlyBoundElement;
|
2017-06-13 06:51:15 +03:00
|
|
|
#endif
|
2017-05-07 17:36:47 +03:00
|
|
|
bool postTraversalRequired = Servo_TraverseSubtree(
|
|
|
|
aRoot, mRawSet.get(), &snapshots, aRootBehavior, aRestyleBehavior);
|
2017-06-11 14:11:08 +03:00
|
|
|
MOZ_ASSERT(!(isInitial || forReconstruct || forNewlyBoundElement) ||
|
|
|
|
!postTraversalRequired);
|
2017-04-04 14:34:30 +03:00
|
|
|
|
2017-05-19 11:16:41 +03:00
|
|
|
// Don't need to trigger a second traversal if this restyle only needs
|
|
|
|
// animation-only restyle.
|
|
|
|
if (forAnimationOnly) {
|
|
|
|
return postTraversalRequired;
|
|
|
|
}
|
|
|
|
|
2017-04-04 14:34:30 +03:00
|
|
|
auto root = const_cast<Element*>(aRoot);
|
2017-03-10 05:53:19 +03:00
|
|
|
|
|
|
|
// If there are still animation restyles needed, trigger a second traversal to
|
2017-04-17 09:22:28 +03:00
|
|
|
// update CSS animations or transitions' styles.
|
2017-04-26 07:00:11 +03:00
|
|
|
//
|
|
|
|
// We don't need to do this for SMIL since SMIL only updates its animation
|
|
|
|
// values once at the begin of a tick. As a result, even if the previous
|
|
|
|
// traversal caused, for example, the font-size to change, the SMIL style
|
|
|
|
// won't be updated until the next tick anyway.
|
2017-04-04 14:34:30 +03:00
|
|
|
EffectCompositor* compositor = mPresContext->EffectCompositor();
|
2017-05-19 11:16:41 +03:00
|
|
|
EffectCompositor::AnimationRestyleType restyleType =
|
|
|
|
EffectCompositor::AnimationRestyleType::Throttled;
|
|
|
|
if (forReconstruct ? compositor->PreTraverseInSubtree(root, restyleType)
|
|
|
|
: compositor->PreTraverse(restyleType)) {
|
2017-05-07 17:36:47 +03:00
|
|
|
if (Servo_TraverseSubtree(
|
|
|
|
aRoot, mRawSet.get(), &snapshots, aRootBehavior, aRestyleBehavior)) {
|
2017-04-04 14:34:30 +03:00
|
|
|
MOZ_ASSERT(!forReconstruct);
|
2017-03-24 01:21:18 +03:00
|
|
|
if (isInitial) {
|
|
|
|
// We're doing initial styling, and the additional animation
|
|
|
|
// traversal changed the styles that were set by the first traversal.
|
|
|
|
// This would normally require a post-traversal to update the style
|
|
|
|
// contexts, and the DOM now has dirty descendant bits and RestyleData
|
|
|
|
// in expectation of that post-traversal. But since this is actually
|
|
|
|
// the initial styling, there are no style contexts to update and no
|
|
|
|
// frames to apply the change hints to, so we don't need to do that
|
|
|
|
// post-traversal. Instead, just drop this state and tell the caller
|
|
|
|
// that no post-traversal is required.
|
|
|
|
MOZ_ASSERT(!postTraversalRequired);
|
2017-04-04 14:34:30 +03:00
|
|
|
ServoRestyleManager::ClearRestyleStateFromSubtree(root);
|
2017-03-24 01:21:18 +03:00
|
|
|
} else {
|
|
|
|
postTraversalRequired = true;
|
|
|
|
}
|
|
|
|
}
|
2017-03-10 05:53:19 +03:00
|
|
|
}
|
|
|
|
|
2017-02-10 05:42:30 +03:00
|
|
|
return postTraversalRequired;
|
2017-01-20 02:56:53 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2016-04-29 07:01:44 +03:00
|
|
|
ServoStyleSet::ResolveStyleForText(nsIContent* aTextNode,
|
|
|
|
nsStyleContext* aParentContext)
|
|
|
|
{
|
2016-04-29 07:04:16 +03:00
|
|
|
MOZ_ASSERT(aTextNode && aTextNode->IsNodeOfType(nsINode::eTEXT));
|
2016-08-12 21:30:29 +03:00
|
|
|
MOZ_ASSERT(aTextNode->GetParent());
|
2016-10-26 02:27:08 +03:00
|
|
|
MOZ_ASSERT(aParentContext);
|
|
|
|
|
|
|
|
// Gecko expects text node style contexts to be like elements that match no
|
|
|
|
// rules: inherit the inherit structs, reset the reset structs. This is cheap
|
|
|
|
// enough to do on the main thread, which means that the parallel style system
|
|
|
|
// can avoid worrying about text nodes.
|
|
|
|
const ServoComputedValues* parentComputedValues =
|
2017-06-11 08:27:45 +03:00
|
|
|
aParentContext->ComputedValues();
|
2016-10-26 02:27:08 +03:00
|
|
|
RefPtr<ServoComputedValues> computedValues =
|
2017-04-28 14:10:00 +03:00
|
|
|
Servo_ComputedValues_Inherit(mRawSet.get(),
|
|
|
|
parentComputedValues,
|
|
|
|
InheritTarget::Text).Consume();
|
2016-08-12 21:30:29 +03:00
|
|
|
|
|
|
|
return GetContext(computedValues.forget(), aParentContext,
|
2017-03-09 07:41:04 +03:00
|
|
|
nsCSSAnonBoxes::mozText,
|
|
|
|
CSSPseudoElementType::InheritingAnonBox,
|
2017-01-29 06:59:00 +03:00
|
|
|
nullptr);
|
2016-04-29 07:01:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsStyleContext>
|
2017-03-08 08:18:32 +03:00
|
|
|
ServoStyleSet::ResolveStyleForFirstLetterContinuation(nsStyleContext* aParentContext)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2017-04-28 14:10:00 +03:00
|
|
|
const ServoComputedValues* parent =
|
2017-06-11 08:27:45 +03:00
|
|
|
aParentContext->ComputedValues();
|
2017-03-08 08:18:32 +03:00
|
|
|
RefPtr<ServoComputedValues> computedValues =
|
2017-04-28 14:10:00 +03:00
|
|
|
Servo_ComputedValues_Inherit(mRawSet.get(),
|
|
|
|
parent,
|
|
|
|
InheritTarget::FirstLetterContinuation)
|
|
|
|
.Consume();
|
2017-03-08 08:18:32 +03:00
|
|
|
MOZ_ASSERT(computedValues);
|
|
|
|
|
|
|
|
return GetContext(computedValues.forget(), aParentContext,
|
|
|
|
nsCSSAnonBoxes::firstLetterContinuation,
|
2017-03-09 07:41:04 +03:00
|
|
|
CSSPseudoElementType::InheritingAnonBox,
|
2017-03-08 08:18:32 +03:00
|
|
|
nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsStyleContext>
|
2017-03-08 08:18:40 +03:00
|
|
|
ServoStyleSet::ResolveStyleForPlaceholder()
|
2017-03-08 08:18:32 +03:00
|
|
|
{
|
2017-03-08 08:18:40 +03:00
|
|
|
RefPtr<nsStyleContext>& cache =
|
2017-03-09 07:39:45 +03:00
|
|
|
mNonInheritingStyleContexts[nsCSSAnonBoxes::NonInheriting::oofPlaceholder];
|
2017-03-08 08:18:40 +03:00
|
|
|
if (cache) {
|
|
|
|
RefPtr<nsStyleContext> retval = cache;
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
2016-08-12 21:30:29 +03:00
|
|
|
RefPtr<ServoComputedValues> computedValues =
|
2017-04-28 14:10:00 +03:00
|
|
|
Servo_ComputedValues_Inherit(mRawSet.get(),
|
|
|
|
nullptr,
|
|
|
|
InheritTarget::PlaceholderFrame)
|
|
|
|
.Consume();
|
2016-05-06 01:32:00 +03:00
|
|
|
MOZ_ASSERT(computedValues);
|
|
|
|
|
2017-03-08 08:18:40 +03:00
|
|
|
RefPtr<nsStyleContext> retval =
|
|
|
|
GetContext(computedValues.forget(), nullptr,
|
|
|
|
nsCSSAnonBoxes::oofPlaceholder,
|
2017-03-09 07:41:04 +03:00
|
|
|
CSSPseudoElementType::NonInheritingAnonBox,
|
2017-03-08 08:18:40 +03:00
|
|
|
nullptr);
|
|
|
|
cache = retval;
|
|
|
|
return retval.forget();
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsStyleContext>
|
2016-12-22 04:58:38 +03:00
|
|
|
ServoStyleSet::ResolvePseudoElementStyle(Element* aOriginatingElement,
|
2016-02-24 10:01:10 +03:00
|
|
|
CSSPseudoElementType aType,
|
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
Element* aPseudoElement)
|
|
|
|
{
|
2017-05-15 19:02:59 +03:00
|
|
|
UpdateStylistIfNeeded();
|
2017-05-10 20:13:39 +03:00
|
|
|
|
2016-12-22 04:58:38 +03:00
|
|
|
// NB: We ignore aParentContext, on the assumption that pseudo element styles
|
|
|
|
// should just inherit from aOriginatingElement's primary style, which Servo
|
|
|
|
// already knows.
|
2016-04-29 03:56:37 +03:00
|
|
|
MOZ_ASSERT(aType < CSSPseudoElementType::Count);
|
|
|
|
|
2017-05-13 20:29:14 +03:00
|
|
|
RefPtr<ServoComputedValues> computedValues;
|
|
|
|
if (aPseudoElement) {
|
|
|
|
MOZ_ASSERT(aType == aPseudoElement->GetPseudoElementType());
|
|
|
|
computedValues = Servo_ResolveStyle(aPseudoElement, mRawSet.get(),
|
|
|
|
mAllowResolveStaleStyles).Consume();
|
|
|
|
} else {
|
|
|
|
computedValues =
|
|
|
|
Servo_ResolvePseudoStyle(aOriginatingElement,
|
2017-05-14 19:39:22 +03:00
|
|
|
aType,
|
2017-05-13 20:29:14 +03:00
|
|
|
/* is_probe = */ false,
|
|
|
|
mRawSet.get()).Consume();
|
|
|
|
}
|
|
|
|
|
2016-04-29 03:56:37 +03:00
|
|
|
MOZ_ASSERT(computedValues);
|
|
|
|
|
2017-01-29 06:59:00 +03:00
|
|
|
bool isBeforeOrAfter = aType == CSSPseudoElementType::before ||
|
|
|
|
aType == CSSPseudoElementType::after;
|
2017-05-14 19:39:22 +03:00
|
|
|
|
|
|
|
nsIAtom* pseudoTag = nsCSSPseudoElements::GetPseudoAtom(aType);
|
2017-01-29 06:59:00 +03:00
|
|
|
return GetContext(computedValues.forget(), aParentContext, pseudoTag, aType,
|
|
|
|
isBeforeOrAfter ? aOriginatingElement : nullptr);
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
2016-12-28 10:49:12 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2017-04-15 01:37:34 +03:00
|
|
|
ServoStyleSet::ResolveTransientStyle(Element* aElement,
|
|
|
|
nsIAtom* aPseudoTag,
|
2017-05-24 09:37:47 +03:00
|
|
|
CSSPseudoElementType aPseudoType,
|
|
|
|
StyleRuleInclusion aRuleInclusion)
|
2016-12-28 10:49:12 +03:00
|
|
|
{
|
2017-04-15 01:37:34 +03:00
|
|
|
RefPtr<ServoComputedValues> computedValues =
|
2017-05-24 09:37:47 +03:00
|
|
|
ResolveTransientServoStyle(aElement, aPseudoType, aRuleInclusion);
|
2017-04-15 01:37:34 +03:00
|
|
|
|
2017-04-15 01:37:34 +03:00
|
|
|
return GetContext(computedValues.forget(),
|
|
|
|
nullptr,
|
|
|
|
aPseudoTag,
|
|
|
|
aPseudoType, nullptr);
|
|
|
|
}
|
2016-12-28 10:49:12 +03:00
|
|
|
|
2017-04-15 01:37:34 +03:00
|
|
|
already_AddRefed<ServoComputedValues>
|
2017-05-24 09:37:47 +03:00
|
|
|
ServoStyleSet::ResolveTransientServoStyle(
|
|
|
|
Element* aElement,
|
|
|
|
CSSPseudoElementType aPseudoType,
|
|
|
|
StyleRuleInclusion aRuleInclusion)
|
2017-04-15 01:37:34 +03:00
|
|
|
{
|
|
|
|
PreTraverseSync();
|
2017-05-24 09:37:47 +03:00
|
|
|
return ResolveStyleLazily(aElement, aPseudoType, aRuleInclusion);
|
2016-12-28 10:49:12 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2017-03-09 07:50:28 +03:00
|
|
|
ServoStyleSet::ResolveInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag,
|
2017-04-24 11:25:37 +03:00
|
|
|
nsStyleContext* aParentContext)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2017-03-09 07:41:04 +03:00
|
|
|
MOZ_ASSERT(nsCSSAnonBoxes::IsAnonBox(aPseudoTag) &&
|
|
|
|
!nsCSSAnonBoxes::IsNonInheritingAnonBox(aPseudoTag));
|
2016-02-26 04:51:02 +03:00
|
|
|
|
2017-05-15 19:02:59 +03:00
|
|
|
UpdateStylistIfNeeded();
|
2017-05-10 20:13:39 +03:00
|
|
|
|
2017-04-24 11:25:37 +03:00
|
|
|
bool skipFixup =
|
|
|
|
nsCSSAnonBoxes::AnonBoxSkipsParentDisplayBasedStyleFixup(aPseudoTag);
|
2016-03-18 23:14:07 +03:00
|
|
|
|
2016-10-18 07:29:03 +03:00
|
|
|
const ServoComputedValues* parentStyle =
|
2017-06-11 08:27:45 +03:00
|
|
|
aParentContext ? aParentContext->ComputedValues()
|
2016-03-18 23:14:07 +03:00
|
|
|
: nullptr;
|
|
|
|
RefPtr<ServoComputedValues> computedValues =
|
2017-03-13 19:53:45 +03:00
|
|
|
Servo_ComputedValues_GetForAnonymousBox(parentStyle, aPseudoTag, skipFixup,
|
2016-08-23 06:14:27 +03:00
|
|
|
mRawSet.get()).Consume();
|
2016-07-28 06:03:49 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (!computedValues) {
|
|
|
|
nsString pseudo;
|
|
|
|
aPseudoTag->ToString(pseudo);
|
|
|
|
NS_ERROR(nsPrintfCString("stylo: could not get anon-box: %s",
|
|
|
|
NS_ConvertUTF16toUTF8(pseudo).get()).get());
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
#endif
|
2016-03-18 23:14:07 +03:00
|
|
|
|
2017-04-25 07:52:51 +03:00
|
|
|
return GetContext(computedValues.forget(), aParentContext, aPseudoTag,
|
|
|
|
CSSPseudoElementType::InheritingAnonBox, nullptr);
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 07:41:04 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
|
|
|
ServoStyleSet::ResolveNonInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(nsCSSAnonBoxes::IsAnonBox(aPseudoTag) &&
|
|
|
|
nsCSSAnonBoxes::IsNonInheritingAnonBox(aPseudoTag));
|
|
|
|
MOZ_ASSERT(aPseudoTag != nsCSSAnonBoxes::pageContent,
|
|
|
|
"If nsCSSAnonBoxes::pageContent ends up non-inheriting, check "
|
|
|
|
"whether we need to do anything to move the "
|
2017-03-09 07:50:28 +03:00
|
|
|
"@page handling from ResolveInheritingAnonymousBoxStyle to "
|
2017-03-09 07:41:04 +03:00
|
|
|
"ResolveNonInheritingAnonymousBoxStyle");
|
|
|
|
|
|
|
|
nsCSSAnonBoxes::NonInheriting type =
|
|
|
|
nsCSSAnonBoxes::NonInheritingTypeForPseudoTag(aPseudoTag);
|
|
|
|
RefPtr<nsStyleContext>& cache = mNonInheritingStyleContexts[type];
|
|
|
|
if (cache) {
|
|
|
|
RefPtr<nsStyleContext> retval = cache;
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
2017-05-15 19:02:59 +03:00
|
|
|
UpdateStylistIfNeeded();
|
2017-05-10 20:13:39 +03:00
|
|
|
|
2017-03-13 19:53:45 +03:00
|
|
|
// We always want to skip parent-based display fixup here. It never makes
|
2017-04-24 11:25:37 +03:00
|
|
|
// sense for non-inheriting anonymous boxes. (Static assertions in
|
|
|
|
// nsCSSAnonBoxes.cpp ensure that all non-inheriting non-anonymous boxes
|
|
|
|
// are indeed annotated as skipping this fixup.)
|
2017-03-13 19:53:45 +03:00
|
|
|
MOZ_ASSERT(!nsCSSAnonBoxes::IsNonInheritingAnonBox(nsCSSAnonBoxes::viewport),
|
|
|
|
"viewport needs fixup to handle blockifying it");
|
2017-03-09 07:41:04 +03:00
|
|
|
RefPtr<ServoComputedValues> computedValues =
|
2017-03-13 19:53:45 +03:00
|
|
|
Servo_ComputedValues_GetForAnonymousBox(nullptr, aPseudoTag, true,
|
2017-03-09 07:41:04 +03:00
|
|
|
mRawSet.get()).Consume();
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (!computedValues) {
|
|
|
|
nsString pseudo;
|
|
|
|
aPseudoTag->ToString(pseudo);
|
|
|
|
NS_ERROR(nsPrintfCString("stylo: could not get anon-box: %s",
|
|
|
|
NS_ConvertUTF16toUTF8(pseudo).get()).get());
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
RefPtr<nsStyleContext> retval =
|
|
|
|
GetContext(computedValues.forget(), nullptr, aPseudoTag,
|
|
|
|
CSSPseudoElementType::NonInheritingAnonBox, nullptr);
|
|
|
|
cache = retval;
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:10 +03:00
|
|
|
// manage the set of style sheets in the style set
|
|
|
|
nsresult
|
|
|
|
ServoStyleSet::AppendStyleSheet(SheetType aType,
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSheet* aSheet)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2016-02-26 04:51:02 +03:00
|
|
|
MOZ_ASSERT(aSheet);
|
|
|
|
MOZ_ASSERT(aSheet->IsApplicable());
|
|
|
|
MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
|
2017-02-15 23:25:21 +03:00
|
|
|
MOZ_ASSERT(aSheet->RawSheet(), "Raw sheet should be in place before insertion.");
|
2017-05-02 02:46:41 +03:00
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
RemoveSheetOfType(aType, aSheet);
|
|
|
|
AppendSheetOfType(aType, aSheet);
|
2016-02-26 04:51:02 +03:00
|
|
|
|
2017-01-04 22:52:26 +03:00
|
|
|
if (mRawSet) {
|
|
|
|
// Maintain a mirrored list of sheets on the servo side.
|
2017-05-12 22:04:55 +03:00
|
|
|
// Servo will remove aSheet from its original position as part of the call
|
|
|
|
// to Servo_StyleSet_AppendStyleSheet.
|
2017-05-02 02:46:41 +03:00
|
|
|
Servo_StyleSet_AppendStyleSheet(mRawSet.get(),
|
|
|
|
aSheet->RawSheet(),
|
2017-05-12 22:04:55 +03:00
|
|
|
UniqueIDForSheet(aSheet));
|
2017-05-15 19:02:59 +03:00
|
|
|
SetStylistStyleSheetsDirty();
|
2017-01-04 22:52:26 +03:00
|
|
|
}
|
2016-02-26 05:57:42 +03:00
|
|
|
|
2016-02-26 04:51:02 +03:00
|
|
|
return NS_OK;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ServoStyleSet::PrependStyleSheet(SheetType aType,
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSheet* aSheet)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2016-02-26 04:51:02 +03:00
|
|
|
MOZ_ASSERT(aSheet);
|
|
|
|
MOZ_ASSERT(aSheet->IsApplicable());
|
|
|
|
MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
|
2017-02-15 23:25:21 +03:00
|
|
|
MOZ_ASSERT(aSheet->RawSheet(), "Raw sheet should be in place before insertion.");
|
2017-05-02 02:46:41 +03:00
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
RemoveSheetOfType(aType, aSheet);
|
|
|
|
PrependSheetOfType(aType, aSheet);
|
2016-02-26 04:51:02 +03:00
|
|
|
|
2017-01-04 22:52:26 +03:00
|
|
|
if (mRawSet) {
|
|
|
|
// Maintain a mirrored list of sheets on the servo side.
|
2017-05-12 22:04:55 +03:00
|
|
|
// Servo will remove aSheet from its original position as part of the call
|
|
|
|
// to Servo_StyleSet_PrependStyleSheet.
|
2017-05-02 02:46:41 +03:00
|
|
|
Servo_StyleSet_PrependStyleSheet(mRawSet.get(),
|
|
|
|
aSheet->RawSheet(),
|
2017-05-12 22:04:55 +03:00
|
|
|
UniqueIDForSheet(aSheet));
|
2017-05-15 19:02:59 +03:00
|
|
|
SetStylistStyleSheetsDirty();
|
2017-01-04 22:52:26 +03:00
|
|
|
}
|
2016-02-26 05:57:42 +03:00
|
|
|
|
2016-02-26 04:51:02 +03:00
|
|
|
return NS_OK;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ServoStyleSet::RemoveStyleSheet(SheetType aType,
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSheet* aSheet)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2016-02-26 05:57:42 +03:00
|
|
|
MOZ_ASSERT(aSheet);
|
|
|
|
MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
|
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
RemoveSheetOfType(aType, aSheet);
|
|
|
|
if (mRawSet) {
|
2017-01-04 22:52:26 +03:00
|
|
|
// Maintain a mirrored list of sheets on the servo side.
|
2017-05-12 22:04:55 +03:00
|
|
|
Servo_StyleSet_RemoveStyleSheet(mRawSet.get(), UniqueIDForSheet(aSheet));
|
2017-05-15 19:02:59 +03:00
|
|
|
SetStylistStyleSheetsDirty();
|
2017-01-04 22:52:26 +03:00
|
|
|
}
|
2016-02-26 05:57:42 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ServoStyleSet::ReplaceSheets(SheetType aType,
|
2016-02-24 10:01:12 +03:00
|
|
|
const nsTArray<RefPtr<ServoStyleSheet>>& aNewSheets)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2016-08-03 07:08:01 +03:00
|
|
|
// Gecko uses a two-dimensional array keyed by sheet type, whereas Servo
|
|
|
|
// stores a flattened list. This makes ReplaceSheets a pretty clunky thing
|
|
|
|
// to express. If the need ever arises, we can easily make this more efficent,
|
|
|
|
// probably by aligning the representations better between engines.
|
|
|
|
|
2017-05-15 19:02:59 +03:00
|
|
|
SetStylistStyleSheetsDirty();
|
2017-05-10 20:13:39 +03:00
|
|
|
|
2017-05-02 02:46:41 +03:00
|
|
|
// Remove all the existing sheets first.
|
2017-05-24 03:02:51 +03:00
|
|
|
for (const auto& sheet : mSheets[aType]) {
|
|
|
|
sheet->DropStyleSet(this);
|
|
|
|
if (mRawSet) {
|
2017-05-12 22:04:55 +03:00
|
|
|
Servo_StyleSet_RemoveStyleSheet(mRawSet.get(), UniqueIDForSheet(sheet));
|
2017-01-04 22:52:26 +03:00
|
|
|
}
|
2016-08-03 07:08:01 +03:00
|
|
|
}
|
2017-05-12 22:04:55 +03:00
|
|
|
mSheets[aType].Clear();
|
2016-08-03 07:08:01 +03:00
|
|
|
|
2017-05-02 02:46:41 +03:00
|
|
|
// Add in all the new sheets.
|
|
|
|
for (auto& sheet : aNewSheets) {
|
2017-05-12 22:04:55 +03:00
|
|
|
AppendSheetOfType(aType, sheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
if (mRawSet) {
|
2017-02-15 23:25:21 +03:00
|
|
|
MOZ_ASSERT(sheet->RawSheet(), "Raw sheet should be in place before replacement.");
|
2017-05-02 02:46:41 +03:00
|
|
|
Servo_StyleSet_AppendStyleSheet(mRawSet.get(),
|
|
|
|
sheet->RawSheet(),
|
2017-05-12 22:04:55 +03:00
|
|
|
UniqueIDForSheet(sheet));
|
2017-01-04 22:52:26 +03:00
|
|
|
}
|
2016-12-22 02:33:24 +03:00
|
|
|
}
|
|
|
|
|
2016-08-03 07:08:01 +03:00
|
|
|
return NS_OK;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ServoStyleSet::InsertStyleSheetBefore(SheetType aType,
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSheet* aNewSheet,
|
|
|
|
ServoStyleSheet* aReferenceSheet)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2016-04-29 07:01:44 +03:00
|
|
|
MOZ_ASSERT(aNewSheet);
|
|
|
|
MOZ_ASSERT(aReferenceSheet);
|
|
|
|
MOZ_ASSERT(aNewSheet->IsApplicable());
|
2017-04-18 21:29:13 +03:00
|
|
|
MOZ_ASSERT(aNewSheet != aReferenceSheet, "Can't place sheet before itself.");
|
2017-05-02 02:46:41 +03:00
|
|
|
MOZ_ASSERT(aNewSheet->RawSheet(), "Raw sheet should be in place before insertion.");
|
|
|
|
MOZ_ASSERT(aReferenceSheet->RawSheet(), "Reference sheet should have a raw sheet.");
|
2016-04-29 07:01:44 +03:00
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
// Servo will remove aNewSheet from its original position as part of the
|
|
|
|
// call to Servo_StyleSet_InsertStyleSheetBefore.
|
|
|
|
RemoveSheetOfType(aType, aNewSheet);
|
|
|
|
InsertSheetOfType(aType, aNewSheet, aReferenceSheet);
|
2016-04-29 07:01:44 +03:00
|
|
|
|
2017-01-04 22:52:26 +03:00
|
|
|
if (mRawSet) {
|
|
|
|
// Maintain a mirrored list of sheets on the servo side.
|
2017-05-02 02:46:41 +03:00
|
|
|
Servo_StyleSet_InsertStyleSheetBefore(mRawSet.get(),
|
|
|
|
aNewSheet->RawSheet(),
|
2017-05-12 22:04:55 +03:00
|
|
|
UniqueIDForSheet(aNewSheet),
|
|
|
|
UniqueIDForSheet(aReferenceSheet));
|
2017-05-15 19:02:59 +03:00
|
|
|
SetStylistStyleSheetsDirty();
|
2017-01-04 22:52:26 +03:00
|
|
|
}
|
2016-04-29 07:01:44 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
ServoStyleSet::SheetCount(SheetType aType) const
|
|
|
|
{
|
2016-02-26 04:51:02 +03:00
|
|
|
MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
|
2017-05-12 22:04:55 +03:00
|
|
|
return mSheets[aType].Length();
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSheet*
|
2016-02-24 10:01:10 +03:00
|
|
|
ServoStyleSet::StyleSheetAt(SheetType aType,
|
|
|
|
int32_t aIndex) const
|
|
|
|
{
|
2016-02-26 04:51:02 +03:00
|
|
|
MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType));
|
2017-05-12 22:04:55 +03:00
|
|
|
return mSheets[aType][aIndex];
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSet::RemoveDocStyleSheet(ServoStyleSheet* aSheet)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2016-04-29 07:01:44 +03:00
|
|
|
return RemoveStyleSheet(SheetType::Doc, aSheet);
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-02-24 10:01:12 +03:00
|
|
|
ServoStyleSet::AddDocStyleSheet(ServoStyleSheet* aSheet,
|
2016-02-24 10:01:10 +03:00
|
|
|
nsIDocument* aDocument)
|
|
|
|
{
|
2017-01-09 12:42:52 +03:00
|
|
|
MOZ_ASSERT(aSheet->IsApplicable());
|
2017-02-15 23:25:21 +03:00
|
|
|
MOZ_ASSERT(aSheet->RawSheet(), "Raw sheet should be in place by this point.");
|
2017-01-09 12:42:52 +03:00
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
RefPtr<StyleSheet> strong(aSheet);
|
2016-04-29 07:01:44 +03:00
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
RemoveSheetOfType(SheetType::Doc, aSheet);
|
2016-04-29 07:01:44 +03:00
|
|
|
|
|
|
|
size_t index =
|
2017-05-12 22:04:55 +03:00
|
|
|
aDocument->FindDocStyleSheetInsertionPoint(mSheets[SheetType::Doc], aSheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
if (index < mSheets[SheetType::Doc].Length()) {
|
2017-05-02 02:46:41 +03:00
|
|
|
// This case is insert before.
|
2017-05-12 22:04:55 +03:00
|
|
|
ServoStyleSheet *beforeSheet = mSheets[SheetType::Doc][index];
|
|
|
|
InsertSheetOfType(SheetType::Doc, aSheet, beforeSheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
|
|
|
|
if (mRawSet) {
|
|
|
|
// Maintain a mirrored list of sheets on the servo side.
|
|
|
|
Servo_StyleSet_InsertStyleSheetBefore(mRawSet.get(),
|
|
|
|
aSheet->RawSheet(),
|
2017-05-12 22:04:55 +03:00
|
|
|
UniqueIDForSheet(aSheet),
|
|
|
|
UniqueIDForSheet(beforeSheet));
|
2017-05-15 19:02:59 +03:00
|
|
|
SetStylistStyleSheetsDirty();
|
2017-05-02 02:46:41 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This case is append.
|
2017-05-12 22:04:55 +03:00
|
|
|
AppendSheetOfType(SheetType::Doc, aSheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
|
|
|
|
if (mRawSet) {
|
|
|
|
// Maintain a mirrored list of sheets on the servo side.
|
|
|
|
Servo_StyleSet_AppendStyleSheet(mRawSet.get(),
|
|
|
|
aSheet->RawSheet(),
|
2017-05-12 22:04:55 +03:00
|
|
|
UniqueIDForSheet(aSheet));
|
2017-05-15 19:02:59 +03:00
|
|
|
SetStylistStyleSheetsDirty();
|
2017-01-04 22:52:26 +03:00
|
|
|
}
|
2016-04-29 07:01:44 +03:00
|
|
|
}
|
|
|
|
|
2016-02-26 05:57:42 +03:00
|
|
|
return NS_OK;
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsStyleContext>
|
2016-12-22 04:58:38 +03:00
|
|
|
ServoStyleSet::ProbePseudoElementStyle(Element* aOriginatingElement,
|
2016-02-24 10:01:10 +03:00
|
|
|
CSSPseudoElementType aType,
|
2017-05-18 12:41:13 +03:00
|
|
|
nsStyleContext* aParentContext,
|
|
|
|
Element* aPseudoElement)
|
2016-02-24 10:01:10 +03:00
|
|
|
{
|
2017-05-15 19:02:59 +03:00
|
|
|
UpdateStylistIfNeeded();
|
2017-05-18 12:41:13 +03:00
|
|
|
if (aPseudoElement) {
|
|
|
|
NS_ERROR("stylo: We don't support CSS_PSEUDO_ELEMENT_SUPPORTS_USER_ACTION_STATE yet");
|
|
|
|
}
|
2017-05-10 20:13:39 +03:00
|
|
|
|
2016-12-22 04:58:38 +03:00
|
|
|
// NB: We ignore aParentContext, on the assumption that pseudo element styles
|
|
|
|
// should just inherit from aOriginatingElement's primary style, which Servo
|
|
|
|
// already knows.
|
2016-04-29 03:56:37 +03:00
|
|
|
MOZ_ASSERT(aType < CSSPseudoElementType::Count);
|
|
|
|
|
|
|
|
RefPtr<ServoComputedValues> computedValues =
|
2017-05-14 19:39:22 +03:00
|
|
|
Servo_ResolvePseudoStyle(aOriginatingElement, aType,
|
2016-12-22 04:58:38 +03:00
|
|
|
/* is_probe = */ true, mRawSet.get()).Consume();
|
2016-04-29 03:56:37 +03:00
|
|
|
if (!computedValues) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For :before and :after pseudo-elements, having display: none or no
|
|
|
|
// 'content' property is equivalent to not having the pseudo-element
|
|
|
|
// at all.
|
2017-05-14 19:39:22 +03:00
|
|
|
bool isBeforeOrAfter = aType == CSSPseudoElementType::before ||
|
|
|
|
aType == CSSPseudoElementType::after;
|
2017-01-29 06:59:00 +03:00
|
|
|
if (isBeforeOrAfter) {
|
2017-05-14 19:39:22 +03:00
|
|
|
const nsStyleDisplay* display = Servo_GetStyleDisplay(computedValues);
|
|
|
|
const nsStyleContent* content = Servo_GetStyleContent(computedValues);
|
2016-04-29 03:56:37 +03:00
|
|
|
// XXXldb What is contentCount for |content: ""|?
|
2016-09-03 21:46:58 +03:00
|
|
|
if (display->mDisplay == StyleDisplay::None ||
|
2016-04-29 03:56:37 +03:00
|
|
|
content->ContentCount() == 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-14 19:39:22 +03:00
|
|
|
nsIAtom* pseudoTag = nsCSSPseudoElements::GetPseudoAtom(aType);
|
2017-01-29 06:59:00 +03:00
|
|
|
return GetContext(computedValues.forget(), aParentContext, pseudoTag, aType,
|
|
|
|
isBeforeOrAfter ? aOriginatingElement : nullptr);
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRestyleHint
|
|
|
|
ServoStyleSet::HasStateDependentStyle(dom::Element* aElement,
|
|
|
|
EventStates aStateMask)
|
|
|
|
{
|
2016-07-29 01:22:54 +03:00
|
|
|
NS_WARNING("stylo: HasStateDependentStyle always returns zero!");
|
2016-07-14 00:37:56 +03:00
|
|
|
return nsRestyleHint(0);
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRestyleHint
|
|
|
|
ServoStyleSet::HasStateDependentStyle(dom::Element* aElement,
|
|
|
|
CSSPseudoElementType aPseudoType,
|
|
|
|
dom::Element* aPseudoElement,
|
|
|
|
EventStates aStateMask)
|
|
|
|
{
|
2016-07-29 01:22:54 +03:00
|
|
|
NS_WARNING("stylo: HasStateDependentStyle always returns zero!");
|
2016-07-14 00:37:56 +03:00
|
|
|
return nsRestyleHint(0);
|
2016-02-24 10:01:10 +03:00
|
|
|
}
|
2016-05-25 09:55:49 +03:00
|
|
|
|
2017-02-10 05:42:30 +03:00
|
|
|
bool
|
2017-05-21 02:16:26 +03:00
|
|
|
ServoStyleSet::StyleDocument(TraversalRestyleBehavior aRestyleBehavior)
|
2016-08-12 00:12:49 +03:00
|
|
|
{
|
2017-05-21 02:16:26 +03:00
|
|
|
MOZ_ASSERT(
|
|
|
|
aRestyleBehavior == TraversalRestyleBehavior::Normal ||
|
|
|
|
aRestyleBehavior == TraversalRestyleBehavior::ForCSSRuleChanges,
|
|
|
|
"StyleDocument() should be only called for normal traversal or CSS rule "
|
|
|
|
"changes");
|
|
|
|
|
2017-03-08 23:20:17 +03:00
|
|
|
PreTraverse();
|
|
|
|
|
2016-12-01 11:19:50 +03:00
|
|
|
// Restyle the document from the root element and each of the document level
|
|
|
|
// NAC subtree roots.
|
2017-02-10 05:42:30 +03:00
|
|
|
bool postTraversalRequired = false;
|
2016-12-01 11:19:50 +03:00
|
|
|
DocumentStyleRootIterator iter(mPresContext->Document());
|
|
|
|
while (Element* root = iter.GetNextStyleRoot()) {
|
2017-04-08 17:57:08 +03:00
|
|
|
if (PrepareAndTraverseSubtree(root,
|
|
|
|
TraversalRootBehavior::Normal,
|
2017-05-21 02:16:26 +03:00
|
|
|
aRestyleBehavior)) {
|
2017-02-10 05:42:30 +03:00
|
|
|
postTraversalRequired = true;
|
2016-12-01 11:19:50 +03:00
|
|
|
}
|
|
|
|
}
|
2017-02-10 05:42:30 +03:00
|
|
|
return postTraversalRequired;
|
2016-08-12 00:12:49 +03:00
|
|
|
}
|
|
|
|
|
2017-05-19 11:16:41 +03:00
|
|
|
bool
|
|
|
|
ServoStyleSet::StyleDocumentForAnimationOnly()
|
|
|
|
{
|
|
|
|
PreTraverse(nullptr, EffectCompositor::AnimationRestyleType::Full);
|
|
|
|
|
|
|
|
bool postTraversalRequired = false;
|
|
|
|
DocumentStyleRootIterator iter(mPresContext->Document());
|
|
|
|
while (Element* root = iter.GetNextStyleRoot()) {
|
|
|
|
if (PrepareAndTraverseSubtree(root,
|
|
|
|
TraversalRootBehavior::Normal,
|
|
|
|
TraversalRestyleBehavior::ForAnimationOnly)) {
|
|
|
|
postTraversalRequired = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return postTraversalRequired;
|
|
|
|
}
|
|
|
|
|
2016-08-12 00:12:49 +03:00
|
|
|
void
|
2016-12-11 09:11:36 +03:00
|
|
|
ServoStyleSet::StyleNewSubtree(Element* aRoot)
|
2016-08-12 00:12:49 +03:00
|
|
|
{
|
2016-12-11 09:11:36 +03:00
|
|
|
MOZ_ASSERT(!aRoot->HasServoData());
|
2017-03-08 23:20:17 +03:00
|
|
|
|
|
|
|
PreTraverse();
|
|
|
|
|
2017-02-10 05:42:30 +03:00
|
|
|
DebugOnly<bool> postTraversalRequired =
|
2017-04-08 17:57:08 +03:00
|
|
|
PrepareAndTraverseSubtree(aRoot,
|
|
|
|
TraversalRootBehavior::Normal,
|
|
|
|
TraversalRestyleBehavior::Normal);
|
2017-02-10 05:42:30 +03:00
|
|
|
MOZ_ASSERT(!postTraversalRequired);
|
2016-08-12 00:12:49 +03:00
|
|
|
}
|
|
|
|
|
2016-05-25 09:55:49 +03:00
|
|
|
void
|
2016-12-11 09:11:36 +03:00
|
|
|
ServoStyleSet::StyleNewChildren(Element* aParent)
|
2016-05-25 09:55:49 +03:00
|
|
|
{
|
2017-03-08 23:20:17 +03:00
|
|
|
PreTraverse();
|
|
|
|
|
2017-04-08 17:57:08 +03:00
|
|
|
PrepareAndTraverseSubtree(aParent,
|
|
|
|
TraversalRootBehavior::UnstyledChildrenOnly,
|
|
|
|
TraversalRestyleBehavior::Normal);
|
2017-02-10 05:42:30 +03:00
|
|
|
// We can't assert that Servo_TraverseSubtree returns false, since aParent
|
|
|
|
// or some of its other children might have pending restyles.
|
2016-11-02 09:11:24 +03:00
|
|
|
}
|
|
|
|
|
2017-06-11 14:11:08 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::StyleNewlyBoundElement(Element* aElement)
|
|
|
|
{
|
|
|
|
PreTraverse();
|
|
|
|
|
|
|
|
// In general the element is always styled by the time we're applying XBL
|
|
|
|
// bindings, because we need to style the element to know what the binding
|
|
|
|
// URI is. However, programmatic consumers of the XBL service (like the
|
|
|
|
// XML pretty printer) _can_ apply bindings without having styled the bound
|
|
|
|
// element. We could assert against this and require the callers manually
|
|
|
|
// resolve the style first, but it's easy enough to just handle here.
|
|
|
|
//
|
|
|
|
// Also, when applying XBL bindings to elements within a display:none or
|
|
|
|
// unstyled subtree (for example, when <object> elements are wrapped to be
|
|
|
|
// exposed to JS), we need to tell the traversal that it is OK to
|
|
|
|
// skip restyling, rather than panic when trying to unwrap the styles
|
|
|
|
// it expects to have just computed.
|
|
|
|
|
|
|
|
TraversalRootBehavior rootBehavior =
|
|
|
|
MOZ_UNLIKELY(!aElement->HasServoData())
|
|
|
|
? TraversalRootBehavior::Normal
|
|
|
|
: TraversalRootBehavior::UnstyledChildrenOnly;
|
|
|
|
|
|
|
|
PrepareAndTraverseSubtree(aElement,
|
|
|
|
rootBehavior,
|
|
|
|
TraversalRestyleBehavior::ForNewlyBoundElement);
|
|
|
|
}
|
|
|
|
|
2017-04-04 14:34:30 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::StyleSubtreeForReconstruct(Element* aRoot)
|
|
|
|
{
|
|
|
|
PreTraverse(aRoot);
|
|
|
|
|
|
|
|
DebugOnly<bool> postTraversalRequired =
|
|
|
|
PrepareAndTraverseSubtree(aRoot,
|
|
|
|
TraversalRootBehavior::Normal,
|
|
|
|
TraversalRestyleBehavior::ForReconstruct);
|
|
|
|
MOZ_ASSERT(!postTraversalRequired);
|
|
|
|
}
|
|
|
|
|
2016-12-19 09:30:14 +03:00
|
|
|
void
|
2017-05-25 20:50:03 +03:00
|
|
|
ServoStyleSet::ForceAllStyleDirty()
|
2016-12-19 09:30:14 +03:00
|
|
|
{
|
2017-05-15 19:02:59 +03:00
|
|
|
SetStylistStyleSheetsDirty();
|
2017-04-11 10:59:44 +03:00
|
|
|
Servo_StyleSet_NoteStyleSheetsChanged(mRawSet.get(), mAuthorStyleDisabled);
|
2016-12-19 09:30:14 +03:00
|
|
|
}
|
|
|
|
|
2017-05-25 20:50:03 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::RecordStyleSheetChange(
|
|
|
|
ServoStyleSheet* aSheet,
|
|
|
|
StyleSheet::ChangeType aChangeType)
|
|
|
|
{
|
|
|
|
SetStylistStyleSheetsDirty();
|
|
|
|
switch (aChangeType) {
|
|
|
|
case StyleSheet::ChangeType::RuleAdded:
|
|
|
|
case StyleSheet::ChangeType::RuleRemoved:
|
|
|
|
case StyleSheet::ChangeType::RuleChanged:
|
|
|
|
// FIXME(emilio): We can presumably do better in a bunch of these.
|
|
|
|
return ForceAllStyleDirty();
|
2017-05-26 18:46:31 +03:00
|
|
|
case StyleSheet::ChangeType::ApplicableStateChanged:
|
2017-05-25 20:50:03 +03:00
|
|
|
case StyleSheet::ChangeType::Added:
|
|
|
|
case StyleSheet::ChangeType::Removed:
|
2017-05-26 18:46:31 +03:00
|
|
|
// Do nothing, we've already recorded the change in the
|
|
|
|
// Append/Remove/Replace methods, etc, and will act consequently.
|
2017-05-25 20:50:03 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
ServoStyleSet::AssertTreeIsClean()
|
|
|
|
{
|
2016-12-28 11:26:10 +03:00
|
|
|
DocumentStyleRootIterator iter(mPresContext->Document());
|
|
|
|
while (Element* root = iter.GetNextStyleRoot()) {
|
2016-11-02 09:11:24 +03:00
|
|
|
Servo_AssertTreeIsClean(root);
|
|
|
|
}
|
2016-05-25 09:55:49 +03:00
|
|
|
}
|
2016-11-02 09:11:24 +03:00
|
|
|
#endif
|
2017-01-04 22:52:27 +03:00
|
|
|
|
2017-01-29 06:58:28 +03:00
|
|
|
bool
|
2017-05-13 10:34:38 +03:00
|
|
|
ServoStyleSet::GetKeyframesForName(const nsString& aName,
|
|
|
|
const nsTimingFunction& aTimingFunction,
|
|
|
|
const ServoComputedValues* aComputedValues,
|
|
|
|
nsTArray<Keyframe>& aKeyframes)
|
2017-01-29 06:58:28 +03:00
|
|
|
{
|
2017-05-15 19:02:59 +03:00
|
|
|
UpdateStylistIfNeeded();
|
2017-05-10 20:13:39 +03:00
|
|
|
|
2017-01-29 06:58:28 +03:00
|
|
|
NS_ConvertUTF16toUTF8 name(aName);
|
2017-05-13 10:34:38 +03:00
|
|
|
return Servo_StyleSet_GetKeyframesForName(mRawSet.get(),
|
|
|
|
&name,
|
|
|
|
&aTimingFunction,
|
|
|
|
aComputedValues,
|
|
|
|
&aKeyframes);
|
2017-01-29 06:58:28 +03:00
|
|
|
}
|
|
|
|
|
2017-03-11 04:40:47 +03:00
|
|
|
nsTArray<ComputedKeyframeValues>
|
2017-03-21 10:41:23 +03:00
|
|
|
ServoStyleSet::GetComputedKeyframeValuesFor(
|
|
|
|
const nsTArray<Keyframe>& aKeyframes,
|
2017-06-02 03:38:22 +03:00
|
|
|
Element* aElement,
|
2017-06-02 03:38:54 +03:00
|
|
|
ServoComputedValuesBorrowed aComputedValues)
|
2017-03-11 04:40:47 +03:00
|
|
|
{
|
|
|
|
nsTArray<ComputedKeyframeValues> result(aKeyframes.Length());
|
|
|
|
|
|
|
|
// Construct each nsTArray<PropertyStyleAnimationValuePair> here.
|
|
|
|
result.AppendElements(aKeyframes.Length());
|
|
|
|
|
|
|
|
Servo_GetComputedKeyframeValues(&aKeyframes,
|
2017-06-02 03:38:22 +03:00
|
|
|
aElement,
|
2017-06-02 03:38:54 +03:00
|
|
|
aComputedValues,
|
2017-03-11 04:40:47 +03:00
|
|
|
mRawSet.get(),
|
|
|
|
&result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-06-09 00:19:37 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::GetAnimationValues(
|
|
|
|
RawServoDeclarationBlock* aDeclarations,
|
|
|
|
Element* aElement,
|
|
|
|
ServoComputedValuesBorrowed aComputedValues,
|
|
|
|
nsTArray<RefPtr<RawServoAnimationValue>>& aAnimationValues)
|
|
|
|
{
|
|
|
|
Servo_GetAnimationValues(aDeclarations,
|
|
|
|
aElement,
|
|
|
|
aComputedValues,
|
|
|
|
mRawSet.get(),
|
|
|
|
&aAnimationValues);
|
|
|
|
}
|
|
|
|
|
2017-04-06 04:34:50 +03:00
|
|
|
already_AddRefed<ServoComputedValues>
|
|
|
|
ServoStyleSet::GetBaseComputedValuesForElement(Element* aElement,
|
2017-05-14 19:39:22 +03:00
|
|
|
CSSPseudoElementType aPseudoType)
|
2017-04-06 04:34:50 +03:00
|
|
|
{
|
|
|
|
return Servo_StyleSet_GetBaseComputedValuesForElement(mRawSet.get(),
|
|
|
|
aElement,
|
2017-05-07 17:36:47 +03:00
|
|
|
&Snapshots(),
|
2017-05-14 19:39:22 +03:00
|
|
|
aPseudoType).Consume();
|
2017-04-06 04:34:50 +03:00
|
|
|
}
|
|
|
|
|
2017-05-03 06:15:27 +03:00
|
|
|
already_AddRefed<RawServoAnimationValue>
|
|
|
|
ServoStyleSet::ComputeAnimationValue(
|
2017-06-02 03:38:22 +03:00
|
|
|
Element* aElement,
|
2017-05-03 06:15:27 +03:00
|
|
|
RawServoDeclarationBlock* aDeclarations,
|
2017-06-02 03:38:46 +03:00
|
|
|
ServoComputedValuesBorrowed aComputedValues)
|
2017-05-03 06:15:27 +03:00
|
|
|
{
|
2017-06-02 03:38:22 +03:00
|
|
|
return Servo_AnimationValue_Compute(aElement,
|
|
|
|
aDeclarations,
|
2017-06-02 03:38:46 +03:00
|
|
|
aComputedValues,
|
2017-05-03 06:15:27 +03:00
|
|
|
mRawSet.get()).Consume();
|
|
|
|
}
|
|
|
|
|
2017-05-16 02:30:10 +03:00
|
|
|
bool
|
|
|
|
ServoStyleSet::EnsureUniqueInnerOnCSSSheets()
|
|
|
|
{
|
2017-05-16 03:11:08 +03:00
|
|
|
AutoTArray<StyleSheet*, 32> queue;
|
|
|
|
for (auto& entryArray : mSheets) {
|
|
|
|
for (auto& sheet : entryArray) {
|
|
|
|
queue.AppendElement(sheet);
|
|
|
|
}
|
|
|
|
}
|
2017-05-16 02:30:10 +03:00
|
|
|
// This is a stub until more of the functionality of nsStyleSet is
|
|
|
|
// replicated for Servo here.
|
|
|
|
|
2017-05-16 03:11:08 +03:00
|
|
|
// Bug 1290276 will replicate the nsStyleSet work of checking
|
|
|
|
// a nsBindingManager
|
|
|
|
|
|
|
|
while (!queue.IsEmpty()) {
|
|
|
|
uint32_t idx = queue.Length() - 1;
|
|
|
|
StyleSheet* sheet = queue[idx];
|
|
|
|
queue.RemoveElementAt(idx);
|
|
|
|
|
|
|
|
sheet->EnsureUniqueInner();
|
|
|
|
|
|
|
|
// Enqueue all the sheet's children.
|
|
|
|
sheet->AppendAllChildSheets(queue);
|
|
|
|
}
|
|
|
|
|
2017-05-16 02:30:10 +03:00
|
|
|
bool res = mNeedsRestyleAfterEnsureUniqueInner;
|
|
|
|
mNeedsRestyleAfterEnsureUniqueInner = false;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-01-04 22:52:27 +03:00
|
|
|
void
|
2017-01-15 01:34:49 +03:00
|
|
|
ServoStyleSet::RebuildData()
|
2017-01-04 22:52:27 +03:00
|
|
|
{
|
2017-03-08 08:18:39 +03:00
|
|
|
ClearNonInheritingStyleContexts();
|
2017-05-24 03:31:59 +03:00
|
|
|
Servo_StyleSet_RebuildData(mRawSet.get());
|
2017-05-15 19:02:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoStyleSet::ClearDataAndMarkDeviceDirty()
|
|
|
|
{
|
|
|
|
ClearNonInheritingStyleContexts();
|
|
|
|
Servo_StyleSet_Clear(mRawSet.get());
|
2017-05-30 03:46:33 +03:00
|
|
|
mStylistState |= StylistState::FullyDirty;
|
2017-01-04 22:52:27 +03:00
|
|
|
}
|
2017-01-04 22:52:27 +03:00
|
|
|
|
2017-06-10 17:22:23 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::CompatibilityModeChanged()
|
|
|
|
{
|
|
|
|
Servo_StyleSet_CompatModeChanged(mRawSet.get());
|
|
|
|
}
|
|
|
|
|
2017-01-04 22:52:27 +03:00
|
|
|
already_AddRefed<ServoComputedValues>
|
2017-01-06 00:12:53 +03:00
|
|
|
ServoStyleSet::ResolveServoStyle(Element* aElement)
|
2017-01-04 22:52:27 +03:00
|
|
|
{
|
2017-05-15 19:02:59 +03:00
|
|
|
UpdateStylistIfNeeded();
|
2017-03-28 10:31:41 +03:00
|
|
|
return Servo_ResolveStyle(aElement, mRawSet.get(),
|
|
|
|
mAllowResolveStaleStyles).Consume();
|
2017-01-04 22:52:27 +03:00
|
|
|
}
|
2017-02-02 22:48:28 +03:00
|
|
|
|
2017-03-08 08:18:39 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::ClearNonInheritingStyleContexts()
|
|
|
|
{
|
|
|
|
for (RefPtr<nsStyleContext>& ptr : mNonInheritingStyleContexts) {
|
|
|
|
ptr = nullptr;
|
2017-03-11 04:40:47 +03:00
|
|
|
}
|
2017-03-08 08:18:39 +03:00
|
|
|
}
|
|
|
|
|
2017-03-08 23:20:17 +03:00
|
|
|
already_AddRefed<ServoComputedValues>
|
2017-05-14 19:39:22 +03:00
|
|
|
ServoStyleSet::ResolveStyleLazily(Element* aElement,
|
2017-05-24 09:37:47 +03:00
|
|
|
CSSPseudoElementType aPseudoType,
|
|
|
|
StyleRuleInclusion aRuleInclusion)
|
2017-03-08 23:20:17 +03:00
|
|
|
{
|
2017-05-14 19:39:22 +03:00
|
|
|
mPresContext->EffectCompositor()->PreTraverse(aElement, aPseudoType);
|
2017-05-15 19:02:59 +03:00
|
|
|
MOZ_ASSERT(!StylistNeedsUpdate());
|
2017-04-30 09:41:11 +03:00
|
|
|
|
|
|
|
AutoSetInServoTraversal guard(this);
|
2017-04-26 15:01:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* NB: This is needed because we process animations and transitions on the
|
|
|
|
* pseudo-elements themselves, not on the parent's EagerPseudoStyles.
|
|
|
|
*
|
|
|
|
* That means that that style doesn't account for animations, and we can't do
|
|
|
|
* that easily from the traversal without doing wasted work.
|
|
|
|
*
|
|
|
|
* As such, we just lie here a bit, which is the entrypoint of
|
|
|
|
* getComputedStyle, the only API where this can be observed, to look at the
|
|
|
|
* style of the pseudo-element if it exists instead.
|
|
|
|
*/
|
|
|
|
Element* elementForStyleResolution = aElement;
|
2017-05-14 19:39:22 +03:00
|
|
|
CSSPseudoElementType pseudoTypeForStyleResolution = aPseudoType;
|
|
|
|
if (aPseudoType == CSSPseudoElementType::before) {
|
2017-04-26 15:01:25 +03:00
|
|
|
if (Element* pseudo = nsLayoutUtils::GetBeforePseudo(aElement)) {
|
|
|
|
elementForStyleResolution = pseudo;
|
2017-05-14 19:39:22 +03:00
|
|
|
pseudoTypeForStyleResolution = CSSPseudoElementType::NotPseudo;
|
2017-04-26 15:01:25 +03:00
|
|
|
}
|
2017-05-14 19:39:22 +03:00
|
|
|
} else if (aPseudoType == CSSPseudoElementType::after) {
|
2017-04-26 15:01:25 +03:00
|
|
|
if (Element* pseudo = nsLayoutUtils::GetAfterPseudo(aElement)) {
|
|
|
|
elementForStyleResolution = pseudo;
|
2017-05-14 19:39:22 +03:00
|
|
|
pseudoTypeForStyleResolution = CSSPseudoElementType::NotPseudo;
|
2017-04-26 15:01:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-10 05:53:19 +03:00
|
|
|
RefPtr<ServoComputedValues> computedValues =
|
2017-04-26 15:01:25 +03:00
|
|
|
Servo_ResolveStyleLazily(elementForStyleResolution,
|
2017-05-14 19:39:22 +03:00
|
|
|
pseudoTypeForStyleResolution,
|
2017-05-24 09:37:47 +03:00
|
|
|
aRuleInclusion,
|
2017-05-07 17:36:47 +03:00
|
|
|
&Snapshots(),
|
2017-04-26 15:01:25 +03:00
|
|
|
mRawSet.get()).Consume();
|
2017-03-10 05:53:19 +03:00
|
|
|
|
2017-05-14 19:39:22 +03:00
|
|
|
if (mPresContext->EffectCompositor()->PreTraverse(aElement, aPseudoType)) {
|
2017-03-10 05:53:19 +03:00
|
|
|
computedValues =
|
2017-04-26 15:01:25 +03:00
|
|
|
Servo_ResolveStyleLazily(elementForStyleResolution,
|
2017-05-14 19:39:22 +03:00
|
|
|
pseudoTypeForStyleResolution,
|
2017-05-24 09:37:47 +03:00
|
|
|
aRuleInclusion,
|
2017-05-07 17:36:47 +03:00
|
|
|
&Snapshots(),
|
2017-04-26 15:01:25 +03:00
|
|
|
mRawSet.get()).Consume();
|
2017-03-10 05:53:19 +03:00
|
|
|
}
|
2017-04-26 15:01:25 +03:00
|
|
|
|
2017-03-10 05:53:19 +03:00
|
|
|
return computedValues.forget();
|
2017-03-08 23:20:17 +03:00
|
|
|
}
|
|
|
|
|
2017-03-27 09:53:27 +03:00
|
|
|
bool
|
|
|
|
ServoStyleSet::AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray)
|
|
|
|
{
|
2017-05-15 19:02:59 +03:00
|
|
|
UpdateStylistIfNeeded();
|
2017-03-27 09:53:27 +03:00
|
|
|
Servo_StyleSet_GetFontFaceRules(mRawSet.get(), &aArray);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-11 07:47:24 +03:00
|
|
|
nsCSSCounterStyleRule*
|
|
|
|
ServoStyleSet::CounterStyleRuleForName(nsIAtom* aName)
|
|
|
|
{
|
|
|
|
return Servo_StyleSet_GetCounterStyleRule(mRawSet.get(), aName);
|
|
|
|
}
|
|
|
|
|
2017-04-15 01:37:35 +03:00
|
|
|
already_AddRefed<ServoComputedValues>
|
|
|
|
ServoStyleSet::ResolveForDeclarations(
|
|
|
|
ServoComputedValuesBorrowedOrNull aParentOrNull,
|
|
|
|
RawServoDeclarationBlockBorrowed aDeclarations)
|
|
|
|
{
|
2017-05-15 19:02:59 +03:00
|
|
|
UpdateStylistIfNeeded();
|
2017-04-15 01:37:35 +03:00
|
|
|
return Servo_StyleSet_ResolveForDeclarations(mRawSet.get(),
|
|
|
|
aParentOrNull,
|
|
|
|
aDeclarations).Consume();
|
|
|
|
}
|
|
|
|
|
2017-05-10 20:13:39 +03:00
|
|
|
void
|
2017-05-15 19:02:59 +03:00
|
|
|
ServoStyleSet::UpdateStylist()
|
2017-05-10 20:13:39 +03:00
|
|
|
{
|
2017-05-15 19:02:59 +03:00
|
|
|
MOZ_ASSERT(StylistNeedsUpdate());
|
2017-05-30 03:46:33 +03:00
|
|
|
if (mStylistState & StylistState::FullyDirty) {
|
2017-05-15 19:02:59 +03:00
|
|
|
RebuildData();
|
2017-05-30 03:46:33 +03:00
|
|
|
|
|
|
|
if (mStylistState & StylistState::StyleSheetsDirty) {
|
|
|
|
// Normally, whoever was in charge of posting a RebuildAllStyleDataEvent,
|
|
|
|
// would also be in charge of posting a restyle/change hint according to
|
|
|
|
// it.
|
|
|
|
//
|
|
|
|
// However, other stylesheets may have been added to the document in the
|
|
|
|
// same period, so when both bits are set, we need to do a full subtree
|
|
|
|
// update, because we can no longer reason about the state of the style
|
|
|
|
// data.
|
|
|
|
//
|
|
|
|
// We could not clear the invalidations when rebuilding the data and
|
|
|
|
// process them here... But it's not clear if that complexity is worth
|
|
|
|
// to handle this edge case more efficiently.
|
|
|
|
if (Element* root = mPresContext->Document()->GetDocumentElement()) {
|
|
|
|
Servo_NoteExplicitHints(root, eRestyle_Subtree, nsChangeHint(0));
|
|
|
|
}
|
|
|
|
}
|
2017-05-15 19:02:59 +03:00
|
|
|
} else {
|
2017-05-30 03:46:33 +03:00
|
|
|
MOZ_ASSERT(mStylistState & StylistState::StyleSheetsDirty);
|
2017-05-25 20:50:03 +03:00
|
|
|
Element* root = mPresContext->Document()->GetDocumentElement();
|
|
|
|
Servo_StyleSet_FlushStyleSheets(mRawSet.get(), root);
|
2017-05-15 19:02:59 +03:00
|
|
|
}
|
|
|
|
mStylistState = StylistState::NotDirty;
|
2017-05-10 20:13:39 +03:00
|
|
|
}
|
|
|
|
|
2017-06-16 20:20:25 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::MaybeGCRuleTree()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
Servo_MaybeGCRuleTree(mRawSet.get());
|
|
|
|
}
|
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
void
|
2017-05-02 02:46:41 +03:00
|
|
|
ServoStyleSet::PrependSheetOfType(SheetType aType,
|
2017-05-12 22:04:55 +03:00
|
|
|
ServoStyleSheet* aSheet)
|
2017-05-02 02:46:41 +03:00
|
|
|
{
|
2017-05-24 03:02:51 +03:00
|
|
|
aSheet->AddStyleSet(this);
|
2017-05-12 22:04:55 +03:00
|
|
|
mSheets[aType].InsertElementAt(0, aSheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
}
|
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
void
|
2017-05-02 02:46:41 +03:00
|
|
|
ServoStyleSet::AppendSheetOfType(SheetType aType,
|
2017-05-12 22:04:55 +03:00
|
|
|
ServoStyleSheet* aSheet)
|
2017-05-02 02:46:41 +03:00
|
|
|
{
|
2017-05-24 03:02:51 +03:00
|
|
|
aSheet->AddStyleSet(this);
|
2017-05-12 22:04:55 +03:00
|
|
|
mSheets[aType].AppendElement(aSheet);
|
2017-05-02 02:46:41 +03:00
|
|
|
}
|
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
void
|
2017-05-02 02:46:41 +03:00
|
|
|
ServoStyleSet::InsertSheetOfType(SheetType aType,
|
|
|
|
ServoStyleSheet* aSheet,
|
2017-05-12 22:04:55 +03:00
|
|
|
ServoStyleSheet* aBeforeSheet)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mSheets[aType].Length(); ++i) {
|
|
|
|
if (mSheets[aType][i] == aBeforeSheet) {
|
2017-05-24 03:02:51 +03:00
|
|
|
aSheet->AddStyleSet(this);
|
2017-05-12 22:04:55 +03:00
|
|
|
mSheets[aType].InsertElementAt(i, aSheet);
|
|
|
|
return;
|
2017-05-02 02:46:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-12 22:04:55 +03:00
|
|
|
void
|
2017-05-02 02:46:41 +03:00
|
|
|
ServoStyleSet::RemoveSheetOfType(SheetType aType,
|
|
|
|
ServoStyleSheet* aSheet)
|
|
|
|
{
|
2017-05-12 22:04:55 +03:00
|
|
|
for (uint32_t i = 0; i < mSheets[aType].Length(); ++i) {
|
|
|
|
if (mSheets[aType][i] == aSheet) {
|
2017-05-24 03:02:51 +03:00
|
|
|
aSheet->DropStyleSet(this);
|
2017-05-12 22:04:55 +03:00
|
|
|
mSheets[aType].RemoveElementAt(i);
|
2017-05-02 02:46:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-30 09:45:32 +03:00
|
|
|
void
|
|
|
|
ServoStyleSet::RunPostTraversalTasks()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!IsInServoTraversal());
|
|
|
|
|
|
|
|
if (mPostTraversalTasks.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<PostTraversalTask> tasks;
|
|
|
|
tasks.SwapElements(mPostTraversalTasks);
|
|
|
|
|
|
|
|
for (auto& task : tasks) {
|
|
|
|
task.Run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-08 11:04:31 +03:00
|
|
|
bool
|
|
|
|
ServoStyleSet::MightHaveAttributeDependency(nsIAtom* aAttribute)
|
|
|
|
{
|
|
|
|
return Servo_StyleSet_MightHaveAttributeDependency(mRawSet.get(), aAttribute);
|
|
|
|
}
|
|
|
|
|
2017-05-09 13:13:45 +03:00
|
|
|
bool
|
|
|
|
ServoStyleSet::HasStateDependency(EventStates aState)
|
|
|
|
{
|
|
|
|
return Servo_StyleSet_HasStateDependency(mRawSet.get(), aState.ServoValue());
|
|
|
|
}
|
|
|
|
|
2017-04-30 09:41:11 +03:00
|
|
|
ServoStyleSet* ServoStyleSet::sInServoTraversal = nullptr;
|