summaryrefslogtreecommitdiff
path: root/dom
diff options
context:
space:
mode:
authorFranklinDM <mrmineshafter17@gmail.com>2023-03-03 23:42:46 +0800
committerFranklinDM <mrmineshafter17@gmail.com>2023-03-04 21:32:12 +0800
commit2fbefbbc584d9380e5b1987a617bc916d29e1a57 (patch)
treecfc9b26679e9c4446bcf14315802d3d4bae9f319 /dom
parent59b4e5ceb2350c355d5e51ebc86949092fd18dc4 (diff)
downloaduxp-2fbefbbc584d9380e5b1987a617bc916d29e1a57.tar.gz
Issue #2135 - Bug 1066965: Make contentEditable and spellchecking to work in Shadow DOM
Diffstat (limited to 'dom')
-rw-r--r--dom/base/Element.cpp7
-rw-r--r--dom/base/nsINode.cpp12
-rw-r--r--dom/base/nsINode.h6
-rw-r--r--dom/html/nsGenericHTMLElement.cpp23
4 files changed, 34 insertions, 14 deletions
diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp
index d44d55bc20..8482047eeb 100644
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -1717,10 +1717,11 @@ Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
if (!hadParent) {
uint32_t editableDescendantChange = EditableInclusiveDescendantCount(this);
if (editableDescendantChange != 0) {
- // If we are binding a subtree root to the document, we need to update
- // the editable descendant count of all the ancestors.
+ // If we are binding a subtree root to the document, we need to update
+ // the editable descendant count of all the ancestors. However, we don't
+ // cross the Shadow DOM boundary (expected behavior is unclear).
nsIContent* parent = GetParent();
- while (parent) {
+ while (parent && parent->IsElement()) {
parent->ChangeEditableDescendantCount(editableDescendantChange);
parent = parent->GetParent();
}
diff --git a/dom/base/nsINode.cpp b/dom/base/nsINode.cpp
index 749a3ee4a2..37980db614 100644
--- a/dom/base/nsINode.cpp
+++ b/dom/base/nsINode.cpp
@@ -273,6 +273,18 @@ nsINode* nsINode::GetRootNode(const GetRootNodeOptions& aOptions)
return SubtreeRoot();
}
+// TODO: was marked as constant.
+nsINode*
+nsINode::GetParentOrHostNode()
+{
+ if (mParent) {
+ return mParent;
+ }
+
+ ShadowRoot* shadowRoot = ShadowRoot::FromNode(this);
+ return shadowRoot ? shadowRoot->GetHost() : nullptr;
+}
+
nsINode*
nsINode::SubtreeRoot() const
{
diff --git a/dom/base/nsINode.h b/dom/base/nsINode.h
index 1d580540f8..3611a4074d 100644
--- a/dom/base/nsINode.h
+++ b/dom/base/nsINode.h
@@ -943,6 +943,12 @@ public:
}
/**
+ * This is similar to above, but in case 'this' is ShadowRoot, we return its
+ * host element.
+ */
+ nsINode* GetParentOrHostNode();
+
+ /**
* Returns the node that is the parent of this node in the flattened
* tree. This differs from the normal parent if the node is filtered
* into an insertion point, or if the node is a direct child of a
diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp
index 0f32d8fb42..da7121a714 100644
--- a/dom/html/nsGenericHTMLElement.cpp
+++ b/dom/html/nsGenericHTMLElement.cpp
@@ -463,7 +463,7 @@ nsGenericHTMLElement::IntrinsicState() const
uint32_t
nsGenericHTMLElement::EditableInclusiveDescendantCount()
{
- bool isEditable = IsInUncomposedDoc() && HasFlag(NODE_IS_EDITABLE) &&
+ bool isEditable = IsInComposedDoc() && HasFlag(NODE_IS_EDITABLE) &&
GetContentEditableValue() == eTrue;
return EditableDescendantCount() + isEditable;
}
@@ -484,12 +484,14 @@ nsGenericHTMLElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
aDocument->
AddToNameTable(this, GetParsedAttr(nsGkAtoms::name)->GetAtomValue());
}
+ }
- if (HasFlag(NODE_IS_EDITABLE) && GetContentEditableValue() == eTrue) {
- nsCOMPtr<nsIHTMLDocument> htmlDocument = do_QueryInterface(aDocument);
- if (htmlDocument) {
- htmlDocument->ChangeContentEditableCount(this, +1);
- }
+ if (HasFlag(NODE_IS_EDITABLE) && GetContentEditableValue() == eTrue &&
+ IsInComposedDoc()) {
+ nsCOMPtr<nsIHTMLDocument> htmlDocument =
+ do_QueryInterface(GetComposedDoc());
+ if (htmlDocument) {
+ htmlDocument->ChangeContentEditableCount(this, +1);
}
}
@@ -514,8 +516,7 @@ nsGenericHTMLElement::UnbindFromTree(bool aDeep, bool aNullParent)
RemoveFromNameTable();
if (GetContentEditableValue() == eTrue) {
- //XXXsmaug Fix this for Shadow DOM, bug 1066965.
- nsCOMPtr<nsIHTMLDocument> htmlDocument = do_QueryInterface(GetUncomposedDoc());
+ nsCOMPtr<nsIHTMLDocument> htmlDocument = do_QueryInterface(GetComposedDoc());
if (htmlDocument) {
htmlDocument->ChangeContentEditableCount(this, -1);
}
@@ -2774,8 +2775,7 @@ MakeContentDescendantsEditable(nsIContent *aContent, nsIDocument *aDocument)
void
nsGenericHTMLElement::ChangeEditableState(int32_t aChange)
{
- //XXXsmaug Fix this for Shadow DOM, bug 1066965.
- nsIDocument* document = GetUncomposedDoc();
+ nsIDocument* document = GetComposedDoc();
if (!document) {
return;
}
@@ -2788,7 +2788,8 @@ nsGenericHTMLElement::ChangeEditableState(int32_t aChange)
}
nsIContent* parent = GetParent();
- while (parent) {
+ // Don't update across Shadow DOM boundary.
+ while (parent && parent->IsElement()) {
parent->ChangeEditableDescendantCount(aChange);
parent = parent->GetParent();
}