2010-06-18 09:23:04 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2010-06-18 09:23:04 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A class which manages pending restyles. This handles keeping track
|
|
|
|
* of what nodes restyles need to happen on and so forth.
|
|
|
|
*/
|
|
|
|
|
2013-07-20 12:14:24 -07:00
|
|
|
#ifndef mozilla_RestyleTracker_h
|
|
|
|
#define mozilla_RestyleTracker_h
|
2010-06-18 12:35:52 -07:00
|
|
|
|
2010-06-18 09:23:04 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2014-09-04 20:48:48 -07:00
|
|
|
#include "nsClassHashtable.h"
|
2014-05-24 15:20:39 -07:00
|
|
|
#include "nsContainerFrame.h"
|
2013-01-15 15:12:40 -08:00
|
|
|
#include "mozilla/SplayTree.h"
|
2010-06-18 09:23:04 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2013-07-20 12:14:25 -07:00
|
|
|
class RestyleManager;
|
2014-08-03 13:11:55 -07:00
|
|
|
class ElementRestyler;
|
2013-07-20 12:14:25 -07:00
|
|
|
|
2012-12-09 18:32:55 -08:00
|
|
|
/**
|
|
|
|
* Helper class that collects a list of frames that need
|
|
|
|
* UpdateOverflow() called on them, and coalesces them
|
|
|
|
* to avoid walking up the same ancestor tree multiple times.
|
|
|
|
*/
|
|
|
|
class OverflowChangedTracker
|
|
|
|
{
|
|
|
|
public:
|
2014-03-13 17:21:25 -07:00
|
|
|
enum ChangeKind {
|
|
|
|
/**
|
|
|
|
* The frame was explicitly added as a result of
|
|
|
|
* nsChangeHint_UpdatePostTransformOverflow and hence may have had a style
|
|
|
|
* change that changes its geometry relative to parent, without reflowing.
|
|
|
|
*/
|
|
|
|
TRANSFORM_CHANGED,
|
|
|
|
/**
|
|
|
|
* The overflow areas of children have changed
|
|
|
|
* and we need to call UpdateOverflow on the frame.
|
|
|
|
*/
|
|
|
|
CHILDREN_CHANGED,
|
|
|
|
/**
|
|
|
|
* The overflow areas of children have changed
|
|
|
|
* and we need to call UpdateOverflow on the frame.
|
|
|
|
* Also call UpdateOverflow on the parent even if the
|
|
|
|
* overflow areas of the frame does not change.
|
|
|
|
*/
|
|
|
|
CHILDREN_AND_PARENT_CHANGED
|
|
|
|
};
|
2012-12-09 18:32:55 -08:00
|
|
|
|
2013-09-06 06:35:16 -07:00
|
|
|
OverflowChangedTracker() :
|
|
|
|
mSubtreeRoot(nullptr)
|
|
|
|
{}
|
|
|
|
|
2013-02-19 16:13:01 -08:00
|
|
|
~OverflowChangedTracker()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mEntryList.empty(), "Need to flush before destroying!");
|
|
|
|
}
|
|
|
|
|
2012-12-09 18:32:55 -08:00
|
|
|
/**
|
|
|
|
* Add a frame that has had a style change, and needs its
|
|
|
|
* overflow updated.
|
|
|
|
*
|
|
|
|
* If there are pre-transform overflow areas stored for this
|
|
|
|
* frame, then we will call FinishAndStoreOverflow with those
|
|
|
|
* areas instead of UpdateOverflow().
|
|
|
|
*
|
|
|
|
* If the overflow area changes, then UpdateOverflow will also
|
|
|
|
* be called on the parent.
|
|
|
|
*/
|
2014-03-13 17:21:25 -07:00
|
|
|
void AddFrame(nsIFrame* aFrame, ChangeKind aChangeKind) {
|
2013-03-20 19:33:00 -07:00
|
|
|
uint32_t depth = aFrame->GetDepthInFrameTree();
|
2014-03-13 17:21:25 -07:00
|
|
|
Entry *entry = nullptr;
|
|
|
|
if (!mEntryList.empty()) {
|
|
|
|
entry = mEntryList.find(Entry(aFrame, depth));
|
|
|
|
}
|
|
|
|
if (entry == nullptr) {
|
|
|
|
// Add new entry.
|
|
|
|
mEntryList.insert(new Entry(aFrame, depth, aChangeKind));
|
|
|
|
} else {
|
|
|
|
// Update the existing entry if the new value is stronger.
|
|
|
|
entry->mChangeKind = std::max(entry->mChangeKind, aChangeKind);
|
2013-01-15 15:12:40 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-25 17:34:58 -08:00
|
|
|
* Remove a frame.
|
2013-01-15 15:12:40 -08:00
|
|
|
*/
|
2013-01-25 17:34:58 -08:00
|
|
|
void RemoveFrame(nsIFrame* aFrame) {
|
2013-03-20 19:33:00 -07:00
|
|
|
if (mEntryList.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t depth = aFrame->GetDepthInFrameTree();
|
2013-12-13 05:21:03 -08:00
|
|
|
if (mEntryList.find(Entry(aFrame, depth))) {
|
|
|
|
delete mEntryList.remove(Entry(aFrame, depth));
|
2013-01-15 15:12:40 -08:00
|
|
|
}
|
2012-12-09 18:32:55 -08:00
|
|
|
}
|
|
|
|
|
2013-09-06 06:35:16 -07:00
|
|
|
/**
|
|
|
|
* Set the subtree root to limit overflow updates. This must be set if and
|
|
|
|
* only if currently reflowing aSubtreeRoot, to ensure overflow changes will
|
|
|
|
* still propagate correctly.
|
|
|
|
*/
|
|
|
|
void SetSubtreeRoot(const nsIFrame* aSubtreeRoot) {
|
|
|
|
mSubtreeRoot = aSubtreeRoot;
|
|
|
|
}
|
|
|
|
|
2012-12-09 18:32:55 -08:00
|
|
|
/**
|
|
|
|
* Update the overflow of all added frames, and clear the entry list.
|
|
|
|
*
|
|
|
|
* Start from those deepest in the frame tree and works upwards. This stops
|
|
|
|
* us from processing the same frame twice.
|
|
|
|
*/
|
|
|
|
void Flush() {
|
2013-01-15 15:12:40 -08:00
|
|
|
while (!mEntryList.empty()) {
|
|
|
|
Entry *entry = mEntryList.removeMin();
|
|
|
|
nsIFrame *frame = entry->mFrame;
|
2012-12-09 18:32:55 -08:00
|
|
|
|
2014-03-13 17:21:25 -07:00
|
|
|
bool overflowChanged = false;
|
|
|
|
if (entry->mChangeKind == CHILDREN_AND_PARENT_CHANGED) {
|
2013-12-13 05:21:03 -08:00
|
|
|
// Need to union the overflow areas of the children.
|
2014-03-13 17:21:25 -07:00
|
|
|
// Always update the parent, even if the overflow does not change.
|
|
|
|
frame->UpdateOverflow();
|
|
|
|
overflowChanged = true;
|
|
|
|
} else if (entry->mChangeKind == CHILDREN_CHANGED) {
|
|
|
|
// Need to union the overflow areas of the children.
|
|
|
|
// Only update the parent if the overflow changes.
|
2013-12-13 05:21:03 -08:00
|
|
|
overflowChanged = frame->UpdateOverflow();
|
|
|
|
} else {
|
2014-03-13 17:21:25 -07:00
|
|
|
// Take a faster path that doesn't require unioning the overflow areas
|
|
|
|
// of our children.
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool hasInitialOverflowPropertyApplied = false;
|
|
|
|
frame->Properties().Get(nsIFrame::DebugInitialOverflowPropertyApplied(),
|
|
|
|
&hasInitialOverflowPropertyApplied);
|
|
|
|
NS_ASSERTION(hasInitialOverflowPropertyApplied,
|
|
|
|
"InitialOverflowProperty must be set first.");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsOverflowAreas* overflow =
|
|
|
|
static_cast<nsOverflowAreas*>(frame->Properties().Get(nsIFrame::InitialOverflowProperty()));
|
|
|
|
if (overflow) {
|
2012-12-09 18:32:55 -08:00
|
|
|
// FinishAndStoreOverflow will change the overflow areas passed in,
|
|
|
|
// so make a copy.
|
2014-03-13 17:21:25 -07:00
|
|
|
nsOverflowAreas overflowCopy = *overflow;
|
|
|
|
frame->FinishAndStoreOverflow(overflowCopy, frame->GetSize());
|
2013-12-13 05:21:03 -08:00
|
|
|
} else {
|
2014-03-13 17:21:25 -07:00
|
|
|
nsRect bounds(nsPoint(0, 0), frame->GetSize());
|
|
|
|
nsOverflowAreas boundsOverflow;
|
|
|
|
boundsOverflow.SetAllTo(bounds);
|
|
|
|
frame->FinishAndStoreOverflow(boundsOverflow, bounds.Size());
|
2012-12-09 18:32:55 -08:00
|
|
|
}
|
2014-03-13 17:21:25 -07:00
|
|
|
|
|
|
|
// We can't tell if the overflow changed, so be conservative
|
|
|
|
overflowChanged = true;
|
2012-12-09 18:32:55 -08:00
|
|
|
}
|
2013-01-15 15:12:40 -08:00
|
|
|
|
2013-12-13 05:21:03 -08:00
|
|
|
// If the frame style changed (e.g. positioning offsets)
|
|
|
|
// then we need to update the parent with the overflow areas of its
|
|
|
|
// children.
|
2014-03-13 17:21:25 -07:00
|
|
|
if (overflowChanged) {
|
2012-12-09 18:32:55 -08:00
|
|
|
nsIFrame *parent = frame->GetParent();
|
2013-09-06 06:35:16 -07:00
|
|
|
if (parent && parent != mSubtreeRoot) {
|
2013-12-13 05:21:03 -08:00
|
|
|
Entry* parentEntry = mEntryList.find(Entry(parent, entry->mDepth - 1));
|
|
|
|
if (parentEntry) {
|
2014-05-06 02:23:00 -07:00
|
|
|
parentEntry->mChangeKind = std::max(parentEntry->mChangeKind, CHILDREN_CHANGED);
|
2013-12-13 05:21:03 -08:00
|
|
|
} else {
|
|
|
|
mEntryList.insert(new Entry(parent, entry->mDepth - 1, CHILDREN_CHANGED));
|
2013-01-15 15:12:40 -08:00
|
|
|
}
|
2012-12-09 18:32:55 -08:00
|
|
|
}
|
|
|
|
}
|
2013-01-15 15:12:40 -08:00
|
|
|
delete entry;
|
2012-12-09 18:32:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-01-15 15:12:40 -08:00
|
|
|
struct Entry : SplayTreeNode<Entry>
|
2012-12-09 18:32:55 -08:00
|
|
|
{
|
2014-03-13 17:21:25 -07:00
|
|
|
Entry(nsIFrame* aFrame, uint32_t aDepth, ChangeKind aChangeKind = CHILDREN_CHANGED)
|
2012-12-09 18:32:55 -08:00
|
|
|
: mFrame(aFrame)
|
|
|
|
, mDepth(aDepth)
|
2014-03-13 17:21:25 -07:00
|
|
|
, mChangeKind(aChangeKind)
|
2012-12-09 18:32:55 -08:00
|
|
|
{}
|
|
|
|
|
|
|
|
bool operator==(const Entry& aOther) const
|
|
|
|
{
|
|
|
|
return mFrame == aOther.mFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-03-10 12:44:13 -07:00
|
|
|
* Sort by *reverse* depth in the tree, and break ties with
|
|
|
|
* the frame pointer.
|
2012-12-09 18:32:55 -08:00
|
|
|
*/
|
|
|
|
bool operator<(const Entry& aOther) const
|
|
|
|
{
|
2013-03-10 12:44:13 -07:00
|
|
|
if (mDepth == aOther.mDepth) {
|
|
|
|
return mFrame < aOther.mFrame;
|
|
|
|
}
|
|
|
|
return mDepth > aOther.mDepth; /* reverse, want "min" to be deepest */
|
2012-12-09 18:32:55 -08:00
|
|
|
}
|
|
|
|
|
2013-01-15 15:12:40 -08:00
|
|
|
static int compare(const Entry& aOne, const Entry& aTwo)
|
|
|
|
{
|
2013-01-25 17:34:58 -08:00
|
|
|
if (aOne == aTwo) {
|
2013-01-15 15:12:40 -08:00
|
|
|
return 0;
|
2013-01-25 17:34:58 -08:00
|
|
|
} else if (aOne < aTwo) {
|
|
|
|
return -1;
|
2013-01-15 15:12:40 -08:00
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-09 18:32:55 -08:00
|
|
|
nsIFrame* mFrame;
|
|
|
|
/* Depth in the frame tree */
|
|
|
|
uint32_t mDepth;
|
2014-03-13 17:21:25 -07:00
|
|
|
ChangeKind mChangeKind;
|
2012-12-09 18:32:55 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* A list of frames to process, sorted by their depth in the frame tree */
|
2013-01-15 15:12:40 -08:00
|
|
|
SplayTree<Entry, Entry> mEntryList;
|
2013-09-06 06:35:16 -07:00
|
|
|
|
|
|
|
/* Don't update overflow of this frame or its ancestors. */
|
|
|
|
const nsIFrame* mSubtreeRoot;
|
2012-12-09 18:32:55 -08:00
|
|
|
};
|
|
|
|
|
2010-06-18 09:23:04 -07:00
|
|
|
class RestyleTracker {
|
|
|
|
public:
|
|
|
|
typedef mozilla::dom::Element Element;
|
|
|
|
|
2014-08-03 13:11:55 -07:00
|
|
|
friend class ElementRestyler; // for AddPendingRestyleToTable
|
|
|
|
|
2014-08-31 20:36:37 -07:00
|
|
|
explicit RestyleTracker(Element::FlagsType aRestyleBits) :
|
2013-04-28 03:02:35 -07:00
|
|
|
mRestyleBits(aRestyleBits),
|
2011-10-17 07:59:28 -07:00
|
|
|
mHaveLaterSiblingRestyles(false)
|
2010-06-18 09:23:04 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION((mRestyleBits & ~ELEMENT_ALL_RESTYLE_FLAGS) == 0,
|
|
|
|
"Why do we have these bits set?");
|
|
|
|
NS_PRECONDITION((mRestyleBits & ELEMENT_PENDING_RESTYLE_FLAGS) != 0,
|
|
|
|
"Must have a restyle flag");
|
|
|
|
NS_PRECONDITION((mRestyleBits & ELEMENT_PENDING_RESTYLE_FLAGS) !=
|
|
|
|
ELEMENT_PENDING_RESTYLE_FLAGS,
|
|
|
|
"Shouldn't have both restyle flags set");
|
|
|
|
NS_PRECONDITION((mRestyleBits & ~ELEMENT_PENDING_RESTYLE_FLAGS) != 0,
|
|
|
|
"Must have root flag");
|
|
|
|
NS_PRECONDITION((mRestyleBits & ~ELEMENT_PENDING_RESTYLE_FLAGS) !=
|
|
|
|
(ELEMENT_ALL_RESTYLE_FLAGS & ~ELEMENT_PENDING_RESTYLE_FLAGS),
|
|
|
|
"Shouldn't have both root flags");
|
|
|
|
}
|
|
|
|
|
2013-07-20 12:14:25 -07:00
|
|
|
void Init(RestyleManager* aRestyleManager) {
|
|
|
|
mRestyleManager = aRestyleManager;
|
2010-06-18 09:23:04 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t Count() const {
|
2010-06-18 09:23:04 -07:00
|
|
|
return mPendingRestyles.Count();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-06-18 09:23:05 -07:00
|
|
|
* Add a restyle for the given element to the tracker. Returns true
|
|
|
|
* if the element already had eRestyle_LaterSiblings set on it.
|
2010-06-18 09:23:04 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool AddPendingRestyle(Element* aElement, nsRestyleHint aRestyleHint,
|
2014-08-03 13:11:55 -07:00
|
|
|
nsChangeHint aMinChangeHint);
|
2010-06-18 09:23:04 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the restyles we've been tracking.
|
|
|
|
*/
|
2011-12-14 20:42:14 -08:00
|
|
|
void ProcessRestyles() {
|
|
|
|
// Fast-path the common case (esp. for the animation restyle
|
|
|
|
// tracker) of not having anything to do.
|
|
|
|
if (mPendingRestyles.Count()) {
|
|
|
|
DoProcessRestyles();
|
|
|
|
}
|
|
|
|
}
|
2010-06-18 09:23:04 -07:00
|
|
|
|
2010-06-18 09:23:05 -07:00
|
|
|
// Return our ELEMENT_HAS_PENDING_(ANIMATION_)RESTYLE bit
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t RestyleBit() const {
|
2010-06-18 09:23:05 -07:00
|
|
|
return mRestyleBits & ELEMENT_PENDING_RESTYLE_FLAGS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return our ELEMENT_IS_POTENTIAL_(ANIMATION_)RESTYLE_ROOT bit
|
2014-06-18 17:07:26 -07:00
|
|
|
Element::FlagsType RootBit() const {
|
2010-06-18 09:23:05 -07:00
|
|
|
return mRestyleBits & ~ELEMENT_PENDING_RESTYLE_FLAGS;
|
|
|
|
}
|
2014-09-04 20:48:48 -07:00
|
|
|
|
2014-09-18 18:12:30 -07:00
|
|
|
struct Hints {
|
|
|
|
nsRestyleHint mRestyleHint; // What we want to restyle
|
|
|
|
nsChangeHint mChangeHint; // The minimal change hint for "self"
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RestyleData : Hints {
|
2014-09-04 20:48:48 -07:00
|
|
|
RestyleData() {
|
|
|
|
mRestyleHint = nsRestyleHint(0);
|
|
|
|
mChangeHint = NS_STYLE_HINT_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RestyleData(nsRestyleHint aRestyleHint, nsChangeHint aChangeHint) {
|
|
|
|
mRestyleHint = aRestyleHint;
|
|
|
|
mChangeHint = aChangeHint;
|
|
|
|
}
|
|
|
|
|
2014-09-04 20:48:47 -07:00
|
|
|
// Descendant elements we must check that we ended up restyling, ordered
|
|
|
|
// with the same invariant as mRestyleRoots. The elements here are those
|
|
|
|
// that we called AddPendingRestyle for and found the element this is
|
|
|
|
// the RestyleData for as its nearest restyle root.
|
|
|
|
nsTArray<nsRefPtr<Element>> mDescendants;
|
2010-06-18 09:23:04 -07:00
|
|
|
};
|
|
|
|
|
2010-06-18 09:23:05 -07:00
|
|
|
/**
|
|
|
|
* If the given Element has a restyle pending for it, return the
|
|
|
|
* relevant restyle data. This function will clear everything other
|
|
|
|
* than a possible eRestyle_LaterSiblings hint for aElement out of
|
|
|
|
* our hashtable. The returned aData will never have an
|
|
|
|
* eRestyle_LaterSiblings hint in it.
|
|
|
|
*
|
|
|
|
* The return value indicates whether any restyle data was found for
|
2014-09-04 20:48:48 -07:00
|
|
|
* the element. aData is set to nullptr iff false is returned.
|
2010-06-18 09:23:05 -07:00
|
|
|
*/
|
2014-09-04 20:48:48 -07:00
|
|
|
bool GetRestyleData(Element* aElement, nsAutoPtr<RestyleData>& aData);
|
2010-06-18 09:23:05 -07:00
|
|
|
|
|
|
|
/**
|
2014-09-04 20:48:47 -07:00
|
|
|
* For each element in aElements, appends it to mRestyleRoots if it
|
|
|
|
* has its restyle bit set. This is used to ensure we restyle elements
|
|
|
|
* that we did not add as restyle roots initially (due to there being
|
|
|
|
* an ancestor with the restyle root bit set), but which we might
|
|
|
|
* not have got around to restyling due to the restyle process
|
|
|
|
* terminating early with eRestyleResult_Stop (see ElementRestyler::Restyle).
|
|
|
|
*
|
|
|
|
* This function must be called with elements in order such that
|
|
|
|
* appending them to mRestyleRoots maintains its ordering invariant that
|
|
|
|
* ancestors appear after descendants.
|
|
|
|
*/
|
|
|
|
void AddRestyleRootsIfAwaitingRestyle(
|
|
|
|
const nsTArray<nsRefPtr<Element>>& aElements);
|
|
|
|
|
|
|
|
/**
|
2010-06-18 09:23:05 -07:00
|
|
|
* The document we're associated with.
|
|
|
|
*/
|
|
|
|
inline nsIDocument* Document() const;
|
|
|
|
|
2010-06-18 09:23:04 -07:00
|
|
|
private:
|
2014-08-03 13:11:55 -07:00
|
|
|
bool AddPendingRestyleToTable(Element* aElement, nsRestyleHint aRestyleHint,
|
|
|
|
nsChangeHint aMinChangeHint);
|
|
|
|
|
2010-06-18 09:23:05 -07:00
|
|
|
/**
|
2010-06-18 09:23:05 -07:00
|
|
|
* Handle a single mPendingRestyles entry. aRestyleHint must not
|
|
|
|
* include eRestyle_LaterSiblings; that needs to be dealt with
|
|
|
|
* before calling this function.
|
2010-06-18 09:23:05 -07:00
|
|
|
*/
|
2010-06-18 09:23:05 -07:00
|
|
|
inline void ProcessOneRestyle(Element* aElement,
|
|
|
|
nsRestyleHint aRestyleHint,
|
2013-02-19 16:13:01 -08:00
|
|
|
nsChangeHint aChangeHint);
|
2010-06-18 09:23:05 -07:00
|
|
|
|
2011-12-14 20:42:14 -08:00
|
|
|
/**
|
|
|
|
* The guts of our restyle processing.
|
|
|
|
*/
|
|
|
|
void DoProcessRestyles();
|
|
|
|
|
2014-09-04 20:48:48 -07:00
|
|
|
typedef nsClassHashtable<nsISupportsHashKey, RestyleData> PendingRestyleTable;
|
2010-06-18 09:23:05 -07:00
|
|
|
typedef nsAutoTArray< nsRefPtr<Element>, 32> RestyleRootArray;
|
2010-06-18 09:23:04 -07:00
|
|
|
// Our restyle bits. These will be a subset of ELEMENT_ALL_RESTYLE_FLAGS, and
|
|
|
|
// will include one flag from ELEMENT_PENDING_RESTYLE_FLAGS and one flag
|
|
|
|
// that's not in ELEMENT_PENDING_RESTYLE_FLAGS.
|
2014-06-18 17:07:26 -07:00
|
|
|
Element::FlagsType mRestyleBits;
|
2013-07-20 12:14:25 -07:00
|
|
|
RestyleManager* mRestyleManager; // Owns us
|
2014-09-04 20:48:48 -07:00
|
|
|
// A hashtable that maps elements to pointers to RestyleData structs. The
|
2010-06-18 09:23:05 -07:00
|
|
|
// values only make sense if the element's current document is our
|
|
|
|
// document and it has our RestyleBit() flag set. In particular,
|
|
|
|
// said bit might not be set if the element had a restyle posted and
|
|
|
|
// then was moved around in the DOM.
|
2010-06-18 09:23:04 -07:00
|
|
|
PendingRestyleTable mPendingRestyles;
|
2010-06-18 09:23:05 -07:00
|
|
|
// An array that keeps track of our possible restyle roots. This
|
|
|
|
// maintains the invariant that if A and B are both restyle roots
|
|
|
|
// and A is an ancestor of B then A will come after B in the array.
|
|
|
|
// We maintain this invariant by checking whether an element has an
|
|
|
|
// ancestor with the restyle root bit set before appending it to the
|
|
|
|
// array.
|
|
|
|
RestyleRootArray mRestyleRoots;
|
|
|
|
// True if we have some entries with the eRestyle_LaterSiblings
|
|
|
|
// flag. We need this to avoid enumerating the hashtable looking
|
|
|
|
// for such entries when we can't possibly have any.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHaveLaterSiblingRestyles;
|
2010-06-18 09:23:04 -07:00
|
|
|
};
|
|
|
|
|
2014-08-03 13:11:55 -07:00
|
|
|
inline bool
|
|
|
|
RestyleTracker::AddPendingRestyleToTable(Element* aElement,
|
|
|
|
nsRestyleHint aRestyleHint,
|
|
|
|
nsChangeHint aMinChangeHint)
|
2010-06-18 09:23:04 -07:00
|
|
|
{
|
2014-09-04 20:48:48 -07:00
|
|
|
RestyleData* existingData;
|
2010-06-18 09:23:04 -07:00
|
|
|
|
2010-06-18 09:23:05 -07:00
|
|
|
// Check the RestyleBit() flag before doing the hashtable Get, since
|
|
|
|
// it's possible that the data in the hashtable isn't actually
|
|
|
|
// relevant anymore (if the flag is not set).
|
|
|
|
if (aElement->HasFlag(RestyleBit())) {
|
|
|
|
mPendingRestyles.Get(aElement, &existingData);
|
|
|
|
} else {
|
|
|
|
aElement->SetFlags(RestyleBit());
|
2014-09-04 20:48:48 -07:00
|
|
|
existingData = nullptr;
|
2010-06-18 09:23:05 -07:00
|
|
|
}
|
2010-06-18 09:23:04 -07:00
|
|
|
|
2014-09-04 20:48:48 -07:00
|
|
|
if (!existingData) {
|
|
|
|
mPendingRestyles.Put(aElement,
|
|
|
|
new RestyleData(aRestyleHint, aMinChangeHint));
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-18 09:23:04 -07:00
|
|
|
|
2014-09-04 20:48:48 -07:00
|
|
|
bool hadRestyleLaterSiblings =
|
|
|
|
(existingData->mRestyleHint & eRestyle_LaterSiblings) != 0;
|
|
|
|
existingData->mRestyleHint =
|
|
|
|
nsRestyleHint(existingData->mRestyleHint | aRestyleHint);
|
|
|
|
NS_UpdateHint(existingData->mChangeHint, aMinChangeHint);
|
2010-06-18 09:23:05 -07:00
|
|
|
|
2014-08-03 13:11:55 -07:00
|
|
|
return hadRestyleLaterSiblings;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
RestyleTracker::AddPendingRestyle(Element* aElement,
|
|
|
|
nsRestyleHint aRestyleHint,
|
|
|
|
nsChangeHint aMinChangeHint)
|
|
|
|
{
|
|
|
|
bool hadRestyleLaterSiblings =
|
|
|
|
AddPendingRestyleToTable(aElement, aRestyleHint, aMinChangeHint);
|
|
|
|
|
2010-06-18 09:23:05 -07:00
|
|
|
// We can only treat this element as a restyle root if we would
|
|
|
|
// actually restyle its descendants (so either call
|
|
|
|
// ReResolveStyleContext on it or just reframe it).
|
2014-08-02 19:37:43 -07:00
|
|
|
if ((aRestyleHint & ~eRestyle_LaterSiblings) ||
|
2010-06-18 09:23:05 -07:00
|
|
|
(aMinChangeHint & nsChangeHint_ReconstructFrame)) {
|
2014-09-04 20:48:45 -07:00
|
|
|
Element* cur = aElement;
|
|
|
|
while (!cur->HasFlag(RootBit())) {
|
2010-06-18 09:23:05 -07:00
|
|
|
nsIContent* parent = cur->GetFlattenedTreeParent();
|
|
|
|
// Stop if we have no parent or the parent is not an element or
|
|
|
|
// we're part of the viewport scrollbars (because those are not
|
|
|
|
// frametree descendants of the primary frame of the root
|
|
|
|
// element).
|
|
|
|
// XXXbz maybe the primary frame of the root should be the root scrollframe?
|
|
|
|
if (!parent || !parent->IsElement() ||
|
|
|
|
// If we've hit the root via a native anonymous kid and that
|
|
|
|
// this native anonymous kid is not obviously a descendant
|
|
|
|
// of the root's primary frame, assume we're under the root
|
|
|
|
// scrollbars. Since those don't get reresolved when
|
|
|
|
// reresolving the root, we need to make sure to add the
|
|
|
|
// element to mRestyleRoots.
|
|
|
|
(cur->IsInNativeAnonymousSubtree() && !parent->GetParent() &&
|
|
|
|
cur->GetPrimaryFrame() &&
|
|
|
|
cur->GetPrimaryFrame()->GetParent() != parent->GetPrimaryFrame())) {
|
|
|
|
mRestyleRoots.AppendElement(aElement);
|
2014-09-04 20:48:45 -07:00
|
|
|
cur = aElement;
|
2010-06-18 09:23:05 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
cur = parent->AsElement();
|
|
|
|
}
|
|
|
|
// At this point some ancestor of aElement (possibly aElement
|
|
|
|
// itself) is in mRestyleRoots. Set the root bit on aElement, to
|
|
|
|
// speed up searching for an existing root on its descendants.
|
|
|
|
aElement->SetFlags(RootBit());
|
2014-09-04 20:48:45 -07:00
|
|
|
if (cur != aElement) {
|
|
|
|
// We are already going to restyle cur, one of aElement's ancestors,
|
|
|
|
// but we might not end up restyling all the way down to aElement.
|
|
|
|
// Record it in the RestyleData so we can ensure it does get restyled
|
|
|
|
// after we deal with cur.
|
|
|
|
//
|
|
|
|
// As with the mRestyleRoots array, mDescendants maintains the
|
|
|
|
// invariant that if two elements appear in the array and one
|
|
|
|
// is an ancestor of the other, that the ancestor appears after
|
|
|
|
// the descendant.
|
2014-09-04 20:48:48 -07:00
|
|
|
RestyleData* curData;
|
2014-09-04 20:48:45 -07:00
|
|
|
mPendingRestyles.Get(cur, &curData);
|
2014-09-04 20:48:48 -07:00
|
|
|
NS_ASSERTION(curData, "expected to find a RestyleData for cur");
|
|
|
|
curData->mDescendants.AppendElement(aElement);
|
2014-09-04 20:48:45 -07:00
|
|
|
}
|
2010-06-18 09:23:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mHaveLaterSiblingRestyles =
|
|
|
|
mHaveLaterSiblingRestyles || (aRestyleHint & eRestyle_LaterSiblings) != 0;
|
|
|
|
return hadRestyleLaterSiblings;
|
2010-06-18 09:23:04 -07:00
|
|
|
}
|
|
|
|
|
2010-06-18 12:18:02 -07:00
|
|
|
} // namespace mozilla
|
2010-06-18 09:23:04 -07:00
|
|
|
|
2013-07-20 12:14:24 -07:00
|
|
|
#endif /* mozilla_RestyleTracker_h */
|