diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 35b9b8af56c..9dcf14c2334 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -2046,7 +2046,9 @@ public: Element* aRoot, PRInt32& aOutStartOffset, PRInt32& aOutEndOffset); - + + static nsIEditor* GetHTMLEditor(nsPresContext* aPresContext); + private: static bool InitializeEventTable(); diff --git a/content/base/public/nsINode.h b/content/base/public/nsINode.h index 8ae8309c227..ba7085e596d 100644 --- a/content/base/public/nsINode.h +++ b/content/base/public/nsINode.h @@ -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, diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index d81e7b1ba0c..d3b37e47100 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -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 container = aPresContext->GetContainer(); + nsCOMPtr editorDocShell(do_QueryInterface(container)); + bool isEditable; + if (!editorDocShell || + NS_FAILED(editorDocShell->GetEditable(&isEditable)) || !isEditable) + return nsnull; + + nsCOMPtr editor; + editorDocShell->GetEditor(getter_AddRefs(editor)); + return editor; +} diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 5e23d64745c..81e7e93f0bd 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -135,37 +135,6 @@ PRInt32 nsIContent::sTabFocusModel = eTabFocus_any; bool nsIContent::sTabFocusModelAppliesToXUL = false; PRUint32 nsMutationGuard::sMutationCount = 0; -static nsIEditor* GetHTMLEditor(nsPresContext* aPresContext) -{ - nsCOMPtr container = aPresContext->GetContainer(); - nsCOMPtr editorDocShell(do_QueryInterface(container)); - bool isEditable; - if (!editorDocShell || - NS_FAILED(editorDocShell->GetEditable(&isEditable)) || !isEditable) - return nsnull; - - nsCOMPtr 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 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()) && diff --git a/content/base/src/nsINode.cpp b/content/base/src/nsINode.cpp index 260f2afc2a7..00db5e6d84c 100644 --- a/content/base/src/nsINode.cpp +++ b/content/base/src/nsINode.cpp @@ -232,20 +232,6 @@ nsINode::GetTextEditorRootContent(nsIEditor** aEditor) return nsnull; } -static nsIEditor* GetHTMLEditor(nsPresContext* aPresContext) -{ - nsCOMPtr container = aPresContext->GetContainer(); - nsCOMPtr editorDocShell(do_QueryInterface(container)); - bool isEditable; - if (!editorDocShell || - NS_FAILED(editorDocShell->GetEditable(&isEditable)) || !isEditable) - return nsnull; - - nsCOMPtr 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; }