mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 15:55:16 +00:00
Bug 1574852 - part 88: Move HTMLEditRules::FindNearEditableNode()
to HTMLEditor
r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D44792 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
a8504046a4
commit
9a7cb5f3c8
@ -223,6 +223,10 @@ template Element* HTMLEditor::GetInvisibleBRElementAt(
|
||||
const EditorDOMPoint& aPoint);
|
||||
template Element* HTMLEditor::GetInvisibleBRElementAt(
|
||||
const EditorRawDOMPoint& aPoint);
|
||||
template nsIContent* HTMLEditor::FindNearEditableContent(
|
||||
const EditorDOMPoint& aPoint, nsIEditor::EDirection aDirection);
|
||||
template nsIContent* HTMLEditor::FindNearEditableContent(
|
||||
const EditorRawDOMPoint& aPoint, nsIEditor::EDirection aDirection);
|
||||
|
||||
HTMLEditRules::HTMLEditRules() : mHTMLEditor(nullptr), mInitialized(false) {
|
||||
mIsHTMLEditRules = true;
|
||||
@ -9850,7 +9854,7 @@ nsresult HTMLEditRules::AdjustSelection(nsIEditor::EDirection aAction) {
|
||||
|
||||
// look for a nearby text node.
|
||||
// prefer the correct direction.
|
||||
nearNode = FindNearEditableNode(point, aAction);
|
||||
nearNode = HTMLEditorRef().FindNearEditableContent(point, aAction);
|
||||
if (!nearNode) {
|
||||
return NS_OK;
|
||||
}
|
||||
@ -9869,25 +9873,21 @@ nsresult HTMLEditRules::AdjustSelection(nsIEditor::EDirection aAction) {
|
||||
}
|
||||
|
||||
template <typename PT, typename CT>
|
||||
nsIContent* HTMLEditRules::FindNearEditableNode(
|
||||
nsIContent* HTMLEditor::FindNearEditableContent(
|
||||
const EditorDOMPointBase<PT, CT>& aPoint,
|
||||
nsIEditor::EDirection aDirection) {
|
||||
MOZ_ASSERT(IsEditorDataAvailable());
|
||||
|
||||
if (NS_WARN_IF(!aPoint.IsSet())) {
|
||||
return nullptr;
|
||||
}
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
MOZ_ASSERT(aPoint.IsSetAndValid());
|
||||
|
||||
nsIContent* nearNode = nullptr;
|
||||
nsIContent* editableContent = nullptr;
|
||||
if (aDirection == nsIEditor::ePrevious) {
|
||||
nearNode = HTMLEditorRef().GetPreviousEditableHTMLNode(aPoint);
|
||||
if (!nearNode) {
|
||||
editableContent = GetPreviousEditableHTMLNode(aPoint);
|
||||
if (!editableContent) {
|
||||
return nullptr; // Not illegal.
|
||||
}
|
||||
} else {
|
||||
nearNode = HTMLEditorRef().GetNextEditableHTMLNode(aPoint);
|
||||
if (NS_WARN_IF(!nearNode)) {
|
||||
editableContent = GetNextEditableHTMLNode(aPoint);
|
||||
if (NS_WARN_IF(!editableContent)) {
|
||||
// Perhaps, illegal because the node pointed by aPoint isn't editable
|
||||
// and nobody of previous nodes is editable.
|
||||
return nullptr;
|
||||
@ -9896,32 +9896,32 @@ nsIContent* HTMLEditRules::FindNearEditableNode(
|
||||
|
||||
// scan in the right direction until we find an eligible text node,
|
||||
// but don't cross any breaks, images, or table elements.
|
||||
// XXX This comment sounds odd. |nearNode| may have already crossed breaks
|
||||
// and/or images.
|
||||
while (nearNode && !(EditorBase::IsTextNode(nearNode) ||
|
||||
TextEditUtils::IsBreak(nearNode) ||
|
||||
HTMLEditUtils::IsImage(nearNode))) {
|
||||
// XXX This comment sounds odd. editableContent may have already crossed
|
||||
// breaks and/or images if they are non-editable.
|
||||
while (editableContent && !EditorBase::IsTextNode(editableContent) &&
|
||||
!TextEditUtils::IsBreak(editableContent) &&
|
||||
!HTMLEditUtils::IsImage(editableContent)) {
|
||||
if (aDirection == nsIEditor::ePrevious) {
|
||||
nearNode = HTMLEditorRef().GetPreviousEditableHTMLNode(*nearNode);
|
||||
if (NS_WARN_IF(!nearNode)) {
|
||||
editableContent = GetPreviousEditableHTMLNode(*editableContent);
|
||||
if (NS_WARN_IF(!editableContent)) {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
nearNode = HTMLEditorRef().GetNextEditableHTMLNode(*nearNode);
|
||||
if (NS_WARN_IF(!nearNode)) {
|
||||
editableContent = GetNextEditableHTMLNode(*editableContent);
|
||||
if (NS_WARN_IF(!editableContent)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// don't cross any table elements
|
||||
if (HTMLEditor::NodesInDifferentTableElements(*nearNode,
|
||||
if (HTMLEditor::NodesInDifferentTableElements(*editableContent,
|
||||
*aPoint.GetContainer())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// otherwise, ok, we have found a good spot to put the selection
|
||||
return nearNode;
|
||||
return editableContent;
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -219,23 +219,6 @@ class HTMLEditRules : public TextEditRules {
|
||||
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult
|
||||
AdjustSelection(nsIEditor::EDirection aAction);
|
||||
|
||||
/**
|
||||
* FindNearEditableNode() tries to find an editable node near aPoint.
|
||||
*
|
||||
* @param aPoint The DOM point where to start to search from.
|
||||
* @param aDirection If nsIEditor::ePrevious is set, this searches an
|
||||
* editable node from next nodes. Otherwise, from
|
||||
* previous nodes.
|
||||
* @return If found, returns non-nullptr. Otherwise, nullptr.
|
||||
* Note that if found node is in different table element,
|
||||
* this returns nullptr.
|
||||
* And also if aDirection is not nsIEditor::ePrevious,
|
||||
* the result may be the node pointed by aPoint.
|
||||
*/
|
||||
template <typename PT, typename CT>
|
||||
nsIContent* FindNearEditableNode(const EditorDOMPointBase<PT, CT>& aPoint,
|
||||
nsIEditor::EDirection aDirection);
|
||||
|
||||
/**
|
||||
* RemoveEmptyNodesInChangedRange() removes all empty nodes in
|
||||
* TopLevelEditSubActionData::mChangedRange. However, if mail-cite node has
|
||||
|
@ -2575,6 +2575,23 @@ class HTMLEditor final : public TextEditor,
|
||||
*/
|
||||
bool StartOrEndOfSelectionRangesIsIn(nsIContent& aContent) const;
|
||||
|
||||
/**
|
||||
* FindNearEditableContent() tries to find an editable node near aPoint.
|
||||
*
|
||||
* @param aPoint The DOM point where to start to search from.
|
||||
* @param aDirection If nsIEditor::ePrevious is set, this searches an
|
||||
* editable node from next nodes. Otherwise, from
|
||||
* previous nodes.
|
||||
* @return If found, returns non-nullptr. Otherwise, nullptr.
|
||||
* Note that if found node is in different table element,
|
||||
* this returns nullptr.
|
||||
* And also if aDirection is not nsIEditor::ePrevious,
|
||||
* the result may be the node pointed by aPoint.
|
||||
*/
|
||||
template <typename PT, typename CT>
|
||||
nsIContent* FindNearEditableContent(const EditorDOMPointBase<PT, CT>& aPoint,
|
||||
nsIEditor::EDirection aDirection);
|
||||
|
||||
protected: // Called by helper classes.
|
||||
virtual void OnStartToHandleTopLevelEditSubAction(
|
||||
EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user