Files
tubestation/dom/base/ElementInlines.h
Masayuki Nakano 16398887a4 Bug 1905267 - part 2: Make PresShell not use non-element event target when target frame is destroyed and the event wants Element target r=smaug
When event target frame is destroyed, `PresShell::NotifyDestroyingFrame` updates
current event target content to the frame content.  However, event target of
some DOM events need to be `Element`.  Therefore,
`PresShell::mCurrentEventTarget` needs to store at least the handling
`EventMessage` to consider whether the event target can be non-element content
node or only element node.  So, we need to make `PresShell::EventTargetInfo`
store `EventMessage`.  Then, we can make `PresShell::NotifyDestroyingFrame`
prefer inclusive ancestor element as new event target from the `EventMessage`.

Although I don't understand what's going on the reported case, but I found the
simple case when event target is changed to a `Text` with the assertion in
`PresShell::DispatchEventToDOM`.  Therefore, this patch has a new test.

Note that if target frame is a frame for element, e.g., when event target is
a focused element, `IsForbiddenDispatchingToNonElementContent` result won't
change the behavior.  Therefore, its implementation is not optimized for
non-user input events.

Differential Revision: https://phabricator.services.mozilla.com/D217205
2024-07-30 00:06:10 +00:00

55 lines
1.6 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_ElementInlines_h
#define mozilla_dom_ElementInlines_h
#include "mozilla/dom/Element.h"
#include "mozilla/ServoBindingTypes.h"
#include "nsIContentInlines.h"
#include "mozilla/dom/Document.h"
namespace mozilla::dom {
inline void Element::RegisterActivityObserver() {
OwnerDoc()->RegisterActivityObserver(this);
}
inline void Element::UnregisterActivityObserver() {
OwnerDoc()->UnregisterActivityObserver(this);
}
} // namespace mozilla::dom
inline mozilla::dom::Element* nsINode::GetFlattenedTreeParentElement() const {
nsINode* parentNode = GetFlattenedTreeParentNode();
if MOZ_LIKELY (parentNode && parentNode->IsElement()) {
return parentNode->AsElement();
}
return nullptr;
}
inline mozilla::dom::Element* nsINode::GetFlattenedTreeParentElementForStyle()
const {
nsINode* parentNode = GetFlattenedTreeParentNodeForStyle();
if (MOZ_LIKELY(parentNode && parentNode->IsElement())) {
return parentNode->AsElement();
}
return nullptr;
}
inline mozilla::dom::Element*
nsINode::GetInclusiveFlattenedTreeAncestorElement() const {
nsIContent* content = const_cast<nsIContent*>(nsIContent::FromNode(this));
while (content && !content->IsElement()) {
content = content->GetFlattenedTreeParent();
}
return mozilla::dom::Element::FromNodeOrNull(content);
}
#endif // mozilla_dom_ElementInlines_h