зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1793694 - part 1: Move some static inline methods of `HTMLEditor` to `HTMLEditUtils` r=m_kato
Depends on D158483 Differential Revision: https://phabricator.services.mozilla.com/D158631
This commit is contained in:
Родитель
403c6dcdb6
Коммит
fbe8ad2ec8
|
@ -582,7 +582,7 @@ CSSEditUtils::RemoveCSSInlineStyleWithTransaction(
|
|||
}
|
||||
|
||||
if (!aStyledElement.IsHTMLElement(nsGkAtoms::span) ||
|
||||
HTMLEditor::HasAttributes(&aStyledElement)) {
|
||||
HTMLEditUtils::ElementHasAttributesExceptMozDirty(aStyledElement)) {
|
||||
return EditorDOMPoint();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <math.h>
|
||||
|
||||
#include "CSSEditUtils.h"
|
||||
#include "EditAction.h"
|
||||
#include "HTMLEditorEventListener.h"
|
||||
#include "HTMLEditUtils.h"
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
|
||||
#include "HTMLEditor.h"
|
||||
|
||||
#include "CSSEditUtils.h"
|
||||
#include "HTMLEditUtils.h"
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/PresShell.h"
|
||||
#include "mozilla/PresShellInlines.h"
|
||||
|
|
|
@ -5950,7 +5950,7 @@ Result<CreateElementResult, nsresult> HTMLEditor::ChangeListElementType(
|
|||
EditorDOMPoint pointToPutCaret;
|
||||
|
||||
AutoTArray<OwningNonNull<nsIContent>, 32> listElementChildren;
|
||||
HTMLEditor::GetChildNodesOf(aListElement, listElementChildren);
|
||||
HTMLEditUtils::CollectAllChildren(aListElement, listElementChildren);
|
||||
|
||||
for (const OwningNonNull<nsIContent>& childContent : listElementChildren) {
|
||||
if (!childContent->IsElement()) {
|
||||
|
@ -8248,7 +8248,7 @@ HTMLEditor::WrapContentsInBlockquoteElementsWithTransaction(
|
|||
curBlock = nullptr;
|
||||
// Recursion time
|
||||
AutoTArray<OwningNonNull<nsIContent>, 24> childContents;
|
||||
HTMLEditor::GetChildNodesOf(*content, childContents);
|
||||
HTMLEditUtils::CollectAllChildren(*content, childContents);
|
||||
Result<CreateElementResult, nsresult>
|
||||
wrapChildrenInAnotherBlockquoteResult =
|
||||
WrapContentsInBlockquoteElementsWithTransaction(childContents,
|
||||
|
@ -8391,7 +8391,7 @@ HTMLEditor::RemoveBlockContainerElementsWithTransaction(
|
|||
}
|
||||
// Recursion time
|
||||
AutoTArray<OwningNonNull<nsIContent>, 24> childContents;
|
||||
HTMLEditor::GetChildNodesOf(*content, childContents);
|
||||
HTMLEditUtils::CollectAllChildren(*content, childContents);
|
||||
Result<EditorDOMPoint, nsresult> removeBlockContainerElementsResult =
|
||||
RemoveBlockContainerElementsWithTransaction(childContents);
|
||||
if (MOZ_UNLIKELY(removeBlockContainerElementsResult.isErr())) {
|
||||
|
@ -8550,7 +8550,7 @@ HTMLEditor::CreateOrChangeBlockContainerElement(
|
|||
curBlock = nullptr;
|
||||
// Recursion time
|
||||
AutoTArray<OwningNonNull<nsIContent>, 24> childContents;
|
||||
HTMLEditor::GetChildNodesOf(*content, childContents);
|
||||
HTMLEditUtils::CollectAllChildren(*content, childContents);
|
||||
if (!childContents.IsEmpty()) {
|
||||
Result<CreateElementResult, nsresult> wrapChildrenInBlockElementResult =
|
||||
CreateOrChangeBlockContainerElement(childContents, aBlockTag,
|
||||
|
@ -10411,7 +10411,7 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::ChangeMarginStart(
|
|||
|
||||
// Remove unnecessary divs
|
||||
if (!aElement.IsHTMLElement(nsGkAtoms::div) ||
|
||||
HTMLEditor::HasAttributes(&aElement)) {
|
||||
HTMLEditUtils::ElementHasAttributesExceptMozDirty(aElement)) {
|
||||
return EditorDOMPoint();
|
||||
}
|
||||
// Don't touch editing host nor node which is outside of it.
|
||||
|
|
|
@ -597,6 +597,17 @@ class HTMLEditUtils final {
|
|||
aFoundLinkElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether aElement has at least one attribute except _moz_dirty attribute or
|
||||
* has no attribute or only has _moz_dirty attribute.
|
||||
*/
|
||||
static bool ElementHasAttributesExceptMozDirty(const Element& aElement) {
|
||||
uint32_t attrCount = aElement.GetAttrCount();
|
||||
return attrCount > 1 ||
|
||||
(attrCount == 1u &&
|
||||
!aElement.GetAttrNameAt(0)->Equals(nsGkAtoms::mozdirty));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get adjacent content node of aNode if there is (even if one is in different
|
||||
* parent element).
|
||||
|
@ -2037,6 +2048,20 @@ class HTMLEditUtils final {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* CollectAllChildren() collects all child nodes of aParentNode.
|
||||
*/
|
||||
static void CollectAllChildren(
|
||||
const nsINode& aParentNode,
|
||||
nsTArray<OwningNonNull<nsIContent>>& aOutArrayOfContents) {
|
||||
MOZ_ASSERT(aOutArrayOfContents.IsEmpty());
|
||||
aOutArrayOfContents.SetCapacity(aParentNode.GetChildCount());
|
||||
for (nsIContent* childContent = aParentNode.GetFirstChild(); childContent;
|
||||
childContent = childContent->GetNextSibling()) {
|
||||
aOutArrayOfContents.AppendElement(*childContent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CollectChildren() collects child nodes of aNode (starting from
|
||||
* first editable child, but may return non-editable children after it).
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "HTMLEditor.h"
|
||||
|
||||
#include "AutoRangeArray.h"
|
||||
#include "CSSEditUtils.h"
|
||||
#include "EditAction.h"
|
||||
#include "EditorBase.h"
|
||||
#include "EditorDOMPoint.h"
|
||||
|
@ -5372,7 +5373,7 @@ nsresult HTMLEditor::DoJoinNodes(nsIContent& aContentToKeep,
|
|||
}
|
||||
// Otherwise it's an interior node, so shuffle around the children.
|
||||
AutoTArray<OwningNonNull<nsIContent>, 64> arrayOfChildContents;
|
||||
HTMLEditor::GetChildNodesOf(aContentToRemove, arrayOfChildContents);
|
||||
HTMLEditUtils::CollectAllChildren(aContentToRemove, arrayOfChildContents);
|
||||
|
||||
if (aDirection == JoinNodesDirection::LeftNodeIntoRightNode) {
|
||||
for (const OwningNonNull<nsIContent>& child :
|
||||
|
@ -6226,7 +6227,7 @@ HTMLEditor::CopyLastEditableChildStylesWithTransaction(
|
|||
// First, clear out aNewBlock. Contract is that we want only the styles
|
||||
// from aPreviousBlock.
|
||||
AutoTArray<OwningNonNull<nsIContent>, 32> newBlockChildren;
|
||||
HTMLEditor::GetChildNodesOf(aNewBlock, newBlockChildren);
|
||||
HTMLEditUtils::CollectAllChildren(aNewBlock, newBlockChildren);
|
||||
for (const OwningNonNull<nsIContent>& child : newBlockChildren) {
|
||||
// MOZ_KNownLive(child) because of bug 1622253
|
||||
nsresult rv = DeleteNodeWithTransaction(MOZ_KnownLive(child));
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/ComposerCommandsUpdater.h"
|
||||
#include "mozilla/CSSEditUtils.h"
|
||||
#include "mozilla/EditorBase.h"
|
||||
#include "mozilla/EditorForwards.h"
|
||||
#include "mozilla/EditorUtils.h"
|
||||
|
@ -32,7 +31,6 @@
|
|||
#include "nsITableEditor.h"
|
||||
#include "nsPoint.h"
|
||||
#include "nsStubMutationObserver.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
class nsDocumentFragment;
|
||||
class nsFrameSelection;
|
||||
|
@ -44,11 +42,14 @@ class nsStaticAtom;
|
|||
class nsStyledElement;
|
||||
class nsTableCellFrame;
|
||||
class nsTableWrapperFrame;
|
||||
template <class E>
|
||||
class nsTArray;
|
||||
|
||||
namespace mozilla {
|
||||
class AlignStateAtSelection;
|
||||
class AutoSelectionSetterAfterTableEdit;
|
||||
class AutoSetTemporaryAncestorLimiter;
|
||||
class CSSEditUtils;
|
||||
class EmptyEditableFunctor;
|
||||
class ListElementSelectionState;
|
||||
class ListItemElementSelectionState;
|
||||
|
@ -866,14 +867,6 @@ class HTMLEditor final : public EditorBase,
|
|||
*/
|
||||
MOZ_CAN_RUN_SCRIPT nsresult CollapseAdjacentTextNodes(nsRange& aRange);
|
||||
|
||||
static bool HasAttributes(Element* aElement) {
|
||||
MOZ_ASSERT(aElement);
|
||||
uint32_t attrCount = aElement->GetAttrCount();
|
||||
return attrCount > 1 ||
|
||||
(1 == attrCount &&
|
||||
!aElement->GetAttrNameAt(0)->Equals(nsGkAtoms::mozdirty));
|
||||
}
|
||||
|
||||
static dom::Element* GetLinkElement(nsINode* aNode);
|
||||
|
||||
/**
|
||||
|
@ -1246,20 +1239,6 @@ class HTMLEditor final : public EditorBase,
|
|||
const EditorDOMPointType1& aStartPoint,
|
||||
const EditorDOMPointType2& aEndPoint);
|
||||
|
||||
/**
|
||||
* GetChildNodesOf() returns all child nodes of aParent with an array.
|
||||
*/
|
||||
static void GetChildNodesOf(
|
||||
nsINode& aParentNode,
|
||||
nsTArray<OwningNonNull<nsIContent>>& aOutArrayOfContents) {
|
||||
MOZ_ASSERT(aOutArrayOfContents.IsEmpty());
|
||||
aOutArrayOfContents.SetCapacity(aParentNode.GetChildCount());
|
||||
for (nsIContent* childContent = aParentNode.GetFirstChild(); childContent;
|
||||
childContent = childContent->GetNextSibling()) {
|
||||
aOutArrayOfContents.AppendElement(*childContent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GetRangeExtendedToHardLineEdgesForBlockEditAction() returns an extended
|
||||
* range if aRange should be extended before handling a block level editing.
|
||||
|
|
|
@ -907,7 +907,7 @@ HTMLEditor::HTMLWithContextInserter::InsertContents(
|
|||
HTMLEditUtils::IsTable(pointToInsert.GetContainer()))) {
|
||||
// Move children of current node to the insertion point.
|
||||
AutoTArray<OwningNonNull<nsIContent>, 24> children;
|
||||
HTMLEditor::GetChildNodesOf(*content, children);
|
||||
HTMLEditUtils::CollectAllChildren(*content, children);
|
||||
EditorDOMPoint pointToPutCaret;
|
||||
for (const OwningNonNull<nsIContent>& child : children) {
|
||||
// MOZ_KnownLive(child) because of bug 1622253
|
||||
|
@ -960,7 +960,7 @@ HTMLEditor::HTMLWithContextInserter::InsertContents(
|
|||
(HTMLEditUtils::IsAnyListElement(pointToInsert.GetContainer()) ||
|
||||
HTMLEditUtils::IsListItem(pointToInsert.GetContainer()))) {
|
||||
AutoTArray<OwningNonNull<nsIContent>, 24> children;
|
||||
HTMLEditor::GetChildNodesOf(*content, children);
|
||||
HTMLEditUtils::CollectAllChildren(*content, children);
|
||||
EditorDOMPoint pointToPutCaret;
|
||||
for (const OwningNonNull<nsIContent>& child : children) {
|
||||
if (HTMLEditUtils::IsListItem(child) ||
|
||||
|
@ -1068,7 +1068,7 @@ HTMLEditor::HTMLWithContextInserter::InsertContents(
|
|||
HTMLEditUtils::IsPre(content)) {
|
||||
// Check for pre's going into pre's.
|
||||
AutoTArray<OwningNonNull<nsIContent>, 24> children;
|
||||
HTMLEditor::GetChildNodesOf(*content, children);
|
||||
HTMLEditUtils::CollectAllChildren(*content, children);
|
||||
EditorDOMPoint pointToPutCaret;
|
||||
for (const OwningNonNull<nsIContent>& child : children) {
|
||||
// MOZ_KnownLive(child) because of bug 1622253
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <utility>
|
||||
|
||||
#include "AutoRangeArray.h"
|
||||
#include "CSSEditUtils.h"
|
||||
#include "EditAction.h"
|
||||
#include "EditorDOMPoint.h"
|
||||
#include "EditorUtils.h"
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "HTMLEditor.h"
|
||||
|
||||
#include "CSSEditUtils.h"
|
||||
#include "HTMLEditorEventListener.h"
|
||||
#include "HTMLEditUtils.h"
|
||||
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "ErrorList.h"
|
||||
#include "HTMLEditor.h"
|
||||
|
||||
#include "AutoRangeArray.h"
|
||||
#include "CSSEditUtils.h"
|
||||
#include "EditAction.h"
|
||||
#include "EditorUtils.h"
|
||||
#include "HTMLEditHelpers.h"
|
||||
|
@ -14,6 +14,7 @@
|
|||
#include "PendingStyles.h"
|
||||
#include "SelectionState.h"
|
||||
|
||||
#include "ErrorList.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/ContentIterator.h"
|
||||
#include "mozilla/EditorForwards.h"
|
||||
|
@ -1426,7 +1427,7 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::RemoveStyleInside(
|
|||
SpecifiedStyle aSpecifiedStyle) {
|
||||
// First, handle all descendants.
|
||||
AutoTArray<OwningNonNull<nsIContent>, 32> arrayOfChildContents;
|
||||
HTMLEditor::GetChildNodesOf(aElement, arrayOfChildContents);
|
||||
HTMLEditUtils::CollectAllChildren(aElement, arrayOfChildContents);
|
||||
EditorDOMPoint pointToPutCaret;
|
||||
for (const OwningNonNull<nsIContent>& child : arrayOfChildContents) {
|
||||
if (!child->IsElement()) {
|
||||
|
@ -2994,7 +2995,7 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::SetFontSizeOfFontElementChildren(
|
|||
|
||||
// Cycle through children and adjust relative font size.
|
||||
AutoTArray<OwningNonNull<nsIContent>, 32> arrayOfContents;
|
||||
HTMLEditor::GetChildNodesOf(aContent, arrayOfContents);
|
||||
HTMLEditUtils::CollectAllChildren(aContent, arrayOfContents);
|
||||
for (const auto& child : arrayOfContents) {
|
||||
// MOZ_KnownLive because of bug 1622253
|
||||
Result<EditorDOMPoint, nsresult> setFontSizeOfChildResult =
|
||||
|
@ -3017,7 +3018,7 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::SetFontSizeOfFontElementChildren(
|
|||
// Otherwise cycle through the children.
|
||||
EditorDOMPoint pointToPutCaret;
|
||||
AutoTArray<OwningNonNull<nsIContent>, 32> arrayOfContents;
|
||||
HTMLEditor::GetChildNodesOf(aContent, arrayOfContents);
|
||||
HTMLEditUtils::CollectAllChildren(aContent, arrayOfContents);
|
||||
for (const auto& child : arrayOfContents) {
|
||||
// MOZ_KnownLive because of bug 1622253
|
||||
Result<EditorDOMPoint, nsresult> fontSizeChangeResult =
|
||||
|
@ -3131,7 +3132,7 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::SetFontSizeWithBigOrSmallElement(
|
|||
// each getting their own.
|
||||
EditorDOMPoint pointToPutCaret;
|
||||
AutoTArray<OwningNonNull<nsIContent>, 32> arrayOfContents;
|
||||
HTMLEditor::GetChildNodesOf(aContent, arrayOfContents);
|
||||
HTMLEditUtils::CollectAllChildren(aContent, arrayOfContents);
|
||||
for (const auto& child : arrayOfContents) {
|
||||
// MOZ_KnownLive because of bug 1622253
|
||||
Result<EditorDOMPoint, nsresult> setFontSizeOfChildResult =
|
||||
|
|
Загрузка…
Ссылка в новой задаче