Bug 1391978 - Part 6. Replace nsISelection::Extend with Selection::Extend. r=masayuki

Except to HTMLEditRules::NormalizeSelection, I replace nsISelection::Extend with Selection::Extend.

MozReview-Commit-ID: H83zpvAo5Xa

--HG--
extra : rebase_source : b217dd1d506229d848126b9c2494d1b4f9dc3a35
extra : histedit_source : 8999bc5b1b1edfe7e48a432d52640b8181490624
This commit is contained in:
Makoto Kato 2017-08-28 17:54:34 +09:00
Родитель 6f6e4ef550
Коммит 83778753b6
4 изменённых файлов: 49 добавлений и 48 удалений

Просмотреть файл

@ -1683,17 +1683,18 @@ HTMLEditor::SelectElement(nsIDOMElement* aElement)
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIDOMNode>parent;
nsresult rv = aElement->GetParentNode(getter_AddRefs(parent));
if (NS_SUCCEEDED(rv) && parent) {
int32_t offsetInParent = GetChildOffset(aElement, parent);
nsINode* parent = element->GetParentNode();
if (NS_WARN_IF(!parent)) {
return NS_ERROR_FAILURE;
}
// Collapse selection to just before desired element,
rv = selection->Collapse(parent, offsetInParent);
if (NS_SUCCEEDED(rv)) {
// then extend it to just after
rv = selection->Extend(parent, offsetInParent + 1);
}
int32_t offsetInParent = parent->IndexOf(element);
// Collapse selection to just before desired element,
nsresult rv = selection->Collapse(parent, offsetInParent);
if (NS_SUCCEEDED(rv)) {
// then extend it to just after
rv = selection->Extend(parent, offsetInParent + 1);
}
return rv;
}

Просмотреть файл

@ -1640,15 +1640,15 @@ TextEditor::SelectEntireDocument(Selection* aSelection)
// Don't select the trailing BR node if we have one
int32_t selOffset;
nsCOMPtr<nsIDOMNode> selNode;
nsCOMPtr<nsINode> selNode;
rv = GetEndNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMNode> childNode = GetChildAt(selNode, selOffset - 1);
nsINode* childNode = selNode->GetChildAt(selOffset - 1);
if (childNode && TextEditUtils::IsMozBR(childNode)) {
int32_t parentOffset;
nsCOMPtr<nsIDOMNode> parentNode = GetNodeLocation(childNode, &parentOffset);
nsINode* parentNode = GetNodeLocation(childNode, &parentOffset);
return aSelection->Extend(parentNode, parentOffset);
}

Просмотреть файл

@ -144,10 +144,10 @@ nsresult TextEditorTest::TestTextProperties()
uint32_t count;
nodeList->GetLength(&count);
NS_ASSERTION(0!=count, "there are no text nodes in the document!");
nsCOMPtr<nsIDOMNode>textNode;
rv = nodeList->Item(count - 1, getter_AddRefs(textNode));
nsCOMPtr<nsIDOMNode> domTextNode;
rv = nodeList->Item(count - 1, getter_AddRefs(domTextNode));
TEST_RESULT(rv);
TEST_POINTER(textNode.get());
TEST_POINTER(domTextNode.get());
// set the whole text node to bold
printf("set the whole first text node to bold\n");
@ -155,12 +155,10 @@ nsresult TextEditorTest::TestTextProperties()
rv = mEditor->GetSelection(getter_AddRefs(selection));
TEST_RESULT(rv);
TEST_POINTER(selection.get());
nsCOMPtr<nsIDOMCharacterData>textData;
textData = do_QueryInterface(textNode);
uint32_t length;
textData->GetLength(&length);
selection->Collapse(textNode, 0);
selection->Extend(textNode, length);
nsCOMPtr<nsINode> textNode = do_QueryInterface(domTextNode);
uint32_t length = textNode->Length();
selection->AsSelection()->Collapse(textNode, 0);
selection->AsSelection()->Extend(textNode, length);
nsCOMPtr<nsIHTMLEditor> htmlEditor (do_QueryInterface(mTextEditor));
NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
@ -202,8 +200,8 @@ nsresult TextEditorTest::TestTextProperties()
// set all but the first and last character to bold
printf("set the first text node (1, length-1) to bold and italic, and (2, length-1) to underline.\n");
selection->Collapse(textNode, 1);
selection->Extend(textNode, length-1);
selection->AsSelection()->Collapse(textNode, 1);
selection->AsSelection()->Extend(textNode, length-1);
rv = htmlEditor->SetInlineProperty(b, empty, empty);
TEST_RESULT(rv);
rv = htmlEditor->GetInlineProperty(b, empty, empty, &first, &any, &all);
@ -233,14 +231,14 @@ nsresult TextEditorTest::TestTextProperties()
TEST_POINTER(nodeList.get());
nodeList->GetLength(&count);
NS_ASSERTION(0!=count, "there are no text nodes in the document!");
rv = nodeList->Item(count-2, getter_AddRefs(textNode));
rv = nodeList->Item(count-2, getter_AddRefs(domTextNode));
TEST_RESULT(rv);
TEST_POINTER(textNode.get());
textData = do_QueryInterface(textNode);
textData->GetLength(&length);
textNode = do_QueryInterface(domTextNode);
length = textNode->Length();
NS_ASSERTION(length==915, "wrong text node");
selection->Collapse(textNode, 1);
selection->Extend(textNode, length-2);
selection->AsSelection()->Collapse(textNode, 1);
selection->AsSelection()->Extend(textNode, length-2);
rv = htmlEditor->SetInlineProperty(u, empty, empty);
TEST_RESULT(rv);
rv = htmlEditor->GetInlineProperty(u, empty, empty, &first, &any, &all);

