Bug 510335, add support for right/bottom attributes in stack, remove left/top css property support, r=neil,sr=bz

This commit is contained in:
Neil Deakin 2009-09-13 17:13:54 -04:00
parent 916dc97c10
commit 05a4dea73e
10 changed files with 350 additions and 60 deletions

View File

@ -1814,7 +1814,8 @@ nsXULElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
} else {
// if left or top changes we reflow. This will happen in xul
// containers that manage positioned children such as a stack.
if (nsGkAtoms::left == aAttribute || nsGkAtoms::top == aAttribute)
if (nsGkAtoms::left == aAttribute || nsGkAtoms::top == aAttribute ||
nsGkAtoms::right == aAttribute || nsGkAtoms::bottom == aAttribute)
retval = NS_STYLE_HINT_REFLOW;
}

View File

@ -47,6 +47,7 @@
#include "nsBox.h"
#include "nsIScrollableFrame.h"
#include "nsSprocketLayout.h"
#include "nsGridLayout2.h"
#include "nsGridRow.h"
#include "nsGridCell.h"
@ -917,7 +918,7 @@ nsGrid::GetPrefRowHeight(nsBoxLayoutState& aState, PRInt32 aIndex, PRBool aIsHor
{
size = box->GetPrefSize(aState);
nsBox::AddMargin(box, size);
nsStackLayout::AddOffset(aState, box, size);
nsGridLayout2::AddOffset(aState, box, size);
}
row->mPref = GET_HEIGHT(size, aIsHorizontal);
@ -991,7 +992,7 @@ nsGrid::GetMinRowHeight(nsBoxLayoutState& aState, PRInt32 aIndex, PRBool aIsHori
if (box) {
size = box->GetPrefSize(aState);
nsBox::AddMargin(box, size);
nsStackLayout::AddOffset(aState, box, size);
nsGridLayout2::AddOffset(aState, box, size);
}
row->mMin = GET_HEIGHT(size, aIsHorizontal) + top + bottom;
@ -1067,7 +1068,7 @@ nsGrid::GetMaxRowHeight(nsBoxLayoutState& aState, PRInt32 aIndex, PRBool aIsHori
if (box) {
size = box->GetPrefSize(aState);
nsBox::AddMargin(box, size);
nsStackLayout::AddOffset(aState, box, size);
nsGridLayout2::AddOffset(aState, box, size);
}
row->mMax = GET_HEIGHT(size, aIsHorizontal);

View File

@ -45,7 +45,7 @@
#include "nsGridCell.h"
#include "nsFrame.h"
#include "nsBox.h"
#include "nsStackLayout.h"
#include "nsGridLayout2.h"
nsGridCell::nsGridCell():mBoxInColumn(nsnull),mBoxInRow(nsnull)
@ -71,7 +71,7 @@ nsGridCell::GetPrefSize(nsBoxLayoutState& aState)
nsSize pref = mBoxInColumn->GetPrefSize(aState);
nsBox::AddMargin(mBoxInColumn, pref);
nsStackLayout::AddOffset(aState, mBoxInColumn, pref);
nsGridLayout2::AddOffset(aState, mBoxInColumn, pref);
nsBoxLayout::AddLargestSize(sum, pref);
}
@ -80,7 +80,7 @@ nsGridCell::GetPrefSize(nsBoxLayoutState& aState)
nsSize pref = mBoxInRow->GetPrefSize(aState);
nsBox::AddMargin(mBoxInRow, pref);
nsStackLayout::AddOffset(aState, mBoxInRow, pref);
nsGridLayout2::AddOffset(aState, mBoxInRow, pref);
nsBoxLayout::AddLargestSize(sum, pref);
}
@ -101,7 +101,7 @@ nsGridCell::GetMinSize(nsBoxLayoutState& aState)
nsSize min = mBoxInColumn->GetMinSize(aState);
nsBox::AddMargin(mBoxInColumn, min);
nsStackLayout::AddOffset(aState, mBoxInColumn, min);
nsGridLayout2::AddOffset(aState, mBoxInColumn, min);
nsBoxLayout::AddLargestSize(sum, min);
}
@ -110,7 +110,7 @@ nsGridCell::GetMinSize(nsBoxLayoutState& aState)
nsSize min = mBoxInRow->GetMinSize(aState);
nsBox::AddMargin(mBoxInRow, min);
nsStackLayout::AddOffset(aState, mBoxInRow, min);
nsGridLayout2::AddOffset(aState, mBoxInRow, min);
nsBoxLayout::AddLargestSize(sum, min);
}
@ -131,7 +131,7 @@ nsGridCell::GetMaxSize(nsBoxLayoutState& aState)
nsSize max = mBoxInColumn->GetMaxSize(aState);
nsBox::AddMargin(mBoxInColumn, max);
nsStackLayout::AddOffset(aState, mBoxInColumn, max);
nsGridLayout2::AddOffset(aState, mBoxInColumn, max);
nsBoxLayout::AddSmallestSize(sum, max);
}
@ -140,7 +140,7 @@ nsGridCell::GetMaxSize(nsBoxLayoutState& aState)
nsSize max = mBoxInRow->GetMaxSize(aState);
nsBox::AddMargin(mBoxInRow, max);
nsStackLayout::AddOffset(aState, mBoxInRow, max);
nsGridLayout2::AddOffset(aState, mBoxInRow, max);
nsBoxLayout::AddSmallestSize(sum, max);
}

