mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 15:55:36 +00:00
Bug 1460509 - part 26: Make HTMLEditRules::AdjustSelection() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r=m_kato
MozReview-Commit-ID: JCEvhhxNBgg --HG-- extra : rebase_source : 8c6972c8367ce0e44fdc1edcb2b18174e7da2930
This commit is contained in:
parent
4d9d37891e
commit
314c0524b5
@ -8816,14 +8816,14 @@ HTMLEditRules::AdjustSelection(nsIEditor::EDirection aAction)
|
||||
RefPtr<Element> theblock = HTMLEditorRef().GetBlock(*point.GetContainer());
|
||||
|
||||
if (theblock && HTMLEditorRef().IsEditable(theblock)) {
|
||||
bool bIsEmptyNode;
|
||||
bool isEmptyNode;
|
||||
nsresult rv =
|
||||
HTMLEditorRef().IsEmptyNode(theblock, &bIsEmptyNode, false, false);
|
||||
HTMLEditorRef().IsEmptyNode(theblock, &isEmptyNode, false, false);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
// check if br can go into the destination node
|
||||
if (bIsEmptyNode &&
|
||||
if (isEmptyNode &&
|
||||
HTMLEditorRef().CanContainTag(*point.GetContainer(), *nsGkAtoms::br)) {
|
||||
Element* rootElement = HTMLEditorRef().GetRoot();
|
||||
if (NS_WARN_IF(!rootElement)) {
|
||||
@ -8875,10 +8875,18 @@ HTMLEditRules::AdjustSelection(nsIEditor::EDirection aAction)
|
||||
// selection stays *before* moz-br, sticking to it
|
||||
ErrorResult error;
|
||||
SelectionRef().SetInterlinePosition(true, error);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
error.SuppressException();
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
NS_WARNING_ASSERTION(!error.Failed(),
|
||||
"Failed to set interline position");
|
||||
error = NS_OK;
|
||||
SelectionRef().Collapse(point, error);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
error.SuppressException();
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (NS_WARN_IF(error.Failed())) {
|
||||
return error.StealNSResult();
|
||||
}
|
||||
@ -8925,6 +8933,10 @@ HTMLEditRules::AdjustSelection(nsIEditor::EDirection aAction)
|
||||
EditorDOMPoint pt = GetGoodSelPointForNode(*nearNode, aAction);
|
||||
ErrorResult error;
|
||||
SelectionRef().Collapse(pt, error);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
error.SuppressException();
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (NS_WARN_IF(error.Failed())) {
|
||||
return error.StealNSResult();
|
||||
}
|
||||
|
@ -597,7 +597,15 @@ protected:
|
||||
nsresult AdjustWhitespace();
|
||||
nsresult PinSelectionToNewBlock();
|
||||
void CheckInterlinePosition();
|
||||
nsresult AdjustSelection(nsIEditor::EDirection aAction);
|
||||
|
||||
/**
|
||||
* AdjustSelection() may adjust Selection range to nearest editable content.
|
||||
* Despite of the name, this may change the DOM tree. If it needs to create
|
||||
* a <br> to put caret, this tries to create a <br> element.
|
||||
*
|
||||
* @param aAction Maybe used to look for a good point to put caret.
|
||||
*/
|
||||
MOZ_MUST_USE nsresult AdjustSelection(nsIEditor::EDirection aAction);
|
||||
|
||||
/**
|
||||
* FindNearEditableNode() tries to find an editable node near aPoint.
|
||||
|
Loading…
Reference in New Issue
Block a user