Bug 1447213 - Change editor methods which take |const EditorRawDOMPoint&| but called with EditorDOMPoint.AsRaw() to template methods r=m_kato

A lot of methods take |const EditorRawDOMPoint&| as their argument.  However,
some of them are called with EditorDOMPoint::AsRaw(). This is not good for
performance because:
1. Needs to create temporary instance of EditorRawDOMPoint.
2. EditorRawDOMPoint::AsRaw() may be used by simple mistake.
3. Such methods may call EditorRawDOMPoint::Offset(), however, it's not copied
   to the original EditorDOMPoint instance.  So, callers may need to compute
   offset again.

So, such methods should be changed to template methods if they are not virtual
method and AsRaw() should be gotten rid of for prevent it looking not expensive.

MozReview-Commit-ID: DAqqW4a2EMS

--HG--
extra : rebase_source : 120b920477fe6e7231271411a00994325acdb842
This commit is contained in:
Masayuki Nakano 2018-03-20 14:05:47 +09:00
Родитель d0a56cf088
Коммит 537b829474
23 изменённых файлов: 399 добавлений и 210 удалений

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

@ -32,20 +32,34 @@ namespace mozilla {
using namespace dom;
template already_AddRefed<CreateElementTransaction>
CreateElementTransaction::Create(
EditorBase& aEditorBase,
nsAtom& aTag,
const EditorDOMPoint& aPointToInsert);
template already_AddRefed<CreateElementTransaction>
CreateElementTransaction::Create(
EditorBase& aEditorBase,
nsAtom& aTag,
const EditorRawDOMPoint& aPointToInsert);
template<typename PT, typename CT>
already_AddRefed<CreateElementTransaction>
CreateElementTransaction::Create(EditorBase& aEditorBase,
nsAtom& aTag,
const EditorRawDOMPoint& aPointToInsert)
CreateElementTransaction::Create(
EditorBase& aEditorBase,
nsAtom& aTag,
const EditorDOMPointBase<PT, CT>& aPointToInsert)
{
RefPtr<CreateElementTransaction> transaction =
new CreateElementTransaction(aEditorBase, aTag, aPointToInsert);
return transaction.forget();
}
template<typename PT, typename CT>
CreateElementTransaction::CreateElementTransaction(
EditorBase& aEditorBase,
nsAtom& aTag,
const EditorRawDOMPoint& aPointToInsert)
const EditorDOMPointBase<PT, CT>& aPointToInsert)
: EditTransactionBase()
, mEditorBase(&aEditorBase)
, mTag(&aTag)

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

@ -29,9 +29,10 @@ class Element;
class CreateElementTransaction final : public EditTransactionBase
{
protected:
template<typename PT, typename CT>
CreateElementTransaction(EditorBase& aEditorBase,
nsAtom& aTag,
const EditorRawDOMPoint& aPointToInsert);
const EditorDOMPointBase<PT, CT>& aPointToInsert);
public:
/**
@ -45,10 +46,11 @@ public:
* or after, the new node will be appended to the
* container.
*/
template<typename PT, typename CT>
static already_AddRefed<CreateElementTransaction>
Create(EditorBase& aEditorBase,
nsAtom& aTag,
const EditorRawDOMPoint& aPointToInsert);
const EditorDOMPointBase<PT, CT>& aPointToInsert);
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CreateElementTransaction,

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

