зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
b1ead5a6f3
Коммит
a8504046a4
|
@ -10017,14 +10017,8 @@ nsresult HTMLEditRules::RemoveEmptyNodesInChangedRange() {
|
||||||
// These node types are candidates if selection is not in them. If
|
// 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
|
// 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.
|
// we can create empty headings, etc., for the user to type into.
|
||||||
bool isSelectionEndInNode;
|
isCandidate = !HTMLEditorRef().StartOrEndOfSelectionRangesIsIn(
|
||||||
rv = SelectionEndpointInNode(node, &isSelectionEndInNode);
|
*node->AsContent());
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
if (!isSelectionEndInNode) {
|
|
||||||
isCandidate = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10098,25 +10092,18 @@ nsresult HTMLEditRules::RemoveEmptyNodesInChangedRange() {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult HTMLEditRules::SelectionEndpointInNode(nsINode* aNode, bool* aResult) {
|
bool HTMLEditor::StartOrEndOfSelectionRangesIsIn(nsIContent& aContent) const {
|
||||||
MOZ_ASSERT(IsEditorDataAvailable());
|
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||||
|
|
||||||
NS_ENSURE_TRUE(aNode && aResult, NS_ERROR_NULL_POINTER);
|
for (uint32_t i = 0; i < SelectionRefPtr()->RangeCount(); ++i) {
|
||||||
|
nsRange* range = SelectionRefPtr()->GetRangeAt(i);
|
||||||
*aResult = false;
|
|
||||||
|
|
||||||
uint32_t rangeCount = SelectionRefPtr()->RangeCount();
|
|
||||||
for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; ++rangeIdx) {
|
|
||||||
RefPtr<nsRange> range = SelectionRefPtr()->GetRangeAt(rangeIdx);
|
|
||||||
nsINode* startContainer = range->GetStartContainer();
|
nsINode* startContainer = range->GetStartContainer();
|
||||||
if (startContainer) {
|
if (startContainer) {
|
||||||
if (aNode == startContainer) {
|
if (&aContent == startContainer) {
|
||||||
*aResult = true;
|
return true;
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
if (EditorUtils::IsDescendantOf(*startContainer, *aNode)) {
|
if (EditorUtils::IsDescendantOf(*startContainer, aContent)) {
|
||||||
*aResult = true;
|
return true;
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nsINode* endContainer = range->GetEndContainer();
|
nsINode* endContainer = range->GetEndContainer();
|
||||||
|
@ -10124,17 +10111,15 @@ nsresult HTMLEditRules::SelectionEndpointInNode(nsINode* aNode, bool* aResult) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (endContainer) {
|
if (endContainer) {
|
||||||
if (aNode == endContainer) {
|
if (&aContent == endContainer) {
|
||||||
*aResult = true;
|
return true;
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
if (EditorUtils::IsDescendantOf(*endContainer, *aNode)) {
|
if (EditorUtils::IsDescendantOf(*endContainer, aContent)) {
|
||||||
*aResult = true;
|
return true;
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NS_OK;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult HTMLEditor::LiftUpListItemElement(
|
nsresult HTMLEditor::LiftUpListItemElement(
|
||||||
|
|
|
@ -249,8 +249,6 @@ class HTMLEditRules : public TextEditRules {
|
||||||
MOZ_CAN_RUN_SCRIPT
|
MOZ_CAN_RUN_SCRIPT
|
||||||
MOZ_MUST_USE nsresult RemoveEmptyNodesInChangedRange();
|
MOZ_MUST_USE nsresult RemoveEmptyNodesInChangedRange();
|
||||||
|
|
||||||
nsresult SelectionEndpointInNode(nsINode* aNode, bool* aResult);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ConfirmSelectionInBody() makes sure that Selection is in editor root
|
* ConfirmSelectionInBody() makes sure that Selection is in editor root
|
||||||
* element typically <body> element (see HTMLEditor::UpdateRootElement())
|
* element typically <body> element (see HTMLEditor::UpdateRootElement())
|
||||||
|
|
|
@ -2569,6 +2569,12 @@ class HTMLEditor final : public TextEditor,
|
||||||
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE EditActionResult
|
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE EditActionResult
|
||||||
AlignAsSubAction(const nsAString& aAlignType);
|
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.
|
protected: // Called by helper classes.
|
||||||
virtual void OnStartToHandleTopLevelEditSubAction(
|
virtual void OnStartToHandleTopLevelEditSubAction(
|
||||||
EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;
|
EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче