Bug 1391978 - Part 4. Replace nsISelection::GetFocusNode with Selection::GetFocusNode. r?masayuki
MozReview-Commit-ID: GFtkRvsFaYI
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -2466,19 +2466,17 @@ HTMLEditor::GetSelectedElement(const nsA
nsCOMPtr<nsIDOMNode> anchorNode;
rv = selection->GetAnchorNode(getter_AddRefs(anchorNode));
NS_ENSURE_SUCCESS(rv, rv);
int32_t anchorOffset = -1;
if (anchorNode) {
selection->GetAnchorOffset(&anchorOffset);
}
- nsCOMPtr<nsIDOMNode> focusNode;
- rv = selection->GetFocusNode(getter_AddRefs(focusNode));
- NS_ENSURE_SUCCESS(rv, rv);
+ nsCOMPtr<nsINode> focusNode = selection->GetFocusNode();
int32_t focusOffset = -1;
if (focusNode) {
selection->GetFocusOffset(&focusOffset);
}
// Link node must be the same for both ends of selection
if (NS_SUCCEEDED(rv) && anchorNode) {
nsCOMPtr<nsIDOMElement> parentLinkOfAnchor;
@@ -2489,17 +2487,17 @@ HTMLEditor::GetSelectedElement(const nsA
if (NS_SUCCEEDED(rv) && parentLinkOfAnchor) {
if (isCollapsed) {
// We have just a caret in the link
bNodeFound = true;
} else if (focusNode) {
// Link node must be the same for both ends of selection.
nsCOMPtr<nsIDOMElement> parentLinkOfFocus;
rv = GetElementOrParentByTagName(NS_LITERAL_STRING("href"),
- focusNode,
+ GetAsDOMNode(focusNode),
getter_AddRefs(parentLinkOfFocus));
if (NS_SUCCEEDED(rv) && parentLinkOfFocus == parentLinkOfAnchor) {
bNodeFound = true;
}
}
// We found a link node parent
if (bNodeFound) {
@@ -2508,17 +2506,18 @@ HTMLEditor::GetSelectedElement(const nsA
NS_IF_ADDREF(*aReturn);
return NS_OK;
}
} else if (anchorOffset >= 0) {
// Check if link node is the only thing selected
nsCOMPtr<nsIDOMNode> anchorChild;
anchorChild = GetChildAt(anchorNode,anchorOffset);
if (anchorChild && HTMLEditUtils::IsLink(anchorChild) &&
- anchorNode == focusNode && focusOffset == anchorOffset + 1) {
+ anchorNode == GetAsDOMNode(focusNode) &&
+ focusOffset == anchorOffset + 1) {
selectedElement = do_QueryInterface(anchorChild);
bNodeFound = true;
}
}
}
}
if (!isCollapsed) {
@@ -5023,23 +5022,21 @@ HTMLEditor::GetActiveEditingHost()
}
if (document->HasFlag(NODE_IS_EDITABLE)) {
return document->GetBodyElement();
}
// We're HTML editor for contenteditable
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_TRUE(selection, nullptr);
- nsCOMPtr<nsIDOMNode> focusNode;
- nsresult rv = selection->GetFocusNode(getter_AddRefs(focusNode));
- NS_ENSURE_SUCCESS(rv, nullptr);
- nsCOMPtr<nsIContent> content = do_QueryInterface(focusNode);
- if (!content) {
+ nsINode* focusNode = selection->GetFocusNode();
+ if (NS_WARN_IF(!focusNode) || NS_WARN_IF(!focusNode->IsContent())) {
return nullptr;
}
+ nsIContent* content = focusNode->AsContent();
// If the active content isn't editable, or it has independent selection,
// we're not active.
if (!content->HasFlag(NODE_IS_EDITABLE) ||
content->HasIndependentSelection()) {
return nullptr;
}
return content->GetEditingHost();