Bug 767130 - Consolidate code duplicated between nsGenericElement.cpp and nsINode.cpp; r=bz

--HG--
rename : content/base/src/nsGenericElement.cpp => content/base/src/nsINode.cpp
extra : rebase_source : 0a14c3b24796cf14c3c90fdeb8147b3f11fd543a
This commit is contained in:
Ms2ger 2012-06-23 08:58:04 +02:00
parent 3d278d217d
commit 5a0691e6d1
5 changed files with 39 additions and 64 deletions

View File

@ -2046,7 +2046,9 @@ public:
Element* aRoot,
PRInt32& aOutStartOffset,
PRInt32& aOutEndOffset);
static nsIEditor* GetHTMLEditor(nsPresContext* aPresContext);
private:
static bool InitializeEventTable();

View File

@ -1170,6 +1170,8 @@ public:
bool Contains(const nsINode* aOther) const;
nsresult Contains(nsIDOMNode* aOther, bool* aReturn);
bool UnoptimizableCCNode() const;
private:
nsIContent* GetNextNodeImpl(const nsINode* aRoot,

View File

@ -173,16 +173,17 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_XTFSERVICE_CID);
#include "mozilla/Base64.h"
#include "mozilla/Preferences.h"
#include "nsDOMMutationObserver.h"
#include "nsWrapperCacheInlines.h"
#include "nsIDOMDocumentType.h"
#include "nsCharSeparatedTokenizer.h"
#include "nsICharsetDetector.h"
#include "nsICharsetDetectionObserver.h"
#include "nsIPlatformCharset.h"
#include "nsIEditor.h"
#include "nsIEditorDocShell.h"
#include "mozilla/Attributes.h"
#include "nsWrapperCacheInlines.h"
extern "C" int MOZ_XMLTranslateEntity(const char* ptr, const char* end,
const char** next, PRUnichar* result);
extern "C" int MOZ_XMLCheckQName(const char* ptr, const char* end,
@ -6917,3 +6918,18 @@ nsContentUtils::GetSelectionInTextControl(Selection* aSelection,
aOutStartOffset = NS_MIN(anchorOffset, focusOffset);
aOutEndOffset = NS_MAX(anchorOffset, focusOffset);
}
nsIEditor*
nsContentUtils::GetHTMLEditor(nsPresContext* aPresContext)
{
nsCOMPtr<nsISupports> container = aPresContext->GetContainer();
nsCOMPtr<nsIEditorDocShell> editorDocShell(do_QueryInterface(container));
bool isEditable;
if (!editorDocShell ||
NS_FAILED(editorDocShell->GetEditable(&isEditable)) || !isEditable)
return nsnull;
nsCOMPtr<nsIEditor> editor;
editorDocShell->GetEditor(getter_AddRefs(editor));
return editor;
}

View File

@ -135,37 +135,6 @@ PRInt32 nsIContent::sTabFocusModel = eTabFocus_any;
bool nsIContent::sTabFocusModelAppliesToXUL = false;
PRUint32 nsMutationGuard::sMutationCount = 0;
static nsIEditor* GetHTMLEditor(nsPresContext* aPresContext)
{
nsCOMPtr<nsISupports> container = aPresContext->GetContainer();
nsCOMPtr<nsIEditorDocShell> editorDocShell(do_QueryInterface(container));
bool isEditable;
if (!editorDocShell ||
NS_FAILED(editorDocShell->GetEditable(&isEditable)) || !isEditable)
return nsnull;
nsCOMPtr<nsIEditor> editor;
editorDocShell->GetEditor(getter_AddRefs(editor));
return editor;
}
static
bool UnoptimizableCCNode(nsINode* aNode)
{
const PtrBits problematicFlags = (NODE_IS_ANONYMOUS |
NODE_IS_IN_ANONYMOUS_SUBTREE |
NODE_IS_NATIVE_ANONYMOUS_ROOT |
NODE_MAY_BE_IN_BINDING_MNGR |
NODE_IS_INSERTION_PARENT);
return aNode->HasFlag(problematicFlags) ||
aNode->NodeType() == nsIDOMNode::ATTRIBUTE_NODE ||
// For strange cases like xbl:content/xbl:children
(aNode->IsElement() &&
aNode->AsElement()->IsInNamespace(kNameSpaceID_XBL));
}
//----------------------------------------------------------------------
nsEventStates
Element::IntrinsicState() const
{
@ -403,7 +372,7 @@ nsIContent::GetDesiredIMEState()
if (!pc) {
return IMEState(IMEState::DISABLED);
}
nsIEditor* editor = GetHTMLEditor(pc);
nsIEditor* editor = nsContentUtils::GetHTMLEditor(pc);
nsCOMPtr<nsIEditorIMESupport> imeEditor = do_QueryInterface(editor);
if (!imeEditor) {
return IMEState(IMEState::DISABLED);
@ -2882,7 +2851,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGenericElement)
}
// Unlink child content (and unbind our subtree).
if (UnoptimizableCCNode(tmp) || !nsCCUncollectableMarker::sGeneration) {
if (tmp->UnoptimizableCCNode() || !nsCCUncollectableMarker::sGeneration) {
PRUint32 childCount = tmp->mAttrsAndChildren.ChildCount();
if (childCount) {
// Don't allow script to run while we're unbinding everything.
@ -2969,13 +2938,13 @@ FindOptimizableSubtreeRoot(nsINode* aNode)
{
nsINode* p;
while ((p = aNode->GetNodeParent())) {
if (UnoptimizableCCNode(aNode)) {
if (aNode->UnoptimizableCCNode()) {
return nsnull;
}
aNode = p;
}
if (UnoptimizableCCNode(aNode)) {
if (aNode->UnoptimizableCCNode()) {
return nsnull;
}
return aNode;
@ -3016,7 +2985,7 @@ nsGenericElement::CanSkipInCC(nsINode* aNode)
// Bail out early if aNode is somewhere in anonymous content,
// or otherwise unusual.
if (UnoptimizableCCNode(aNode)) {
if (aNode->UnoptimizableCCNode()) {
return false;
}
@ -3175,7 +3144,7 @@ nsGenericElement::CanSkip(nsINode* aNode, bool aRemovingAllowed)
return false;
}
bool unoptimizable = UnoptimizableCCNode(aNode);
bool unoptimizable = aNode->UnoptimizableCCNode();
nsIDocument* currentDoc = aNode->GetCurrentDoc();
if (currentDoc &&
nsCCUncollectableMarker::InGeneration(currentDoc->GetMarkedCCGeneration()) &&

View File

@ -232,20 +232,6 @@ nsINode::GetTextEditorRootContent(nsIEditor** aEditor)
return nsnull;
}
static nsIEditor* GetHTMLEditor(nsPresContext* aPresContext)
{
nsCOMPtr<nsISupports> container = aPresContext->GetContainer();
nsCOMPtr<nsIEditorDocShell> editorDocShell(do_QueryInterface(container));
bool isEditable;
if (!editorDocShell ||
NS_FAILED(editorDocShell->GetEditable(&isEditable)) || !isEditable)
return nsnull;
nsCOMPtr<nsIEditor> editor;
editorDocShell->GetEditor(getter_AddRefs(editor));
return editor;
}
static nsIContent* GetRootForContentSubtree(nsIContent* aContent)
{
NS_ENSURE_TRUE(aContent, nsnull);
@ -283,7 +269,7 @@ nsINode::GetSelectionRootContent(nsIPresShell* aPresShell)
nsPresContext* presContext = aPresShell->GetPresContext();
if (presContext) {
nsIEditor* editor = GetHTMLEditor(presContext);
nsIEditor* editor = nsContentUtils::GetHTMLEditor(presContext);
if (editor) {
// This node is in HTML editor.
nsIDocument* doc = GetCurrentDoc();
@ -1132,19 +1118,19 @@ nsINode::Trace(nsINode *tmp, TraceCallback cb, void *closure)
}
static
bool UnoptimizableCCNode(nsINode* aNode)
bool
nsINode::UnoptimizableCCNode() const
{
const PtrBits problematicFlags = (NODE_IS_ANONYMOUS |
NODE_IS_IN_ANONYMOUS_SUBTREE |
NODE_IS_NATIVE_ANONYMOUS_ROOT |
NODE_MAY_BE_IN_BINDING_MNGR |
NODE_IS_INSERTION_PARENT);
return aNode->HasFlag(problematicFlags) ||
aNode->NodeType() == nsIDOMNode::ATTRIBUTE_NODE ||
return HasFlag(problematicFlags) ||
NodeType() == nsIDOMNode::ATTRIBUTE_NODE ||
// For strange cases like xbl:content/xbl:children
(aNode->IsElement() &&
aNode->AsElement()->IsInNamespace(kNameSpaceID_XBL));
(IsElement() &&
AsElement()->IsInNamespace(kNameSpaceID_XBL));
}
/* static */
@ -1164,7 +1150,7 @@ nsINode::Traverse(nsINode *tmp, nsCycleCollectionTraversalCallback &cb)
return false;
}
if (!UnoptimizableCCNode(tmp)) {
if (!tmp->UnoptimizableCCNode()) {
// If we're in a black document, return early.
if ((currentDoc && currentDoc->IsBlack())) {
return false;
@ -1172,7 +1158,7 @@ nsINode::Traverse(nsINode *tmp, nsCycleCollectionTraversalCallback &cb)
// If we're not in anonymous content and we have a black parent,
// return early.
nsIContent* parent = tmp->GetParent();
if (parent && !UnoptimizableCCNode(parent) && parent->IsBlack()) {
if (parent && !parent->UnoptimizableCCNode() && parent->IsBlack()) {
NS_ABORT_IF_FALSE(parent->IndexOf(tmp) >= 0, "Parent doesn't own us?");
return false;
}