Bug 1783402 - part 2: Make result of safe getter methods of `EditorDOMPointBase` templated r=m_kato

Similar to the previous patch, and for consistency between editor helper
classes, we should make result of getter methods of `EditorDOMPointBase` too.

Differential Revision: https://phabricator.services.mozilla.com/D153841
This commit is contained in:
Masayuki Nakano 2022-08-09 01:43:24 +00:00
Родитель 2c1d4805a6
Коммит fe4e77e324
15 изменённых файлов: 79 добавлений и 102 удалений

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

@ -295,7 +295,7 @@ AutoRangeArray::ExtendAnchorFocusRangeFor(
}
const nsTextFragment* data =
&insertionPoint.GetContainerAsText()->TextFragment();
&insertionPoint.ContainerAsText()->TextFragment();
uint32_t offset = insertionPoint.Offset();
if (!(offset > 1 &&
data->IsLowSurrogateFollowingHighSurrogateAt(offset - 1)) &&

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

@ -38,7 +38,7 @@ already_AddRefed<CompositionTransaction> CompositionTransaction::Create(
if (Text* textNode = composition->GetContainerTextNode()) {
pointToInsert.Set(textNode, composition->XPOffsetInTextNode());
NS_WARNING_ASSERTION(
pointToInsert.GetContainerAsText() ==
pointToInsert.GetContainerAs<Text>() ==
composition->GetContainerTextNode(),
"The editor tries to insert composition string into different node");
NS_WARNING_ASSERTION(

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

@ -4068,7 +4068,7 @@ EditorBase::CreateTransactionForCollapsedRange(
}
} else {
MOZ_ASSERT(point.IsInTextNode());
editableContent = point.GetContainerAsContent();
editableContent = point.GetContainerAs<nsIContent>();
if (!editableContent) {
NS_WARNING("If there was no text node, should've been handled first");
return nullptr;
@ -4405,8 +4405,7 @@ nsresult EditorBase::HandleDropEvent(DragEvent* aDropEvent) {
}
EditorDOMPoint droppedAt(dropParentContent,
AssertedCast<uint32_t>(dropOffset));
if (NS_WARN_IF(!droppedAt.IsSet()) ||
NS_WARN_IF(!droppedAt.GetContainerAsContent())) {
if (NS_WARN_IF(!droppedAt.IsInContentNode())) {
return NS_ERROR_FAILURE;
}
@ -4470,7 +4469,7 @@ nsresult EditorBase::HandleDropEvent(DragEvent* aDropEvent) {
}
if (IsInPlaintextMode()) {
for (nsIContent* content = droppedAt.GetContainerAsContent(); content;
for (nsIContent* content = droppedAt.ContainerAsContent(); content;
content = content->GetParent()) {
nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(content));
if (formControl && !formControl->AllowDrop()) {
@ -4531,6 +4530,7 @@ nsresult EditorBase::HandleDropEvent(DragEvent* aDropEvent) {
}
droppedAt = rangeAtDropPoint->StartRef();
MOZ_ASSERT(droppedAt.IsSetAndValid());
MOZ_ASSERT(droppedAt.IsInContentNode());
}
// Before inserting dropping content, we need to move focus for compatibility
@ -4546,11 +4546,11 @@ nsresult EditorBase::HandleDropEvent(DragEvent* aDropEvent) {
else if (!AsHTMLEditor()->IsInDesignMode()) {
focusedElement = AsHTMLEditor()->ComputeEditingHost();
if (focusedElement &&
droppedAt.GetContainerAsContent()->IsInclusiveDescendantOf(
droppedAt.ContainerAsContent()->IsInclusiveDescendantOf(
focusedElement)) {
newFocusedElement = focusedElement;
} else {
newFocusedElement = droppedAt.GetContainerAsContent()->GetEditingHost();
newFocusedElement = droppedAt.ContainerAsContent()->GetEditingHost();
}
}
// Move selection right now. Note that this does not move focus because
@ -5285,7 +5285,7 @@ nsresult EditorBase::InitializeSelection(
EditorRawDOMPoint atStartOfFirstRange(firstRange->StartRef());
EditorRawDOMPoint betterInsertionPoint =
FindBetterInsertionPoint(atStartOfFirstRange);
RefPtr<Text> textNode = betterInsertionPoint.GetContainerAsText();
RefPtr<Text> textNode = betterInsertionPoint.GetContainerAs<Text>();
MOZ_ASSERT(textNode,
"There must be text node if composition string is not empty");
if (textNode) {
@ -5808,7 +5808,7 @@ EditorBase::AutoCaretBidiLevelManager::AutoCaretBidiLevelManager(
return; // Perform the deletion
}
if (!aPointAtCaret.GetContainerAsContent()) {
if (!aPointAtCaret.IsInContentNode()) {
mFailed = true;
return;
}
@ -5822,7 +5822,7 @@ EditorBase::AutoCaretBidiLevelManager::AutoCaretBidiLevelManager(
}
nsPrevNextBidiLevels levels = frameSelection->GetPrevNextBidiLevels(
aPointAtCaret.GetContainerAsContent(), aPointAtCaret.Offset(), true);
aPointAtCaret.ContainerAsContent(), aPointAtCaret.Offset(), true);
mozilla::intl::BidiEmbeddingLevel levelBefore = levels.mLevelBefore;
mozilla::intl::BidiEmbeddingLevel levelAfter = levels.mLevelAfter;

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

@ -195,12 +195,12 @@ class EditorDOMPointBase final {
/**
* GetContainer() returns the container node at the point.
* GetContainerAs*() returns the container node as specific type.
* GetContainerAs() returns the container node as specific type.
*/
nsINode* GetContainer() const { return mParent; }
nsIContent* GetContainerAsContent() const {
return nsIContent::FromNodeOrNull(mParent);
template <typename ContentNodeType>
ContentNodeType* GetContainerAs() const {
return ContentNodeType::FromNodeOrNull(mParent);
}
MOZ_NEVER_INLINE_DEBUG nsIContent* ContainerAsContent() const {
@ -209,24 +209,12 @@ class EditorDOMPointBase final {
return mParent->AsContent();
}
dom::Element* GetContainerAsElement() const {
return dom::Element::FromNodeOrNull(mParent);
}
MOZ_NEVER_INLINE_DEBUG dom::Element* ContainerAsElement() const {
MOZ_ASSERT(mParent);
MOZ_ASSERT(mParent->IsElement());
return mParent->AsElement();
}
nsStyledElement* GetContainerAsStyledElement() const {
return nsStyledElement::FromNodeOrNull(mParent);
}
dom::Text* GetContainerAsText() const {
return dom::Text::FromNodeOrNull(mParent);
}
MOZ_NEVER_INLINE_DEBUG dom::Text* ContainerAsText() const {
MOZ_ASSERT(mParent);
MOZ_ASSERT(IsInTextNode());
@ -239,13 +227,9 @@ class EditorDOMPointBase final {
nsINode* GetContainerParent() const {
return mParent ? mParent->GetParent() : nullptr;
}
nsIContent* GetContainerParentAsContent() const {
return nsIContent::FromNodeOrNull(GetContainerParent());
}
dom::Element* GetContainerParentAsElement() const {
return dom::Element::FromNodeOrNull(GetContainerParent());
template <typename ContentNodeType>
ContentNodeType* GetContainerParentAs() const {
return ContentNodeType::FromNodeOrNull(GetContainerParent());
}
dom::Element* GetContainerOrContainerParentElement() const {
@ -253,7 +237,7 @@ class EditorDOMPointBase final {
return nullptr;
}
return mParent->IsElement() ? ContainerAsElement()
: GetContainerParentAsElement();
: GetContainerParentAs<dom::Element>();
}
/**

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

@ -493,7 +493,7 @@ class MOZ_STACK_CLASS SplitNodeResult final {
if (mGivenSplitPoint.IsSet()) {
// Different from previous/next content, if the creator didn't split a
// node, the container of the split point is the original node.
return mGivenSplitPoint.GetContainerAsContent();
return mGivenSplitPoint.GetContainerAs<nsIContent>();
}
if (mDirection == SplitNodeDirection::LeftNodeIsNewOne) {
return mNextNode ? mNextNode : mPreviousNode;

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

@ -1057,7 +1057,7 @@ EditActionResult HTMLEditor::HandleInsertText(
while (!HTMLEditUtils::CanNodeContain(*pointToInsert.GetContainer(),
*nsGkAtoms::textTagName)) {
if (NS_WARN_IF(pointToInsert.GetContainer() == editingHost) ||
NS_WARN_IF(!pointToInsert.GetContainerParentAsContent())) {
NS_WARN_IF(!pointToInsert.GetContainerParentAs<nsIContent>())) {
NS_WARNING("Selection start point couldn't have text nodes");
return EditActionHandled(NS_ERROR_FAILURE);
}
@ -2253,7 +2253,7 @@ HTMLEditor::HandleInsertParagraphInMailCiteElement(
forwardScanFromPointToSplitResult.PointAfterContent<EditorDOMPoint>();
}
if (NS_WARN_IF(!pointToSplit.GetContainerAsContent())) {
if (NS_WARN_IF(!pointToSplit.IsInContentNode())) {
return SplitNodeResult(NS_ERROR_FAILURE);
}
@ -2905,7 +2905,7 @@ nsresult HTMLEditor::InsertBRElementIfHardLineIsEmptyAndEndsWithBlockBoundary(
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(aPointToInsert.IsSet());
if (!aPointToInsert.GetContainerAsContent()) {
if (!aPointToInsert.IsInContentNode()) {
return NS_OK;
}
@ -3438,7 +3438,7 @@ EditActionResult HTMLEditor::ConvertContentAroundRangesToList(
// If we've not met a list element, set current list element to the
// parent of current list item element.
if (!curList) {
curList = atContent.GetContainerAsElement();
curList = atContent.GetContainerAs<Element>();
NS_WARNING_ASSERTION(
HTMLEditUtils::IsAnyListElement(curList),
"Current list item parent is not a list element");
@ -5811,7 +5811,7 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::CreateStyleForInsertText(
if (pointToInsertTextNode.IsInTextNode()) {
// if we are in a text node, split it
SplitNodeResult splitTextNodeResult = SplitNodeDeepWithTransaction(
MOZ_KnownLive(*pointToInsertTextNode.GetContainerAsText()),
MOZ_KnownLive(*pointToInsertTextNode.ContainerAsText()),
pointToInsertTextNode, SplitAtEdges::eAllowToCreateEmptyContainer);
if (splitTextNodeResult.isErr()) {
NS_WARNING(
@ -5865,7 +5865,7 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::CreateStyleForInsertText(
while (item) {
Result<EditorDOMPoint, nsresult> setStyleResult = SetInlinePropertyOnNode(
MOZ_KnownLive(*pointToPutCaret.GetContainerAsContent()),
MOZ_KnownLive(*pointToPutCaret.ContainerAsContent()),
MOZ_KnownLive(*item->tag), MOZ_KnownLive(item->attr), item->value);
if (MOZ_UNLIKELY(setStyleResult.isErr())) {
NS_WARNING("HTMLEditor::SetInlinePropertyOnNode() failed");
@ -6838,7 +6838,7 @@ HTMLEditor::SplitParentInlineElementsAtRangeEdges(RangeItem& aRangeItem) {
if (pointToPutCaret.IsInContentNode() &&
MOZ_UNLIKELY(
editingHost !=
ComputeEditingHost(*pointToPutCaret.GetContainerAsContent()))) {
ComputeEditingHost(*pointToPutCaret.ContainerAsContent()))) {
NS_WARNING(
"HTMLEditor::SplitNodeDeepWithTransaction(SplitAtEdges::"
"eDoNotCreateEmptyContainer) caused changing editing host");
@ -7167,7 +7167,7 @@ SplitNodeResult HTMLEditor::HandleInsertParagraphInParagraph(
if (aCandidatePointToSplit.IsStartOfContainer()) {
EditorDOMPoint candidatePoint(aCandidatePointToSplit);
for (nsIContent* container =
aCandidatePointToSplit.GetContainerAsContent();
aCandidatePointToSplit.GetContainerAs<nsIContent>();
container && container != &aParentDivOrP;
container = container->GetParent()) {
if (HTMLEditUtils::IsLink(container)) {
@ -7203,7 +7203,7 @@ SplitNodeResult HTMLEditor::HandleInsertParagraphInParagraph(
aCandidatePointToSplit.IsBRElementAtEndOfContainer();
EditorDOMPoint candidatePoint(aCandidatePointToSplit);
for (nsIContent* container =
aCandidatePointToSplit.GetContainerAsContent();
aCandidatePointToSplit.GetContainerAs<nsIContent>();
container && container != &aParentDivOrP;
container = container->GetParent()) {
if (HTMLEditUtils::IsLink(container)) {

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

@ -2825,20 +2825,19 @@ Element* HTMLEditor::GetInclusiveAncestorByTagNameAtSelection(
// If no node supplied, get it from anchor node of current selection
const EditorRawDOMPoint atAnchor(SelectionRef().AnchorRef());
if (NS_WARN_IF(!atAnchor.IsSet()) ||
NS_WARN_IF(!atAnchor.GetContainerAsContent())) {
if (NS_WARN_IF(!atAnchor.IsInContentNode())) {
return nullptr;
}
// Try to get the actual selected node
nsIContent* content = nullptr;
if (atAnchor.GetContainer()->HasChildNodes() &&
atAnchor.GetContainerAsContent()) {
atAnchor.ContainerAsContent()) {
content = atAnchor.GetChild();
}
// Anchor node is probably a text node - just use that
if (!content) {
content = atAnchor.GetContainerAsContent();
content = atAnchor.ContainerAsContent();
if (NS_WARN_IF(!content)) {
return nullptr;
}
@ -4625,7 +4624,7 @@ SplitNodeResult HTMLEditor::SplitNodeDeepWithTransaction(
// if you are after the last <li> or before the first, etc. For now we
// just have some smarts about unnecessarily splitting text nodes, which
// should be universal enough to put straight in this EditorBase routine.
nsIContent* splittingContent = atStartOfRightNode.GetContainerAsContent();
auto* splittingContent = atStartOfRightNode.GetContainerAs<nsIContent>();
if (NS_WARN_IF(!splittingContent)) {
lastResult.IgnoreCaretPointSuggestion();
return SplitNodeResult(NS_ERROR_FAILURE);
@ -4633,7 +4632,7 @@ SplitNodeResult HTMLEditor::SplitNodeDeepWithTransaction(
// If we meet an orphan node before meeting aMostAncestorToSplit, we need
// to stop splitting. This is a bug of the caller.
if (NS_WARN_IF(splittingContent != &aMostAncestorToSplit &&
!atStartOfRightNode.GetContainerParentAsContent())) {
!atStartOfRightNode.GetContainerParentAs<nsIContent>())) {
lastResult.IgnoreCaretPointSuggestion();
return SplitNodeResult(NS_ERROR_FAILURE);
}
@ -4650,7 +4649,7 @@ SplitNodeResult HTMLEditor::SplitNodeDeepWithTransaction(
// If the split point is middle of the node or the node is not a text node
// and we're allowed to create empty element node, split it.
if ((aSplitAtEdges == SplitAtEdges::eAllowToCreateEmptyContainer &&
!atStartOfRightNode.GetContainerAsText()) ||
!atStartOfRightNode.IsInTextNode()) ||
(!atStartOfRightNode.IsStartOfContainer() &&
!atStartOfRightNode.IsEndOfContainer())) {
lastResult = SplitNodeResult::MergeWithDeeperSplitNodeResult(
@ -4761,7 +4760,7 @@ SplitNodeResult HTMLEditor::DoSplitNode(const EditorDOMPoint& aStartOfRightNode,
// the children which are before aStartOfRightNode.
if (!aStartOfRightNode.IsStartOfContainer()) {
// If it's a text node, just shuffle around some text
Text* rightAsText = aStartOfRightNode.GetContainerAsText();
Text* rightAsText = aStartOfRightNode.GetContainerAs<Text>();
Text* leftAsText = aNewNode.GetAsText();
if (rightAsText && leftAsText) {
// Fix right node
@ -5719,7 +5718,7 @@ nsresult HTMLEditor::SetCSSBackgroundColorWithTransaction(
if (startOfRange.GetContainer()->IsHTMLElement(nsGkAtoms::body) &&
selectionIsCollapsed) {
if (RefPtr<nsStyledElement> styledElement =
startOfRange.GetContainerAsStyledElement()) {
startOfRange.GetContainerAs<nsStyledElement>()) {
Result<int32_t, nsresult> result =
mCSSEditUtils->SetCSSEquivalentToHTMLStyleWithTransaction(
*styledElement, nullptr, nsGkAtoms::bgcolor, &aColor);

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

@ -742,8 +742,8 @@ nsresult HTMLEditor::HTMLWithContextInserter::Run(
if (pointToInsert.IsInTextNode()) {
const SplitNodeResult splitNodeResult =
mHTMLEditor.SplitNodeDeepWithTransaction(
MOZ_KnownLive(*pointToInsert.GetContainerAsContent()),
pointToInsert, SplitAtEdges::eAllowToCreateEmptyContainer);
MOZ_KnownLive(*pointToInsert.ContainerAsContent()), pointToInsert,
SplitAtEdges::eAllowToCreateEmptyContainer);
if (splitNodeResult.isErr()) {
NS_WARNING("HTMLEditor::SplitNodeDeepWithTransaction() failed");
return splitNodeResult.unwrapErr();

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

@ -1151,9 +1151,9 @@ EditActionResult HTMLEditor::HandleDeleteSelection(
if (NS_WARN_IF(!atNewStartOfSelection.IsSet())) {
return EditActionHandled(NS_ERROR_FAILURE);
}
if (atNewStartOfSelection.GetContainerAsContent()) {
if (atNewStartOfSelection.IsInContentNode()) {
nsresult rv = DeleteMostAncestorMailCiteElementIfEmpty(
MOZ_KnownLive(*atNewStartOfSelection.GetContainerAsContent()));
MOZ_KnownLive(*atNewStartOfSelection.ContainerAsContent()));
if (NS_FAILED(rv)) {
NS_WARNING(
"HTMLEditor::DeleteMostAncestorMailCiteElementIfEmpty() failed");
@ -1192,10 +1192,10 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDelete(
if (NS_WARN_IF(!editingHost)) {
return NS_ERROR_FAILURE;
}
if (startPoint.GetContainerAsContent()) {
if (startPoint.IsInContentNode()) {
AutoEmptyBlockAncestorDeleter deleter;
if (deleter.ScanEmptyBlockInclusiveAncestor(
aHTMLEditor, *startPoint.GetContainerAsContent())) {
aHTMLEditor, *startPoint.ContainerAsContent())) {
nsresult rv = deleter.ComputeTargetRanges(
aHTMLEditor, aDirectionAndAmount, *editingHost, aRangesToDelete);
NS_WARNING_ASSERTION(
@ -1444,13 +1444,13 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::Run(
}
// If we are inside an empty block, delete it.
if (startPoint.GetContainerAsContent()) {
if (startPoint.IsInContentNode()) {
#ifdef DEBUG
nsMutationGuard debugMutation;
#endif // #ifdef DEBUG
AutoEmptyBlockAncestorDeleter deleter;
if (deleter.ScanEmptyBlockInclusiveAncestor(
aHTMLEditor, *startPoint.GetContainerAsContent())) {
aHTMLEditor, *startPoint.ContainerAsContent())) {
EditActionResult result = deleter.Run(aHTMLEditor, aDirectionAndAmount);
if (result.Failed() || result.Handled()) {
NS_WARNING_ASSERTION(result.Succeeded(),
@ -2078,7 +2078,7 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::
MOZ_ASSERT(aPointToDelete.IsSet());
MOZ_ASSERT(aPointToDelete.IsInTextNode());
OwningNonNull<Text> visibleTextNode = *aPointToDelete.GetContainerAsText();
OwningNonNull<Text> visibleTextNode = *aPointToDelete.ContainerAsText();
EditorDOMPoint startToDelete, endToDelete;
if (aDirectionAndAmount == nsIEditor::ePrevious) {
if (aPointToDelete.IsStartOfContainer()) {
@ -2467,12 +2467,12 @@ bool HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
aOtherBlockElement, {LeafNodeType::OnlyEditableLeafNode},
&aOtherBlockElement);
mLeftContent = mLeafContentInOtherBlock;
mRightContent = aCaretPoint.GetContainerAsContent();
mRightContent = aCaretPoint.GetContainerAs<nsIContent>();
} else {
mLeafContentInOtherBlock = HTMLEditUtils::GetFirstLeafContent(
aOtherBlockElement, {LeafNodeType::OnlyEditableLeafNode},
&aOtherBlockElement);
mLeftContent = aCaretPoint.GetContainerAsContent();
mLeftContent = aCaretPoint.GetContainerAs<nsIContent>();
mRightContent = mLeafContentInOtherBlock;
}
@ -2818,12 +2818,12 @@ bool HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
mLeftContent = HTMLEditUtils::GetPreviousContent(
aCurrentBlockElement, {WalkTreeOption::IgnoreNonEditableNode},
editingHost);
mRightContent = aCaretPoint.GetContainerAsContent();
mRightContent = aCaretPoint.GetContainerAs<nsIContent>();
} else {
mRightContent = HTMLEditUtils::GetNextContent(
aCurrentBlockElement, {WalkTreeOption::IgnoreNonEditableNode},
editingHost);
mLeftContent = aCaretPoint.GetContainerAsContent();
mLeftContent = aCaretPoint.GetContainerAs<nsIContent>();
}
// Nothing to join
@ -3534,7 +3534,7 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
EditorDOMPoint rangeEnd(aRange.EndRef());
if (rangeStart.IsInTextNode() && !rangeStart.IsEndOfContainer()) {
// Delete to last character
OwningNonNull<Text> textNode = *rangeStart.GetContainerAsText();
OwningNonNull<Text> textNode = *rangeStart.ContainerAsText();
nsresult rv = aHTMLEditor.DeleteTextWithTransaction(
textNode, rangeStart.Offset(),
rangeStart.GetContainer()->Length() - rangeStart.Offset());
@ -3548,7 +3548,7 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
}
if (rangeEnd.IsInTextNode() && !rangeEnd.IsStartOfContainer()) {
// Delete to first character
OwningNonNull<Text> textNode = *rangeEnd.GetContainerAsText();
OwningNonNull<Text> textNode = *rangeEnd.ContainerAsText();
nsresult rv =
aHTMLEditor.DeleteTextWithTransaction(textNode, 0, rangeEnd.Offset());
if (NS_WARN_IF(aHTMLEditor.Destroyed())) {
@ -4740,7 +4740,7 @@ Result<bool, nsresult> HTMLEditor::CanMoveOrDeleteSomethingInHardLine(
}
if (startPoint.GetContainer() != commonAncestor) {
while (true) {
EditorRawDOMPoint pointInParent(startPoint.GetContainerAsContent());
EditorRawDOMPoint pointInParent(startPoint.GetContainerAs<nsIContent>());
if (NS_WARN_IF(!pointInParent.IsInContentNode())) {
return Err(NS_ERROR_FAILURE);
}
@ -4755,7 +4755,7 @@ Result<bool, nsresult> HTMLEditor::CanMoveOrDeleteSomethingInHardLine(
}
if (endPoint.GetContainer() != commonAncestor) {
while (true) {
EditorRawDOMPoint pointInParent(endPoint.GetContainerAsContent());
EditorRawDOMPoint pointInParent(endPoint.GetContainerAs<nsIContent>());
if (NS_WARN_IF(!pointInParent.IsInContentNode())) {
return Err(NS_ERROR_FAILURE);
}

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

@ -266,7 +266,7 @@ AlignStateAtSelection::AlignStateAtSelection(HTMLEditor& aHTMLEditor,
// If selection is collapsed or in a text node, take the container.
if (aHTMLEditor.SelectionRef().IsCollapsed() ||
atStartOfSelection.IsInTextNode()) {
editTargetContent = atStartOfSelection.GetContainerAsContent();
editTargetContent = atStartOfSelection.GetContainerAs<nsIContent>();
if (NS_WARN_IF(!editTargetContent)) {
aRv.Throw(NS_ERROR_FAILURE);
return;
@ -513,16 +513,11 @@ ParagraphStateAtSelection::ParagraphStateAtSelection(HTMLEditor& aHTMLEditor,
if (arrayOfContents.IsEmpty()) {
const auto atCaret =
aHTMLEditor.GetFirstSelectionStartPoint<EditorRawDOMPoint>();
if (NS_WARN_IF(!atCaret.IsSet())) {
if (NS_WARN_IF(!atCaret.IsInContentNode())) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
nsIContent* content = atCaret.GetContainerAsContent();
if (NS_WARN_IF(!content)) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
arrayOfContents.AppendElement(*content);
arrayOfContents.AppendElement(*atCaret.ContainerAsContent());
}
dom::Element* bodyOrDocumentElement = aHTMLEditor.GetRoot();

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

@ -274,7 +274,7 @@ nsresult HTMLEditor::SetInlinePropertyInternal(
if (startOfRange.GetContainer() == endOfRange.GetContainer() &&
startOfRange.IsInTextNode()) {
nsresult rv = SetInlinePropertyOnTextNode(
MOZ_KnownLive(*startOfRange.GetContainerAsText()),
MOZ_KnownLive(*startOfRange.ContainerAsText()),
startOfRange.Offset(), endOfRange.Offset(), aProperty, aAttribute,
aAttributeValue);
if (NS_FAILED(rv)) {
@ -308,7 +308,7 @@ nsresult HTMLEditor::SetInlinePropertyInternal(
EditorUtils::IsEditableContent(*startOfRange.ContainerAsText(),
EditorType::HTML)) {
nsresult rv = SetInlinePropertyOnTextNode(
MOZ_KnownLive(*startOfRange.GetContainerAsText()),
MOZ_KnownLive(*startOfRange.ContainerAsText()),
startOfRange.Offset(), startOfRange.GetContainer()->Length(),
aProperty, aAttribute, aAttributeValue);
if (NS_FAILED(rv)) {
@ -334,10 +334,10 @@ nsresult HTMLEditor::SetInlinePropertyInternal(
// Finally, if end node is a text node, apply new style to a part of it.
if (endOfRange.IsInTextNode() &&
EditorUtils::IsEditableContent(*endOfRange.GetContainerAsText(),
EditorUtils::IsEditableContent(*endOfRange.ContainerAsText(),
EditorType::HTML)) {
nsresult rv = SetInlinePropertyOnTextNode(
MOZ_KnownLive(*endOfRange.GetContainerAsText()), 0,
MOZ_KnownLive(*endOfRange.ContainerAsText()), 0,
endOfRange.Offset(), aProperty, aAttribute, aAttributeValue);
if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::SetInlinePropertyOnTextNode() failed");
@ -979,8 +979,7 @@ SplitRangeOffResult HTMLEditor::SplitAncestorStyledInlineElementsAtRangeEdges(
SplitNodeResult HTMLEditor::SplitAncestorStyledInlineElementsAt(
const EditorDOMPoint& aPointToSplit, nsAtom* aProperty,
nsAtom* aAttribute) {
if (NS_WARN_IF(!aPointToSplit.IsSet()) ||
NS_WARN_IF(!aPointToSplit.GetContainerAsContent())) {
if (NS_WARN_IF(!aPointToSplit.IsInContentNode())) {
return SplitNodeResult(NS_ERROR_INVALID_ARG);
}
@ -1175,7 +1174,7 @@ EditResult HTMLEditor::ClearStyleAt(const EditorDOMPoint& aPoint,
*atStartOfNextNode.ContainerAsContent())) {
// If it's a `<br>` element, let's move it into new node later.
brElement = HTMLBRElement::FromNode(atStartOfNextNode.GetContainer());
if (!atStartOfNextNode.GetContainerParentAsContent()) {
if (!atStartOfNextNode.GetContainerParentAs<nsIContent>()) {
NS_WARNING("atStartOfNextNode was in an orphan node");
return EditResult(NS_ERROR_FAILURE);
}
@ -1600,7 +1599,7 @@ nsresult HTMLEditor::PromoteRangeIfStartsOrEndsInNamedAnchor(nsRange& aRange) {
break;
}
if (!newRangeStart.GetContainerAsContent()) {
if (!newRangeStart.IsInContentNode()) {
NS_WARNING(
"HTMLEditor::PromoteRangeIfStartsOrEndsInNamedAnchor() reached root "
"element from start container");
@ -1620,7 +1619,7 @@ nsresult HTMLEditor::PromoteRangeIfStartsOrEndsInNamedAnchor(nsRange& aRange) {
break;
}
if (!newRangeEnd.GetContainerAsContent()) {
if (!newRangeEnd.IsInContentNode()) {
NS_WARNING(
"HTMLEditor::PromoteRangeIfStartsOrEndsInNamedAnchor() reached root "
"element from end container");
@ -1653,7 +1652,7 @@ nsresult HTMLEditor::PromoteInlineRange(nsRange& aRange) {
}
newRangeStart.Set(content);
}
if (!newRangeStart.GetContainerAsContent()) {
if (!newRangeStart.IsInContentNode()) {
NS_WARNING(
"HTMLEditor::PromoteInlineRange() reached root element from start "
"container");
@ -1671,7 +1670,7 @@ nsresult HTMLEditor::PromoteInlineRange(nsRange& aRange) {
}
newRangeEnd.SetAfter(content);
}
if (!newRangeEnd.GetContainerAsContent()) {
if (!newRangeEnd.IsInContentNode()) {
NS_WARNING(
"HTMLEditor::PromoteInlineRange() reached root element from end "
"container");

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

@ -42,7 +42,7 @@ SplitNodeTransaction::SplitNodeTransaction(
HTMLEditor& aHTMLEditor,
const EditorDOMPointBase<PT, CT>& aStartOfRightContent)
: mHTMLEditor(&aHTMLEditor),
mSplitContent(aStartOfRightContent.GetContainerAsContent()),
mSplitContent(aStartOfRightContent.template GetContainerAs<nsIContent>()),
mSplitOffset(aStartOfRightContent.Offset()) {
// printf("SplitNodeTransaction size: %zu\n", sizeof(SplitNodeTransaction));
static_assert(sizeof(SplitNodeTransaction) <= 64,

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

@ -238,13 +238,13 @@ EditActionResult WhiteSpaceVisibilityKeeper::
// XXX And afterRightBlockChild.GetContainerAsElement() always returns
// an element pointer so that probably here should not use
// accessors of EditorDOMPoint, should use DOM API directly instead.
if (afterRightBlockChild.GetContainerAsElement()) {
rightBlockElement = *afterRightBlockChild.GetContainerAsElement();
if (afterRightBlockChild.GetContainerAs<Element>()) {
rightBlockElement = *afterRightBlockChild.ContainerAsElement();
} else if (NS_WARN_IF(
!afterRightBlockChild.GetContainerParentAsElement())) {
!afterRightBlockChild.GetContainerParentAs<Element>())) {
return EditActionResult(NS_ERROR_UNEXPECTED);
} else {
rightBlockElement = *afterRightBlockChild.GetContainerParentAsElement();
rightBlockElement = *afterRightBlockChild.GetContainerParentAs<Element>();
}
}
@ -1466,8 +1466,7 @@ nsresult WhiteSpaceVisibilityKeeper::DeleteContentNodeAndJoinTextNodesAroundIt(
}
EditorDOMPoint atFirstChildOfRightNode;
rv = aHTMLEditor.JoinNearestEditableNodesWithTransaction(
*previousEditableSibling,
MOZ_KnownLive(*aCaretPoint.GetContainerAsText()),
*previousEditableSibling, MOZ_KnownLive(*aCaretPoint.ContainerAsText()),
&atFirstChildOfRightNode);
if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::JoinNearestEditableNodesWithTransaction() failed");
@ -3210,7 +3209,7 @@ nsresult WhiteSpaceVisibilityKeeper::NormalizeVisibleWhiteSpacesAt(
!(followedByVisibleContent || followedByBRElement) ||
EditorUtils::IsWhiteSpacePreformatted(
*atPreviousCharOfPreviousCharOfEndOfVisibleWhiteSpaces
.GetContainerAsText())) {
.ContainerAsText())) {
return NS_OK;
}

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

@ -70,7 +70,7 @@ class MOZ_STACK_CLASS WSScanResult final {
}
MOZ_NEVER_INLINE_DEBUG WSScanResult(const EditorDOMPoint& aPoint,
WSType aReason)
: mContent(aPoint.GetContainerAsContent()),
: mContent(aPoint.GetContainerAs<nsIContent>()),
mOffset(Some(aPoint.Offset())),
mReason(aReason) {
AssertIfInvalidData();

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

@ -344,7 +344,7 @@ nsresult TextServicesDocument::ExpandRangeToWordBoundaries(
"TextServicesDocument::OffsetEntryArray::FindWordRange() failed");
return maybeWordRange.unwrapErr();
}
rngStartNode = maybeWordRange.inspect().StartRef().GetContainerAsText();
rngStartNode = maybeWordRange.inspect().StartRef().GetContainerAs<Text>();
rngStartOffset = maybeWordRange.inspect().StartRef().Offset();
// Grab all the text in the block containing our
@ -374,10 +374,11 @@ nsresult TextServicesDocument::ExpandRangeToWordBoundaries(
// rngEndNode and rngEndOffset if it isn't already at the start of the
// word and isn't equivalent to rngStartNode and rngStartOffset.
if (rngEndNode != maybeWordRange.inspect().StartRef().GetContainerAsText() ||
if (rngEndNode !=
maybeWordRange.inspect().StartRef().GetContainerAs<Text>() ||
rngEndOffset != maybeWordRange.inspect().StartRef().Offset() ||
(rngEndNode == rngStartNode && rngEndOffset == rngStartOffset)) {
rngEndNode = maybeWordRange.inspect().EndRef().GetContainerAsText();
rngEndNode = maybeWordRange.inspect().EndRef().GetContainerAs<Text>();
rngEndOffset = maybeWordRange.inspect().EndRef().Offset();
}