Issue #2030 - (chore) refactor event dispatch functions

Based on selected bits of M-C 1461708:
- EventStateManager::CheckForAndDispatchClick() to early-return style
- split EventStateManager::CheckForAndDispatchClick() into:
  EventCausesClickEvents, PostHandleMouseUp, DispatchClickEvents
- Move implementation of UIEvent::GetRangeParent() and UIEvent::RangeOffset() to nsLayoutUtils
This commit is contained in:
Martok 2022-11-27 16:35:25 +01:00 committed by roytam1
commit 4d310562d9
5 changed files with 292 additions and 97 deletions

View file

@ -228,26 +228,20 @@ UIEvent::GetWhich(uint32_t* aWhich)
already_AddRefed<nsINode>
UIEvent::GetRangeParent()
{
nsIFrame* targetFrame = nullptr;
if (mPresContext) {
targetFrame = mPresContext->EventStateManager()->GetEventTarget();
if (NS_WARN_IF(!mPresContext)) {
return nullptr;
}
if (targetFrame) {
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mEvent,
targetFrame);
nsCOMPtr<nsIContent> parent = targetFrame->GetContentOffsetsFromPoint(pt).content;
if (parent) {
if (parent->ChromeOnlyAccess() &&
!nsContentUtils::CanAccessNativeAnon()) {
return nullptr;
}
return parent.forget();
}
nsCOMPtr<nsIPresShell> presShell = mPresContext->GetPresShell();
if (NS_WARN_IF(!presShell)) {
return nullptr;
}
return nullptr;
nsCOMPtr<nsIContent> container;
nsLayoutUtils::GetContainerAndOffsetAtEvent(presShell, mEvent,
getter_AddRefs(container),
nullptr);
return container.forget();
}
NS_IMETHODIMP
@ -273,18 +267,19 @@ UIEvent::GetRangeOffset(int32_t* aRangeOffset)
int32_t
UIEvent::RangeOffset() const
{
if (!mPresContext) {
if (NS_WARN_IF(!mPresContext)) {
return 0;
}
nsIFrame* targetFrame = mPresContext->EventStateManager()->GetEventTarget();
if (!targetFrame) {
nsCOMPtr<nsIPresShell> presShell = mPresContext->GetPresShell();
if (NS_WARN_IF(!presShell)) {
return 0;
}
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mEvent,
targetFrame);
return targetFrame->GetContentOffsetsFromPoint(pt).offset;
int32_t offset = 0;
nsLayoutUtils::GetContainerAndOffsetAtEvent(presShell, mEvent,
nullptr, &offset);
return offset;
}
nsIntPoint