mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 23:02:20 +00:00
Bug 1432186 part 14. Remove nsIDOMNode's childNodes attribute. r=mccr8
MozReview-Commit-ID: JyQjEYngKAT
This commit is contained in:
parent
323cec654b
commit
87cd3b385a
@ -1184,6 +1184,7 @@ protected:
|
||||
nsCOMPtr<nsIDOMNode> *outNode, int32_t *outOffset, nsIDOMNode *aCommon);
|
||||
nsCOMPtr<nsIDOMNode> GetChildAt(nsIDOMNode *aParent, int32_t aOffset);
|
||||
bool IsMozBR(nsIDOMNode* aNode);
|
||||
bool IsMozBR(Element* aNode);
|
||||
nsresult GetNodeLocation(nsIDOMNode *inChild, nsCOMPtr<nsIDOMNode> *outParent, int32_t *outOffset);
|
||||
bool IsRoot(nsIDOMNode* aNode);
|
||||
bool IsFirstNode(nsIDOMNode *aNode);
|
||||
@ -1773,10 +1774,15 @@ nsHTMLCopyEncoder::IsMozBR(nsIDOMNode* aNode)
|
||||
{
|
||||
MOZ_ASSERT(aNode);
|
||||
nsCOMPtr<Element> element = do_QueryInterface(aNode);
|
||||
return element &&
|
||||
element->IsHTMLElement(nsGkAtoms::br) &&
|
||||
element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
||||
NS_LITERAL_STRING("_moz"), eIgnoreCase);
|
||||
return element && IsMozBR(element);
|
||||
}
|
||||
|
||||
bool
|
||||
nsHTMLCopyEncoder::IsMozBR(Element* aElement)
|
||||
{
|
||||
return aElement->IsHTMLElement(nsGkAtoms::br) &&
|
||||
aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
||||
NS_LITERAL_STRING("_moz"), eIgnoreCase);
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -1822,86 +1828,44 @@ nsHTMLCopyEncoder::IsRoot(nsIDOMNode* aNode)
|
||||
bool
|
||||
nsHTMLCopyEncoder::IsFirstNode(nsIDOMNode *aNode)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
int32_t offset, j=0;
|
||||
nsresult rv = GetNodeLocation(aNode, address_of(parent), &offset);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
NS_NOTREACHED("failure in IsFirstNode");
|
||||
return false;
|
||||
}
|
||||
if (offset == 0) // easy case, we are first dom child
|
||||
return true;
|
||||
if (!parent)
|
||||
return true;
|
||||
|
||||
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
||||
// need to check if any nodes before us are really visible.
|
||||
// Mike wrote something for me along these lines in nsSelectionController,
|
||||
// but I don't think it's ready for use yet - revisit.
|
||||
// HACK: for now, simply consider all whitespace text nodes to be
|
||||
// invisible formatting nodes.
|
||||
nsCOMPtr<nsIDOMNodeList> childList;
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
|
||||
rv = parent->GetChildNodes(getter_AddRefs(childList));
|
||||
if (NS_FAILED(rv) || !childList)
|
||||
{
|
||||
NS_NOTREACHED("failure in IsFirstNode");
|
||||
return true;
|
||||
}
|
||||
while (j < offset)
|
||||
{
|
||||
childList->Item(j, getter_AddRefs(child));
|
||||
if (!IsEmptyTextContent(child))
|
||||
for (nsIContent* sibling = node->GetPreviousSibling();
|
||||
sibling;
|
||||
sibling = sibling->GetPreviousSibling()) {
|
||||
if (!sibling->TextIsOnlyWhitespace()) {
|
||||
return false;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
nsHTMLCopyEncoder::IsLastNode(nsIDOMNode *aNode)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
int32_t offset,j;
|
||||
nsresult rv = GetNodeLocation(aNode, address_of(parent), &offset);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
NS_NOTREACHED("failure in IsLastNode");
|
||||
return false;
|
||||
}
|
||||
nsCOMPtr<nsINode> parentNode = do_QueryInterface(parent);
|
||||
if (!parentNode) {
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t numChildren = parentNode->Length();
|
||||
if (offset+1 == (int32_t)numChildren) // easy case, we are last dom child
|
||||
return true;
|
||||
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
||||
// need to check if any nodes after us are really visible.
|
||||
// Mike wrote something for me along these lines in nsSelectionController,
|
||||
// but I don't think it's ready for use yet - revisit.
|
||||
// HACK: for now, simply consider all whitespace text nodes to be
|
||||
// invisible formatting nodes.
|
||||
j = (int32_t)numChildren-1;
|
||||
nsCOMPtr<nsIDOMNodeList>childList;
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
rv = parent->GetChildNodes(getter_AddRefs(childList));
|
||||
if (NS_FAILED(rv) || !childList)
|
||||
{
|
||||
NS_NOTREACHED("failure in IsLastNode");
|
||||
return true;
|
||||
}
|
||||
while (j > offset)
|
||||
{
|
||||
childList->Item(j, getter_AddRefs(child));
|
||||
j--;
|
||||
if (IsMozBR(child)) // we ignore trailing moz BRs.
|
||||
for (nsIContent* sibling = node->GetNextSibling();
|
||||
sibling;
|
||||
sibling = sibling->GetNextSibling()) {
|
||||
if (sibling->IsElement() && IsMozBR(sibling->AsElement())) {
|
||||
// we ignore trailing moz BRs.
|
||||
continue;
|
||||
if (!IsEmptyTextContent(child))
|
||||
}
|
||||
if (!sibling->TextIsOnlyWhitespace()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -524,14 +524,6 @@ nsINode::GetParentNode(nsIDOMNode** aParentNode)
|
||||
return parent ? CallQueryInterface(parent, aParentNode) : NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsINode::GetChildNodes(nsIDOMNodeList** aChildNodes)
|
||||
{
|
||||
NS_ADDREF(*aChildNodes = ChildNodes());
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsINode::GetOwnerDocument(nsIDOMDocument** aOwnerDocument)
|
||||
{
|
||||
|
@ -2077,7 +2077,6 @@ protected:
|
||||
// These are just used to implement nsIDOMNode using
|
||||
// NS_FORWARD_NSIDOMNODE_TO_NSINODE_HELPER and for quickstubs.
|
||||
nsresult GetParentNode(nsIDOMNode** aParentNode);
|
||||
nsresult GetChildNodes(nsIDOMNodeList** aChildNodes);
|
||||
nsresult GetOwnerDocument(nsIDOMDocument** aOwnerDocument);
|
||||
|
||||
void EnsurePreInsertionValidity1(nsINode& aNewChild, nsINode* aRefChild,
|
||||
@ -2269,10 +2268,6 @@ ToCanonicalSupports(nsINode* aPointer)
|
||||
{ \
|
||||
return nsINode::GetParentNode(aParentNode); \
|
||||
} \
|
||||
NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes) __VA_ARGS__ override \
|
||||
{ \
|
||||
return nsINode::GetChildNodes(aChildNodes); \
|
||||
} \
|
||||
NS_IMETHOD GetOwnerDocument(nsIDOMDocument** aOwnerDocument) __VA_ARGS__ override \
|
||||
{ \
|
||||
return nsINode::GetOwnerDocument(aOwnerDocument); \
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsError.h"
|
||||
#include "nsIContentIterator.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsINodeList.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsGenericDOMDataNode.h"
|
||||
@ -2919,7 +2919,7 @@ nsRange::InsertNode(nsINode& aNode, ErrorResult& aRv)
|
||||
nsCOMPtr<nsINode> referenceParentNode = tStartContainer;
|
||||
|
||||
nsCOMPtr<nsIDOMText> startTextNode(do_QueryInterface(tStartContainer));
|
||||
nsCOMPtr<nsIDOMNodeList> tChildList;
|
||||
nsCOMPtr<nsINodeList> tChildList;
|
||||
if (startTextNode) {
|
||||
referenceParentNode = tStartContainer->GetParentNode();
|
||||
if (!referenceParentNode) {
|
||||
@ -2941,18 +2941,10 @@ nsRange::InsertNode(nsINode& aNode, ErrorResult& aRv)
|
||||
|
||||
referenceNode = do_QueryInterface(secondPart);
|
||||
} else {
|
||||
aRv = tStartContainer->AsDOMNode()->GetChildNodes(getter_AddRefs(tChildList));
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
tChildList = tStartContainer->ChildNodes();
|
||||
|
||||
// find the insertion point in the DOM and insert the Node
|
||||
nsCOMPtr<nsIDOMNode> q;
|
||||
aRv = tChildList->Item(tStartOffset, getter_AddRefs(q));
|
||||
referenceNode = do_QueryInterface(q);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
referenceNode = tChildList->Item(tStartOffset);
|
||||
|
||||
tStartContainer->EnsurePreInsertionValidity(aNode, referenceNode, aRv);
|
||||
if (aRv.Failed()) {
|
||||
@ -2973,10 +2965,7 @@ nsRange::InsertNode(nsINode& aNode, ErrorResult& aRv)
|
||||
}
|
||||
newOffset = static_cast<uint32_t>(indexInParent);
|
||||
} else {
|
||||
aRv = tChildList->GetLength(&newOffset);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
newOffset = tChildList->Length();
|
||||
}
|
||||
|
||||
if (aNode.NodeType() == nsIDOMNode::DOCUMENT_FRAGMENT_NODE) {
|
||||
|
@ -33,7 +33,6 @@ interface nsIDOMNode : nsISupports
|
||||
const unsigned short NOTATION_NODE = 12;
|
||||
|
||||
readonly attribute nsIDOMNode parentNode;
|
||||
readonly attribute nsIDOMNodeList childNodes;
|
||||
// Modified in DOM Level 2:
|
||||
readonly attribute nsIDOMDocument ownerDocument;
|
||||
boolean hasChildNodes();
|
||||
|
@ -1102,15 +1102,14 @@ mozInlineSpellChecker::MakeSpellCheckRange(
|
||||
}
|
||||
|
||||
if (aEndOffset == -1) {
|
||||
nsCOMPtr<nsIDOMNodeList> childNodes;
|
||||
rv = aEndNode->GetChildNodes(getter_AddRefs(childNodes));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
uint32_t childCount;
|
||||
rv = childNodes->GetLength(&childCount);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
aEndOffset = childCount;
|
||||
// It's hard to say whether it's better to just do nsINode::GetChildCount or
|
||||
// get the ChildNodes() and then its length. The latter is faster if we
|
||||
// keep going through this code for the same nodes (because it caches the
|
||||
// length). The former is faster if we keep getting different nodes here...
|
||||
//
|
||||
// Let's do the thing which can't end up with bad O(N^2) behavior.
|
||||
nsCOMPtr<nsINode> endNode = do_QueryInterface(aEndNode);
|
||||
aEndOffset = endNode->ChildNodes()->Length();
|
||||
}
|
||||
|
||||
// sometimes we are are requested to check an empty range (possibly an empty
|
||||
|
@ -848,9 +848,9 @@ nsTextControlFrame::GetTextEditor()
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextControlFrame::SetSelectionInternal(nsIDOMNode *aStartNode,
|
||||
nsTextControlFrame::SetSelectionInternal(nsINode* aStartNode,
|
||||
uint32_t aStartOffset,
|
||||
nsIDOMNode *aEndNode,
|
||||
nsINode* aEndNode,
|
||||
uint32_t aEndOffset,
|
||||
nsITextControlFrame::SelectionDirection aDirection)
|
||||
{
|
||||
@ -861,14 +861,13 @@ nsTextControlFrame::SetSelectionInternal(nsIDOMNode *aStartNode,
|
||||
RefPtr<nsRange> range = new nsRange(mContent);
|
||||
// Be careful to use internal nsRange methods which do not check to make sure
|
||||
// we have access to the node.
|
||||
nsCOMPtr<nsINode> start = do_QueryInterface(aStartNode);
|
||||
nsCOMPtr<nsINode> end = do_QueryInterface(aEndNode);
|
||||
// XXXbz nsRange::SetStartAndEnd takes int32_t (and ranges generally work on
|
||||
// int32_t), but we're passing uint32_t. The good news is that at this point
|
||||
// our endpoints should really be within our length, so not really that big.
|
||||
// And if they _are_ that big, SetStartAndEnd() will simply error out, which
|
||||
// is not too bad for a case we don't expect to happen.
|
||||
nsresult rv = range->SetStartAndEnd(start, aStartOffset, end, aEndOffset);
|
||||
nsresult rv = range->SetStartAndEnd(aStartNode, aStartOffset,
|
||||
aEndNode, aEndOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Get the selection, clear it and add the new range to it!
|
||||
@ -938,7 +937,8 @@ nsTextControlFrame::SelectAllOrCollapseToEndOfText(bool aSelect)
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIContent> rootContent = do_QueryInterface(rootElement);
|
||||
nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootElement));
|
||||
nsCOMPtr<nsINode> rootNode;
|
||||
rootNode = rootContent;
|
||||
|
||||
NS_ENSURE_TRUE(rootNode && rootContent, NS_ERROR_FAILURE);
|
||||
|
||||
@ -960,7 +960,7 @@ nsTextControlFrame::SelectAllOrCollapseToEndOfText(bool aSelect)
|
||||
if (!aSelect && numChildren) {
|
||||
child = child->GetPreviousSibling();
|
||||
if (child && child->IsNodeOfType(nsINode::eTEXT)) {
|
||||
rootNode = do_QueryInterface(child);
|
||||
rootNode = child;
|
||||
const nsTextFragment* fragment = child->GetText();
|
||||
numChildren = fragment ? fragment->GetLength() : 0;
|
||||
}
|
||||
@ -983,7 +983,7 @@ nsTextControlFrame::SetSelectionEndPoints(uint32_t aSelStart, uint32_t aSelEnd,
|
||||
if (aSelStart > aSelEnd)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> startNode, endNode;
|
||||
nsCOMPtr<nsINode> startNode, endNode;
|
||||
uint32_t startOffset, endOffset;
|
||||
|
||||
// Calculate the selection start point.
|
||||
@ -1029,7 +1029,7 @@ nsTextControlFrame::SetSelectionRange(uint32_t aSelStart, uint32_t aSelEnd,
|
||||
|
||||
nsresult
|
||||
nsTextControlFrame::OffsetToDOMPoint(uint32_t aOffset,
|
||||
nsIDOMNode** aResult,
|
||||
nsINode** aResult,
|
||||
uint32_t* aPosition)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResult && aPosition);
|
||||
@ -1040,26 +1040,16 @@ nsTextControlFrame::OffsetToDOMPoint(uint32_t aOffset,
|
||||
nsCOMPtr<nsIDOMElement> rootElement;
|
||||
nsresult rv = GetRootNodeAndInitializeEditor(getter_AddRefs(rootElement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootElement));
|
||||
nsCOMPtr<nsINode> rootNode(do_QueryInterface(rootElement));
|
||||
|
||||
NS_ENSURE_TRUE(rootNode, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDOMNodeList> nodeList;
|
||||
|
||||
rv = rootNode->GetChildNodes(getter_AddRefs(nodeList));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(nodeList, NS_ERROR_FAILURE);
|
||||
|
||||
uint32_t length = 0;
|
||||
|
||||
rv = nodeList->GetLength(&length);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsINodeList> nodeList = rootNode->ChildNodes();
|
||||
uint32_t length = nodeList->Length();
|
||||
|
||||
NS_ASSERTION(length <= 2, "We should have one text node and one mozBR at most");
|
||||
|
||||
nsCOMPtr<nsIDOMNode> firstNode;
|
||||
rv = nodeList->Item(0, getter_AddRefs(firstNode));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsINode> firstNode = nodeList->Item(0);
|
||||
nsCOMPtr<nsIDOMText> textNode = do_QueryInterface(firstNode);
|
||||
|
||||
if (length == 0) {
|
||||
|
@ -276,7 +276,8 @@ protected:
|
||||
nsTextControlFrame* mFrame;
|
||||
};
|
||||
|
||||
nsresult OffsetToDOMPoint(uint32_t aOffset, nsIDOMNode** aResult, uint32_t* aPosition);
|
||||
nsresult OffsetToDOMPoint(uint32_t aOffset, nsINode** aResult,
|
||||
uint32_t* aPosition);
|
||||
|
||||
/**
|
||||
* Update the textnode under our anonymous div to show the new
|
||||
@ -319,8 +320,8 @@ protected:
|
||||
|
||||
private:
|
||||
//helper methods
|
||||
nsresult SetSelectionInternal(nsIDOMNode *aStartNode, uint32_t aStartOffset,
|
||||
nsIDOMNode *aEndNode, uint32_t aEndOffset,
|
||||
nsresult SetSelectionInternal(nsINode* aStartNode, uint32_t aStartOffset,
|
||||
nsINode* aEndNode, uint32_t aEndOffset,
|
||||
SelectionDirection aDirection = eNone);
|
||||
nsresult SelectAllOrCollapseToEndOfText(bool aSelect);
|
||||
nsresult SetSelectionEndPoints(uint32_t aSelStart, uint32_t aSelEnd,
|
||||
|
Loading…
Reference in New Issue
Block a user