2017-10-27 20:33:53 +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
|
2012-05-21 15:12:37 +04:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2017-08-17 00:10:56 +03:00
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-03-30 09:56:38 +04:00
|
|
|
|
|
|
|
/* storage of the frame tree and information about it */
|
|
|
|
|
2001-08-14 11:59:59 +04:00
|
|
|
#include "nscore.h"
|
1999-08-04 07:39:34 +04:00
|
|
|
#include "nsIPresShell.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
1999-08-04 07:39:34 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "plhash.h"
|
|
|
|
#include "nsPlaceholderFrame.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
1999-08-31 18:35:50 +04:00
|
|
|
#include "nsILayoutHistoryState.h"
|
2005-01-28 01:52:53 +03:00
|
|
|
#include "nsPresState.h"
|
2013-08-20 02:55:18 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2000-11-28 01:00:33 +03:00
|
|
|
#include "nsIDocument.h"
|
1999-08-04 07:39:34 +04:00
|
|
|
|
2003-05-30 04:21:01 +04:00
|
|
|
#include "nsContentUtils.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2011-04-30 03:02:33 +04:00
|
|
|
#include "nsAbsoluteContainingBlock.h"
|
2013-05-02 02:50:08 +04:00
|
|
|
#include "ChildIterator.h"
|
2001-05-30 15:26:21 +04:00
|
|
|
|
2004-02-24 00:29:06 +03:00
|
|
|
#include "nsFrameManager.h"
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2013-08-20 02:55:18 +04:00
|
|
|
#include "nsIStatefulFrame.h"
|
2014-05-25 02:20:39 +04:00
|
|
|
#include "nsContainerFrame.h"
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 15:39:26 +03:00
|
|
|
|
2017-03-19 22:19:06 +03:00
|
|
|
// #define DEBUG_UNDISPLAYED_MAP
|
|
|
|
// #define DEBUG_DISPLAY_CONTENTS_MAP
|
2000-09-13 02:47:09 +04:00
|
|
|
|
2010-03-29 05:46:55 +04:00
|
|
|
using namespace mozilla;
|
2010-06-23 08:46:27 +04:00
|
|
|
using namespace mozilla::dom;
|
1999-08-04 07:39:34 +04:00
|
|
|
|
1999-08-06 00:17:44 +04:00
|
|
|
//----------------------------------------------------------------------
|
1999-08-04 07:39:34 +04:00
|
|
|
|
2015-05-19 05:24:34 +03:00
|
|
|
nsFrameManagerBase::nsFrameManagerBase()
|
|
|
|
: mPresShell(nullptr)
|
|
|
|
, mRootFrame(nullptr)
|
2017-08-01 15:50:23 +03:00
|
|
|
, mDisplayNoneMap(nullptr)
|
2015-05-19 05:24:34 +03:00
|
|
|
, mDisplayContentsMap(nullptr)
|
|
|
|
, mIsDestroyingFrames(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-12-06 08:45:07 +03:00
|
|
|
//----------------------------------------------------------------------
|
1999-08-04 07:39:34 +04:00
|
|
|
|
2017-03-19 22:19:06 +03:00
|
|
|
/**
|
|
|
|
* The undisplayed map is a class that maps a parent content node to the
|
|
|
|
* undisplayed content children, and their style contexts.
|
|
|
|
*
|
|
|
|
* The linked list of nodes holds strong references to the style contexts and
|
|
|
|
* the content.
|
|
|
|
*/
|
|
|
|
class nsFrameManagerBase::UndisplayedMap :
|
|
|
|
private nsClassHashtable<nsPtrHashKey<nsIContent>,
|
|
|
|
LinkedList<UndisplayedNode>>
|
|
|
|
{
|
|
|
|
typedef nsClassHashtable<nsPtrHashKey<nsIContent>, LinkedList<UndisplayedNode>> base_type;
|
1999-10-09 00:41:19 +04:00
|
|
|
|
1999-10-02 08:25:29 +04:00
|
|
|
public:
|
2017-03-19 22:19:06 +03:00
|
|
|
UndisplayedMap();
|
|
|
|
~UndisplayedMap();
|
1999-10-02 08:25:29 +04:00
|
|
|
|
2014-06-02 16:08:21 +04:00
|
|
|
UndisplayedNode* GetFirstNode(nsIContent* aParentContent);
|
1999-10-02 08:25:29 +04:00
|
|
|
|
2017-03-19 22:19:06 +03:00
|
|
|
void AddNodeFor(nsIContent* aParentContent,
|
|
|
|
nsIContent* aChild,
|
|
|
|
nsStyleContext* aStyle);
|
1999-10-02 08:25:29 +04:00
|
|
|
|
2017-03-19 22:19:06 +03:00
|
|
|
void RemoveNodeFor(nsIContent* aParentContent, UndisplayedNode* aNode);
|
2004-02-24 00:29:06 +03:00
|
|
|
|
2014-06-02 16:08:21 +04:00
|
|
|
void RemoveNodesFor(nsIContent* aParentContent);
|
2017-03-19 22:19:06 +03:00
|
|
|
|
|
|
|
nsAutoPtr<LinkedList<UndisplayedNode>>
|
|
|
|
UnlinkNodesFor(nsIContent* aParentContent);
|
1999-10-02 08:25:29 +04:00
|
|
|
|
|
|
|
// Removes all entries from the hash table
|
2017-03-19 22:19:06 +03:00
|
|
|
void Clear();
|
1999-10-02 08:25:29 +04:00
|
|
|
|
2013-06-21 03:21:15 +04:00
|
|
|
/**
|
2017-03-19 22:19:06 +03:00
|
|
|
* Get the applicable parent for the map lookup. This is almost always the
|
|
|
|
* provided argument, except if it's a <xbl:children> element, in which case
|
|
|
|
* it's the parent of the children element.
|
2017-08-04 16:52:25 +03:00
|
|
|
*
|
|
|
|
* All functions that are entry points into code that handles "parent"
|
|
|
|
* objects (used as the hash table keys) must ensure that the parent objects
|
|
|
|
* that they act on (and pass to other code) have been normalized by calling
|
|
|
|
* this method.
|
2013-06-21 03:21:15 +04:00
|
|
|
*/
|
2017-08-04 16:52:25 +03:00
|
|
|
static nsIContent* GetApplicableParent(nsIContent* aParent);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
LinkedList<UndisplayedNode>* GetListFor(nsIContent* aParentContent);
|
|
|
|
LinkedList<UndisplayedNode>* GetOrCreateListFor(nsIContent* aParentContent);
|
|
|
|
void AppendNodeFor(UndisplayedNode* aNode, nsIContent* aParentContent);
|
1999-10-02 08:25:29 +04:00
|
|
|
};
|
|
|
|
|
1999-08-04 07:39:34 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2004-02-24 00:29:06 +03:00
|
|
|
nsFrameManager::~nsFrameManager()
|
1999-08-04 07:39:34 +04:00
|
|
|
{
|
2004-02-24 00:29:06 +03:00
|
|
|
NS_ASSERTION(!mPresShell, "nsFrameManager::Destroy never called");
|
1999-08-04 07:39:34 +04:00
|
|
|
}
|
|
|
|
|
2004-02-24 00:29:06 +03:00
|
|
|
void
|
|
|
|
nsFrameManager::Destroy()
|
2001-03-06 04:46:03 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mPresShell, "Frame manager already shut down.");
|
|
|
|
|
2004-08-24 22:50:29 +04:00
|
|
|
// Destroy the frame hierarchy.
|
2011-10-17 18:59:28 +04:00
|
|
|
mPresShell->SetIgnoreFrameDestruction(true);
|
2002-03-10 09:47:42 +03:00
|
|
|
|
1999-10-19 02:20:37 +04:00
|
|
|
if (mRootFrame) {
|
2006-04-10 04:16:29 +04:00
|
|
|
mRootFrame->Destroy();
|
2012-07-30 18:20:58 +04:00
|
|
|
mRootFrame = nullptr;
|
1999-10-19 02:20:37 +04:00
|
|
|
}
|
2017-03-19 22:19:06 +03:00
|
|
|
|
2017-08-01 15:50:23 +03:00
|
|
|
delete mDisplayNoneMap;
|
|
|
|
mDisplayNoneMap = nullptr;
|
2014-11-20 21:24:09 +03:00
|
|
|
delete mDisplayContentsMap;
|
|
|
|
mDisplayContentsMap = nullptr;
|
1999-08-04 07:39:34 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mPresShell = nullptr;
|
1999-10-19 02:20:37 +04:00
|
|
|
}
|
|
|
|
|
1999-08-06 00:17:44 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2017-08-04 16:52:25 +03:00
|
|
|
/* static */ nsIContent*
|
|
|
|
nsFrameManager::ParentForUndisplayedMap(const nsIContent* aContent)
|
2017-02-21 13:25:11 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aContent);
|
|
|
|
|
|
|
|
nsIContent* parent = aContent->GetParentElementCrossingShadowRoot();
|
|
|
|
MOZ_ASSERT(parent || !aContent->GetParent(), "no non-elements");
|
|
|
|
|
2017-08-04 16:52:25 +03:00
|
|
|
// Normalize the parent:
|
|
|
|
parent = UndisplayedMap::GetApplicableParent(parent);
|
|
|
|
|
2017-02-21 13:25:11 +03:00
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2014-11-20 21:24:09 +03:00
|
|
|
/* static */ nsStyleContext*
|
2017-02-21 16:21:07 +03:00
|
|
|
nsFrameManager::GetStyleContextInMap(UndisplayedMap* aMap,
|
|
|
|
const nsIContent* aContent)
|
2017-02-21 13:25:11 +03:00
|
|
|
{
|
|
|
|
UndisplayedNode* node = GetUndisplayedNodeInMapFor(aMap, aContent);
|
|
|
|
return node ? node->mStyle.get() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ UndisplayedNode*
|
|
|
|
nsFrameManager::GetUndisplayedNodeInMapFor(UndisplayedMap* aMap,
|
|
|
|
const nsIContent* aContent)
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
2014-11-20 21:24:09 +03:00
|
|
|
if (!aContent) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2014-11-20 21:24:09 +03:00
|
|
|
}
|
2017-08-04 16:52:25 +03:00
|
|
|
|
|
|
|
// This function is an entry point into UndisplayedMap handling code, so the
|
|
|
|
// parent that we act on must be normalized by GetApplicableParent (as per
|
|
|
|
// that function's documentation). We rely on ParentForUndisplayedMap to
|
|
|
|
// have done that for us.
|
2017-02-21 13:25:11 +03:00
|
|
|
nsIContent* parent = ParentForUndisplayedMap(aContent);
|
2017-08-04 16:52:25 +03:00
|
|
|
|
2014-11-20 21:24:09 +03:00
|
|
|
for (UndisplayedNode* node = aMap->GetFirstNode(parent);
|
2017-03-19 22:19:06 +03:00
|
|
|
node; node = node->getNext()) {
|
2003-02-22 03:32:13 +03:00
|
|
|
if (node->mContent == aContent)
|
2017-02-21 13:25:11 +03:00
|
|
|
return node;
|
2002-05-01 04:36:50 +04:00
|
|
|
}
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2013-07-20 23:14:25 +04:00
|
|
|
|
2017-02-21 13:25:11 +03:00
|
|
|
|
2014-11-20 21:24:09 +03:00
|
|
|
/* static */ UndisplayedNode*
|
|
|
|
nsFrameManager::GetAllUndisplayedNodesInMapFor(UndisplayedMap* aMap,
|
|
|
|
nsIContent* aParentContent)
|
|
|
|
{
|
|
|
|
return aMap ? aMap->GetFirstNode(aParentContent) : nullptr;
|
|
|
|
}
|
|
|
|
|
2013-07-20 23:14:25 +04:00
|
|
|
UndisplayedNode*
|
2017-08-01 19:03:07 +03:00
|
|
|
nsFrameManager::GetAllRegisteredDisplayNoneStylesIn(nsIContent* aParentContent)
|
2013-07-20 23:14:25 +04:00
|
|
|
{
|
2017-08-01 15:50:23 +03:00
|
|
|
return GetAllUndisplayedNodesInMapFor(mDisplayNoneMap, aParentContent);
|
2013-07-20 23:14:25 +04:00
|
|
|
}
|
|
|
|
|
2014-11-20 21:24:09 +03:00
|
|
|
/* static */ void
|
|
|
|
nsFrameManager::SetStyleContextInMap(UndisplayedMap* aMap,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsStyleContext* aStyleContext)
|
1999-10-02 08:25:29 +04:00
|
|
|
{
|
2017-03-19 22:19:06 +03:00
|
|
|
MOZ_ASSERT(!aStyleContext->GetPseudo(),
|
|
|
|
"Should only have actual elements here");
|
2009-05-15 05:40:26 +04:00
|
|
|
|
2014-11-20 21:24:09 +03:00
|
|
|
#if defined(DEBUG_UNDISPLAYED_MAP) || defined(DEBUG_DISPLAY_BOX_CONTENTS_MAP)
|
2006-05-13 00:36:39 +04:00
|
|
|
static int i = 0;
|
2014-11-20 21:24:09 +03:00
|
|
|
printf("SetStyleContextInMap(%d): p=%p \n", i++, (void *)aContent);
|
2002-04-03 01:14:43 +04:00
|
|
|
#endif
|
|
|
|
|
2017-03-19 22:19:06 +03:00
|
|
|
MOZ_ASSERT(!GetStyleContextInMap(aMap, aContent),
|
|
|
|
"Already have an entry for aContent");
|
2006-05-13 00:36:39 +04:00
|
|
|
|
2017-08-04 16:52:25 +03:00
|
|
|
// This function is an entry point into UndisplayedMap handling code, so the
|
|
|
|
// parent that we act on must be normalized by GetApplicableParent (as per
|
|
|
|
// that function's documentation). We rely on ParentForUndisplayedMap to
|
|
|
|
// have done that for us.
|
2017-02-21 13:25:11 +03:00
|
|
|
nsIContent* parent = ParentForUndisplayedMap(aContent);
|
2017-08-04 16:52:25 +03:00
|
|
|
|
2014-11-20 21:24:09 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsIPresShell* shell = aStyleContext->PresContext()->PresShell();
|
|
|
|
NS_ASSERTION(parent || (shell && shell->GetDocument() &&
|
|
|
|
shell->GetDocument()->GetRootElement() == aContent),
|
2011-04-29 09:02:40 +04:00
|
|
|
"undisplayed content must have a parent, unless it's the root "
|
|
|
|
"element");
|
2014-11-20 21:24:09 +03:00
|
|
|
#endif
|
2017-08-04 21:09:41 +03:00
|
|
|
|
|
|
|
// We set this bit as an optimization so that we can can know when a content
|
|
|
|
// node may have |display:none| or |display:contents| children. This allows
|
|
|
|
// other parts of the code to avoid checking for such children in
|
|
|
|
// mDisplayNoneMap and mDisplayContentsMap if the bit isn't present on a node
|
|
|
|
// that it's handling.
|
|
|
|
if (parent) {
|
|
|
|
parent->SetMayHaveChildrenWithLayoutBoxesDisabled();
|
|
|
|
}
|
|
|
|
|
2014-11-20 21:24:09 +03:00
|
|
|
aMap->AddNodeFor(parent, aContent, aStyleContext);
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|
|
|
|
|
2003-06-19 01:54:51 +04:00
|
|
|
void
|
2017-08-01 17:04:36 +03:00
|
|
|
nsFrameManager::RegisterDisplayNoneStyleFor(nsIContent* aContent,
|
|
|
|
nsStyleContext* aStyleContext)
|
2003-06-19 01:54:51 +04:00
|
|
|
{
|
2017-08-01 15:50:23 +03:00
|
|
|
if (!mDisplayNoneMap) {
|
|
|
|
mDisplayNoneMap = new UndisplayedMap;
|
2014-11-20 21:24:09 +03:00
|
|
|
}
|
2017-08-01 15:50:23 +03:00
|
|
|
SetStyleContextInMap(mDisplayNoneMap, aContent, aStyleContext);
|
2014-11-20 21:24:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsFrameManager::ChangeStyleContextInMap(UndisplayedMap* aMap,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsStyleContext* aStyleContext)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aMap, "expecting a map");
|
|
|
|
|
|
|
|
#if defined(DEBUG_UNDISPLAYED_MAP) || defined(DEBUG_DISPLAY_BOX_CONTENTS_MAP)
|
2003-06-19 01:54:51 +04:00
|
|
|
static int i = 0;
|
2014-11-20 21:24:09 +03:00
|
|
|
printf("ChangeStyleContextInMap(%d): p=%p \n", i++, (void *)aContent);
|
2003-06-19 01:54:51 +04:00
|
|
|
#endif
|
|
|
|
|
2017-08-04 16:52:25 +03:00
|
|
|
// This function is an entry point into UndisplayedMap handling code, so the
|
|
|
|
// parent that we act on must be normalized by GetApplicableParent (as per
|
|
|
|
// that function's documentation). We rely on ParentForUndisplayedMap to
|
|
|
|
// have done that for us.
|
2017-08-03 15:51:24 +03:00
|
|
|
nsIContent* parent = ParentForUndisplayedMap(aContent);
|
|
|
|
|
|
|
|
for (UndisplayedNode* node = aMap->GetFirstNode(parent);
|
2017-03-19 22:19:06 +03:00
|
|
|
node; node = node->getNext()) {
|
2003-06-19 01:54:51 +04:00
|
|
|
if (node->mContent == aContent) {
|
|
|
|
node->mStyle = aStyleContext;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 21:24:09 +03:00
|
|
|
MOZ_CRASH("couldn't find the entry to change");
|
2003-06-19 01:54:51 +04:00
|
|
|
}
|
|
|
|
|
2004-02-24 00:29:06 +03:00
|
|
|
void
|
2017-08-01 19:12:44 +03:00
|
|
|
nsFrameManager::UnregisterDisplayNoneStyleFor(nsIContent* aContent,
|
|
|
|
nsIContent* aParentContent)
|
1999-10-02 08:25:29 +04:00
|
|
|
{
|
2002-04-03 01:14:43 +04:00
|
|
|
#ifdef DEBUG_UNDISPLAYED_MAP
|
|
|
|
static int i = 0;
|
|
|
|
printf("ClearUndisplayedContent(%d): content=%p parent=%p --> ", i++, (void *)aContent, (void*)aParentContent);
|
|
|
|
#endif
|
2017-03-19 22:19:06 +03:00
|
|
|
|
2017-08-01 15:50:23 +03:00
|
|
|
if (!mDisplayNoneMap) {
|
2017-03-19 22:19:06 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-04 16:52:25 +03:00
|
|
|
// This function is an entry point into UndisplayedMap handling code, so we
|
|
|
|
// must call GetApplicableParent so the parent we pass around is correct.
|
|
|
|
aParentContent = UndisplayedMap::GetApplicableParent(aParentContent);
|
|
|
|
|
2017-08-04 21:09:41 +03:00
|
|
|
if (aParentContent &&
|
|
|
|
!aParentContent->MayHaveChildrenWithLayoutBoxesDisabled()) {
|
|
|
|
MOZ_ASSERT(!mDisplayNoneMap->GetFirstNode(aParentContent),
|
|
|
|
"MayHaveChildrenWithLayoutBoxesDisabled bit out of sync - "
|
|
|
|
"may fail to remove node from mDisplayNoneMap");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UndisplayedNode* node = mDisplayNoneMap->GetFirstNode(aParentContent);
|
|
|
|
|
|
|
|
const bool haveOneDisplayNoneChild = node && !node->getNext();
|
|
|
|
|
|
|
|
for (; node; node = node->getNext()) {
|
2017-03-19 22:19:06 +03:00
|
|
|
if (node->mContent == aContent) {
|
2017-08-01 15:50:23 +03:00
|
|
|
mDisplayNoneMap->RemoveNodeFor(aParentContent, node);
|
2002-04-03 01:14:43 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_UNDISPLAYED_MAP
|
2017-03-19 22:19:06 +03:00
|
|
|
printf( "REMOVED!\n");
|
2002-04-03 01:14:43 +04:00
|
|
|
#endif
|
2017-03-19 22:19:06 +03:00
|
|
|
// make sure that there are no more entries for the same content
|
2017-08-01 17:27:59 +03:00
|
|
|
MOZ_ASSERT(!GetDisplayNoneStyleFor(aContent),
|
2017-03-19 22:19:06 +03:00
|
|
|
"Found more undisplayed content data after removal");
|
2017-08-04 21:09:41 +03:00
|
|
|
|
|
|
|
if (haveOneDisplayNoneChild) {
|
|
|
|
// There are no more children of aParentContent in mDisplayNoneMap.
|
|
|
|
MOZ_ASSERT(!mDisplayNoneMap->GetFirstNode(aParentContent),
|
|
|
|
"Bad UnsetMayHaveChildrenWithLayoutBoxesDisabled call");
|
|
|
|
// If we also know that none of its children are in mDisplayContentsMap
|
|
|
|
// then we can call UnsetMayHaveChildrenWithLayoutBoxesDisabled. We
|
|
|
|
// don't want to check mDisplayContentsMap though since that involves a
|
|
|
|
// hash table lookup in relatively hot code. Still, we know there are
|
|
|
|
// no children in mDisplayContentsMap if the map is empty, so we do
|
|
|
|
// check for that.
|
|
|
|
if (aParentContent && !mDisplayContentsMap) {
|
|
|
|
aParentContent->UnsetMayHaveChildrenWithLayoutBoxesDisabled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-19 22:19:06 +03:00
|
|
|
return;
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|
|
|
|
}
|
2017-03-19 22:19:06 +03:00
|
|
|
|
2014-11-20 21:24:09 +03:00
|
|
|
#ifdef DEBUG_UNDISPLAYED_MAP
|
|
|
|
printf( "not found.\n");
|
|
|
|
#endif
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|
|
|
|
|
2004-02-24 00:29:06 +03:00
|
|
|
void
|
2017-06-08 13:48:31 +03:00
|
|
|
nsFrameManager::ClearAllMapsFor(nsIContent* aParentContent)
|
1999-10-02 08:25:29 +04:00
|
|
|
{
|
2017-06-08 13:48:31 +03:00
|
|
|
#if defined(DEBUG_UNDISPLAYED_MAP) || defined(DEBUG_DISPLAY_CONTENTS_MAP)
|
2002-04-03 01:14:43 +04:00
|
|
|
static int i = 0;
|
2017-06-08 13:48:31 +03:00
|
|
|
printf("ClearAllMapsFor(%d): parent=%p \n", i++, aParentContent);
|
2002-04-03 01:14:43 +04:00
|
|
|
#endif
|
|
|
|
|
2017-08-04 21:09:41 +03:00
|
|
|
if (!aParentContent ||
|
|
|
|
aParentContent->MayHaveChildrenWithLayoutBoxesDisabled()) {
|
|
|
|
if (mDisplayNoneMap) {
|
|
|
|
mDisplayNoneMap->RemoveNodesFor(aParentContent);
|
|
|
|
}
|
|
|
|
if (mDisplayContentsMap) {
|
|
|
|
nsAutoPtr<LinkedList<UndisplayedNode>> list =
|
|
|
|
mDisplayContentsMap->UnlinkNodesFor(aParentContent);
|
|
|
|
if (list) {
|
|
|
|
while (UndisplayedNode* node = list->popFirst()) {
|
|
|
|
ClearAllMapsFor(node->mContent);
|
|
|
|
delete node;
|
|
|
|
}
|
2017-06-08 13:48:31 +03:00
|
|
|
}
|
|
|
|
}
|
2017-08-04 21:09:41 +03:00
|
|
|
if (aParentContent) {
|
|
|
|
aParentContent->UnsetMayHaveChildrenWithLayoutBoxesDisabled();
|
|
|
|
}
|
2017-06-08 13:48:31 +03:00
|
|
|
}
|
2017-08-04 21:09:41 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
if (mDisplayNoneMap) {
|
|
|
|
MOZ_ASSERT(!mDisplayNoneMap->GetFirstNode(aParentContent),
|
|
|
|
"We failed to remove a node from mDisplayNoneMap");
|
|
|
|
}
|
|
|
|
if (mDisplayContentsMap) {
|
|
|
|
MOZ_ASSERT(!mDisplayContentsMap->GetFirstNode(aParentContent),
|
|
|
|
"We failed to remove a node from mDisplayContentsMap");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2009-08-07 23:51:25 +04: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-02 02:50:08 +04: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()) {
|
2017-06-08 13:48:31 +03:00
|
|
|
auto parent = child->GetParent();
|
|
|
|
if (parent != aParentContent) {
|
2017-08-01 19:12:44 +03:00
|
|
|
UnregisterDisplayNoneStyleFor(child, parent);
|
|
|
|
UnregisterDisplayContentsStyleFor(child, parent);
|
2009-08-07 23:51:25 +04:00
|
|
|
}
|
|
|
|
}
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|
|
|
|
|
2014-11-20 21:24:09 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
2017-08-01 17:04:36 +03:00
|
|
|
nsFrameManager::RegisterDisplayContentsStyleFor(nsIContent* aContent,
|
|
|
|
nsStyleContext* aStyleContext)
|
2014-11-20 21:24:09 +03:00
|
|
|
{
|
|
|
|
if (!mDisplayContentsMap) {
|
|
|
|
mDisplayContentsMap = new UndisplayedMap;
|
|
|
|
}
|
|
|
|
SetStyleContextInMap(mDisplayContentsMap, aContent, aStyleContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
UndisplayedNode*
|
2017-08-01 19:03:07 +03:00
|
|
|
nsFrameManager::GetAllRegisteredDisplayContentsStylesIn(nsIContent* aParentContent)
|
2014-11-20 21:24:09 +03:00
|
|
|
{
|
|
|
|
return GetAllUndisplayedNodesInMapFor(mDisplayContentsMap, aParentContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-08-01 19:12:44 +03:00
|
|
|
nsFrameManager::UnregisterDisplayContentsStyleFor(nsIContent* aContent,
|
|
|
|
nsIContent* aParentContent)
|
2014-11-20 21:24:09 +03:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_DISPLAY_CONTENTS_MAP
|
|
|
|
static int i = 0;
|
|
|
|
printf("ClearDisplayContents(%d): content=%p parent=%p --> ", i++, (void *)aContent, (void*)aParentContent);
|
|
|
|
#endif
|
2017-03-19 22:19:06 +03:00
|
|
|
|
|
|
|
if (!mDisplayContentsMap) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-04 16:52:25 +03:00
|
|
|
// This function is an entry point into UndisplayedMap handling code, so we
|
|
|
|
// must call GetApplicableParent so the parent we pass around is correct.
|
|
|
|
aParentContent = UndisplayedMap::GetApplicableParent(aParentContent);
|
|
|
|
|
2017-08-04 21:09:41 +03:00
|
|
|
if (aParentContent &&
|
|
|
|
!aParentContent->MayHaveChildrenWithLayoutBoxesDisabled()) {
|
|
|
|
MOZ_ASSERT(!mDisplayContentsMap->GetFirstNode(aParentContent),
|
|
|
|
"MayHaveChildrenWithLayoutBoxesDisabled bit out of sync - "
|
|
|
|
"may fail to remove node from mDisplayContentsMap");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UndisplayedNode* node = mDisplayContentsMap->GetFirstNode(aParentContent);
|
|
|
|
|
|
|
|
const bool haveOneDisplayContentsChild = node && !node->getNext();
|
|
|
|
|
|
|
|
for (; node; node = node->getNext()) {
|
2017-03-19 22:19:06 +03:00
|
|
|
if (node->mContent == aContent) {
|
|
|
|
mDisplayContentsMap->RemoveNodeFor(aParentContent, node);
|
2014-11-20 21:24:09 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG_DISPLAY_CONTENTS_MAP
|
2017-03-19 22:19:06 +03:00
|
|
|
printf( "REMOVED!\n");
|
2014-11-20 21:24:09 +03:00
|
|
|
#endif
|
2017-03-19 22:19:06 +03:00
|
|
|
// make sure that there are no more entries for the same content
|
|
|
|
MOZ_ASSERT(!GetDisplayContentsStyleFor(aContent),
|
|
|
|
"Found more entries for aContent after removal");
|
2017-06-08 13:48:31 +03:00
|
|
|
ClearAllMapsFor(aContent);
|
2017-08-04 21:09:41 +03:00
|
|
|
|
|
|
|
if (haveOneDisplayContentsChild) {
|
|
|
|
// There are no more children of aParentContent in mDisplayContentsMap.
|
|
|
|
MOZ_ASSERT(!mDisplayContentsMap->GetFirstNode(aParentContent),
|
|
|
|
"Bad UnsetMayHaveChildrenWithLayoutBoxesDisabled call");
|
|
|
|
// If we also know that none of its children are in mDisplayNoneMap
|
|
|
|
// then we can call UnsetMayHaveChildrenWithLayoutBoxesDisabled. We
|
|
|
|
// don't want to check mDisplayNoneMap though since that involves a
|
|
|
|
// hash table lookup in relatively hot code. Still, we know there are
|
|
|
|
// no children in mDisplayNoneMap if the map is empty, so we do
|
|
|
|
// check for that.
|
|
|
|
if (aParentContent && !mDisplayNoneMap) {
|
|
|
|
aParentContent->UnsetMayHaveChildrenWithLayoutBoxesDisabled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-19 22:19:06 +03:00
|
|
|
return;
|
2014-11-20 21:24:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef DEBUG_DISPLAY_CONTENTS_MAP
|
|
|
|
printf( "not found.\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-10-02 08:25:29 +04:00
|
|
|
//----------------------------------------------------------------------
|
2014-05-28 23:36:58 +04:00
|
|
|
void
|
2014-05-25 02:20:40 +04:00
|
|
|
nsFrameManager::AppendFrames(nsContainerFrame* aParentFrame,
|
|
|
|
ChildListID aListID,
|
|
|
|
nsFrameList& aFrameList)
|
2011-04-30 03:02:33 +04:00
|
|
|
{
|
|
|
|
if (aParentFrame->IsAbsoluteContainer() &&
|
|
|
|
aListID == aParentFrame->GetAbsoluteListID()) {
|
2014-05-28 23:36:58 +04:00
|
|
|
aParentFrame->GetAbsoluteContainingBlock()->
|
|
|
|
AppendFrames(aParentFrame, aListID, aFrameList);
|
2011-04-30 03:02:33 +04:00
|
|
|
} else {
|
2014-05-28 23:36:58 +04:00
|
|
|
aParentFrame->AppendFrames(aListID, aFrameList);
|
2011-04-30 03:02:33 +04:00
|
|
|
}
|
|
|
|
}
|
1999-10-02 08:25:29 +04:00
|
|
|
|
2014-05-28 23:36:58 +04:00
|
|
|
void
|
2014-05-25 02:20:40 +04:00
|
|
|
nsFrameManager::InsertFrames(nsContainerFrame* aParentFrame,
|
|
|
|
ChildListID aListID,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsFrameList& aFrameList)
|
1999-08-04 07:39:34 +04:00
|
|
|
{
|
2007-11-12 22:05:42 +03:00
|
|
|
NS_PRECONDITION(!aPrevFrame || (!aPrevFrame->GetNextContinuation()
|
2012-10-15 09:42:40 +04:00
|
|
|
|| (((aPrevFrame->GetNextContinuation()->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER))
|
|
|
|
&& !(aPrevFrame->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER))),
|
2006-02-22 00:33:47 +03:00
|
|
|
"aPrevFrame must be the last continuation in its chain!");
|
2001-03-09 06:29:00 +03:00
|
|
|
|
2011-04-30 03:02:33 +04:00
|
|
|
if (aParentFrame->IsAbsoluteContainer() &&
|
|
|
|
aListID == aParentFrame->GetAbsoluteListID()) {
|
2014-05-28 23:36:58 +04:00
|
|
|
aParentFrame->GetAbsoluteContainingBlock()->
|
|
|
|
InsertFrames(aParentFrame, aListID, aPrevFrame, aFrameList);
|
2011-04-30 03:02:33 +04:00
|
|
|
} else {
|
2014-05-28 23:36:58 +04:00
|
|
|
aParentFrame->InsertFrames(aListID, aPrevFrame, aFrameList);
|
2011-04-30 03:02:33 +04:00
|
|
|
}
|
1999-08-04 07:39:34 +04:00
|
|
|
}
|
|
|
|
|
2014-05-28 23:36:58 +04:00
|
|
|
void
|
2011-08-25 00:54:30 +04:00
|
|
|
nsFrameManager::RemoveFrame(ChildListID aListID,
|
2012-08-29 09:39:31 +04:00
|
|
|
nsIFrame* aOldFrame)
|
1999-08-04 07:39:34 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool wasDestroyingFrames = mIsDestroyingFrames;
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsDestroyingFrames = true;
|
2008-12-12 11:25:16 +03:00
|
|
|
|
2012-08-29 09:48:45 +04: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-24 08:20:41 +03:00
|
|
|
NS_ASSERTION(!aOldFrame->GetPrevContinuation() ||
|
|
|
|
// exception for nsCSSFrameConstructor::RemoveFloatingFirstLetterFrames
|
2017-04-30 18:30:08 +03:00
|
|
|
aOldFrame->IsTextFrame(),
|
2009-12-24 08:20:41 +03:00
|
|
|
"Must remove first continuation.");
|
|
|
|
NS_ASSERTION(!(aOldFrame->GetStateBits() & NS_FRAME_OUT_OF_FLOW &&
|
2017-05-31 22:29:49 +03:00
|
|
|
aOldFrame->GetPlaceholderFrame()),
|
2009-12-24 08:20:41 +03:00
|
|
|
"Must call RemoveFrame on placeholder for out-of-flows.");
|
2014-05-25 02:20:40 +04:00
|
|
|
nsContainerFrame* parentFrame = aOldFrame->GetParent();
|
2011-04-30 03:02:33 +04:00
|
|
|
if (parentFrame->IsAbsoluteContainer() &&
|
|
|
|
aListID == parentFrame->GetAbsoluteListID()) {
|
|
|
|
parentFrame->GetAbsoluteContainingBlock()->
|
|
|
|
RemoveFrame(parentFrame, aListID, aOldFrame);
|
|
|
|
} else {
|
2014-05-28 23:36:58 +04:00
|
|
|
parentFrame->RemoveFrame(aListID, aOldFrame);
|
2011-04-30 03:02:33 +04:00
|
|
|
}
|
2008-12-12 11:25:16 +03:00
|
|
|
|
2008-10-13 02:05:04 +04:00
|
|
|
mIsDestroyingFrames = wasDestroyingFrames;
|
1999-08-04 07:39:34 +04:00
|
|
|
}
|
|
|
|
|
1999-08-06 00:17:44 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2004-02-24 00:29:06 +03:00
|
|
|
void
|
|
|
|
nsFrameManager::NotifyDestroyingFrame(nsIFrame* aFrame)
|
1999-08-06 00:17:44 +04:00
|
|
|
{
|
2009-12-24 08:20:41 +03:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
2009-12-29 23:13:54 +03:00
|
|
|
if (content && content->GetPrimaryFrame() == aFrame) {
|
2017-06-08 13:48:31 +03:00
|
|
|
ClearAllMapsFor(content);
|
2001-12-11 22:16:15 +03:00
|
|
|
}
|
1999-08-06 00:17:44 +04:00
|
|
|
}
|
|
|
|
|
2000-06-15 04:35:46 +04:00
|
|
|
// Capture state for a given frame.
|
|
|
|
// Accept a content id here, in some cases we may not have content (scroll position)
|
2004-02-24 00:29:06 +03:00
|
|
|
void
|
|
|
|
nsFrameManager::CaptureFrameStateFor(nsIFrame* aFrame,
|
2012-11-15 10:40:17 +04:00
|
|
|
nsILayoutHistoryState* aState)
|
1999-08-31 18:35:50 +04:00
|
|
|
{
|
2004-02-24 00:29:06 +03:00
|
|
|
if (!aFrame || !aState) {
|
|
|
|
NS_WARNING("null frame, or state");
|
|
|
|
return;
|
|
|
|
}
|
1999-08-31 18:35:50 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
// Only capture state for stateful frames
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIStatefulFrame* statefulFrame = do_QueryFrame(aFrame);
|
2001-05-30 15:26:21 +04:00
|
|
|
if (!statefulFrame) {
|
2004-02-24 00:29:06 +03:00
|
|
|
return;
|
2001-05-30 15:26:21 +04:00
|
|
|
}
|
2000-06-15 04:35:46 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
// Capture the state, exit early if we get null (nothing to save)
|
2005-01-28 01:52:53 +03:00
|
|
|
nsAutoPtr<nsPresState> frameState;
|
2012-11-15 10:40:17 +04:00
|
|
|
nsresult rv = statefulFrame->SaveState(getter_Transfers(frameState));
|
2001-05-30 15:26:21 +04:00
|
|
|
if (!frameState) {
|
2004-02-24 00:29:06 +03:00
|
|
|
return;
|
2001-05-30 15:26:21 +04:00
|
|
|
}
|
2000-06-15 04:35:46 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
// Generate the hash key to store the state under
|
|
|
|
// Exit early if we get empty key
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString stateKey;
|
2005-01-15 20:47:23 +03:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
2016-03-31 14:46:32 +03:00
|
|
|
nsIDocument* doc = content ? content->GetUncomposedDoc() : nullptr;
|
2016-03-10 18:14:37 +03:00
|
|
|
rv = statefulFrame->GenerateStateKey(content, doc, stateKey);
|
2001-05-30 15:26:21 +04:00
|
|
|
if(NS_FAILED(rv) || stateKey.IsEmpty()) {
|
2004-02-24 00:29:06 +03:00
|
|
|
return;
|
1999-08-31 18:35:50 +04:00
|
|
|
}
|
|
|
|
|
2013-07-24 11:38:13 +04:00
|
|
|
// Store the state. aState owns frameState now.
|
|
|
|
aState->AddState(stateKey, frameState.forget());
|
1999-10-23 05:43:49 +04:00
|
|
|
}
|
1999-08-31 18:35:50 +04:00
|
|
|
|
2004-02-24 00:29:06 +03:00
|
|
|
void
|
|
|
|
nsFrameManager::CaptureFrameState(nsIFrame* aFrame,
|
|
|
|
nsILayoutHistoryState* aState)
|
1999-10-23 05:43:49 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(nullptr != aFrame && nullptr != aState, "null parameters passed in");
|
1999-08-31 18:35:50 +04:00
|
|
|
|
2004-02-24 00:29:06 +03:00
|
|
|
CaptureFrameStateFor(aFrame, aState);
|
1999-10-23 05:43:49 +04:00
|
|
|
|
|
|
|
// Now capture state recursively for the frame hierarchy rooted at aFrame
|
2011-08-25 00:54:29 +04:00
|
|
|
nsIFrame::ChildListIterator lists(aFrame);
|
|
|
|
for (; !lists.IsDone(); lists.Next()) {
|
|
|
|
nsFrameList::Enumerator childFrames(lists.CurrentList());
|
|
|
|
for (; !childFrames.AtEnd(); childFrames.Next()) {
|
2012-05-10 05:27:47 +04: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);
|
1999-10-23 05:43:49 +04:00
|
|
|
}
|
2011-08-25 00:54:29 +04:00
|
|
|
}
|
1999-08-31 18:35:50 +04:00
|
|
|
}
|
|
|
|
|
2000-06-15 04:35:46 +04:00
|
|
|
// Restore state for a given frame.
|
|
|
|
// Accept a content id here, in some cases we may not have content (scroll position)
|
2004-02-24 00:29:06 +03:00
|
|
|
void
|
|
|
|
nsFrameManager::RestoreFrameStateFor(nsIFrame* aFrame,
|
2012-11-15 10:40:17 +04:00
|
|
|
nsILayoutHistoryState* aState)
|
1999-08-31 18:35:50 +04:00
|
|
|
{
|
2004-02-24 00:29:06 +03:00
|
|
|
if (!aFrame || !aState) {
|
|
|
|
NS_WARNING("null frame or state");
|
|
|
|
return;
|
|
|
|
}
|
1999-08-31 18:35:50 +04:00
|
|
|
|
2008-12-03 20:55:14 +03:00
|
|
|
// Only restore state for stateful frames
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIStatefulFrame* statefulFrame = do_QueryFrame(aFrame);
|
2001-05-30 15:26:21 +04:00
|
|
|
if (!statefulFrame) {
|
2004-02-24 00:29:06 +03:00
|
|
|
return;
|
2001-05-30 15:26:21 +04:00
|
|
|
}
|
2000-06-15 04:35:46 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
// Generate the hash key the state was stored under
|
|
|
|
// Exit early if we get empty key
|
2003-06-29 07:43:05 +04:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
2001-09-29 21:50:15 +04:00
|
|
|
// If we don't have content, we can't generate a hash
|
|
|
|
// key and there's probably no state information for us.
|
|
|
|
if (!content) {
|
2004-02-24 00:29:06 +03:00
|
|
|
return;
|
2001-09-29 21:50:15 +04:00
|
|
|
}
|
2000-06-15 04:35:46 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString stateKey;
|
2016-03-31 14:46:32 +03:00
|
|
|
nsIDocument* doc = content->GetUncomposedDoc();
|
2016-03-10 18:14:37 +03:00
|
|
|
nsresult rv = statefulFrame->GenerateStateKey(content, doc, stateKey);
|
2001-11-02 10:40:01 +03:00
|
|
|
if (NS_FAILED(rv) || stateKey.IsEmpty()) {
|
2004-02-24 00:29:06 +03:00
|
|
|
return;
|
2001-05-30 15:26:21 +04:00
|
|
|
}
|
2000-06-15 04:35:46 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
// Get the state from the hash
|
2013-07-24 11:38:13 +04:00
|
|
|
nsPresState* frameState = aState->GetState(stateKey);
|
2001-05-30 15:26:21 +04:00
|
|
|
if (!frameState) {
|
2004-02-24 00:29:06 +03:00
|
|
|
return;
|
2001-05-30 15:26:21 +04:00
|
|
|
}
|
2000-06-15 04:35:46 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
// Restore it
|
2005-12-07 02:56:17 +03:00
|
|
|
rv = statefulFrame->RestoreState(frameState);
|
2004-02-24 00:29:06 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
1999-08-31 18:35:50 +04:00
|
|
|
|
2001-05-30 15:26:21 +04:00
|
|
|
// If we restore ok, remove the state from the state table
|
2004-02-24 00:29:06 +03:00
|
|
|
aState->RemoveState(stateKey);
|
1999-10-23 05:43:49 +04:00
|
|
|
}
|
1999-08-31 18:35:50 +04:00
|
|
|
|
2004-02-24 00:29:06 +03:00
|
|
|
void
|
|
|
|
nsFrameManager::RestoreFrameState(nsIFrame* aFrame,
|
|
|
|
nsILayoutHistoryState* aState)
|
1999-10-23 05:43:49 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(nullptr != aFrame && nullptr != aState, "null parameters passed in");
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2004-02-24 00:29:06 +03:00
|
|
|
RestoreFrameStateFor(aFrame, aState);
|
1999-10-23 05:43:49 +04:00
|
|
|
|
|
|
|
// Now restore state recursively for the frame hierarchy rooted at aFrame
|
2011-08-25 00:54:29 +04:00
|
|
|
nsIFrame::ChildListIterator lists(aFrame);
|
|
|
|
for (; !lists.IsDone(); lists.Next()) {
|
|
|
|
nsFrameList::Enumerator childFrames(lists.CurrentList());
|
|
|
|
for (; !childFrames.AtEnd(); childFrames.Next()) {
|
|
|
|
RestoreFrameState(childFrames.get(), aState);
|
1999-10-23 05:43:49 +04:00
|
|
|
}
|
2011-08-25 00:54:29 +04:00
|
|
|
}
|
1999-08-31 18:35:50 +04:00
|
|
|
}
|
|
|
|
|
2017-08-26 04:30:45 +03:00
|
|
|
void
|
|
|
|
nsFrameManager::DestroyAnonymousContent(already_AddRefed<nsIContent> aContent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content = aContent;
|
|
|
|
if (content) {
|
|
|
|
// Invoke ClearAllMapsFor before unbinding from the tree. When we unbind,
|
|
|
|
// we remove the mPrimaryFrame pointer, which is used by the frame
|
|
|
|
// teardown code to determine whether to invoke ClearAllMapsFor or not.
|
|
|
|
// These maps will go away when we drop support for the old style system.
|
|
|
|
ClearAllMapsFor(content);
|
|
|
|
|
|
|
|
content->UnbindFromTree();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-06 00:17:44 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2017-03-19 22:19:06 +03:00
|
|
|
nsFrameManagerBase::UndisplayedMap::UndisplayedMap()
|
1999-10-02 08:25:29 +04:00
|
|
|
{
|
2004-03-06 07:46:11 +03:00
|
|
|
MOZ_COUNT_CTOR(nsFrameManagerBase::UndisplayedMap);
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|
|
|
|
|
2004-03-06 07:46:11 +03:00
|
|
|
nsFrameManagerBase::UndisplayedMap::~UndisplayedMap(void)
|
1999-10-02 08:25:29 +04:00
|
|
|
{
|
2004-03-06 07:46:11 +03:00
|
|
|
MOZ_COUNT_DTOR(nsFrameManagerBase::UndisplayedMap);
|
1999-10-02 08:25:29 +04:00
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
2017-03-19 22:19:06 +03:00
|
|
|
void
|
|
|
|
nsFrameManagerBase::UndisplayedMap::Clear()
|
1999-10-02 08:25:29 +04:00
|
|
|
{
|
2017-03-19 22:19:06 +03:00
|
|
|
for (auto iter = Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
auto* list = iter.UserData();
|
|
|
|
while (auto* node = list->popFirst()) {
|
|
|
|
delete node;
|
|
|
|
}
|
|
|
|
iter.Remove();
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|
2017-03-19 22:19:06 +03:00
|
|
|
}
|
2013-06-21 03:21:15 +04:00
|
|
|
|
2017-03-19 22:19:06 +03:00
|
|
|
|
|
|
|
nsIContent*
|
|
|
|
nsFrameManagerBase::UndisplayedMap::GetApplicableParent(nsIContent* aParent)
|
|
|
|
{
|
2013-06-21 03:21:15 +04: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.
|
2017-12-21 00:45:19 +03:00
|
|
|
if (aParent && aParent->IsActiveChildrenElement()) {
|
2017-03-19 22:19:06 +03:00
|
|
|
return aParent->GetParent();
|
2013-06-21 03:21:15 +04:00
|
|
|
}
|
|
|
|
|
2017-03-19 22:19:06 +03:00
|
|
|
return aParent;
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|
|
|
|
|
2017-03-19 22:19:06 +03:00
|
|
|
LinkedList<UndisplayedNode>*
|
2017-05-01 19:57:55 +03:00
|
|
|
nsFrameManagerBase::UndisplayedMap::GetListFor(nsIContent* aParent)
|
1999-10-02 08:25:29 +04:00
|
|
|
{
|
2017-08-04 16:52:25 +03:00
|
|
|
MOZ_ASSERT(aParent == GetApplicableParent(aParent),
|
|
|
|
"The parent that we use as the hash key must have been normalized");
|
2017-03-19 22:19:06 +03:00
|
|
|
|
|
|
|
LinkedList<UndisplayedNode>* list;
|
2017-05-01 19:57:55 +03:00
|
|
|
if (Get(aParent, &list)) {
|
2017-03-19 22:19:06 +03:00
|
|
|
return list;
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|
2017-03-19 22:19:06 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|
|
|
|
|
2017-03-19 22:19:06 +03:00
|
|
|
LinkedList<UndisplayedNode>*
|
2017-05-01 19:57:55 +03:00
|
|
|
nsFrameManagerBase::UndisplayedMap::GetOrCreateListFor(nsIContent* aParent)
|
2017-03-19 22:19:06 +03:00
|
|
|
{
|
2017-08-04 16:52:25 +03:00
|
|
|
MOZ_ASSERT(aParent == GetApplicableParent(aParent),
|
|
|
|
"The parent that we use as the hash key must have been normalized");
|
|
|
|
|
2017-05-01 19:57:55 +03:00
|
|
|
return LookupOrAdd(aParent);
|
2017-03-19 22:19:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UndisplayedNode*
|
|
|
|
nsFrameManagerBase::UndisplayedMap::GetFirstNode(nsIContent* aParentContent)
|
|
|
|
{
|
2017-05-01 19:57:55 +03:00
|
|
|
auto* list = GetListFor(aParentContent);
|
2017-03-19 22:19:06 +03:00
|
|
|
return list ? list->getFirst() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-24 00:29:06 +03:00
|
|
|
void
|
2004-03-06 07:46:11 +03:00
|
|
|
nsFrameManagerBase::UndisplayedMap::AppendNodeFor(UndisplayedNode* aNode,
|
|
|
|
nsIContent* aParentContent)
|
1999-10-02 08:25:29 +04:00
|
|
|
{
|
2017-05-01 19:57:55 +03:00
|
|
|
LinkedList<UndisplayedNode>* list = GetOrCreateListFor(aParentContent);
|
2017-03-19 22:19:06 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
for (UndisplayedNode* node = list->getFirst(); node; node = node->getNext()) {
|
|
|
|
// NOTE: In the original code there was a work around for this case, I want
|
|
|
|
// to check it still happens before hacking around it the same way.
|
|
|
|
MOZ_ASSERT(node->mContent != aNode->mContent,
|
|
|
|
"Duplicated content in undisplayed list!");
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|
2017-03-19 22:19:06 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
list->insertBack(aNode);
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|
|
|
|
|
2017-03-19 22:19:06 +03:00
|
|
|
void
|
2004-03-06 07:46:11 +03:00
|
|
|
nsFrameManagerBase::UndisplayedMap::AddNodeFor(nsIContent* aParentContent,
|
2017-03-19 22:19:06 +03:00
|
|
|
nsIContent* aChild,
|
2004-03-06 07:46:11 +03:00
|
|
|
nsStyleContext* aStyle)
|
1999-10-02 08:25:29 +04:00
|
|
|
{
|
|
|
|
UndisplayedNode* node = new UndisplayedNode(aChild, aStyle);
|
2004-02-24 00:29:06 +03:00
|
|
|
AppendNodeFor(node, aParentContent);
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|
|
|
|
|
2004-02-24 00:29:06 +03:00
|
|
|
void
|
2004-03-06 07:46:11 +03:00
|
|
|
nsFrameManagerBase::UndisplayedMap::RemoveNodeFor(nsIContent* aParentContent,
|
|
|
|
UndisplayedNode* aNode)
|
1999-10-02 08:25:29 +04:00
|
|
|
{
|
2017-03-19 22:19:06 +03:00
|
|
|
#ifdef DEBUG
|
2017-05-01 19:57:55 +03:00
|
|
|
auto list = GetListFor(aParentContent);
|
2017-03-19 22:19:06 +03:00
|
|
|
MOZ_ASSERT(list, "content not in map");
|
|
|
|
aNode->removeFrom(*list);
|
|
|
|
#else
|
|
|
|
aNode->remove();
|
|
|
|
#endif
|
1999-10-02 08:25:29 +04:00
|
|
|
delete aNode;
|
|
|
|
}
|
|
|
|
|
2014-11-20 21:24:09 +03:00
|
|
|
|
2017-03-19 22:19:06 +03:00
|
|
|
nsAutoPtr<LinkedList<UndisplayedNode>>
|
2014-11-20 21:24:09 +03:00
|
|
|
nsFrameManagerBase::UndisplayedMap::UnlinkNodesFor(nsIContent* aParentContent)
|
1999-10-02 08:25:29 +04:00
|
|
|
{
|
2017-03-19 22:19:06 +03:00
|
|
|
nsAutoPtr<LinkedList<UndisplayedNode>> list;
|
2017-07-05 03:01:45 +03:00
|
|
|
Remove(GetApplicableParent(aParentContent), &list);
|
2017-03-19 22:19:06 +03:00
|
|
|
return list;
|
2014-11-20 21:24:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameManagerBase::UndisplayedMap::RemoveNodesFor(nsIContent* aParentContent)
|
|
|
|
{
|
2017-03-19 22:19:06 +03:00
|
|
|
nsAutoPtr<LinkedList<UndisplayedNode>> list = UnlinkNodesFor(aParentContent);
|
|
|
|
if (list) {
|
|
|
|
while (auto* node = list->popFirst()) {
|
|
|
|
delete node;
|
|
|
|
}
|
|
|
|
}
|
1999-10-02 08:25:29 +04:00
|
|
|
}
|