PDA

View Full Version : [OPEN-1458] Ext.Window.setSize does not respect constrain option



timbonicus
6 Dec 2010, 3:18 PM
Ext version tested:


Ext 3.3 rev 1


Adapter used:


ext


css used:


only default ext-all.css


Browser versions tested against:


IE8


Operating System:


Windows Vista


Description:


The Ext.Window constrain config option states that it constrains the window within its containing element, yet the Window can be programmatically positioned or resized to break this claim. The setSize and setPosition functions may need to be altered for Window to support this feature.


Test Case:



var viewport = undefined;
var win = undefined;
Ext.onReady(function() {
viewport = new Ext.Viewport({
items:[{
autoScroll:true,
items:[{
handler:launchWin,
text:'Launch window',
x:'50%',
y:'50%',
xtype:'button'
},{
region:'center',
xtype:'panel'
}],
layout:'absolute',
xtype:'panel'
}],
layout:'fit'
});
});

function launchWin() {
win = new Ext.Window({
constrain:true,
height:200,
items:[{
autoScroll:true,
items:[{
handler:addHeight,
text:'Expand window',
region:'north',
xtype:'button'
},{
region:'center',
xtype:'panel'
},{
handler:moveWindow,
text:'Reposition window',
region:'south',
xtype:'button'
}],
layout:'border',
xtype:'panel'
}],
layout:'fit',
renderTo:viewport.el,
title:'FormLayout Test',
width:300
});
win.show();
}

function addHeight() {
win.setHeight(win.getHeight()+100);
}

function moveWindow() {
win.setPosition(win.getPosition()[0], win.getPosition()[1]+100);
}
Steps to reproduce the problem:


Fire up sample code
Click 'Launch window'
Click 'Expand window' several times until the bottom of the window expands past the bottom of the viewport.
Click 'Reposition window' several times until the bottom of the window is positioned past the bottom of the viewport.


The result that was expected:


The window size would be constrained to the size of the viewport.
The window position would be constrained within the viewport.


The result that occurs instead:


The window can be resized beyond the extent of the viewport.
The window can be repositioned outside the bounds of the viewport.


Possible fix:


A inelegant hack to correct the issue:


Ext.override(Ext.Window, {
setSize : function(w, h) {
if (this.constrain) {
var cmp = this.renderTo || Ext.getBody();
var bw = cmp.getWidth();
var bh = cmp.getHeight();
// Disallow resize beyond the constrained area.
if (h > bh) {
h = bh;
}
if (w > bw) {
w = bw;
}
// Adjust position to keep the Window int he container
var newX = this.x;
if (w + this.x > bw) {
newX = bw - w;
}
var newY = this.y;
if (h + this.y > bh) {
newY = bh - h;
}
if (newX != this.x || newY != this.y) {
this.setPosition(newX, newY);
}
}
Ext.Window.superclass.setSize.call(this, w, h);
}
});