2016-07-08 10:08:46 +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/. */
|
|
|
|
|
2017-02-13 06:21:32 +03:00
|
|
|
#ifndef mozilla_RestyleManager_h
|
|
|
|
#define mozilla_RestyleManager_h
|
2016-07-08 10:08:46 +03:00
|
|
|
|
2018-04-09 11:33:56 +03:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2018-04-05 21:55:51 +03:00
|
|
|
#include "mozilla/EventStates.h"
|
|
|
|
#include "mozilla/Maybe.h"
|
2016-08-02 04:32:06 +03:00
|
|
|
#include "mozilla/OverflowChangedTracker.h"
|
2018-04-05 21:55:51 +03:00
|
|
|
#include "mozilla/ServoElementSnapshot.h"
|
|
|
|
#include "mozilla/ServoElementSnapshotTable.h"
|
2016-07-08 10:08:46 +03:00
|
|
|
#include "nsChangeHint.h"
|
2016-08-29 18:19:49 +03:00
|
|
|
#include "nsPresContext.h"
|
2019-03-29 18:11:22 +03:00
|
|
|
#include "nsPresContextInlines.h" // XXX Shouldn't be included by header though
|
2017-08-17 02:48:52 +03:00
|
|
|
#include "nsStringFwd.h"
|
2016-07-08 10:08:46 +03:00
|
|
|
|
2018-04-05 21:55:51 +03:00
|
|
|
class nsAttrValue;
|
2016-08-29 18:19:49 +03:00
|
|
|
class nsCSSFrameConstructor;
|
2018-04-05 21:55:51 +03:00
|
|
|
class nsAtom;
|
|
|
|
class nsIContent;
|
|
|
|
class nsIFrame;
|
|
|
|
class nsStyleChangeList;
|
2016-08-01 23:31:57 +03:00
|
|
|
class nsStyleChangeList;
|
|
|
|
|
2016-07-08 10:08:46 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2016-08-29 18:19:49 +03:00
|
|
|
class EventStates;
|
2018-04-05 21:55:51 +03:00
|
|
|
class ServoStyleSet;
|
2016-08-29 18:19:49 +03:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
}
|
2016-07-08 10:08:46 +03:00
|
|
|
|
|
|
|
/**
|
2018-04-05 21:55:51 +03:00
|
|
|
* A stack class used to pass some common restyle state in a slightly more
|
|
|
|
* comfortable way than a bunch of individual arguments, and that also checks
|
|
|
|
* that the change hint used for optimization is correctly used in debug mode.
|
2016-07-08 10:08:46 +03:00
|
|
|
*/
|
2018-04-05 21:55:51 +03:00
|
|
|
class ServoRestyleState {
|
|
|
|
public:
|
|
|
|
ServoRestyleState(ServoStyleSet& aStyleSet, nsStyleChangeList& aChangeList,
|
|
|
|
nsTArray<nsIFrame*>& aPendingWrapperRestyles)
|
|
|
|
: mStyleSet(aStyleSet),
|
|
|
|
mChangeList(aChangeList),
|
|
|
|
mPendingWrapperRestyles(aPendingWrapperRestyles),
|
|
|
|
mPendingWrapperRestyleOffset(aPendingWrapperRestyles.Length()),
|
|
|
|
mChangesHandled(nsChangeHint(0))
|
|
|
|
#ifdef DEBUG
|
|
|
|
// If !mOwner, then we wouldn't have processed our wrapper restyles,
|
|
|
|
// because we only process those when handling an element with a frame.
|
|
|
|
// But that's OK, because if we started our traversal at an element with
|
|
|
|
// no frame (e.g. it's display:contents), that means the wrapper frames
|
|
|
|
// in our list actually inherit from one of its ancestors, not from it,
|
|
|
|
// and hence not restyling them is OK.
|
|
|
|
,
|
|
|
|
mAssertWrapperRestyleLength(false)
|
|
|
|
#endif // DEBUG
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// We shouldn't assume that changes handled from our parent are handled for
|
|
|
|
// our children too if we're out of flow since they aren't necessarily
|
|
|
|
// parented in DOM order, and thus a change handled by a DOM ancestor doesn't
|
|
|
|
// necessarily mean that it's handled for an ancestor frame.
|
|
|
|
enum class Type {
|
|
|
|
InFlow,
|
|
|
|
OutOfFlow,
|
|
|
|
};
|
|
|
|
|
|
|
|
ServoRestyleState(const nsIFrame& aOwner, ServoRestyleState& aParentState,
|
|
|
|
nsChangeHint aHintForThisFrame, Type aType,
|
|
|
|
bool aAssertWrapperRestyleLength = true)
|
|
|
|
: mStyleSet(aParentState.mStyleSet),
|
|
|
|
mChangeList(aParentState.mChangeList),
|
|
|
|
mPendingWrapperRestyles(aParentState.mPendingWrapperRestyles),
|
|
|
|
mPendingWrapperRestyleOffset(
|
|
|
|
aParentState.mPendingWrapperRestyles.Length()),
|
|
|
|
mChangesHandled(aType == Type::InFlow
|
|
|
|
? aParentState.mChangesHandled | aHintForThisFrame
|
|
|
|
: aHintForThisFrame)
|
|
|
|
#ifdef DEBUG
|
|
|
|
,
|
|
|
|
mOwner(&aOwner),
|
|
|
|
mAssertWrapperRestyleLength(aAssertWrapperRestyleLength)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (aType == Type::InFlow) {
|
|
|
|
AssertOwner(aParentState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~ServoRestyleState() {
|
|
|
|
MOZ_ASSERT(
|
|
|
|
!mAssertWrapperRestyleLength ||
|
|
|
|
mPendingWrapperRestyles.Length() == mPendingWrapperRestyleOffset,
|
|
|
|
"Someone forgot to call ProcessWrapperRestyles!");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsStyleChangeList& ChangeList() { return mChangeList; }
|
|
|
|
ServoStyleSet& StyleSet() { return mStyleSet; }
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void AssertOwner(const ServoRestyleState& aParentState) const;
|
2018-09-21 20:45:49 +03:00
|
|
|
nsChangeHint ChangesHandledFor(const nsIFrame*) const;
|
2018-04-05 21:55:51 +03:00
|
|
|
#else
|
|
|
|
void AssertOwner(const ServoRestyleState&) const {}
|
2018-09-21 20:45:49 +03:00
|
|
|
nsChangeHint ChangesHandledFor(const nsIFrame*) const {
|
2018-04-05 21:55:51 +03:00
|
|
|
return mChangesHandled;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Add a pending wrapper restyle. We don't have to do anything if the thing
|
|
|
|
// being added is already last in the list, but otherwise we do want to add
|
|
|
|
// it, in order for ProcessWrapperRestyles to work correctly.
|
|
|
|
void AddPendingWrapperRestyle(nsIFrame* aWrapperFrame);
|
|
|
|
|
|
|
|
// Process wrapper restyles for this restyle state. This should be done
|
|
|
|
// before it comes off the stack.
|
|
|
|
void ProcessWrapperRestyles(nsIFrame* aParentFrame);
|
|
|
|
|
|
|
|
// Get the table-aware parent for the given child. This will walk through
|
|
|
|
// outer table and cellcontent frames.
|
|
|
|
static nsIFrame* TableAwareParentFor(const nsIFrame* aChild);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Process a wrapper restyle at the given index, and restyles for any
|
|
|
|
// wrappers nested in it. Returns the number of entries from
|
|
|
|
// mPendingWrapperRestyles that we processed. The return value is always at
|
|
|
|
// least 1.
|
|
|
|
size_t ProcessMaybeNestedWrapperRestyle(nsIFrame* aParent, size_t aIndex);
|
|
|
|
|
|
|
|
ServoStyleSet& mStyleSet;
|
|
|
|
nsStyleChangeList& mChangeList;
|
|
|
|
|
|
|
|
// A list of pending wrapper restyles. Anonymous box wrapper frames that need
|
|
|
|
// restyling are added to this list when their non-anonymous kids are
|
|
|
|
// restyled. This avoids us having to do linear searches along the frame tree
|
|
|
|
// for these anonymous boxes. The problem then becomes that we can have
|
|
|
|
// multiple kids all with the same anonymous parent, and we don't want to
|
|
|
|
// restyle it more than once. We use mPendingWrapperRestyles to track which
|
|
|
|
// anonymous wrapper boxes we've requested be restyled and which of them have
|
|
|
|
// already been restyled. We use a single array propagated through
|
|
|
|
// ServoRestyleStates by reference, because in a situation like this:
|
|
|
|
//
|
|
|
|
// <div style="display: table"><span></span></div>
|
|
|
|
//
|
|
|
|
// We have multiple wrappers to restyle (cell, row, table-row-group) and we
|
|
|
|
// want to add them in to the list all at once but restyle them using
|
|
|
|
// different ServoRestyleStates with different owners. When this situation
|
|
|
|
// occurs, the relevant frames will be placed in the array with ancestors
|
|
|
|
// before descendants.
|
|
|
|
nsTArray<nsIFrame*>& mPendingWrapperRestyles;
|
|
|
|
|
|
|
|
// Since we're given a possibly-nonempty mPendingWrapperRestyles to start
|
|
|
|
// with, we need to keep track of where the part of it we're responsible for
|
|
|
|
// starts.
|
|
|
|
size_t mPendingWrapperRestyleOffset;
|
|
|
|
|
|
|
|
const nsChangeHint mChangesHandled;
|
|
|
|
|
|
|
|
// We track the "owner" frame of this restyle state, that is, the frame that
|
|
|
|
// generated the last change that is stored in mChangesHandled, in order to
|
|
|
|
// verify that we only use mChangesHandled for actual descendants of that
|
|
|
|
// frame (given DOM order isn't always frame order, and that there are a few
|
|
|
|
// special cases for stuff like wrapper frames, ::backdrop, and so on).
|
|
|
|
#ifdef DEBUG
|
|
|
|
const nsIFrame* mOwner{nullptr};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Whether we should assert in our destructor that we've processed all of the
|
|
|
|
// relevant wrapper restyles.
|
|
|
|
#ifdef DEBUG
|
|
|
|
const bool mAssertWrapperRestyleLength;
|
|
|
|
#endif // DEBUG
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class ServoPostTraversalFlags : uint32_t;
|
|
|
|
|
2017-02-13 06:21:32 +03:00
|
|
|
class RestyleManager {
|
2018-04-05 21:55:51 +03:00
|
|
|
friend class ServoStyleSet;
|
|
|
|
|
2016-07-08 10:08:46 +03:00
|
|
|
public:
|
2018-04-05 21:55:51 +03:00
|
|
|
typedef ServoElementSnapshotTable SnapshotTable;
|
2016-07-08 10:08:46 +03:00
|
|
|
typedef mozilla::dom::Element Element;
|
|
|
|
|
|
|
|
// Get an integer that increments every time we process pending restyles.
|
|
|
|
// The value is never 0.
|
2017-11-28 12:42:22 +03:00
|
|
|
uint64_t GetRestyleGeneration() const { return mRestyleGeneration; }
|
2017-05-23 09:13:47 +03:00
|
|
|
// Unlike GetRestyleGeneration, which means the actual restyling count,
|
|
|
|
// GetUndisplayedRestyleGeneration represents any possible DOM changes that
|
|
|
|
// can cause restyling. This is needed for getComputedStyle to work with
|
|
|
|
// non-styled (e.g. display: none) elements.
|
2017-11-28 12:42:22 +03:00
|
|
|
uint64_t GetUndisplayedRestyleGeneration() const {
|
2017-05-23 09:13:47 +03:00
|
|
|
return mUndisplayedRestyleGeneration;
|
|
|
|
}
|
2016-07-08 10:08:46 +03:00
|
|
|
|
|
|
|
void Disconnect() { mPresContext = nullptr; }
|
|
|
|
|
2018-04-17 00:45:17 +03:00
|
|
|
~RestyleManager() {
|
|
|
|
MOZ_ASSERT(!mAnimationsWithDestroyedFrame,
|
|
|
|
"leaving dangling pointers from AnimationsWithDestroyedFrame");
|
|
|
|
MOZ_ASSERT(!mReentrantChanges);
|
|
|
|
}
|
|
|
|
|
2016-08-01 23:31:57 +03:00
|
|
|
#ifdef DEBUG
|
2016-08-05 21:54:22 +03:00
|
|
|
static nsCString ChangeHintToString(nsChangeHint aHint);
|
|
|
|
|
2016-08-01 23:31:57 +03:00
|
|
|
/**
|
|
|
|
* DEBUG ONLY method to verify integrity of style tree versus frame tree
|
|
|
|
*/
|
2017-01-11 07:46:38 +03:00
|
|
|
void DebugVerifyStyleTree(nsIFrame* aFrame);
|
2016-08-01 23:31:57 +03:00
|
|
|
#endif
|
|
|
|
|
2016-08-02 04:32:06 +03:00
|
|
|
void FlushOverflowChangedTracker() { mOverflowChangedTracker.Flush(); }
|
|
|
|
|
|
|
|
// Should be called when a frame is going to be destroyed and
|
|
|
|
// WillDestroyFrameTree hasn't been called yet.
|
|
|
|
void NotifyDestroyingFrame(nsIFrame* aFrame) {
|
|
|
|
mOverflowChangedTracker.RemoveFrame(aFrame);
|
2017-05-27 14:36:00 +03:00
|
|
|
// If ProcessRestyledFrames is tracking frames which have been
|
|
|
|
// destroyed (to avoid re-visiting them), add this one to its set.
|
|
|
|
if (mDestroyedFrames) {
|
|
|
|
mDestroyedFrames->PutEntry(aFrame);
|
|
|
|
}
|
2016-08-02 04:32:06 +03:00
|
|
|
}
|
|
|
|
|
2016-08-03 01:47:19 +03:00
|
|
|
// Note: It's the caller's responsibility to make sure to wrap a
|
|
|
|
// ProcessRestyledFrames call in a view update batch and a script blocker.
|
|
|
|
// This function does not call ProcessAttachedQueue() on the binding manager.
|
|
|
|
// If the caller wants that to happen synchronously, it needs to handle that
|
|
|
|
// itself.
|
2017-02-17 22:25:56 +03:00
|
|
|
void ProcessRestyledFrames(nsStyleChangeList& aChangeList);
|
2016-08-03 01:47:19 +03:00
|
|
|
|
2016-11-02 09:11:24 +03:00
|
|
|
bool IsInStyleRefresh() const { return mInStyleRefresh; }
|
|
|
|
|
2017-01-26 12:05:53 +03:00
|
|
|
// AnimationsWithDestroyedFrame is used to stop animations and transitions
|
|
|
|
// on elements that have no frame at the end of the restyling process.
|
|
|
|
// It only lives during the restyling process.
|
|
|
|
class MOZ_STACK_CLASS AnimationsWithDestroyedFrame final {
|
|
|
|
public:
|
|
|
|
// Construct a AnimationsWithDestroyedFrame object. The caller must
|
|
|
|
// ensure that aRestyleManager lives at least as long as the
|
|
|
|
// object. (This is generally easy since the caller is typically a
|
|
|
|
// method of RestyleManager.)
|
2017-02-13 06:21:32 +03:00
|
|
|
explicit AnimationsWithDestroyedFrame(RestyleManager* aRestyleManager);
|
2017-01-26 12:05:53 +03:00
|
|
|
|
|
|
|
// This method takes the content node for the generated content for
|
|
|
|
// animation/transition on ::before and ::after, rather than the
|
|
|
|
// content node for the real element.
|
2018-03-22 21:20:41 +03:00
|
|
|
void Put(nsIContent* aContent, ComputedStyle* aComputedStyle) {
|
2017-01-26 12:05:53 +03:00
|
|
|
MOZ_ASSERT(aContent);
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType pseudoType = aComputedStyle->GetPseudoType();
|
|
|
|
if (pseudoType == PseudoStyleType::NotPseudo) {
|
2017-01-26 12:05:53 +03:00
|
|
|
mContents.AppendElement(aContent);
|
2019-02-19 16:44:33 +03:00
|
|
|
} else if (pseudoType == PseudoStyleType::before) {
|
2017-01-26 12:05:53 +03:00
|
|
|
MOZ_ASSERT(aContent->NodeInfo()->NameAtom() ==
|
|
|
|
nsGkAtoms::mozgeneratedcontentbefore);
|
|
|
|
mBeforeContents.AppendElement(aContent->GetParent());
|
2019-02-19 16:44:33 +03:00
|
|
|
} else if (pseudoType == PseudoStyleType::after) {
|
2017-01-26 12:05:53 +03:00
|
|
|
MOZ_ASSERT(aContent->NodeInfo()->NameAtom() ==
|
|
|
|
nsGkAtoms::mozgeneratedcontentafter);
|
|
|
|
mAfterContents.AppendElement(aContent->GetParent());
|
2019-03-26 07:48:26 +03:00
|
|
|
} else if (pseudoType == PseudoStyleType::marker) {
|
|
|
|
MOZ_ASSERT(aContent->NodeInfo()->NameAtom() ==
|
|
|
|
nsGkAtoms::mozgeneratedcontentmarker);
|
|
|
|
mMarkerContents.AppendElement(aContent->GetParent());
|
2017-01-26 12:05:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StopAnimationsForElementsWithoutFrames();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void StopAnimationsWithoutFrame(nsTArray<RefPtr<nsIContent>>& aArray,
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType aPseudoType);
|
2017-01-26 12:05:53 +03:00
|
|
|
|
2017-02-13 06:21:32 +03:00
|
|
|
RestyleManager* mRestyleManager;
|
2017-01-26 12:05:53 +03:00
|
|
|
AutoRestore<AnimationsWithDestroyedFrame*> mRestorePointer;
|
|
|
|
|
|
|
|
// Below three arrays might include elements that have already had their
|
|
|
|
// animations or transitions stopped.
|
|
|
|
//
|
2019-03-26 07:48:26 +03:00
|
|
|
// mBeforeContents, mAfterContents and mMarkerContents hold the real element
|
|
|
|
// rather than the content node for the generated content (which might
|
|
|
|
// change during a reframe)
|
2017-01-26 12:05:53 +03:00
|
|
|
nsTArray<RefPtr<nsIContent>> mContents;
|
|
|
|
nsTArray<RefPtr<nsIContent>> mBeforeContents;
|
|
|
|
nsTArray<RefPtr<nsIContent>> mAfterContents;
|
2019-03-26 07:48:26 +03:00
|
|
|
nsTArray<RefPtr<nsIContent>> mMarkerContents;
|
2017-01-26 12:05:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the current AnimationsWithDestroyedFrame struct, or null if we're
|
|
|
|
* not currently in a restyling operation.
|
|
|
|
*/
|
|
|
|
AnimationsWithDestroyedFrame* GetAnimationsWithDestroyedFrame() {
|
|
|
|
return mAnimationsWithDestroyedFrame;
|
|
|
|
}
|
|
|
|
|
2018-04-02 06:30:51 +03:00
|
|
|
void ContentInserted(nsIContent* aChild);
|
|
|
|
void ContentAppended(nsIContent* aFirstNewContent);
|
2017-02-13 06:21:33 +03:00
|
|
|
|
2017-02-13 06:21:33 +03:00
|
|
|
// This would be have the same logic as RestyleForInsertOrChange if we got the
|
|
|
|
// notification before the removal. However, we get it after, so we need the
|
2018-04-02 06:30:51 +03:00
|
|
|
// following sibling in addition to the old child.
|
|
|
|
//
|
|
|
|
// aFollowingSibling is the sibling that used to come after aOldChild before
|
|
|
|
// the removal.
|
|
|
|
void ContentRemoved(nsIContent* aOldChild, nsIContent* aFollowingSibling);
|
2017-02-13 06:21:33 +03:00
|
|
|
|
|
|
|
// Restyling for a ContentInserted (notification after insertion) or
|
2018-04-02 06:30:51 +03:00
|
|
|
// for some CharacterDataChanged.
|
|
|
|
void RestyleForInsertOrChange(nsIContent* aChild);
|
2017-02-13 06:21:33 +03:00
|
|
|
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
// Restyle for a CharacterDataChanged notification. In practice this can only
|
|
|
|
// affect :empty / :-moz-only-whitespace / :-moz-first-node / :-moz-last-node.
|
|
|
|
void CharacterDataChanged(nsIContent*, const CharacterDataChangeInfo&);
|
2017-02-13 06:21:33 +03:00
|
|
|
|
2019-03-14 14:47:50 +03:00
|
|
|
void PostRestyleEvent(dom::Element*, RestyleHint,
|
2018-04-05 21:55:51 +03:00
|
|
|
nsChangeHint aMinChangeHint);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Posts restyle hints for animations.
|
|
|
|
* This is only called for the second traversal for CSS animations during
|
|
|
|
* updating CSS animations in a SequentialTask.
|
|
|
|
* This function does neither register a refresh observer nor flag that a
|
|
|
|
* style flush is needed since this function is supposed to be called during
|
|
|
|
* restyling process and this restyle event will be processed in the second
|
|
|
|
* traversal of the same restyling process.
|
|
|
|
*/
|
2019-02-19 16:44:33 +03:00
|
|
|
void PostRestyleEventForAnimations(dom::Element*, PseudoStyleType,
|
2019-03-14 14:47:50 +03:00
|
|
|
RestyleHint);
|
2018-04-05 21:55:51 +03:00
|
|
|
|
2018-05-11 19:37:47 +03:00
|
|
|
void NextRestyleIsForCSSRuleChanges() { mRestyleForCSSRuleChanges = true; }
|
2018-04-05 21:55:51 +03:00
|
|
|
|
2019-03-14 14:47:50 +03:00
|
|
|
void RebuildAllStyleData(nsChangeHint aExtraHint, RestyleHint);
|
|
|
|
void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint, RestyleHint);
|
2018-04-05 21:55:51 +03:00
|
|
|
|
|
|
|
void ProcessPendingRestyles();
|
|
|
|
void ProcessAllPendingAttributeAndStateInvalidations();
|
|
|
|
|
|
|
|
void ContentStateChanged(nsIContent* aContent, EventStates aStateMask);
|
|
|
|
void AttributeWillChange(Element* aElement, int32_t aNameSpaceID,
|
2019-01-29 18:27:02 +03:00
|
|
|
nsAtom* aAttribute, int32_t aModType);
|
2018-04-05 21:55:51 +03:00
|
|
|
void ClassAttributeWillBeChangedBySMIL(dom::Element* aElement);
|
|
|
|
void AttributeChanged(dom::Element* aElement, int32_t aNameSpaceID,
|
|
|
|
nsAtom* aAttribute, int32_t aModType,
|
|
|
|
const nsAttrValue* aOldValue);
|
|
|
|
|
|
|
|
// This is only used to reparent things when moving them in/out of the
|
2018-04-06 04:14:09 +03:00
|
|
|
// ::first-line.
|
|
|
|
void ReparentComputedStyleForFirstLine(nsIFrame*);
|
2018-04-05 21:55:51 +03:00
|
|
|
|
|
|
|
bool HasPendingRestyleAncestor(dom::Element* aElement) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs a Servo animation-only traversal to compute style for all nodes
|
|
|
|
* with the animation-only dirty bit in the document.
|
|
|
|
*
|
|
|
|
* This processes just the traversal for animation-only restyles and skips the
|
|
|
|
* normal traversal for other restyles unrelated to animations.
|
|
|
|
* This is used to bring throttled animations up-to-date such as when we need
|
|
|
|
* to get correct position for transform animations that are throttled because
|
|
|
|
* they are running on the compositor.
|
|
|
|
*
|
|
|
|
* This will traverse all of the document's style roots (that is, its document
|
|
|
|
* element, and the roots of the document-level native anonymous content).
|
|
|
|
*/
|
|
|
|
void UpdateOnlyAnimationStyles();
|
2017-05-19 11:16:41 +03:00
|
|
|
|
2017-03-09 12:15:08 +03:00
|
|
|
// Get a counter that increments on every style change, that we use to
|
|
|
|
// track whether off-main-thread animations are up-to-date.
|
|
|
|
uint64_t GetAnimationGeneration() const { return mAnimationGeneration; }
|
|
|
|
|
2019-03-18 07:12:14 +03:00
|
|
|
// Typically only style frames have animations associated with them so this
|
|
|
|
// will likely return zero for anything that is not a style frame.
|
|
|
|
static uint64_t GetAnimationGenerationForFrame(nsIFrame* aStyleFrame);
|
2017-03-09 12:15:08 +03:00
|
|
|
|
|
|
|
// Update the animation generation count to mark that animation state
|
|
|
|
// has changed.
|
|
|
|
//
|
|
|
|
// This is normally performed automatically by ProcessPendingRestyles
|
|
|
|
// but it is also called when we have out-of-band changes to animations
|
|
|
|
// such as changes made through the Web Animations API.
|
|
|
|
void IncrementAnimationGeneration();
|
|
|
|
|
2018-07-30 05:13:54 +03:00
|
|
|
// Apply change hints for animations on the compositor.
|
|
|
|
//
|
|
|
|
// There are some cases where we forcibly apply change hints for animations
|
|
|
|
// even if there is no change hint produced in order to synchronize with
|
|
|
|
// animations running on the compositor.
|
|
|
|
//
|
|
|
|
// For example:
|
|
|
|
//
|
|
|
|
// a) Pausing animations via the Web Animations API
|
|
|
|
// b) When the style before sending the animation to the compositor exactly
|
|
|
|
// the same as the current style
|
2017-05-02 09:03:16 +03:00
|
|
|
static void AddLayerChangesForAnimation(
|
2018-07-30 05:13:54 +03:00
|
|
|
nsIFrame* aFrame, nsIContent* aContent, nsChangeHint aHintForThisFrame,
|
2017-05-02 09:03:16 +03:00
|
|
|
nsStyleChangeList& aChangeListToProcess);
|
|
|
|
|
2018-04-05 21:55:51 +03:00
|
|
|
/**
|
|
|
|
* Whether to clear all the style data (including the element itself), or just
|
|
|
|
* the descendants' data.
|
|
|
|
*/
|
|
|
|
enum class IncludeRoot {
|
|
|
|
Yes,
|
|
|
|
No,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears the ServoElementData and HasDirtyDescendants from all elements
|
|
|
|
* in the subtree rooted at aElement.
|
|
|
|
*/
|
|
|
|
static void ClearServoDataFromSubtree(Element*,
|
|
|
|
IncludeRoot = IncludeRoot::Yes);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears HasDirtyDescendants and RestyleData from all elements in the
|
|
|
|
* subtree rooted at aElement.
|
|
|
|
*/
|
|
|
|
static void ClearRestyleStateFromSubtree(Element* aElement);
|
|
|
|
|
2018-03-28 18:34:34 +03:00
|
|
|
explicit RestyleManager(nsPresContext* aPresContext);
|
2017-02-13 06:21:33 +03:00
|
|
|
|
2018-04-05 21:55:51 +03:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Reparent the descendants of aFrame. This is used by ReparentComputedStyle
|
|
|
|
* and shouldn't be called by anyone else. aProviderChild, if non-null, is a
|
|
|
|
* child that was the style parent for aFrame and hence shouldn't be
|
|
|
|
* reparented.
|
|
|
|
*/
|
|
|
|
void ReparentFrameDescendants(nsIFrame* aFrame, nsIFrame* aProviderChild,
|
|
|
|
ServoStyleSet& aStyleSet);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs post-Servo-traversal processing on this element and its
|
|
|
|
* descendants.
|
|
|
|
*
|
|
|
|
* Returns whether any style did actually change. There may be cases where we
|
|
|
|
* didn't need to change any style after all, for example, when a content
|
|
|
|
* attribute changes that happens not to have any effect on the style of that
|
|
|
|
* element or any descendant or sibling.
|
|
|
|
*/
|
|
|
|
bool ProcessPostTraversal(Element* aElement, ComputedStyle* aParentContext,
|
|
|
|
ServoRestyleState& aRestyleState,
|
|
|
|
ServoPostTraversalFlags aFlags);
|
|
|
|
|
|
|
|
struct TextPostTraversalState;
|
|
|
|
bool ProcessPostTraversalForText(nsIContent* aTextNode,
|
|
|
|
TextPostTraversalState& aState,
|
|
|
|
ServoRestyleState& aRestyleState,
|
|
|
|
ServoPostTraversalFlags aFlags);
|
|
|
|
|
|
|
|
ServoStyleSet* StyleSet() const { return PresContext()->StyleSet(); }
|
|
|
|
|
2017-02-13 06:21:33 +03:00
|
|
|
void RestyleForEmptyChange(Element* aContainer);
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
void MaybeRestyleForEdgeChildChange(Element* aContainer,
|
|
|
|
nsIContent* aChangedChild);
|
2017-02-13 06:21:33 +03:00
|
|
|
|
2018-04-05 21:55:51 +03:00
|
|
|
bool IsDisconnected() const { return !mPresContext; }
|
2016-07-08 10:08:46 +03:00
|
|
|
|
|
|
|
void IncrementRestyleGeneration() {
|
|
|
|
if (++mRestyleGeneration == 0) {
|
|
|
|
// Keep mRestyleGeneration from being 0, since that's what
|
|
|
|
// nsPresContext::GetRestyleGeneration returns when it no
|
|
|
|
// longer has a RestyleManager.
|
|
|
|
++mRestyleGeneration;
|
|
|
|
}
|
2017-05-23 09:13:47 +03:00
|
|
|
IncrementUndisplayedRestyleGeneration();
|
|
|
|
}
|
|
|
|
|
|
|
|
void IncrementUndisplayedRestyleGeneration() {
|
|
|
|
if (++mUndisplayedRestyleGeneration == 0) {
|
|
|
|
// Ensure mUndisplayedRestyleGeneration > 0, for the same reason as
|
|
|
|
// IncrementRestyleGeneration.
|
|
|
|
++mUndisplayedRestyleGeneration;
|
|
|
|
}
|
2016-07-08 10:08:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext* PresContext() const {
|
|
|
|
MOZ_ASSERT(mPresContext);
|
|
|
|
return mPresContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSFrameConstructor* FrameConstructor() const {
|
|
|
|
return PresContext()->FrameConstructor();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsPresContext* mPresContext; // weak, can be null after Disconnect().
|
2017-11-28 12:42:22 +03:00
|
|
|
uint64_t mRestyleGeneration;
|
|
|
|
uint64_t mUndisplayedRestyleGeneration;
|
2017-02-13 06:21:32 +03:00
|
|
|
|
2017-05-27 14:36:00 +03:00
|
|
|
// Used to keep track of frames that have been destroyed during
|
|
|
|
// ProcessRestyledFrames, so we don't try to touch them again even if
|
|
|
|
// they're referenced again later in the changelist.
|
|
|
|
mozilla::UniquePtr<nsTHashtable<nsPtrHashKey<const nsIFrame>>>
|
|
|
|
mDestroyedFrames;
|
|
|
|
|
2017-07-09 04:29:18 +03:00
|
|
|
protected:
|
2016-08-04 04:58:06 +03:00
|
|
|
// True if we're in the middle of a nsRefreshDriver refresh
|
|
|
|
bool mInStyleRefresh;
|
|
|
|
|
2017-03-09 12:15:08 +03:00
|
|
|
// The total number of animation flushes by this frame constructor.
|
|
|
|
// Used to keep the layer and animation manager in sync.
|
|
|
|
uint64_t mAnimationGeneration;
|
|
|
|
|
2016-08-02 04:32:06 +03:00
|
|
|
OverflowChangedTracker mOverflowChangedTracker;
|
|
|
|
|
2017-01-26 12:05:53 +03:00
|
|
|
AnimationsWithDestroyedFrame* mAnimationsWithDestroyedFrame = nullptr;
|
2017-02-13 06:21:32 +03:00
|
|
|
|
2018-04-05 21:55:51 +03:00
|
|
|
const SnapshotTable& Snapshots() const { return mSnapshots; }
|
|
|
|
void ClearSnapshots();
|
2018-08-07 02:44:56 +03:00
|
|
|
ServoElementSnapshot& SnapshotFor(Element&);
|
|
|
|
void TakeSnapshotForAttributeChange(Element&, int32_t aNameSpaceID,
|
2018-04-05 21:55:51 +03:00
|
|
|
nsAtom* aAttribute);
|
|
|
|
|
|
|
|
void DoProcessPendingRestyles(ServoTraversalFlags aFlags);
|
|
|
|
|
2018-04-06 04:14:09 +03:00
|
|
|
// Function to do the actual (recursive) work of
|
|
|
|
// ReparentComputedStyleForFirstLine, once we have asserted the invariants
|
|
|
|
// that only hold on the initial call.
|
|
|
|
void DoReparentComputedStyleForFirstLine(nsIFrame*, ServoStyleSet&);
|
2018-04-05 21:55:51 +03:00
|
|
|
|
|
|
|
// We use a separate data structure from nsStyleChangeList because we need a
|
|
|
|
// frame to create nsStyleChangeList entries, and the primary frame may not be
|
|
|
|
// attached yet.
|
|
|
|
struct ReentrantChange {
|
|
|
|
nsCOMPtr<nsIContent> mContent;
|
|
|
|
nsChangeHint mHint;
|
|
|
|
};
|
|
|
|
typedef AutoTArray<ReentrantChange, 10> ReentrantChangeList;
|
|
|
|
|
|
|
|
// Only non-null while processing change hints. See the comment in
|
|
|
|
// ProcessPendingRestyles.
|
|
|
|
ReentrantChangeList* mReentrantChanges = nullptr;
|
|
|
|
|
|
|
|
// We use this flag to track if the current restyle contains any non-animation
|
|
|
|
// update, which triggers a normal restyle, and so there might be any new
|
|
|
|
// transition created later. Therefore, if this flag is true, we need to
|
|
|
|
// increase mAnimationGeneration before creating new transitions, so their
|
|
|
|
// creation sequence will be correct.
|
|
|
|
bool mHaveNonAnimationRestyles = false;
|
|
|
|
|
|
|
|
// Set to true when posting restyle events triggered by CSS rule changes.
|
|
|
|
// This flag is cleared once ProcessPendingRestyles has completed.
|
|
|
|
// When we process a traversal all descendants elements of the document
|
|
|
|
// triggered by CSS rule changes, we will need to update all elements with
|
|
|
|
// CSS animations. We propagate TraversalRestyleBehavior::ForCSSRuleChanges
|
|
|
|
// to traversal function if this flag is set.
|
|
|
|
bool mRestyleForCSSRuleChanges = false;
|
|
|
|
|
|
|
|
// A hashtable with the elements that have changed state or attributes, in
|
|
|
|
// order to calculate restyle hints during the traversal.
|
|
|
|
SnapshotTable mSnapshots;
|
2016-07-08 10:08:46 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|