зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1358758 - Use CSSIntRect for nsIFrame::GetScreenRect. r=kats
MozReview-Commit-ID: KXPL1ERbFDa --HG-- extra : rebase_source : 263b18d1736b09bb62d914f066481281966b288c
This commit is contained in:
Родитель
0c4c482352
Коммит
a4c9e326d4
|
@ -191,7 +191,7 @@ XULTreeAccessible::ChildAtPoint(int32_t aX, int32_t aY,
|
|||
nsIFrame *rootFrame = presShell->GetRootFrame();
|
||||
NS_ENSURE_TRUE(rootFrame, nullptr);
|
||||
|
||||
nsIntRect rootRect = rootFrame->GetScreenRect();
|
||||
CSSIntRect rootRect = rootFrame->GetScreenRect();
|
||||
|
||||
int32_t clientX = presContext->DevPixelsToIntCSSPixels(aX) - rootRect.x;
|
||||
int32_t clientY = presContext->DevPixelsToIntCSSPixels(aY) - rootRect.y;
|
||||
|
|
|
@ -325,7 +325,7 @@ XULTreeGridRowAccessible::ChildAtPoint(int32_t aX, int32_t aY,
|
|||
nsIFrame *rootFrame = presShell->GetRootFrame();
|
||||
NS_ENSURE_TRUE(rootFrame, nullptr);
|
||||
|
||||
nsIntRect rootRect = rootFrame->GetScreenRect();
|
||||
CSSIntRect rootRect = rootFrame->GetScreenRect();
|
||||
|
||||
int32_t clientX = presContext->DevPixelsToIntCSSPixels(aX) - rootRect.x;
|
||||
int32_t clientY = presContext->DevPixelsToIntCSSPixels(aY) - rootRect.y;
|
||||
|
|
|
@ -2654,7 +2654,7 @@ ContentEventHandler::OnQueryDOMWidgetHittest(WidgetQueryContentEvent* aEvent)
|
|||
|
||||
LayoutDeviceIntPoint eventLoc =
|
||||
aEvent->mRefPoint + aEvent->mWidget->WidgetToScreenOffset();
|
||||
nsIntRect docFrameRect = docFrame->GetScreenRect(); // Returns CSS pixels
|
||||
CSSIntRect docFrameRect = docFrame->GetScreenRect();
|
||||
CSSIntPoint eventLocCSS(
|
||||
mPresContext->DevPixelsToIntCSSPixels(eventLoc.x) - docFrameRect.x,
|
||||
mPresContext->DevPixelsToIntCSSPixels(eventLoc.y) - docFrameRect.y);
|
||||
|
|
|
@ -234,8 +234,10 @@ WheelTransaction::OnEvent(WidgetEvent* aEvent)
|
|||
if (mouseEvent->IsReal()) {
|
||||
// If the cursor is moving to be outside the frame,
|
||||
// terminate the scrollwheel transaction.
|
||||
nsIntPoint pt = GetScreenPoint(mouseEvent);
|
||||
nsIntRect r = sTargetFrame->GetScreenRect();
|
||||
LayoutDeviceIntPoint pt = GetScreenPoint(mouseEvent);
|
||||
auto r = LayoutDeviceIntRect::FromAppUnitsToNearest(
|
||||
sTargetFrame->GetScreenRectInAppUnits(),
|
||||
sTargetFrame->PresContext()->AppUnitsPerDevPixel());
|
||||
if (!r.Contains(pt)) {
|
||||
EndTransaction();
|
||||
return;
|
||||
|
@ -336,13 +338,12 @@ WheelTransaction::SetTimeout()
|
|||
"nsITimer::InitWithFuncCallback failed");
|
||||
}
|
||||
|
||||
/* static */ nsIntPoint
|
||||
/* static */ LayoutDeviceIntPoint
|
||||
WheelTransaction::GetScreenPoint(WidgetGUIEvent* aEvent)
|
||||
{
|
||||
NS_ASSERTION(aEvent, "aEvent is null");
|
||||
NS_ASSERTION(aEvent->mWidget, "aEvent-mWidget is null");
|
||||
return (aEvent->mRefPoint + aEvent->mWidget->WidgetToScreenOffset())
|
||||
.ToUnknownPoint();
|
||||
return aEvent->mRefPoint + aEvent->mWidget->WidgetToScreenOffset();
|
||||
}
|
||||
|
||||
/* static */ uint32_t
|
||||
|
|
|
@ -158,7 +158,7 @@ protected:
|
|||
static bool UpdateTransaction(WidgetWheelEvent* aEvent);
|
||||
static void MayEndTransaction();
|
||||
|
||||
static nsIntPoint GetScreenPoint(WidgetGUIEvent* aEvent);
|
||||
static LayoutDeviceIntPoint GetScreenPoint(WidgetGUIEvent* aEvent);
|
||||
static void OnFailToScrollTarget();
|
||||
static void OnTimeout(nsITimer* aTimer, void* aClosure);
|
||||
static void SetTimeout();
|
||||
|
|
|
@ -105,10 +105,6 @@ using namespace mozilla;
|
|||
using namespace mozilla::dom;
|
||||
using namespace mozilla::layers;
|
||||
|
||||
static inline nsPoint AsNsPoint(const nsIntPoint &p) {
|
||||
return nsPoint(p.x, p.y);
|
||||
}
|
||||
|
||||
// special class for handeling DOM context menu events because for
|
||||
// some reason it starves other mouse events if implemented on the
|
||||
// same class
|
||||
|
@ -1066,47 +1062,53 @@ NPBool nsPluginInstanceOwner::ConvertPointPuppet(PuppetWidget *widget,
|
|||
}
|
||||
|
||||
nsPresContext* presContext = pluginFrame->PresContext();
|
||||
double scaleFactor = double(nsPresContext::AppUnitsPerCSSPixel())/
|
||||
presContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom();
|
||||
CSSToLayoutDeviceScale scaleFactor(
|
||||
double(nsPresContext::AppUnitsPerCSSPixel()) /
|
||||
presContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom());
|
||||
|
||||
PuppetWidget *puppetWidget = static_cast<PuppetWidget*>(widget);
|
||||
PuppetWidget *rootWidget = static_cast<PuppetWidget*>(widget->GetTopLevelWidget());
|
||||
if (!rootWidget) {
|
||||
return false;
|
||||
}
|
||||
nsPoint chromeSize = AsNsPoint(rootWidget->GetChromeDimensions()) / scaleFactor;
|
||||
CSSIntPoint chromeSize = CSSIntPoint::Truncate(
|
||||
LayoutDeviceIntPoint::FromUnknownPoint(rootWidget->GetChromeDimensions()) /
|
||||
scaleFactor);
|
||||
nsIntSize intScreenDims = rootWidget->GetScreenDimensions();
|
||||
nsSize screenDims = nsSize(intScreenDims.width / scaleFactor,
|
||||
intScreenDims.height / scaleFactor);
|
||||
CSSIntSize screenDims = CSSIntSize::Truncate(
|
||||
LayoutDeviceIntSize::FromUnknownSize(intScreenDims) / scaleFactor);
|
||||
int32_t screenH = screenDims.height;
|
||||
nsPoint windowPosition = AsNsPoint(rootWidget->GetWindowPosition()) / scaleFactor;
|
||||
CSSIntPoint windowPosition = CSSIntPoint::Truncate(
|
||||
LayoutDeviceIntPoint::FromUnknownPoint(rootWidget->GetWindowPosition()) /
|
||||
scaleFactor);
|
||||
|
||||
// Window size is tab size + chrome size.
|
||||
LayoutDeviceIntRect tabContentBounds = puppetWidget->GetBounds();
|
||||
tabContentBounds.ScaleInverseRoundOut(scaleFactor);
|
||||
tabContentBounds.ScaleInverseRoundOut(scaleFactor.scale);
|
||||
int32_t windowH = tabContentBounds.height + int(chromeSize.y);
|
||||
|
||||
nsPoint pluginPosition = AsNsPoint(pluginFrame->GetScreenRect().TopLeft());
|
||||
CSSIntPoint pluginPosition = pluginFrame->GetScreenRect().TopLeft();
|
||||
|
||||
// Convert (sourceX, sourceY) to 'real' (not PuppetWidget) screen space.
|
||||
// In OSX, the Y-axis increases upward, which is the reverse of ours.
|
||||
// We want OSX coordinates for window and screen so those equations are swapped.
|
||||
nsPoint sourcePoint(sourceX, sourceY);
|
||||
nsPoint screenPoint;
|
||||
CSSIntPoint sourcePoint = CSSIntPoint::Truncate(sourceX, sourceY);
|
||||
CSSIntPoint screenPoint;
|
||||
switch (sourceSpace) {
|
||||
case NPCoordinateSpacePlugin:
|
||||
screenPoint = sourcePoint + pluginPosition +
|
||||
pluginFrame->GetContentRectRelativeToSelf().TopLeft() / nsPresContext::AppUnitsPerCSSPixel();
|
||||
CSSIntPoint::Truncate(CSSPoint::FromAppUnits(
|
||||
pluginFrame->GetContentRectRelativeToSelf().TopLeft()));
|
||||
break;
|
||||
case NPCoordinateSpaceWindow:
|
||||
screenPoint = nsPoint(sourcePoint.x, windowH-sourcePoint.y) +
|
||||
screenPoint = CSSIntPoint(sourcePoint.x, windowH-sourcePoint.y) +
|
||||
windowPosition;
|
||||
break;
|
||||
case NPCoordinateSpaceFlippedWindow:
|
||||
screenPoint = sourcePoint + windowPosition;
|
||||
break;
|
||||
case NPCoordinateSpaceScreen:
|
||||
screenPoint = nsPoint(sourcePoint.x, screenH-sourcePoint.y);
|
||||
screenPoint = CSSIntPoint(sourcePoint.x, screenH-sourcePoint.y);
|
||||
break;
|
||||
case NPCoordinateSpaceFlippedScreen:
|
||||
screenPoint = sourcePoint;
|
||||
|
@ -1116,11 +1118,12 @@ NPBool nsPluginInstanceOwner::ConvertPointPuppet(PuppetWidget *widget,
|
|||
}
|
||||
|
||||
// Convert from screen to dest space.
|
||||
nsPoint destPoint;
|
||||
CSSIntPoint destPoint;
|
||||
switch (destSpace) {
|
||||
case NPCoordinateSpacePlugin:
|
||||
destPoint = screenPoint - pluginPosition -
|
||||
pluginFrame->GetContentRectRelativeToSelf().TopLeft() / nsPresContext::AppUnitsPerCSSPixel();
|
||||
CSSIntPoint::Truncate(CSSPoint::FromAppUnits(
|
||||
pluginFrame->GetContentRectRelativeToSelf().TopLeft()));
|
||||
break;
|
||||
case NPCoordinateSpaceWindow:
|
||||
destPoint = screenPoint - windowPosition;
|
||||
|
@ -1130,7 +1133,7 @@ NPBool nsPluginInstanceOwner::ConvertPointPuppet(PuppetWidget *widget,
|
|||
destPoint = screenPoint - windowPosition;
|
||||
break;
|
||||
case NPCoordinateSpaceScreen:
|
||||
destPoint = nsPoint(screenPoint.x, screenH-screenPoint.y);
|
||||
destPoint = CSSIntPoint(screenPoint.x, screenH-screenPoint.y);
|
||||
break;
|
||||
case NPCoordinateSpaceFlippedScreen:
|
||||
destPoint = screenPoint;
|
||||
|
@ -1189,7 +1192,7 @@ NPBool nsPluginInstanceOwner::ConvertPointNoPuppet(nsIWidget *widget,
|
|||
int32_t windowY = windowScreenBounds.y;
|
||||
int32_t windowHeight = windowScreenBounds.height;
|
||||
|
||||
nsIntRect pluginScreenRect = pluginFrame->GetScreenRect();
|
||||
CSSIntRect pluginScreenRect = pluginFrame->GetScreenRect();
|
||||
|
||||
double screenXGecko, screenYGecko;
|
||||
switch (sourceSpace) {
|
||||
|
|
|
@ -8441,8 +8441,9 @@ PresShell::AdjustContextMenuKeyEvent(WidgetMouseEvent* aEvent)
|
|||
nsCOMPtr<nsIWidget> widget = popupFrame->GetNearestWidget();
|
||||
aEvent->mWidget = widget;
|
||||
LayoutDeviceIntPoint widgetPoint = widget->WidgetToScreenOffset();
|
||||
aEvent->mRefPoint = LayoutDeviceIntPoint::FromUnknownPoint(
|
||||
itemFrame->GetScreenRect().BottomLeft()) - widgetPoint;
|
||||
aEvent->mRefPoint = LayoutDeviceIntPoint::FromAppUnitsToNearest(
|
||||
itemFrame->GetScreenRectInAppUnits().BottomLeft(),
|
||||
itemFrame->PresContext()->AppUnitsPerDevPixel()) - widgetPoint;
|
||||
|
||||
mCurrentEventContent = itemFrame->GetContent();
|
||||
mCurrentEventFrame = itemFrame;
|
||||
|
|
|
@ -240,6 +240,10 @@ struct CSSPixel {
|
|||
NSAppUnitsToIntPixels(aRect.height, float(AppUnitsPerCSSPixel())));
|
||||
}
|
||||
|
||||
static CSSIntRect FromAppUnitsToNearest(const nsRect& aRect) {
|
||||
return CSSIntRect::FromUnknownRect(aRect.ToNearestPixels(AppUnitsPerCSSPixel()));
|
||||
}
|
||||
|
||||
// Conversions to app units
|
||||
|
||||
static nscoord ToAppUnits(CSSCoord aCoord) {
|
||||
|
|
|
@ -6098,9 +6098,9 @@ nsIFrame::GetOffsetToCrossDoc(const nsIFrame* aOther, const int32_t aAPD) const
|
|||
return offset;
|
||||
}
|
||||
|
||||
nsIntRect nsIFrame::GetScreenRect() const
|
||||
CSSIntRect nsIFrame::GetScreenRect() const
|
||||
{
|
||||
return GetScreenRectInAppUnits().ToNearestPixels(PresContext()->AppUnitsPerCSSPixel());
|
||||
return CSSIntRect::FromAppUnitsToNearest(GetScreenRectInAppUnits());
|
||||
}
|
||||
|
||||
nsRect nsIFrame::GetScreenRectInAppUnits() const
|
||||
|
|
|
@ -2582,10 +2582,12 @@ public:
|
|||
nsPoint GetOffsetToCrossDoc(const nsIFrame* aOther, const int32_t aAPD) const;
|
||||
|
||||
/**
|
||||
* Get the screen rect of the frame in pixels.
|
||||
* @return the pixel rect of the frame in screen coordinates.
|
||||
* Get the rect of the frame relative to the top-left corner of the
|
||||
* screen in CSS pixels.
|
||||
* @return the CSS pixel rect of the frame relative to the top-left
|
||||
* corner of the screen.
|
||||
*/
|
||||
nsIntRect GetScreenRect() const;
|
||||
mozilla::CSSIntRect GetScreenRect() const;
|
||||
|
||||
/**
|
||||
* Get the screen rect of the frame in app units.
|
||||
|
|
|
@ -217,7 +217,7 @@ BoxObject::GetScreenPosition(nsIntPoint& aPoint)
|
|||
|
||||
nsIFrame* frame = GetFrame(true);
|
||||
if (frame) {
|
||||
nsIntRect rect = frame->GetScreenRect();
|
||||
CSSIntRect rect = frame->GetScreenRect();
|
||||
aPoint.x = rect.x;
|
||||
aPoint.y = rect.y;
|
||||
}
|
||||
|
|
|
@ -202,7 +202,7 @@ nsResizerFrame::HandleEvent(nsPresContext* aPresContext,
|
|||
nsCOMPtr<nsIScreen> screen;
|
||||
nsCOMPtr<nsIScreenManager> sm(do_GetService("@mozilla.org/gfx/screenmanager;1"));
|
||||
if (sm) {
|
||||
nsIntRect frameRect = GetScreenRect();
|
||||
CSSIntRect frameRect = GetScreenRect();
|
||||
// ScreenForRect requires display pixels, so scale from device pix
|
||||
double scale;
|
||||
window->GetUnscaledDevicePixelsPerCSSPixel(&scale);
|
||||
|
|
|
@ -262,11 +262,11 @@ nsXULPopupManager::Rollup(uint32_t aCount, bool aFlush,
|
|||
// reopen the menu.
|
||||
if ((consumeResult == ConsumeOutsideClicks_ParentOnly || noRollupOnAnchor) && pos) {
|
||||
nsMenuPopupFrame* popupFrame = item->Frame();
|
||||
nsIntRect anchorRect;
|
||||
CSSIntRect anchorRect;
|
||||
if (popupFrame->IsAnchored()) {
|
||||
// Check if the popup has a screen anchor rectangle. If not, get the rectangle
|
||||
// from the anchor element.
|
||||
anchorRect = popupFrame->GetScreenAnchorRect();
|
||||
anchorRect = CSSIntRect::FromUnknownRect(popupFrame->GetScreenAnchorRect());
|
||||
if (anchorRect.x == -1 || anchorRect.y == -1) {
|
||||
nsCOMPtr<nsIContent> anchor = popupFrame->GetAnchor();
|
||||
|
||||
|
@ -298,8 +298,8 @@ nsXULPopupManager::Rollup(uint32_t aCount, bool aFlush,
|
|||
// event will get consumed, so here only a quick coordinates check is
|
||||
// done rather than a slower complete check of what is at that location.
|
||||
nsPresContext* presContext = item->Frame()->PresContext();
|
||||
nsIntPoint posCSSPixels(presContext->DevPixelsToIntCSSPixels(pos->x),
|
||||
presContext->DevPixelsToIntCSSPixels(pos->y));
|
||||
CSSIntPoint posCSSPixels(presContext->DevPixelsToIntCSSPixels(pos->x),
|
||||
presContext->DevPixelsToIntCSSPixels(pos->y));
|
||||
if (anchorRect.Contains(posCSSPixels)) {
|
||||
if (consumeResult == ConsumeOutsideClicks_ParentOnly) {
|
||||
consume = true;
|
||||
|
|
|
@ -588,13 +588,13 @@ nsBaseDragService::DrawDrag(nsIDOMNode* aDOMNode,
|
|||
if (!enableDragImages || !mHasImage) {
|
||||
// if a region was specified, set the screen rectangle to the area that
|
||||
// the region occupies
|
||||
nsIntRect dragRect;
|
||||
CSSIntRect dragRect;
|
||||
if (aRegion) {
|
||||
// the region's coordinates are relative to the root frame
|
||||
aRegion->GetBoundingBox(&dragRect.x, &dragRect.y, &dragRect.width, &dragRect.height);
|
||||
|
||||
nsIFrame* rootFrame = presShell->GetRootFrame();
|
||||
nsIntRect screenRect = rootFrame->GetScreenRect();
|
||||
CSSIntRect screenRect = rootFrame->GetScreenRect();
|
||||
dragRect.MoveBy(screenRect.TopLeft());
|
||||
}
|
||||
else {
|
||||
|
@ -607,9 +607,10 @@ nsBaseDragService::DrawDrag(nsIDOMNode* aDOMNode,
|
|||
}
|
||||
}
|
||||
|
||||
dragRect = ToAppUnits(dragRect, nsPresContext::AppUnitsPerCSSPixel()).
|
||||
ToOutsidePixels((*aPresContext)->AppUnitsPerDevPixel());
|
||||
aScreenDragRect->SizeTo(dragRect.width, dragRect.height);
|
||||
nsIntRect dragRectDev =
|
||||
ToAppUnits(dragRect, nsPresContext::AppUnitsPerCSSPixel()).
|
||||
ToOutsidePixels((*aPresContext)->AppUnitsPerDevPixel());
|
||||
aScreenDragRect->SizeTo(dragRectDev.width, dragRectDev.height);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче