Skip to content

Commit

Permalink
Bug 1054735 part 1 - Clean up nsAutoReplaceContainerSelNotify; r=ehsan
Browse files Browse the repository at this point in the history
  • Loading branch information
ayg committed Aug 20, 2014
1 parent 4431461 commit 9dcb3c4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
4 changes: 2 additions & 2 deletions editor/libeditor/nsEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1555,8 +1555,8 @@ nsEditor::ReplaceContainer(Element* aOldContainer,
// notify our internal selection state listener
// (Note: A nsAutoSelectionReset object must be created
// before calling this to initialize mRangeUpdater)
nsAutoReplaceContainerSelNotify selStateNotify(mRangeUpdater,
aOldContainer->AsDOMNode(), ret->AsDOMNode());
AutoReplaceContainerSelNotify selStateNotify(mRangeUpdater, aOldContainer,
ret);
{
nsAutoTxnsConserveSelection conserveSelection(this);
while (aOldContainer->HasChildren()) {
Expand Down
11 changes: 1 addition & 10 deletions editor/libeditor/nsSelectionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ nsRangeUpdater::WillReplaceContainer()


nsresult
nsRangeUpdater::DidReplaceContainer(nsINode* aOriginalNode, nsINode* aNewNode)
nsRangeUpdater::DidReplaceContainer(Element* aOriginalNode, Element* aNewNode)
{
NS_ENSURE_TRUE(mLock, NS_ERROR_UNEXPECTED);
mLock = false;
Expand All @@ -564,15 +564,6 @@ nsRangeUpdater::DidReplaceContainer(nsINode* aOriginalNode, nsINode* aNewNode)
return NS_OK;
}

nsresult
nsRangeUpdater::DidReplaceContainer(nsIDOMNode* aOriginalNode,
nsIDOMNode* aNewNode)
{
nsCOMPtr<nsINode> originalNode = do_QueryInterface(aOriginalNode);
nsCOMPtr<nsINode> newNode = do_QueryInterface(aNewNode);
return DidReplaceContainer(originalNode, newNode);
}


nsresult
nsRangeUpdater::WillRemoveContainer()
Expand Down
32 changes: 19 additions & 13 deletions editor/libeditor/nsSelectionState.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ class nsRangeUpdater
// the following gravity routines need will/did sandwiches, because the other gravity
// routines will be called inside of these sandwiches, but should be ignored.
nsresult WillReplaceContainer();
nsresult DidReplaceContainer(nsINode* aOriginalNode, nsINode* aNewNode);
nsresult DidReplaceContainer(nsIDOMNode *aOriginalNode, nsIDOMNode *aNewNode);
nsresult DidReplaceContainer(mozilla::dom::Element* aOriginalNode,
mozilla::dom::Element* aNewNode);
nsresult WillRemoveContainer();
nsresult DidRemoveContainer(nsINode* aNode, nsINode* aParent,
int32_t aOffset, uint32_t aNodeOrigLen);
Expand Down Expand Up @@ -193,32 +193,38 @@ class MOZ_STACK_CLASS nsAutoTrackDOMPoint



/***************************************************************************
/******************************************************************************
* another helper class for nsSelectionState. stack based class for doing
* Will/DidReplaceContainer()
*/

class MOZ_STACK_CLASS nsAutoReplaceContainerSelNotify
namespace mozilla {
namespace dom {
class MOZ_STACK_CLASS AutoReplaceContainerSelNotify
{
private:
nsRangeUpdater &mRU;
nsIDOMNode *mOriginalNode;
nsIDOMNode *mNewNode;
Element* mOriginalElement;
Element* mNewElement;

public:
nsAutoReplaceContainerSelNotify(nsRangeUpdater &aRangeUpdater, nsIDOMNode *aOriginalNode, nsIDOMNode *aNewNode) :
mRU(aRangeUpdater)
,mOriginalNode(aOriginalNode)
,mNewNode(aNewNode)
AutoReplaceContainerSelNotify(nsRangeUpdater& aRangeUpdater,
Element* aOriginalElement,
Element* aNewElement)
: mRU(aRangeUpdater)
, mOriginalElement(aOriginalElement)
, mNewElement(aNewElement)
{
mRU.WillReplaceContainer();
}
~nsAutoReplaceContainerSelNotify()

~AutoReplaceContainerSelNotify()
{
mRU.DidReplaceContainer(mOriginalNode, mNewNode);
mRU.DidReplaceContainer(mOriginalElement, mNewElement);
}
};
}
}


/***************************************************************************
Expand Down

0 comments on commit 9dcb3c4

Please sign in to comment.