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
|
|
|
|
2016-08-02 04:32:06 +03:00
|
|
|
#include "mozilla/OverflowChangedTracker.h"
|
2016-07-08 10:08:46 +03:00
|
|
|
#include "nsChangeHint.h"
|
2016-08-29 18:19:49 +03:00
|
|
|
#include "nsPresContext.h"
|
2017-08-17 02:48:52 +03:00
|
|
|
#include "nsStringFwd.h"
|
2016-07-08 10:08:46 +03:00
|
|
|
|
2016-08-29 18:19:49 +03:00
|
|
|
class nsCSSFrameConstructor;
|
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;
|
2017-02-13 06:21:32 +03:00
|
|
|
class GeckoRestyleManager;
|
2016-08-29 18:19:49 +03:00
|
|
|
class ServoRestyleManager;
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
}
|
2016-07-08 10:08:46 +03:00
|
|
|
|
|
|
|
/**
|
2017-02-13 06:21:32 +03:00
|
|
|
* Class for sharing data and logic common to both GeckoRestyleManager and
|
2016-07-08 10:08:46 +03:00
|
|
|
* ServoRestyleManager.
|
|
|
|
*/
|
2017-02-13 06:21:32 +03:00
|
|
|
class RestyleManager
|
2016-07-08 10:08:46 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef mozilla::dom::Element Element;
|
|
|
|
|
2017-02-13 06:21:33 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(mozilla::RestyleManager)
|
|
|
|
|
2016-07-08 10:08:46 +03:00
|
|
|
// 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
|
|
|
|
|
|
|
// Get an integer that increments every time there is a style change
|
|
|
|
// as a result of a change to the :hover content state.
|
|
|
|
uint32_t GetHoverGeneration() const { return mHoverGeneration; }
|
|
|
|
|
|
|
|
void Disconnect() { mPresContext = nullptr; }
|
|
|
|
|
2016-07-23 01:27:05 +03:00
|
|
|
static nsCString RestyleHintToString(nsRestyleHint aHint);
|
|
|
|
|
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);
|
2018-03-22 21:20:41 +03:00
|
|
|
CSSPseudoElementType pseudoType = aComputedStyle->GetPseudoType();
|
2017-01-26 12:05:53 +03:00
|
|
|
if (pseudoType == CSSPseudoElementType::NotPseudo) {
|
|
|
|
mContents.AppendElement(aContent);
|
|
|
|
} else if (pseudoType == CSSPseudoElementType::before) {
|
|
|
|
MOZ_ASSERT(aContent->NodeInfo()->NameAtom() ==
|
|
|
|
nsGkAtoms::mozgeneratedcontentbefore);
|
|
|
|
mBeforeContents.AppendElement(aContent->GetParent());
|
|
|
|
} else if (pseudoType == CSSPseudoElementType::after) {
|
|
|
|
MOZ_ASSERT(aContent->NodeInfo()->NameAtom() ==
|
|
|
|
nsGkAtoms::mozgeneratedcontentafter);
|
|
|
|
mAfterContents.AppendElement(aContent->GetParent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StopAnimationsForElementsWithoutFrames();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void StopAnimationsWithoutFrame(nsTArray<RefPtr<nsIContent>>& aArray,
|
|
|
|
CSSPseudoElementType aPseudoType);
|
|
|
|
|
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.
|
|
|
|
//
|
|
|
|
// mBeforeContents and mAfterContents hold the real element rather than
|
|
|
|
// the content node for the generated content (which might change during
|
|
|
|
// a reframe)
|
|
|
|
nsTArray<RefPtr<nsIContent>> mContents;
|
|
|
|
nsTArray<RefPtr<nsIContent>> mBeforeContents;
|
|
|
|
nsTArray<RefPtr<nsIContent>> mAfterContents;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the current AnimationsWithDestroyedFrame struct, or null if we're
|
|
|
|
* not currently in a restyling operation.
|
|
|
|
*/
|
|
|
|
AnimationsWithDestroyedFrame* GetAnimationsWithDestroyedFrame() {
|
|
|
|
return mAnimationsWithDestroyedFrame;
|
|
|
|
}
|
|
|
|
|
2017-02-13 06:21:33 +03:00
|
|
|
void ContentInserted(nsINode* aContainer, nsIContent* aChild);
|
|
|
|
void ContentAppended(nsIContent* aContainer, nsIContent* aFirstNewContent);
|
|
|
|
|
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
|
|
|
|
// following sibling in addition to the old child. |aContainer| must be
|
|
|
|
// non-null; when the container is null, no work is needed. aFollowingSibling
|
|
|
|
// is the sibling that used to come after aOldChild before the removal.
|
|
|
|
void ContentRemoved(nsINode* aContainer,
|
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aFollowingSibling);
|
|
|
|
|
|
|
|
// Restyling for a ContentInserted (notification after insertion) or
|
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
|
|
|
// for some CharacterDataChanged. |aContainer| must be non-null; when
|
2017-02-13 06:21:33 +03:00
|
|
|
// the container is null, no work is needed.
|
|
|
|
void RestyleForInsertOrChange(nsINode* aContainer, nsIContent* aChild);
|
|
|
|
|
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
|
|
|
|
2017-02-13 06:21:33 +03:00
|
|
|
MOZ_DECL_STYLO_METHODS(GeckoRestyleManager, ServoRestyleManager)
|
|
|
|
|
|
|
|
inline void PostRestyleEvent(dom::Element* aElement,
|
|
|
|
nsRestyleHint aRestyleHint,
|
|
|
|
nsChangeHint aMinChangeHint);
|
|
|
|
inline void RebuildAllStyleData(nsChangeHint aExtraHint,
|
|
|
|
nsRestyleHint aRestyleHint);
|
|
|
|
inline void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
|
|
|
|
nsRestyleHint aRestyleHint);
|
|
|
|
inline void ProcessPendingRestyles();
|
2017-03-19 14:00:50 +03:00
|
|
|
inline void ContentStateChanged(nsIContent* aContent,
|
|
|
|
EventStates aStateMask);
|
2017-02-13 06:21:33 +03:00
|
|
|
inline void AttributeWillChange(dom::Element* aElement,
|
|
|
|
int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute,
|
2017-02-13 06:21:33 +03:00
|
|
|
int32_t aModType,
|
|
|
|
const nsAttrValue* aNewValue);
|
|
|
|
inline void AttributeChanged(dom::Element* aElement,
|
|
|
|
int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute,
|
2017-02-13 06:21:33 +03:00
|
|
|
int32_t aModType,
|
|
|
|
const nsAttrValue* aOldValue);
|
2018-03-22 21:20:41 +03:00
|
|
|
inline nsresult ReparentComputedStyle(nsIFrame* aFrame);
|
2017-02-13 06:21:33 +03:00
|
|
|
|
2017-08-14 16:16:28 +03:00
|
|
|
inline 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; }
|
|
|
|
|
|
|
|
static uint64_t GetAnimationGenerationForFrame(nsIFrame* aFrame);
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
2017-05-02 09:03:16 +03:00
|
|
|
static void AddLayerChangesForAnimation(nsIFrame* aFrame,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsStyleChangeList&
|
|
|
|
aChangeListToProcess);
|
|
|
|
|
2016-07-08 10:08:46 +03:00
|
|
|
protected:
|
2018-03-28 18:34:34 +03:00
|
|
|
explicit RestyleManager(nsPresContext* aPresContext);
|
2017-02-13 06:21:33 +03:00
|
|
|
|
|
|
|
virtual ~RestyleManager()
|
|
|
|
{
|
2017-01-26 12:05:53 +03:00
|
|
|
MOZ_ASSERT(!mAnimationsWithDestroyedFrame,
|
|
|
|
"leaving dangling pointers from AnimationsWithDestroyedFrame");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2016-07-08 10:08:46 +03:00
|
|
|
void ContentStateChangedInternal(Element* aElement,
|
|
|
|
EventStates aStateMask,
|
2017-08-30 01:50:50 +03:00
|
|
|
nsChangeHint* aOutChangeHint);
|
2016-07-08 10:08:46 +03:00
|
|
|
|
|
|
|
bool IsDisconnected() { return mPresContext == nullptr; }
|
|
|
|
|
|
|
|
void IncrementHoverGeneration() {
|
|
|
|
++mHoverGeneration;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2016-07-08 10:08:46 +03:00
|
|
|
uint32_t mHoverGeneration;
|
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
|
|
|
|
|
|
|
friend class mozilla::GeckoRestyleManager;
|
|
|
|
friend class mozilla::ServoRestyleManager;
|
2016-07-08 10:08:46 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|