Merge for "Backed out changeset: 719dca3419b5" of

Bug 476731 - Media element should fire error event when src is a 404; missing test_error_on_404.html; r=chris.double sr=roc
which
does not compile on Windows.
This commit is contained in:
Serge Gautherie 2009-02-15 18:44:14 +01:00
commit 3df905faa5
23 changed files with 324 additions and 100 deletions

View File

@ -344,7 +344,7 @@ nsCaretAccessible::GetCaretRect(nsIWidget **aOutWidget)
rect += offsetFromWidget;
caretRect = nsRect::ToOutsidePixels(rect, presContext->AppUnitsPerDevPixel());
caretRect.MoveBy((*aOutWidget)->WidgetToScreenOffset());
(*aOutWidget)->WidgetToScreen(caretRect, caretRect);
// Correct for character size, so that caret always matches the size of the character
// This is important for font size transitions, and is necessary because the Gecko caret uses the

View File

@ -136,8 +136,9 @@ nsDOMUIEvent::GetScreenPoint()
return mEvent->refPoint;
}
nsIntPoint offset = mEvent->refPoint +
((nsGUIEvent*)mEvent)->widget->WidgetToScreenOffset();
nsIntRect bounds(mEvent->refPoint, nsIntSize(1, 1));
nsIntRect offset;
((nsGUIEvent*)mEvent)->widget->WidgetToScreen ( bounds, offset );
nscoord factor = mPresContext->DeviceContext()->UnscaledAppUnitsPerDevPixel();
return nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(offset.x * factor),
nsPresContext::AppUnitsToIntCSSPixels(offset.y * factor));

View File