Просмотреть файл

@ -2151,13 +2151,13 @@ nsTextServicesDocument::SetSelectionInternal(int32_t aOffset, int32_t aLength, b
{
NS_ENSURE_TRUE(mSelCon && aOffset >= 0 && aLength >= 0, NS_ERROR_FAILURE);
nsIDOMNode *sNode = 0, *eNode = 0;
int32_t sOffset = 0, eOffset = 0;
nsCOMPtr<nsINode> startNode;
int32_t startNodeOffset = 0;
OffsetEntry *entry;
// Find start of selection in node offset terms:
for (size_t i = 0; !sNode && i < mOffsetTable.Length(); i++) {
for (size_t i = 0; !startNode && i < mOffsetTable.Length(); i++) {
entry = mOffsetTable[i];
if (entry->mIsValid) {
if (entry->mIsInsertedText) {
@ -2166,8 +2166,8 @@ nsTextServicesDocument::SetSelectionInternal(int32_t aOffset, int32_t aLength, b
// match exactly!
if (entry->mStrOffset == aOffset) {
sNode = entry->mNode;
sOffset = entry->mNodeOffset + entry->mLength;
startNode = do_QueryInterface(entry->mNode);
startNodeOffset = entry->mNodeOffset + entry->mLength;
}
} else if (aOffset >= entry->mStrOffset) {
bool foundEntry = false;
@ -2193,19 +2193,19 @@ nsTextServicesDocument::SetSelectionInternal(int32_t aOffset, int32_t aLength, b
}
if (foundEntry) {
sNode = entry->mNode;
sOffset = entry->mNodeOffset + aOffset - entry->mStrOffset;
startNode = do_QueryInterface(entry->mNode);
startNodeOffset = entry->mNodeOffset + aOffset - entry->mStrOffset;
}
}
if (sNode) {
if (startNode) {
mSelStartIndex = static_cast<int32_t>(i);
mSelStartOffset = aOffset;
}
}
}
NS_ENSURE_TRUE(sNode, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
// XXX: If we ever get a SetSelection() method in nsIEditor, we should
// use it.
@ -2219,7 +2219,7 @@ nsTextServicesDocument::SetSelectionInternal(int32_t aOffset, int32_t aLength, b
NS_ENSURE_SUCCESS(rv, rv);
rv = selection->Collapse(sNode, sOffset);
rv = selection->AsSelection()->Collapse(startNode, startNodeOffset);
NS_ENSURE_SUCCESS(rv, rv);
}
@ -2238,34 +2238,36 @@ nsTextServicesDocument::SetSelectionInternal(int32_t aOffset, int32_t aLength, b
}
// Find the end of the selection in node offset terms:
nsCOMPtr<nsINode> endNode;
int32_t endNodeOffset = 0;
int32_t endOffset = aOffset + aLength;
for (int32_t i = mOffsetTable.Length() - 1; !eNode && i >= 0; i--) {
for (int32_t i = mOffsetTable.Length() - 1; !endNode && i >= 0; i--) {
entry = mOffsetTable[i];
if (entry->mIsValid) {
if (entry->mIsInsertedText) {
if (entry->mStrOffset == eOffset) {
if (entry->mStrOffset == endNodeOffset) {
// If the selection ends on an inserted text offset entry,
// the selection includes the entire entry!
eNode = entry->mNode;
eOffset = entry->mNodeOffset + entry->mLength;
endNode = do_QueryInterface(entry->mNode);
endNodeOffset = entry->mNodeOffset + entry->mLength;
}
} else if (endOffset >= entry->mStrOffset &&
endOffset <= entry->mStrOffset + entry->mLength) {
eNode = entry->mNode;
eOffset = entry->mNodeOffset + endOffset - entry->mStrOffset;
endNode = do_QueryInterface(entry->mNode);
endNodeOffset = entry->mNodeOffset + endOffset - entry->mStrOffset;
}
if (eNode) {
if (endNode) {
mSelEndIndex = i;
mSelEndOffset = endOffset;
}
}
}
if (aDoUpdate && eNode) {
nsresult rv = selection->Extend(eNode, eOffset);
if (aDoUpdate && endNode) {
nsresult rv = selection->AsSelection()->Extend(endNode, endNodeOffset);
NS_ENSURE_SUCCESS(rv, rv);
}