Merge remote-tracking branch 'origin/tracking' into custom

This commit is contained in:
roytam1 2023-03-06 16:29:00 +08:00
commit eb8748c537
119 changed files with 3277 additions and 1496 deletions

View file

@ -1114,7 +1114,7 @@ EditorEventListener::Focus(WidgetEvent* aFocusEvent)
return NS_OK;
}
nsCOMPtr<nsIDOMEventTarget> target = aFocusEvent->GetDOMEventTarget();
nsCOMPtr<nsIDOMEventTarget> target = aFocusEvent->GetOriginalDOMEventTarget();
nsCOMPtr<nsINode> node = do_QueryInterface(target);
NS_ENSURE_TRUE(node, NS_ERROR_UNEXPECTED);
@ -1126,13 +1126,15 @@ EditorEventListener::Focus(WidgetEvent* aFocusEvent)
}
if (node->IsNodeOfType(nsINode::eCONTENT)) {
nsIContent* content =
node->AsContent()->FindFirstNonChromeOnlyAccessContent();
// XXX If the focus event target is a form control in contenteditable
// element, perhaps, the parent HTML editor should do nothing by this
// handler. However, FindSelectionRoot() returns the root element of the
// contenteditable editor. So, the editableRoot value is invalid for
// the plain text editor, and it will be set to the wrong limiter of
// the selection. However, fortunately, actual bugs are not found yet.
nsCOMPtr<nsIContent> editableRoot = editorBase->FindSelectionRoot(node);
nsCOMPtr<nsIContent> editableRoot = editorBase->FindSelectionRoot(content);
// make sure that the element is really focused in case an earlier
// listener in the chain changed the focus.

View file

@ -7986,16 +7986,20 @@ HTMLEditRules::ConfirmSelectionInBody()
{
// get the body
NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<nsIDOMElement> rootElement = do_QueryInterface(mHTMLEditor->GetRoot());
NS_ENSURE_TRUE(rootElement, NS_ERROR_UNEXPECTED);
RefPtr<Element> rootElement = mHTMLEditor->GetRoot();
if (NS_WARN_IF(!rootElement)) {
return NS_ERROR_UNEXPECTED;
}
// get the selection
NS_ENSURE_STATE(mHTMLEditor);
RefPtr<Selection> selection = mHTMLEditor->GetSelection();
NS_ENSURE_STATE(selection);
if (NS_WARN_IF(!selection)) {
return NS_ERROR_UNEXPECTED;
}
// get the selection start location
nsCOMPtr<nsIDOMNode> selNode, temp, parent;
nsCOMPtr<nsINode> selNode;
int32_t selOffset;
NS_ENSURE_STATE(mHTMLEditor);
nsresult rv =
@ -8005,12 +8009,11 @@ HTMLEditRules::ConfirmSelectionInBody()
return rv;
}
temp = selNode;
nsINode* temp = selNode;
// check that selNode is inside body
while (temp && !TextEditUtils::IsBody(temp)) {
temp->GetParentNode(getter_AddRefs(parent));
temp = parent;
while (temp && !temp->IsHTMLElement(nsGkAtoms::body)) {
temp = temp->GetParentOrHostNode();
}
// if we aren't in the body, force the issue
@ -8018,6 +8021,7 @@ HTMLEditRules::ConfirmSelectionInBody()
// uncomment this to see when we get bad selections
// NS_NOTREACHED("selection not in body");
selection->Collapse(rootElement, 0);
return NS_OK;
}
// get the selection end location
@ -8028,9 +8032,8 @@ HTMLEditRules::ConfirmSelectionInBody()
temp = selNode;
// check that selNode is inside body
while (temp && !TextEditUtils::IsBody(temp)) {
rv = temp->GetParentNode(getter_AddRefs(parent));
temp = parent;
while (temp && !temp->IsHTMLElement(nsGkAtoms::body)) {
temp = temp->GetParentOrHostNode();
}
// if we aren't in the body, force the issue
@ -8040,9 +8043,7 @@ HTMLEditRules::ConfirmSelectionInBody()
selection->Collapse(rootElement, 0);
}
// XXX This is the result of the last call of GetParentNode(), it doesn't
// make sense...
return rv;
return NS_OK;
}
nsresult

View file

@ -381,13 +381,14 @@ HTMLEditor::FindSelectionRoot(nsINode* aNode)
aNode->IsNodeOfType(nsINode::eCONTENT),
"aNode must be content or document node");
nsCOMPtr<nsIDocument> doc = aNode->GetUncomposedDoc();
nsCOMPtr<nsIDocument> doc = aNode->GetComposedDoc();
if (!doc) {
return nullptr;
}
nsCOMPtr<nsIContent> content;
if (doc->HasFlag(NODE_IS_EDITABLE) || !aNode->IsContent()) {
if (aNode->IsInUncomposedDoc() &&
doc->HasFlag(NODE_IS_EDITABLE) || !aNode->IsContent()) {
content = doc->GetRootElement();
return content.forget();
}
@ -5135,7 +5136,11 @@ HTMLEditor::IsAcceptableInputEvent(WidgetGUIEvent* aGUIEvent)
return true;
}
nsCOMPtr<nsIDOMEventTarget> target = aGUIEvent->GetDOMEventTarget();
nsCOMPtr<nsIDOMEventTarget> target = aGUIEvent->GetOriginalDOMEventTarget();
nsCOMPtr<nsIContent> content = do_QueryInterface(target);
if (content) {
target = content->FindFirstNonChromeOnlyAccessContent();
}
NS_ENSURE_TRUE(target, false);
nsCOMPtr<nsIDocument> document = GetDocument();