зеркало из https://github.com/mozilla/pjs.git
Bug 413277: Restrict window resizing to the size of the current screen on Mac OS X. r=josh a=josh
This commit is contained in:
Родитель
99ecef1ae4
Коммит
3e1dd41aa2
|
@ -206,25 +206,26 @@ nsCocoaWindow::~nsCocoaWindow()
|
||||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Very large windows work in Cocoa, but can take a long time to
|
static void FitRectToVisibleAreaForScreen(nsIntRect &aRect, NSScreen *screen)
|
||||||
// process (multiple minutes), during which time the system is
|
|
||||||
// unresponsive and seems hung. Although it's likely that windows
|
|
||||||
// much larger than screen size are bugs, be conservative and only
|
|
||||||
// intervene if the values are so large as to hog the cpu.
|
|
||||||
#define SIZE_LIMIT 100000
|
|
||||||
static bool WindowSizeAllowed(PRInt32 aWidth, PRInt32 aHeight)
|
|
||||||
{
|
{
|
||||||
if (aWidth > SIZE_LIMIT) {
|
if (!screen)
|
||||||
NS_ERROR(nsPrintfCString(256, "Requested Cocoa window width of %d is too much, max allowed is %d",
|
return;
|
||||||
aWidth, SIZE_LIMIT).get());
|
|
||||||
return false;
|
nsIntRect screenBounds(nsCocoaUtils::CocoaRectToGeckoRect([screen visibleFrame]));
|
||||||
|
|
||||||
|
if (aRect.width > screenBounds.width) {
|
||||||
|
aRect.width = screenBounds.width;
|
||||||
}
|
}
|
||||||
if (aHeight > SIZE_LIMIT) {
|
if (aRect.height > screenBounds.height) {
|
||||||
NS_ERROR(nsPrintfCString(256, "Requested Cocoa window height of %d is too much, max allowed is %d",
|
aRect.height = screenBounds.height;
|
||||||
aHeight, SIZE_LIMIT).get());
|
}
|
||||||
return false;
|
|
||||||
|
if (aRect.x - screenBounds.x + aRect.width > screenBounds.width) {
|
||||||
|
aRect.x += screenBounds.width - (aRect.x - screenBounds.x + aRect.width);
|
||||||
|
}
|
||||||
|
if (aRect.y - screenBounds.y + aRect.height > screenBounds.height) {
|
||||||
|
aRect.y += screenBounds.height - (aRect.y - screenBounds.y + aRect.height);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some applications like Camino use native popup windows
|
// Some applications like Camino use native popup windows
|
||||||
|
@ -255,14 +256,14 @@ nsresult nsCocoaWindow::Create(nsIWidget *aParent,
|
||||||
// we have to provide an autorelease pool (see bug 559075).
|
// we have to provide an autorelease pool (see bug 559075).
|
||||||
nsAutoreleasePool localPool;
|
nsAutoreleasePool localPool;
|
||||||
|
|
||||||
if (!WindowSizeAllowed(aRect.width, aRect.height))
|
nsIntRect newBounds = aRect;
|
||||||
return NS_ERROR_FAILURE;
|
FitRectToVisibleAreaForScreen(newBounds, [NSScreen mainScreen]);
|
||||||
|
|
||||||
// Set defaults which can be overriden from aInitData in BaseCreate
|
// Set defaults which can be overriden from aInitData in BaseCreate
|
||||||
mWindowType = eWindowType_toplevel;
|
mWindowType = eWindowType_toplevel;
|
||||||
mBorderStyle = eBorderStyle_default;
|
mBorderStyle = eBorderStyle_default;
|
||||||
|
|
||||||
Inherited::BaseCreate(aParent, aRect, aHandleEventFunction, aContext, aAppShell,
|
Inherited::BaseCreate(aParent, newBounds, aHandleEventFunction, aContext, aAppShell,
|
||||||
aToolkit, aInitData);
|
aToolkit, aInitData);
|
||||||
|
|
||||||
mParent = aParent;
|
mParent = aParent;
|
||||||
|
@ -271,12 +272,12 @@ nsresult nsCocoaWindow::Create(nsIWidget *aParent,
|
||||||
if ((mWindowType == eWindowType_popup) && UseNativePopupWindows())
|
if ((mWindowType == eWindowType_popup) && UseNativePopupWindows())
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
||||||
nsresult rv = CreateNativeWindow(nsCocoaUtils::GeckoRectToCocoaRect(aRect),
|
nsresult rv = CreateNativeWindow(nsCocoaUtils::GeckoRectToCocoaRect(newBounds),
|
||||||
mBorderStyle, PR_FALSE);
|
mBorderStyle, PR_FALSE);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
if (mWindowType == eWindowType_popup)
|
if (mWindowType == eWindowType_popup)
|
||||||
return CreatePopupContentView(aRect, aHandleEventFunction, aContext, aAppShell, aToolkit);
|
return CreatePopupContentView(newBounds, aHandleEventFunction, aContext, aAppShell, aToolkit);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
||||||
|
@ -1126,17 +1127,17 @@ NS_IMETHODIMP nsCocoaWindow::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRIn
|
||||||
{
|
{
|
||||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||||
|
|
||||||
if (!WindowSizeAllowed(aWidth, aHeight))
|
nsIntRect newBounds = nsIntRect(aX, aY, aWidth, aHeight);
|
||||||
return NS_ERROR_FAILURE;
|
FitRectToVisibleAreaForScreen(newBounds, [mWindow screen]);
|
||||||
|
|
||||||
nsIntRect windowBounds(nsCocoaUtils::CocoaRectToGeckoRect([mWindow frame]));
|
nsIntRect windowBounds(nsCocoaUtils::CocoaRectToGeckoRect([mWindow frame]));
|
||||||
BOOL isMoving = (windowBounds.x != aX || windowBounds.y != aY);
|
BOOL isMoving = (windowBounds.x != newBounds.x || windowBounds.y != newBounds.y);
|
||||||
BOOL isResizing = (windowBounds.width != aWidth || windowBounds.height != aHeight);
|
BOOL isResizing = (windowBounds.width != newBounds.width || windowBounds.height != newBounds.height);
|
||||||
|
|
||||||
if (IsResizing() || !mWindow || (!isMoving && !isResizing))
|
if (IsResizing() || !mWindow || (!isMoving && !isResizing))
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
||||||
mBounds = nsIntRect(aX, aY, aWidth, aHeight);
|
mBounds = newBounds;
|
||||||
NSRect newFrame = nsCocoaUtils::GeckoRectToCocoaRect(mBounds);
|
NSRect newFrame = nsCocoaUtils::GeckoRectToCocoaRect(mBounds);
|
||||||
|
|
||||||
// We have to report the size event -first-, to make sure that content
|
// We have to report the size event -first-, to make sure that content
|
||||||
|
@ -1172,9 +1173,6 @@ NS_IMETHODIMP nsCocoaWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRep
|
||||||
{
|
{
|
||||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||||
|
|
||||||
if (!WindowSizeAllowed(aWidth, aHeight))
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
nsIntRect windowBounds(nsCocoaUtils::CocoaRectToGeckoRect([mWindow frame]));
|
nsIntRect windowBounds(nsCocoaUtils::CocoaRectToGeckoRect([mWindow frame]));
|
||||||
return Resize(windowBounds.x, windowBounds.y, aWidth, aHeight, aRepaint);
|
return Resize(windowBounds.x, windowBounds.y, aWidth, aHeight, aRepaint);
|
||||||
|
|
||||||
|
|
|
@ -82,11 +82,14 @@ _CHROME_FILES = test_bug343416.xul \
|
||||||
test_input_events_on_deactive_window.xul \
|
test_input_events_on_deactive_window.xul \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
# test_bug413277.html mac-only based on 604789, 605178
|
||||||
|
|
||||||
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
||||||
_CHROME_FILES += native_menus_window.xul \
|
_CHROME_FILES += native_menus_window.xul \
|
||||||
test_native_menus.xul \
|
test_native_menus.xul \
|
||||||
native_mouse_mac_window.xul \
|
native_mouse_mac_window.xul \
|
||||||
test_native_mouse_mac.xul \
|
test_native_mouse_mac.xul \
|
||||||
|
test_bug413277.html \
|
||||||
test_bug428405.xul \
|
test_bug428405.xul \
|
||||||
test_bug466599.xul \
|
test_bug466599.xul \
|
||||||
test_bug485118.xul \
|
test_bug485118.xul \
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<!--
|
||||||
|
https://bugzilla.mozilla.org/show_bug.cgi?id=413277
|
||||||
|
-->
|
||||||
|
<head>
|
||||||
|
<title>Test for Bug 413277</title>
|
||||||
|
<script type="text/javascript"
|
||||||
|
src="chrome://mochikit/content/MochiKit/packed.js"></script>
|
||||||
|
<script type="text/javascript"
|
||||||
|
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css"
|
||||||
|
href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=413277">Mozilla Bug 413277</a>
|
||||||
|
<p id="display"></p>
|
||||||
|
<div id="content" style="display: none">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<pre id="test">
|
||||||
|
<script class="testbody" type="application/javascript">
|
||||||
|
var atts='width=100, height=100, top=100, screenY=100';
|
||||||
|
atts += ', left=100, screenX=100, toolbar=no';
|
||||||
|
atts += ', location=no, directories=no, status=no';
|
||||||
|
atts += ', menubar=no, scrollbars=no, resizable=no';
|
||||||
|
var newWindow = window.open('_blank', 'win_name', atts);
|
||||||
|
|
||||||
|
newWindow.resizeBy(1000000, 1000000);
|
||||||
|
SimpleTest.is(newWindow.outerWidth, newWindow.screen.availWidth, true);
|
||||||
|
SimpleTest.is(newWindow.outerHeight, newWindow.screen.availHeight, true);
|
||||||
|
SimpleTest.is(newWindow.screenY, newWindow.screen.availTop, true);
|
||||||
|
SimpleTest.is(newWindow.screenX, newWindow.screen.availLeft, true);
|
||||||
|
|
||||||
|
newWindow.close();
|
||||||
|
</script>
|
||||||
|
</pre>
|
||||||
|
</body>
|
Загрузка…
Ссылка в новой задаче