diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 1e8dfd947d4ff..13237714705bb 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -2096,8 +2096,18 @@ bool Element::ShouldBlur(nsIContent* aContent) { nsCOMPtr focusedFrame; nsIContent* contentToBlur = nsFocusManager::GetFocusedDescendant( window, nsFocusManager::eOnlyCurrentWindow, getter_AddRefs(focusedFrame)); + + if (!contentToBlur) { + return false; + } + if (contentToBlur == aContent) return true; + ShadowRoot* root = aContent->GetShadowRoot(); + if (root && root->DelegatesFocus() && + contentToBlur->IsShadowIncludingInclusiveDescendantOf(root)) { + return true; + } // if focus on this element would get redirected, then check the redirected // content as well when blurring. return (contentToBlur && diff --git a/testing/web-platform/tests/shadow-dom/focus/blur-on-shadow-host-delegatesFocus.html b/testing/web-platform/tests/shadow-dom/focus/blur-on-shadow-host-delegatesFocus.html new file mode 100644 index 0000000000000..289b554372136 --- /dev/null +++ b/testing/web-platform/tests/shadow-dom/focus/blur-on-shadow-host-delegatesFocus.html @@ -0,0 +1,38 @@ + + +HTML Test: Blur on shadow host + + + + + +
+ +
+ +