diff --git a/editor/libeditor/EditorDOMPoint.h b/editor/libeditor/EditorDOMPoint.h index 2330c52eb93f..b3b8f8e35282 100644 --- a/editor/libeditor/EditorDOMPoint.h +++ b/editor/libeditor/EditorDOMPoint.h @@ -77,7 +77,7 @@ class EditorDOMPointBase final { : mParent(nullptr), mChild(nullptr), mIsChildInitialized(false) {} template - EditorDOMPointBase(ContainerType aContainer, int32_t aOffset) + EditorDOMPointBase(ContainerType* aContainer, int32_t aOffset) : mParent(aContainer), mChild(nullptr), mOffset(mozilla::Some(aOffset)), @@ -90,6 +90,11 @@ class EditorDOMPointBase final { } } + template typename StrongPtr> + EditorDOMPointBase(const StrongPtr& aContainer, + int32_t aOffset) + : EditorDOMPointBase(aContainer.get(), aOffset) {} + /** * Different from RangeBoundary, aPointedNode should be a child node * which you want to refer. @@ -319,7 +324,8 @@ class EditorDOMPointBase final { * If it's set with aOffset, mChild is invalidated. If it's set with aChild, * mOffset may be invalidated. */ - void Set(nsINode* aContainer, int32_t aOffset) { + template + void Set(ContainerType* aContainer, int32_t aOffset) { mParent = aContainer; mChild = nullptr; mOffset = mozilla::Some(aOffset); @@ -327,6 +333,10 @@ class EditorDOMPointBase final { NS_ASSERTION(!mParent || mOffset.value() <= mParent->Length(), "The offset is out of bounds"); } + template typename StrongPtr> + void Set(const StrongPtr& aContainer, int32_t aOffset) { + Set(aContainer.get(), aOffset); + } void Set(const nsINode* aChild) { MOZ_ASSERT(aChild); if (NS_WARN_IF(!aChild->IsContent())) { @@ -343,18 +353,32 @@ class EditorDOMPointBase final { * SetToEndOf() sets this to the end of aContainer. Then, mChild is always * nullptr but marked as initialized and mOffset is always set. */ - void SetToEndOf(const nsINode* aContainer) { + template + MOZ_NEVER_INLINE_DEBUG void SetToEndOf(const ContainerType* aContainer) { MOZ_ASSERT(aContainer); - mParent = const_cast(aContainer); + mParent = const_cast(aContainer); mChild = nullptr; mOffset = mozilla::Some(mParent->Length()); mIsChildInitialized = true; } - static SelfType AtEndOf(const nsINode& aContainer) { + template typename StrongPtr> + MOZ_NEVER_INLINE_DEBUG void SetToEndOf( + const StrongPtr& aContainer) { + SetToEndOf(aContainer.get()); + } + template + MOZ_NEVER_INLINE_DEBUG static SelfType AtEndOf( + const ContainerType& aContainer) { SelfType point; point.SetToEndOf(&aContainer); return point; } + template typename StrongPtr> + MOZ_NEVER_INLINE_DEBUG static SelfType AtEndOf( + const StrongPtr& aContainer) { + MOZ_ASSERT(aContainer.get()); + return AtEndOf(*aContainer.get()); + } /** * SetAfter() sets mChild to next sibling of aChild. @@ -373,11 +397,18 @@ class EditorDOMPointBase final { } SetToEndOf(parentNode); } - static SelfType After(const nsINode& aContainer) { + template + static SelfType After(const ContainerType& aContainer) { SelfType point; point.SetAfter(&aContainer); return point; } + template typename StrongPtr> + MOZ_NEVER_INLINE_DEBUG static SelfType After( + const StrongPtr& aContainer) { + MOZ_ASSERT(aContainer.get()); + return After(*aContainer.get()); + } /** * Clear() makes the instance not point anywhere. diff --git a/editor/libeditor/HTMLEditSubActionHandler.cpp b/editor/libeditor/HTMLEditSubActionHandler.cpp index 195556a1566a..2fad6d77b5e9 100644 --- a/editor/libeditor/HTMLEditSubActionHandler.cpp +++ b/editor/libeditor/HTMLEditSubActionHandler.cpp @@ -3525,8 +3525,7 @@ EditActionResult HTMLEditor::TryToJoinBlocksWithTransaction( advanced, "Failed to advance offset to after child of rightBlock, " "leftBlock is a descendant of the child"); - nsresult rv = - WSRunObject::Scrub(*this, EditorDOMPoint::AtEndOf(*leftBlock)); + nsresult rv = WSRunObject::Scrub(*this, EditorDOMPoint::AtEndOf(leftBlock)); if (NS_WARN_IF(NS_FAILED(rv))) { return EditActionIgnored(rv); } @@ -3552,7 +3551,7 @@ EditActionResult HTMLEditor::TryToJoinBlocksWithTransaction( // Do br adjustment. RefPtr invisibleBRElement = - GetInvisibleBRElementAt(EditorDOMPoint::AtEndOf(*leftBlock)); + GetInvisibleBRElementAt(EditorDOMPoint::AtEndOf(leftBlock)); EditActionResult ret(NS_OK); if (NS_WARN_IF(mergeListElements)) { // Since 2002, here was the following comment: @@ -3767,7 +3766,7 @@ EditActionResult HTMLEditor::TryToJoinBlocksWithTransaction( } // Do br adjustment. RefPtr invisibleBRElement = - GetInvisibleBRElementAt(EditorDOMPoint::AtEndOf(*leftBlock)); + GetInvisibleBRElementAt(EditorDOMPoint::AtEndOf(leftBlock)); EditActionResult ret(NS_OK); if (mergeListElements || leftBlock->NodeInfo()->NameAtom() == rightBlock->NodeInfo()->NameAtom()) { @@ -10760,7 +10759,7 @@ nsresult HTMLEditor::MoveSelectedContentsToDivElementToMakeItAbsolutePosition( } createdListElement = CreateNodeWithTransaction( MOZ_KnownLive(*ULOrOLOrDLTagName), - EditorDOMPoint::AtEndOf(*targetDivElement)); + EditorDOMPoint::AtEndOf(targetDivElement)); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } @@ -10824,7 +10823,7 @@ nsresult HTMLEditor::MoveSelectedContentsToDivElementToMakeItAbsolutePosition( // XXX So, createdListElement may be set to a non-list element. createdListElement = CreateNodeWithTransaction( MOZ_KnownLive(*containerName), - EditorDOMPoint::AtEndOf(*targetDivElement)); + EditorDOMPoint::AtEndOf(targetDivElement)); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } diff --git a/editor/libeditor/HTMLEditorDataTransfer.cpp b/editor/libeditor/HTMLEditorDataTransfer.cpp index de92ec6a3043..00b19daff33c 100644 --- a/editor/libeditor/HTMLEditorDataTransfer.cpp +++ b/editor/libeditor/HTMLEditorDataTransfer.cpp @@ -250,7 +250,7 @@ nsresult HTMLEditor::DoInsertHTMLWithContext( : EditorRawDOMPoint(fragmentAsNode, 0); EditorRawDOMPoint streamEndPoint = streamStartParent ? EditorRawDOMPoint(streamEndParent, streamEndOffset) - : EditorRawDOMPoint::AtEndOf(*fragmentAsNode); + : EditorRawDOMPoint::AtEndOf(fragmentAsNode); HTMLEditor::CollectTopMostChildNodesCompletelyInRange( EditorRawDOMPoint(streamStartParent, streamStartOffset), EditorRawDOMPoint(streamEndParent, streamEndOffset), diff --git a/editor/libeditor/WSRunObject.h b/editor/libeditor/WSRunObject.h index 5c3e286b6d95..65107318b8dd 100644 --- a/editor/libeditor/WSRunObject.h +++ b/editor/libeditor/WSRunObject.h @@ -259,11 +259,11 @@ class MOZ_STACK_CLASS WSScanResult final { */ MOZ_NEVER_INLINE_DEBUG EditorDOMPoint PointAfterContent() const { MOZ_ASSERT(mContent); - return mContent ? EditorDOMPoint::After(*mContent) : EditorDOMPoint(); + return mContent ? EditorDOMPoint::After(mContent) : EditorDOMPoint(); } MOZ_NEVER_INLINE_DEBUG EditorRawDOMPoint RawPointAfterContent() const { MOZ_ASSERT(mContent); - return mContent ? EditorRawDOMPoint::After(*mContent) : EditorRawDOMPoint(); + return mContent ? EditorRawDOMPoint::After(mContent) : EditorRawDOMPoint(); } /**