mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 18:08:58 +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}
|
// MoveNode: move aNode to {aParent,aOffset}
|
||||||
nsresult
|
nsresult
|
||||||
nsEditor::MoveNode(nsIDOMNode* aNode, nsIDOMNode* aParent, int32_t aOffset)
|
nsEditor::MoveNode(nsIContent* aNode, nsINode* 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)
|
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(aNode);
|
MOZ_ASSERT(aNode);
|
||||||
MOZ_ASSERT(aParent);
|
MOZ_ASSERT(aParent);
|
||||||
MOZ_ASSERT(aOffset == -1 ||
|
MOZ_ASSERT(aOffset == -1 ||
|
||||||
(0 <= aOffset && SafeCast<uint32_t>(aOffset) <= aParent->Length()));
|
(0 <= aOffset && SafeCast<uint32_t>(aOffset) <= aParent->Length()));
|
||||||
|
|
||||||
int32_t oldOffset;
|
nsCOMPtr<nsINode> oldParent = aNode->GetParentNode();
|
||||||
nsCOMPtr<nsINode> oldParent = GetNodeLocation(aNode, &oldOffset);
|
int32_t oldOffset = oldParent ? oldParent->IndexOf(aNode) : -1;
|
||||||
|
|
||||||
if (aOffset == -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());
|
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) {
|
if (aParent == oldParent && aOffset == oldOffset) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify our internal selection state listener.
|
// Notify our internal selection state listener
|
||||||
nsAutoMoveNodeSelNotify selNotify(mRangeUpdater, oldParent, oldOffset,
|
nsAutoMoveNodeSelNotify selNotify(mRangeUpdater, oldParent, oldOffset,
|
||||||
aParent, aOffset);
|
aParent, aOffset);
|
||||||
|
|
||||||
// Need to adjust aOffset if we are moving aNode further along in its current
|
// Need to adjust aOffset if we're moving aNode later in its current parent
|
||||||
// parent.
|
|
||||||
if (aParent == oldParent && oldOffset < aOffset) {
|
if (aParent == oldParent && oldOffset < aOffset) {
|
||||||
// This is because when we delete aNode, it will make the offsets after it
|
// When we delete aNode, it will make the offsets after it off by one
|
||||||
// off by one.
|
|
||||||
aOffset--;
|
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;
|
nsCOMPtr<nsINode> kungFuDeathGrip = aNode;
|
||||||
|
|
||||||
nsresult rv = DeleteNode(aNode);
|
nsresult rv = DeleteNode(aNode);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
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,
|
nsIAtom* aAttribute = nullptr,
|
||||||
const nsAString* aValue = nullptr);
|
const nsAString* aValue = nullptr);
|
||||||
nsresult JoinNodes(nsINode* aNodeToKeep, nsIContent* aNodeToMove);
|
nsresult JoinNodes(nsINode* aNodeToKeep, nsIContent* aNodeToMove);
|
||||||
nsresult MoveNode(nsINode* aNode, nsINode* aParent, int32_t aOffset);
|
nsresult MoveNode(nsIContent* aNode, nsINode* aParent, int32_t aOffset);
|
||||||
nsresult MoveNode(nsIDOMNode *aNode, nsIDOMNode *aParent, int32_t aOffset);
|
|
||||||
|
|
||||||
/* Method to replace certain CreateElementNS() calls.
|
/* Method to replace certain CreateElementNS() calls.
|
||||||
Arguments:
|
Arguments:
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -198,7 +198,7 @@ protected:
|
|||||||
nsresult GetFormatString(nsIDOMNode *aNode, nsAString &outFormat);
|
nsresult GetFormatString(nsIDOMNode *aNode, nsAString &outFormat);
|
||||||
nsresult GetInnerContent(nsIDOMNode *aNode, nsCOMArray<nsIDOMNode>& outArrayOfNodes, int32_t *aIndex, bool aList = true, bool aTble = true);
|
nsresult GetInnerContent(nsIDOMNode *aNode, nsCOMArray<nsIDOMNode>& outArrayOfNodes, int32_t *aIndex, bool aList = true, bool aTble = true);
|
||||||
already_AddRefed<nsIDOMNode> IsInListItem(nsIDOMNode* aNode);
|
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 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 ReturnInParagraph(nsISelection *aSelection, nsIDOMNode *aHeader, nsIDOMNode *aTextNode, int32_t aOffset, bool *aCancel, bool *aHandled);
|
||||||
nsresult SplitParagraph(nsIDOMNode *aPara,
|
nsresult SplitParagraph(nsIDOMNode *aPara,
|
||||||
|
@ -426,6 +426,13 @@ nsHTMLEditUtils::IsMozDiv(nsIDOMNode* aNode)
|
|||||||
return false;
|
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(nsINode* aNode);
|
||||||
static bool IsNamedAnchor(nsIDOMNode *aNode);
|
static bool IsNamedAnchor(nsIDOMNode *aNode);
|
||||||
static bool IsDiv(nsIDOMNode *aNode);
|
static bool IsDiv(nsIDOMNode *aNode);
|
||||||
|
static bool IsMozDiv(nsINode* aNode);
|
||||||
static bool IsMozDiv(nsIDOMNode *aNode);
|
static bool IsMozDiv(nsIDOMNode *aNode);
|
||||||
static bool IsMailCite(nsINode* aNode);
|
static bool IsMailCite(nsINode* aNode);
|
||||||
static bool IsMailCite(nsIDOMNode *aNode);
|
static bool IsMailCite(nsIDOMNode *aNode);
|
||||||
|
@ -388,12 +388,12 @@ nsHTMLEditor::SetInlinePropertyOnTextNode( nsIDOMCharacterData *aTextNode,
|
|||||||
nsIContent* sibling = GetPriorHTMLSibling(content);
|
nsIContent* sibling = GetPriorHTMLSibling(content);
|
||||||
if (IsSimpleModifiableNode(sibling, aProperty, aAttribute, aValue)) {
|
if (IsSimpleModifiableNode(sibling, aProperty, aAttribute, aValue)) {
|
||||||
// previous sib is already right kind of inline node; slide this over into it
|
// 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);
|
sibling = GetNextHTMLSibling(content);
|
||||||
if (IsSimpleModifiableNode(sibling, aProperty, aAttribute, aValue)) {
|
if (IsSimpleModifiableNode(sibling, aProperty, aAttribute, aValue)) {
|
||||||
// following sib is already right kind of inline node; slide this over into it
|
// 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) {
|
if (!secondSplitParent) {
|
||||||
secondSplitParent = rightNode;
|
secondSplitParent = rightNode;
|
||||||
}
|
}
|
||||||
nsCOMPtr<nsIDOMNode> savedBR;
|
nsCOMPtr<Element> savedBR;
|
||||||
if (!IsContainer(secondSplitParent)) {
|
if (!IsContainer(secondSplitParent)) {
|
||||||
if (nsTextEditUtils::IsBreak(secondSplitParent)) {
|
if (nsTextEditUtils::IsBreak(secondSplitParent)) {
|
||||||
savedBR = secondSplitParent;
|
savedBR = do_QueryInterface(secondSplitParent);
|
||||||
|
NS_ENSURE_STATE(savedBR);
|
||||||
}
|
}
|
||||||
|
|
||||||
secondSplitParent->GetParentNode(getter_AddRefs(tmp));
|
secondSplitParent->GetParentNode(getter_AddRefs(tmp));
|
||||||
@ -706,9 +707,11 @@ nsHTMLEditor::ClearStyle(nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset,
|
|||||||
NS_ENSURE_SUCCESS(res, res);
|
NS_ENSURE_SUCCESS(res, res);
|
||||||
// should be impossible to not get a new leftnode here
|
// should be impossible to not get a new leftnode here
|
||||||
NS_ENSURE_TRUE(leftNode, NS_ERROR_FAILURE);
|
NS_ENSURE_TRUE(leftNode, NS_ERROR_FAILURE);
|
||||||
nsCOMPtr<nsIDOMNode> newSelParent = GetLeftmostChild(leftNode);
|
nsCOMPtr<nsINode> newSelParent =
|
||||||
|
do_QueryInterface(GetLeftmostChild(leftNode));
|
||||||
if (!newSelParent) {
|
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
|
// 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
|
// 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);
|
NS_ENSURE_SUCCESS(res, res);
|
||||||
}
|
}
|
||||||
// reset our node offset values to the resulting new sel point
|
// reset our node offset values to the resulting new sel point
|
||||||
*aNode = newSelParent;
|
*aNode = GetAsDOMNode(newSelParent);
|
||||||
*aOffset = newSelOffset;
|
*aOffset = newSelOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1651,7 +1654,9 @@ nsHTMLEditor::RelativeFontChangeOnTextNode( int32_t aSizeChange,
|
|||||||
return NS_OK;
|
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?
|
// do we need to split the text node?
|
||||||
uint32_t textLen;
|
uint32_t textLen;
|
||||||
@ -1663,40 +1668,35 @@ nsHTMLEditor::RelativeFontChangeOnTextNode( int32_t aSizeChange,
|
|||||||
if ( (uint32_t)aEndOffset != textLen )
|
if ( (uint32_t)aEndOffset != textLen )
|
||||||
{
|
{
|
||||||
// we need to split off back of text node
|
// 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);
|
NS_ENSURE_SUCCESS(res, res);
|
||||||
node = tmp; // remember left node
|
// remember left node
|
||||||
|
node = do_QueryInterface(tmp);
|
||||||
}
|
}
|
||||||
if ( aStartOffset )
|
if ( aStartOffset )
|
||||||
{
|
{
|
||||||
// we need to split off front of text node
|
// 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);
|
NS_ENSURE_SUCCESS(res, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
// look for siblings that are correct type of node
|
// look for siblings that are correct type of node
|
||||||
nsCOMPtr<nsIDOMNode> sibling;
|
nsIAtom* nodeType = aSizeChange == 1 ? nsGkAtoms::big : nsGkAtoms::small;
|
||||||
GetPriorHTMLSibling(node, address_of(sibling));
|
nsCOMPtr<nsIContent> sibling = GetPriorHTMLSibling(node);
|
||||||
if (sibling && NodeIsType(sibling, (aSizeChange==1) ? nsEditProperty::big : nsEditProperty::small))
|
if (sibling && sibling->Tag() == nodeType) {
|
||||||
{
|
|
||||||
// previous sib is already right kind of inline node; slide this over into it
|
// previous sib is already right kind of inline node; slide this over into it
|
||||||
res = MoveNode(node, sibling, -1);
|
res = MoveNode(node, sibling, -1);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
sibling = nullptr;
|
sibling = GetNextHTMLSibling(node);
|
||||||
GetNextHTMLSibling(node, address_of(sibling));
|
if (sibling && sibling->Tag() == nodeType) {
|
||||||
if (sibling && NodeIsType(sibling, (aSizeChange==1) ? nsEditProperty::big : nsEditProperty::small))
|
|
||||||
{
|
|
||||||
// following sib is already right kind of inline node; slide this over into it
|
// following sib is already right kind of inline node; slide this over into it
|
||||||
res = MoveNode(node, sibling, 0);
|
res = MoveNode(node, sibling, 0);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// else reparent the node inside font node with appropriate relative size
|
// else reparent the node inside font node with appropriate relative size
|
||||||
nsIAtom* nodeType = aSizeChange == 1 ? nsGkAtoms::big : nsGkAtoms::small;
|
nsCOMPtr<Element> newElement = InsertContainerAbove(node, nodeType);
|
||||||
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
|
|
||||||
NS_ENSURE_STATE(content);
|
|
||||||
nsCOMPtr<Element> newElement = InsertContainerAbove(content, nodeType);
|
|
||||||
NS_ENSURE_STATE(newElement);
|
NS_ENSURE_STATE(newElement);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
@ -1782,13 +1782,13 @@ nsHTMLEditor::RelativeFontChangeOnNode(int32_t aSizeChange, nsIContent* aNode)
|
|||||||
nsIContent* sibling = GetPriorHTMLSibling(aNode);
|
nsIContent* sibling = GetPriorHTMLSibling(aNode);
|
||||||
if (sibling && sibling->IsHTML(atom)) {
|
if (sibling && sibling->IsHTML(atom)) {
|
||||||
// previous sib is already right kind of inline node; slide this over into it
|
// 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);
|
sibling = GetNextHTMLSibling(aNode);
|
||||||
if (sibling && sibling->IsHTML(atom)) {
|
if (sibling && sibling->IsHTML(atom)) {
|
||||||
// following sib is already right kind of inline node; slide this over into it
|
// 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
|
// else insert it above aNode
|
||||||
|
Loading…
Reference in New Issue
Block a user