зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1618089 - part 1: Redsign `EditorDOMPointBase` with template methods r=m_kato
Some methods of `EditorDOMPointBase` assumes the container node type is `nsINode`. However, it's not good for reuse. Therefore, this patch makes most methods of them be template methods. Differential Revision: https://phabricator.services.mozilla.com/D64331 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
8fcc291b3c
Коммит
b93a2782a0
|
@ -77,7 +77,7 @@ class EditorDOMPointBase final {
|
|||
: mParent(nullptr), mChild(nullptr), mIsChildInitialized(false) {}
|
||||
|
||||
template <typename ContainerType>
|
||||
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 ContainerType, template <typename> typename StrongPtr>
|
||||
EditorDOMPointBase(const StrongPtr<ContainerType>& 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 <typename ContainerType>
|
||||
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 ContainerType, template <typename> typename StrongPtr>
|
||||
void Set(const StrongPtr<ContainerType>& 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 <typename ContainerType>
|
||||
MOZ_NEVER_INLINE_DEBUG void SetToEndOf(const ContainerType* aContainer) {
|
||||
MOZ_ASSERT(aContainer);
|
||||
mParent = const_cast<nsINode*>(aContainer);
|
||||
mParent = const_cast<ContainerType*>(aContainer);
|
||||
mChild = nullptr;
|
||||
mOffset = mozilla::Some(mParent->Length());
|
||||
mIsChildInitialized = true;
|
||||
}
|
||||
static SelfType AtEndOf(const nsINode& aContainer) {
|
||||
template <typename ContainerType, template <typename> typename StrongPtr>
|
||||
MOZ_NEVER_INLINE_DEBUG void SetToEndOf(
|
||||
const StrongPtr<ContainerType>& aContainer) {
|
||||
SetToEndOf(aContainer.get());
|
||||
}
|
||||
template <typename ContainerType>
|
||||
MOZ_NEVER_INLINE_DEBUG static SelfType AtEndOf(
|
||||
const ContainerType& aContainer) {
|
||||
SelfType point;
|
||||
point.SetToEndOf(&aContainer);
|
||||
return point;
|
||||
}
|
||||
template <typename ContainerType, template <typename> typename StrongPtr>
|
||||
MOZ_NEVER_INLINE_DEBUG static SelfType AtEndOf(
|
||||
const StrongPtr<ContainerType>& 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 <typename ContainerType>
|
||||
static SelfType After(const ContainerType& aContainer) {
|
||||
SelfType point;
|
||||
point.SetAfter(&aContainer);
|
||||
return point;
|
||||
}
|
||||
template <typename ContainerType, template <typename> typename StrongPtr>
|
||||
MOZ_NEVER_INLINE_DEBUG static SelfType After(
|
||||
const StrongPtr<ContainerType>& aContainer) {
|
||||
MOZ_ASSERT(aContainer.get());
|
||||
return After(*aContainer.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear() makes the instance not point anywhere.
|
||||
|
|
|
@ -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<Element> 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<Element> 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;
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче