Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / editor / libeditor / HTMLEditorInlines.h
blob653b408d75675030c1c4955c5e8fbee18b8eba5e
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef HTMLEditorInlines_h
7 #define HTMLEditorInlines_h
9 #include "HTMLEditor.h"
11 #include "EditorDOMPoint.h"
12 #include "HTMLEditHelpers.h"
13 #include "SelectionState.h" // for RangeItem
15 #include "ErrorList.h" // for nsresult
17 #include "mozilla/AlreadyAddRefed.h"
18 #include "mozilla/Debug.h"
19 #include "mozilla/Likely.h"
20 #include "mozilla/RefPtr.h"
22 #include "mozilla/dom/Element.h"
24 #include "nsAtom.h"
25 #include "nsGkAtoms.h"
26 #include "nsIContent.h"
27 #include "nsRange.h"
28 #include "nsString.h"
30 #include <ostream>
32 namespace mozilla {
34 using namespace dom;
36 Result<CreateElementResult, nsresult>
37 HTMLEditor::ReplaceContainerAndCloneAttributesWithTransaction(
38 Element& aOldContainer, const nsAtom& aTagName) {
39 return ReplaceContainerWithTransactionInternal(
40 aOldContainer, aTagName, *nsGkAtoms::_empty, u""_ns, true);
43 Result<CreateElementResult, nsresult>
44 HTMLEditor::ReplaceContainerWithTransaction(Element& aOldContainer,
45 const nsAtom& aTagName,
46 const nsAtom& aAttribute,
47 const nsAString& aAttributeValue) {
48 return ReplaceContainerWithTransactionInternal(
49 aOldContainer, aTagName, aAttribute, aAttributeValue, false);
52 Result<CreateElementResult, nsresult>
53 HTMLEditor::ReplaceContainerWithTransaction(Element& aOldContainer,
54 const nsAtom& aTagName) {
55 return ReplaceContainerWithTransactionInternal(
56 aOldContainer, aTagName, *nsGkAtoms::_empty, u""_ns, false);
59 Result<MoveNodeResult, nsresult> HTMLEditor::MoveNodeToEndWithTransaction(
60 nsIContent& aContentToMove, nsINode& aNewContainer) {
61 return MoveNodeWithTransaction(aContentToMove,
62 EditorDOMPoint::AtEndOf(aNewContainer));
65 Element* HTMLEditor::GetTableCellElementAt(
66 Element& aTableElement, const CellIndexes& aCellIndexes) const {
67 return GetTableCellElementAt(aTableElement, aCellIndexes.mRow,
68 aCellIndexes.mColumn);
71 already_AddRefed<RangeItem>
72 HTMLEditor::GetSelectedRangeItemForTopLevelEditSubAction() const {
73 if (!mSelectedRangeForTopLevelEditSubAction) {
74 mSelectedRangeForTopLevelEditSubAction = new RangeItem();
76 return do_AddRef(mSelectedRangeForTopLevelEditSubAction);
79 already_AddRefed<nsRange> HTMLEditor::GetChangedRangeForTopLevelEditSubAction()
80 const {
81 if (!mChangedRangeForTopLevelEditSubAction) {
82 mChangedRangeForTopLevelEditSubAction = nsRange::Create(GetDocument());
84 return do_AddRef(mChangedRangeForTopLevelEditSubAction);
87 // static
88 template <typename EditorDOMPointType>
89 HTMLEditor::CharPointType HTMLEditor::GetPreviousCharPointType(
90 const EditorDOMPointType& aPoint) {
91 MOZ_ASSERT(aPoint.IsInTextNode());
92 if (aPoint.IsStartOfContainer()) {
93 return CharPointType::TextEnd;
95 if (aPoint.IsPreviousCharPreformattedNewLine()) {
96 return CharPointType::PreformattedLineBreak;
98 if (EditorUtils::IsWhiteSpacePreformatted(
99 *aPoint.template ContainerAs<Text>())) {
100 return CharPointType::PreformattedChar;
102 if (aPoint.IsPreviousCharASCIISpace()) {
103 return CharPointType::ASCIIWhiteSpace;
105 return aPoint.IsPreviousCharNBSP() ? CharPointType::NoBreakingSpace
106 : CharPointType::VisibleChar;
109 // static
110 template <typename EditorDOMPointType>
111 HTMLEditor::CharPointType HTMLEditor::GetCharPointType(
112 const EditorDOMPointType& aPoint) {
113 MOZ_ASSERT(aPoint.IsInTextNode());
114 if (aPoint.IsEndOfContainer()) {
115 return CharPointType::TextEnd;
117 if (aPoint.IsCharPreformattedNewLine()) {
118 return CharPointType::PreformattedLineBreak;
120 if (EditorUtils::IsWhiteSpacePreformatted(
121 *aPoint.template ContainerAs<Text>())) {
122 return CharPointType::PreformattedChar;
124 if (aPoint.IsCharASCIISpace()) {
125 return CharPointType::ASCIIWhiteSpace;
127 return aPoint.IsCharNBSP() ? CharPointType::NoBreakingSpace
128 : CharPointType::VisibleChar;
131 /******************************************************************************
132 * Logging utils
133 ******************************************************************************/
135 inline std::ostream& operator<<(
136 std::ostream& aStream,
137 const HTMLEditor::PreserveWhiteSpaceStyle aPreserveWhiteSpaceStyle) {
138 aStream << "PreserveWhiteSpaceStyle::"
139 << (aPreserveWhiteSpaceStyle ==
140 HTMLEditor::PreserveWhiteSpaceStyle::No
141 ? "No"
142 : "Yes");
143 return aStream;
146 } // namespace mozilla
148 #endif // HTMLEditorInlines_h