Bug 1407305 - Part 4: Avoid using GetChildAt() in EditorBase::GetNextNode(); r=masayuki

This commit is contained in:
Ehsan Akhgari 2017-10-07 18:36:50 -04:00
Родитель 40afcd0316
Коммит 6a2135a0bb
4 изменённых файлов: 17 добавлений и 11 удалений

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

@ -3313,6 +3313,7 @@ EditorBase::GetPriorNode(nsINode* aParentNode,
nsIContent*
EditorBase::GetNextNode(nsINode* aParentNode,
int32_t aOffset,
nsINode* aChildAtOffset,
bool aEditableNode,
bool aNoBlockCrossing)
{
@ -3327,15 +3328,16 @@ EditorBase::GetNextNode(nsINode* aParentNode,
}
// look at the child at 'aOffset'
nsIContent* child = aParentNode->GetChildAt(aOffset);
if (child) {
if (aNoBlockCrossing && IsBlockNode(child)) {
return child;
if (aChildAtOffset) {
if (aNoBlockCrossing && IsBlockNode(aChildAtOffset)) {
MOZ_ASSERT(aChildAtOffset->IsContent());
return aChildAtOffset->AsContent();
}
nsIContent* resultNode = GetLeftmostChild(child, aNoBlockCrossing);
nsIContent* resultNode = GetLeftmostChild(aChildAtOffset, aNoBlockCrossing);
if (!resultNode) {
return child;
MOZ_ASSERT(aChildAtOffset->IsContent());
return aChildAtOffset->AsContent();
}
if (!IsDescendantOfEditorRoot(resultNode)) {
@ -4660,7 +4662,7 @@ EditorBase::CreateTxnForDeleteRange(nsRange* aRangeToDelete,
if (aAction == ePrevious) {
selectedNode = GetPriorNode(node, offset, child, true);
} else if (aAction == eNext) {
selectedNode = GetNextNode(node, offset, true);
selectedNode = GetNextNode(node, offset, child, true);
}
while (selectedNode &&

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

@ -731,6 +731,7 @@ public:
*/
nsIContent* GetNextNode(nsINode* aParentNode,
int32_t aOffset,
nsINode* aChildAtOffset,
bool aEditableNode,
bool aNoBlockCrossing = false);

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

@ -854,6 +854,7 @@ HTMLEditRules::GetAlignment(bool* aMixed,
selection->GetRangeAt(0)->GetStartContainer());
OwningNonNull<nsINode> parent =
*selection->GetRangeAt(0)->GetStartContainer();
nsIContent* child = selection->GetRangeAt(0)->GetChildAtStartOffset();
int32_t offset = selection->GetRangeAt(0)->StartOffset();
// Is the selection collapsed?
@ -865,7 +866,7 @@ HTMLEditRules::GetAlignment(bool* aMixed,
nodeToExamine = parent;
} else if (parent->IsHTMLElement(nsGkAtoms::html) && offset == rootOffset) {
// If we have selected the body, let's look at the first editable node
nodeToExamine = htmlEditor->GetNextNode(parent, offset, true);
nodeToExamine = htmlEditor->GetNextNode(parent, offset, child, true);
} else {
nsTArray<RefPtr<nsRange>> arrayOfRanges;
GetPromotedRanges(selection, arrayOfRanges, EditAction::align);
@ -5047,8 +5048,9 @@ HTMLEditRules::CheckForEmptyBlock(nsINode* aStartNode,
if (aAction == nsIEditor::eNext || aAction == nsIEditor::eNextWord ||
aAction == nsIEditor::eToEndOfLine) {
// Move to the start of the next node, if any
nsCOMPtr<nsIContent> nextNode = htmlEditor->GetNextNode(blockParent,
offset + 1, true);
nsINode* child = emptyBlock->GetNextSibling();
nsCOMPtr<nsIContent> nextNode =
htmlEditor->GetNextNode(blockParent, offset + 1, child, true);
if (nextNode) {
EditorDOMPoint pt = GetGoodSelPointForNode(*nextNode, aAction);
nsresult rv = aSelection->Collapse(pt.node, pt.offset);

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

@ -3946,7 +3946,8 @@ HTMLEditor::GetNextHTMLNode(nsINode* aParent,
nsINode* aChildAtOffset,
bool aNoBlockCrossing)
{
nsIContent* content = GetNextNode(aParent, aOffset, true, aNoBlockCrossing);
nsIContent* content = GetNextNode(aParent, aOffset, aChildAtOffset,
true, aNoBlockCrossing);
if (content && !IsDescendantOfEditorRoot(content)) {
return nullptr;
}