View File

@ -63,6 +63,16 @@ nsGridLayout2::nsGridLayout2(nsIPresShell* aPresShell):nsStackLayout()
{
}
// static
void
nsGridLayout2::AddOffset(nsBoxLayoutState& aState, nsIBox* aChild, nsSize& aSize)
{
nsMargin offset;
GetOffset(aState, aChild, offset);
aSize.width += offset.left;
aSize.height += offset.top;
}
NS_IMETHODIMP
nsGridLayout2::Layout(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState)
{

View File

@ -88,6 +88,9 @@ public:
nsIBox* aChildList);
virtual void ChildrenSet(nsIBox* aBox, nsBoxLayoutState& aState,
nsIBox* aChildList);
static void AddOffset(nsBoxLayoutState& aState, nsIBox* aChild, nsSize& aSize);
protected:
nsGridLayout2(nsIPresShell* aShell);

View File

@ -1122,6 +1122,8 @@ nsBoxFrame::AttributeChanged(PRInt32 aNameSpaceID,
aAttribute == nsGkAtoms::valign ||
aAttribute == nsGkAtoms::left ||
aAttribute == nsGkAtoms::top ||
aAttribute == nsGkAtoms::right ||
aAttribute == nsGkAtoms::bottom ||
aAttribute == nsGkAtoms::minwidth ||
aAttribute == nsGkAtoms::maxwidth ||
aAttribute == nsGkAtoms::minheight ||
@ -1192,7 +1194,9 @@ nsBoxFrame::AttributeChanged(PRInt32 aNameSpaceID,
mState &= ~NS_STATE_AUTO_STRETCH;
}
else if (aAttribute == nsGkAtoms::left ||
aAttribute == nsGkAtoms::top) {
aAttribute == nsGkAtoms::top ||
aAttribute == nsGkAtoms::right ||
aAttribute == nsGkAtoms::bottom) {
mState &= ~NS_STATE_STACK_NOT_POSITIONED;
}
else if (aAttribute == nsGkAtoms::mousethrough) {

View File

@ -54,6 +54,11 @@
nsIBoxLayout* nsStackLayout::gInstance = nsnull;
#define SPECIFIED_LEFT (1 << NS_SIDE_LEFT)
#define SPECIFIED_RIGHT (1 << NS_SIDE_RIGHT)
#define SPECIFIED_TOP (1 << NS_SIDE_TOP)
#define SPECIFIED_BOTTOM (1 << NS_SIDE_BOTTOM)
nsresult
NS_NewStackLayout( nsIPresShell* aPresShell, nsCOMPtr<nsIBoxLayout>& aNewLayout)
{
@ -95,7 +100,10 @@ nsStackLayout::GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aState)
nsSize pref = child->GetPrefSize(aState);
AddMargin(child, pref);
AddOffset(aState, child, pref);
nsMargin offset;
GetOffset(aState, child, offset);
pref.width += offset.LeftRight();
pref.height += offset.TopBottom();
AddLargestSize(prefSize, pref);
}
@ -118,7 +126,10 @@ nsStackLayout::GetMinSize(nsIBox* aBox, nsBoxLayoutState& aState)
nsSize min = child->GetMinSize(aState);
AddMargin(child, min);
AddOffset(aState, child, min);
nsMargin offset;
GetOffset(aState, child, offset);
min.width += offset.LeftRight();
min.height += offset.TopBottom();
AddLargestSize(minSize, min);
}
@ -144,7 +155,10 @@ nsStackLayout::GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aState)
max = nsBox::BoundsCheckMinMax(min, max);
AddMargin(child, max);
AddOffset(aState, child, max);
nsMargin offset;
GetOffset(aState, child, offset);
max.width += offset.LeftRight();
max.height += offset.TopBottom();
AddSmallestSize(maxSize, max);
}
@ -177,33 +191,21 @@ nsStackLayout::GetAscent(nsIBox* aBox, nsBoxLayoutState& aState)
return vAscent;
}
PRBool
nsStackLayout::AddOffset(nsBoxLayoutState& aState, nsIBox* aChild, nsSize& aSize)
PRUint8
nsStackLayout::GetOffset(nsBoxLayoutState& aState, nsIBox* aChild, nsMargin& aOffset)
{
nsSize offset(0,0);
// get the left and top offsets
aOffset = nsMargin(0, 0, 0, 0);
// get the left, right, top and bottom offsets
// As an optimization, we cache the fact that we are not positioned to avoid
// wasting time fetching attributes and checking style data.
// wasting time fetching attributes.
if (aChild->IsBoxFrame() &&
(aChild->GetStateBits() & NS_STATE_STACK_NOT_POSITIONED))
return PR_FALSE;
PRBool offsetSpecified = PR_FALSE;
const nsStylePosition* pos = aChild->GetStylePosition();
if (eStyleUnit_Coord == pos->mOffset.GetLeftUnit()) {
offset.width = pos->mOffset.GetLeft().GetCoordValue();
offsetSpecified = PR_TRUE;
}
if (eStyleUnit_Coord == pos->mOffset.GetTopUnit()) {
offset.height = pos->mOffset.GetTop().GetCoordValue();
offsetSpecified = PR_TRUE;
}
return 0;
PRUint8 offsetSpecified = 0;
nsIContent* content = aChild->GetContent();
if (content) {
nsAutoString value;
PRInt32 error;
@ -211,28 +213,42 @@ nsStackLayout::AddOffset(nsBoxLayoutState& aState, nsIBox* aChild, nsSize& aSize
content->GetAttr(kNameSpaceID_None, nsGkAtoms::left, value);
if (!value.IsEmpty()) {
value.Trim("%");
offset.width =
aOffset.left =
nsPresContext::CSSPixelsToAppUnits(value.ToInteger(&error));
offsetSpecified = PR_TRUE;
offsetSpecified |= SPECIFIED_LEFT;
}
content->GetAttr(kNameSpaceID_None, nsGkAtoms::right, value);
if (!value.IsEmpty()) {
value.Trim("%");
aOffset.right =
nsPresContext::CSSPixelsToAppUnits(value.ToInteger(&error));
offsetSpecified |= SPECIFIED_RIGHT;
}
content->GetAttr(kNameSpaceID_None, nsGkAtoms::top, value);
if (!value.IsEmpty()) {
value.Trim("%");
offset.height =
aOffset.top =
nsPresContext::CSSPixelsToAppUnits(value.ToInteger(&error));
offsetSpecified = PR_TRUE;
offsetSpecified |= SPECIFIED_TOP;
}
content->GetAttr(kNameSpaceID_None, nsGkAtoms::bottom, value);
if (!value.IsEmpty()) {
value.Trim("%");
aOffset.bottom =
nsPresContext::CSSPixelsToAppUnits(value.ToInteger(&error));
offsetSpecified |= SPECIFIED_BOTTOM;
}
}
aSize += offset;
if (!offsetSpecified && aChild->IsBoxFrame()) {
// If no offset was specified at all, then we cache this fact to avoid requerying
// CSS or the content model.
aChild->AddStateBits(NS_STATE_STACK_NOT_POSITIONED);
}
return offsetSpecified;
}
@ -272,20 +288,51 @@ nsStackLayout::Layout(nsIBox* aBox, nsBoxLayoutState& aState)
child->GetMargin(margin);
// obtain our offset from the top left border of the stack's content box.
nsSize offset(0,0);
PRBool offsetSpecified = AddOffset(aState, child, offset);
nsMargin offset;
PRUint8 offsetSpecified = GetOffset(aState, child, offset);
// Correct the child's x/y position by adding in both the margins
// and the left/top offset.
childRect.x = clientRect.x + offset.width + margin.left;
childRect.y = clientRect.y + offset.height + margin.top;
// If we have an offset, we don't stretch the child. Just use
// its preferred size.
// Set the position and size based on which offsets have been specified:
// left only - offset from left edge, preferred width
// right only - offset from right edge, preferred width
// left and right - offset from left and right edges, width in between this
// neither - no offset, full width of stack
// Vertical direction is similar.
//
// Margins on the child are also included in the edge offsets
if (offsetSpecified) {
nsSize pref = child->GetPrefSize(aState);
childRect.width = pref.width;
childRect.height = pref.height;
if (offsetSpecified & SPECIFIED_LEFT) {
childRect.x = clientRect.x + offset.left + margin.left;
if (offsetSpecified & SPECIFIED_RIGHT) {
nsSize min = child->GetMinSize(aState);
nsSize max = child->GetMaxSize(aState);
nscoord width = clientRect.width - offset.LeftRight() - margin.LeftRight();
childRect.width = PR_MAX(min.width, PR_MIN(max.width, width));
}
else {
childRect.width = child->GetPrefSize(aState).width;
}
}
else if (offsetSpecified & SPECIFIED_RIGHT) {
childRect.width = child->GetPrefSize(aState).width;
childRect.x = clientRect.XMost() - offset.right - margin.right - childRect.width;
}
if (offsetSpecified & SPECIFIED_TOP) {
childRect.y = clientRect.y + offset.top + margin.top;
if (offsetSpecified & SPECIFIED_BOTTOM) {
nsSize min = child->GetMinSize(aState);
nsSize max = child->GetMaxSize(aState);
nscoord height = clientRect.height - offset.TopBottom() - margin.TopBottom();
childRect.height = PR_MAX(min.height, PR_MIN(max.height, height));
}
else {
childRect.height = child->GetPrefSize(aState).height;
}
}
else if (offsetSpecified & SPECIFIED_BOTTOM) {
childRect.height = child->GetPrefSize(aState).height;
childRect.y = clientRect.YMost() - offset.bottom - margin.bottom - childRect.height;
}
}
// Now place the child.
@ -301,13 +348,13 @@ nsStackLayout::Layout(nsIBox* aBox, nsBoxLayoutState& aState)
if (child->GetStyleXUL()->mStretchStack) {
// Did the child push back on us and get bigger?
if (offset.width + childRect.width > clientRect.width) {
clientRect.width = childRect.width + offset.width;
if (offset.LeftRight() + childRect.width > clientRect.width) {
clientRect.width = childRect.width + offset.LeftRight();
grow = PR_TRUE;
}
if (offset.height + childRect.height > clientRect.height) {
clientRect.height = childRect.height + offset.height;
if (offset.TopBottom() + childRect.height > clientRect.height) {
clientRect.height = childRect.height + offset.TopBottom();
grow = PR_TRUE;
}
}

View File

@ -67,7 +67,12 @@ public:
virtual nsSize GetMinSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState);
virtual nsSize GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState);
virtual nscoord GetAscent(nsIBox* aBox, nsBoxLayoutState& aBoxLayoutState);
static PRBool AddOffset(nsBoxLayoutState& aState, nsIBox* aChild, nsSize& aSize);
// get the child offsets for aChild and set them in aMargin. Returns a
// bitfield mask of the SPECIFIED_LEFT, SPECIFIED_RIGHT, SPECIFIED_TOP and
// SPECIFIED_BOTTOM offsets indicating which sides have been specified by
// attributes.
static PRUint8 GetOffset(nsBoxLayoutState& aState, nsIBox* aChild, nsMargin& aMargin);
private:
static nsIBoxLayout* gInstance;

View File

@ -49,6 +49,7 @@ _TEST_FILES = test_bug381167.xhtml \
test_resizer.xul \
window_resizer.xul \
test_bug477754.xul \
test_stack.xul \
$(NULL)
libs:: $(_TEST_FILES)

View File

@ -0,0 +1,218 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
<window align="start" title="XUL stack tests" onload="runTest()"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="/MochiKit/packed.js" />
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"/>
<!-- a * before an expected value means an offset from the right or bottom edge -->
<stack id="stack">
<hbox id="left-top" left="10" top="12" width="20" height="24"
expectedleft="10" expectedtop="12" expectedright="30" expectedbottom="36"
stackwidth="30" stackheight="36"/>
<hbox id="right-bottom" right="10" bottom="12" width="20" height="24"
expectedleft="*30" expectedtop="*36" expectedright="*10" expectedbottom="*12"
stackwidth="30" stackheight="36"/>
<hbox id="left-bottom" left="18" bottom="15" width="16" height="19"
expectedleft="18" expectedtop="*34" expectedright="34" expectedbottom="*15"
stackwidth="34" stackheight="34"/>
<hbox id="right-top" right="5" top="8" width="10" height="11"
expectedleft="*15" expectedtop="8" expectedright="*5" expectedbottom="19"
stackwidth="15" stackheight="19"/>
<hbox id="left-right" left="12" right="9" width="15" height="6"
expectedleft="12" expectedtop="0" expectedright="*9" expectedbottom="*0"
stackwidth="36" stackheight="6"/>
<hbox id="top-bottom" top="20" bottom="39" width="15" height="6"
expectedleft="0" expectedtop="20" expectedright="*0" expectedbottom="*39"
stackwidth="15" stackheight="65"/>
<hbox id="left-right-top-bottom" style="left: 5px; top: 5px; right: 8px; bottom: 8px;"
left="16" top="20" right="20" bottom="35" width="7" height="8"
expectedleft="16" expectedtop="20" expectedright="*20" expectedbottom="*35"
stackwidth="43" stackheight="63"/>
<hbox id="left-right-top-bottom-nosize" left="16" top="20" right="20" bottom="35"
expectedleft="16" expectedtop="20" expectedright="*20" expectedbottom="*35"
stackwidth="36" stackheight="55"/>
<hbox id="none" width="10" height="12" expectedleft="0" expectedtop="0" expectedright="*0" expectedbottom="*0"
stackwidth="10" stackheight="12"/>
<hbox id="none-nosize" expectedleft="0" expectedtop="0" expectedright="*0" expectedbottom="*0"
stackwidth="0" stackheight="0"/>
<hbox id="style-left-right-top-bottom"
style="left: 17px; top: 20px;" right="20" bottom="35" width="7" height="8"
expectedleft="*27" expectedtop="*43" expectedright="*20" expectedbottom="*35"
stackwidth="27" stackheight="43"/>
<hbox id="style-left-right-top-bottom-nosize"
style="left: 16px; top: 20px; right: 20px; bottom: 35px;"
expectedleft="0" expectedtop="0" expectedright="*0" expectedbottom="*0"
stackwidth="0" stackheight="0"/>
<hbox id="left-large-right" left="20" right="1000" height="6"
expectedleft="20" expectedtop="0" expectedright="20" expectedbottom="*0"
stackwidth="1020" stackheight="6"/>
<hbox id="left-top-with-margin" left="8" top="17" width="20" height="24"
style="margin: 1px 2px 3px 4px;"
expectedleft="12" expectedtop="18" expectedright="32" expectedbottom="42"
stackwidth="34" stackheight="45"/>
<hbox id="right-bottom-with-margin" right="6" bottom="15" width="10" height="14"
style="margin: 1px 2px 3px 4px;"
expectedleft="*18" expectedtop="*32" expectedright="*8" expectedbottom="*18"
stackwidth="22" stackheight="33"/>
<hbox id="left-top-right-bottom-with-margin" left="14" right="6" top="8" bottom="15" width="10" height="14"
style="margin: 1px 2px 3px 4px;"
expectedleft="18" expectedtop="9" expectedright="*8" expectedbottom="*18"
stackwidth="36" stackheight="41"/>
<hbox id="none-with-margin"
style="margin: 1px 2px 3px 4px;"
expectedleft="4" expectedtop="1" expectedright="*2" expectedbottom="*3"
stackwidth="6" stackheight="4"/>
</stack>
<stack id="stack-with-size" width="12" height="14">
<hbox id="left-top-with-stack-size" left="10" top="12" width="20" height="24"
expectedleft="10" expectedtop="12" expectedright="30" expectedbottom="36"/>
</stack>
<stack id="stack-with-border"
style="border-left: 4px solid black; border-top: 2px solid black; border-right: 1px solid black; border-bottom: 3px solid black;">
<hbox id="left-top-with-border" left="10" top="14" width="20" height="24"
expectedleft="14" expectedtop="16" expectedright="34" expectedbottom="40"/>
<hbox id="right-bottom-with-border" right="5" bottom="8" width="6" height="10"
expectedleft="*12" expectedtop="*21" expectedright="*6" expectedbottom="*11"/>
<hbox id="left-top-right-bottom-with-border" left="12" right="5" top="18" bottom="8"
expectedleft="16" expectedtop="20" expectedright="*6" expectedbottom="*11"/>
<hbox id="none-with-with-border"
expectedleft="4" expectedtop="2" expectedright="*1" expectedbottom="*3"/>
</stack>
<stack id="stack-dyn"/>
<stack id="stack-dyn-sized" width="12" height="14"/>
<body xmlns="http://www.w3.org/1999/xhtml"/>
<script><![CDATA[
SimpleTest.waitForExplicitFinish();
var stackRect;
var dynStack;
function compareSide(child, actual, side, dyn)
{
var vertical = (side == "top" || side == "bottom");
var expectedval = child.getAttribute("expected" + side);
if (expectedval.indexOf("*") == 0)
expectedval = (vertical ? stackRect.bottom : stackRect.right) - Number(expectedval.substring(1));
else
expectedval = (vertical ? stackRect.top : stackRect.left) + Number(expectedval);
is(actual, expectedval, child.id + " " + side + (dyn ? " dynamic" : ""));
}
function runTest()
{
runTestForStack("stack", false);
runTestForStack("stack-with-size", false);
var stackWithSize = $("stack-with-size");
var sizedStackRect = stackWithSize.getBoundingClientRect();
is(sizedStackRect.width, 30, "stack size stretched width");
is(sizedStackRect.height, 36, "stack size stretched height");
// set -moz-stack-sizing: ignore and ensure that the stack does not grow
// to include the child
var item = $("left-top-with-stack-size");
item.style.MozStackSizing = "ignore";
var parent = item.parentNode;
parent.removeChild(item);
parent.appendChild(item);
sizedStackRect = stackWithSize.getBoundingClientRect();
is(sizedStackRect.width, 12, "stack size not stretched width");
is(sizedStackRect.height, 14, "stack size not stretched height");
testPositionChanges(stackWithSize, true);
item.style.MozStackSizing = "";
testPositionChanges(stackWithSize, false);
// now test adding stack children dynamically to ensure that
// the size of the stack adjusts accordingly
dynStack = $("stack-dyn");
runTestForStack("stack", true);
SimpleTest.finish();
}
function runTestForStack(stackid, dyn)
{
var stack = $(stackid);
if (!dyn)
stackRect = stack.getBoundingClientRect();
var children = stack.childNodes;
for (var c = children.length - 1; c >= 0; c--) {
var child = children[c];
if (dyn) {
// for dynamic tests, get the size after appending the child as the
// stack size will be effected by it
dynStack.appendChild(child);
stackRect = dynStack.getBoundingClientRect();
is(stackRect.width, child.getAttribute("stackwidth"), child.id + " stack width" + (dyn ? " dynamic" : ""));
is(stackRect.height, child.getAttribute("stackheight"), child.id + " stack height" + (dyn ? " dynamic" : ""));
}
var childrect = child.getBoundingClientRect();
compareSide(child, childrect.left, "left", dyn);
compareSide(child, childrect.top, "top", dyn);
compareSide(child, childrect.right, "right", dyn);
compareSide(child, childrect.bottom, "bottom", dyn);
if (dyn)
dynStack.removeChild(child);
}
}
function testPositionChanges(stack, ignoreStackSizing)
{
var add = ignoreStackSizing ? " ignore stack sizing" : "";
// ensure that changing left/top/right/bottom works
var stackchild = document.getElementById("left-top-with-stack-size");
stackchild.left = 18;
is(stackchild.getBoundingClientRect().left, stack.getBoundingClientRect().left + 18, "left changed" + add);
is(stack.getBoundingClientRect().width, ignoreStackSizing ? 12 : 38, "left changed stack width" + add);
stackchild.top = 22;
is(stackchild.getBoundingClientRect().top, stack.getBoundingClientRect().top + 22, "top changed" + add);
is(stack.getBoundingClientRect().height, ignoreStackSizing ? 14 : 46, "left changed stack height" + add);
stackchild.setAttribute("right", "6");
is(stackchild.getBoundingClientRect().right, stack.getBoundingClientRect().left + 18, "right changed" + add);
// the width is only 12 pixels in ignoreStackSizing mode, so don't check the offset
// from the right edge in this case
if (!ignoreStackSizing)
is(stackchild.getBoundingClientRect().right, stack.getBoundingClientRect().right - 6,
"right changed from right edge" + add);
is(stack.getBoundingClientRect().width, ignoreStackSizing ? 12 : 24, "right changed stack width" + add);
stackchild.setAttribute("bottom", "9");
is(stackchild.getBoundingClientRect().bottom, stack.getBoundingClientRect().top + 22, "bottom changed" + add);
is(stack.getBoundingClientRect().height, ignoreStackSizing ? 14 : 31, "bottom changed stack height" + add);
if (!ignoreStackSizing)
is(stackchild.getBoundingClientRect().bottom, stack.getBoundingClientRect().bottom - 9,
"right changed from bottom edge" + add);
stackchild.left = "";
is(stackchild.getBoundingClientRect().right, stack.getBoundingClientRect().right - 6, "right changed" + add);
is(stack.getBoundingClientRect().width, ignoreStackSizing ? 12 : 26, "right changed no left stack width" + add);
stackchild.removeAttribute("right");
is(stackchild.getBoundingClientRect().right, stack.getBoundingClientRect().right, "right cleared" + add);
is(stack.getBoundingClientRect().width, 12, "right cleared stack height" + add);
// reset the values
stackchild.removeAttribute("bottom");
stackchild.left = 10;
stackchild.top = 12;
}
]]></script>
</window>