Bug 1627175 - part 37: Get rid of editor type argument from `EditorBase::GetNextContent()` and `EditorBase::GetPreviousContent()` r=m_kato

Differential Revision: https://phabricator.services.mozilla.com/D113241
This commit is contained in:
Masayuki Nakano 2021-04-27 11:17:43 +00:00
Родитель 267025f6e5
Коммит 7da0836039
6 изменённых файлов: 65 добавлений и 73 удалений

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

@ -2805,20 +2805,19 @@ nsresult EditorBase::DeleteTextWithTransaction(Text& aTextNode,
// static
nsIContent* EditorBase::GetPreviousContent(
const nsINode& aNode, const WalkTreeOptions& aOptions,
EditorType aEditorType, const Element* aAncestorLimiter /* = nullptr */) {
const Element* aAncestorLimiter /* = nullptr */) {
if (&aNode == aAncestorLimiter ||
(aAncestorLimiter && !aNode.IsInclusiveDescendantOf(aAncestorLimiter))) {
return nullptr;
}
return EditorBase::GetAdjacentContent(aNode, WalkTreeDirection::Backward,
aOptions, aEditorType,
aAncestorLimiter);
aOptions, aAncestorLimiter);
}
// static
nsIContent* EditorBase::GetPreviousContent(
const EditorRawDOMPoint& aPoint, const WalkTreeOptions& aOptions,
EditorType aEditorType, const Element* aAncestorLimiter /* = nullptr */) {
const Element* aAncestorLimiter /* = nullptr */) {
MOZ_ASSERT(aPoint.IsSetAndValid());
NS_WARNING_ASSERTION(
!aPoint.IsInDataNode() || aPoint.IsInTextNode(),
@ -2835,13 +2834,13 @@ nsIContent* EditorBase::GetPreviousContent(
return nullptr;
}
return EditorBase::GetPreviousContent(*aPoint.GetContainer(), aOptions,
aEditorType, aAncestorLimiter);
aAncestorLimiter);
}
// else look before the child at 'aOffset'
if (aPoint.GetChild()) {
return EditorBase::GetPreviousContent(*aPoint.GetChild(), aOptions,
aEditorType, aAncestorLimiter);
aAncestorLimiter);
}
// unless there isn't one, in which case we are at the end of the node
@ -2856,34 +2855,33 @@ nsIContent* EditorBase::GetPreviousContent(
}
if ((!aOptions.contains(WalkTreeOption::IgnoreNonEditableNode) ||
EditorUtils::IsEditableContent(*lastLeafContent, aEditorType)) &&
EditorUtils::IsEditableContent(*lastLeafContent, EditorType::HTML)) &&
(!aOptions.contains(WalkTreeOption::IgnoreDataNodeExceptText) ||
EditorUtils::IsElementOrText(*lastLeafContent))) {
return lastLeafContent;
}
// restart the search from the non-editable node we just found
return EditorBase::GetPreviousContent(*lastLeafContent, aOptions, aEditorType,
return EditorBase::GetPreviousContent(*lastLeafContent, aOptions,
aAncestorLimiter);
}
// static
nsIContent* EditorBase::GetNextContent(
const nsINode& aNode, const WalkTreeOptions& aOptions,
EditorType aEditorType, const Element* aAncestorLimiter /* = nullptr */) {
const Element* aAncestorLimiter /* = nullptr */) {
if (&aNode == aAncestorLimiter ||
(aAncestorLimiter && !aNode.IsInclusiveDescendantOf(aAncestorLimiter))) {
return nullptr;
}
return EditorBase::GetAdjacentContent(aNode, WalkTreeDirection::Forward,
aOptions, aEditorType,
aAncestorLimiter);
aOptions, aAncestorLimiter);
}
// static
nsIContent* EditorBase::GetNextContent(
const EditorRawDOMPoint& aPoint, const WalkTreeOptions& aOptions,
EditorType aEditorType, const Element* aAncestorLimiter /* = nullptr */) {
const Element* aAncestorLimiter /* = nullptr */) {
MOZ_ASSERT(aPoint.IsSetAndValid());
NS_WARNING_ASSERTION(
!aPoint.IsInDataNode() || aPoint.IsInTextNode(),
@ -2924,14 +2922,14 @@ nsIContent* EditorBase::GetNextContent(
}
if ((!aOptions.contains(WalkTreeOption::IgnoreNonEditableNode) ||
EditorUtils::IsEditableContent(*firstLeafContent, aEditorType)) &&
EditorUtils::IsEditableContent(*firstLeafContent, EditorType::HTML)) &&
(!aOptions.contains(WalkTreeOption::IgnoreDataNodeExceptText) ||
EditorUtils::IsElementOrText(*firstLeafContent))) {
return firstLeafContent;
}
// restart the search from the non-editable node we just found
return EditorBase::GetNextContent(*firstLeafContent, aOptions, aEditorType,
return EditorBase::GetNextContent(*firstLeafContent, aOptions,
aAncestorLimiter);
}
@ -2945,7 +2943,7 @@ nsIContent* EditorBase::GetNextContent(
}
return EditorBase::GetNextContent(*point.GetContainer(), aOptions,
aEditorType, aAncestorLimiter);
aAncestorLimiter);
}
// static
@ -3003,7 +3001,7 @@ nsIContent* EditorBase::GetAdjacentLeafContent(
// static
nsIContent* EditorBase::GetAdjacentContent(
const nsINode& aNode, WalkTreeDirection aWalkTreeDirection,
const WalkTreeOptions& aOptions, EditorType aEditorType,
const WalkTreeOptions& aOptions,
const Element* aAncestorLimiter /* = nullptr */) {
if (&aNode == aAncestorLimiter) {
// Don't allow traversal above the root node! This helps
@ -3019,15 +3017,14 @@ nsIContent* EditorBase::GetAdjacentContent(
}
if ((!aOptions.contains(WalkTreeOption::IgnoreNonEditableNode) ||
EditorUtils::IsEditableContent(*leafContent, aEditorType)) &&
EditorUtils::IsEditableContent(*leafContent, EditorType::HTML)) &&
(!aOptions.contains(WalkTreeOption::IgnoreDataNodeExceptText) ||
EditorUtils::IsElementOrText(*leafContent))) {
return leafContent;
}
return EditorBase::GetAdjacentContent(*leafContent, aWalkTreeDirection,
aOptions, aEditorType,
aAncestorLimiter);
aOptions, aAncestorLimiter);
}
bool EditorBase::IsRoot(const nsINode* inNode) const {
@ -3514,7 +3511,7 @@ EditorBase::CreateTransactionForCollapsedRange(
// of previous editable content.
nsIContent* previousEditableContent = EditorBase::GetPreviousContent(
*point.GetContainer(), {WalkTreeOption::IgnoreNonEditableNode},
EditorType::HTML, GetEditorRoot());
GetEditorRoot());
if (!previousEditableContent) {
NS_WARNING("There was no editable content before the collapsed range");
return nullptr;
@ -3558,7 +3555,7 @@ EditorBase::CreateTransactionForCollapsedRange(
// next editable content.
nsIContent* nextEditableContent = EditorBase::GetNextContent(
*point.GetContainer(), {WalkTreeOption::IgnoreNonEditableNode},
EditorType::HTML, GetEditorRoot());
GetEditorRoot());
if (!nextEditableContent) {
NS_WARNING("There was no editable content after the collapsed range");
return nullptr;
@ -3621,10 +3618,10 @@ EditorBase::CreateTransactionForCollapsedRange(
aHowToHandleCollapsedRange == HowToHandleCollapsedRange::ExtendBackward
? EditorBase::GetPreviousContent(
point, {WalkTreeOption::IgnoreNonEditableNode},
EditorType::HTML, GetEditorRoot())
GetEditorRoot())
: EditorBase::GetNextContent(
point, {WalkTreeOption::IgnoreNonEditableNode},
EditorType::HTML, GetEditorRoot());
GetEditorRoot());
if (!editableContent) {
NS_WARNING("There was no editable content around the collapsed range");
return nullptr;
@ -3637,10 +3634,10 @@ EditorBase::CreateTransactionForCollapsedRange(
HowToHandleCollapsedRange::ExtendBackward
? EditorBase::GetPreviousContent(
*editableContent, {WalkTreeOption::IgnoreNonEditableNode},
EditorType::HTML, GetEditorRoot())
GetEditorRoot())
: EditorBase::GetNextContent(
*editableContent, {WalkTreeOption::IgnoreNonEditableNode},
EditorType::HTML, GetEditorRoot());
GetEditorRoot());
}
if (!editableContent) {
NS_WARNING(

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

@ -1745,14 +1745,14 @@ class EditorBase : public nsIEditor,
using WalkTreeOptions = EnumSet<WalkTreeOption>;
static nsIContent* GetPreviousContent(
const nsINode& aNode, const WalkTreeOptions& aOptions,
EditorType aEditorType, const Element* aAncestorLimiter = nullptr);
const Element* aAncestorLimiter = nullptr);
/**
* And another version that takes a point in DOM tree rather than a node.
*/
static nsIContent* GetPreviousContent(
const EditorRawDOMPoint& aPoint, const WalkTreeOptions& aOptions,
EditorType aEditorType, const Element* aAncestorLimiter = nullptr);
const Element* aAncestorLimiter = nullptr);
/**
* Get next content node of aNode if there is.
@ -1761,7 +1761,6 @@ class EditorBase : public nsIEditor,
*/
static nsIContent* GetNextContent(const nsINode& aNode,
const WalkTreeOptions& aOptions,
EditorType aEditorType,
const Element* aAncestorLimiter = nullptr);
/**
@ -1789,7 +1788,6 @@ class EditorBase : public nsIEditor,
*/
static nsIContent* GetNextContent(const EditorRawDOMPoint& aPoint,
const WalkTreeOptions& aOptions,
EditorType aEditorType,
const Element* aAncestorLimiter = nullptr);
/**
@ -2166,7 +2164,7 @@ class EditorBase : public nsIEditor,
const Element* aAncestorLimiter = nullptr);
static nsIContent* GetAdjacentContent(
const nsINode& aNode, WalkTreeDirection aWalkTreeDirection,
const WalkTreeOptions& aOptions, EditorType aEditorType,
const WalkTreeOptions& aOptions,
const Element* aAncestorLimiter = nullptr);
virtual nsresult InstallEventListeners();

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

@ -698,7 +698,7 @@ class HTMLEditUtils final {
*leafContent, EditorBase::EditorType::HTML)) {
leafContent = EditorBase::GetNextContent(
*leafContent, {EditorBase::WalkTreeOption::IgnoreNonEditableNode},
EditorBase::EditorType::HTML, &aRootElement);
&aRootElement);
}
MOZ_ASSERT(leafContent != &aRootElement);
return leafContent;

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

@ -5010,10 +5010,10 @@ nsIContent* HTMLEditor::GetPreviousHTMLElementOrTextInternal(
aNode,
{WalkTreeOption::IgnoreDataNodeExceptText,
WalkTreeOption::StopAtBlockBoundary},
EditorType::HTML, editingHost)
editingHost)
: EditorBase::GetPreviousContent(
aNode, {WalkTreeOption::IgnoreDataNodeExceptText},
EditorType::HTML, editingHost);
editingHost);
}
template <typename PT, typename CT>
@ -5028,10 +5028,10 @@ nsIContent* HTMLEditor::GetPreviousHTMLElementOrTextInternal(
aPoint,
{WalkTreeOption::IgnoreDataNodeExceptText,
WalkTreeOption::StopAtBlockBoundary},
EditorType::HTML, editingHost)
editingHost)
: EditorBase::GetPreviousContent(
aPoint, {WalkTreeOption::IgnoreDataNodeExceptText},
EditorType::HTML, editingHost);
editingHost);
}
nsIContent* HTMLEditor::GetPreviousEditableHTMLNodeInternal(
@ -5040,14 +5040,14 @@ nsIContent* HTMLEditor::GetPreviousEditableHTMLNodeInternal(
if (NS_WARN_IF(!editingHost)) {
return nullptr;
}
return aNoBlockCrossing ? EditorBase::GetPreviousContent(
aNode,
{WalkTreeOption::IgnoreNonEditableNode,
WalkTreeOption::StopAtBlockBoundary},
EditorType::HTML, editingHost)
: EditorBase::GetPreviousContent(
aNode, {WalkTreeOption::IgnoreNonEditableNode},
EditorType::HTML, editingHost);
return aNoBlockCrossing
? EditorBase::GetPreviousContent(
aNode,
{WalkTreeOption::IgnoreNonEditableNode,
WalkTreeOption::StopAtBlockBoundary},
editingHost)
: EditorBase::GetPreviousContent(
aNode, {WalkTreeOption::IgnoreNonEditableNode}, editingHost);
}
template <typename PT, typename CT>
@ -5061,10 +5061,10 @@ nsIContent* HTMLEditor::GetPreviousEditableHTMLNodeInternal(
aPoint,
{WalkTreeOption::IgnoreNonEditableNode,
WalkTreeOption::StopAtBlockBoundary},
EditorType::HTML, editingHost)
editingHost)
: EditorBase::GetPreviousContent(
aPoint, {WalkTreeOption::IgnoreNonEditableNode},
EditorType::HTML, editingHost);
editingHost);
}
nsIContent* HTMLEditor::GetNextHTMLElementOrTextInternal(
@ -5078,10 +5078,10 @@ nsIContent* HTMLEditor::GetNextHTMLElementOrTextInternal(
aNode,
{WalkTreeOption::IgnoreDataNodeExceptText,
WalkTreeOption::StopAtBlockBoundary},
EditorType::HTML, editingHost)
editingHost)
: EditorBase::GetNextContent(
aNode, {WalkTreeOption::IgnoreDataNodeExceptText},
EditorType::HTML, editingHost);
editingHost);
}
template <typename PT, typename CT>
@ -5096,10 +5096,10 @@ nsIContent* HTMLEditor::GetNextHTMLElementOrTextInternal(
aPoint,
{WalkTreeOption::IgnoreDataNodeExceptText,
WalkTreeOption::StopAtBlockBoundary},
EditorType::HTML, editingHost)
editingHost)
: EditorBase::GetNextContent(
aPoint, {WalkTreeOption::IgnoreDataNodeExceptText},
EditorType::HTML, editingHost);
editingHost);
}
nsIContent* HTMLEditor::GetNextEditableHTMLNodeInternal(
@ -5108,14 +5108,14 @@ nsIContent* HTMLEditor::GetNextEditableHTMLNodeInternal(
if (NS_WARN_IF(!editingHost)) {
return nullptr;
}
return aNoBlockCrossing ? EditorBase::GetNextContent(
aNode,
{WalkTreeOption::IgnoreNonEditableNode,
WalkTreeOption::StopAtBlockBoundary},
EditorType::HTML, editingHost)
: EditorBase::GetNextContent(
aNode, {WalkTreeOption::IgnoreNonEditableNode},
EditorType::HTML, editingHost);
return aNoBlockCrossing
? EditorBase::GetNextContent(
aNode,
{WalkTreeOption::IgnoreNonEditableNode,
WalkTreeOption::StopAtBlockBoundary},
editingHost)
: EditorBase::GetNextContent(
aNode, {WalkTreeOption::IgnoreNonEditableNode}, editingHost);
}
template <typename PT, typename CT>
@ -5129,10 +5129,10 @@ nsIContent* HTMLEditor::GetNextEditableHTMLNodeInternal(
aPoint,
{WalkTreeOption::IgnoreNonEditableNode,
WalkTreeOption::StopAtBlockBoundary},
EditorType::HTML, editingHost)
editingHost)
: EditorBase::GetNextContent(
aPoint, {WalkTreeOption::IgnoreNonEditableNode},
EditorType::HTML, editingHost);
editingHost);
}
bool HTMLEditor::IsFirstEditableChild(nsINode* aNode) const {

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

@ -3899,8 +3899,7 @@ HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDeleteRangesWithTransaction(
caretPoint.IsStartOfContainer()) {
nsIContent* previousEditableContent = EditorBase::GetPreviousContent(
*caretPoint.GetContainer(),
{EditorBase::WalkTreeOption::IgnoreNonEditableNode}, EditorType::HTML,
editingHost);
{EditorBase::WalkTreeOption::IgnoreNonEditableNode}, editingHost);
if (!previousEditableContent) {
continue;
}
@ -3923,8 +3922,7 @@ HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDeleteRangesWithTransaction(
caretPoint.IsEndOfContainer()) {
nsIContent* nextEditableContent = EditorBase::GetNextContent(
*caretPoint.GetContainer(),
{EditorBase::WalkTreeOption::IgnoreNonEditableNode}, EditorType::HTML,
editingHost);
{EditorBase::WalkTreeOption::IgnoreNonEditableNode}, editingHost);
if (!nextEditableContent) {
continue;
}
@ -3962,11 +3960,11 @@ HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDeleteRangesWithTransaction(
? EditorBase::GetPreviousContent(
caretPoint,
{EditorBase::WalkTreeOption::IgnoreNonEditableNode},
EditorType::HTML, editingHost)
editingHost)
: EditorBase::GetNextContent(
caretPoint,
{EditorBase::WalkTreeOption::IgnoreNonEditableNode},
EditorType::HTML, editingHost);
editingHost);
if (!editableContent) {
continue;
}
@ -3977,10 +3975,10 @@ HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDeleteRangesWithTransaction(
EditorBase::HowToHandleCollapsedRange::ExtendBackward
? EditorBase::GetPreviousContent(
*editableContent, {WalkTreeOption::IgnoreNonEditableNode},
EditorType::HTML, editingHost)
editingHost)
: EditorBase::GetNextContent(
*editableContent, {WalkTreeOption::IgnoreNonEditableNode},
EditorType::HTML, editingHost);
editingHost);
}
if (!editableContent) {
continue;
@ -4434,7 +4432,7 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
*atStart.ContainerAsContent(),
{WalkTreeOption::IgnoreDataNodeExceptText,
WalkTreeOption::StopAtBlockBoundary},
EditorType::HTML, aHTMLEditor.GetActiveEditingHost())
aHTMLEditor.GetActiveEditingHost())
: nullptr;
if (!nextContent || nextContent != range.StartRef().GetChild()) {
noNeedToChangeStart = true;
@ -5179,9 +5177,8 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::AutoDeleteRangesHandler::
EditorDOMPoint afterEmptyBlock(
EditorRawDOMPoint::After(mEmptyInclusiveAncestorBlockElement));
MOZ_ASSERT(afterEmptyBlock.IsSet());
if (nsIContent* nextContentOfEmptyBlock =
EditorBase::GetNextContent(afterEmptyBlock, {}, EditorType::HTML,
aHTMLEditor.GetActiveEditingHost())) {
if (nsIContent* nextContentOfEmptyBlock = EditorBase::GetNextContent(
afterEmptyBlock, {}, aHTMLEditor.GetActiveEditingHost())) {
EditorDOMPoint pt = aHTMLEditor.GetGoodCaretPointFor(
*nextContentOfEmptyBlock, aDirectionAndAmount);
if (!pt.IsSet()) {
@ -5204,7 +5201,7 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::AutoDeleteRangesHandler::
if (nsIContent* previousContentOfEmptyBlock =
EditorBase::GetPreviousContent(
atEmptyBlock, {WalkTreeOption::IgnoreNonEditableNode},
EditorType::HTML, aHTMLEditor.GetActiveEditingHost())) {
aHTMLEditor.GetActiveEditingHost())) {
EditorDOMPoint pt = aHTMLEditor.GetGoodCaretPointFor(
*previousContentOfEmptyBlock, aDirectionAndAmount);
if (!pt.IsSet()) {

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

@ -249,7 +249,7 @@ AlignStateAtSelection::AlignStateAtSelection(HTMLEditor& aHTMLEditor,
atStartOfSelection.Offset() == atBodyOrDocumentElement.Offset()) {
editTargetContent = EditorBase::GetNextContent(
atStartOfSelection, {EditorBase::WalkTreeOption::IgnoreNonEditableNode},
EditorType::HTML, aHTMLEditor.GetActiveEditingHost());
aHTMLEditor.GetActiveEditingHost());
if (NS_WARN_IF(!editTargetContent)) {
aRv.Throw(NS_ERROR_FAILURE);
return;