2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim:cindent:ts=2:et:sw=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/.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* This Original Code has been modified by IBM Corporation. Modifications made by IBM
|
|
|
|
* described herein are Copyright (c) International Business Machines Corporation, 2000.
|
|
|
|
* Modifications to Mozilla code or documentation identified per MPL Section 3.3
|
|
|
|
*
|
|
|
|
* Date Modified by Description of modification
|
|
|
|
* 04/20/2000 IBM Corp. OS/2 VisualAge build.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* storage of the frame tree and information about it */
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "plhash.h"
|
|
|
|
#include "nsPlaceholderFrame.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsILayoutHistoryState.h"
|
|
|
|
#include "nsPresState.h"
|
2013-08-19 15:55:18 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
|
|
|
|
#include "nsContentUtils.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2011-04-29 16:02:33 -07:00
|
|
|
#include "nsAbsoluteContainingBlock.h"
|
2013-05-01 15:50:08 -07:00
|
|
|
#include "ChildIterator.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsFrameManager.h"
|
2013-03-18 07:25:50 -07:00
|
|
|
#include "GeckoProfiler.h"
|
2013-08-19 15:55:18 -07:00
|
|
|
#include "nsIStatefulFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
//#define DEBUG_UNDISPLAYED_MAP
|
|
|
|
#else
|
|
|
|
#undef DEBUG_UNDISPLAYED_MAP
|
|
|
|
#endif
|
|
|
|
|
2010-03-28 18:46:55 -07:00
|
|
|
using namespace mozilla;
|
2010-06-22 21:46:27 -07:00
|
|
|
using namespace mozilla::dom;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
struct PlaceholderMapEntry : public PLDHashEntryHdr {
|
|
|
|
// key (the out of flow frame) can be obtained through placeholder frame
|
|
|
|
nsPlaceholderFrame *placeholderFrame;
|
|
|
|
};
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
PlaceholderMapMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
|
|
|
|
const void *key)
|
|
|
|
{
|
|
|
|
const PlaceholderMapEntry *entry =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<const PlaceholderMapEntry*>(hdr);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(entry->placeholderFrame->GetOutOfFlowFrame() !=
|
|
|
|
(void*)0xdddddddd,
|
|
|
|
"Dead placeholder in placeholder map");
|
|
|
|
return entry->placeholderFrame->GetOutOfFlowFrame() == key;
|
|
|
|
}
|
|
|
|
|
2013-11-18 18:51:48 -08:00
|
|
|
static const PLDHashTableOps PlaceholderMapOps = {
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashVoidPtrKeyStub,
|
|
|
|
PlaceholderMapMatchEntry,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
PL_DHashClearEntryStub,
|
|
|
|
PL_DHashFinalizeStub,
|
2013-10-08 11:47:21 -07:00
|
|
|
nullptr
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// XXXldb This seems too complicated for what I think it's doing, and it
|
|
|
|
// should also be using pldhash rather than plhash to use less memory.
|
|
|
|
|
|
|
|
class nsFrameManagerBase::UndisplayedMap {
|
|
|
|
public:
|
2012-08-22 08:56:38 -07:00
|
|
|
UndisplayedMap(uint32_t aNumBuckets = 16) NS_HIDDEN;
|
2007-03-22 10:30:00 -07:00
|
|
|
~UndisplayedMap(void) NS_HIDDEN;
|
|
|
|
|
|
|
|
NS_HIDDEN_(UndisplayedNode*) GetFirstNode(nsIContent* aParentContent);
|
|
|
|
|
|
|
|
NS_HIDDEN_(nsresult) AddNodeFor(nsIContent* aParentContent,
|
|
|
|
nsIContent* aChild, nsStyleContext* aStyle);
|
|
|
|
|
|
|
|
NS_HIDDEN_(void) RemoveNodeFor(nsIContent* aParentContent,
|
|
|
|
UndisplayedNode* aNode);
|
|
|
|
|
|
|
|
NS_HIDDEN_(void) RemoveNodesFor(nsIContent* aParentContent);
|
|
|
|
|
|
|
|
// Removes all entries from the hash table
|
|
|
|
NS_HIDDEN_(void) Clear(void);
|
|
|
|
|
|
|
|
protected:
|
2013-06-20 16:21:15 -07:00
|
|
|
/**
|
|
|
|
* Gets the entry for the provided parent content. If the content
|
|
|
|
* is a <xbl:children> element, |**aParentContent| is set to
|
|
|
|
* the parent of the children element.
|
|
|
|
*/
|
|
|
|
NS_HIDDEN_(PLHashEntry**) GetEntryFor(nsIContent** aParentContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_HIDDEN_(void) AppendNodeFor(UndisplayedNode* aNode,
|
|
|
|
nsIContent* aParentContent);
|
|
|
|
|
|
|
|
PLHashTable* mTable;
|
|
|
|
PLHashEntry** mLastLookup;
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsFrameManager::~nsFrameManager()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mPresShell, "nsFrameManager::Destroy never called");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameManager::Destroy()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mPresShell, "Frame manager already shut down.");
|
|
|
|
|
|
|
|
// Destroy the frame hierarchy.
|
2011-10-17 07:59:28 -07:00
|
|
|
mPresShell->SetIgnoreFrameDestruction(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Unregister all placeholders before tearing down the frame tree
|
|
|
|
nsFrameManager::ClearPlaceholderFrameMap();
|
|
|
|
|
|
|
|
if (mRootFrame) {
|
|
|
|
mRootFrame->Destroy();
|
2012-07-30 07:20:58 -07:00
|
|
|
mRootFrame = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
delete mUndisplayedMap;
|
2012-07-30 07:20:58 -07:00
|
|
|
mUndisplayedMap = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mPresShell = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Placeholder frame functions
|
|
|
|
nsPlaceholderFrame*
|
2012-02-15 01:28:21 -08:00
|
|
|
nsFrameManager::GetPlaceholderFrameFor(const nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "null param unexpected");
|
|
|
|
|
|
|
|
if (mPlaceholderMap.ops) {
|
2007-07-08 00:08:04 -07:00
|
|
|
PlaceholderMapEntry *entry = static_cast<PlaceholderMapEntry*>
|
|
|
|
(PL_DHashTableOperate(const_cast<PLDHashTable*>(&mPlaceholderMap),
|
2007-03-22 10:30:00 -07:00
|
|
|
aFrame, PL_DHASH_LOOKUP));
|
|
|
|
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
|
|
|
return entry->placeholderFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFrameManager::RegisterPlaceholderFrame(nsPlaceholderFrame* aPlaceholderFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aPlaceholderFrame, "null param unexpected");
|
|
|
|
NS_PRECONDITION(nsGkAtoms::placeholderFrame == aPlaceholderFrame->GetType(),
|
|
|
|
"unexpected frame type");
|
|
|
|
if (!mPlaceholderMap.ops) {
|
2014-02-27 10:04:09 -08:00
|
|
|
PL_DHashTableInit(&mPlaceholderMap, &PlaceholderMapOps, nullptr,
|
|
|
|
sizeof(PlaceholderMapEntry), 16);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-07-08 00:08:04 -07:00
|
|
|
PlaceholderMapEntry *entry = static_cast<PlaceholderMapEntry*>(PL_DHashTableOperate(&mPlaceholderMap,
|
2007-03-22 10:30:00 -07:00
|
|
|
aPlaceholderFrame->GetOutOfFlowFrame(),
|
|
|
|
PL_DHASH_ADD));
|
|
|
|
if (!entry)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ASSERTION(!entry->placeholderFrame, "Registering a placeholder for a frame that already has a placeholder!");
|
|
|
|
entry->placeholderFrame = aPlaceholderFrame;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameManager::UnregisterPlaceholderFrame(nsPlaceholderFrame* aPlaceholderFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aPlaceholderFrame, "null param unexpected");
|
|
|
|
NS_PRECONDITION(nsGkAtoms::placeholderFrame == aPlaceholderFrame->GetType(),
|
|
|
|
"unexpected frame type");
|
|
|
|
|
|
|
|
if (mPlaceholderMap.ops) {
|
|
|
|
PL_DHashTableOperate(&mPlaceholderMap,
|
|
|
|
aPlaceholderFrame->GetOutOfFlowFrame(),
|
|
|
|
PL_DHASH_REMOVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static PLDHashOperator
|
2007-03-22 10:30:00 -07:00
|
|
|
UnregisterPlaceholders(PLDHashTable* table, PLDHashEntryHdr* hdr,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t number, void* arg)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
PlaceholderMapEntry* entry = static_cast<PlaceholderMapEntry*>(hdr);
|
2012-07-30 07:20:58 -07:00
|
|
|
entry->placeholderFrame->SetOutOfFlowFrame(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameManager::ClearPlaceholderFrameMap()
|
|
|
|
{
|
|
|
|
if (mPlaceholderMap.ops) {
|
2012-07-30 07:20:58 -07:00
|
|
|
PL_DHashTableEnumerate(&mPlaceholderMap, UnregisterPlaceholders, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_DHashTableFinish(&mPlaceholderMap);
|
2012-07-30 07:20:58 -07:00
|
|
|
mPlaceholderMap.ops = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsStyleContext*
|
|
|
|
nsFrameManager::GetUndisplayedContent(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (!aContent || !mUndisplayedMap)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIContent* parent = aContent->GetParent();
|
|
|
|
for (UndisplayedNode* node = mUndisplayedMap->GetFirstNode(parent);
|
|
|
|
node; node = node->mNext) {
|
|
|
|
if (node->mContent == aContent)
|
|
|
|
return node->mStyle;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-07-20 12:14:25 -07:00
|
|
|
|
|
|
|
UndisplayedNode*
|
|
|
|
nsFrameManager::GetAllUndisplayedContentIn(nsIContent* aParentContent)
|
|
|
|
{
|
|
|
|
if (!mUndisplayedMap)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return mUndisplayedMap->GetFirstNode(aParentContent);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsFrameManager::SetUndisplayedContent(nsIContent* aContent,
|
|
|
|
nsStyleContext* aStyleContext)
|
|
|
|
{
|
2009-10-29 14:17:56 -07:00
|
|
|
NS_PRECONDITION(!aStyleContext->GetPseudo(),
|
2009-05-14 18:40:26 -07:00
|
|
|
"Should only have actual elements here");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG_UNDISPLAYED_MAP
|
|
|
|
static int i = 0;
|
|
|
|
printf("SetUndisplayedContent(%d): p=%p \n", i++, (void *)aContent);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_ASSERTION(!GetUndisplayedContent(aContent),
|
|
|
|
"Already have an undisplayed context entry for aContent");
|
|
|
|
|
|
|
|
if (! mUndisplayedMap) {
|
|
|
|
mUndisplayedMap = new UndisplayedMap;
|
|
|
|
}
|
2011-04-28 22:02:40 -07:00
|
|
|
nsIContent* parent = aContent->GetParent();
|
|
|
|
NS_ASSERTION(parent || (mPresShell && mPresShell->GetDocument() &&
|
|
|
|
mPresShell->GetDocument()->GetRootElement() == aContent),
|
|
|
|
"undisplayed content must have a parent, unless it's the root "
|
|
|
|
"element");
|
|
|
|
mUndisplayedMap->AddNodeFor(parent, aContent, aStyleContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameManager::ChangeUndisplayedContent(nsIContent* aContent,
|
|
|
|
nsStyleContext* aStyleContext)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mUndisplayedMap, "no existing undisplayed content");
|
|
|
|
|
|
|
|
#ifdef DEBUG_UNDISPLAYED_MAP
|
|
|
|
static int i = 0;
|
|
|
|
printf("ChangeUndisplayedContent(%d): p=%p \n", i++, (void *)aContent);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (UndisplayedNode* node = mUndisplayedMap->GetFirstNode(aContent->GetParent());
|
|
|
|
node; node = node->mNext) {
|
|
|
|
if (node->mContent == aContent) {
|
|
|
|
node->mStyle = aStyleContext;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NOTREACHED("no existing undisplayed content");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameManager::ClearUndisplayedContentIn(nsIContent* aContent,
|
|
|
|
nsIContent* aParentContent)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_UNDISPLAYED_MAP
|
|
|
|
static int i = 0;
|
|
|
|
printf("ClearUndisplayedContent(%d): content=%p parent=%p --> ", i++, (void *)aContent, (void*)aParentContent);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (mUndisplayedMap) {
|
|
|
|
UndisplayedNode* node = mUndisplayedMap->GetFirstNode(aParentContent);
|
|
|
|
while (node) {
|
|
|
|
if (node->mContent == aContent) {
|
|
|
|
mUndisplayedMap->RemoveNodeFor(aParentContent, node);
|
|
|
|
|
|
|
|
#ifdef DEBUG_UNDISPLAYED_MAP
|
|
|
|
printf( "REMOVED!\n");
|
|
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
|
|
|
// make sure that there are no more entries for the same content
|
|
|
|
nsStyleContext *context = GetUndisplayedContent(aContent);
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(context == nullptr, "Found more undisplayed content data after removal");
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
node = node->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameManager::ClearAllUndisplayedContentIn(nsIContent* aParentContent)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_UNDISPLAYED_MAP
|
|
|
|
static int i = 0;
|
|
|
|
printf("ClearAllUndisplayedContentIn(%d): parent=%p \n", i++, (void*)aParentContent);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (mUndisplayedMap) {
|
|
|
|
mUndisplayedMap->RemoveNodesFor(aParentContent);
|
|
|
|
}
|
2009-08-07 12:51:25 -07:00
|
|
|
|
|
|
|
// Need to look at aParentContent's content list due to XBL insertions.
|
|
|
|
// Nodes in aParentContent's content list do not have aParentContent as a
|
2013-05-01 15:50:08 -07:00
|
|
|
// parent, but are treated as children of aParentContent. We iterate over
|
|
|
|
// the flattened content list and just ignore any nodes we don't care about.
|
|
|
|
FlattenedChildIterator iter(aParentContent);
|
|
|
|
for (nsIContent* child = iter.GetNextChild(); child; child = iter.GetNextChild()) {
|
|
|
|
if (child->GetParent() != aParentContent) {
|
|
|
|
ClearUndisplayedContentIn(child, child->GetParent());
|
2009-08-07 12:51:25 -07:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2011-04-29 16:02:33 -07:00
|
|
|
nsresult
|
|
|
|
nsFrameManager::AppendFrames(nsIFrame* aParentFrame,
|
|
|
|
ChildListID aListID,
|
|
|
|
nsFrameList& aFrameList)
|
|
|
|
{
|
|
|
|
if (aParentFrame->IsAbsoluteContainer() &&
|
|
|
|
aListID == aParentFrame->GetAbsoluteListID()) {
|
|
|
|
return aParentFrame->GetAbsoluteContainingBlock()->
|
|
|
|
AppendFrames(aParentFrame, aListID, aFrameList);
|
|
|
|
} else {
|
|
|
|
return aParentFrame->AppendFrames(aListID, aFrameList);
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFrameManager::InsertFrames(nsIFrame* aParentFrame,
|
2011-08-24 13:54:30 -07:00
|
|
|
ChildListID aListID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-11-12 11:05:42 -08:00
|
|
|
NS_PRECONDITION(!aPrevFrame || (!aPrevFrame->GetNextContinuation()
|
2012-10-14 22:42:40 -07:00
|
|
|
|| (((aPrevFrame->GetNextContinuation()->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER))
|
|
|
|
&& !(aPrevFrame->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER))),
|
2007-03-22 10:30:00 -07:00
|
|
|
"aPrevFrame must be the last continuation in its chain!");
|
|
|
|
|
2011-04-29 16:02:33 -07:00
|
|
|
if (aParentFrame->IsAbsoluteContainer() &&
|
|
|
|
aListID == aParentFrame->GetAbsoluteListID()) {
|
|
|
|
return aParentFrame->GetAbsoluteContainingBlock()->
|
|
|
|
InsertFrames(aParentFrame, aListID, aPrevFrame, aFrameList);
|
|
|
|
} else {
|
|
|
|
return aParentFrame->InsertFrames(aListID, aPrevFrame, aFrameList);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-08-24 13:54:30 -07:00
|
|
|
nsFrameManager::RemoveFrame(ChildListID aListID,
|
2012-08-28 22:39:31 -07:00
|
|
|
nsIFrame* aOldFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool wasDestroyingFrames = mIsDestroyingFrames;
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsDestroyingFrames = true;
|
2008-12-12 00:25:16 -08:00
|
|
|
|
2012-08-28 22:48:45 -07:00
|
|
|
// In case the reflow doesn't invalidate anything since it just leaves
|
|
|
|
// a gap where the old frame was, we invalidate it here. (This is
|
|
|
|
// reasonably likely to happen when removing a last child in a way
|
|
|
|
// that doesn't change the size of the parent.)
|
|
|
|
// This has to sure to invalidate the entire overflow rect; this
|
|
|
|
// is important in the presence of absolute positioning
|
|
|
|
aOldFrame->InvalidateFrameForRemoval();
|
|
|
|
|
2009-12-23 21:20:41 -08:00
|
|
|
NS_ASSERTION(!aOldFrame->GetPrevContinuation() ||
|
|
|
|
// exception for nsCSSFrameConstructor::RemoveFloatingFirstLetterFrames
|
|
|
|
aOldFrame->GetType() == nsGkAtoms::textFrame,
|
|
|
|
"Must remove first continuation.");
|
|
|
|
NS_ASSERTION(!(aOldFrame->GetStateBits() & NS_FRAME_OUT_OF_FLOW &&
|
|
|
|
GetPlaceholderFrameFor(aOldFrame)),
|
|
|
|
"Must call RemoveFrame on placeholder for out-of-flows.");
|
2011-04-29 16:02:33 -07:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsIFrame* parentFrame = aOldFrame->GetParent();
|
|
|
|
if (parentFrame->IsAbsoluteContainer() &&
|
|
|
|
aListID == parentFrame->GetAbsoluteListID()) {
|
|
|
|
parentFrame->GetAbsoluteContainingBlock()->
|
|
|
|
RemoveFrame(parentFrame, aListID, aOldFrame);
|
|
|
|
} else {
|
|
|
|
rv = parentFrame->RemoveFrame(aListID, aOldFrame);
|
|
|
|
}
|
2008-12-12 00:25:16 -08:00
|
|
|
|
2008-10-12 15:05:04 -07:00
|
|
|
mIsDestroyingFrames = wasDestroyingFrames;
|
2008-12-12 00:25:16 -08:00
|
|
|
|
2008-10-12 15:05:04 -07:00
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameManager::NotifyDestroyingFrame(nsIFrame* aFrame)
|
|
|
|
{
|
2009-12-23 21:20:41 -08:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
2009-12-29 12:13:54 -08:00
|
|
|
if (content && content->GetPrimaryFrame() == aFrame) {
|
|
|
|
ClearAllUndisplayedContentIn(content);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Capture state for a given frame.
|
|
|
|
// Accept a content id here, in some cases we may not have content (scroll position)
|
|
|
|
void
|
|
|
|
nsFrameManager::CaptureFrameStateFor(nsIFrame* aFrame,
|
2012-11-14 22:40:17 -08:00
|
|
|
nsILayoutHistoryState* aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!aFrame || !aState) {
|
|
|
|
NS_WARNING("null frame, or state");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only capture state for stateful frames
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIStatefulFrame* statefulFrame = do_QueryFrame(aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!statefulFrame) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Capture the state, exit early if we get null (nothing to save)
|
|
|
|
nsAutoPtr<nsPresState> frameState;
|
2012-11-14 22:40:17 -08:00
|
|
|
nsresult rv = statefulFrame->SaveState(getter_Transfers(frameState));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!frameState) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the hash key to store the state under
|
|
|
|
// Exit early if we get empty key
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString stateKey;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIDocument* doc = content ? content->GetCurrentDoc() : nullptr;
|
2012-11-14 22:40:17 -08:00
|
|
|
rv = nsContentUtils::GenerateStateKey(content, doc, stateKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
if(NS_FAILED(rv) || stateKey.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-24 00:38:13 -07:00
|
|
|
// Store the state. aState owns frameState now.
|
|
|
|
aState->AddState(stateKey, frameState.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameManager::CaptureFrameState(nsIFrame* aFrame,
|
|
|
|
nsILayoutHistoryState* aState)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_PRECONDITION(nullptr != aFrame && nullptr != aState, "null parameters passed in");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
CaptureFrameStateFor(aFrame, aState);
|
|
|
|
|
|
|
|
// Now capture state recursively for the frame hierarchy rooted at aFrame
|
2011-08-24 13:54:29 -07:00
|
|
|
nsIFrame::ChildListIterator lists(aFrame);
|
|
|
|
for (; !lists.IsDone(); lists.Next()) {
|
|
|
|
nsFrameList::Enumerator childFrames(lists.CurrentList());
|
|
|
|
for (; !childFrames.AtEnd(); childFrames.Next()) {
|
2012-05-09 18:27:47 -07:00
|
|
|
nsIFrame* child = childFrames.get();
|
|
|
|
if (child->GetStateBits() & NS_FRAME_OUT_OF_FLOW) {
|
|
|
|
// We'll pick it up when we get to its placeholder
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Make sure to walk through placeholders as needed, so that we
|
|
|
|
// save state for out-of-flows which may not be our descendants
|
|
|
|
// themselves but whose placeholders are our descendants.
|
|
|
|
CaptureFrameState(nsPlaceholderFrame::GetRealFrameFor(child), aState);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-08-24 13:54:29 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Restore state for a given frame.
|
|
|
|
// Accept a content id here, in some cases we may not have content (scroll position)
|
|
|
|
void
|
|
|
|
nsFrameManager::RestoreFrameStateFor(nsIFrame* aFrame,
|
2012-11-14 22:40:17 -08:00
|
|
|
nsILayoutHistoryState* aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!aFrame || !aState) {
|
|
|
|
NS_WARNING("null frame or state");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-03 09:55:14 -08:00
|
|
|
// Only restore state for stateful frames
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIStatefulFrame* statefulFrame = do_QueryFrame(aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!statefulFrame) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the hash key the state was stored under
|
|
|
|
// Exit early if we get empty key
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
// If we don't have content, we can't generate a hash
|
|
|
|
// key and there's probably no state information for us.
|
|
|
|
if (!content) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString stateKey;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDocument* doc = content->GetCurrentDoc();
|
2012-11-14 22:40:17 -08:00
|
|
|
nsresult rv = nsContentUtils::GenerateStateKey(content, doc, stateKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv) || stateKey.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the state from the hash
|
2013-07-24 00:38:13 -07:00
|
|
|
nsPresState* frameState = aState->GetState(stateKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!frameState) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore it
|
|
|
|
rv = statefulFrame->RestoreState(frameState);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we restore ok, remove the state from the state table
|
|
|
|
aState->RemoveState(stateKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameManager::RestoreFrameState(nsIFrame* aFrame,
|
|
|
|
nsILayoutHistoryState* aState)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_PRECONDITION(nullptr != aFrame && nullptr != aState, "null parameters passed in");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
RestoreFrameStateFor(aFrame, aState);
|
|
|
|
|
|
|
|
// Now restore state recursively for the frame hierarchy rooted at aFrame
|
2011-08-24 13:54:29 -07:00
|
|
|
nsIFrame::ChildListIterator lists(aFrame);
|
|
|
|
for (; !lists.IsDone(); lists.Next()) {
|
|
|
|
nsFrameList::Enumerator childFrames(lists.CurrentList());
|
|
|
|
for (; !childFrames.AtEnd(); childFrames.Next()) {
|
|
|
|
RestoreFrameState(childFrames.get(), aState);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-08-24 13:54:29 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
static PLHashNumber
|
|
|
|
HashKey(void* key)
|
|
|
|
{
|
|
|
|
return NS_PTR_TO_INT32(key);
|
|
|
|
}
|
|
|
|
|
2012-08-09 00:09:40 -07:00
|
|
|
static int
|
2007-03-22 10:30:00 -07:00
|
|
|
CompareKeys(void* key1, void* key2)
|
|
|
|
{
|
|
|
|
return key1 == key2;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsFrameManagerBase::UndisplayedMap::UndisplayedMap(uint32_t aNumBuckets)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsFrameManagerBase::UndisplayedMap);
|
|
|
|
mTable = PL_NewHashTable(aNumBuckets, (PLHashFunction)HashKey,
|
|
|
|
(PLHashComparator)CompareKeys,
|
2012-07-30 07:20:58 -07:00
|
|
|
(PLHashComparator)nullptr,
|
|
|
|
nullptr, nullptr);
|
|
|
|
mLastLookup = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsFrameManagerBase::UndisplayedMap::~UndisplayedMap(void)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsFrameManagerBase::UndisplayedMap);
|
|
|
|
Clear();
|
|
|
|
PL_HashTableDestroy(mTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
PLHashEntry**
|
2013-06-20 16:21:15 -07:00
|
|
|
nsFrameManagerBase::UndisplayedMap::GetEntryFor(nsIContent** aParentContent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-20 16:21:15 -07:00
|
|
|
nsIContent* parentContent = *aParentContent;
|
|
|
|
|
|
|
|
if (mLastLookup && (parentContent == (*mLastLookup)->key)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return mLastLookup;
|
|
|
|
}
|
2013-06-20 16:21:15 -07:00
|
|
|
|
|
|
|
// In the case of XBL default content, <xbl:children> elements do not get a
|
|
|
|
// frame causing a mismatch between the content tree and the frame tree.
|
|
|
|
// |GetEntryFor| is sometimes called with the content tree parent (which may
|
|
|
|
// be a <xbl:children> element) but the parent in the frame tree would be the
|
|
|
|
// insertion parent (parent of the <xbl:children> element). Here the children
|
|
|
|
// elements are normalized to the insertion parent to correct for the mismatch.
|
2013-12-02 02:26:12 -08:00
|
|
|
if (parentContent && nsContentUtils::IsContentInsertionPoint(parentContent)) {
|
2013-06-20 16:21:15 -07:00
|
|
|
parentContent = parentContent->GetParent();
|
|
|
|
// Change the caller's pointer for the parent content to be the insertion parent.
|
|
|
|
*aParentContent = parentContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLHashNumber hashCode = NS_PTR_TO_INT32(parentContent);
|
|
|
|
PLHashEntry** entry = PL_HashTableRawLookup(mTable, hashCode, parentContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (*entry) {
|
|
|
|
mLastLookup = entry;
|
|
|
|
}
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
UndisplayedNode*
|
|
|
|
nsFrameManagerBase::UndisplayedMap::GetFirstNode(nsIContent* aParentContent)
|
|
|
|
{
|
2013-06-20 16:21:15 -07:00
|
|
|
PLHashEntry** entry = GetEntryFor(&aParentContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (*entry) {
|
|
|
|
return (UndisplayedNode*)((*entry)->value);
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameManagerBase::UndisplayedMap::AppendNodeFor(UndisplayedNode* aNode,
|
|
|
|
nsIContent* aParentContent)
|
|
|
|
{
|
2013-06-20 16:21:15 -07:00
|
|
|
PLHashEntry** entry = GetEntryFor(&aParentContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (*entry) {
|
|
|
|
UndisplayedNode* node = (UndisplayedNode*)((*entry)->value);
|
|
|
|
while (node->mNext) {
|
|
|
|
if (node->mContent == aNode->mContent) {
|
|
|
|
// We actually need to check this in optimized builds because
|
|
|
|
// there are some callers that do this. See bug 118014, bug
|
|
|
|
// 136704, etc.
|
|
|
|
NS_NOTREACHED("node in map twice");
|
|
|
|
delete aNode;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
node = node->mNext;
|
|
|
|
}
|
|
|
|
node->mNext = aNode;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PLHashNumber hashCode = NS_PTR_TO_INT32(aParentContent);
|
|
|
|
PL_HashTableRawAdd(mTable, entry, hashCode, aParentContent, aNode);
|
2012-07-30 07:20:58 -07:00
|
|
|
mLastLookup = nullptr; // hashtable may have shifted bucket out from under us
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFrameManagerBase::UndisplayedMap::AddNodeFor(nsIContent* aParentContent,
|
|
|
|
nsIContent* aChild,
|
|
|
|
nsStyleContext* aStyle)
|
|
|
|
{
|
|
|
|
UndisplayedNode* node = new UndisplayedNode(aChild, aStyle);
|
|
|
|
|
|
|
|
AppendNodeFor(node, aParentContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameManagerBase::UndisplayedMap::RemoveNodeFor(nsIContent* aParentContent,
|
|
|
|
UndisplayedNode* aNode)
|
|
|
|
{
|
2013-06-20 16:21:15 -07:00
|
|
|
PLHashEntry** entry = GetEntryFor(&aParentContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(*entry, "content not in map");
|
|
|
|
if (*entry) {
|
|
|
|
if ((UndisplayedNode*)((*entry)->value) == aNode) { // first node
|
|
|
|
if (aNode->mNext) {
|
|
|
|
(*entry)->value = aNode->mNext;
|
2012-07-30 07:20:58 -07:00
|
|
|
aNode->mNext = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
PL_HashTableRawRemove(mTable, entry, *entry);
|
2012-07-30 07:20:58 -07:00
|
|
|
mLastLookup = nullptr; // hashtable may have shifted bucket out from under us
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
UndisplayedNode* node = (UndisplayedNode*)((*entry)->value);
|
|
|
|
while (node->mNext) {
|
|
|
|
if (node->mNext == aNode) {
|
|
|
|
node->mNext = aNode->mNext;
|
2012-07-30 07:20:58 -07:00
|
|
|
aNode->mNext = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
node = node->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete aNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameManagerBase::UndisplayedMap::RemoveNodesFor(nsIContent* aParentContent)
|
|
|
|
{
|
2013-06-20 16:21:15 -07:00
|
|
|
PLHashEntry** entry = GetEntryFor(&aParentContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(entry, "content not in map");
|
|
|
|
if (*entry) {
|
|
|
|
UndisplayedNode* node = (UndisplayedNode*)((*entry)->value);
|
|
|
|
NS_ASSERTION(node, "null node for non-null entry in UndisplayedMap");
|
|
|
|
delete node;
|
|
|
|
PL_HashTableRawRemove(mTable, entry, *entry);
|
2012-07-30 07:20:58 -07:00
|
|
|
mLastLookup = nullptr; // hashtable may have shifted bucket out from under us
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-09 00:09:40 -07:00
|
|
|
static int
|
|
|
|
RemoveUndisplayedEntry(PLHashEntry* he, int i, void* arg)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
UndisplayedNode* node = (UndisplayedNode*)(he->value);
|
|
|
|
delete node;
|
|
|
|
// Remove and free this entry and continue enumerating
|
|
|
|
return HT_ENUMERATE_REMOVE | HT_ENUMERATE_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameManagerBase::UndisplayedMap::Clear(void)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mLastLookup = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_HashTableEnumerateEntries(mTable, RemoveUndisplayedEntry, 0);
|
|
|
|
}
|
2012-07-04 08:42:29 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t nsFrameManagerBase::sGlobalGenerationNumber;
|