mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 16:22:00 +00:00
Bug 1055032 part 1 - Clean up nsEditor::MoveNode; r=ehsan
This commit is contained in:
parent
b51de04d4d
commit
630695995b
@ -1667,57 +1667,43 @@ nsEditor::InsertContainerAbove(nsIContent* aNode,
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// MoveNode: move aNode to {aParent,aOffset}
|
||||
nsresult
|
||||
nsEditor::MoveNode(nsIDOMNode* aNode, nsIDOMNode* aParent, int32_t aOffset)
|
||||
{
|
||||
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
||||
NS_ENSURE_STATE(node);
|
||||
|
||||
nsCOMPtr<nsINode> parent = do_QueryInterface(aParent);
|
||||
NS_ENSURE_STATE(parent);
|
||||
|
||||
return MoveNode(node, parent, aOffset);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsEditor::MoveNode(nsINode* aNode, nsINode* aParent, int32_t aOffset)
|
||||
nsEditor::MoveNode(nsIContent* aNode, nsINode* aParent, int32_t aOffset)
|
||||
{
|
||||
MOZ_ASSERT(aNode);
|
||||
MOZ_ASSERT(aParent);
|
||||
MOZ_ASSERT(aOffset == -1 ||
|
||||
(0 <= aOffset && SafeCast<uint32_t>(aOffset) <= aParent->Length()));
|
||||
|
||||
int32_t oldOffset;
|
||||
nsCOMPtr<nsINode> oldParent = GetNodeLocation(aNode, &oldOffset);
|
||||
nsCOMPtr<nsINode> oldParent = aNode->GetParentNode();
|
||||
int32_t oldOffset = oldParent ? oldParent->IndexOf(aNode) : -1;
|
||||
|
||||
if (aOffset == -1) {
|
||||
// Magic value meaning "move to end of aParent".
|
||||
// Magic value meaning "move to end of aParent"
|
||||
aOffset = SafeCast<int32_t>(aParent->Length());
|
||||
}
|
||||
|
||||
// Don't do anything if it's already in right place.
|
||||
// Don't do anything if it's already in right place
|
||||
if (aParent == oldParent && aOffset == oldOffset) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Notify our internal selection state listener.
|
||||
// Notify our internal selection state listener
|
||||
nsAutoMoveNodeSelNotify selNotify(mRangeUpdater, oldParent, oldOffset,
|
||||
aParent, aOffset);
|
||||
|
||||
// Need to adjust aOffset if we are moving aNode further along in its current
|
||||
// parent.
|
||||
// Need to adjust aOffset if we're moving aNode later in its current parent
|
||||
if (aParent == oldParent && oldOffset < aOffset) {
|
||||
// This is because when we delete aNode, it will make the offsets after it
|
||||
// off by one.
|
||||
// When we delete aNode, it will make the offsets after it off by one
|
||||
aOffset--;
|
||||
}
|
||||
|
||||
// Hold a reference so aNode doesn't go away when we remove it (bug 772282).
|
||||
// Hold a reference so aNode doesn't go away when we remove it (bug 772282)
|
||||
nsCOMPtr<nsINode> kungFuDeathGrip = aNode;
|
||||
|
||||
nsresult rv = DeleteNode(aNode);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return InsertNode(aNode->AsDOMNode(), aParent->AsDOMNode(), aOffset);
|
||||
return InsertNode(aNode, aParent, aOffset);
|
||||
}
|
||||
|
||||
|
||||
|
@ -241,8 +241,7 @@ public:
|
||||
nsIAtom* aAttribute = nullptr,
|
||||
const nsAString* aValue = nullptr);
|
||||
nsresult JoinNodes(nsINode* aNodeToKeep, nsIContent* aNodeToMove);
|
||||
nsresult MoveNode(nsINode* aNode, nsINode* aParent, int32_t aOffset);
|
||||
nsresult MoveNode(nsIDOMNode *aNode, nsIDOMNode *aParent, int32_t aOffset);
|
||||
nsresult MoveNode(nsIContent* aNode, nsINode* aParent, int32_t aOffset);
|
||||
|
||||
/* Method to replace certain CreateElementNS() calls.
|
||||
Arguments:
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -198,7 +198,7 @@ protected:
|
||||
nsresult GetFormatString(nsIDOMNode *aNode, nsAString &outFormat);
|
||||
nsresult GetInnerContent(nsIDOMNode *aNode, nsCOMArray<nsIDOMNode>& outArrayOfNodes, int32_t *aIndex, bool aList = true, bool aTble = true);
|
||||
already_AddRefed<nsIDOMNode> IsInListItem(nsIDOMNode* aNode);
|
||||
nsINode* IsInListItem(nsINode* aNode);
|
||||
mozilla::dom::Element* IsInListItem(nsINode* aNode);
|
||||
nsresult ReturnInHeader(nsISelection *aSelection, nsIDOMNode *aHeader, nsIDOMNode *aTextNode, int32_t aOffset);
|
||||
nsresult ReturnInParagraph(nsISelection *aSelection, nsIDOMNode *aHeader, nsIDOMNode *aTextNode, int32_t aOffset, bool *aCancel, bool *aHandled);
|
||||
nsresult SplitParagraph(nsIDOMNode *aPara,
|
||||
|
@ -426,6 +426,13 @@ nsHTMLEditUtils::IsMozDiv(nsIDOMNode* aNode)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
nsHTMLEditUtils::IsMozDiv(nsINode* aNode)
|
||||
{
|
||||
MOZ_ASSERT(aNode);
|
||||
return aNode->Tag() == nsGkAtoms::div &&
|
||||
nsTextEditUtils::HasMozAttr(GetAsDOMNode(aNode));
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
@ -51,6 +51,7 @@ public:
|
||||
static bool IsNamedAnchor(nsINode* aNode);
|
||||
static bool IsNamedAnchor(nsIDOMNode *aNode);
|
||||
static bool IsDiv(nsIDOMNode *aNode);
|
||||
static bool IsMozDiv(nsINode* aNode);
|
||||
static bool IsMozDiv(nsIDOMNode *aNode);
|
||||
static bool IsMailCite(nsINode* aNode);
|
||||
static bool IsMailCite(nsIDOMNode *aNode);
|
||||
|
@ -388,12 +388,12 @@ nsHTMLEditor::SetInlinePropertyOnTextNode( nsIDOMCharacterData *aTextNode,
|
||||
nsIContent* sibling = GetPriorHTMLSibling(content);
|
||||
if (IsSimpleModifiableNode(sibling, aProperty, aAttribute, aValue)) {
|
||||
// previous sib is already right kind of inline node; slide this over into it
|
||||
return MoveNode(node, sibling->AsDOMNode(), -1);
|
||||
return MoveNode(content, sibling, -1);
|
||||
}
|
||||
sibling = GetNextHTMLSibling(content);
|
||||
if (IsSimpleModifiableNode(sibling, aProperty, aAttribute, aValue)) {
|
||||
// following sib is already right kind of inline node; slide this over into it
|
||||
return MoveNode(node, sibling->AsDOMNode(), 0);
|
||||
return MoveNode(content, sibling, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -690,10 +690,11 @@ nsHTMLEditor::ClearStyle(nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset,
|
||||
if (!secondSplitParent) {
|
||||
secondSplitParent = rightNode;
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> savedBR;
|
||||
nsCOMPtr<Element> savedBR;
|
||||
if (!IsContainer(secondSplitParent)) {
|
||||
if (nsTextEditUtils::IsBreak(secondSplitParent)) {
|
||||
savedBR = secondSplitParent;
|
||||
savedBR = do_QueryInterface(secondSplitParent);
|
||||
NS_ENSURE_STATE(savedBR);
|
||||
}
|
||||
|
||||
secondSplitParent->GetParentNode(getter_AddRefs(tmp));
|
||||
@ -706,9 +707,11 @@ nsHTMLEditor::ClearStyle(nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset,
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
// should be impossible to not get a new leftnode here
|
||||
NS_ENSURE_TRUE(leftNode, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsIDOMNode> newSelParent = GetLeftmostChild(leftNode);
|
||||
nsCOMPtr<nsINode> newSelParent =
|
||||
do_QueryInterface(GetLeftmostChild(leftNode));
|
||||
if (!newSelParent) {
|
||||
newSelParent = leftNode;
|
||||
newSelParent = do_QueryInterface(leftNode);
|
||||
NS_ENSURE_STATE(newSelParent);
|
||||
}
|
||||
// If rightNode starts with a br, suck it out of right node and into
|
||||
// leftNode. This is so we you don't revert back to the previous style
|
||||
@ -738,7 +741,7 @@ nsHTMLEditor::ClearStyle(nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset,
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
}
|
||||
// reset our node offset values to the resulting new sel point
|
||||
*aNode = newSelParent;
|
||||
*aNode = GetAsDOMNode(newSelParent);
|
||||
*aOffset = newSelOffset;
|
||||
}
|
||||
|
||||
@ -1651,7 +1654,9 @@ nsHTMLEditor::RelativeFontChangeOnTextNode( int32_t aSizeChange,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> tmp, node = do_QueryInterface(aTextNode);
|
||||
nsCOMPtr<nsIDOMNode> tmp;
|
||||
nsCOMPtr<nsIContent> node = do_QueryInterface(aTextNode);
|
||||
NS_ENSURE_STATE(node);
|
||||
|
||||
// do we need to split the text node?
|
||||
uint32_t textLen;
|
||||
@ -1663,40 +1668,35 @@ nsHTMLEditor::RelativeFontChangeOnTextNode( int32_t aSizeChange,
|
||||
if ( (uint32_t)aEndOffset != textLen )
|
||||
{
|
||||
// we need to split off back of text node
|
||||
res = SplitNode(node, aEndOffset, getter_AddRefs(tmp));
|
||||
res = SplitNode(GetAsDOMNode(node), aEndOffset, getter_AddRefs(tmp));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
node = tmp; // remember left node
|
||||
// remember left node
|
||||
node = do_QueryInterface(tmp);
|
||||
}
|
||||
if ( aStartOffset )
|
||||
{
|
||||
// we need to split off front of text node
|
||||
res = SplitNode(node, aStartOffset, getter_AddRefs(tmp));
|
||||
res = SplitNode(GetAsDOMNode(node), aStartOffset, getter_AddRefs(tmp));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
}
|
||||
|
||||
// look for siblings that are correct type of node
|
||||
nsCOMPtr<nsIDOMNode> sibling;
|
||||
GetPriorHTMLSibling(node, address_of(sibling));
|
||||
if (sibling && NodeIsType(sibling, (aSizeChange==1) ? nsEditProperty::big : nsEditProperty::small))
|
||||
{
|
||||
nsIAtom* nodeType = aSizeChange == 1 ? nsGkAtoms::big : nsGkAtoms::small;
|
||||
nsCOMPtr<nsIContent> sibling = GetPriorHTMLSibling(node);
|
||||
if (sibling && sibling->Tag() == nodeType) {
|
||||
// previous sib is already right kind of inline node; slide this over into it
|
||||
res = MoveNode(node, sibling, -1);
|
||||
return res;
|
||||
}
|
||||
sibling = nullptr;
|
||||
GetNextHTMLSibling(node, address_of(sibling));
|
||||
if (sibling && NodeIsType(sibling, (aSizeChange==1) ? nsEditProperty::big : nsEditProperty::small))
|
||||
{
|
||||
sibling = GetNextHTMLSibling(node);
|
||||
if (sibling && sibling->Tag() == nodeType) {
|
||||
// following sib is already right kind of inline node; slide this over into it
|
||||
res = MoveNode(node, sibling, 0);
|
||||
return res;
|
||||
}
|
||||
|
||||
// else reparent the node inside font node with appropriate relative size
|
||||
nsIAtom* nodeType = aSizeChange == 1 ? nsGkAtoms::big : nsGkAtoms::small;
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
|
||||
NS_ENSURE_STATE(content);
|
||||
nsCOMPtr<Element> newElement = InsertContainerAbove(content, nodeType);
|
||||
nsCOMPtr<Element> newElement = InsertContainerAbove(node, nodeType);
|
||||
NS_ENSURE_STATE(newElement);
|
||||
|
||||
return NS_OK;
|
||||
@ -1782,13 +1782,13 @@ nsHTMLEditor::RelativeFontChangeOnNode(int32_t aSizeChange, nsIContent* aNode)
|
||||
nsIContent* sibling = GetPriorHTMLSibling(aNode);
|
||||
if (sibling && sibling->IsHTML(atom)) {
|
||||
// previous sib is already right kind of inline node; slide this over into it
|
||||
return MoveNode(aNode->AsDOMNode(), sibling->AsDOMNode(), -1);
|
||||
return MoveNode(aNode, sibling, -1);
|
||||
}
|
||||
|
||||
sibling = GetNextHTMLSibling(aNode);
|
||||
if (sibling && sibling->IsHTML(atom)) {
|
||||
// following sib is already right kind of inline node; slide this over into it
|
||||
return MoveNode(aNode->AsDOMNode(), sibling->AsDOMNode(), 0);
|
||||
return MoveNode(aNode, sibling, 0);
|
||||
}
|
||||
|
||||
// else insert it above aNode
|
||||
|
Loading…
Reference in New Issue
Block a user