mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-24 05:44:10 +00:00
implemented intrinsic sizing method on DOM Window
This commit is contained in:
parent
5dbc2f05f7
commit
e68f60f671
@ -71,6 +71,7 @@
|
||||
#include "nsIDOMHTMLDocument.h"
|
||||
#include "nsLayoutCID.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsIFrameReflow.h"
|
||||
|
||||
#include "nsMultiMixedConv.h" // for
|
||||
#include "nsIRegistry.h"
|
||||
@ -186,6 +187,7 @@ public:
|
||||
NS_IMETHOD Destroy(void);
|
||||
NS_IMETHOD GetBounds(PRInt32 &x, PRInt32 &y, PRInt32 &w, PRInt32 &h);
|
||||
NS_IMETHOD SetBounds(PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h);
|
||||
NS_IMETHOD SizeToContent();
|
||||
NS_IMETHOD MoveTo(PRInt32 aX, PRInt32 aY);
|
||||
NS_IMETHOD Show();
|
||||
NS_IMETHOD Hide();
|
||||
@ -1354,6 +1356,62 @@ nsWebShell::SetBounds(PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWebShell::SizeToContent()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// get the presentation shell
|
||||
nsCOMPtr<nsIContentViewer> cv;
|
||||
GetContentViewer(getter_AddRefs(cv));
|
||||
if (cv) {
|
||||
nsCOMPtr<nsIDocumentViewer> dv = do_QueryInterface(cv);
|
||||
if (dv) {
|
||||
nsCOMPtr<nsIPresContext> pcx;
|
||||
dv->GetPresContext(*getter_AddRefs(pcx));
|
||||
if (pcx) {
|
||||
nsCOMPtr<nsIPresShell> pshell;
|
||||
pcx->GetShell(getter_AddRefs(pshell));
|
||||
|
||||
// whew! so resize the presentation shell
|
||||
if (pshell) {
|
||||
nsRect shellArea;
|
||||
PRInt32 width, height;
|
||||
float pixelScale;
|
||||
|
||||
rv = pshell->ResizeReflow(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
||||
|
||||
// so how big is it?
|
||||
pcx->GetVisibleArea(shellArea);
|
||||
pcx->GetTwipsToPixels(&pixelScale);
|
||||
width = PRInt32((float)shellArea.width*pixelScale);
|
||||
height = PRInt32((float)shellArea.height*pixelScale);
|
||||
|
||||
// if we're the outermost webshell for this window, size the window
|
||||
if (mContainer) {
|
||||
nsCOMPtr<nsIBrowserWindow> browser = do_QueryInterface(mContainer);
|
||||
if (browser) {
|
||||
nsCOMPtr<nsIWebShell> browserWebShell;
|
||||
PRInt32 oldX, oldY, oldWidth, oldHeight,
|
||||
widthDelta, heightDelta;
|
||||
nsRect windowBounds;
|
||||
|
||||
GetBounds(oldX, oldY, oldWidth, oldHeight);
|
||||
widthDelta = width - oldWidth;
|
||||
heightDelta = height - oldHeight;
|
||||
browser->GetWindowBounds(windowBounds);
|
||||
browser->SizeWindowTo(windowBounds.width + widthDelta,
|
||||
windowBounds.height + heightDelta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWebShell::MoveTo(PRInt32 aX, PRInt32 aY)
|
||||
{
|
||||
|
@ -146,6 +146,8 @@ public:
|
||||
|
||||
NS_IMETHOD ResizeBy(PRInt32 aWidthDif, PRInt32 aHeightDif)=0;
|
||||
|
||||
NS_IMETHOD SizeToContent()=0;
|
||||
|
||||
NS_IMETHOD ScrollTo(PRInt32 aXScroll, PRInt32 aYScroll)=0;
|
||||
|
||||
NS_IMETHOD ScrollBy(PRInt32 aXScrollDif, PRInt32 aYScrollDif)=0;
|
||||
@ -225,6 +227,7 @@ public:
|
||||
NS_IMETHOD MoveBy(PRInt32 aXDif, PRInt32 aYDif); \
|
||||
NS_IMETHOD ResizeTo(PRInt32 aWidth, PRInt32 aHeight); \
|
||||
NS_IMETHOD ResizeBy(PRInt32 aWidthDif, PRInt32 aHeightDif); \
|
||||
NS_IMETHOD SizeToContent(); \
|
||||
NS_IMETHOD ScrollTo(PRInt32 aXScroll, PRInt32 aYScroll); \
|
||||
NS_IMETHOD ScrollBy(PRInt32 aXScrollDif, PRInt32 aYScrollDif); \
|
||||
NS_IMETHOD ClearTimeout(PRInt32 aTimerID); \
|
||||
@ -296,6 +299,7 @@ public:
|
||||
NS_IMETHOD MoveBy(PRInt32 aXDif, PRInt32 aYDif) { return _to MoveBy(aXDif, aYDif); } \
|
||||
NS_IMETHOD ResizeTo(PRInt32 aWidth, PRInt32 aHeight) { return _to ResizeTo(aWidth, aHeight); } \
|
||||
NS_IMETHOD ResizeBy(PRInt32 aWidthDif, PRInt32 aHeightDif) { return _to ResizeBy(aWidthDif, aHeightDif); } \
|
||||
NS_IMETHOD SizeToContent() { return _to SizeToContent(); } \
|
||||
NS_IMETHOD ScrollTo(PRInt32 aXScroll, PRInt32 aYScroll) { return _to ScrollTo(aXScroll, aYScroll); } \
|
||||
NS_IMETHOD ScrollBy(PRInt32 aXScrollDif, PRInt32 aYScrollDif) { return _to ScrollBy(aXScrollDif, aYScrollDif); } \
|
||||
NS_IMETHOD ClearTimeout(PRInt32 aTimerID) { return _to ClearTimeout(aTimerID); } \
|
||||
|
@ -48,20 +48,21 @@
|
||||
void moveTo(in long xPos, in long yPos);
|
||||
void moveBy(in long xDif, in long yDif);
|
||||
void resizeTo(in long width, in long height);
|
||||
void resizeBy(in long widthDif, in long heightDif);
|
||||
void resizeBy(in long widthDif, in long heightDif);
|
||||
void sizeToContent();
|
||||
void scrollTo(in long xScroll, in long yScroll);
|
||||
void scrollBy(in long xScrollDif, in long yScrollDif);
|
||||
void scrollBy(in long xScrollDif, in long yScrollDif);
|
||||
|
||||
void clearTimeout(in long timerID);
|
||||
void clearInterval(in long timerID);
|
||||
long setTimeout(/* ... */);
|
||||
long setInterval(/* ... */);
|
||||
|
||||
Window createPopup(in Element element, in Element popupContent,
|
||||
in long xPos, in long yPos,
|
||||
in DOMString popupType, in DOMString anchorAlignment,
|
||||
in DOMString popupAlignment);
|
||||
|
||||
Window createPopup(in Element element, in Element popupContent,
|
||||
in long xPos, in long yPos,
|
||||
in DOMString popupType, in DOMString anchorAlignment,
|
||||
in DOMString popupAlignment);
|
||||
|
||||
Window open(/* ... */);
|
||||
Window openDialog(/* ... */);
|
||||
};
|
||||
|
@ -1476,6 +1476,14 @@ GlobalWindowImpl::ResizeBy(PRInt32 aWidthDif, PRInt32 aHeightDif)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::SizeToContent()
|
||||
{
|
||||
if (mWebShell)
|
||||
return mWebShell->SizeToContent();
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::ScrollTo(PRInt32 aXScroll, PRInt32 aYScroll)
|
||||
{
|
||||
|
@ -153,6 +153,7 @@ public:
|
||||
NS_IMETHOD MoveBy(PRInt32 aXDif, PRInt32 aYDif);
|
||||
NS_IMETHOD ResizeTo(PRInt32 aWidth, PRInt32 aHeight);
|
||||
NS_IMETHOD ResizeBy(PRInt32 aWidthDif, PRInt32 aHeightDif);
|
||||
NS_IMETHOD SizeToContent();
|
||||
NS_IMETHOD ScrollTo(PRInt32 aXScroll, PRInt32 aYScroll);
|
||||
NS_IMETHOD ScrollBy(PRInt32 aXScrollDif, PRInt32 aYScrollDif);
|
||||
|
||||
|
@ -1708,6 +1708,48 @@ WindowResizeBy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method SizeToContent
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
WindowSizeToContent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMWindow *nativeThis = (nsIDOMWindow*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
nsCOMPtr<nsIScriptSecurityManager> secMan;
|
||||
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
{
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "window.sizetocontent",PR_FALSE , &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == nativeThis) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
if (NS_OK != nativeThis->SizeToContent()) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = JSVAL_VOID;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method ScrollTo
|
||||
//
|
||||
@ -2498,6 +2540,7 @@ static JSFunctionSpec WindowMethods[] =
|
||||
{"moveBy", WindowMoveBy, 2},
|
||||
{"resizeTo", WindowResizeTo, 2},
|
||||
{"resizeBy", WindowResizeBy, 2},
|
||||
{"sizeToContent", WindowSizeToContent, 0},
|
||||
{"scrollTo", WindowScrollTo, 2},
|
||||
{"scrollBy", WindowScrollBy, 2},
|
||||
{"clearTimeout", WindowClearTimeout, 1},
|
||||
|
@ -533,7 +533,8 @@ ViewportFrame::Reflow(nsIPresContext& aPresContext,
|
||||
|
||||
// If we were flowed initially at both an unconstrained width and height,
|
||||
// this is a hint that we should return our child's intrinsic size.
|
||||
if (eReflowReason_Initial == aReflowState.reason &&
|
||||
if ((eReflowReason_Initial == aReflowState.reason ||
|
||||
eReflowReason_Resize == aReflowState.reason) &&
|
||||
aReflowState.availableWidth == NS_UNCONSTRAINEDSIZE &&
|
||||
aReflowState.availableHeight == NS_UNCONSTRAINEDSIZE) {
|
||||
aDesiredSize.width = kidRect.width;
|
||||
|
@ -533,7 +533,8 @@ ViewportFrame::Reflow(nsIPresContext& aPresContext,
|
||||
|
||||
// If we were flowed initially at both an unconstrained width and height,
|
||||
// this is a hint that we should return our child's intrinsic size.
|
||||
if (eReflowReason_Initial == aReflowState.reason &&
|
||||
if ((eReflowReason_Initial == aReflowState.reason ||
|
||||
eReflowReason_Resize == aReflowState.reason) &&
|
||||
aReflowState.availableWidth == NS_UNCONSTRAINEDSIZE &&
|
||||
aReflowState.availableHeight == NS_UNCONSTRAINEDSIZE) {
|
||||
aDesiredSize.width = kidRect.width;
|
||||
|
@ -174,6 +174,11 @@ public:
|
||||
*/
|
||||
NS_IMETHOD SetBounds(PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h) = 0;
|
||||
|
||||
/**
|
||||
* Shrink-to-fit the WebShell to its contents
|
||||
*/
|
||||
NS_IMETHOD SizeToContent() = 0;
|
||||
|
||||
NS_IMETHOD MoveTo(PRInt32 aX, PRInt32 aY) = 0;
|
||||
|
||||
/**
|
||||
|
@ -71,6 +71,7 @@
|
||||
#include "nsIDOMHTMLDocument.h"
|
||||
#include "nsLayoutCID.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsIFrameReflow.h"
|
||||
|
||||
#include "nsMultiMixedConv.h" // for
|
||||
#include "nsIRegistry.h"
|
||||
@ -186,6 +187,7 @@ public:
|
||||
NS_IMETHOD Destroy(void);
|
||||
NS_IMETHOD GetBounds(PRInt32 &x, PRInt32 &y, PRInt32 &w, PRInt32 &h);
|
||||
NS_IMETHOD SetBounds(PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h);
|
||||
NS_IMETHOD SizeToContent();
|
||||
NS_IMETHOD MoveTo(PRInt32 aX, PRInt32 aY);
|
||||
NS_IMETHOD Show();
|
||||
NS_IMETHOD Hide();
|
||||
@ -1354,6 +1356,62 @@ nsWebShell::SetBounds(PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWebShell::SizeToContent()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// get the presentation shell
|
||||
nsCOMPtr<nsIContentViewer> cv;
|
||||
GetContentViewer(getter_AddRefs(cv));
|
||||
if (cv) {
|
||||
nsCOMPtr<nsIDocumentViewer> dv = do_QueryInterface(cv);
|
||||
if (dv) {
|
||||
nsCOMPtr<nsIPresContext> pcx;
|
||||
dv->GetPresContext(*getter_AddRefs(pcx));
|
||||
if (pcx) {
|
||||
nsCOMPtr<nsIPresShell> pshell;
|
||||
pcx->GetShell(getter_AddRefs(pshell));
|
||||
|
||||
// whew! so resize the presentation shell
|
||||
if (pshell) {
|
||||
nsRect shellArea;
|
||||
PRInt32 width, height;
|
||||
float pixelScale;
|
||||
|
||||
rv = pshell->ResizeReflow(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
||||
|
||||
// so how big is it?
|
||||
pcx->GetVisibleArea(shellArea);
|
||||
pcx->GetTwipsToPixels(&pixelScale);
|
||||
width = PRInt32((float)shellArea.width*pixelScale);
|
||||
height = PRInt32((float)shellArea.height*pixelScale);
|
||||
|
||||
// if we're the outermost webshell for this window, size the window
|
||||
if (mContainer) {
|
||||
nsCOMPtr<nsIBrowserWindow> browser = do_QueryInterface(mContainer);
|
||||
if (browser) {
|
||||
nsCOMPtr<nsIWebShell> browserWebShell;
|
||||
PRInt32 oldX, oldY, oldWidth, oldHeight,
|
||||
widthDelta, heightDelta;
|
||||
nsRect windowBounds;
|
||||
|
||||
GetBounds(oldX, oldY, oldWidth, oldHeight);
|
||||
widthDelta = width - oldWidth;
|
||||
heightDelta = height - oldHeight;
|
||||
browser->GetWindowBounds(windowBounds);
|
||||
browser->SizeWindowTo(windowBounds.width + widthDelta,
|
||||
windowBounds.height + heightDelta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWebShell::MoveTo(PRInt32 aX, PRInt32 aY)
|
||||
{
|
||||
|
@ -213,6 +213,11 @@
|
||||
<html:button onclick="SetFromParams()">Startup from Params</html:button>
|
||||
</html:td>
|
||||
</html:tr>
|
||||
<html:tr>
|
||||
<html:td>
|
||||
<html:button onclick="sizeToContent()">Size To Content</html:button>
|
||||
</html:td>
|
||||
</html:tr>
|
||||
<html:tr>
|
||||
<html:td>
|
||||
<html:button onclick="DumpWindow()">Dump Window</html:button>
|
||||
|
Loading…
x
Reference in New Issue
Block a user