Bug 1574852 - part 87: Move `HTMLEditRules::SelectionEndpointInNode()` to `HTMLEditor` r=m_kato

Differential Revision: https://phabricator.services.mozilla.com/D44791

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-09-09 05:21:04 +00:00
Родитель b1ead5a6f3
Коммит a8504046a4
3 изменённых файлов: 21 добавлений и 32 удалений

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

@ -10017,14 +10017,8 @@ nsresult HTMLEditRules::RemoveEmptyNodesInChangedRange() {
// These node types are candidates if selection is not in them. If
// it is one of these, don't delete if selection inside. This is so
// we can create empty headings, etc., for the user to type into.
bool isSelectionEndInNode;
rv = SelectionEndpointInNode(node, &isSelectionEndInNode);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (!isSelectionEndInNode) {
isCandidate = true;
}
isCandidate = !HTMLEditorRef().StartOrEndOfSelectionRangesIsIn(
*node->AsContent());
}
}
@ -10098,25 +10092,18 @@ nsresult HTMLEditRules::RemoveEmptyNodesInChangedRange() {
return NS_OK;
}
nsresult HTMLEditRules::SelectionEndpointInNode(nsINode* aNode, bool* aResult) {
MOZ_ASSERT(IsEditorDataAvailable());
bool HTMLEditor::StartOrEndOfSelectionRangesIsIn(nsIContent& aContent) const {
MOZ_ASSERT(IsEditActionDataAvailable());
NS_ENSURE_TRUE(aNode && aResult, NS_ERROR_NULL_POINTER);
*aResult = false;
uint32_t rangeCount = SelectionRefPtr()->RangeCount();
for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; ++rangeIdx) {
RefPtr<nsRange> range = SelectionRefPtr()->GetRangeAt(rangeIdx);
for (uint32_t i = 0; i < SelectionRefPtr()->RangeCount(); ++i) {
nsRange* range = SelectionRefPtr()->GetRangeAt(i);
nsINode* startContainer = range->GetStartContainer();
if (startContainer) {
if (aNode == startContainer) {
*aResult = true;
return NS_OK;
if (&aContent == startContainer) {
return true;
}
if (EditorUtils::IsDescendantOf(*startContainer, *aNode)) {
*aResult = true;
return NS_OK;
if (EditorUtils::IsDescendantOf(*startContainer, aContent)) {
return true;
}
}
nsINode* endContainer = range->GetEndContainer();
@ -10124,17 +10111,15 @@ nsresult HTMLEditRules::SelectionEndpointInNode(nsINode* aNode, bool* aResult) {
continue;
}
if (endContainer) {
if (aNode == endContainer) {
*aResult = true;
return NS_OK;
if (&aContent == endContainer) {
return true;
}
if (EditorUtils::IsDescendantOf(*endContainer, *aNode)) {
*aResult = true;
return NS_OK;
if (EditorUtils::IsDescendantOf(*endContainer, aContent)) {
return true;
}
}
}
return NS_OK;
return false;
}
nsresult HTMLEditor::LiftUpListItemElement(

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

@ -249,8 +249,6 @@ class HTMLEditRules : public TextEditRules {
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult RemoveEmptyNodesInChangedRange();
nsresult SelectionEndpointInNode(nsINode* aNode, bool* aResult);
/**
* ConfirmSelectionInBody() makes sure that Selection is in editor root
* element typically <body> element (see HTMLEditor::UpdateRootElement())

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

@ -2569,6 +2569,12 @@ class HTMLEditor final : public TextEditor,
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE EditActionResult
AlignAsSubAction(const nsAString& aAlignType);
/**
* StartOrEndOfSelectionRangesIsIn() returns true if start or end of one
* of selection ranges is in aContent.
*/
bool StartOrEndOfSelectionRangesIsIn(nsIContent& aContent) const;
protected: // Called by helper classes.
virtual void OnStartToHandleTopLevelEditSubAction(
EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;