From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- editor/libeditor/HTMLEditorInlines.h | 144 +++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 editor/libeditor/HTMLEditorInlines.h (limited to 'editor/libeditor/HTMLEditorInlines.h') diff --git a/editor/libeditor/HTMLEditorInlines.h b/editor/libeditor/HTMLEditorInlines.h new file mode 100644 index 0000000000..1b6e5a1834 --- /dev/null +++ b/editor/libeditor/HTMLEditorInlines.h @@ -0,0 +1,144 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +#ifndef HTMLEditorInlines_h +#define HTMLEditorInlines_h + +#include "HTMLEditor.h" + +#include "EditorDOMPoint.h" +#include "HTMLEditHelpers.h" +#include "JoinSplitNodeDirection.h" // for JoinNodesDirection and SplitNodeDirection +#include "SelectionState.h" // for RangeItem + +#include "ErrorList.h" // for nsresult + +#include "mozilla/AlreadyAddRefed.h" +#include "mozilla/Debug.h" +#include "mozilla/Likely.h" +#include "mozilla/RefPtr.h" + +#include "mozilla/dom/Element.h" + +#include "nsAtom.h" +#include "nsGkAtoms.h" +#include "nsIContent.h" +#include "nsRange.h" +#include "nsString.h" + +namespace mozilla { + +using namespace dom; + +SplitNodeDirection HTMLEditor::GetSplitNodeDirection() const { + return MOZ_LIKELY(mUseGeckoTraditionalJoinSplitBehavior) + ? SplitNodeDirection::LeftNodeIsNewOne + : SplitNodeDirection::RightNodeIsNewOne; +} + +JoinNodesDirection HTMLEditor::GetJoinNodesDirection() const { + return MOZ_LIKELY(mUseGeckoTraditionalJoinSplitBehavior) + ? JoinNodesDirection::LeftNodeIntoRightNode + : JoinNodesDirection::RightNodeIntoLeftNode; +} + +Result +HTMLEditor::ReplaceContainerAndCloneAttributesWithTransaction( + Element& aOldContainer, const nsAtom& aTagName) { + return ReplaceContainerWithTransactionInternal( + aOldContainer, aTagName, *nsGkAtoms::_empty, u""_ns, true); +} + +Result +HTMLEditor::ReplaceContainerWithTransaction(Element& aOldContainer, + const nsAtom& aTagName, + const nsAtom& aAttribute, + const nsAString& aAttributeValue) { + return ReplaceContainerWithTransactionInternal( + aOldContainer, aTagName, aAttribute, aAttributeValue, false); +} + +Result +HTMLEditor::ReplaceContainerWithTransaction(Element& aOldContainer, + const nsAtom& aTagName) { + return ReplaceContainerWithTransactionInternal( + aOldContainer, aTagName, *nsGkAtoms::_empty, u""_ns, false); +} + +Result HTMLEditor::MoveNodeToEndWithTransaction( + nsIContent& aContentToMove, nsINode& aNewContainer) { + return MoveNodeWithTransaction(aContentToMove, + EditorDOMPoint::AtEndOf(aNewContainer)); +} + +Element* HTMLEditor::GetTableCellElementAt( + Element& aTableElement, const CellIndexes& aCellIndexes) const { + return GetTableCellElementAt(aTableElement, aCellIndexes.mRow, + aCellIndexes.mColumn); +} + +already_AddRefed +HTMLEditor::GetSelectedRangeItemForTopLevelEditSubAction() const { + if (!mSelectedRangeForTopLevelEditSubAction) { + mSelectedRangeForTopLevelEditSubAction = new RangeItem(); + } + return do_AddRef(mSelectedRangeForTopLevelEditSubAction); +} + +already_AddRefed HTMLEditor::GetChangedRangeForTopLevelEditSubAction() + const { + if (!mChangedRangeForTopLevelEditSubAction) { + mChangedRangeForTopLevelEditSubAction = nsRange::Create(GetDocument()); + } + return do_AddRef(mChangedRangeForTopLevelEditSubAction); +} + +// static +template +HTMLEditor::CharPointType HTMLEditor::GetPreviousCharPointType( + const EditorDOMPointType& aPoint) { + MOZ_ASSERT(aPoint.IsInTextNode()); + if (aPoint.IsStartOfContainer()) { + return CharPointType::TextEnd; + } + if (aPoint.IsPreviousCharPreformattedNewLine()) { + return CharPointType::PreformattedLineBreak; + } + if (EditorUtils::IsWhiteSpacePreformatted( + *aPoint.template ContainerAs())) { + return CharPointType::PreformattedChar; + } + if (aPoint.IsPreviousCharASCIISpace()) { + return CharPointType::ASCIIWhiteSpace; + } + return aPoint.IsPreviousCharNBSP() ? CharPointType::NoBreakingSpace + : CharPointType::VisibleChar; +} + +// static +template +HTMLEditor::CharPointType HTMLEditor::GetCharPointType( + const EditorDOMPointType& aPoint) { + MOZ_ASSERT(aPoint.IsInTextNode()); + if (aPoint.IsEndOfContainer()) { + return CharPointType::TextEnd; + } + if (aPoint.IsCharPreformattedNewLine()) { + return CharPointType::PreformattedLineBreak; + } + if (EditorUtils::IsWhiteSpacePreformatted( + *aPoint.template ContainerAs())) { + return CharPointType::PreformattedChar; + } + if (aPoint.IsCharASCIISpace()) { + return CharPointType::ASCIIWhiteSpace; + } + return aPoint.IsCharNBSP() ? CharPointType::NoBreakingSpace + : CharPointType::VisibleChar; +} + +} // namespace mozilla + +#endif // HTMLEditorInlines_h -- cgit v1.2.3