Bug 1556556 - Propagate RelativeTo far and wide. r=kats,mattwoodrow

This "upgrades" various nsLayoutUtils functions which take as inputs
a set of coordinates and a frame that the coordinates are relative to,
to accept a RelativeTo object instead of a frame.

Most of the patch is just dumb propagation, but the few places where
we use an explicit ViewportType::Visual are important. There are
probably a few other places I've overlooked, but this seems to cover
the important ones that come up commonly.

There are undoubtedly other functions into which we can propagate
RelativeTo, in this patch I've propagated it as far as necessary
for my needs in this bug (mainly GetTransformToAncestor() and
GetEventCoordinatesRelativeTo()).

Differential Revision: https://phabricator.services.mozilla.com/D68919
This commit is contained in:
Botond Ballo 2020-05-05 19:26:38 +00:00
Родитель 6bda5b208d
Коммит 173d001b86
36 изменённых файлов: 243 добавлений и 177 удалений

Просмотреть файл

@ -12346,8 +12346,8 @@ already_AddRefed<nsDOMCaretPosition> Document::CaretPositionFromPoint(
nsCOMPtr<nsIWidget> widget = nsContentUtils::GetWidget(presShell, &aOffset);
LayoutDeviceIntPoint refPoint = nsContentUtils::ToWidgetPoint(
CSSPoint(aX, aY), aOffset, GetPresContext());
nsPoint adjustedPoint =
nsLayoutUtils::GetEventCoordinatesRelativeTo(widget, refPoint, ptFrame);
nsPoint adjustedPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(
widget, refPoint, RelativeTo{ptFrame});
nsFrame::ContentOffsets offsets =
ptFrame->GetContentOffsetsFromPoint(adjustedPoint);

Просмотреть файл

@ -3227,8 +3227,9 @@ already_AddRefed<DOMMatrixReadOnly> Element::GetTransformToAncestor(
// If aAncestor is not actually an ancestor of this (including nullptr),
// then the call to GetTransformToAncestor will return the transform
// all the way up through the parent chain.
transform = nsLayoutUtils::GetTransformToAncestor(
primaryFrame, ancestorFrame, nsIFrame::IN_CSS_UNITS)
transform = nsLayoutUtils::GetTransformToAncestor(RelativeTo{primaryFrame},
RelativeTo{ancestorFrame},
nsIFrame::IN_CSS_UNITS)
.GetMatrix();
}
@ -3243,7 +3244,8 @@ already_AddRefed<DOMMatrixReadOnly> Element::GetTransformToParent() {
Matrix4x4 transform;
if (primaryFrame) {
nsIFrame* parentFrame = primaryFrame->GetParent();
transform = nsLayoutUtils::GetTransformToAncestor(primaryFrame, parentFrame,
transform = nsLayoutUtils::GetTransformToAncestor(RelativeTo{primaryFrame},
RelativeTo{parentFrame},
nsIFrame::IN_CSS_UNITS)
.GetMatrix();
}
@ -3259,7 +3261,8 @@ already_AddRefed<DOMMatrixReadOnly> Element::GetTransformToViewport() {
if (primaryFrame) {
transform =
nsLayoutUtils::GetTransformToAncestor(
primaryFrame, nsLayoutUtils::GetDisplayRootFrame(primaryFrame),
RelativeTo{primaryFrame},
RelativeTo{nsLayoutUtils::GetDisplayRootFrame(primaryFrame)},
nsIFrame::IN_CSS_UNITS)
.GetMatrix();
}

Просмотреть файл

@ -3231,8 +3231,8 @@ nsDOMWindowUtils::SelectAtPoint(float aX, float aY, uint32_t aSelectBehavior,
nsCOMPtr<nsIWidget> widget = GetWidget(&offset);
LayoutDeviceIntPoint pt =
nsContentUtils::ToWidgetPoint(CSSPoint(aX, aY), offset, GetPresContext());
nsPoint ptInRoot =
nsLayoutUtils::GetEventCoordinatesRelativeTo(widget, pt, rootFrame);
nsPoint ptInRoot = nsLayoutUtils::GetEventCoordinatesRelativeTo(
widget, pt, RelativeTo{rootFrame});
nsIFrame* targetFrame = nsLayoutUtils::GetFrameForPoint(rootFrame, ptInRoot);
// This can happen if the page hasn't loaded yet or if the point
// is outside the frame.
@ -3242,8 +3242,8 @@ nsDOMWindowUtils::SelectAtPoint(float aX, float aY, uint32_t aSelectBehavior,
// Convert point to coordinates relative to the target frame, which is
// what targetFrame's SelectByTypeAtPoint expects.
nsPoint relPoint =
nsLayoutUtils::GetEventCoordinatesRelativeTo(widget, pt, targetFrame);
nsPoint relPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(
widget, pt, RelativeTo{targetFrame});
nsresult rv = static_cast<nsFrame*>(targetFrame)
->SelectByTypeAtPoint(GetPresContext(), relPoint, amount,

Просмотреть файл

@ -2549,8 +2549,8 @@ nsresult ContentEventHandler::OnQueryCharacterAtPoint(
eventOnRoot.mRefPoint += aEvent->mWidget->WidgetToScreenOffset() -
rootWidget->WidgetToScreenOffset();
}
nsPoint ptInRoot =
nsLayoutUtils::GetEventCoordinatesRelativeTo(&eventOnRoot, rootFrame);
nsPoint ptInRoot = nsLayoutUtils::GetEventCoordinatesRelativeTo(
&eventOnRoot, RelativeTo{rootFrame});
nsIFrame* targetFrame = nsLayoutUtils::GetFrameForPoint(rootFrame, ptInRoot);
if (!targetFrame || !targetFrame->GetContent() ||

Просмотреть файл

@ -612,8 +612,8 @@ CSSIntPoint Event::GetClientCoords(nsPresContext* aPresContext,
if (!rootFrame) {
return CSSIntPoint(0, 0);
}
nsPoint pt =
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, aPoint, rootFrame);
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
aEvent, aPoint, RelativeTo{rootFrame});
return CSSIntPoint::FromAppUnitsRounded(pt);
}
@ -646,8 +646,8 @@ CSSIntPoint Event::GetOffsetCoords(nsPresContext* aPresContext,
CSSIntPoint clientCoords =
GetClientCoords(aPresContext, aEvent, aPoint, aDefaultPoint);
nsPoint pt = CSSPixel::ToAppUnits(clientCoords);
if (nsLayoutUtils::TransformPoint(rootFrame, frame, pt) ==
nsLayoutUtils::TRANSFORM_SUCCEEDED) {
if (nsLayoutUtils::TransformPoint(RelativeTo{rootFrame}, RelativeTo{frame},
pt) == nsLayoutUtils::TRANSFORM_SUCCEEDED) {
pt -= frame->GetPaddingRectRelativeToSelf().TopLeft();
return CSSPixel::FromAppUnitsRounded(pt);
}

Просмотреть файл

@ -3798,7 +3798,7 @@ static bool ShouldBlockCustomCursor(nsPresContext* aPresContext,
}
nsPoint point = nsLayoutUtils::GetEventCoordinatesRelativeTo(
aEvent, topLevel->PresShell()->GetRootFrame());
aEvent, RelativeTo{topLevel->PresShell()->GetRootFrame()});
nsSize size(CSSPixel::ToAppUnits(width), CSSPixel::ToAppUnits(height));
nsPoint hotspot(CSSPixel::ToAppUnits(aCursor.mHotspot.x),
@ -3893,8 +3893,8 @@ void EventStateManager::UpdateCursor(nsPresContext* aPresContext,
}
// If not locked, look for correct cursor
else if (aTargetFrame) {
nsPoint pt =
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, aTargetFrame);
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
aEvent, RelativeTo{aTargetFrame});
Maybe<nsIFrame::Cursor> framecursor = aTargetFrame->GetCursor(pt);
// Avoid setting cursor when the mouse is over a windowless plugin.
if (!framecursor) {

Просмотреть файл

@ -181,7 +181,8 @@ nsIntPoint UIEvent::GetLayerPoint() const {
nsIFrame* targetFrame = mPresContext->EventStateManager()->GetEventTarget();
if (!targetFrame) return mLayerPoint;
nsIFrame* layer = nsLayoutUtils::GetClosestLayer(targetFrame);
nsPoint pt(nsLayoutUtils::GetEventCoordinatesRelativeTo(mEvent, layer));
nsPoint pt(
nsLayoutUtils::GetEventCoordinatesRelativeTo(mEvent, RelativeTo{layer}));
return nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(pt.x),
nsPresContext::AppUnitsToIntCSSPixels(pt.y));
}

Просмотреть файл

@ -563,7 +563,7 @@ void HTMLCanvasElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
return;
}
nsPoint ptInRoot =
nsLayoutUtils::GetEventCoordinatesRelativeTo(evt, frame);
nsLayoutUtils::GetEventCoordinatesRelativeTo(evt, RelativeTo{frame});
nsRect paddingRect = frame->GetContentRectRelativeToSelf();
Point hitpoint;
hitpoint.x = (ptInRoot.x - paddingRect.x) / AppUnitsPerCSSPixel();

Просмотреть файл

@ -1833,9 +1833,9 @@ static NPCocoaEvent TranslateToNPCocoaEvent(WidgetGUIEvent* anEvent,
anEvent->mMessage == eMouseUp ||
anEvent->mMessage == eLegacyMouseLineOrPageScroll ||
anEvent->mMessage == eMouseOver || anEvent->mMessage == eMouseOut) {
nsPoint pt =
nsLayoutUtils::GetEventCoordinatesRelativeTo(anEvent, aObjectFrame) -
aObjectFrame->GetContentRectRelativeToSelf().TopLeft();
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
anEvent, RelativeTo{aObjectFrame}) -
aObjectFrame->GetContentRectRelativeToSelf().TopLeft();
nsPresContext* presContext = aObjectFrame->PresContext();
// Plugin event coordinates need to be translated from device pixels
// into "display pixels" in HiDPI modes.
@ -2164,9 +2164,9 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(
anEvent.mMessage == eMouseOver || anEvent.mMessage == eMouseOut ||
anEvent.mMessage == eMouseMove || anEvent.mMessage == eWheel,
"Incorrect event type for coordinate translation");
nsPoint pt =
nsLayoutUtils::GetEventCoordinatesRelativeTo(&anEvent, mPluginFrame) -
mPluginFrame->GetContentRectRelativeToSelf().TopLeft();
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
&anEvent, RelativeTo{mPluginFrame}) -
mPluginFrame->GetContentRectRelativeToSelf().TopLeft();
nsPresContext* presContext = mPluginFrame->PresContext();
nsIntPoint ptPx(presContext->AppUnitsToDevPixels(pt.x),
presContext->AppUnitsToDevPixels(pt.y));
@ -2246,9 +2246,9 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(
// Get reference point relative to plugin origin.
const nsPresContext* presContext = mPluginFrame->PresContext();
nsPoint appPoint =
nsLayoutUtils::GetEventCoordinatesRelativeTo(&anEvent, mPluginFrame) -
mPluginFrame->GetContentRectRelativeToSelf().TopLeft();
nsPoint appPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(
&anEvent, RelativeTo{mPluginFrame}) -
mPluginFrame->GetContentRectRelativeToSelf().TopLeft();
nsIntPoint pluginPoint(presContext->AppUnitsToDevPixels(appPoint.x),
presContext->AppUnitsToDevPixels(appPoint.y));
const WidgetMouseEvent& mouseEvent = *anEvent.AsMouseEvent();

Просмотреть файл

@ -566,7 +566,7 @@ static bool PrepareForSetTargetAPZCNotification(
nsTArray<ScrollableLayerGuid>* aTargets) {
ScrollableLayerGuid guid(aLayersId, 0, ScrollableLayerGuid::NULL_SCROLL_ID);
nsPoint point = nsLayoutUtils::GetEventCoordinatesRelativeTo(
aWidget, aRefPoint, aRootFrame);
aWidget, aRefPoint, RelativeTo{aRootFrame, ViewportType::Visual});
nsIFrame* target = nsLayoutUtils::GetFrameForPoint(aRootFrame, point);
nsIScrollableFrame* scrollAncestor =
target ? nsLayoutUtils::GetAsyncScrollableAncestorFrame(target)
@ -772,7 +772,8 @@ void APZCCallbackHelper::SendSetAllowedTouchBehaviorNotification(
nsTArray<TouchBehaviorFlags> flags;
for (uint32_t i = 0; i < aEvent.mTouches.Length(); i++) {
flags.AppendElement(TouchActionHelper::GetAllowedTouchBehavior(
aWidget, rootFrame, aEvent.mTouches[i]->mRefPoint));
aWidget, RelativeTo{rootFrame, ViewportType::Visual},
aEvent.mTouches[i]->mRefPoint));
}
aCallback(aInputBlockId, std::move(flags));
}

Просмотреть файл

@ -47,7 +47,7 @@ static void UpdateAllowedBehavior(StyleTouchAction aTouchActionValue,
}
TouchBehaviorFlags TouchActionHelper::GetAllowedTouchBehavior(
nsIWidget* aWidget, nsIFrame* aRootFrame,
nsIWidget* aWidget, RelativeTo aRootFrame,
const LayoutDeviceIntPoint& aPoint) {
TouchBehaviorFlags behavior = AllowedTouchBehavior::VERTICAL_PAN |
AllowedTouchBehavior::HORIZONTAL_PAN |
@ -57,7 +57,8 @@ TouchBehaviorFlags TouchActionHelper::GetAllowedTouchBehavior(
nsPoint relativePoint =
nsLayoutUtils::GetEventCoordinatesRelativeTo(aWidget, aPoint, aRootFrame);
nsIFrame* target = nsLayoutUtils::GetFrameForPoint(aRootFrame, relativePoint);
nsIFrame* target =
nsLayoutUtils::GetFrameForPoint(aRootFrame.mFrame, relativePoint);
if (!target) {
return behavior;
}

Просмотреть файл

@ -8,6 +8,7 @@
#define __mozilla_layers_TouchActionHelper_h__
#include "mozilla/layers/LayersTypes.h" // for TouchBehaviorFlags
#include "nsLayoutUtils.h" // for RelativeTo
class nsIFrame;
class nsIWidget;
@ -28,7 +29,7 @@ class TouchActionHelper {
* http://www.w3.org/TR/pointerevents/#the-touch-action-css-property.
*/
static TouchBehaviorFlags GetAllowedTouchBehavior(
nsIWidget* aWidget, nsIFrame* aRootFrame,
nsIWidget* aWidget, RelativeTo aRootFrame,
const LayoutDeviceIntPoint& aPoint);
};

Просмотреть файл

@ -698,8 +698,8 @@ nsPoint AccessibleCaretEventHub::GetTouchEventPosition(
// Get event coordinate relative to root frame.
nsIFrame* rootFrame = mPresShell->GetRootFrame();
return nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, touchIntPoint,
rootFrame);
return nsLayoutUtils::GetEventCoordinatesRelativeTo(
aEvent, touchIntPoint, RelativeTo{rootFrame});
}
}
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
@ -712,7 +712,7 @@ nsPoint AccessibleCaretEventHub::GetMouseEventPosition(
// Get event coordinate relative to root frame.
nsIFrame* rootFrame = mPresShell->GetRootFrame();
return nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, mouseIntPoint,
rootFrame);
RelativeTo{rootFrame});
}
} // namespace mozilla

Просмотреть файл

@ -565,7 +565,8 @@ nsresult AccessibleCaretManager::SelectWordOrShortcut(const nsPoint& aPoint) {
// something under the original point will be selected, which may not be the
// original text the user wants to select.
nsPoint ptInFrame = aPoint;
nsLayoutUtils::TransformPoint(rootFrame, ptFrame, ptInFrame);
nsLayoutUtils::TransformPoint(RelativeTo{rootFrame}, RelativeTo{ptFrame},
ptInFrame);
// Firstly check long press on an empty editable content.
Element* newFocusEditingHost = GetEditingHostForFrame(ptFrame);
@ -1229,7 +1230,8 @@ nsresult AccessibleCaretManager::DragCaretInternal(const nsPoint& aPoint) {
nsIFrame* newFrame = nullptr;
nsPoint newPoint;
nsPoint ptInFrame = point;
nsLayoutUtils::TransformPoint(rootFrame, ptFrame, ptInFrame);
nsLayoutUtils::TransformPoint(RelativeTo{rootFrame}, RelativeTo{ptFrame},
ptInFrame);
result = fs->ConstrainFrameAndPointToAnchorSubtree(ptFrame, ptInFrame,
&newFrame, newPoint);
if (NS_FAILED(result) || !newFrame) {
@ -1378,7 +1380,8 @@ void AccessibleCaretManager::StartSelectionAutoScrollTimer(
nsIFrame* rootFrame = mPresShell->GetRootFrame();
MOZ_ASSERT(rootFrame);
nsPoint ptInScrolled = aPoint;
nsLayoutUtils::TransformPoint(rootFrame, capturingFrame, ptInScrolled);
nsLayoutUtils::TransformPoint(RelativeTo{rootFrame},
RelativeTo{capturingFrame}, ptInScrolled);
RefPtr<nsFrameSelection> fs = GetFrameSelection();
MOZ_ASSERT(fs);

Просмотреть файл

@ -261,8 +261,8 @@ static nsIContent* GetClickableAncestor(
return nullptr;
}
static nscoord AppUnitsFromMM(nsIFrame* aFrame, uint32_t aMM) {
nsPresContext* pc = aFrame->PresContext();
static nscoord AppUnitsFromMM(RelativeTo aFrame, uint32_t aMM) {
nsPresContext* pc = aFrame.mFrame->PresContext();
PresShell* presShell = pc->PresShell();
float result = float(aMM) * (pc->DeviceContext()->AppUnitsPerPhysicalInch() /
MM_PER_INCH_FLOAT);
@ -274,17 +274,18 @@ static nscoord AppUnitsFromMM(nsIFrame* aFrame, uint32_t aMM) {
* Clip aRect with the bounds of aFrame in the coordinate system of
* aRootFrame. aRootFrame is an ancestor of aFrame.
*/
static nsRect ClipToFrame(nsIFrame* aRootFrame, nsIFrame* aFrame,
static nsRect ClipToFrame(const nsIFrame* aRootFrame, const nsIFrame* aFrame,
nsRect& aRect) {
nsRect bound = nsLayoutUtils::TransformFrameRectToAncestor(
aFrame, nsRect(nsPoint(0, 0), aFrame->GetSize()), aRootFrame);
aFrame, nsRect(nsPoint(0, 0), aFrame->GetSize()),
RelativeTo{aRootFrame, ViewportType::Visual});
nsRect result = bound.Intersect(aRect);
return result;
}
static nsRect GetTargetRect(nsIFrame* aRootFrame,
static nsRect GetTargetRect(RelativeTo aRootFrame,
const nsPoint& aPointRelativeToRootFrame,
nsIFrame* aRestrictToDescendants,
const nsIFrame* aRestrictToDescendants,
const EventRadiusPrefs* aPrefs, uint32_t aFlags) {
nsMargin m(AppUnitsFromMM(aRootFrame, aPrefs->mSideRadii[0]),
AppUnitsFromMM(aRootFrame, aPrefs->mSideRadii[1]),
@ -296,7 +297,7 @@ static nsRect GetTargetRect(nsIFrame* aRootFrame,
// Don't clip this rect to the root scroll frame if the flag to ignore the
// root scroll frame is set. Note that the GetClosest code will still
// enforce that the target found is a descendant of aRestrictToDescendants.
r = ClipToFrame(aRootFrame, aRestrictToDescendants, r);
r = ClipToFrame(aRootFrame.mFrame, aRestrictToDescendants, r);
}
return r;
}
@ -340,11 +341,11 @@ static void SubtractFromExposedRegion(nsRegion* aExposedRegion,
}
}
static nsIFrame* GetClosest(nsIFrame* aRoot,
static nsIFrame* GetClosest(const nsIFrame* aRoot,
const nsPoint& aPointRelativeToRootFrame,
const nsRect& aTargetRect,
const EventRadiusPrefs* aPrefs,
nsIFrame* aRestrictToDescendants,
const nsIFrame* aRestrictToDescendants,
nsIContent* aClickableAncestor,
nsTArray<nsIFrame*>& aCandidates) {
nsIFrame* bestTarget = nullptr;
@ -356,7 +357,8 @@ static nsIFrame* GetClosest(nsIFrame* aRoot,
bool preservesAxisAlignedRectangles = false;
nsRect borderBox = nsLayoutUtils::TransformFrameRectToAncestor(
f, nsRect(nsPoint(0, 0), f->GetSize()), aRoot,
f, nsRect(nsPoint(0, 0), f->GetSize()),
RelativeTo{aRoot, ViewportType::Visual},
&preservesAxisAlignedRectangles);
PET_LOG("Checking candidate %p with border box %s\n", f,
mozilla::layers::Stringify(borderBox).c_str());
@ -419,7 +421,7 @@ static nsIFrame* GetClosest(nsIFrame* aRoot,
}
nsIFrame* FindFrameTargetedByInputEvent(
WidgetGUIEvent* aEvent, nsIFrame* aRootFrame,
WidgetGUIEvent* aEvent, RelativeTo aRootFrame,
const nsPoint& aPointRelativeToRootFrame, uint32_t aFlags) {
using FrameForPointOption = nsLayoutUtils::FrameForPointOption;
EnumSet<FrameForPointOption> options;
@ -427,13 +429,13 @@ nsIFrame* FindFrameTargetedByInputEvent(
options += FrameForPointOption::IgnoreRootScrollFrame;
}
nsIFrame* target = nsLayoutUtils::GetFrameForPoint(
aRootFrame, aPointRelativeToRootFrame, options);
aRootFrame.mFrame, aPointRelativeToRootFrame, options);
PET_LOG(
"Found initial target %p for event class %s message %s point %s "
"relative to root frame %p\n",
target, ToChar(aEvent->mClass), ToChar(aEvent->mMessage),
mozilla::layers::Stringify(aPointRelativeToRootFrame).c_str(),
aRootFrame);
aRootFrame.mFrame);
const EventRadiusPrefs* prefs = GetPrefsFor(aEvent->mClass);
if (!prefs || !prefs->mEnabled || EventRetargetSuppression::IsActive()) {
@ -467,23 +469,23 @@ nsIFrame* FindFrameTargetedByInputEvent(
// a mouse event handler for example, targets that are !GetClickableAncestor
// can never be targeted --- something nsSubDocumentFrame in an ancestor
// document would be targeted instead.
nsIFrame* restrictToDescendants =
target ? target->PresShell()->GetRootFrame() : aRootFrame;
const nsIFrame* restrictToDescendants =
target ? target->PresShell()->GetRootFrame() : aRootFrame.mFrame;
nsRect targetRect = GetTargetRect(aRootFrame, aPointRelativeToRootFrame,
restrictToDescendants, prefs, aFlags);
PET_LOG("Expanded point to target rect %s\n",
mozilla::layers::Stringify(targetRect).c_str());
AutoTArray<nsIFrame*, 8> candidates;
nsresult rv = nsLayoutUtils::GetFramesForArea(aRootFrame, targetRect,
nsresult rv = nsLayoutUtils::GetFramesForArea(aRootFrame.mFrame, targetRect,
candidates, options);
if (NS_FAILED(rv)) {
return target;
}
nsIFrame* closestClickable =
GetClosest(aRootFrame, aPointRelativeToRootFrame, targetRect, prefs,
restrictToDescendants, clickableAncestor, candidates);
GetClosest(aRootFrame.mFrame, aPointRelativeToRootFrame, targetRect,
prefs, restrictToDescendants, clickableAncestor, candidates);
if (closestClickable) {
target = closestClickable;
}
@ -494,7 +496,7 @@ nsIFrame* FindFrameTargetedByInputEvent(
// Note that dumping the frame tree at the top of the function may flood
// logcat on Android devices and cause the PET_LOGs to get dropped.
if (MOZ_LOG_TEST(sEvtTgtLog, LogLevel::Verbose)) {
aRootFrame->DumpFrameTree();
aRootFrame.mFrame->DumpFrameTree();
}
#endif
@ -507,22 +509,22 @@ nsIFrame* FindFrameTargetedByInputEvent(
// clamp it to the bounds, and then make it relative to the root frame again.
nsPoint point = aPointRelativeToRootFrame;
if (nsLayoutUtils::TRANSFORM_SUCCEEDED !=
nsLayoutUtils::TransformPoint(aRootFrame, target, point)) {
nsLayoutUtils::TransformPoint(aRootFrame, RelativeTo{target}, point)) {
return target;
}
point = target->GetRectRelativeToSelf().ClampPoint(point);
if (nsLayoutUtils::TRANSFORM_SUCCEEDED !=
nsLayoutUtils::TransformPoint(target, aRootFrame, point)) {
nsLayoutUtils::TransformPoint(RelativeTo{target}, aRootFrame, point)) {
return target;
}
// Now we basically undo the operations in GetEventCoordinatesRelativeTo, to
// get back the (now-clamped) coordinates in the event's widget's space.
nsView* view = aRootFrame->GetView();
nsView* view = aRootFrame.mFrame->GetView();
if (!view) {
return target;
}
LayoutDeviceIntPoint widgetPoint = nsLayoutUtils::TranslateViewToWidget(
aRootFrame->PresContext(), view, point, aEvent->mWidget);
aRootFrame.mFrame->PresContext(), view, point, aEvent->mWidget);
if (widgetPoint.x != NS_UNCONSTRAINEDSIZE) {
// If that succeeded, we update the point in the event
aEvent->mRefPoint = widgetPoint;

Просмотреть файл

@ -9,6 +9,7 @@
#include <stdint.h>
#include "mozilla/EventForwards.h"
#include "nsLayoutUtils.h"
class nsIFrame;
struct nsPoint;
@ -22,7 +23,7 @@ enum { INPUT_IGNORE_ROOT_SCROLL_FRAME = 0x01 };
* that are suitable targets, to account for inaccurate pointing devices.
*/
nsIFrame* FindFrameTargetedByInputEvent(
WidgetGUIEvent* aEvent, nsIFrame* aRootFrame,
WidgetGUIEvent* aEvent, RelativeTo aRootFrame,
const nsPoint& aPointRelativeToRootFrame, uint32_t aFlags = 0);
class MOZ_RAII EventRetargetSuppression {

Просмотреть файл

@ -6382,8 +6382,8 @@ void PresShell::RecordMouseLocation(WidgetGUIEvent* aEvent) {
mPresContext, aEvent->mWidget, aEvent->mRefPoint, rootView);
mMouseEventTargetGuid = InputAPZContext::GetTargetLayerGuid();
} else {
mMouseLocation =
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, rootFrame);
mMouseLocation = nsLayoutUtils::GetEventCoordinatesRelativeTo(
aEvent, RelativeTo{rootFrame});
mMouseEventTargetGuid = InputAPZContext::GetTargetLayerGuid();
}
mMouseLocationWasSetBySynthesizedMouseEventForTests =
@ -6833,8 +6833,14 @@ nsIFrame* PresShell::EventHandler::GetFrameToHandleNonTouchEvent(
MOZ_ASSERT(aGUIEvent);
MOZ_ASSERT(aGUIEvent->mClass != eTouchEventClass);
nsPoint eventPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(
aGUIEvent, aRootFrameToHandleEvent);
ViewportType viewportType = ViewportType::Layout;
if (aRootFrameToHandleEvent->Type() == LayoutFrameType::Viewport &&
aRootFrameToHandleEvent->PresContext()->IsRootContentDocument()) {
viewportType = ViewportType::Visual;
}
RelativeTo relativeTo{aRootFrameToHandleEvent, viewportType};
nsPoint eventPoint =
nsLayoutUtils::GetEventCoordinatesRelativeTo(aGUIEvent, relativeTo);
uint32_t flags = 0;
if (aGUIEvent->mClass == eMouseEventClass) {
@ -6844,8 +6850,8 @@ nsIFrame* PresShell::EventHandler::GetFrameToHandleNonTouchEvent(
}
}
nsIFrame* targetFrame = FindFrameTargetedByInputEvent(
aGUIEvent, aRootFrameToHandleEvent, eventPoint, flags);
nsIFrame* targetFrame =
FindFrameTargetedByInputEvent(aGUIEvent, relativeTo, eventPoint, flags);
if (!targetFrame) {
return aRootFrameToHandleEvent;
}
@ -6874,8 +6880,8 @@ nsIFrame* PresShell::EventHandler::GetFrameToHandleNonTouchEvent(
}
// Finally, we need to recompute the target with the latest layout.
targetFrame = FindFrameTargetedByInputEvent(
aGUIEvent, aRootFrameToHandleEvent, eventPoint, flags);
targetFrame =
FindFrameTargetedByInputEvent(aGUIEvent, relativeTo, eventPoint, flags);
return targetFrame ? targetFrame : aRootFrameToHandleEvent;
}
@ -11093,14 +11099,15 @@ nsIContent* PresShell::EventHandler::GetOverrideClickTarget(
WidgetMouseEvent* mouseEvent = aGUIEvent->AsMouseEvent();
uint32_t flags = 0;
RelativeTo relativeTo{aFrame};
nsPoint eventPoint =
nsLayoutUtils::GetEventCoordinatesRelativeTo(aGUIEvent, aFrame);
nsLayoutUtils::GetEventCoordinatesRelativeTo(aGUIEvent, relativeTo);
if (mouseEvent->mIgnoreRootScrollFrame) {
flags |= INPUT_IGNORE_ROOT_SCROLL_FRAME;
}
nsIFrame* target =
FindFrameTargetedByInputEvent(aGUIEvent, aFrame, eventPoint, flags);
FindFrameTargetedByInputEvent(aGUIEvent, relativeTo, eventPoint, flags);
if (!target) {
return nullptr;
}

Просмотреть файл

@ -118,9 +118,10 @@ nsIFrame* TouchManager::SetupTarget(WidgetTouchEvent* aEvent,
int32_t id = touch->Identifier();
if (!TouchManager::HasCapturedTouch(id)) {
// find the target for this touch
RelativeTo relativeTo{aFrame};
nsPoint eventPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(
aEvent, touch->mRefPoint, aFrame);
target = FindFrameTargetedByInputEvent(aEvent, aFrame, eventPoint);
aEvent, touch->mRefPoint, relativeTo);
target = FindFrameTargetedByInputEvent(aEvent, relativeTo, eventPoint);
if (target) {
nsCOMPtr<nsIContent> targetContent;
target->GetContentForEvent(aEvent, getter_AddRefs(targetContent));

Просмотреть файл

@ -34,6 +34,7 @@
#include "mozilla/StaticPrefs_layout.h"
#include "mozilla/Unused.h"
#include "mozilla/ViewportFrame.h"
#include "mozilla/ViewportUtils.h"
#include "nsCharTraits.h"
#include "mozilla/dom/BrowserChild.h"
#include "mozilla/dom/Document.h"
@ -142,6 +143,7 @@
#include "TextDrawTarget.h"
#include "nsDeckFrame.h"
#include "mozilla/dom/InspectorFontFace.h"
#include "ViewportFrame.h"
#ifdef MOZ_XUL
# include "nsXULPopupManager.h"
@ -2186,11 +2188,11 @@ nsPoint nsLayoutUtils::GetDOMEventCoordinatesRelativeTo(Event* aDOMEvent,
if (!aDOMEvent) return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
WidgetEvent* event = aDOMEvent->WidgetEventPtr();
if (!event) return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
return GetEventCoordinatesRelativeTo(event, aFrame);
return GetEventCoordinatesRelativeTo(event, RelativeTo{aFrame});
}
nsPoint nsLayoutUtils::GetEventCoordinatesRelativeTo(const WidgetEvent* aEvent,
nsIFrame* aFrame) {
RelativeTo aFrame) {
if (!aEvent || (aEvent->mClass != eMouseEventClass &&
aEvent->mClass != eMouseScrollEventClass &&
aEvent->mClass != eWheelEventClass &&
@ -2208,8 +2210,8 @@ nsPoint nsLayoutUtils::GetEventCoordinatesRelativeTo(const WidgetEvent* aEvent,
nsPoint nsLayoutUtils::GetEventCoordinatesRelativeTo(
const WidgetEvent* aEvent, const LayoutDeviceIntPoint& aPoint,
nsIFrame* aFrame) {
if (!aFrame) {
RelativeTo aFrame) {
if (!aFrame.mFrame) {
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
}
@ -2222,19 +2224,20 @@ nsPoint nsLayoutUtils::GetEventCoordinatesRelativeTo(
}
nsPoint nsLayoutUtils::GetEventCoordinatesRelativeTo(
nsIWidget* aWidget, const LayoutDeviceIntPoint& aPoint, nsIFrame* aFrame) {
if (!aFrame || !aWidget) {
nsIWidget* aWidget, const LayoutDeviceIntPoint& aPoint, RelativeTo aFrame) {
const nsIFrame* frame = aFrame.mFrame;
if (!frame || !aWidget) {
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
}
nsView* view = aFrame->GetView();
nsView* view = frame->GetView();
if (view) {
nsIWidget* frameWidget = view->GetWidget();
if (frameWidget && frameWidget == aWidget) {
// Special case this cause it happens a lot.
// This also fixes bug 664707, events in the extra-special case of select
// dropdown popups that are transformed.
nsPresContext* presContext = aFrame->PresContext();
nsPresContext* presContext = frame->PresContext();
nsPoint pt(presContext->DevPixelsToAppUnits(aPoint.x),
presContext->DevPixelsToAppUnits(aPoint.y));
pt = pt - view->ViewToWidgetOffset();
@ -2248,9 +2251,9 @@ nsPoint nsLayoutUtils::GetEventCoordinatesRelativeTo(
* transformed, we need to do extra work to convert from the global
* space to the local space.
*/
nsIFrame* rootFrame = aFrame;
const nsIFrame* rootFrame = frame;
bool transformFound = false;
for (nsIFrame* f = aFrame; f; f = GetCrossDocParentFrame(f)) {
for (const nsIFrame* f = frame; f; f = GetCrossDocParentFrame(f)) {
if (f->IsTransformed()) {
transformFound = true;
}
@ -2273,9 +2276,9 @@ nsPoint nsLayoutUtils::GetEventCoordinatesRelativeTo(
// Convert from root document app units to app units of the document aFrame
// is in.
int32_t rootAPD = rootFrame->PresContext()->AppUnitsPerDevPixel();
int32_t localAPD = aFrame->PresContext()->AppUnitsPerDevPixel();
int32_t localAPD = frame->PresContext()->AppUnitsPerDevPixel();
widgetToView = widgetToView.ScaleToOtherAppUnits(rootAPD, localAPD);
PresShell* presShell = aFrame->PresShell();
PresShell* presShell = aFrame.mFrame->PresShell();
// XXX Bug 1224748 - Update nsLayoutUtils functions to correctly handle
// PresShell resolution
@ -2285,14 +2288,15 @@ nsPoint nsLayoutUtils::GetEventCoordinatesRelativeTo(
/* If we encountered a transform, we can't do simple arithmetic to figure
* out how to convert back to aFrame's coordinates and must use the CTM.
*/
if (transformFound || nsSVGUtils::IsInSVGTextSubtree(aFrame)) {
return TransformRootPointToFrame(aFrame, widgetToView);
if (transformFound || nsSVGUtils::IsInSVGTextSubtree(frame)) {
return TransformRootPointToFrame(ViewportType::Layout, aFrame,
widgetToView);
}
/* Otherwise, all coordinate systems are translations of one another,
* so we can just subtract out the difference.
*/
return widgetToView - aFrame->GetOffsetToCrossDoc(rootFrame);
return widgetToView - frame->GetOffsetToCrossDoc(rootFrame);
}
nsIFrame* nsLayoutUtils::GetPopupFrameForEventCoordinates(
@ -2310,7 +2314,7 @@ nsIFrame* nsLayoutUtils::GetPopupFrameForEventCoordinates(
nsIFrame* popup = popups[i];
if (popup->PresContext()->GetRootPresContext() == aPresContext &&
popup->GetScrollableOverflowRect().Contains(
GetEventCoordinatesRelativeTo(aEvent, popup))) {
GetEventCoordinatesRelativeTo(aEvent, RelativeTo{popup}))) {
return popup;
}
}
@ -2347,8 +2351,8 @@ void nsLayoutUtils::GetContainerAndOffsetAtEvent(PresShell* aPresShell,
return;
}
nsPoint point =
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, targetFrame);
nsPoint point = nsLayoutUtils::GetEventCoordinatesRelativeTo(
aEvent, RelativeTo{targetFrame});
if (aContainer) {
// TODO: This result may be useful to change to Selection. However, this
@ -2611,22 +2615,23 @@ bool nsLayoutUtils::FrameHasDisplayPort(nsIFrame* aFrame,
}
Matrix4x4Flagged nsLayoutUtils::GetTransformToAncestor(
const nsIFrame* aFrame, const nsIFrame* aAncestor, uint32_t aFlags,
RelativeTo aFrame, RelativeTo aAncestor, uint32_t aFlags,
nsIFrame** aOutAncestor) {
nsIFrame* parent;
Matrix4x4Flagged ctm;
if (aFrame == aAncestor) {
return ctm;
}
ctm = aFrame->GetTransformMatrix(aAncestor, &parent, aFlags);
while (parent && parent != aAncestor &&
ctm = ctm *
aFrame.mFrame->GetTransformMatrix(aAncestor.mFrame, &parent, aFlags);
while (parent && parent != aAncestor.mFrame &&
(!(aFlags & nsIFrame::STOP_AT_STACKING_CONTEXT_AND_DISPLAY_PORT) ||
(!parent->HasAnyStateBits(NS_FRAME_OUT_OF_FLOW) &&
!parent->IsStackingContext() && !FrameHasDisplayPort(parent)))) {
if (!parent->Extend3DContext()) {
ctm.ProjectTo2D();
}
ctm = ctm * parent->GetTransformMatrix(aAncestor, &parent, aFlags);
ctm = ctm * parent->GetTransformMatrix(aAncestor.mFrame, &parent, aFlags);
}
if (aOutAncestor) {
*aOutAncestor = parent;
@ -2636,7 +2641,8 @@ Matrix4x4Flagged nsLayoutUtils::GetTransformToAncestor(
gfxSize nsLayoutUtils::GetTransformToAncestorScale(nsIFrame* aFrame) {
Matrix4x4Flagged transform = GetTransformToAncestor(
aFrame, nsLayoutUtils::GetDisplayRootFrame(aFrame));
RelativeTo{aFrame},
RelativeTo{nsLayoutUtils::GetDisplayRootFrame(aFrame)});
Matrix transform2D;
if (transform.Is2D(&transform2D)) {
return ThebesMatrix(transform2D).ScaleFactors(true);
@ -2714,14 +2720,14 @@ nsLayoutUtils::TransformResult nsLayoutUtils::TransformPoints(
if (!nearestCommonAncestor) {
return NO_COMMON_ANCESTOR;
}
Matrix4x4Flagged downToDest =
GetTransformToAncestor(aToFrame, nearestCommonAncestor);
Matrix4x4Flagged downToDest = GetTransformToAncestor(
RelativeTo{aToFrame}, RelativeTo{nearestCommonAncestor});
if (downToDest.IsSingular()) {
return NONINVERTIBLE_TRANSFORM;
}
downToDest.Invert();
Matrix4x4Flagged upToAncestor =
GetTransformToAncestor(aFromFrame, nearestCommonAncestor);
Matrix4x4Flagged upToAncestor = GetTransformToAncestor(
RelativeTo{aFromFrame}, RelativeTo{nearestCommonAncestor});
CSSToLayoutDeviceScale devPixelsPerCSSPixelFromFrame =
aFromFrame->PresContext()->CSSToDevPixelScale();
CSSToLayoutDeviceScale devPixelsPerCSSPixelToFrame =
@ -2745,10 +2751,17 @@ nsLayoutUtils::TransformResult nsLayoutUtils::TransformPoints(
}
nsLayoutUtils::TransformResult nsLayoutUtils::TransformPoint(
const nsIFrame* aFromFrame, const nsIFrame* aToFrame, nsPoint& aPoint) {
const nsIFrame* nearestCommonAncestor =
FindNearestCommonAncestorFrame(aFromFrame, aToFrame);
if (!nearestCommonAncestor) {
RelativeTo aFromFrame, RelativeTo aToFrame, nsPoint& aPoint) {
// Conceptually, {ViewportFrame, Visual} is an ancestor of
// {ViewportFrame, Layout}, so factor that into the nearest ancestor
// computation.
RelativeTo nearestCommonAncestor{
FindNearestCommonAncestorFrame(aFromFrame.mFrame, aToFrame.mFrame),
aFromFrame.mViewportType == ViewportType::Visual ||
aToFrame.mViewportType == ViewportType::Visual
? ViewportType::Visual
: ViewportType::Layout};
if (!nearestCommonAncestor.mFrame) {
return NO_COMMON_ANCESTOR;
}
Matrix4x4Flagged downToDest =
@ -2761,9 +2774,9 @@ nsLayoutUtils::TransformResult nsLayoutUtils::TransformPoint(
GetTransformToAncestor(aFromFrame, nearestCommonAncestor);
float devPixelsPerAppUnitFromFrame =
1.0f / aFromFrame->PresContext()->AppUnitsPerDevPixel();
1.0f / aFromFrame.mFrame->PresContext()->AppUnitsPerDevPixel();
float devPixelsPerAppUnitToFrame =
1.0f / aToFrame->PresContext()->AppUnitsPerDevPixel();
1.0f / aToFrame.mFrame->PresContext()->AppUnitsPerDevPixel();
Point4D toDevPixels = downToDest.ProjectPoint(upToAncestor.TransformPoint(
Point(aPoint.x * devPixelsPerAppUnitFromFrame,
aPoint.y * devPixelsPerAppUnitFromFrame)));
@ -2784,14 +2797,14 @@ nsLayoutUtils::TransformResult nsLayoutUtils::TransformRect(
if (!nearestCommonAncestor) {
return NO_COMMON_ANCESTOR;
}
Matrix4x4Flagged downToDest =
GetTransformToAncestor(aToFrame, nearestCommonAncestor);
Matrix4x4Flagged downToDest = GetTransformToAncestor(
RelativeTo{aToFrame}, RelativeTo{nearestCommonAncestor});
if (downToDest.IsSingular()) {
return NONINVERTIBLE_TRANSFORM;
}
downToDest.Invert();
Matrix4x4Flagged upToAncestor =
GetTransformToAncestor(aFromFrame, nearestCommonAncestor);
Matrix4x4Flagged upToAncestor = GetTransformToAncestor(
RelativeTo{aFromFrame}, RelativeTo{nearestCommonAncestor});
float devPixelsPerAppUnitFromFrame =
1.0f / aFromFrame->PresContext()->AppUnitsPerDevPixel();
@ -2914,8 +2927,9 @@ bool nsLayoutUtils::GetLayerTransformForFrame(nsIFrame* aFrame,
return true;
}
static bool TransformGfxPointFromAncestor(nsIFrame* aFrame, const Point& aPoint,
nsIFrame* aAncestor, Point* aOut) {
static bool TransformGfxPointFromAncestor(RelativeTo aFrame,
const Point& aPoint,
RelativeTo aAncestor, Point* aOut) {
Matrix4x4Flagged ctm =
nsLayoutUtils::GetTransformToAncestor(aFrame, aAncestor);
ctm.Invert();
@ -2928,7 +2942,7 @@ static bool TransformGfxPointFromAncestor(nsIFrame* aFrame, const Point& aPoint,
}
static Rect TransformGfxRectToAncestor(
const nsIFrame* aFrame, const Rect& aRect, const nsIFrame* aAncestor,
RelativeTo aFrame, const Rect& aRect, RelativeTo aAncestor,
bool* aPreservesAxisAlignedRectangles = nullptr,
Maybe<Matrix4x4Flagged>* aMatrixCache = nullptr,
bool aStopAtStackingContextAndDisplayPortAndOOFFrame = false,
@ -2956,7 +2970,7 @@ static Rect TransformGfxRectToAncestor(
*aPreservesAxisAlignedRectangles =
ctm.Is2D(&matrix2d) && matrix2d.PreservesAxisAlignedRectangles();
}
const nsIFrame* ancestor = aOutAncestor ? *aOutAncestor : aAncestor;
const nsIFrame* ancestor = aOutAncestor ? *aOutAncestor : aAncestor.mFrame;
float factor = ancestor->PresContext()->AppUnitsPerDevPixel();
Rect maxBounds =
Rect(float(nscoord_MIN) / factor * 0.5, float(nscoord_MIN) / factor * 0.5,
@ -2973,22 +2987,23 @@ static SVGTextFrame* GetContainingSVGTextFrame(const nsIFrame* aFrame) {
aFrame->GetParent(), LayoutFrameType::SVGText));
}
nsPoint nsLayoutUtils::TransformAncestorPointToFrame(nsIFrame* aFrame,
nsPoint nsLayoutUtils::TransformAncestorPointToFrame(RelativeTo aFrame,
const nsPoint& aPoint,
nsIFrame* aAncestor) {
SVGTextFrame* text = GetContainingSVGTextFrame(aFrame);
RelativeTo aAncestor) {
SVGTextFrame* text = GetContainingSVGTextFrame(aFrame.mFrame);
float factor = aFrame->PresContext()->AppUnitsPerDevPixel();
float factor = aFrame.mFrame->PresContext()->AppUnitsPerDevPixel();
Point result(NSAppUnitsToFloatPixels(aPoint.x, factor),
NSAppUnitsToFloatPixels(aPoint.y, factor));
if (!TransformGfxPointFromAncestor(text ? text : aFrame, result, aAncestor,
&result)) {
if (!TransformGfxPointFromAncestor(
text ? RelativeTo{text, aFrame.mViewportType} : aFrame, result,
aAncestor, &result)) {
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
}
if (text) {
result = text->TransformFramePointToTextChild(result, aFrame);
result = text->TransformFramePointToTextChild(result, aFrame.mFrame);
}
return nsPoint(NSFloatPixelsToAppUnits(float(result.x), factor),
@ -2996,7 +3011,7 @@ nsPoint nsLayoutUtils::TransformAncestorPointToFrame(nsIFrame* aFrame,
}
nsRect nsLayoutUtils::TransformFrameRectToAncestor(
const nsIFrame* aFrame, const nsRect& aRect, const nsIFrame* aAncestor,
const nsIFrame* aFrame, const nsRect& aRect, RelativeTo aAncestor,
bool* aPreservesAxisAlignedRectangles /* = nullptr */,
Maybe<Matrix4x4Flagged>* aMatrixCache /* = nullptr */,
bool aStopAtStackingContextAndDisplayPortAndOOFFrame /* = false */,
@ -3016,7 +3031,7 @@ nsRect nsLayoutUtils::TransformFrameRectToAncestor(
result.Scale(devPixelPerCSSPixel);
result = TransformGfxRectToAncestor(
text, result, aAncestor, nullptr, aMatrixCache,
RelativeTo{text}, result, aAncestor, nullptr, aMatrixCache,
aStopAtStackingContextAndDisplayPortAndOOFFrame, aOutAncestor);
// TransformFrameRectFromTextChild could involve any kind of transform, we
// could drill down into it to get an answer out of it but we don't yet.
@ -3029,13 +3044,13 @@ nsRect nsLayoutUtils::TransformFrameRectToAncestor(
NSAppUnitsToFloatPixels(aRect.width, srcAppUnitsPerDevPixel),
NSAppUnitsToFloatPixels(aRect.height, srcAppUnitsPerDevPixel));
result = TransformGfxRectToAncestor(
aFrame, result, aAncestor, aPreservesAxisAlignedRectangles,
RelativeTo{aFrame}, result, aAncestor, aPreservesAxisAlignedRectangles,
aMatrixCache, aStopAtStackingContextAndDisplayPortAndOOFFrame,
aOutAncestor);
}
float destAppUnitsPerDevPixel =
aAncestor->PresContext()->AppUnitsPerDevPixel();
aAncestor.mFrame->PresContext()->AppUnitsPerDevPixel();
return nsRect(
NSFloatPixelsToAppUnits(float(result.x), destAppUnitsPerDevPixel),
NSFloatPixelsToAppUnits(float(result.y), destAppUnitsPerDevPixel),

Просмотреть файл

@ -808,7 +808,7 @@ class nsLayoutUtils {
* the event is not a GUI event).
*/
static nsPoint GetEventCoordinatesRelativeTo(
const mozilla::WidgetEvent* aEvent, nsIFrame* aFrame);
const mozilla::WidgetEvent* aEvent, RelativeTo aFrame);
/**
* Get the coordinates of a given point relative to an event and a
@ -822,7 +822,7 @@ class nsLayoutUtils {
*/
static nsPoint GetEventCoordinatesRelativeTo(
const mozilla::WidgetEvent* aEvent,
const mozilla::LayoutDeviceIntPoint& aPoint, nsIFrame* aFrame);
const mozilla::LayoutDeviceIntPoint& aPoint, RelativeTo aFrame);
/**
* Get the coordinates of a given point relative to a widget and a
@ -836,7 +836,7 @@ class nsLayoutUtils {
*/
static nsPoint GetEventCoordinatesRelativeTo(
nsIWidget* aWidget, const mozilla::LayoutDeviceIntPoint& aPoint,
nsIFrame* aFrame);
RelativeTo aFrame);
/**
* Get the popup frame of a given native mouse event.
@ -966,6 +966,17 @@ class nsLayoutUtils {
bool* aPreservesAxisAlignedRectangles = nullptr,
mozilla::Maybe<Matrix4x4Flagged>* aMatrixCache = nullptr,
bool aStopAtStackingContextAndDisplayPortAndOOFFrame = false,
nsIFrame** aOutAncestor = nullptr) {
return TransformFrameRectToAncestor(
aFrame, aRect, RelativeTo{aAncestor}, aPreservesAxisAlignedRectangles,
aMatrixCache, aStopAtStackingContextAndDisplayPortAndOOFFrame,
aOutAncestor);
}
static nsRect TransformFrameRectToAncestor(
const nsIFrame* aFrame, const nsRect& aRect, RelativeTo aAncestor,
bool* aPreservesAxisAlignedRectangles = nullptr,
mozilla::Maybe<Matrix4x4Flagged>* aMatrixCache = nullptr,
bool aStopAtStackingContextAndDisplayPortAndOOFFrame = false,
nsIFrame** aOutAncestor = nullptr);
/**
@ -976,7 +987,7 @@ class nsLayoutUtils {
* More info can be found in nsIFrame::GetTransformMatrix.
*/
static Matrix4x4Flagged GetTransformToAncestor(
const nsIFrame* aFrame, const nsIFrame* aAncestor, uint32_t aFlags = 0,
RelativeTo aFrame, RelativeTo aAncestor, uint32_t aFlags = 0,
nsIFrame** aOutAncestor = nullptr);
/**
@ -1024,9 +1035,8 @@ class nsLayoutUtils {
* Same as above function, but transform points in app units and
* handle 1 point per call.
*/
static TransformResult TransformPoint(const nsIFrame* aFromFrame,
const nsIFrame* aToFrame,
nsPoint& aPoint);
static TransformResult TransformPoint(RelativeTo aFromFrame,
RelativeTo aToFrame, nsPoint& aPoint);
/**
* Transforms a rect from aFromFrame to aToFrame. In app units.
@ -1077,23 +1087,27 @@ class nsLayoutUtils {
* in the coordinate system of aFrame. This effectively inverts all
* transforms between this point and the root frame.
*
* @param aFromType Specifies whether |aPoint| is in layout or visual
* coordinates.
* @param aFrame The frame that acts as the coordinate space container.
* @param aPoint The point, in the global space, to get in the frame-local
* space.
* @param aPoint The point, in global layout or visual coordinates (as per
* |aFromType|, to get in the frame-local space.
* @return aPoint, expressed in aFrame's canonical coordinate space.
*/
static nsPoint TransformRootPointToFrame(nsIFrame* aFrame,
static nsPoint TransformRootPointToFrame(ViewportType aFromType,
RelativeTo aFrame,
const nsPoint& aPoint) {
return TransformAncestorPointToFrame(aFrame, aPoint, nullptr);
return TransformAncestorPointToFrame(aFrame, aPoint,
RelativeTo{nullptr, aFromType});
}
/**
* Transform aPoint relative to aAncestor down to the coordinate system of
* aFrame.
*/
static nsPoint TransformAncestorPointToFrame(nsIFrame* aFrame,
static nsPoint TransformAncestorPointToFrame(RelativeTo aFrame,
const nsPoint& aPoint,
nsIFrame* aAncestor);
RelativeTo aAncestor);
/**
* Helper function that, given a rectangle and a matrix, returns the smallest

Просмотреть файл

@ -140,7 +140,8 @@ nsresult nsImageControlFrame::HandleEvent(nsPresContext* aPresContext,
mContent->GetProperty(nsGkAtoms::imageClickedPoint));
if (lastClickPoint) {
// normally lastClickedPoint is not null, as it's allocated in Init()
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this);
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
aEvent, RelativeTo{this});
TranslateEventCoords(pt, *lastClickPoint);
}
}

Просмотреть файл

@ -196,7 +196,7 @@ int32_t nsNumberControlFrame::GetSpinButtonForPointerEvent(
// default UA style sheet. See the comment in forms.css for why.
LayoutDeviceIntPoint absPoint = aEvent->mRefPoint;
nsPoint point = nsLayoutUtils::GetEventCoordinatesRelativeTo(
aEvent, absPoint, mSpinBox->GetPrimaryFrame());
aEvent, absPoint, RelativeTo{mSpinBox->GetPrimaryFrame()});
if (point != nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE)) {
if (point.y < mSpinBox->GetPrimaryFrame()->GetSize().height / 2) {
return eSpinButtonUp;

Просмотреть файл

@ -497,8 +497,8 @@ Decimal nsRangeFrame::GetValueAtEventPoint(WidgetGUIEvent* aEvent) {
} else {
absPoint = aEvent->mRefPoint;
}
nsPoint point =
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, absPoint, this);
nsPoint point = nsLayoutUtils::GetEventCoordinatesRelativeTo(
aEvent, absPoint, RelativeTo{this});
if (point == nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE)) {
// We don't want to change the current value for this error state.

Просмотреть файл

@ -27,6 +27,7 @@
#include "mozilla/Sprintf.h"
#include "mozilla/StaticPrefs_layout.h"
#include "mozilla/ToString.h"
#include "mozilla/ViewportUtils.h"
#include "nsCOMPtr.h"
#include "nsFlexContainerFrame.h"
@ -4734,7 +4735,7 @@ nsFrame::HandlePress(nsPresContext* aPresContext, WidgetGUIEvent* aEvent,
// coordinate stuff is the fix for bug #55921
if ((mRect - GetPosition())
.Contains(nsLayoutUtils::GetEventCoordinatesRelativeTo(
mouseEvent, this))) {
mouseEvent, RelativeTo{this}))) {
return NS_OK;
}
}
@ -4795,7 +4796,8 @@ nsFrame::HandlePress(nsPresContext* aPresContext, WidgetGUIEvent* aEvent,
return HandleMultiplePress(aPresContext, mouseEvent, aEventStatus, control);
}
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mouseEvent, this);
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mouseEvent,
RelativeTo{this});
ContentOffsets offsets = GetContentOffsetsFromPoint(pt, SKIP_HIDDEN);
if (!offsets.content) return NS_ERROR_FAILURE;
@ -4976,8 +4978,8 @@ nsFrame::HandleMultiplePress(nsPresContext* aPresContext,
return NS_OK;
}
nsPoint relPoint =
nsLayoutUtils::GetEventCoordinatesRelativeTo(mouseEvent, this);
nsPoint relPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(
mouseEvent, RelativeTo{this});
return SelectByTypeAtPoint(aPresContext, relPoint, beginAmount, endAmount,
(aControlHeld ? SELECT_ACCUMULATE : 0));
}
@ -5090,7 +5092,8 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsPresContext* aPresContext,
return result;
}
} else {
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mouseEvent, this);
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mouseEvent,
RelativeTo{this});
frameselection->HandleDrag(this, pt);
}
@ -5108,8 +5111,8 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsPresContext* aPresContext,
if (scrollFrame) {
nsIFrame* capturingFrame = scrollFrame->GetScrolledFrame();
if (capturingFrame) {
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mouseEvent,
capturingFrame);
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
mouseEvent, RelativeTo{capturingFrame});
frameselection->StartAutoScrollTimer(capturingFrame, pt, 30);
}
}
@ -5213,7 +5216,8 @@ NS_IMETHODIMP nsFrame::HandleRelease(nsPresContext* aPresContext,
// Place the caret before continuing!
if (frameselection->MouseDownRecorded()) {
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this);
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
aEvent, RelativeTo{this});
offsets = GetContentOffsetsFromPoint(pt, SKIP_HIDDEN);
handleTableSelection = false;
} else {
@ -5687,8 +5691,8 @@ nsIFrame::ContentOffsets nsIFrame::GetContentOffsetsFromPoint(
nsPoint pt;
if (closest.frame != this) {
if (nsSVGUtils::IsInSVGTextSubtree(closest.frame)) {
pt = nsLayoutUtils::TransformAncestorPointToFrame(closest.frame, aPoint,
this);
pt = nsLayoutUtils::TransformAncestorPointToFrame(
RelativeTo{closest.frame}, aPoint, RelativeTo{this});
} else {
pt = aPoint - closest.frame->GetOffsetTo(this);
}
@ -7303,7 +7307,8 @@ Matrix4x4Flagged nsIFrame::GetTransformMatrix(const nsIFrame* aStopAtAncestor,
*aOutAncestor = docRootFrame;
Matrix4x4 docRootTransformToTop =
nsLayoutUtils::GetTransformToAncestor(docRootFrame, nullptr)
nsLayoutUtils::GetTransformToAncestor(RelativeTo{docRootFrame},
RelativeTo{nullptr})
.GetMatrix();
if (docRootTransformToTop.IsSingular()) {
NS_WARNING(

Просмотреть файл

@ -7055,7 +7055,8 @@ bool ScrollFrameHelper::DragScroll(WidgetEvent* aEvent) {
// far as it can go in both directions. Return false so that an ancestor
// scrollframe can scroll instead.
bool willScroll = false;
nsPoint pnt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, mOuter);
nsPoint pnt =
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, RelativeTo{mOuter});
nsPoint scrollPoint = GetScrollPosition();
nsRect rangeRect = GetLayoutScrollRange();

Просмотреть файл

@ -2261,7 +2261,8 @@ nsresult nsImageFrame::GetContentForEvent(WidgetEvent* aEvent,
if (nsImageMap* map = GetImageMap()) {
nsIntPoint p;
TranslateEventCoords(
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this), p);
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, RelativeTo{this}),
p);
nsCOMPtr<nsIContent> area = map->GetArea(p.x, p.y);
if (area) {
area.forget(aContent);
@ -2287,8 +2288,9 @@ nsresult nsImageFrame::HandleEvent(nsPresContext* aPresContext,
bool isServerMap = IsServerImageMap();
if (map || isServerMap) {
nsIntPoint p;
TranslateEventCoords(
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this), p);
TranslateEventCoords(nsLayoutUtils::GetEventCoordinatesRelativeTo(
aEvent, RelativeTo{this}),
p);
bool inside = false;
// Even though client-side image map triggering happens
// through content, we need to make sure we're not inside

Просмотреть файл

@ -6503,7 +6503,9 @@ gfxSize FrameLayerBuilder::GetPaintedLayerScaleForFrame(nsIFrame* aFrame) {
Matrix4x4Flagged transform = Matrix4x4::Scaling(resolution, resolution, 1.0);
if (aFrame != root) {
// aTransform is applied first, then the scale is applied to the result
transform = nsLayoutUtils::GetTransformToAncestor(aFrame, root) * transform;
transform = nsLayoutUtils::GetTransformToAncestor(RelativeTo{aFrame},
RelativeTo{root}) *
transform;
}
Matrix transform2d;

Просмотреть файл

@ -2246,8 +2246,8 @@ void nsDisplayListBuilder::AdjustWindowDraggingRegion(nsIFrame* aFrame) {
// RTL mode - it should be able to exclude itself from the draggable region.
referenceFrameToRootReferenceFrame =
ViewAs<LayoutDeviceToLayoutDeviceMatrix4x4>(
nsLayoutUtils::GetTransformToAncestor(referenceFrame,
mReferenceFrame)
nsLayoutUtils::GetTransformToAncestor(RelativeTo{referenceFrame},
RelativeTo{mReferenceFrame})
.GetMatrix());
Matrix referenceFrameToRootReferenceFrame2d;
if (!referenceFrameToRootReferenceFrame.Is2D(
@ -8438,7 +8438,8 @@ auto nsDisplayTransform::ShouldPrerenderTransformedContent(
nsSize maxSize = Min(relativeLimit, absoluteLimit);
const auto transform = nsLayoutUtils::GetTransformToAncestor(
aFrame, nsLayoutUtils::GetDisplayRootFrame(aFrame));
RelativeTo{aFrame},
RelativeTo{nsLayoutUtils::GetDisplayRootFrame(aFrame)});
const gfxRect transformedBounds = transform.TransformAndClipBounds(
gfxRect(overflow.x, overflow.y, overflow.width, overflow.height),
gfxRect::MaxIntRect());

Просмотреть файл

@ -5234,8 +5234,8 @@ double SVGTextFrame::GetFontSizeScaleFactor() const {
* it to the appropriate frame user space of aChildFrame according to
* which rendered run the point hits.
*/
Point SVGTextFrame::TransformFramePointToTextChild(const Point& aPoint,
nsIFrame* aChildFrame) {
Point SVGTextFrame::TransformFramePointToTextChild(
const Point& aPoint, const nsIFrame* aChildFrame) {
NS_ASSERTION(aChildFrame && nsLayoutUtils::GetClosestFrameOfType(
aChildFrame->GetParent(),
LayoutFrameType::SVGText) == this,

Просмотреть файл

@ -317,7 +317,7 @@ class SVGTextFrame final : public nsSVGDisplayContainerFrame {
* according to which rendered run the point hits.
*/
Point TransformFramePointToTextChild(const Point& aPoint,
nsIFrame* aChildFrame);
const nsIFrame* aChildFrame);
/**
* Takes an app unit rectangle in the coordinate space of a given descendant

Просмотреть файл

@ -310,7 +310,8 @@ nsIFrame* nsSVGUtils::GetOuterSVGFrameAndCoveredRegion(nsIFrame* aFrame,
nsSVGUtils::eForGetClientRects | nsSVGUtils::eBBoxIncludeFill |
nsSVGUtils::eBBoxIncludeStroke | nsSVGUtils::eBBoxIncludeMarkers;
auto ctm = nsLayoutUtils::GetTransformToAncestor(aFrame, outer);
auto ctm = nsLayoutUtils::GetTransformToAncestor(RelativeTo{aFrame},
RelativeTo{outer});
float initPositionX = NSAppUnitsToFloatPixels(aFrame->GetPosition().x,
AppUnitsPerCSSPixel()),

Просмотреть файл

@ -1195,7 +1195,8 @@ void nsBoxFrame::WrapListsInRedirector(nsDisplayListBuilder* aBuilder,
bool nsBoxFrame::GetEventPoint(WidgetGUIEvent* aEvent, nsPoint& aPoint) {
LayoutDeviceIntPoint refPoint;
bool res = GetEventPoint(aEvent, refPoint);
aPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, refPoint, this);
aPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, refPoint,
RelativeTo{this});
return res;
}

Просмотреть файл

@ -68,8 +68,8 @@ nsresult nsScrollbarButtonFrame::HandleEvent(nsPresContext* aPresContext,
mCursorOnThis = false;
break;
case eMouseMove: {
nsPoint cursor =
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this);
nsPoint cursor = nsLayoutUtils::GetEventCoordinatesRelativeTo(
aEvent, RelativeTo{this});
nsRect frameRect(nsPoint(0, 0), GetSize());
mCursorOnThis = frameRect.Contains(cursor);
break;

Просмотреть файл

@ -385,8 +385,8 @@ void nsSplitterFrameInner::MouseDrag(nsPresContext* aPresContext,
bool isHorizontal = !mOuter->IsXULHorizontal();
// convert coord to pixels
nsPoint pt =
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, mParentBox);
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
aEvent, RelativeTo{mParentBox});
nscoord pos = isHorizontal ? pt.x : pt.y;
// mDragStart is in frame coordinates

Просмотреть файл

@ -616,7 +616,7 @@ void nsXULPopupManager::InitTriggerEvent(Event* aEvent, nsIContent* aPopup,
thisDocToRootDocOffset.y);
} else if (rootDocumentRootFrame) {
nsPoint pnt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
event, rootDocumentRootFrame);
event, RelativeTo{rootDocumentRootFrame});
mCachedMousePoint = LayoutDeviceIntPoint(
rootDocPresContext->AppUnitsToDevPixels(pnt.x),
rootDocPresContext->AppUnitsToDevPixels(pnt.y));

Просмотреть файл

@ -2272,7 +2272,8 @@ nsresult nsTreeBodyFrame::HandleEvent(nsPresContext* aPresContext,
WidgetGUIEvent* aEvent,
nsEventStatus* aEventStatus) {
if (aEvent->mMessage == eMouseOver || aEvent->mMessage == eMouseMove) {
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this);
nsPoint pt =
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, RelativeTo{this});
int32_t xTwips = pt.x - mInnerBox.x;
int32_t yTwips = pt.y - mInnerBox.y;
int32_t newrow = GetRowAtInternal(xTwips, yTwips);
@ -4034,7 +4035,8 @@ void nsTreeBodyFrame::ComputeDropPosition(WidgetGUIEvent* aEvent, int32_t* aRow,
// Convert the event's point to our coordinates. We want it in
// the coordinates of our inner box's coordinates.
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this);
nsPoint pt =
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, RelativeTo{this});
int32_t xTwips = pt.x - mInnerBox.x;
int32_t yTwips = pt.y - mInnerBox.y;