Bug 668437. Part 4. Add an API to widgets for resizing/moving the client area. r=jimm sr=roc

This commit is contained in:
Timothy Nikkel 2011-12-01 13:56:42 -06:00
parent 1db9b6328a
commit 98438c72bb
6 changed files with 98 additions and 47 deletions

View File

@ -1888,14 +1888,19 @@ DocumentViewerImpl::SetBounds(const nsIntRect& aBounds)
// window frame. // window frame.
// Don't have the widget repaint. Layout will generate repaint requests // Don't have the widget repaint. Layout will generate repaint requests
// during reflow. // during reflow.
if (mAttachedToParent) if (mAttachedToParent) {
mWindow->ResizeClient(aBounds.x, aBounds.y, if (aBounds.x != 0 || aBounds.y != 0) {
aBounds.width, aBounds.height, mWindow->ResizeClient(aBounds.x, aBounds.y,
false); aBounds.width, aBounds.height,
else false);
} else {
mWindow->ResizeClient(aBounds.width, aBounds.height, false);
}
} else {
mWindow->Resize(aBounds.x, aBounds.y, mWindow->Resize(aBounds.x, aBounds.y,
aBounds.width, aBounds.height, aBounds.width, aBounds.height,
false); false);
}
} else if (mPresContext && mViewManager) { } else if (mPresContext && mViewManager) {
PRInt32 p2a = mPresContext->AppUnitsPerDevPixel(); PRInt32 p2a = mPresContext->AppUnitsPerDevPixel();
mViewManager->SetWindowDimensions(NSIntPixelsToAppUnits(mBounds.width, p2a), mViewManager->SetWindowDimensions(NSIntPixelsToAppUnits(mBounds.width, p2a),

View File

@ -118,8 +118,8 @@ typedef nsEventStatus (* EVENT_CALLBACK)(nsGUIEvent *event);
#endif #endif
#define NS_IWIDGET_IID \ #define NS_IWIDGET_IID \
{ 0x34460b01, 0x3dc2, 0x4b58, \ { 0x41fc0f2c, 0x65c2, 0x418e, \
{ 0x8e, 0xd3, 0x7e, 0x7c, 0x33, 0xb5, 0x78, 0x8b } } { 0x89, 0x91, 0x5f, 0x0c, 0xa7, 0x01, 0x05, 0x34 } }
/* /*
* Window shadow styles * Window shadow styles
* Also used for the -moz-window-shadow CSS property * Also used for the -moz-window-shadow CSS property
@ -672,6 +672,21 @@ class nsIWidget : public nsISupports {
**/ **/
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY) = 0; NS_IMETHOD Move(PRInt32 aX, PRInt32 aY) = 0;
/**
* Reposition this widget so that the client area has the given offset.
*
* @param aX the new x offset of the client area expressed as an
* offset from the origin of the client area of the parent
* widget (for root widgets and popup widgets it is in
* screen coordinates)
* @param aY the new y offset of the client area expressed as an
* offset from the origin of the client area of the parent
* widget (for root widgets and popup widgets it is in
* screen coordinates)
*
**/
NS_IMETHOD MoveClient(PRInt32 aX, PRInt32 aY) = 0;
/** /**
* Resize this widget. * Resize this widget.
* *
@ -701,10 +716,29 @@ class nsIWidget : public nsISupports {
bool aRepaint) = 0; bool aRepaint) = 0;
/** /**
* Resize and reposition the inner client area of the widget. * Resize the widget so that the inner client area has the given size.
* *
* @param aX the new x offset expressed in the parent's coordinate system * @param aWidth the new width of the client area.
* @param aY the new y offset expressed in the parent's coordinate system * @param aHeight the new height of the client area.
* @param aRepaint whether the widget should be repainted
*
*/
NS_IMETHOD ResizeClient(PRInt32 aWidth,
PRInt32 aHeight,
bool aRepaint) = 0;
/**
* Resize and reposition the widget so tht inner client area has the given
* offset and size.
*
* @param aX the new x offset of the client area expressed as an
* offset from the origin of the client area of the parent
* widget (for root widgets and popup widgets it is in
* screen coordinates)
* @param aY the new y offset of the client area expressed as an
* offset from the origin of the client area of the parent
* widget (for root widgets and popup widgets it is in
* screen coordinates)
* @param aWidth the new width of the client area. * @param aWidth the new width of the client area.
* @param aHeight the new height of the client area. * @param aHeight the new height of the client area.
* @param aRepaint whether the widget should be repainted * @param aRepaint whether the widget should be repainted

View File

@ -1523,30 +1523,6 @@ NS_METHOD nsWindow::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeig
return NS_OK; return NS_OK;
} }
// Resize the client area and position the widget within it's parent
NS_METHOD nsWindow::ResizeClient(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, bool aRepaint)
{
NS_ASSERTION((aWidth >=0) , "Negative width passed to ResizeClient");
NS_ASSERTION((aHeight >=0), "Negative height passed to ResizeClient");
// Adjust our existing window bounds, based on the new client dims.
RECT client;
GetClientRect(mWnd, &client);
nsIntPoint dims(client.right - client.left, client.bottom - client.top);
aWidth = mBounds.width + (aWidth - dims.x);
aHeight = mBounds.height + (aHeight - dims.y);
if (aX || aY) {
// offsets
nsIntRect bounds;
GetScreenBounds(bounds);
aX += bounds.x;
aY += bounds.y;
return Resize(aX, aY, aWidth, aHeight, aRepaint);
}
return Resize(aWidth, aHeight, aRepaint);
}
NS_IMETHODIMP NS_IMETHODIMP
nsWindow::BeginResizeDrag(nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical) nsWindow::BeginResizeDrag(nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical)
{ {

View File

@ -125,7 +125,6 @@ public:
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
NS_IMETHOD Resize(PRInt32 aWidth, PRInt32 aHeight, bool aRepaint); NS_IMETHOD Resize(PRInt32 aWidth, PRInt32 aHeight, bool aRepaint);
NS_IMETHOD Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, bool aRepaint); NS_IMETHOD Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, bool aRepaint);
NS_IMETHOD ResizeClient(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, bool aRepaint);
NS_IMETHOD BeginResizeDrag(nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical); NS_IMETHOD BeginResizeDrag(nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical);
NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, nsIWidget *aWidget, bool aActivate); NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, nsIWidget *aWidget, bool aActivate);
NS_IMETHOD SetSizeMode(PRInt32 aMode); NS_IMETHOD SetSizeMode(PRInt32 aMode);

View File

@ -300,15 +300,6 @@ NS_IMETHODIMP nsBaseWidget::SetAttachedViewPtr(ViewWrapper* aViewWrapper)
return NS_OK; return NS_OK;
} }
NS_METHOD nsBaseWidget::ResizeClient(PRInt32 aX,
PRInt32 aY,
PRInt32 aWidth,
PRInt32 aHeight,
bool aRepaint)
{
return Resize(aX, aY, aWidth, aHeight, aRepaint);
}
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// //
// Close this nsBaseWidget // Close this nsBaseWidget
@ -919,6 +910,50 @@ NS_METHOD nsBaseWidget::SetWindowClass(const nsAString& xulWinType)
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
NS_METHOD nsBaseWidget::MoveClient(PRInt32 aX, PRInt32 aY)
{
nsIntPoint clientOffset(GetClientOffset());
aX -= clientOffset.x;
aY -= clientOffset.y;
return Move(aX, aY);
}
NS_METHOD nsBaseWidget::ResizeClient(PRInt32 aWidth,
PRInt32 aHeight,
bool aRepaint)
{
NS_ASSERTION((aWidth >=0) , "Negative width passed to ResizeClient");
NS_ASSERTION((aHeight >=0), "Negative height passed to ResizeClient");
nsIntRect clientBounds;
GetClientBounds(clientBounds);
aWidth = mBounds.width + (aWidth - clientBounds.width);
aHeight = mBounds.height + (aHeight - clientBounds.height);
return Resize(aWidth, aHeight, aRepaint);
}
NS_METHOD nsBaseWidget::ResizeClient(PRInt32 aX,
PRInt32 aY,
PRInt32 aWidth,
PRInt32 aHeight,
bool aRepaint)
{
NS_ASSERTION((aWidth >=0) , "Negative width passed to ResizeClient");
NS_ASSERTION((aHeight >=0), "Negative height passed to ResizeClient");
nsIntRect clientBounds;
GetClientBounds(clientBounds);
aWidth = mBounds.width + (aWidth - clientBounds.width);
aHeight = mBounds.height + (aHeight - clientBounds.height);
nsIntPoint clientOffset(GetClientOffset());
aX -= clientOffset.x;
aY -= clientOffset.y;
return Resize(aX, aY, aWidth, aHeight, aRepaint);
}
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// //
// Bounds // Bounds

View File

@ -122,10 +122,15 @@ public:
virtual gfxASurface* GetThebesSurface(); virtual gfxASurface* GetThebesSurface();
NS_IMETHOD SetModal(bool aModal); NS_IMETHOD SetModal(bool aModal);
NS_IMETHOD SetWindowClass(const nsAString& xulWinType); NS_IMETHOD SetWindowClass(const nsAString& xulWinType);
NS_IMETHOD MoveClient(PRInt32 aX, PRInt32 aY);
NS_IMETHOD ResizeClient(PRInt32 aWidth, PRInt32 aHeight, bool aRepaint);
NS_IMETHOD ResizeClient(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, bool aRepaint);
NS_IMETHOD SetBounds(const nsIntRect &aRect); NS_IMETHOD SetBounds(const nsIntRect &aRect);
NS_IMETHOD GetBounds(nsIntRect &aRect); NS_IMETHOD GetBounds(nsIntRect &aRect);
NS_IMETHOD GetClientBounds(nsIntRect &aRect); NS_IMETHOD GetClientBounds(nsIntRect &aRect);
NS_IMETHOD GetScreenBounds(nsIntRect &aRect); NS_IMETHOD GetScreenBounds(nsIntRect &aRect);
NS_IMETHOD GetNonClientMargins(nsIntMargin &margins);
NS_IMETHOD SetNonClientMargins(nsIntMargin &margins);
virtual nsIntPoint GetClientOffset(); virtual nsIntPoint GetClientOffset();
NS_IMETHOD EnableDragDrop(bool aEnable); NS_IMETHOD EnableDragDrop(bool aEnable);
NS_IMETHOD GetAttention(PRInt32 aCycleCount); NS_IMETHOD GetAttention(PRInt32 aCycleCount);
@ -163,9 +168,6 @@ public:
NS_IMETHOD AttachViewToTopLevel(EVENT_CALLBACK aViewEventFunction, nsDeviceContext *aContext); NS_IMETHOD AttachViewToTopLevel(EVENT_CALLBACK aViewEventFunction, nsDeviceContext *aContext);
virtual ViewWrapper* GetAttachedViewPtr(); virtual ViewWrapper* GetAttachedViewPtr();
NS_IMETHOD SetAttachedViewPtr(ViewWrapper* aViewWrapper); NS_IMETHOD SetAttachedViewPtr(ViewWrapper* aViewWrapper);
NS_IMETHOD ResizeClient(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, bool aRepaint);
NS_IMETHOD GetNonClientMargins(nsIntMargin &margins);
NS_IMETHOD SetNonClientMargins(nsIntMargin &margins);
NS_IMETHOD RegisterTouchWindow(); NS_IMETHOD RegisterTouchWindow();
NS_IMETHOD UnregisterTouchWindow(); NS_IMETHOD UnregisterTouchWindow();