summaryrefslogtreecommitdiffstats
path: root/editor
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-07-31 14:26:18 +0200
committerGitHub <noreply@github.com>2020-07-31 14:26:18 +0200
commit091749192cc7595a0013850fb450a5c1b6dde20b (patch)
tree6559c7577a5d15203e488742ac0b32ed278ece56 /editor
parent0afbef750e655a61b4f76d76d59be9339d9acbd9 (diff)
parent392aa3987bbbb3704289c70412c429001e41960d (diff)
downloadUXP-091749192cc7595a0013850fb450a5c1b6dde20b.tar
UXP-091749192cc7595a0013850fb450a5c1b6dde20b.tar.gz
UXP-091749192cc7595a0013850fb450a5c1b6dde20b.tar.lz
UXP-091749192cc7595a0013850fb450a5c1b6dde20b.tar.xz
UXP-091749192cc7595a0013850fb450a5c1b6dde20b.zip
Merge pull request #1618 from g4jc/libeditor_patch
Clean up GetTextNode into TextEditRules.
Diffstat (limited to 'editor')
-rw-r--r--editor/libeditor/TextEditRules.cpp34
1 files changed, 14 insertions, 20 deletions
diff --git a/editor/libeditor/TextEditRules.cpp b/editor/libeditor/TextEditRules.cpp
index 35d4a2f3d..4ecaff722 100644
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -25,7 +25,6 @@
#include "nsError.h"
#include "nsGkAtoms.h"
#include "nsIContent.h"
-#include "nsIDOMCharacterData.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMNode.h"
@@ -479,26 +478,24 @@ TextEditRules::CollapseSelectionToTrailingBRIfNeeded(Selection* aSelection)
return NS_OK;
}
-static inline already_AddRefed<nsIDOMNode>
-GetTextNode(Selection* selection,
- EditorBase* editor)
+static inline already_AddRefed<nsINode>
+GetTextNode(Selection* selection)
{
int32_t selOffset;
- nsCOMPtr<nsIDOMNode> selNode;
+ nsCOMPtr<nsINode> selNode;
nsresult rv =
- editor->GetStartNodeAndOffset(selection,
- getter_AddRefs(selNode), &selOffset);
+ EditorBase::GetStartNodeAndOffset(selection,
+ getter_AddRefs(selNode), &selOffset);
NS_ENSURE_SUCCESS(rv, nullptr);
- if (!editor->IsTextNode(selNode)) {
- // Get an nsINode from the nsIDOMNode
- nsCOMPtr<nsINode> node = do_QueryInterface(selNode);
- // if node is null, return it to indicate there's no text
- NS_ENSURE_TRUE(node, nullptr);
+ if (!EditorBase::IsTextNode(selNode)) {
// This should be the root node, walk the tree looking for text nodes
RefPtr<NodeIterator> iter =
- new NodeIterator(node, nsIDOMNodeFilter::SHOW_TEXT, NodeFilterHolder());
- while (!editor->IsTextNode(selNode)) {
- if (NS_FAILED(iter->NextNode(getter_AddRefs(selNode))) || !selNode) {
+ new NodeIterator(selNode, nsIDOMNodeFilter::SHOW_TEXT,
+ NodeFilterHolder());
+ while (!EditorBase::IsTextNode(selNode)) {
+ IgnoredErrorResult rv;
+ selNode = iter->NextNode(rv);
+ if (!selNode) {
return nullptr;
}
}
@@ -1382,13 +1379,10 @@ TextEditRules::HideLastPWInput()
nsContentUtils::GetSelectionInTextControl(selection, mTextEditor->GetRoot(),
start, end);
- nsCOMPtr<nsIDOMNode> selNode = GetTextNode(selection, mTextEditor);
+ nsCOMPtr<nsINode> selNode = GetTextNode(selection);
NS_ENSURE_TRUE(selNode, NS_OK);
- nsCOMPtr<nsIDOMCharacterData> nodeAsText(do_QueryInterface(selNode));
- NS_ENSURE_TRUE(nodeAsText, NS_OK);
-
- nodeAsText->ReplaceData(mLastStart, mLastLength, hiddenText);
+ selNode->GetAsText()->ReplaceData(mLastStart, mLastLength, hiddenText);
selection->Collapse(selNode, start);
if (start != end) {
selection->Extend(selNode, end);