зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
6f6e4ef550
Коммит
83778753b6
|
@ -1683,17 +1683,18 @@ HTMLEditor::SelectElement(nsIDOMElement* aElement)
|
||||||
|
|
||||||
RefPtr<Selection> selection = GetSelection();
|
RefPtr<Selection> selection = GetSelection();
|
||||||
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
|
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
|
||||||
nsCOMPtr<nsIDOMNode>parent;
|
nsINode* parent = element->GetParentNode();
|
||||||
nsresult rv = aElement->GetParentNode(getter_AddRefs(parent));
|
if (NS_WARN_IF(!parent)) {
|
||||||
if (NS_SUCCEEDED(rv) && parent) {
|
return NS_ERROR_FAILURE;
|
||||||
int32_t offsetInParent = GetChildOffset(aElement, parent);
|
}
|
||||||
|
|
||||||
// Collapse selection to just before desired element,
|
int32_t offsetInParent = parent->IndexOf(element);
|
||||||
rv = selection->Collapse(parent, offsetInParent);
|
|
||||||
if (NS_SUCCEEDED(rv)) {
|
// Collapse selection to just before desired element,
|
||||||
// then extend it to just after
|
nsresult rv = selection->Collapse(parent, offsetInParent);
|
||||||
rv = selection->Extend(parent, offsetInParent + 1);
|
if (NS_SUCCEEDED(rv)) {
|
||||||
}
|
// then extend it to just after
|
||||||
|
rv = selection->Extend(parent, offsetInParent + 1);
|
||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1640,15 +1640,15 @@ TextEditor::SelectEntireDocument(Selection* aSelection)
|
||||||
|
|
||||||
// Don't select the trailing BR node if we have one
|
// Don't select the trailing BR node if we have one
|
||||||
int32_t selOffset;
|
int32_t selOffset;
|
||||||
nsCOMPtr<nsIDOMNode> selNode;
|
nsCOMPtr<nsINode> selNode;
|
||||||
rv = GetEndNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
|
rv = GetEndNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> childNode = GetChildAt(selNode, selOffset - 1);
|
nsINode* childNode = selNode->GetChildAt(selOffset - 1);
|
||||||
|
|
||||||
if (childNode && TextEditUtils::IsMozBR(childNode)) {
|
if (childNode && TextEditUtils::IsMozBR(childNode)) {
|
||||||
int32_t parentOffset;
|
int32_t parentOffset;
|
||||||
nsCOMPtr<nsIDOMNode> parentNode = GetNodeLocation(childNode, &parentOffset);
|
nsINode* parentNode = GetNodeLocation(childNode, &parentOffset);
|
||||||
|
|
||||||
return aSelection->Extend(parentNode, parentOffset);
|
return aSelection->Extend(parentNode, parentOffset);
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,10 +144,10 @@ nsresult TextEditorTest::TestTextProperties()
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
nodeList->GetLength(&count);
|
nodeList->GetLength(&count);
|
||||||
NS_ASSERTION(0!=count, "there are no text nodes in the document!");
|
NS_ASSERTION(0!=count, "there are no text nodes in the document!");
|
||||||
nsCOMPtr<nsIDOMNode>textNode;
|
nsCOMPtr<nsIDOMNode> domTextNode;
|
||||||
rv = nodeList->Item(count - 1, getter_AddRefs(textNode));
|
rv = nodeList->Item(count - 1, getter_AddRefs(domTextNode));
|
||||||
TEST_RESULT(rv);
|
TEST_RESULT(rv);
|
||||||
TEST_POINTER(textNode.get());
|
TEST_POINTER(domTextNode.get());
|
||||||
|
|
||||||
// set the whole text node to bold
|
// set the whole text node to bold
|
||||||
printf("set the whole first text node to bold\n");
|
printf("set the whole first text node to bold\n");
|
||||||
|
@ -155,12 +155,10 @@ nsresult TextEditorTest::TestTextProperties()
|
||||||
rv = mEditor->GetSelection(getter_AddRefs(selection));
|
rv = mEditor->GetSelection(getter_AddRefs(selection));
|
||||||
TEST_RESULT(rv);
|
TEST_RESULT(rv);
|
||||||
TEST_POINTER(selection.get());
|
TEST_POINTER(selection.get());
|
||||||
nsCOMPtr<nsIDOMCharacterData>textData;
|
nsCOMPtr<nsINode> textNode = do_QueryInterface(domTextNode);
|
||||||
textData = do_QueryInterface(textNode);
|
uint32_t length = textNode->Length();
|
||||||
uint32_t length;
|
selection->AsSelection()->Collapse(textNode, 0);
|
||||||
textData->GetLength(&length);
|
selection->AsSelection()->Extend(textNode, length);
|
||||||
selection->Collapse(textNode, 0);
|
|
||||||
selection->Extend(textNode, length);
|
|
||||||
|
|
||||||
nsCOMPtr<nsIHTMLEditor> htmlEditor (do_QueryInterface(mTextEditor));
|
nsCOMPtr<nsIHTMLEditor> htmlEditor (do_QueryInterface(mTextEditor));
|
||||||
NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
|
NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
|
||||||
|
@ -202,8 +200,8 @@ nsresult TextEditorTest::TestTextProperties()
|
||||||
|
|
||||||
// set all but the first and last character to bold
|
// 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");
|
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->AsSelection()->Collapse(textNode, 1);
|
||||||
selection->Extend(textNode, length-1);
|
selection->AsSelection()->Extend(textNode, length-1);
|
||||||
rv = htmlEditor->SetInlineProperty(b, empty, empty);
|
rv = htmlEditor->SetInlineProperty(b, empty, empty);
|
||||||
TEST_RESULT(rv);
|
TEST_RESULT(rv);
|
||||||
rv = htmlEditor->GetInlineProperty(b, empty, empty, &first, &any, &all);
|
rv = htmlEditor->GetInlineProperty(b, empty, empty, &first, &any, &all);
|
||||||
|
@ -233,14 +231,14 @@ nsresult TextEditorTest::TestTextProperties()
|
||||||
TEST_POINTER(nodeList.get());
|
TEST_POINTER(nodeList.get());
|
||||||
nodeList->GetLength(&count);
|
nodeList->GetLength(&count);
|
||||||
NS_ASSERTION(0!=count, "there are no text nodes in the document!");
|
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_RESULT(rv);
|
||||||
TEST_POINTER(textNode.get());
|
TEST_POINTER(textNode.get());
|
||||||
textData = do_QueryInterface(textNode);
|
textNode = do_QueryInterface(domTextNode);
|
||||||
textData->GetLength(&length);
|
length = textNode->Length();
|
||||||
NS_ASSERTION(length==915, "wrong text node");
|
NS_ASSERTION(length==915, "wrong text node");
|
||||||
selection->Collapse(textNode, 1);
|
selection->AsSelection()->Collapse(textNode, 1);
|
||||||
selection->Extend(textNode, length-2);
|
selection->AsSelection()->Extend(textNode, length-2);
|
||||||
rv = htmlEditor->SetInlineProperty(u, empty, empty);
|
rv = htmlEditor->SetInlineProperty(u, empty, empty);
|
||||||
TEST_RESULT(rv);
|
TEST_RESULT(rv);
|
||||||
rv = htmlEditor->GetInlineProperty(u, empty, empty, &first, &any, &all);
|
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);
|
NS_ENSURE_TRUE(mSelCon && aOffset >= 0 && aLength >= 0, NS_ERROR_FAILURE);
|
||||||
|
|
||||||
nsIDOMNode *sNode = 0, *eNode = 0;
|
nsCOMPtr<nsINode> startNode;
|
||||||
int32_t sOffset = 0, eOffset = 0;
|
int32_t startNodeOffset = 0;
|
||||||
OffsetEntry *entry;
|
OffsetEntry *entry;
|
||||||
|
|
||||||
// Find start of selection in node offset terms:
|
// 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];
|
entry = mOffsetTable[i];
|
||||||
if (entry->mIsValid) {
|
if (entry->mIsValid) {
|
||||||
if (entry->mIsInsertedText) {
|
if (entry->mIsInsertedText) {
|
||||||
|
@ -2166,8 +2166,8 @@ nsTextServicesDocument::SetSelectionInternal(int32_t aOffset, int32_t aLength, b
|
||||||
// match exactly!
|
// match exactly!
|
||||||
|
|
||||||
if (entry->mStrOffset == aOffset) {
|
if (entry->mStrOffset == aOffset) {
|
||||||
sNode = entry->mNode;
|
startNode = do_QueryInterface(entry->mNode);
|
||||||
sOffset = entry->mNodeOffset + entry->mLength;
|
startNodeOffset = entry->mNodeOffset + entry->mLength;
|
||||||
}
|
}
|
||||||
} else if (aOffset >= entry->mStrOffset) {
|
} else if (aOffset >= entry->mStrOffset) {
|
||||||
bool foundEntry = false;
|
bool foundEntry = false;
|
||||||
|
@ -2193,19 +2193,19 @@ nsTextServicesDocument::SetSelectionInternal(int32_t aOffset, int32_t aLength, b
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundEntry) {
|
if (foundEntry) {
|
||||||
sNode = entry->mNode;
|
startNode = do_QueryInterface(entry->mNode);
|
||||||
sOffset = entry->mNodeOffset + aOffset - entry->mStrOffset;
|
startNodeOffset = entry->mNodeOffset + aOffset - entry->mStrOffset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sNode) {
|
if (startNode) {
|
||||||
mSelStartIndex = static_cast<int32_t>(i);
|
mSelStartIndex = static_cast<int32_t>(i);
|
||||||
mSelStartOffset = aOffset;
|
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
|
// XXX: If we ever get a SetSelection() method in nsIEditor, we should
|
||||||
// use it.
|
// use it.
|
||||||
|
@ -2219,7 +2219,7 @@ nsTextServicesDocument::SetSelectionInternal(int32_t aOffset, int32_t aLength, b
|
||||||
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
rv = selection->Collapse(sNode, sOffset);
|
rv = selection->AsSelection()->Collapse(startNode, startNodeOffset);
|
||||||
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
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:
|
// Find the end of the selection in node offset terms:
|
||||||
|
nsCOMPtr<nsINode> endNode;
|
||||||
|
int32_t endNodeOffset = 0;
|
||||||
int32_t endOffset = aOffset + aLength;
|
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];
|
entry = mOffsetTable[i];
|
||||||
|
|
||||||
if (entry->mIsValid) {
|
if (entry->mIsValid) {
|
||||||
if (entry->mIsInsertedText) {
|
if (entry->mIsInsertedText) {
|
||||||
if (entry->mStrOffset == eOffset) {
|
if (entry->mStrOffset == endNodeOffset) {
|
||||||
// If the selection ends on an inserted text offset entry,
|
// If the selection ends on an inserted text offset entry,
|
||||||
// the selection includes the entire entry!
|
// the selection includes the entire entry!
|
||||||
|
|
||||||
eNode = entry->mNode;
|
endNode = do_QueryInterface(entry->mNode);
|
||||||
eOffset = entry->mNodeOffset + entry->mLength;
|
endNodeOffset = entry->mNodeOffset + entry->mLength;
|
||||||
}
|
}
|
||||||
} else if (endOffset >= entry->mStrOffset &&
|
} else if (endOffset >= entry->mStrOffset &&
|
||||||
endOffset <= entry->mStrOffset + entry->mLength) {
|
endOffset <= entry->mStrOffset + entry->mLength) {
|
||||||
eNode = entry->mNode;
|
endNode = do_QueryInterface(entry->mNode);
|
||||||
eOffset = entry->mNodeOffset + endOffset - entry->mStrOffset;
|
endNodeOffset = entry->mNodeOffset + endOffset - entry->mStrOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eNode) {
|
if (endNode) {
|
||||||
mSelEndIndex = i;
|
mSelEndIndex = i;
|
||||||
mSelEndOffset = endOffset;
|
mSelEndOffset = endOffset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aDoUpdate && eNode) {
|
if (aDoUpdate && endNode) {
|
||||||
nsresult rv = selection->Extend(eNode, eOffset);
|
nsresult rv = selection->AsSelection()->Extend(endNode, endNodeOffset);
|
||||||
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче