diff --git a/dom/base/nsGenericDOMDataNode.cpp b/dom/base/nsGenericDOMDataNode.cpp index 938bf613e..4db131db1 100644 --- a/dom/base/nsGenericDOMDataNode.cpp +++ b/dom/base/nsGenericDOMDataNode.cpp @@ -976,7 +976,7 @@ nsGenericDOMDataNode::GetText() uint32_t nsGenericDOMDataNode::TextLength() const { - return mText.GetLength(); + return TextDataLength(); } nsresult diff --git a/dom/base/nsGenericDOMDataNode.h b/dom/base/nsGenericDOMDataNode.h index 0b60860bc..069748272 100644 --- a/dom/base/nsGenericDOMDataNode.h +++ b/dom/base/nsGenericDOMDataNode.h @@ -219,6 +219,11 @@ public: rv = ReplaceData(aOffset, aCount, aData); } + uint32_t TextDataLength() const + { + return mText.GetLength(); + } + //---------------------------------------- #ifdef DEBUG diff --git a/editor/libeditor/nsEditor.cpp b/editor/libeditor/nsEditor.cpp index 4bb4ba4a8..dfe99d8ed 100644 --- a/editor/libeditor/nsEditor.cpp +++ b/editor/libeditor/nsEditor.cpp @@ -3473,15 +3473,6 @@ nsEditor::IsEditable(nsINode* aNode) } } -bool -nsEditor::IsMozEditorBogusNode(nsINode* element) -{ - return element && element->IsElement() && - element->AsElement()->AttrValueIs(kNameSpaceID_None, - kMOZEditorBogusNodeAttrAtom, kMOZEditorBogusNodeValue, - eCaseMatters); -} - uint32_t nsEditor::CountEditableChildren(nsINode* aNode) { @@ -3625,12 +3616,6 @@ nsEditor::IsTextNode(nsIDOMNode *aNode) return (nodeType == nsIDOMNode::TEXT_NODE); } -bool -nsEditor::IsTextNode(nsINode *aNode) -{ - return aNode->NodeType() == nsIDOMNode::TEXT_NODE; -} - /////////////////////////////////////////////////////////////////////////// // GetChildAt: returns the node at this position index in the parent // @@ -4844,20 +4829,6 @@ nsEditor::FinalizeSelection() return NS_OK; } -dom::Element * -nsEditor::GetRoot() -{ - if (!mRootElement) - { - nsCOMPtr root; - - // Let GetRootElement() do the work - GetRootElement(getter_AddRefs(root)); - } - - return mRootElement; -} - dom::Element* nsEditor::GetEditorRoot() { diff --git a/editor/libeditor/nsEditor.h b/editor/libeditor/nsEditor.h index feb3ed21a..64e6b1b89 100644 --- a/editor/libeditor/nsEditor.h +++ b/editor/libeditor/nsEditor.h @@ -569,7 +569,13 @@ public: virtual bool IsEditable(nsINode* aNode); /** returns true if aNode is a MozEditorBogus node */ - bool IsMozEditorBogusNode(nsINode* aNode); + bool IsMozEditorBogusNode(nsINode* aNode) + { + return aNode && aNode->IsElement() && + aNode->AsElement()->AttrValueIs(kNameSpaceID_None, + kMOZEditorBogusNodeAttrAtom, kMOZEditorBogusNodeValue, + eCaseMatters); + } /** counts number of editable child nodes */ uint32_t CountEditableChildren(nsINode* aNode); @@ -598,7 +604,10 @@ public: virtual bool AreNodesSameType(nsIContent* aNode1, nsIContent* aNode2); static bool IsTextNode(nsIDOMNode *aNode); - static bool IsTextNode(nsINode *aNode); + static bool IsTextNode(nsINode* aNode) + { + return aNode->NodeType() == nsIDOMNode::TEXT_NODE; + } static nsCOMPtr GetChildAt(nsIDOMNode *aParent, int32_t aOffset); static nsCOMPtr GetNodeAtRangeOffsetPoint(nsIDOMNode* aParentOrNode, int32_t aOffset); @@ -664,7 +673,16 @@ public: virtual already_AddRefed GetDOMEventTarget() = 0; // Fast non-refcounting editor root element accessor - mozilla::dom::Element *GetRoot(); + mozilla::dom::Element *GetRoot() + { + if (!mRootElement) { + // Let GetRootElement() do the work + nsCOMPtr root; + GetRootElement(getter_AddRefs(root)); + } + + return mRootElement; + } // Likewise, but gets the editor's root instead, which is different for HTML // editors diff --git a/editor/libeditor/nsTextEditRules.cpp b/editor/libeditor/nsTextEditRules.cpp index 6d8ab6669..788f1f2a7 100644 --- a/editor/libeditor/nsTextEditRules.cpp +++ b/editor/libeditor/nsTextEditRules.cpp @@ -1176,11 +1176,12 @@ nsTextEditRules::CreateBogusNodeIfNeeded(Selection* aSelection) // Now we've got the body element. Iterate over the body element's children, // looking for editable content. If no editable content is found, insert the // bogus node. - for (nsCOMPtr bodyChild = body->GetFirstChild(); + bool bodyEditable = mEditor->IsEditable(body); + for (nsIContent* bodyChild = body->GetFirstChild(); bodyChild; bodyChild = bodyChild->GetNextSibling()) { if (mEditor->IsMozEditorBogusNode(bodyChild) || - !mEditor->IsEditable(body) || // XXX hoist out of the loop? + !bodyEditable || mEditor->IsEditable(bodyChild) || mEditor->IsBlockNode(bodyChild)) { return NS_OK; }