Bug 1616257 - part 2: Change `mStartReasonNode` and `mEndReasonNode` to `nsIContent` r=m_kato

Now, all setter guarantee that they are subclass instances of `nsIContent`.

Differential Revision: https://phabricator.services.mozilla.com/D63612

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2020-02-25 09:31:18 +00:00
Родитель ca9705cc2b
Коммит 6382dae45f
5 изменённых файлов: 59 добавлений и 51 удалений

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

@ -6836,7 +6836,7 @@ Element* HTMLEditor::GetInvisibleBRElementAt(
WSRunObject wsTester(this, aPoint);
return WSType::br == wsTester.mStartReason
? wsTester.mStartReasonNode->AsElement()
? wsTester.GetStartReasonContent()->AsElement()
: nullptr;
}
@ -6903,12 +6903,12 @@ HTMLEditor::GetExtendedRangeToIncludeInvisibleNodes(
}
// We want to keep looking up. But stop if we are crossing table
// element boundaries, or if we hit the root.
if (HTMLEditUtils::IsTableElement(wsObj.mStartReasonNode) ||
wsObj.mStartReasonNode == commonAncestorBlock ||
wsObj.mStartReasonNode == editingHost) {
if (HTMLEditUtils::IsTableElement(wsObj.GetStartReasonContent()) ||
wsObj.GetStartReasonContent() == commonAncestorBlock ||
wsObj.GetStartReasonContent() == editingHost) {
break;
}
atStart.Set(wsObj.mStartReasonNode);
atStart.Set(wsObj.GetStartReasonContent());
}
}
@ -6925,13 +6925,13 @@ HTMLEditor::GetExtendedRangeToIncludeInvisibleNodes(
WSType wsType;
wsObj.NextVisibleNode(atEnd, &wsType);
if (wsType == WSType::br) {
if (IsVisibleBRElement(wsObj.mEndReasonNode)) {
if (IsVisibleBRElement(wsObj.GetEndReasonContent())) {
break;
}
if (!atFirstInvisibleBRElement.IsSet()) {
atFirstInvisibleBRElement = atEnd;
}
atEnd.Set(wsObj.mEndReasonNode);
atEnd.Set(wsObj.GetEndReasonContent());
atEnd.AdvanceOffset();
continue;
}
@ -6939,12 +6939,12 @@ HTMLEditor::GetExtendedRangeToIncludeInvisibleNodes(
if (wsType == WSType::thisBlock) {
// We want to keep looking up. But stop if we are crossing table
// element boundaries, or if we hit the root.
if (HTMLEditUtils::IsTableElement(wsObj.mEndReasonNode) ||
wsObj.mEndReasonNode == commonAncestorBlock ||
wsObj.mEndReasonNode == editingHost) {
if (HTMLEditUtils::IsTableElement(wsObj.GetEndReasonContent()) ||
wsObj.GetEndReasonContent() == commonAncestorBlock ||
wsObj.GetEndReasonContent() == editingHost) {
break;
}
atEnd.Set(wsObj.mEndReasonNode);
atEnd.Set(wsObj.GetEndReasonContent());
atEnd.AdvanceOffset();
continue;
}
@ -7035,7 +7035,8 @@ nsresult HTMLEditor::MaybeExtendSelectionToHardLineEdgesForBlockEditAction() {
// of going "down" into a block and "up" out of a block.
if (wsEndObj.mStartReason == WSType::otherBlock) {
// endpoint is just after the close of a block.
nsINode* child = GetRightmostChild(wsEndObj.mStartReasonNode, true);
nsINode* child =
GetRightmostChild(wsEndObj.GetStartReasonContent(), true);
if (child) {
newEndPoint.SetAfter(child);
}
@ -7049,7 +7050,7 @@ nsresult HTMLEditor::MaybeExtendSelectionToHardLineEdgesForBlockEditAction() {
// else block is empty - we can leave selection alone here, i think.
} else if (wsEndObj.mStartReason == WSType::br) {
// endpoint is just after break. lets adjust it to before it.
newEndPoint.Set(wsEndObj.mStartReasonNode);
newEndPoint.Set(wsEndObj.GetStartReasonContent());
}
}
@ -7063,7 +7064,7 @@ nsresult HTMLEditor::MaybeExtendSelectionToHardLineEdgesForBlockEditAction() {
// of going "down" into a block and "up" out of a block.
if (wsStartObj.mEndReason == WSType::otherBlock) {
// startpoint is just before the start of a block.
nsINode* child = GetLeftmostChild(wsStartObj.mEndReasonNode, true);
nsINode* child = GetLeftmostChild(wsStartObj.GetEndReasonContent(), true);
if (child) {
newStartPoint.Set(child);
}
@ -7077,7 +7078,7 @@ nsresult HTMLEditor::MaybeExtendSelectionToHardLineEdgesForBlockEditAction() {
// else block is empty - we can leave selection alone here, i think.
} else if (wsStartObj.mEndReason == WSType::br) {
// startpoint is just before a break. lets adjust it to after it.
newStartPoint.SetAfter(wsStartObj.mEndReasonNode);
newStartPoint.SetAfter(wsStartObj.GetEndReasonContent());
}
}

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

@ -3134,15 +3134,15 @@ nsresult HTMLEditor::DeleteParentBlocksWithTransactionIfEmpty(
// parent block.
return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND;
}
if (NS_WARN_IF(!wsObj.mStartReasonNode) ||
NS_WARN_IF(!wsObj.mStartReasonNode->GetParentNode())) {
if (NS_WARN_IF(!wsObj.GetStartReasonContent()) ||
NS_WARN_IF(!wsObj.GetStartReasonContent()->GetParentNode())) {
return NS_ERROR_FAILURE;
}
if (wsObj.GetEditingHost() == wsObj.mStartReasonNode) {
if (wsObj.GetEditingHost() == wsObj.GetStartReasonContent()) {
// If we reach editing host, there is no parent blocks which can be removed.
return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND;
}
if (HTMLEditUtils::IsTableCellOrCaption(*wsObj.mStartReasonNode)) {
if (HTMLEditUtils::IsTableCellOrCaption(*wsObj.GetStartReasonContent())) {
// If we reach a <td>, <th> or <caption>, we shouldn't remove it even
// becomes empty because removing such element changes the structure of
// the <table>.
@ -3154,12 +3154,12 @@ nsresult HTMLEditor::DeleteParentBlocksWithTransactionIfEmpty(
wsObj.NextVisibleNode(aPoint, &wsType);
if (wsType == WSType::br) {
// If the <br> element is visible, we shouldn't remove the parent block.
if (IsVisibleBRElement(wsObj.mEndReasonNode)) {
if (IsVisibleBRElement(wsObj.GetEndReasonContent())) {
return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND;
}
if (wsObj.mEndReasonNode->GetNextSibling()) {
if (wsObj.GetEndReasonContent()->GetNextSibling()) {
EditorRawDOMPoint afterBRElement;
afterBRElement.SetAfter(wsObj.mEndReasonNode);
afterBRElement.SetAfter(wsObj.GetEndReasonContent());
WSRunObject wsRunObjAfterBR(this, afterBRElement);
WSType wsTypeAfterBR = WSType::none;
wsRunObjAfterBR.NextVisibleNode(afterBRElement, &wsTypeAfterBR);
@ -3175,9 +3175,9 @@ nsresult HTMLEditor::DeleteParentBlocksWithTransactionIfEmpty(
}
// Delete the parent block.
EditorDOMPoint nextPoint(wsObj.mStartReasonNode->GetParentNode(), 0);
EditorDOMPoint nextPoint(wsObj.GetStartReasonContent()->GetParentNode(), 0);
nsresult rv =
DeleteNodeWithTransaction(MOZ_KnownLive(*wsObj.mStartReasonNode));
DeleteNodeWithTransaction(MOZ_KnownLive(*wsObj.GetStartReasonContent()));
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return NS_ERROR_EDITOR_DESTROYED;
}

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

@ -373,11 +373,11 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
// element at end of what we paste, it will make the existing invisible
// `<br>` element visible.
WSRunObject wsObj(this, pointToInsert);
if (wsObj.mEndReasonNode &&
wsObj.mEndReasonNode->IsHTMLElement(nsGkAtoms::br) &&
!IsVisibleBRElement(wsObj.mEndReasonNode)) {
if (wsObj.GetEndReasonContent() &&
wsObj.GetEndReasonContent()->IsHTMLElement(nsGkAtoms::br) &&
!IsVisibleBRElement(wsObj.GetEndReasonContent())) {
AutoEditorDOMPointChildInvalidator lockOffset(pointToInsert);
rv = DeleteNodeWithTransaction(MOZ_KnownLive(*wsObj.mEndReasonNode));
rv = DeleteNodeWithTransaction(MOZ_KnownLive(*wsObj.GetEndReasonContent()));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -635,8 +635,10 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
WSRunObject wsRunObj(this, pointToPutCaret);
WSType visType;
wsRunObj.PriorVisibleNode(pointToPutCaret, &visType);
if (visType == WSType::br && !IsVisibleBRElement(wsRunObj.mStartReasonNode)) {
WSRunObject wsRunObj2(this, EditorDOMPoint(wsRunObj.mStartReasonNode));
if (visType == WSType::br &&
!IsVisibleBRElement(wsRunObj.GetStartReasonContent())) {
WSRunObject wsRunObj2(this,
EditorDOMPoint(wsRunObj.GetStartReasonContent()));
nsCOMPtr<nsINode> visibleNode;
int32_t visibleNodeOffset;
wsRunObj2.PriorVisibleNode(pointToPutCaret, address_of(visibleNode),
@ -644,7 +646,7 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
if (visType == WSType::text || visType == WSType::normalWS) {
pointToPutCaret.Set(visibleNode, visibleNodeOffset);
} else if (visType == WSType::special) {
pointToPutCaret.Set(wsRunObj2.mStartReasonNode);
pointToPutCaret.Set(wsRunObj2.GetStartReasonContent());
DebugOnly<bool> advanced = pointToPutCaret.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset from found object");

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

@ -573,10 +573,10 @@ void WSRunScanner::PriorVisibleNode(const EditorDOMPointBase<PT, CT>& aPoint,
if (outVisNode) {
// If we get here, then nothing in ws data to find. Return start reason.
*outVisNode = mStartReasonNode;
*outVisNode = mStartReasonContent;
}
if (outVisOffset) {
// This really isn't meaningful if mStartReasonNode != mStartNode
// This really isn't meaningful if mStartReasonContent != mStartNode
*outVisOffset = mStartOffset;
}
*outType = mStartReason;
@ -619,10 +619,10 @@ void WSRunScanner::NextVisibleNode(const EditorDOMPointBase<PT, CT>& aPoint,
if (outVisNode) {
// If we get here, then nothing in ws data to find. Return end reason
*outVisNode = mEndReasonNode;
*outVisNode = mEndReasonContent;
}
if (outVisOffset) {
// This really isn't meaningful if mEndReasonNode != mEndNode
// This really isn't meaningful if mEndReasonContent != mEndNode
*outVisOffset = mEndOffset;
}
*outType = mEndReason;
@ -713,7 +713,7 @@ nsresult WSRunScanner::GetWSNodes() {
mStartNode = textNode;
mStartOffset = i;
mStartReason = WSType::text;
mStartReasonNode = textNode;
mStartReasonContent = textNode;
break;
}
// as we look backwards update our earliest found nbsp
@ -739,7 +739,7 @@ nsresult WSRunScanner::GetWSNodes() {
mStartNode = start.GetContainer();
mStartOffset = start.Offset();
mStartReason = WSType::otherBlock;
mStartReasonNode = priorNode;
mStartReasonContent = priorNode;
} else if (priorNode->IsText() && priorNode->IsEditable()) {
RefPtr<Text> textNode = priorNode->GetAsText();
mNodeArray.InsertElementAt(0, textNode);
@ -766,7 +766,7 @@ nsresult WSRunScanner::GetWSNodes() {
mStartNode = textNode;
mStartOffset = pos + 1;
mStartReason = WSType::text;
mStartReasonNode = textNode;
mStartReasonContent = textNode;
break;
}
// as we look backwards update our earliest found nbsp
@ -791,7 +791,7 @@ nsresult WSRunScanner::GetWSNodes() {
} else {
mStartReason = WSType::special;
}
mStartReasonNode = priorNode;
mStartReasonContent = priorNode;
}
} else {
// no prior node means we exhausted
@ -799,9 +799,9 @@ nsresult WSRunScanner::GetWSNodes() {
mStartNode = start.GetContainer();
mStartOffset = start.Offset();
mStartReason = WSType::thisBlock;
// mStartReasonNode can be either a block element or any non-editable
// mStartReasonContent can be either a block element or any non-editable
// content in this case.
mStartReasonNode = editableBlockParentOrTopmotEditableInlineContent;
mStartReasonContent = editableBlockParentOrTopmotEditableInlineContent;
}
}
@ -822,7 +822,7 @@ nsresult WSRunScanner::GetWSNodes() {
mEndNode = textNode;
mEndOffset = i;
mEndReason = WSType::text;
mEndReasonNode = textNode;
mEndReasonContent = textNode;
break;
}
// as we look forwards update our latest found nbsp
@ -849,7 +849,7 @@ nsresult WSRunScanner::GetWSNodes() {
mEndNode = end.GetContainer();
mEndOffset = end.Offset();
mEndReason = WSType::otherBlock;
mEndReasonNode = nextNode;
mEndReasonContent = nextNode;
} else if (nextNode->IsText() && nextNode->IsEditable()) {
RefPtr<Text> textNode = nextNode->GetAsText();
mNodeArray.AppendElement(textNode);
@ -876,7 +876,7 @@ nsresult WSRunScanner::GetWSNodes() {
mEndNode = textNode;
mEndOffset = pos;
mEndReason = WSType::text;
mEndReasonNode = textNode;
mEndReasonContent = textNode;
break;
}
// as we look forwards update our latest found nbsp
@ -902,7 +902,7 @@ nsresult WSRunScanner::GetWSNodes() {
} else {
mEndReason = WSType::special;
}
mEndReasonNode = nextNode;
mEndReasonContent = nextNode;
}
} else {
// no next node means we exhausted
@ -910,9 +910,9 @@ nsresult WSRunScanner::GetWSNodes() {
mEndNode = end.GetContainer();
mEndOffset = end.Offset();
mEndReason = WSType::thisBlock;
// mEndReasonNode can be either a block element or any non-editable
// mEndReasonContent can be either a block element or any non-editable
// content in this case.
mEndReasonNode = editableBlockParentOrTopmotEditableInlineContent;
mEndReasonContent = editableBlockParentOrTopmotEditableInlineContent;
}
}

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

@ -200,6 +200,12 @@ class MOZ_STACK_CLASS WSRunScanner {
PriorVisibleNode(aPoint, nullptr, nullptr, outType);
}
/**
* TODO: Document us!
*/
nsIContent* GetStartReasonContent() const { return mStartReasonContent; }
nsIContent* GetEndReasonContent() const { return mEndReasonContent; }
protected:
// WSFragment represents a single run of ws (all leadingws, or all normalws,
// or all trailingws, or all leading+trailingws). Note that this single run
@ -343,16 +349,12 @@ class MOZ_STACK_CLASS WSRunScanner {
int32_t mStartOffset;
// Reason why ws starts (eText, eOtherBlock, etc.).
WSType mStartReason;
// The node that implicated by start reason.
nsCOMPtr<nsINode> mStartReasonNode;
// Node/offset where ws ends.
nsCOMPtr<nsINode> mEndNode;
int32_t mEndOffset;
// Reason why ws ends (eText, eOtherBlock, etc.).
WSType mEndReason;
// The node that implicated by end reason.
nsCOMPtr<nsINode> mEndReasonNode;
// Location of first nbsp in ws run, if any.
RefPtr<dom::Text> mFirstNBSPNode;
@ -368,6 +370,9 @@ class MOZ_STACK_CLASS WSRunScanner {
// The last WSFragment in the run, may be same as first.
WSFragment* mEndRun;
nsCOMPtr<nsIContent> mStartReasonContent;
nsCOMPtr<nsIContent> mEndReasonContent;
// Non-owning.
const HTMLEditor* mHTMLEditor;
};