Bug 1445569 - part 3: Make TextEditRules::CheckBidiLevelForDeletion() take |const EditorRawDOMPoint&| instead of |nsINode*| and offset in it r?m_kato
There are 2 callers of TextEditRules::CheckBidiLevelForDeletion(). One of them
will start to use EditorRawDOMPoint. Therefore, making it take
|const EditorRawDOMPoint&| instead of |nsINode*| and offset in it keeps the
caller simpler.
MozReview-Commit-ID: DRJXo8gnzba
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -2197,19 +2197,22 @@ HTMLEditRules::WillDeleteSelection(Selec
NS_ENSURE_TRUE(host, NS_ERROR_FAILURE);
rv = CheckForEmptyBlock(startNode, host, aSelection, aAction, aHandled);
NS_ENSURE_SUCCESS(rv, rv);
if (*aHandled) {
return NS_OK;
}
// Test for distance between caret and text that will be deleted
- rv = CheckBidiLevelForDeletion(aSelection, startNode,
- startOffset, aAction, aCancel);
- NS_ENSURE_SUCCESS(rv, rv);
+ rv = CheckBidiLevelForDeletion(aSelection,
+ EditorRawDOMPoint(startNode, startOffset),
+ aAction, aCancel);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
if (*aCancel) {
return NS_OK;
}
NS_ENSURE_STATE(mHTMLEditor);
rv = mHTMLEditor->ExtendSelectionForDelete(aSelection, &aAction);
NS_ENSURE_SUCCESS(rv, rv);
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -1040,19 +1040,22 @@ TextEditRules::WillDeleteSelection(Selec
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
if (!aSelection->IsCollapsed()) {
return NS_OK;
}
// Test for distance between caret and text that will be deleted
- rv = CheckBidiLevelForDeletion(aSelection, startNode, startOffset,
+ rv = CheckBidiLevelForDeletion(aSelection,
+ EditorRawDOMPoint(startNode, startOffset),
aCollapsedAction, aCancel);
- NS_ENSURE_SUCCESS(rv, rv);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
if (*aCancel) {
return NS_OK;
}
NS_ENSURE_STATE(mTextEditor);
rv = mTextEditor->ExtendSelectionForDelete(aSelection, &aCollapsedAction);
NS_ENSURE_SUCCESS(rv, rv);
}
--- a/editor/libeditor/TextEditRules.h
+++ b/editor/libeditor/TextEditRules.h
@@ -257,18 +257,17 @@ protected:
*/
already_AddRefed<Element>
CreateBRInternal(const EditorRawDOMPoint& aPointToInsert,
bool aCreateMozBR);
void UndefineCaretBidiLevel(Selection* aSelection);
nsresult CheckBidiLevelForDeletion(Selection* aSelection,
- nsINode* aSelNode,
- int32_t aSelOffset,
+ const EditorRawDOMPoint& aSelectionPoint,
nsIEditor::EDirection aAction,
bool* aCancel);
nsresult HideLastPWInput();
nsresult CollapseSelectionToTrailingBRIfNeeded(Selection* aSelection);
bool IsPasswordEditor() const;
--- a/editor/libeditor/TextEditRulesBidi.cpp
+++ b/editor/libeditor/TextEditRulesBidi.cpp
@@ -19,48 +19,48 @@
#include "nscore.h"
namespace mozilla {
using namespace dom;
// Test for distance between caret and text that will be deleted
nsresult
-TextEditRules::CheckBidiLevelForDeletion(Selection* aSelection,
- nsINode* aSelNode,
- int32_t aSelOffset,
- nsIEditor::EDirection aAction,
- bool* aCancel)
+TextEditRules::CheckBidiLevelForDeletion(
+ Selection* aSelection,
+ const EditorRawDOMPoint& aSelectionPoint,
+ nsIEditor::EDirection aAction,
+ bool* aCancel)
{
NS_ENSURE_ARG_POINTER(aCancel);
*aCancel = false;
nsCOMPtr<nsIPresShell> shell = mTextEditor->GetPresShell();
NS_ENSURE_TRUE(shell, NS_ERROR_NOT_INITIALIZED);
nsPresContext *context = shell->GetPresContext();
NS_ENSURE_TRUE(context, NS_ERROR_NULL_POINTER);
if (!context->BidiEnabled()) {
return NS_OK;
}
- if (!aSelNode || !aSelNode->IsContent()) {
+ if (!aSelectionPoint.GetContainerAsContent()) {
return NS_ERROR_NULL_POINTER;
}
- nsCOMPtr<nsIContent> content = aSelNode->AsContent();
nsBidiLevel levelBefore;
nsBidiLevel levelAfter;
RefPtr<nsFrameSelection> frameSelection =
aSelection->AsSelection()->GetFrameSelection();
NS_ENSURE_TRUE(frameSelection, NS_ERROR_NULL_POINTER);
nsPrevNextBidiLevels levels = frameSelection->
- GetPrevNextBidiLevels(content, aSelOffset, true);
+ GetPrevNextBidiLevels(aSelectionPoint.GetContainerAsContent(),
+ aSelectionPoint.Offset(), true);
levelBefore = levels.mLevelBefore;
levelAfter = levels.mLevelAfter;
nsBidiLevel currentCaretLevel = frameSelection->GetCaretBidiLevel();
nsBidiLevel levelOfDeletion;
levelOfDeletion =