@ -123,6 +123,31 @@ using namespace widget;
* mozilla::EditorBase
*****************************************************************************/
template already_AddRefed<Element>
EditorBase::CreateNode(nsAtom* aTag, const EditorDOMPoint& aPointToInsert);
template already_AddRefed<Element>
EditorBase::CreateNode(nsAtom* aTag, const EditorRawDOMPoint& aPointToInsert);
template nsresult
EditorBase::InsertNode(nsIContent& aContentToInsert,
const EditorDOMPoint& aPointToInsert);
template nsresult
EditorBase::InsertNode(nsIContent& aContentToInsert,
const EditorRawDOMPoint& aPointToInsert);
template already_AddRefed<nsIContent>
EditorBase::SplitNode(const EditorDOMPoint& aStartOfRightNode,
ErrorResult& aError);
template already_AddRefed<nsIContent>
EditorBase::SplitNode(const EditorRawDOMPoint& aStartOfRightNode,
ErrorResult& aError);
template SplitNodeResult
EditorBase::SplitNodeDeep(nsIContent& aMostAncestorToSplit,
const EditorDOMPoint& aStartOfDeepestRightNode,
SplitAtEdges aSplitAtEdges);
template SplitNodeResult
EditorBase::SplitNodeDeep(nsIContent& aMostAncestorToSplit,
const EditorRawDOMPoint& aStartOfDeepestRightNode,
SplitAtEdges aSplitAtEdges);
EditorBase::EditorBase()
: mPlaceholderName(nullptr)
, mModCount(0)
@ -1417,9 +1442,10 @@ EditorBase::SetSpellcheckUserOverride(bool enable)
return SyncRealTimeSpell();
}
template<typename PT, typename CT>
already_AddRefed<Element>
EditorBase::CreateNode(nsAtom* aTag,
const EditorRawDOMPoint& aPointToInsert)
const EditorDOMPointBase<PT, CT>& aPointToInsert)
{
MOZ_ASSERT(aTag);
MOZ_ASSERT(aPointToInsert.IsSetAndValid());
@ -1489,9 +1515,10 @@ EditorBase::InsertNode(nsIDOMNode* aNodeToInsert,
return InsertNode(*contentToInsert, EditorRawDOMPoint(container, offset));
}
template<typename PT, typename CT>
nsresult
EditorBase::InsertNode(nsIContent& aContentToInsert,
const EditorRawDOMPoint& aPointToInsert)
const EditorDOMPointBase<PT, CT>& aPointToInsert)
{
if (NS_WARN_IF(!aPointToInsert.IsSet())) {
return NS_ERROR_INVALID_ARG;
@ -1504,7 +1531,7 @@ EditorBase::InsertNode(nsIContent& aContentToInsert,
InsertNodeTransaction::Create(*this, aContentToInsert, aPointToInsert);
nsresult rv = DoTransaction(transaction);
mRangeUpdater.SelAdjInsertNode(aPointToInsert.AsRaw());
mRangeUpdater.SelAdjInsertNode(aPointToInsert);
if (mRules && mRules->AsHTMLEditRules()) {
RefPtr<HTMLEditRules> htmlEditRules = mRules->AsHTMLEditRules();
@ -1543,8 +1570,9 @@ EditorBase::SplitNode(nsIDOMNode* aNode,
return NS_OK;
}
template<typename PT, typename CT>
already_AddRefed<nsIContent>
EditorBase::SplitNode(const EditorRawDOMPoint& aStartOfRightNode,
EditorBase::SplitNode(const EditorDOMPointBase<PT, CT>& aStartOfRightNode,
ErrorResult& aError)
{
if (NS_WARN_IF(!aStartOfRightNode.IsSet()) ||
@ -1775,7 +1803,7 @@ EditorBase::ReplaceContainer(Element* aOldContainer,
// Insert new container into tree.
NS_WARNING_ASSERTION(atOldContainer.IsSetAndValid(),
"The old container might be moved by mutation observer");
nsresult rv = InsertNode(*newContainer, atOldContainer.AsRaw());
nsresult rv = InsertNode(*newContainer, atOldContainer);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
@ -1889,7 +1917,7 @@ EditorBase::InsertContainerAbove(nsIContent* aNode,
}
// Put the new container where aNode was.
rv = InsertNode(*newContainer, pointToInsertNewContainer.AsRaw());
rv = InsertNode(*newContainer, pointToInsertNewContainer);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
@ -4132,10 +4160,12 @@ EditorBase::IsPreformatted(nsIDOMNode* aNode,
return NS_OK;
}
template<typename PT, typename CT>
SplitNodeResult
EditorBase::SplitNodeDeep(nsIContent& aMostAncestorToSplit,
const EditorRawDOMPoint& aStartOfDeepestRightNode,
SplitAtEdges aSplitAtEdges)
EditorBase::SplitNodeDeep(
nsIContent& aMostAncestorToSplit,
const EditorDOMPointBase<PT, CT>& aStartOfDeepestRightNode,
SplitAtEdges aSplitAtEdges)
{
MOZ_ASSERT(aStartOfDeepestRightNode.IsSetAndValid());
MOZ_ASSERT(aStartOfDeepestRightNode.GetContainer() == &aMostAncestorToSplit ||
@ -4174,8 +4204,7 @@ EditorBase::SplitNodeDeep(nsIContent& aMostAncestorToSplit,
(!atStartOfRightNode.IsStartOfContainer() &&
!atStartOfRightNode.IsEndOfContainer())) {
ErrorResult error;
nsCOMPtr<nsIContent> newLeftNode =
SplitNode(atStartOfRightNode.AsRaw(), error);
nsCOMPtr<nsIContent> newLeftNode = SplitNode(atStartOfRightNode, error);
if (NS_WARN_IF(error.Failed())) {
return SplitNodeResult(error.StealNSResult());
}
@ -4522,7 +4551,7 @@ EditorBase::DeleteSelectionAndPrepareToCreateNode()
}
ErrorResult error;
nsCOMPtr<nsIContent> newLeftNode = SplitNode(atAnchor.AsRaw(), error);
nsCOMPtr<nsIContent> newLeftNode = SplitNode(atAnchor, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}

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

@ -350,8 +350,9 @@ public:
* container. Otherwise, will insert the node
* before child node referred by this.
*/
template<typename PT, typename CT>
nsresult InsertNode(nsIContent& aContentToInsert,
const EditorRawDOMPoint& aPointToInsert);
const EditorDOMPointBase<PT, CT>& aPointToInsert);
enum ECloneAttributes { eDontCloneAttributes, eCloneAttributes };
already_AddRefed<Element> ReplaceContainer(Element* aOldContainer,
@ -381,8 +382,9 @@ public:
* @param aError If succeed, returns no error. Otherwise, an
* error.
*/
template<typename PT, typename CT>
already_AddRefed<nsIContent>
SplitNode(const EditorRawDOMPoint& aStartOfRightNode,
SplitNode(const EditorDOMPointBase<PT, CT>& aStartOfRightNode,
ErrorResult& aResult);
nsresult JoinNodes(nsINode& aLeftNode, nsINode& aRightNode);
@ -520,8 +522,10 @@ protected:
* child node referred by this.
* @return The created new element node.
*/
already_AddRefed<Element> CreateNode(nsAtom* aTag,
const EditorRawDOMPoint& aPointToInsert);
template<typename PT, typename CT>
already_AddRefed<Element>
CreateNode(nsAtom* aTag,
const EditorDOMPointBase<PT, CT>& aPointToInsert);
/**
* Create an aggregate transaction for delete selection. The result may
@ -905,28 +909,35 @@ public:
* you want. They start to search the result from next node of the given
* node.
*/
nsIContent* GetNextNode(const EditorRawDOMPoint& aPoint)
template<typename PT, typename CT>
nsIContent* GetNextNode(const EditorDOMPointBase<PT, CT>& aPoint)
{
return GetNextNodeInternal(aPoint, false, true, false);
}
nsIContent* GetNextElementOrText(const EditorRawDOMPoint& aPoint)
template<typename PT, typename CT>
nsIContent* GetNextElementOrText(const EditorDOMPointBase<PT, CT>& aPoint)
{
return GetNextNodeInternal(aPoint, false, false, false);
}
nsIContent* GetNextEditableNode(const EditorRawDOMPoint& aPoint)
template<typename PT, typename CT>
nsIContent* GetNextEditableNode(const EditorDOMPointBase<PT, CT>& aPoint)
{
return GetNextNodeInternal(aPoint, true, true, false);
}
nsIContent* GetNextNodeInBlock(const EditorRawDOMPoint& aPoint)
template<typename PT, typename CT>
nsIContent* GetNextNodeInBlock(const EditorDOMPointBase<PT, CT>& aPoint)
{
return GetNextNodeInternal(aPoint, false, true, true);
}
nsIContent* GetNextElementOrTextInBlock(const EditorRawDOMPoint& aPoint)
template<typename PT, typename CT>
nsIContent* GetNextElementOrTextInBlock(
const EditorDOMPointBase<PT, CT>& aPoint)
{
return GetNextNodeInternal(aPoint, false, false, true);
}
template<typename PT, typename CT>
nsIContent* GetNextEditableNodeInBlock(
const EditorRawDOMPoint& aPoint)
const EditorDOMPointBase<PT, CT>& aPoint)
{
return GetNextNodeInternal(aPoint, true, true, true);
}
@ -1182,9 +1193,10 @@ public:
* be good to insert something if the
* caller want to do it.
*/
template<typename PT, typename CT>
SplitNodeResult
SplitNodeDeep(nsIContent& aMostAncestorToSplit,
const EditorRawDOMPoint& aDeepestStartOfRightNode,
const EditorDOMPointBase<PT, CT>& aDeepestStartOfRightNode,
SplitAtEdges aSplitAtEdges);
EditorDOMPoint JoinNodeDeep(nsIContent& aLeftNode,

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

@ -629,14 +629,6 @@ public:
return mChild->IsHTMLElement(nsGkAtoms::br);
}
// Convenience methods for switching between the two types
// of EditorDOMPointBase.
EditorDOMPointBase<nsINode*, nsIContent*>
AsRaw() const
{
return EditorRawDOMPoint(*this);
}
template<typename A, typename B>
EditorDOMPointBase& operator=(const RangeBoundaryBase<A,B>& aOther)
{

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

@ -221,7 +221,7 @@ public:
return EditorRawDOMPoint();
}
if (mGivenSplitPoint.IsSet()) {
return mGivenSplitPoint.AsRaw();
return EditorRawDOMPoint(mGivenSplitPoint);
}
if (!mPreviousNode) {
return EditorRawDOMPoint(mNextNode);

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

@ -1258,8 +1258,11 @@ HTMLEditRules::WillInsert(Selection& aSelection,
// the same block as the selection. We need to move the selection start
// to be before the mozBR.
EditorRawDOMPoint point(priorNode);
nsresult rv = aSelection.Collapse(point.AsRaw());
NS_ENSURE_SUCCESS_VOID(rv);
IgnoredErrorResult error;
aSelection.Collapse(point, error);
if (NS_WARN_IF(error.Failed())) {
return;
}
}
}
@ -1349,7 +1352,8 @@ HTMLEditRules::WillInsertText(EditAction aAction,
}
if (inString->IsEmpty()) {
rv = mHTMLEditor->InsertTextImpl(*doc, *inString, pointToInsert.AsRaw());
rv = mHTMLEditor->InsertTextImpl(*doc, *inString,
EditorRawDOMPoint(pointToInsert));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -1357,7 +1361,7 @@ HTMLEditRules::WillInsertText(EditAction aAction,
}
WSRunObject wsObj(mHTMLEditor, pointToInsert);
rv = wsObj.InsertText(*doc, *inString, pointToInsert.AsRaw());
rv = wsObj.InsertText(*doc, *inString, pointToInsert);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -1422,7 +1426,7 @@ HTMLEditRules::WillInsertText(EditAction aAction,
if (subStr.Equals(newlineStr)) {
NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<Element> br =
mHTMLEditor->CreateBRImpl(*aSelection, currentPoint.AsRaw(),
mHTMLEditor->CreateBRImpl(*aSelection, currentPoint,
nsIEditor::eNone);
NS_ENSURE_STATE(br);
pos++;
@ -1444,7 +1448,8 @@ HTMLEditRules::WillInsertText(EditAction aAction,
} else {
NS_ENSURE_STATE(mHTMLEditor);
EditorRawDOMPoint pointAfterInsertedString;
rv = mHTMLEditor->InsertTextImpl(*doc, subStr, currentPoint.AsRaw(),
rv = mHTMLEditor->InsertTextImpl(*doc, subStr,
EditorRawDOMPoint(currentPoint),
&pointAfterInsertedString);
NS_ENSURE_SUCCESS(rv, rv);
currentPoint = pointAfterInsertedString;
@ -1479,7 +1484,7 @@ HTMLEditRules::WillInsertText(EditAction aAction,
// is it a tab?
if (subStr.Equals(tabStr)) {
EditorRawDOMPoint pointAfterInsertedSpaces;
rv = wsObj.InsertText(*doc, spacesStr, currentPoint.AsRaw(),
rv = wsObj.InsertText(*doc, spacesStr, currentPoint,
&pointAfterInsertedSpaces);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
@ -1491,8 +1496,7 @@ HTMLEditRules::WillInsertText(EditAction aAction,
// is it a return?
else if (subStr.Equals(newlineStr)) {
RefPtr<Element> newBRElement =
wsObj.InsertBreak(*aSelection, currentPoint.AsRaw(),
nsIEditor::eNone);
wsObj.InsertBreak(*aSelection, currentPoint, nsIEditor::eNone);
if (NS_WARN_IF(!newBRElement)) {
return NS_ERROR_FAILURE;
}
@ -1514,7 +1518,7 @@ HTMLEditRules::WillInsertText(EditAction aAction,
"Perhaps, newBRElement has been moved or removed unexpectedly");
} else {
EditorRawDOMPoint pointAfterInsertedString;
rv = wsObj.InsertText(*doc, subStr, currentPoint.AsRaw(),
rv = wsObj.InsertText(*doc, subStr, currentPoint,
&pointAfterInsertedString);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
@ -1532,7 +1536,7 @@ HTMLEditRules::WillInsertText(EditAction aAction,
if (currentPoint.IsSet()) {
ErrorResult error;
aSelection->Collapse(currentPoint.AsRaw(), error);
aSelection->Collapse(currentPoint, error);
if (error.Failed()) {
NS_WARNING("Failed to collapse at current point");
error.SuppressException();
@ -1546,15 +1550,14 @@ HTMLEditRules::WillInsertText(EditAction aAction,
}
if (currentPoint.IsSet()) {
rv = mDocChangeRange->SetStartAndEnd(pointToInsert.AsRaw(),
currentPoint.AsRaw());
rv = mDocChangeRange->SetStartAndEnd(pointToInsert, currentPoint);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
rv = mDocChangeRange->CollapseTo(pointToInsert.AsRaw());
rv = mDocChangeRange->CollapseTo(pointToInsert);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -1856,7 +1859,7 @@ HTMLEditRules::InsertBRElement(Selection& aSelection,
// First, insert a <br> element.
RefPtr<Element> brElement;
if (IsPlaintextEditor()) {
brElement = htmlEditor->CreateBR(aPointToBreak.AsRaw());
brElement = htmlEditor->CreateBR(aPointToBreak);
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
@ -1886,15 +1889,14 @@ HTMLEditRules::InsertBRElement(Selection& aSelection,
return NS_ERROR_FAILURE;
}
SplitNodeResult splitLinkNodeResult =
htmlEditor->SplitNodeDeep(*linkNode, pointToBreak.AsRaw(),
htmlEditor->SplitNodeDeep(*linkNode, pointToBreak,
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(splitLinkNodeResult.Failed())) {
return splitLinkNodeResult.Rv();
}
pointToBreak = splitLinkNodeResult.SplitPoint();
}
brElement =
wsObj.InsertBreak(aSelection, pointToBreak.AsRaw(), nsIEditor::eNone);
brElement = wsObj.InsertBreak(aSelection, pointToBreak, nsIEditor::eNone);
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
@ -1963,7 +1965,7 @@ HTMLEditRules::InsertBRElement(Selection& aSelection,
aSelection.SetInterlinePosition(!(nextSiblingOfBRElement &&
IsBlockNode(*nextSiblingOfBRElement)));
ErrorResult error;
aSelection.Collapse(afterBRElement.AsRaw(), error);
aSelection.Collapse(afterBRElement, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
@ -2474,8 +2476,11 @@ HTMLEditRules::WillDeleteSelection(Selection* aSelection,
return NS_ERROR_FAILURE;
}
// Fix up selection
rv = aSelection->Collapse(pt.AsRaw());
NS_ENSURE_SUCCESS(rv, rv);
ErrorResult error;
aSelection->Collapse(pt, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
}
rv = InsertBRIfNeeded(aSelection);
NS_ENSURE_SUCCESS(rv, rv);
@ -2547,7 +2552,7 @@ HTMLEditRules::WillDeleteSelection(Selection* aSelection,
if (NS_WARN_IF(!newSel.IsSet())) {
return NS_ERROR_FAILURE;
}
aSelection->Collapse(newSel.AsRaw());
aSelection->Collapse(newSel);
return NS_OK;
}
@ -2739,8 +2744,11 @@ HTMLEditRules::WillDeleteSelection(Selection* aSelection,
return NS_ERROR_FAILURE;
}
// Fix up selection
rv = aSelection->Collapse(pt.AsRaw());
NS_ENSURE_SUCCESS(rv, rv);
ErrorResult error;
aSelection->Collapse(pt, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
return NS_OK;
}
@ -3474,7 +3482,7 @@ HTMLEditRules::DidDeleteSelection(Selection* aSelection,
}
}
if (atCiteNode.IsSet() && seenBR) {
RefPtr<Element> brNode = htmlEditor->CreateBR(atCiteNode.AsRaw());
RefPtr<Element> brNode = htmlEditor->CreateBR(atCiteNode);
if (NS_WARN_IF(!brNode)) {
return NS_ERROR_FAILURE;
}
@ -3584,7 +3592,7 @@ HTMLEditRules::WillMakeList(Selection* aSelection,
}
SplitNodeResult splitAtSelectionStartResult =
MaybeSplitAncestorsForInsert(listType, atStartOfSelection.AsRaw());
MaybeSplitAncestorsForInsert(listType, atStartOfSelection);
if (NS_WARN_IF(splitAtSelectionStartResult.Failed())) {
return splitAtSelectionStartResult.Rv();
}
@ -3941,7 +3949,7 @@ HTMLEditRules::MakeBasicBlock(Selection& aSelection, nsAtom& blockType)
// Otherwise it gets pushed into a following block after the split,
// which is visually bad.
nsCOMPtr<nsIContent> brNode =
htmlEditor->GetNextEditableHTMLNode(pointToInsertBlock.AsRaw());
htmlEditor->GetNextEditableHTMLNode(pointToInsertBlock);
if (brNode && brNode->IsHTMLElement(nsGkAtoms::br)) {
AutoEditorDOMPointChildInvalidator lockOffset(pointToInsertBlock);
rv = htmlEditor->DeleteNode(brNode);
@ -3949,7 +3957,7 @@ HTMLEditRules::MakeBasicBlock(Selection& aSelection, nsAtom& blockType)
}
// Do the splits!
SplitNodeResult splitNodeResult =
htmlEditor->SplitNodeDeep(*curBlock, pointToInsertBlock.AsRaw(),
htmlEditor->SplitNodeDeep(*curBlock, pointToInsertBlock,
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
@ -3972,7 +3980,7 @@ HTMLEditRules::MakeBasicBlock(Selection& aSelection, nsAtom& blockType)
// We are making a block. Consume a br, if needed.
nsCOMPtr<nsIContent> brNode =
htmlEditor->GetNextEditableHTMLNodeInBlock(pointToInsertBlock.AsRaw());
htmlEditor->GetNextEditableHTMLNodeInBlock(pointToInsertBlock);
if (brNode && brNode->IsHTMLElement(nsGkAtoms::br)) {
AutoEditorDOMPointChildInvalidator lockOffset(pointToInsertBlock);
rv = htmlEditor->DeleteNode(brNode);
@ -3982,7 +3990,7 @@ HTMLEditRules::MakeBasicBlock(Selection& aSelection, nsAtom& blockType)
}
// Make sure we can put a block here.
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(blockType, pointToInsertBlock.AsRaw());
MaybeSplitAncestorsForInsert(blockType, pointToInsertBlock);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -4131,7 +4139,7 @@ HTMLEditRules::WillCSSIndent(Selection* aSelection,
// make sure we can put a block here
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*nsGkAtoms::div, atStartOfSelection.AsRaw());
MaybeSplitAncestorsForInsert(*nsGkAtoms::div, atStartOfSelection);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -4219,7 +4227,7 @@ HTMLEditRules::WillCSSIndent(Selection* aSelection,
atCurNode.GetContainer()->NodeInfo()->NameAtom();
// Create a new nested list of correct type.
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*containerName, atCurNode.AsRaw());
MaybeSplitAncestorsForInsert(*containerName, atCurNode);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -4254,7 +4262,7 @@ HTMLEditRules::WillCSSIndent(Selection* aSelection,
}
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*nsGkAtoms::div, atCurNode.AsRaw());
MaybeSplitAncestorsForInsert(*nsGkAtoms::div, atCurNode);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -4329,7 +4337,7 @@ HTMLEditRules::WillHTMLIndent(Selection* aSelection,
// Make sure we can put a block here.
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*nsGkAtoms::blockquote,
atStartOfSelection.AsRaw());
atStartOfSelection);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -4417,7 +4425,7 @@ HTMLEditRules::WillHTMLIndent(Selection* aSelection,
atCurNode.GetContainer()->NodeInfo()->NameAtom();
// Create a new nested list of correct type.
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*containerName, atCurNode.AsRaw());
MaybeSplitAncestorsForInsert(*containerName, atCurNode);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -4466,7 +4474,7 @@ HTMLEditRules::WillHTMLIndent(Selection* aSelection,
atListItem.GetContainer()->NodeInfo()->NameAtom();
// Create a new nested list of correct type.
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*containerName, atListItem.AsRaw());
MaybeSplitAncestorsForInsert(*containerName, atListItem);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -4500,7 +4508,7 @@ HTMLEditRules::WillHTMLIndent(Selection* aSelection,
}
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*nsGkAtoms::blockquote, atCurNode.AsRaw());
MaybeSplitAncestorsForInsert(*nsGkAtoms::blockquote, atCurNode);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -5104,7 +5112,7 @@ HTMLEditRules::WillAlign(Selection& aSelection,
}
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*nsGkAtoms::div, atStartOfSelection.AsRaw());
MaybeSplitAncestorsForInsert(*nsGkAtoms::div, atStartOfSelection);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -5129,7 +5137,7 @@ HTMLEditRules::WillAlign(Selection& aSelection,
}
}
RefPtr<Element> div =
htmlEditor->CreateNode(nsGkAtoms::div, pointToInsertDiv.AsRaw());
htmlEditor->CreateNode(nsGkAtoms::div, pointToInsertDiv);
NS_ENSURE_STATE(div);
// Remember our new block for postprocessing
mNewBlock = div;
@ -5238,7 +5246,7 @@ HTMLEditRules::WillAlign(Selection& aSelection,
}
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*nsGkAtoms::div, atCurNode.AsRaw());
MaybeSplitAncestorsForInsert(*nsGkAtoms::div, atCurNode);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -5396,7 +5404,7 @@ HTMLEditRules::CheckForEmptyBlock(nsINode* aStartNode,
// If we are a sublist, skip the br creation
if (!HTMLEditUtils::IsList(atBlockParent.GetContainer())) {
// Create a br before list
RefPtr<Element> br = htmlEditor->CreateBR(atBlockParent.AsRaw());
RefPtr<Element> br = htmlEditor->CreateBR(atBlockParent);
if (NS_WARN_IF(!br)) {
return NS_ERROR_FAILURE;
}
@ -5422,16 +5430,22 @@ HTMLEditRules::CheckForEmptyBlock(nsINode* aStartNode,
htmlEditor->GetNextNode(afterEmptyBlock);
if (nextNode) {
EditorDOMPoint pt = GetGoodSelPointForNode(*nextNode, aAction);
nsresult rv = aSelection->Collapse(pt.AsRaw());
NS_ENSURE_SUCCESS(rv, rv);
ErrorResult error;
aSelection->Collapse(pt, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
} else {
// Adjust selection to be right after it.
EditorRawDOMPoint afterEmptyBlock(emptyBlock);
if (NS_WARN_IF(!afterEmptyBlock.AdvanceOffset())) {
return NS_ERROR_FAILURE;
}
nsresult rv = aSelection->Collapse(afterEmptyBlock);
NS_ENSURE_SUCCESS(rv, rv);
ErrorResult error;
aSelection->Collapse(afterEmptyBlock, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
}
} else if (aAction == nsIEditor::ePrevious ||
aAction == nsIEditor::ePreviousWord ||
@ -5442,7 +5456,7 @@ HTMLEditRules::CheckForEmptyBlock(nsINode* aStartNode,
htmlEditor->GetPreviousEditableNode(atEmptyBlock);
if (priorNode) {
EditorDOMPoint pt = GetGoodSelPointForNode(*priorNode, aAction);
nsresult rv = aSelection->Collapse(pt.AsRaw());
nsresult rv = aSelection->Collapse(pt);
NS_ENSURE_SUCCESS(rv, rv);
} else {
EditorRawDOMPoint afterEmptyBlock(emptyBlock);
@ -5899,20 +5913,20 @@ HTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere,
// look back through any further inline nodes that aren't across a <br>
// from us, and that are enclosed in the same block.
nsCOMPtr<nsINode> priorNode =
htmlEditor->GetPreviousEditableHTMLNodeInBlock(point.AsRaw());
htmlEditor->GetPreviousEditableHTMLNodeInBlock(point);
while (priorNode && priorNode->GetParentNode() &&
!htmlEditor->IsVisibleBRElement(priorNode) &&
!IsBlockNode(*priorNode)) {
point.Set(priorNode);
priorNode = htmlEditor->GetPreviousEditableHTMLNodeInBlock(point.AsRaw());
priorNode = htmlEditor->GetPreviousEditableHTMLNodeInBlock(point);
}
// finding the real start for this point. look up the tree for as long as
// we are the first node in the container, and as long as we haven't hit
// the body node.
nsCOMPtr<nsIContent> nearNode =
htmlEditor->GetPreviousEditableHTMLNodeInBlock(point.AsRaw());
htmlEditor->GetPreviousEditableHTMLNodeInBlock(point);
while (!nearNode &&
!point.IsContainerHTMLElement(nsGkAtoms::body) &&
point.GetContainer()->GetParentNode()) {
@ -5941,7 +5955,7 @@ HTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere,
}
point.Set(point.GetContainer());
nearNode = htmlEditor->GetPreviousEditableHTMLNodeInBlock(point.AsRaw());
nearNode = htmlEditor->GetPreviousEditableHTMLNodeInBlock(point);
}
return point;
}
@ -5975,7 +5989,7 @@ HTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere,
// Only in the first case, after the caret position isn't wrapped with
// new <div> element.
nsCOMPtr<nsIContent> nextNode =
htmlEditor->GetNextEditableHTMLNodeInBlock(point.AsRaw());
htmlEditor->GetNextEditableHTMLNodeInBlock(point);
while (nextNode && !IsBlockNode(*nextNode) && nextNode->GetParentNode()) {
point.Set(nextNode);
@ -6003,14 +6017,14 @@ HTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere,
}
}
}
nextNode = htmlEditor->GetNextEditableHTMLNodeInBlock(point.AsRaw());
nextNode = htmlEditor->GetNextEditableHTMLNodeInBlock(point);
}
// finding the real end for this point. look up the tree for as long as we
// are the last node in the container, and as long as we haven't hit the body
// node.
nsCOMPtr<nsIContent> nearNode =
htmlEditor->GetNextEditableHTMLNodeInBlock(point.AsRaw());
htmlEditor->GetNextEditableHTMLNodeInBlock(point);
while (!nearNode &&
!point.IsContainerHTMLElement(nsGkAtoms::body) &&
point.GetContainer()->GetParentNode()) {
@ -6027,7 +6041,7 @@ HTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere,
if (NS_WARN_IF(!point.AdvanceOffset())) {
break;
}
nearNode = htmlEditor->GetNextEditableHTMLNodeInBlock(point.AsRaw());
nearNode = htmlEditor->GetNextEditableHTMLNodeInBlock(point);
}
return point;
}
@ -6126,20 +6140,19 @@ HTMLEditRules::PromoteRange(nsRange& aRange,
EditorDOMPoint startPoint =
GetPromotedPoint(kStart, *startNode, startOffset, aOperationType);
if (!htmlEditor->IsDescendantOfEditorRoot(
EditorBase::GetNodeAtRangeOffsetPoint(startPoint.AsRaw()))) {
EditorBase::GetNodeAtRangeOffsetPoint(startPoint))) {
return;
}
EditorDOMPoint endPoint =
GetPromotedPoint(kEnd, *endNode, endOffset, aOperationType);
EditorRawDOMPoint lastRawPoint(endPoint.AsRaw());
EditorRawDOMPoint lastRawPoint(endPoint);
lastRawPoint.RewindOffset();
if (!htmlEditor->IsDescendantOfEditorRoot(
EditorBase::GetNodeAtRangeOffsetPoint(lastRawPoint))) {
return;
}
DebugOnly<nsresult> rv =
aRange.SetStartAndEnd(startPoint.AsRaw(), endPoint.AsRaw());
DebugOnly<nsresult> rv = aRange.SetStartAndEnd(startPoint, endPoint);
MOZ_ASSERT(NS_SUCCEEDED(rv));
}
@ -6189,7 +6202,7 @@ HTMLEditRules::GetNodesForOperation(
// Split the text node.
ErrorResult error;
nsCOMPtr<nsIContent> newLeftNode =
htmlEditor->SplitNode(atEnd.AsRaw(), error);
htmlEditor->SplitNode(atEnd, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
@ -7034,7 +7047,7 @@ HTMLEditRules::ReturnInParagraph(Selection& aSelection,
if (doesCRCreateNewP) {
ErrorResult error;
nsCOMPtr<nsIContent> newLeftDivOrP =
htmlEditor->SplitNode(pointToSplitParentDivOrP.AsRaw(), error);
htmlEditor->SplitNode(pointToSplitParentDivOrP, error);
if (NS_WARN_IF(error.Failed())) {
return EditActionResult(error.StealNSResult());
}
@ -7053,12 +7066,12 @@ HTMLEditRules::ReturnInParagraph(Selection& aSelection,
// is there a BR prior to it?
nsCOMPtr<nsIContent> nearNode;
nearNode =
htmlEditor->GetPreviousEditableHTMLNode(atStartOfSelection.AsRaw());
htmlEditor->GetPreviousEditableHTMLNode(atStartOfSelection);
if (!nearNode || !htmlEditor->IsVisibleBRElement(nearNode) ||
TextEditUtils::HasMozAttr(GetAsDOMNode(nearNode))) {
// is there a BR after it?
nearNode =
htmlEditor->GetNextEditableHTMLNode(atStartOfSelection.AsRaw());
htmlEditor->GetNextEditableHTMLNode(atStartOfSelection);
if (!nearNode || !htmlEditor->IsVisibleBRElement(nearNode) ||
TextEditUtils::HasMozAttr(GetAsDOMNode(nearNode))) {
pointToInsertBR = atStartOfSelection;
@ -7090,7 +7103,7 @@ HTMLEditRules::ReturnInParagraph(Selection& aSelection,
}
}
EditActionResult result(
SplitParagraph(aSelection, aParentDivOrP, pointToSplitParentDivOrP.AsRaw(),
SplitParagraph(aSelection, aParentDivOrP, pointToSplitParentDivOrP,
brNode));
result.MarkAsHandled();
if (NS_WARN_IF(result.Failed())) {
@ -7099,11 +7112,13 @@ HTMLEditRules::ReturnInParagraph(Selection& aSelection,
return result;
}
template<typename PT, typename CT>
nsresult
HTMLEditRules::SplitParagraph(Selection& aSelection,
Element& aParentDivOrP,
const EditorRawDOMPoint& aStartOfRightNode,
nsIContent* aNextBRNode)
HTMLEditRules::SplitParagraph(
Selection& aSelection,
Element& aParentDivOrP,
const EditorDOMPointBase<PT, CT>& aStartOfRightNode,
nsIContent* aNextBRNode)
{
if (NS_WARN_IF(!mHTMLEditor)) {
return NS_ERROR_NOT_AVAILABLE;
@ -7417,7 +7432,7 @@ HTMLEditRules::MakeBlockquote(nsTArray<OwningNonNull<nsINode>>& aNodeArray)
if (!curBlock) {
EditorDOMPoint atCurNode(curNode);
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*nsGkAtoms::blockquote, atCurNode.AsRaw());
MaybeSplitAncestorsForInsert(*nsGkAtoms::blockquote, atCurNode);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -7594,7 +7609,7 @@ HTMLEditRules::ApplyBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray,
// Make sure we can put a block here
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(aBlockTag, atCurNode.AsRaw());
MaybeSplitAncestorsForInsert(aBlockTag, atCurNode);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -7620,7 +7635,7 @@ HTMLEditRules::ApplyBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray,
// The break is the first (or even only) node we encountered. Create a
// block for it.
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(aBlockTag, atCurNode.AsRaw());
MaybeSplitAncestorsForInsert(aBlockTag, atCurNode);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -7653,7 +7668,7 @@ HTMLEditRules::ApplyBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray,
AutoEditorDOMPointOffsetInvalidator lockChild(atCurNode);
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(aBlockTag, atCurNode.AsRaw());
MaybeSplitAncestorsForInsert(aBlockTag, atCurNode);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -7681,10 +7696,11 @@ HTMLEditRules::ApplyBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray,
return NS_OK;
}
template<typename PT, typename CT>
SplitNodeResult
HTMLEditRules::MaybeSplitAncestorsForInsert(
nsAtom& aTag,
const EditorRawDOMPoint& aStartOfDeepestRightNode)
const EditorDOMPointBase<PT, CT>& aStartOfDeepestRightNode)
{
if (NS_WARN_IF(!aStartOfDeepestRightNode.IsSet())) {
return SplitNodeResult(NS_ERROR_INVALID_ARG);
@ -8131,7 +8147,7 @@ HTMLEditRules::CheckInterlinePosition(Selection& aSelection)
// special-case first so that we don't accidentally fall through into one of
// the other conditionals.
nsCOMPtr<nsIContent> node =
htmlEditor->GetPreviousEditableHTMLNodeInBlock(atStartOfSelection.AsRaw());
htmlEditor->GetPreviousEditableHTMLNodeInBlock(atStartOfSelection);
if (node && node->IsHTMLElement(nsGkAtoms::br)) {
aSelection.SetInterlinePosition(true);
return;
@ -8218,7 +8234,7 @@ HTMLEditRules::AdjustSelection(Selection* aSelection,
}
// we know we can skip the rest of this routine given the cirumstance
RefPtr<Element> brElement = CreateMozBR(point.AsRaw());
RefPtr<Element> brElement = CreateMozBR(point);
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
@ -8237,7 +8253,7 @@ HTMLEditRules::AdjustSelection(Selection* aSelection,
// 3) that br is not visible
nsCOMPtr<nsIContent> nearNode =
htmlEditor->GetPreviousEditableHTMLNode(point.AsRaw());
htmlEditor->GetPreviousEditableHTMLNode(point);
if (nearNode) {
// is nearNode also a descendant of same block?
RefPtr<Element> block = htmlEditor->GetBlock(*point.GetContainer());
@ -8248,7 +8264,7 @@ HTMLEditRules::AdjustSelection(Selection* aSelection,
// need to insert special moz BR. Why? Because if we don't
// the user will see no new line for the break. Also, things
// like table cells won't grow in height.
RefPtr<Element> brElement = CreateMozBR(point.AsRaw());
RefPtr<Element> brElement = CreateMozBR(point);
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
@ -8256,7 +8272,7 @@ HTMLEditRules::AdjustSelection(Selection* aSelection,
// selection stays *before* moz-br, sticking to it
aSelection->SetInterlinePosition(true);
ErrorResult error;
aSelection->Collapse(point.AsRaw(), error);
aSelection->Collapse(point, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
@ -8274,7 +8290,7 @@ HTMLEditRules::AdjustSelection(Selection* aSelection,
}
// we aren't in a textnode: are we adjacent to text or a break or an image?
nearNode = htmlEditor->GetPreviousEditableHTMLNodeInBlock(point.AsRaw());
nearNode = htmlEditor->GetPreviousEditableHTMLNodeInBlock(point);
if (nearNode && (TextEditUtils::IsBreak(nearNode) ||
EditorBase::IsTextNode(nearNode) ||
HTMLEditUtils::IsImage(nearNode) ||
@ -8282,7 +8298,7 @@ HTMLEditRules::AdjustSelection(Selection* aSelection,
// this is a good place for the caret to be
return NS_OK;
}
nearNode = htmlEditor->GetNextEditableHTMLNodeInBlock(point.AsRaw());
nearNode = htmlEditor->GetNextEditableHTMLNodeInBlock(point);
if (nearNode && (TextEditUtils::IsBreak(nearNode) ||
EditorBase::IsTextNode(nearNode) ||
nearNode->IsAnyOfHTMLElements(nsGkAtoms::img,
@ -8292,22 +8308,23 @@ HTMLEditRules::AdjustSelection(Selection* aSelection,
// look for a nearby text node.
// prefer the correct direction.
nearNode = FindNearEditableNode(point.AsRaw(), aAction);
nearNode = FindNearEditableNode(point, aAction);
if (!nearNode) {
return NS_OK;
}
EditorDOMPoint pt = GetGoodSelPointForNode(*nearNode, aAction);
ErrorResult error;
aSelection->Collapse(pt.AsRaw(), error);
aSelection->Collapse(pt, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
return NS_OK;
}
template<typename PT, typename CT>
nsIContent*
HTMLEditRules::FindNearEditableNode(const EditorRawDOMPoint& aPoint,
HTMLEditRules::FindNearEditableNode(const EditorDOMPointBase<PT, CT>& aPoint,
nsIEditor::EDirection aDirection)
{
if (NS_WARN_IF(!aPoint.IsSet()) ||
@ -8662,7 +8679,7 @@ HTMLEditRules::PopListItem(nsIContent& aListItem,
// split the list
ErrorResult error;
leftListNode = mHTMLEditor->SplitNode(atListItem.AsRaw(), error);
leftListNode = mHTMLEditor->SplitNode(atListItem, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
@ -9335,7 +9352,7 @@ HTMLEditRules::WillAbsolutePosition(Selection& aSelection,
// Make sure we can put a block here.
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*nsGkAtoms::div, atStartOfSelection.AsRaw());
MaybeSplitAncestorsForInsert(*nsGkAtoms::div, atStartOfSelection);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -9390,7 +9407,7 @@ HTMLEditRules::WillAbsolutePosition(Selection& aSelection,
atCurNode.GetContainer()->NodeInfo()->NameAtom();
// Create a new nested list of correct type.
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*containerName, atCurNode.AsRaw());
MaybeSplitAncestorsForInsert(*containerName, atCurNode);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -9441,7 +9458,7 @@ HTMLEditRules::WillAbsolutePosition(Selection& aSelection,
atListItem.GetContainer()->NodeInfo()->NameAtom();
// Create a new nested list of correct type
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*containerName, atListItem.AsRaw());
MaybeSplitAncestorsForInsert(*containerName, atListItem);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -9473,7 +9490,7 @@ HTMLEditRules::WillAbsolutePosition(Selection& aSelection,
continue;
}
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsert(*nsGkAtoms::div, atCurNode.AsRaw());
MaybeSplitAncestorsForInsert(*nsGkAtoms::div, atCurNode);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}

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

@ -320,9 +320,10 @@ protected:
* If this is not nullptr, the <br> node may be
* removed.
*/
template<typename PT, typename CT>
nsresult SplitParagraph(Selection& aSelection,
Element& aParentDivOrP,
const EditorRawDOMPoint& aStartOfRightNode,
const EditorDOMPointBase<PT, CT>& aStartOfRightNode,
nsIContent* aBRNode);
nsresult ReturnInListItem(Selection& aSelection, Element& aHeader,
@ -457,9 +458,10 @@ protected:
* @return When succeeded, SplitPoint() returns
* the point to insert the element.
*/
template<typename PT, typename CT>
SplitNodeResult MaybeSplitAncestorsForInsert(
nsAtom& aTag,
const EditorRawDOMPoint& aStartOfDeepestRightNode);
const EditorDOMPointBase<PT, CT>& aStartOfDeepestRightNode);
nsresult AddTerminatingBR(nsIDOMNode *aBlock);
EditorDOMPoint JoinNodesSmart(nsIContent& aNodeLeft,
@ -490,7 +492,8 @@ protected:
* And also if aDirection is not nsIEditor::ePrevious,
* the result may be the node pointed by aPoint.
*/
nsIContent* FindNearEditableNode(const EditorRawDOMPoint& aPoint,
template<typename PT, typename CT>
nsIContent* FindNearEditableNode(const EditorDOMPointBase<PT, CT>& aPoint,
nsIEditor::EDirection aDirection);
/**
* Returns true if aNode1 or aNode2 or both is the descendant of some type of

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

@ -88,6 +88,17 @@ IsNamedAnchorTag(const nsString& s)
return s.EqualsIgnoreCase("anchor") || s.EqualsIgnoreCase("namedanchor");
}
template EditorDOMPoint
HTMLEditor::InsertNodeIntoProperAncestor(
nsIContent& aNode,
const EditorDOMPoint& aPointToInsert,
SplitAtEdges aSplitAtEdges);
template EditorDOMPoint
HTMLEditor::InsertNodeIntoProperAncestor(
nsIContent& aNode,
const EditorRawDOMPoint& aPointToInsert,
SplitAtEdges aSplitAtEdges);
HTMLEditor::HTMLEditor()
: mCRInParagraphCreatesParagraph(false)
, mCSSAware(false)
@ -1600,7 +1611,7 @@ HTMLEditor::InsertElementAtSelection(nsIDOMElement* aElement,
"Failed to advance offset from inserted point");
// Collapse selection to the new <br> element node after creating it.
RefPtr<Element> newBRElement =
CreateBRImpl(*selection, insertedPoint.AsRaw(), ePrevious);
CreateBRImpl(*selection, insertedPoint, ePrevious);
if (NS_WARN_IF(!newBRElement)) {
return NS_ERROR_FAILURE;
}
@ -1611,10 +1622,11 @@ HTMLEditor::InsertElementAtSelection(nsIDOMElement* aElement,
return rv;
}
template<typename PT, typename CT>
EditorDOMPoint
HTMLEditor::InsertNodeIntoProperAncestor(
nsIContent& aNode,
const EditorRawDOMPoint& aPointToInsert,
const EditorDOMPointBase<PT, CT>& aPointToInsert,
SplitAtEdges aSplitAtEdges)
{
if (NS_WARN_IF(!aPointToInsert.IsSet())) {
@ -1670,7 +1682,7 @@ HTMLEditor::InsertNodeIntoProperAncestor(
// when it's necessary.
AutoEditorDOMPointChildInvalidator lockOffset(pointToInsert);
// Now we can insert the new node.
nsresult rv = InsertNode(aNode, pointToInsert.AsRaw());
nsresult rv = InsertNode(aNode, pointToInsert);
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditorDOMPoint();
}
@ -2042,7 +2054,7 @@ HTMLEditor::MakeOrChangeList(const nsAString& aListType,
// Create a list and insert it before the right node if we split some
// parents of start of selection above, or just start of selection
// otherwise.
RefPtr<Element> newList = CreateNode(listAtom, pointToInsertList.AsRaw());
RefPtr<Element> newList = CreateNode(listAtom, pointToInsertList);
NS_ENSURE_STATE(newList);
// make a list item
EditorRawDOMPoint atStartOfNewList(newList, 0);
@ -2192,8 +2204,7 @@ HTMLEditor::InsertBasicBlock(const nsAString& aBlockType)
// Create a block and insert it before the right node if we split some
// parents of start of selection above, or just start of selection
// otherwise.
RefPtr<Element> newBlock =
CreateNode(blockAtom, pointToInsertBlock.AsRaw());
RefPtr<Element> newBlock = CreateNode(blockAtom, pointToInsertBlock);
NS_ENSURE_STATE(newBlock);
// reposition selection to inside the block
@ -2276,7 +2287,7 @@ HTMLEditor::Indent(const nsAString& aIndent)
// parents of start of selection above, or just start of selection
// otherwise.
RefPtr<Element> newBQ =
CreateNode(nsGkAtoms::blockquote, pointToInsertBlockquote.AsRaw());
CreateNode(nsGkAtoms::blockquote, pointToInsertBlockquote);
NS_ENSURE_STATE(newBQ);
// put a space in it so layout will draw the list item
rv = selection->Collapse(newBQ, 0);
@ -3801,9 +3812,10 @@ HTMLEditor::GetPreviousHTMLElementOrTextInternal(nsINode& aNode,
GetPreviousElementOrText(aNode);
}
template<typename PT, typename CT>
nsIContent*
HTMLEditor::GetPreviousHTMLElementOrTextInternal(
const EditorRawDOMPoint& aPoint,
const EditorDOMPointBase<PT, CT>& aPoint,
bool aNoBlockCrossing)
{
if (!GetActiveEditingHost()) {
@ -3824,9 +3836,11 @@ HTMLEditor::GetPreviousEditableHTMLNodeInternal(nsINode& aNode,
GetPreviousEditableNode(aNode);
}
template<typename PT, typename CT>
nsIContent*
HTMLEditor::GetPreviousEditableHTMLNodeInternal(const EditorRawDOMPoint& aPoint,
bool aNoBlockCrossing)
HTMLEditor::GetPreviousEditableHTMLNodeInternal(
const EditorDOMPointBase<PT, CT>& aPoint,
bool aNoBlockCrossing)
{
if (!GetActiveEditingHost()) {
return nullptr;
@ -3846,9 +3860,11 @@ HTMLEditor::GetNextHTMLElementOrTextInternal(nsINode& aNode,
GetNextElementOrText(aNode);
}
template<typename PT, typename CT>
nsIContent*
HTMLEditor::GetNextHTMLElementOrTextInternal(const EditorRawDOMPoint& aPoint,
bool aNoBlockCrossing)
HTMLEditor::GetNextHTMLElementOrTextInternal(
const EditorDOMPointBase<PT, CT>& aPoint,
bool aNoBlockCrossing)
{
if (!GetActiveEditingHost()) {
return nullptr;
@ -3868,9 +3884,11 @@ HTMLEditor::GetNextEditableHTMLNodeInternal(nsINode& aNode,
GetNextEditableNode(aNode);
}
template<typename PT, typename CT>
nsIContent*
HTMLEditor::GetNextEditableHTMLNodeInternal(const EditorRawDOMPoint& aPoint,
bool aNoBlockCrossing)
HTMLEditor::GetNextEditableHTMLNodeInternal(
const EditorDOMPointBase<PT, CT>& aPoint,
bool aNoBlockCrossing)
{
if (!GetActiveEditingHost()) {
return nullptr;

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

@ -423,9 +423,10 @@ public:
* @return Returns inserted point if succeeded.
* Otherwise, the result is not set.
*/
template<typename PT, typename CT>
EditorDOMPoint
InsertNodeIntoProperAncestor(nsIContent& aNode,
const EditorRawDOMPoint& aPointToInsert,
const EditorDOMPointBase<PT, CT>& aPointToInsert,
SplitAtEdges aSplitAtEdges);
/**
@ -934,12 +935,15 @@ protected:
{
return GetPreviousHTMLElementOrTextInternal(aNode, true);
}
nsIContent* GetPreviousHTMLElementOrText(const EditorRawDOMPoint& aPoint)
template<typename PT, typename CT>
nsIContent*
GetPreviousHTMLElementOrText(const EditorDOMPointBase<PT, CT>& aPoint)
{
return GetPreviousHTMLElementOrTextInternal(aPoint, false);
}
template<typename PT, typename CT>
nsIContent*
GetPreviousHTMLElementOrTextInBlock(const EditorRawDOMPoint& aPoint)
GetPreviousHTMLElementOrTextInBlock(const EditorDOMPointBase<PT, CT>& aPoint)
{
return GetPreviousHTMLElementOrTextInternal(aPoint, true);
}
@ -950,8 +954,9 @@ protected:
*/
nsIContent* GetPreviousHTMLElementOrTextInternal(nsINode& aNode,
bool aNoBlockCrossing);
template<typename PT, typename CT>
nsIContent*
GetPreviousHTMLElementOrTextInternal(const EditorRawDOMPoint& aPoint,
GetPreviousHTMLElementOrTextInternal(const EditorDOMPointBase<PT, CT>& aPoint,
bool aNoBlockCrossing);
/**
@ -967,12 +972,15 @@ protected:
{
return GetPreviousEditableHTMLNodeInternal(aNode, true);
}
nsIContent* GetPreviousEditableHTMLNode(const EditorRawDOMPoint& aPoint)
template<typename PT, typename CT>
nsIContent*
GetPreviousEditableHTMLNode(const EditorDOMPointBase<PT, CT>& aPoint)
{
return GetPreviousEditableHTMLNodeInternal(aPoint, false);
}
template<typename PT, typename CT>
nsIContent* GetPreviousEditableHTMLNodeInBlock(
const EditorRawDOMPoint& aPoint)
const EditorDOMPointBase<PT, CT>& aPoint)
{
return GetPreviousEditableHTMLNodeInternal(aPoint, true);
}
@ -983,8 +991,9 @@ protected:
*/
nsIContent* GetPreviousEditableHTMLNodeInternal(nsINode& aNode,
bool aNoBlockCrossing);
template<typename PT, typename CT>
nsIContent* GetPreviousEditableHTMLNodeInternal(
const EditorRawDOMPoint& aPoint,
const EditorDOMPointBase<PT, CT>& aPoint,
bool aNoBlockCrossing);
/**
@ -1005,11 +1014,15 @@ protected:
{
return GetNextHTMLElementOrTextInternal(aNode, true);
}
nsIContent* GetNextHTMLElementOrText(const EditorRawDOMPoint& aPoint)
template<typename PT, typename CT>
nsIContent*
GetNextHTMLElementOrText(const EditorDOMPointBase<PT, CT>& aPoint)
{
return GetNextHTMLElementOrTextInternal(aPoint, false);
}
nsIContent* GetNextHTMLElementOrTextInBlock(const EditorRawDOMPoint& aPoint)
template<typename PT, typename CT>
nsIContent*
GetNextHTMLElementOrTextInBlock(const EditorDOMPointBase<PT, CT>& aPoint)
{
return GetNextHTMLElementOrTextInternal(aPoint, true);
}
@ -1020,8 +1033,10 @@ protected:
*/
nsIContent* GetNextHTMLElementOrTextInternal(nsINode& aNode,
bool aNoBlockCrossing);
nsIContent* GetNextHTMLElementOrTextInternal(const EditorRawDOMPoint& aPoint,
bool aNoBlockCrossing);
template<typename PT, typename CT>
nsIContent*
GetNextHTMLElementOrTextInternal(const EditorDOMPointBase<PT, CT>& aPoint,
bool aNoBlockCrossing);
/**
* GetNextEditableHTMLNode*() methods are similar to
@ -1041,12 +1056,14 @@ protected:
{
return GetNextEditableHTMLNodeInternal(aNode, true);
}
nsIContent* GetNextEditableHTMLNode(const EditorRawDOMPoint& aPoint)
template<typename PT, typename CT>
nsIContent* GetNextEditableHTMLNode(const EditorDOMPointBase<PT, CT>& aPoint)
{
return GetNextEditableHTMLNodeInternal(aPoint, false);
}
template<typename PT, typename CT>
nsIContent* GetNextEditableHTMLNodeInBlock(
const EditorRawDOMPoint& aPoint)
const EditorDOMPointBase<PT, CT>& aPoint)
{
return GetNextEditableHTMLNodeInternal(aPoint, true);
}
@ -1056,9 +1073,10 @@ protected:
* of above methods. Please don't use this method directly.
*/
nsIContent* GetNextEditableHTMLNodeInternal(nsINode& aNode,
bool aNoBlockCrossing);
bool aNoBlockCrossing);
template<typename PT, typename CT>
nsIContent* GetNextEditableHTMLNodeInternal(
const EditorRawDOMPoint& aPoint,
const EditorDOMPointBase<PT, CT>& aPoint,
bool aNoBlockCrossing);
bool IsFirstEditableChild(nsINode* aNode);

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

@ -142,7 +142,7 @@ HTMLEditor::LoadHTML(const nsAString& aInputString)
documentFragment->GetFirstChild();
contentToInsert;
contentToInsert = documentFragment->GetFirstChild()) {
rv = InsertNode(*contentToInsert, pointToInsert.AsRaw());
rv = InsertNode(*contentToInsert, pointToInsert);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -362,8 +362,7 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
// Are we in a text node? If so, split it.
if (pointToInsert.IsInTextNode()) {
SplitNodeResult splitNodeResult =
SplitNodeDeep(*pointToInsert.GetContainerAsContent(),
pointToInsert.AsRaw(),
SplitNodeDeep(*pointToInsert.GetContainerAsContent(), pointToInsert,
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
@ -452,7 +451,7 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
firstChild = curNode->GetFirstChild()) {
EditorDOMPoint insertedPoint =
InsertNodeIntoProperAncestor(
*firstChild, pointToInsert.AsRaw(),
*firstChild, pointToInsert,
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(!insertedPoint.IsSet())) {
break;
@ -494,7 +493,7 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
}
EditorDOMPoint insertedPoint =
InsertNodeIntoProperAncestor(
*firstChild, pointToInsert.AsRaw(),
*firstChild, pointToInsert,
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(!insertedPoint.IsSet())) {
break;
@ -523,7 +522,7 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
firstChild = curNode->GetFirstChild()) {
EditorDOMPoint insertedPoint =
InsertNodeIntoProperAncestor(
*firstChild, pointToInsert.AsRaw(),
*firstChild, pointToInsert,
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(!insertedPoint.IsSet())) {
break;
@ -542,7 +541,7 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
// Try to insert.
EditorDOMPoint insertedPoint =
InsertNodeIntoProperAncestor(
*curNode->AsContent(), pointToInsert.AsRaw(),
*curNode->AsContent(), pointToInsert,
SplitAtEdges::eDoNotCreateEmptyContainer);
if (insertedPoint.IsSet()) {
lastInsertNode = curNode->AsContent();
@ -562,7 +561,7 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
nsCOMPtr<nsINode> oldParent = content->GetParentNode();
insertedPoint =
InsertNodeIntoProperAncestor(
*content->GetParent(), pointToInsert.AsRaw(),
*content->GetParent(), pointToInsert,
SplitAtEdges::eDoNotCreateEmptyContainer);
if (insertedPoint.IsSet()) {
insertedContextParent = oldParent;

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

@ -151,7 +151,7 @@ HTMLEditor::InsertCell(nsIDOMElement* aDOMCell,
// Don't let Rules System change the selection.
AutoTransactionsConserveSelection dontChangeSelection(this);
return InsertNode(*newCell, pointToInsert.AsRaw());
return InsertNode(*newCell, pointToInsert);
}
nsresult

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

@ -22,21 +22,32 @@ namespace mozilla {
using namespace dom;
template already_AddRefed<InsertNodeTransaction>
InsertNodeTransaction::Create(EditorBase& aEditorBase,
nsIContent& aContentToInsert,
const EditorDOMPoint& aPointToInsert);
template already_AddRefed<InsertNodeTransaction>
InsertNodeTransaction::Create(EditorBase& aEditorBase,
nsIContent& aContentToInsert,
const EditorRawDOMPoint& aPointToInsert);
// static
template<typename PT, typename CT>
already_AddRefed<InsertNodeTransaction>
InsertNodeTransaction::Create(EditorBase& aEditorBase,
nsIContent& aContentToInsert,
const EditorRawDOMPoint& aPointToInsert)
const EditorDOMPointBase<PT, CT>& aPointToInsert)
{
RefPtr<InsertNodeTransaction> transaction =
new InsertNodeTransaction(aEditorBase, aContentToInsert, aPointToInsert);
return transaction.forget();
}
template<typename PT, typename CT>
InsertNodeTransaction::InsertNodeTransaction(
EditorBase& aEditorBase,
nsIContent& aContentToInsert,
const EditorRawDOMPoint& aPointToInsert)
const EditorDOMPointBase<PT, CT>& aPointToInsert)
: mContentToInsert(&aContentToInsert)
, mPointToInsert(aPointToInsert)
, mEditorBase(&aEditorBase)

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

@ -23,9 +23,10 @@ class EditorBase;
class InsertNodeTransaction final : public EditTransactionBase
{
protected:
template<typename PT, typename CT>
InsertNodeTransaction(EditorBase& aEditorBase,
nsIContent& aContentToInsert,
const EditorRawDOMPoint& aPointToInsert);
const EditorDOMPointBase<PT, CT>& aPointToInsert);
public:
/**
@ -42,10 +43,11 @@ public:
* @return A InsertNodeTranaction which was initialized
* with the arguments.
*/
template<typename PT, typename CT>
static already_AddRefed<InsertNodeTransaction>
Create(EditorBase& aEditorBase,
nsIContent& aContentToInsert,
const EditorRawDOMPoint& aPointToInsert);
const EditorDOMPointBase<PT, CT>& aPointToInsert);
NS_DECL_ISUPPORTS_INHERITED

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

@ -28,6 +28,16 @@ using namespace dom;
* { {startnode, startoffset} , {endnode, endoffset} } tuples. Can't store
* ranges since dom gravity will possibly change the ranges.
******************************************************************************/
template nsresult
RangeUpdater::SelAdjCreateNode(const EditorDOMPoint& aPoint);
template nsresult
RangeUpdater::SelAdjCreateNode(const EditorRawDOMPoint& aPoint);
template nsresult
RangeUpdater::SelAdjInsertNode(const EditorDOMPoint& aPoint);
template nsresult
RangeUpdater::SelAdjInsertNode(const EditorRawDOMPoint& aPoint);
SelectionState::SelectionState()
{
}
@ -211,8 +221,9 @@ RangeUpdater::DropSelectionState(SelectionState& aSelState)
// gravity methods:
template<typename PT, typename CT>
nsresult
RangeUpdater::SelAdjCreateNode(const EditorRawDOMPoint& aPoint)
RangeUpdater::SelAdjCreateNode(const EditorDOMPointBase<PT, CT>& aPoint)
{
if (mLock) {
// lock set by Will/DidReplaceParent, etc...
@ -243,8 +254,9 @@ RangeUpdater::SelAdjCreateNode(const EditorRawDOMPoint& aPoint)
return NS_OK;
}
template<typename PT, typename CT>
nsresult
RangeUpdater::SelAdjInsertNode(const EditorRawDOMPoint& aPoint)
RangeUpdater::SelAdjInsertNode(const EditorDOMPointBase<PT, CT>& aPoint)
{
return SelAdjCreateNode(aPoint);
}

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

@ -108,8 +108,10 @@ public:
// if you move a node, that corresponds to deleting it and reinserting it.
// DOM Range gravity will promote the selection out of the node on deletion,
// which is not what you want if you know you are reinserting it.
nsresult SelAdjCreateNode(const EditorRawDOMPoint& aPoint);
nsresult SelAdjInsertNode(const EditorRawDOMPoint& aPoint);
template<typename PT, typename CT>
nsresult SelAdjCreateNode(const EditorDOMPointBase<PT, CT>& aPoint);
template<typename PT, typename CT>
nsresult SelAdjInsertNode(const EditorDOMPointBase<PT, CT>& aPoint);
void SelAdjDeleteNode(nsINode* aNode);
nsresult SelAdjSplitNode(nsIContent& aRightNode, nsIContent* aNewLeftNode);
nsresult SelAdjJoinNodes(nsINode& aLeftNode,

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

@ -17,19 +17,31 @@ namespace mozilla {
using namespace dom;
template already_AddRefed<SplitNodeTransaction>
SplitNodeTransaction::Create(
EditorBase& aEditorBase,
const EditorDOMPoint& aStartOfRightNode);
template already_AddRefed<SplitNodeTransaction>
SplitNodeTransaction::Create(
EditorBase& aEditorBase,
const EditorRawDOMPoint& aStartOfRightNode);
// static
template<typename PT, typename CT>
already_AddRefed<SplitNodeTransaction>
SplitNodeTransaction::Create(EditorBase& aEditorBase,
const EditorRawDOMPoint& aStartOfRightNode)
SplitNodeTransaction::Create(
EditorBase& aEditorBase,
const EditorDOMPointBase<PT, CT>& aStartOfRightNode)
{
RefPtr<SplitNodeTransaction> transaction =
new SplitNodeTransaction(aEditorBase, aStartOfRightNode);
return transaction.forget();
}
template<typename PT, typename CT>
SplitNodeTransaction::SplitNodeTransaction(
EditorBase& aEditorBase,
const EditorRawDOMPoint& aStartOfRightNode)
const EditorDOMPointBase<PT, CT>& aStartOfRightNode)
: mEditorBase(&aEditorBase)
, mStartOfRightNode(aStartOfRightNode)
{

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

@ -27,8 +27,9 @@ class EditorBase;
class SplitNodeTransaction final : public EditTransactionBase
{
private:
template<typename PT, typename CT>
SplitNodeTransaction(EditorBase& aEditorBase,
const EditorRawDOMPoint& aStartOfRightNode);
const EditorDOMPointBase<PT, CT>& aStartOfRightNode);
public:
/**
@ -42,9 +43,10 @@ public:
* next sibling. And the point will be start
* of the right node.
*/
template<typename PT, typename CT>
static already_AddRefed<SplitNodeTransaction>
Create(EditorBase& aEditorBase,
const EditorRawDOMPoint& aStartOfRightNode);
const EditorDOMPointBase<PT, CT>& aStartOfRightNode);
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SplitNodeTransaction,

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

@ -228,7 +228,9 @@ protected:
* inserted.
* @return Returns created <br> element.
*/
already_AddRefed<Element> CreateBR(const EditorRawDOMPoint& aPointToInsert)
template<typename PT, typename CT>
already_AddRefed<Element>
CreateBR(const EditorDOMPointBase<PT, CT>& aPointToInsert)
{
return CreateBRInternal(aPointToInsert, false);
}
@ -240,7 +242,9 @@ protected:
* inserted.
* @return Returns created moz-<br> element.
*/
already_AddRefed<Element> CreateMozBR(const EditorRawDOMPoint& aPointToInsert)
template<typename PT, typename CT>
already_AddRefed<Element>
CreateMozBR(const EditorDOMPointBase<PT, CT>& aPointToInsert)
{
return CreateBRInternal(aPointToInsert, true);
}

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

@ -63,6 +63,13 @@ namespace mozilla {
using namespace dom;
template already_AddRefed<Element>
TextEditor::CreateBR(const EditorDOMPoint& aPointToInsert,
EDirection aSelect);
template already_AddRefed<Element>
TextEditor::CreateBR(const EditorRawDOMPoint& aPointToInsert,
EDirection aSelect);
TextEditor::TextEditor()
: mWrapColumn(0)
, mMaxTextLength(-1)
@ -408,8 +415,9 @@ TextEditor::TypedText(const nsAString& aString, ETypingAction aAction)
}
}
template<typename PT, typename CT>
already_AddRefed<Element>
TextEditor::CreateBR(const EditorRawDOMPoint& aPointToInsert,
TextEditor::CreateBR(const EditorDOMPointBase<PT, CT>& aPointToInsert,
EDirection aSelect /* = eNone */)
{
RefPtr<Selection> selection = GetSelection();
@ -420,9 +428,10 @@ TextEditor::CreateBR(const EditorRawDOMPoint& aPointToInsert,
return CreateBRImpl(*selection, aPointToInsert, aSelect);
}
template<typename PT, typename CT>
already_AddRefed<Element>
TextEditor::CreateBRImpl(Selection& aSelection,
const EditorRawDOMPoint& aPointToInsert,
const EditorDOMPointBase<PT, CT>& aPointToInsert,
EDirection aSelect)
{
if (NS_WARN_IF(!aPointToInsert.IsSet())) {
@ -462,7 +471,7 @@ TextEditor::CreateBRImpl(Selection& aSelection,
pointInContainer.Set(aPointToInsert.GetContainer());
}
// Create a <br> node.
newBRElement = CreateNode(nsGkAtoms::br, pointInContainer.AsRaw());
newBRElement = CreateNode(nsGkAtoms::br, pointInContainer);
if (NS_WARN_IF(!newBRElement)) {
return nullptr;
}

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

@ -213,8 +213,10 @@ protected:
* @return The new <br> node. If failed to create new <br>
* node, returns nullptr.
*/
already_AddRefed<Element> CreateBR(const EditorRawDOMPoint& aPointToInsert,
EDirection aSelect = eNone);
template<typename PT, typename CT>
already_AddRefed<Element>
CreateBR(const EditorDOMPointBase<PT, CT>& aPointToInsert,
EDirection aSelect = eNone);
/**
* CreateBRImpl() creates a <br> element and inserts it before aPointToInsert.
@ -233,9 +235,10 @@ protected:
* @return The new <br> node. If failed to create new
* <br> node, returns nullptr.
*/
template<typename PT, typename CT>
already_AddRefed<Element>
CreateBRImpl(Selection& aSelection,
const EditorRawDOMPoint& aPointToInsert,
const EditorDOMPointBase<PT, CT>& aPointToInsert,
EDirection aSelect);
/**

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

@ -54,6 +54,24 @@ template void WSRunObject::NextVisibleNode(const EditorRawDOMPoint& aPoint,
nsCOMPtr<nsINode>* outVisNode,
int32_t* outVisOffset,
WSType* outType);
template already_AddRefed<Element>
WSRunObject::InsertBreak(Selection& aSelection,
const EditorDOMPoint& aPointToInsert,
nsIEditor::EDirection aSelect);
template already_AddRefed<Element>
WSRunObject::InsertBreak(Selection& aSelection,
const EditorRawDOMPoint& aPointToInsert,
nsIEditor::EDirection aSelect);
template nsresult
WSRunObject::InsertText(nsIDocument& aDocument,
const nsAString& aStringToInsert,
const EditorDOMPoint& aPointToInsert,
EditorRawDOMPoint* aPointAfterInsertedString);
template nsresult
WSRunObject::InsertText(nsIDocument& aDocument,
const nsAString& aStringToInsert,
const EditorRawDOMPoint& aPointToInsert,
EditorRawDOMPoint* aPointAfterInsertedString);
template<typename PT, typename CT>
WSRunObject::WSRunObject(HTMLEditor* aHTMLEditor,
@ -176,9 +194,10 @@ WSRunObject::PrepareToSplitAcrossBlocks(HTMLEditor* aHTMLEditor,
return wsObj.PrepareToSplitAcrossBlocksPriv();
}
template<typename PT, typename CT>
already_AddRefed<Element>
WSRunObject::InsertBreak(Selection& aSelection,
const EditorRawDOMPoint& aPointToInsert,
const EditorDOMPointBase<PT, CT>& aPointToInsert,
nsIEditor::EDirection aSelect)
{
if (NS_WARN_IF(!aPointToInsert.IsSet())) {
@ -205,14 +224,14 @@ WSRunObject::InsertBreak(Selection& aSelection,
// Delete the leading ws that is after insertion point. We don't
// have to (it would still not be significant after br), but it's
// just more aesthetically pleasing to.
nsresult rv = DeleteRange(pointToInsert.AsRaw(), afterRun->EndPoint());
nsresult rv = DeleteRange(pointToInsert, afterRun->EndPoint());
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
} else if (afterRun->mType == WSType::normalWS) {
// Need to determine if break at front of non-nbsp run. If so, convert
// run to nbsp.
WSPoint thePoint = GetNextCharPoint(pointToInsert.AsRaw());
WSPoint thePoint = GetNextCharPoint(pointToInsert);
if (thePoint.mTextNode && nsCRT::IsAsciiSpace(thePoint.mChar)) {
WSPoint prevPoint = GetPreviousCharPoint(thePoint);
if (!prevPoint.mTextNode ||
@ -232,14 +251,14 @@ WSRunObject::InsertBreak(Selection& aSelection,
} else if (beforeRun->mType & WSType::trailingWS) {
// Need to delete the trailing ws that is before insertion point, because it
// would become significant after break inserted.
nsresult rv = DeleteRange(beforeRun->StartPoint(), pointToInsert.AsRaw());
nsresult rv = DeleteRange(beforeRun->StartPoint(), pointToInsert);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
} else if (beforeRun->mType == WSType::normalWS) {
// Try to change an nbsp to a space, just to prevent nbsp proliferation
nsresult rv =
ReplacePreviousNBSPIfUnncessary(beforeRun, pointToInsert.AsRaw());
ReplacePreviousNBSPIfUnncessary(beforeRun, pointToInsert);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
@ -247,17 +266,18 @@ WSRunObject::InsertBreak(Selection& aSelection,
}
RefPtr<Element> newBRElement =
mHTMLEditor->CreateBRImpl(aSelection, pointToInsert.AsRaw(), aSelect);
mHTMLEditor->CreateBRImpl(aSelection, pointToInsert, aSelect);
if (NS_WARN_IF(!newBRElement)) {
return nullptr;
}
return newBRElement.forget();
}
template<typename PT, typename CT>
nsresult
WSRunObject::InsertText(nsIDocument& aDocument,
const nsAString& aStringToInsert,
const EditorRawDOMPoint& aPointToInsert,
const EditorDOMPointBase<PT, CT>& aPointToInsert,
EditorRawDOMPoint* aPointAfterInsertedString)
{
// MOOSE: for now, we always assume non-PRE formatting. Fix this later.
@ -297,7 +317,7 @@ WSRunObject::InsertText(nsIDocument& aDocument,
} else if (afterRun->mType & WSType::leadingWS) {
// Delete the leading ws that is after insertion point, because it
// would become significant after text inserted.
nsresult rv = DeleteRange(pointToInsert.AsRaw(), afterRun->EndPoint());
nsresult rv = DeleteRange(pointToInsert, afterRun->EndPoint());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -315,7 +335,7 @@ WSRunObject::InsertText(nsIDocument& aDocument,
} else if (beforeRun->mType & WSType::trailingWS) {
// Need to delete the trailing ws that is before insertion point, because
// it would become significant after text inserted.
nsresult rv = DeleteRange(beforeRun->StartPoint(), pointToInsert.AsRaw());
nsresult rv = DeleteRange(beforeRun->StartPoint(), pointToInsert);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -323,7 +343,7 @@ WSRunObject::InsertText(nsIDocument& aDocument,
// Try to change an nbsp to a space, if possible, just to prevent nbsp
// proliferation
nsresult rv =
ReplacePreviousNBSPIfUnncessary(beforeRun, pointToInsert.AsRaw());
ReplacePreviousNBSPIfUnncessary(beforeRun, pointToInsert);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -342,7 +362,7 @@ WSRunObject::InsertText(nsIDocument& aDocument,
if (beforeRun->mType & WSType::leadingWS) {
theString.SetCharAt(kNBSP, 0);
} else if (beforeRun->mType & WSType::normalWS) {
WSPoint wspoint = GetPreviousCharPoint(pointToInsert.AsRaw());
WSPoint wspoint = GetPreviousCharPoint(pointToInsert);
if (wspoint.mTextNode && nsCRT::IsAsciiSpace(wspoint.mChar)) {
theString.SetCharAt(kNBSP, 0);
}
@ -361,7 +381,7 @@ WSRunObject::InsertText(nsIDocument& aDocument,
if (afterRun->mType & WSType::trailingWS) {
theString.SetCharAt(kNBSP, lastCharIndex);
} else if (afterRun->mType & WSType::normalWS) {
WSPoint wspoint = GetNextCharPoint(pointToInsert.AsRaw());
WSPoint wspoint = GetNextCharPoint(pointToInsert);
if (wspoint.mTextNode && nsCRT::IsAsciiSpace(wspoint.mChar)) {
theString.SetCharAt(kNBSP, lastCharIndex);
}
@ -391,7 +411,7 @@ WSRunObject::InsertText(nsIDocument& aDocument,
// Ready, aim, fire!
nsresult rv =
mHTMLEditor->InsertTextImpl(aDocument, theString, pointToInsert.AsRaw(),
mHTMLEditor->InsertTextImpl(aDocument, theString, pointToInsert,
aPointAfterInsertedString);
if (NS_WARN_IF(NS_FAILED(rv))) {
return NS_OK;
@ -1325,9 +1345,10 @@ WSRunObject::PrepareToSplitAcrossBlocksPriv()
return NS_OK;
}
template<typename PT1, typename CT1, typename PT2, typename CT2>
nsresult
WSRunObject::DeleteRange(const EditorRawDOMPoint& aStartPoint,
const EditorRawDOMPoint& aEndPoint)
WSRunObject::DeleteRange(const EditorDOMPointBase<PT1, CT1>& aStartPoint,
const EditorDOMPointBase<PT2, CT2>& aEndPoint)
{
if (NS_WARN_IF(!aStartPoint.IsSet()) ||
NS_WARN_IF(!aEndPoint.IsSet())) {
@ -1908,9 +1929,11 @@ WSRunObject::CheckTrailingNBSPOfRun(WSFragment *aRun)
return NS_OK;
}
template<typename PT, typename CT>
nsresult
WSRunObject::ReplacePreviousNBSPIfUnncessary(WSFragment* aRun,
const EditorRawDOMPoint& aPoint)
WSRunObject::ReplacePreviousNBSPIfUnncessary(
WSFragment* aRun,
const EditorDOMPointBase<PT, CT>& aPoint)
{
if (NS_WARN_IF(!aRun) ||
NS_WARN_IF(!aPoint.IsSet())) {

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

@ -230,9 +230,10 @@ public:
* @return The new <br> node. If failed to create new <br>
* node, returns nullptr.
*/
template<typename PT, typename CT>
already_AddRefed<dom::Element>
InsertBreak(Selection& aSelection,
const EditorRawDOMPoint& aPointToInsert,
const EditorDOMPointBase<PT, CT>& aPointToInsert,
nsIEditor::EDirection aSelect);
/**
@ -256,9 +257,10 @@ public:
* does nothing during composition, returns NS_OK.
* Otherwise, an error code.
*/
template<typename PT, typename CT>
nsresult InsertText(nsIDocument& aDocument,
const nsAString& aStringToInsert,
const EditorRawDOMPoint& aPointToInsert,
const EditorDOMPointBase<PT, CT>& aPointToInsert,
EditorRawDOMPoint* aPointAfterInsertedString = nullptr);
// DeleteWSBackward deletes a single visible piece of ws before the ws
@ -381,8 +383,9 @@ protected:
* When aEndPoint is in a text node, removes the text data before the point.
* Removes any nodes between them.
*/
nsresult DeleteRange(const EditorRawDOMPoint& aStartPoint,
const EditorRawDOMPoint& aEndPoint);
template<typename PT1, typename CT1, typename PT2, typename CT2>
nsresult DeleteRange(const EditorDOMPointBase<PT1, CT1>& aStartPoint,
const EditorDOMPointBase<PT2, CT2>& aEndPoint);
/**
* GetNextCharPoint() returns next character's point of aPoint. If there is
@ -486,8 +489,10 @@ protected:
* @param aPoint Current insertion point. Its previous character is
* unnecessary NBSP will be checked.
*/
nsresult ReplacePreviousNBSPIfUnncessary(WSFragment* aRun,
const EditorRawDOMPoint& aPoint);
template<typename PT, typename CT>
nsresult
ReplacePreviousNBSPIfUnncessary(WSFragment* aRun,
const EditorDOMPointBase<PT, CT>& aPoint);
nsresult CheckLeadingNBSP(WSFragment* aRun, nsINode* aNode,
int32_t aOffset);