@ -587,7 +587,10 @@ nsMouseWheelTransaction::GetScreenPoint(nsGUIEvent* aEvent)
{
NS_ASSERTION(aEvent, "aEvent is null");
NS_ASSERTION(aEvent->widget, "aEvent-widget is null");
return aEvent->refPoint + aEvent->widget->WidgetToScreenOffset();
nsIntRect tmpRect;
aEvent->widget->WidgetToScreen(nsIntRect(aEvent->refPoint, nsIntSize(1, 1)),
tmpRect);
return tmpRect.TopLeft();
}
PRUint32
@ -2078,8 +2081,10 @@ nsEventStateManager::BeginTrackingDragGesture(nsPresContext* aPresContext,
{
// Note that |inDownEvent| could be either a mouse down event or a
// synthesized mouse move event.
mGestureDownPoint = inDownEvent->refPoint +
inDownEvent->widget->WidgetToScreenOffset();
nsIntRect screenPt;
inDownEvent->widget->WidgetToScreen(nsIntRect(inDownEvent->refPoint, nsIntSize(1, 1)),
screenPt);
mGestureDownPoint = screenPt.TopLeft();
inDownFrame->GetContentForEvent(aPresContext, inDownEvent,
getter_AddRefs(mGestureDownContent));
@ -2120,8 +2125,9 @@ nsEventStateManager::FillInEventFromGestureDown(nsMouseEvent* aEvent)
// Set the coordinates in the new event to the coordinates of
// the old event, adjusted for the fact that the widget might be
// different
nsIntPoint tmpPoint = aEvent->widget->WidgetToScreenOffset();
aEvent->refPoint = mGestureDownPoint - tmpPoint;
nsIntRect tmpRect(0, 0, 1, 1);
aEvent->widget->WidgetToScreen(tmpRect, tmpRect);
aEvent->refPoint = mGestureDownPoint - tmpRect.TopLeft();
aEvent->isShift = mGestureDownShift;
aEvent->isControl = mGestureDownControl;
aEvent->isAlt = mGestureDownAlt;
@ -2180,7 +2186,10 @@ nsEventStateManager::GenerateDragGesture(nsPresContext* aPresContext,
}
// fire drag gesture if mouse has moved enough
nsIntPoint pt = aEvent->refPoint + aEvent->widget->WidgetToScreenOffset();
nsIntRect tmpRect;
aEvent->widget->WidgetToScreen(nsIntRect(aEvent->refPoint, nsIntSize(1, 1)),
tmpRect);
nsIntPoint pt = tmpRect.TopLeft();
if (PR_ABS(pt.x - mGestureDownPoint.x) > pixelThresholdX ||
PR_ABS(pt.y - mGestureDownPoint.y) > pixelThresholdY) {
#ifdef CLICK_HOLD_CONTEXT_MENUS

View File

@ -1482,7 +1482,9 @@ ChromeTooltipListener::sTooltipCallback(nsITimer *aTimer,
if (textFound) {
nsString tipText(tooltipText);
self->CreateAutoHideTimer();
nsIntPoint screenDot = widget->WidgetToScreenOffset();
nsIntRect widgetDot(0, 0, 1, 1);
nsIntRect screenDot;
widget->WidgetToScreen(widgetDot, screenDot);
self->ShowTooltip (self->mMouseScreenX - screenDot.x,
self->mMouseScreenY - screenDot.y,
tipText);

View File

@ -111,9 +111,6 @@ struct nsIntPoint {
y -= aPoint.y;
return *this;
}
nsIntPoint operator-() const {
return nsIntPoint(-x, -y);
}
void MoveTo(PRInt32 aX, PRInt32 aY) {x = aX; y = aY;}
};

View File

@ -844,8 +844,11 @@ nsLayoutUtils::TranslateWidgetToView(nsPresContext* aPresContext,
if (fromRoot == toRoot) {
widgetPoint = aPt + fromOffset - toOffset;
} else {
nsIntPoint screenPoint = aWidget->WidgetToScreenOffset();
widgetPoint = aPt + screenPoint - viewWidget->WidgetToScreenOffset();
nsIntRect widgetRect(0, 0, 0, 0);
nsIntRect screenRect;
aWidget->WidgetToScreen(widgetRect, screenRect);
viewWidget->ScreenToWidget(screenRect, widgetRect);
widgetPoint = aPt + widgetRect.TopLeft();
}
nsPoint widgetAppUnits(aPresContext->DevPixelsToAppUnits(widgetPoint.x),

View File

@ -6015,8 +6015,9 @@ PresShell::AdjustContextMenuKeyEvent(nsMouseEvent* aEvent)
nsCOMPtr<nsIWidget> widget = popupFrame->GetWindow();
aEvent->widget = widget;
nsIntPoint widgetPoint = widget->WidgetToScreenOffset();
aEvent->refPoint = itemFrame->GetScreenRect().BottomLeft() - widgetPoint;
nsIntRect widgetRect(0, 0, 1, 1);
widget->WidgetToScreen(widgetRect, widgetRect);
aEvent->refPoint = itemFrame->GetScreenRect().BottomLeft() - widgetRect.TopLeft();
mCurrentEventContent = itemFrame->GetContent();
mCurrentEventFrame = itemFrame;

View File

@ -3555,12 +3555,13 @@ nsRect nsIFrame::GetScreenRectInAppUnits() const
nsIWidget* widget = view->GetNearestWidget(&toWidgetOffset);
if (widget) {
nsIntPoint screenPoint = widget->WidgetToScreenOffset();
nsIntRect localRect(0,0,0,0), screenRect;
widget->WidgetToScreen(localRect, screenRect);
retval = mRect;
retval.MoveTo(toViewOffset + toWidgetOffset);
retval.x += PresContext()->DevPixelsToAppUnits(screenPoint.x);
retval.y += PresContext()->DevPixelsToAppUnits(screenPoint.y);
retval.x += PresContext()->DevPixelsToAppUnits(screenRect.x);
retval.y += PresContext()->DevPixelsToAppUnits(screenRect.y);
}
}

View File

@ -3829,9 +3829,10 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const nsGUIEvent& anEvent)
const nsMouseEvent& mouseEvent =
static_cast<const nsMouseEvent&>(anEvent);
// Get reference point relative to screen:
nsIntPoint rootPoint(-1,-1);
nsIntRect windowRect(anEvent.refPoint, nsIntSize(1, 1));
nsIntRect rootPoint(-1,-1,1,1);
if (widget)
rootPoint = anEvent.refPoint + widget->WidgetToScreenOffset();
widget->WidgetToScreen(windowRect, rootPoint);
#ifdef MOZ_WIDGET_GTK2
Window root = GDK_ROOT_WINDOW();
#else
@ -4736,7 +4737,14 @@ WindowRef nsPluginInstanceOwner::FixUpPluginWindow(PRInt32 inPaintState)
// use its native widget (an obj-c object) we have to go
// from the widget's screen coordinates to its window coords
// instead of straight to window coords.
nsIntPoint geckoScreenCoords = mWidget->WidgetToScreenOffset();
nsIntRect geckoBounds;
mWidget->GetBounds(geckoBounds);
// we need a rect that is the entire *internal* rect, so the
// x and y coords are 0, width is the same.
geckoBounds.x = 0;
geckoBounds.y = 0;
nsIntRect geckoScreenCoords;
mWidget->WidgetToScreen(geckoBounds, geckoScreenCoords);
Rect windowRect;
WindowRef window = (WindowRef)pluginPort->cgPort.window;

View File

@ -373,9 +373,10 @@ nsIntRect nsView::CalcWidgetBounds(nsWindowType aType)
if (parentWidget && aType == eWindowType_popup &&
mVis == nsViewVisibility_kShow) {
nsIntPoint screenPoint = parentWidget->WidgetToScreenOffset();
viewBounds += nsPoint(NSIntPixelsToAppUnits(screenPoint.x, p2a),
NSIntPixelsToAppUnits(screenPoint.y, p2a));
nsIntRect screenRect(0,0,1,1);
parentWidget->WidgetToScreen(screenRect, screenRect);
viewBounds += nsPoint(NSIntPixelsToAppUnits(screenRect.x, p2a),
NSIntPixelsToAppUnits(screenRect.y, p2a));
}
}
@ -808,19 +809,21 @@ nsPoint nsIView::GetOffsetTo(const nsIView* aOther) const
nsIntPoint nsIView::GetScreenPosition() const
{
nsIntPoint screenPoint(0,0);
nsIntRect screenRect(0,0,0,0);
nsPoint toWidgetOffset(0,0);
nsIWidget* widget = GetNearestWidget(&toWidgetOffset);
if (widget) {
nsCOMPtr<nsIDeviceContext> dx;
mViewManager->GetDeviceContext(*getter_AddRefs(dx));
PRInt32 p2a = dx->AppUnitsPerDevPixel();
nsIntPoint ourPoint(NSAppUnitsToIntPixels(toWidgetOffset.x, p2a),
NSAppUnitsToIntPixels(toWidgetOffset.y, p2a));
screenPoint = ourPoint + widget->WidgetToScreenOffset();
nsIntRect ourRect(NSAppUnitsToIntPixels(toWidgetOffset.x, p2a),
NSAppUnitsToIntPixels(toWidgetOffset.y, p2a),
0,
0);
widget->WidgetToScreen(ourRect, screenRect);
}
return screenPoint;
return nsIntPoint(screenRect.x, screenRect.y);
}
nsIWidget* nsIView::GetNearestWidget(nsPoint* aOffset) const

View File

@ -97,10 +97,10 @@ typedef nsEventStatus (* EVENT_CALLBACK)(nsGUIEvent *event);
#define NS_NATIVE_TSF_POINTER 100
#endif
// 0dda48db-4f61-44a7-9f92-041cd92b8a9c
// 075a7792-6ba9-454e-b431-25a43fdbd3f6
#define NS_IWIDGET_IID \
{ 0x0dda48db, 0x4f61, 0x44a7, \
{ 0x9f, 0x92, 0x04, 0x1c, 0xd9, 0x2b, 0x8a, 0x9c } }
{ 0x075a7792, 0x6ba9, 0x454e, \
{ 0xb4, 0x31, 0x25, 0xa4, 0x3f, 0xdb, 0xd3, 0xf6 } }
// Hide the native window systems real window type so as to avoid
// including native window system types and APIs. This is necessary
@ -901,12 +901,22 @@ class nsIWidget : public nsISupports {
NS_IMETHOD ShowMenuBar(PRBool aShow) = 0;
/**
* Return this widget's origin in screen coordinates.
* Convert from this widget coordinates to screen coordinates.
*
* @return screen coordinates stored in the x,y members
* @param aOldRect widget coordinates stored in the x,y members
* @param aNewRect screen coordinates stored in the x,y members
*/
virtual nsIntPoint WidgetToScreenOffset() = 0;
NS_IMETHOD WidgetToScreen(const nsIntRect& aOldRect, nsIntRect& aNewRect) = 0;
/**
* Convert from screen coordinates to this widget's coordinates.
*
* @param aOldRect screen coordinates stored in the x,y members
* @param aNewRect widget's coordinates stored in the x,y members
*/
NS_IMETHOD ScreenToWidget(const nsIntRect& aOldRect, nsIntRect& aNewRect) = 0;
/**
* When adjustments are to made to a whole set of child widgets, call this

View File

@ -356,7 +356,8 @@ public:
virtual void* GetNativeData(PRUint32 aDataType);
NS_IMETHOD SetColorMap(nsColorMap *aColorMap);
NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsIntRect *aClipRect);
virtual nsIntPoint WidgetToScreenOffset();
NS_IMETHOD WidgetToScreen(const nsIntRect& aOldRect, nsIntRect& aNewRect);
NS_IMETHOD ScreenToWidget(const nsIntRect& aOldRect, nsIntRect& aNewRect);
NS_IMETHOD BeginResizingChildren(void);
NS_IMETHOD EndResizingChildren(void);
virtual PRBool ShowsResizeIndicator(nsIntRect* aResizerRect);

View File

@ -2097,33 +2097,68 @@ PRBool nsChildView::PointInWidget(Point aThePoint)
#pragma mark -
// Return the offset between this child view and the screen.
// @return -- widget origin in screen coordinates
nsIntPoint nsChildView::WidgetToScreenOffset()
// Convert the given rect to global coordinates.
// @param aLocalRect -- rect in local coordinates of this widget
// @param aGlobalRect -- |aLocalRect| in global coordinates
NS_IMETHODIMP nsChildView::WidgetToScreen(const nsIntRect& aLocalRect, nsIntRect& aGlobalRect)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
NSPoint temp;
temp.x = 0;
temp.y = 0;
NSRect temp;
GeckoRectToNSRect(aLocalRect, temp);
// 1. First translate this point into window coords. The returned point is always in
// 1. First translate this rect into window coords. The returned rect is always in
// bottom-left coordinates.
temp = [mView convertPoint:temp toView:nil];
//
// NOTE: convertRect:toView:nil doesn't care if |mView| is a flipped view (with
// top-left coords) and so assumes that our passed-in rect's origin is in
// bottom-left coordinates. We adjust this further down, by subtracting
// the final screen rect's origin by the rect's height, to get the origo
// where we want it.
temp = [mView convertRect:temp toView:nil];
// 2. We turn the window-coord rect's origin into screen (still bottom-left) coords.
temp = [[mView nativeWindow] convertBaseToScreen:temp];
temp.origin = [[mView nativeWindow] convertBaseToScreen:temp.origin];
// 3. Since we're dealing in bottom-left coords, we need to make it top-left coords
// before we pass it back to Gecko.
FlipCocoaScreenCoordinate(temp);
FlipCocoaScreenCoordinate(temp.origin);
return nsIntPoint(NSToIntRound(temp.x), NSToIntRound(temp.y));
// 4. If this is rect has a size (and is not simply a point), it is important to account
// for the fact that convertRect:toView:nil thought our passed-in point was in bottom-left
// coords in step #1. Thus, we subtract the rect's height, to get the top-left rect's origin
// where we want it.
temp.origin.y -= temp.size.height;
NSRectToGeckoRect(temp, aGlobalRect);
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(nsIntPoint(0,0));
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
// Convert the given rect to local coordinates.
// @param aGlobalRect -- rect in screen coordinates
// @param aLocalRect -- |aGlobalRect| in coordinates of this widget
NS_IMETHODIMP nsChildView::ScreenToWidget(const nsIntRect& aGlobalRect, nsIntRect& aLocalRect)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
NSRect temp;
GeckoRectToNSRect(aGlobalRect, temp);
FlipCocoaScreenCoordinate(temp.origin);
temp.origin = [[mView nativeWindow] convertScreenToBase:temp.origin]; // convert to screen coords
temp = [mView convertRect:temp fromView:nil]; // convert to window coords
NSRectToGeckoRect(temp, aLocalRect);
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
// Convert the coordinates to some device coordinates so GFX can draw.
void nsChildView::ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY)
{

View File

@ -222,7 +222,8 @@ public:
NS_IMETHOD SetMenuBar(void* aMenuBar);
virtual nsMenuBarX* GetMenuBar();
NS_IMETHOD ShowMenuBar(PRBool aShow);
virtual nsIntPoint WidgetToScreenOffset();
NS_IMETHOD WidgetToScreen(const nsIntRect& aOldRect, nsIntRect& aNewRect);
NS_IMETHOD ScreenToWidget(const nsIntRect& aOldRect, nsIntRect& aNewRect);
virtual void* GetNativeData(PRUint32 aDataType) ;

View File

@ -1221,15 +1221,37 @@ NS_IMETHODIMP nsCocoaWindow::ShowMenuBar(PRBool aShow)
}
nsIntPoint nsCocoaWindow::WidgetToScreenOffset()
NS_IMETHODIMP nsCocoaWindow::WidgetToScreen(const nsIntRect& aOldRect, nsIntRect& aNewRect)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect([mWindow contentRectForFrameRect:[mWindow frame]]);
return r.TopLeft();
aNewRect.x = r.x + aOldRect.x;
aNewRect.y = r.y + aOldRect.y;
aNewRect.width = aOldRect.width;
aNewRect.height = aOldRect.height;
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(nsIntPoint(0,0));
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
NS_IMETHODIMP nsCocoaWindow::ScreenToWidget(const nsIntRect& aOldRect, nsIntRect& aNewRect)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect([mWindow contentRectForFrameRect:[mWindow frame]]);
aNewRect.x = aOldRect.x - r.x;
aNewRect.y = aOldRect.y - r.y;
aNewRect.width = aOldRect.width;
aNewRect.height = aOldRect.height;
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}

View File

@ -1350,7 +1350,8 @@ nsWindow::SetFocus(PRBool aRaise)
NS_IMETHODIMP
nsWindow::GetScreenBounds(nsIntRect &aRect)
{
aRect = nsIntRect(WidgetToScreenOffset(), mBounds.Size());
nsIntRect origin(0, 0, mBounds.width, mBounds.height);
WidgetToScreen(origin, aRect);
LOG(("GetScreenBounds %d %d | %d %d | %d %d\n",
aRect.x, aRect.y,
mBounds.width, mBounds.height,
@ -1852,22 +1853,48 @@ nsWindow::ShowMenuBar(PRBool aShow)
return NS_ERROR_NOT_IMPLEMENTED;
}
nsIntPoint
nsWindow::WidgetToScreenOffset()
NS_IMETHODIMP
nsWindow::WidgetToScreen(const nsIntRect& aOldRect, nsIntRect& aNewRect)
{
gint x = 0, y = 0;
if (mContainer) {
gdk_window_get_root_origin(GTK_WIDGET(mContainer)->window,
&x, &y);
LOG(("WidgetToScreenOffset (container) %d %d\n", x, y));
LOG(("WidgetToScreen (container) %d %d\n", x, y));
}
else if (mDrawingarea) {
gdk_window_get_origin(mDrawingarea->inner_window, &x, &y);
LOG(("WidgetToScreenOffset (drawing) %d %d\n", x, y));
LOG(("WidgetToScreen (drawing) %d %d\n", x, y));
}
return nsIntPoint(x, y);
aNewRect.x = x + aOldRect.x;
aNewRect.y = y + aOldRect.y;
aNewRect.width = aOldRect.width;
aNewRect.height = aOldRect.height;
return NS_OK;
}
NS_IMETHODIMP
nsWindow::ScreenToWidget(const nsIntRect& aOldRect, nsIntRect& aNewRect)
{
gint x = 0, y = 0;
if (mContainer) {
gdk_window_get_root_origin(GTK_WIDGET(mContainer)->window,
&x, &y);
}
else if (mDrawingarea) {
gdk_window_get_origin(mDrawingarea->inner_window, &x, &y);
}
aNewRect.x = aOldRect.x - x;
aNewRect.y = aOldRect.y - y;
aNewRect.width = aOldRect.width;
aNewRect.height = aOldRect.height;
return NS_OK;
}
NS_IMETHODIMP
@ -2353,7 +2380,10 @@ nsWindow::OnConfigureEvent(GtkWidget *aWidget, GdkEventConfigure *aEvent)
if (mIsTopLevel) {
mPlaced = PR_TRUE;
// Need to translate this into the right coordinates
mBounds.MoveTo(WidgetToScreenOffset());
nsIntRect oldrect, newrect;
WidgetToScreen(oldrect, newrect);
mBounds.x = newrect.x;
mBounds.y = newrect.y;
}
nsGUIEvent event(PR_TRUE, NS_MOVE, this);
@ -2513,7 +2543,11 @@ nsWindow::OnMotionNotifyEvent(GtkWidget *aWidget, GdkEventMotion *aEvent)
mLastMotionPressure = pressure;
event.pressure = mLastMotionPressure;
event.refPoint = nsIntPoint(cursorX, cursorY) - WidgetToScreenOffset();
nsRect windowRect;
ScreenToWidget(nsRect(nscoord(cursorX), nscoord(cursorY), 1, 1), windowRect);
event.refPoint.x = windowRect.x;
event.refPoint.y = windowRect.y;
event.isShift = (aEvent->state & GDK_SHIFT_MASK)
? PR_TRUE : PR_FALSE;
@ -2603,8 +2637,11 @@ nsWindow::OnMotionNotifyEvent(GtkWidget *aWidget, GdkEventMotion *aEvent)
event.refPoint.x = nscoord(aEvent->x);
event.refPoint.y = nscoord(aEvent->y);
} else {
nsIntPoint point(NSToIntFloor(aEvent->x_root), NSToIntFloor(aEvent->y_root));
event.refPoint = point - WidgetToScreenOffset();
nsIntRect windowRect;
ScreenToWidget(nsIntRect(NSToIntFloor(aEvent->x_root), NSToIntFloor(aEvent->y_root), 1, 1), windowRect);
event.refPoint.x = windowRect.x;
event.refPoint.y = windowRect.y;
}
event.isShift = (aEvent->state & GDK_SHIFT_MASK)
@ -2631,8 +2668,11 @@ nsWindow::InitButtonEvent(nsMouseEvent &aEvent,
aEvent.refPoint.x = nscoord(aGdkEvent->x);
aEvent.refPoint.y = nscoord(aGdkEvent->y);
} else {
nsIntPoint point(NSToIntFloor(aGdkEvent->x_root), NSToIntFloor(aGdkEvent->y_root));
aEvent.refPoint = point - WidgetToScreenOffset();
nsIntRect windowRect;
ScreenToWidget(nsIntRect(NSToIntFloor(aGdkEvent->x_root), NSToIntFloor(aGdkEvent->y_root), 1, 1), windowRect);
aEvent.refPoint.x = windowRect.x;
aEvent.refPoint.y = windowRect.y;
}
aEvent.isShift = (aGdkEvent->state & GDK_SHIFT_MASK) != 0;
@ -3183,15 +3223,18 @@ nsWindow::OnScrollEvent(GtkWidget *aWidget, GdkEventScroll *aEvent)
}
if (aEvent->window == mDrawingarea->inner_window) {
// we are the window that the event happened on so no need for expensive WidgetToScreenOffset
// we are the window that the event happened on so no need for expensive ScreenToWidget
event.refPoint.x = nscoord(aEvent->x);
event.refPoint.y = nscoord(aEvent->y);
} else {
// XXX we're never quite sure which GdkWindow the event came from due to our custom bubbling
// in scroll_event_cb(), so use ScreenToWidget to translate the screen root coordinates into
// coordinates relative to this widget.
nsIntPoint point(NSToIntFloor(aEvent->x_root), NSToIntFloor(aEvent->y_root));
event.refPoint = point - WidgetToScreenOffset();
nsIntRect windowRect;
ScreenToWidget(nsIntRect(NSToIntFloor(aEvent->x_root), NSToIntFloor(aEvent->y_root), 1, 1), windowRect);
event.refPoint.x = windowRect.x;
event.refPoint.y = windowRect.y;
}
event.isShift = (aEvent->state & GDK_SHIFT_MASK) != 0;

View File

@ -208,7 +208,10 @@ public:
NS_IMETHOD SetWindowClass(const nsAString& xulWinType);
NS_IMETHOD SetMenuBar(void * aMenuBar);
NS_IMETHOD ShowMenuBar(PRBool aShow);
virtual nsIntPoint WidgetToScreenOffset();
NS_IMETHOD WidgetToScreen(const nsIntRect& aOldRect,
nsIntRect& aNewRect);
NS_IMETHOD ScreenToWidget(const nsIntRect& aOldRect,
nsIntRect& aNewRect);
NS_IMETHOD BeginResizingChildren(void);
NS_IMETHOD EndResizingChildren(void);
NS_IMETHOD EnableDragDrop(PRBool aEnable);

View File

@ -367,15 +367,33 @@ NS_METHOD nsWindow::EndResizingChildren(void)
return NS_OK;
}
nsIntPoint nsWindow::WidgetToScreenOffset()
NS_METHOD nsWindow::WidgetToScreen(const nsIntRect &aOldRect, nsIntRect &aNewRect)
{
POINTL point = { 0, 0 };
POINTL point = { aOldRect.x, aOldRect.y };
NS2PM( point);
WinMapWindowPoints( mWnd, HWND_DESKTOP, &point, 1);
return nsIntPoint(point.x,
WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN) - point.y - 1);
aNewRect.x = point.x;
aNewRect.y = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN) - point.y - 1;
aNewRect.width = aOldRect.width;
aNewRect.height = aOldRect.height;
return NS_OK;
}
NS_METHOD nsWindow::ScreenToWidget( const nsIntRect &aOldRect, nsIntRect &aNewRect)
{
POINTL point = { aOldRect.x,
WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN) - aOldRect.y - 1 };
WinMapWindowPoints( HWND_DESKTOP, mWnd, &point, 1);
PM2NS( point);
aNewRect.x = point.x;
aNewRect.y = point.y;
aNewRect.width = aOldRect.width;
aNewRect.height = aOldRect.height;
return NS_OK;
}
//-------------------------------------------------------------------------

View File

@ -162,7 +162,8 @@ class nsWindow : public nsBaseWidget,
NS_IMETHOD BeginResizingChildren();
NS_IMETHOD EndResizingChildren();
virtual nsIntPoint WidgetToScreenOffset();
NS_IMETHOD WidgetToScreen( const nsIntRect &aOldRect, nsIntRect &aNewRect);
NS_IMETHOD ScreenToWidget( const nsIntRect &aOldRect, nsIntRect &aNewRect);
NS_IMETHOD DispatchEvent( struct nsGUIEvent *event, nsEventStatus &aStatus);
NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent);

View File

@ -416,8 +416,13 @@ nsWindow::Move(PRInt32 aX, PRInt32 aY)
QPoint pos(aX, aY);
if (mDrawingArea) {
if (mParent && mDrawingArea->windowType() == Qt::Popup) {
if (mParent->mDrawingArea)
pos = mParent->mDrawingArea->mapToGlobal(pos);
nsIntRect oldrect, newrect;
oldrect.x = aX;
oldrect.y = aY;
mParent->WidgetToScreen(oldrect, newrect);
pos = QPoint(newrect.x, newrect.y);
#ifdef DEBUG_WIDGETS
qDebug("pos is [%d,%d]", pos.x(), pos.y());
#endif
@ -583,7 +588,8 @@ nsWindow::SetFocus(PRBool aRaise)
NS_IMETHODIMP
nsWindow::GetScreenBounds(nsIntRect &aRect)
{
aRect = nsIntRect(WidgetToScreenOffset(), mBounds.Size());
nsIntRect origin(0, 0, mBounds.width, mBounds.height);
WidgetToScreen(origin, aRect);
LOG(("GetScreenBounds %d %d | %d %d | %d %d\n",
aRect.x, aRect.y,
mBounds.width, mBounds.height,
@ -907,17 +913,38 @@ nsWindow::ShowMenuBar(PRBool aShow)
return NS_ERROR_NOT_IMPLEMENTED;
}
nsIntPoint
nsWindow::WidgetToScreenOffset()
NS_IMETHODIMP
nsWindow::WidgetToScreen(const nsIntRect& aOldRect, nsIntRect& aNewRect)
{
NS_ENSURE_TRUE(mDrawingArea, nsIntPoint(0,0));
NS_ENSURE_TRUE(mDrawingArea, NS_OK);
QPoint origin(0, 0);
QPoint origin(aOldRect.x, aOldRect.y);
origin = mDrawingArea->mapToGlobal(origin);
return nsIntPoint(origin.x(), origin.y());
aNewRect.x = origin.x();
aNewRect.y = origin.y();
aNewRect.width = aOldRect.width;
aNewRect.height = aOldRect.height;
return NS_OK;
}
NS_IMETHODIMP
nsWindow::ScreenToWidget(const nsIntRect& aOldRect, nsIntRect& aNewRect)
{
NS_ENSURE_TRUE(mDrawingArea, NS_OK);
QPoint origin(aOldRect.x, aOldRect.y);
origin = mDrawingArea->mapFromGlobal(origin);
aNewRect.x = origin.x();
aNewRect.y = origin.y();
aNewRect.width = aOldRect.width;
aNewRect.height = aOldRect.height;
return NS_OK;
}
NS_IMETHODIMP
nsWindow::BeginResizingChildren(void)
{
@ -1198,7 +1225,10 @@ nsWindow::OnMoveEvent(QMoveEvent *aEvent)
QPoint pos = aEvent->pos();
if (mIsTopLevel) {
// Need to translate this into the right coordinates
mBounds.MoveTo(WidgetToScreenOffset());
nsIntRect oldrect, newrect;
WidgetToScreen(oldrect, newrect);
mBounds.x = newrect.x;
mBounds.y = newrect.y;
}
nsGUIEvent event(PR_TRUE, NS_MOVE, this);
@ -1869,8 +1899,13 @@ nsWindow::NativeResize(PRInt32 aX, PRInt32 aY,
if (mDrawingArea)
{
if (mParent && mDrawingArea->windowType() == Qt::Popup) {
if (mParent->mDrawingArea)
pos = mParent->mDrawingArea->mapToGlobal(pos);
nsIntRect oldrect, newrect;
oldrect.x = aX;
oldrect.y = aY;
mParent->WidgetToScreen(oldrect, newrect);
pos = QPoint(newrect.x, newrect.y);
#ifdef DEBUG_WIDGETS
qDebug("pos is [%d,%d]", pos.x(), pos.y());
#endif
@ -2496,8 +2531,13 @@ nsWindow::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight,
// XXXvlad what?
#if 0
if (mParent && mDrawingArea->windowType() == Qt::Popup) {
if (mParent->mDrawingArea)
pos = mParent->mDrawingArea->mapToGlobal(pos);
nsIntRect oldrect, newrect;
oldrect.x = aX;
oldrect.y = aY;
mParent->WidgetToScreen(oldrect, newrect);
pos = QPoint(newrect.x, newrect.y);
#ifdef DEBUG_WIDGETS
qDebug("pos is [%d,%d]", pos.x(), pos.y());
#endif

View File

@ -196,7 +196,10 @@ public:
NS_IMETHOD SetIcon(const nsAString& aIconSpec);
NS_IMETHOD SetMenuBar(void * aMenuBar) { return NS_ERROR_FAILURE; }
NS_IMETHOD ShowMenuBar(PRBool aShow);
virtual nsIntPoint WidgetToScreenOffset();
NS_IMETHOD WidgetToScreen(const nsIntRect& aOldRect,
nsIntRect& aNewRect);
NS_IMETHOD ScreenToWidget(const nsIntRect& aOldRect,
nsIntRect& aNewRect);
NS_IMETHOD BeginResizingChildren(void);
NS_IMETHOD EndResizingChildren(void);
NS_IMETHOD GetPreferredSize (PRInt32 &aWidth,

View File

@ -899,13 +899,30 @@ NS_METHOD nsWindow::EndResizingChildren(void)
return NS_OK;
}
nsIntPoint nsWindow::WidgetToScreenOffset()
NS_METHOD nsWindow::WidgetToScreen(const nsIntRect& aOldRect, nsIntRect& aNewRect)
{
POINT point;
point.x = 0;
point.y = 0;
point.x = aOldRect.x;
point.y = aOldRect.y;
::ClientToScreen(mWnd, &point);
return nsIntPoint(point.x, point.y);
aNewRect.x = point.x;
aNewRect.y = point.y;
aNewRect.width = aOldRect.width;
aNewRect.height = aOldRect.height;
return NS_OK;
}
NS_METHOD nsWindow::ScreenToWidget(const nsIntRect& aOldRect, nsIntRect& aNewRect)
{
POINT point;
point.x = aOldRect.x;
point.y = aOldRect.y;
::ScreenToClient(mWnd, &point);
aNewRect.x = point.x;
aNewRect.y = point.y;
aNewRect.width = aOldRect.width;
aNewRect.height = aOldRect.height;
return NS_OK;
}
LPARAM nsWindow::lParamToScreen(LPARAM lParam)
@ -6271,7 +6288,11 @@ PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam,
event.isAlt = IS_VK_DOWN(NS_VK_ALT);
event.button = aButton;
nsIntPoint mpScreen = eventPoint + WidgetToScreenOffset();
nsIntRect mpWidget;
nsIntRect mpScreen;
mpWidget.x = eventPoint.x;
mpWidget.y = eventPoint.y;
WidgetToScreen(mpWidget, mpScreen);
// Suppress mouse moves caused by widget creation
if (aEventType == NS_MOUSE_MOVE)
@ -7533,10 +7554,10 @@ nsWindow::ResolveIMECaretPos(nsIWidget* aReferenceWidget,
return;
if (aReferenceWidget)
aOutRect.MoveBy(aReferenceWidget->WidgetToScreenOffset());
aReferenceWidget->WidgetToScreen(aOutRect, aOutRect);
if (aNewOriginWidget)
aOutRect.MoveBy(-aNewOriginWidget->WidgetToScreenOffset());
aNewOriginWidget->ScreenToWidget(aOutRect, aOutRect);
}
//==========================================================================

View File

@ -196,7 +196,8 @@ public:
NS_IMETHOD SetIcon(const nsAString& aIconSpec);
NS_IMETHOD SetMenuBar(void * aMenuBar) { return NS_ERROR_FAILURE; }
NS_IMETHOD ShowMenuBar(PRBool aShow) { return NS_ERROR_FAILURE; }
virtual nsIntPoint WidgetToScreenOffset();
NS_IMETHOD WidgetToScreen(const nsIntRect& aOldRect, nsIntRect& aNewRect);
NS_IMETHOD ScreenToWidget(const nsIntRect& aOldRect, nsIntRect& aNewRect);
NS_IMETHOD BeginResizingChildren(void);
NS_IMETHOD EndResizingChildren(void);
NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight);