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

@ -11,6 +11,7 @@
#include "mozilla/EffectCompositor.h"
#include "mozilla/EffectSet.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/FloatingPoint.h"
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/gfx/PathHelpers.h"
@ -2255,6 +2256,59 @@ nsLayoutUtils::GetPopupFrameForEventCoordinates(nsPresContext* aPresContext,
return nullptr;
}
void
nsLayoutUtils::GetContainerAndOffsetAtEvent(nsIPresShell* aPresShell,
const WidgetEvent* aEvent,
nsIContent** aContainer,
int32_t* aOffset)
{
MOZ_ASSERT(aContainer || aOffset);
if (aContainer) {
*aContainer = nullptr;
}
if (aOffset) {
*aOffset = 0;
}
if (!aPresShell) {
return;
}
aPresShell->FlushPendingNotifications(Flush_Layout);
RefPtr<nsPresContext> presContext = aPresShell->GetPresContext();
if (!presContext) {
return;
}
nsIFrame* targetFrame = presContext->EventStateManager()->GetEventTarget();
if (!targetFrame) {
return;
}
nsPoint point =
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, targetFrame);
if (aContainer) {
// TODO: This result may be useful to change to Selection. However, this
// may return improper node (e.g., native anonymous node) for the
// Selection. Perhaps, this should take Selection optionally and
// if it's specified, needs to check if it's proper for the
// Selection.
nsCOMPtr<nsIContent> container =
targetFrame->GetContentOffsetsFromPoint(point).content;
if (container &&
(!container->ChromeOnlyAccess() ||
nsContentUtils::CanAccessNativeAnon())) {
container.forget(aContainer);
}
}
if (aOffset) {
*aOffset = targetFrame->GetContentOffsetsFromPoint(point).offset;
}
}
static void ConstrainToCoordValues(float& aStart, float& aSize)
{
MOZ_ASSERT(aSize >= 0);