Bug 1467799 - part 2: Stop using nsIEditor::GetDocumentIsEmpty() from C++ code r?m_kato
nsIEditor::GetDocumentIsEmpty() is a virtual code and there is non-virtual
method, TextEditor::IsEmpty(). So, any callers in C++ should use
TextEditor::IsEmpty() instead.
MozReview-Commit-ID: CQE8LP6XI96
--- a/accessible/generic/HyperTextAccessible.cpp
+++ b/accessible/generic/HyperTextAccessible.cpp
@@ -381,19 +381,17 @@ HyperTextAccessible::OffsetsToDOMRange(i
DOMPoint
HyperTextAccessible::OffsetToDOMPoint(int32_t aOffset)
{
// 0 offset is valid even if no children. In this case the associated editor
// is empty so return a DOM point for editor root element.
if (aOffset == 0) {
RefPtr<TextEditor> textEditor = GetEditor();
if (textEditor) {
- bool isEmpty = false;
- textEditor->GetDocumentIsEmpty(&isEmpty);
- if (isEmpty) {
+ if (textEditor->IsEmpty()) {
return DOMPoint(textEditor->GetRoot(), 0);
}
}
}
int32_t childIdx = GetChildIndexAtOffset(aOffset);
if (childIdx == -1)
return DOMPoint();
--- a/editor/libeditor/EditorCommands.cpp
+++ b/editor/libeditor/EditorCommands.cpp
@@ -834,31 +834,31 @@ SelectAllCommand::IsCommandEnabled(const
bool* aIsEnabled)
{
NS_ENSURE_ARG_POINTER(aIsEnabled);
nsresult rv = NS_OK;
// You can always select all, unless the selection is editable,
// and the editable region is empty!
*aIsEnabled = true;
- bool docIsEmpty;
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
if (!editor) {
return NS_OK;
}
// You can select all if there is an editor which is non-empty
TextEditor* textEditor = editor->AsTextEditor();
MOZ_ASSERT(textEditor);
- rv = textEditor->GetDocumentIsEmpty(&docIsEmpty);
+ bool isEmpty = false;
+ rv = textEditor->IsEmpty(&isEmpty);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
- *aIsEnabled = !docIsEmpty;
+ *aIsEnabled = !isEmpty;
return NS_OK;
}
NS_IMETHODIMP
SelectAllCommand::DoCommand(const char* aCommandName,
nsISupports* aCommandRefCon)
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -1357,35 +1357,41 @@ TextEditor::GetDocumentIsEmpty(bool* aDo
return rv;
}
return NS_OK;
}
NS_IMETHODIMP
TextEditor::GetTextLength(int32_t* aCount)
{
- NS_ASSERTION(aCount, "null pointer");
+ MOZ_ASSERT(aCount);
// initialize out params
*aCount = 0;
// special-case for empty document, to account for the bogus node
- bool docEmpty;
- nsresult rv = GetDocumentIsEmpty(&docEmpty);
- NS_ENSURE_SUCCESS(rv, rv);
- if (docEmpty) {
+ bool isEmpty = false;
+ nsresult rv = IsEmpty(&isEmpty);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
+ if (isEmpty) {
return NS_OK;
}
- dom::Element *rootElement = GetRoot();
- NS_ENSURE_TRUE(rootElement, NS_ERROR_NULL_POINTER);
+ Element* rootElement = GetRoot();
+ if (NS_WARN_IF(!rootElement)) {
+ return NS_ERROR_FAILURE;
+ }
nsCOMPtr<nsIContentIterator> iter =
do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &rv);
- NS_ENSURE_SUCCESS(rv, rv);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
uint32_t totalLength = 0;
iter->Init(rootElement);
for (; !iter->IsDone(); iter->Next()) {
nsCOMPtr<nsINode> currentNode = iter->GetCurrentNode();
if (IsTextNode(currentNode) && IsEditable(currentNode)) {
totalLength += currentNode->Length();
}