2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Eric Vaughan
|
|
|
|
// Netscape Communications
|
|
|
|
//
|
|
|
|
// See documentation in associated header file
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
#include "nsSprocketLayout.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2000-03-31 11:02:06 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIPresShell.h"
|
2011-12-28 00:18:48 +04:00
|
|
|
#include "nsContainerFrame.h"
|
2000-03-31 11:02:06 +04:00
|
|
|
#include "nsBoxFrame.h"
|
2012-05-04 04:14:02 +04:00
|
|
|
#include "StackArena.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsBoxLayout* nsSprocketLayout::gInstance = nullptr;
|
2000-04-05 04:19:00 +04:00
|
|
|
|
2000-06-03 02:15:09 +04:00
|
|
|
//#define DEBUG_GROW
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
#define DEBUG_SPRING_SIZE 8
|
|
|
|
#define DEBUG_BORDER_SIZE 2
|
|
|
|
#define COIL_SIZE 8
|
|
|
|
|
2000-04-05 04:19:00 +04:00
|
|
|
|
|
|
|
nsresult
|
2015-12-08 02:27:01 +03:00
|
|
|
NS_NewSprocketLayout(nsCOMPtr<nsBoxLayout>& aNewLayout)
|
2000-04-05 04:19:00 +04:00
|
|
|
{
|
2000-11-08 06:20:22 +03:00
|
|
|
if (!nsSprocketLayout::gInstance) {
|
|
|
|
nsSprocketLayout::gInstance = new nsSprocketLayout();
|
|
|
|
NS_IF_ADDREF(nsSprocketLayout::gInstance);
|
|
|
|
}
|
2000-04-05 04:19:00 +04:00
|
|
|
// we have not instance variables so just return our static one.
|
|
|
|
aNewLayout = nsSprocketLayout::gInstance;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-11-08 06:20:22 +03:00
|
|
|
/*static*/ void
|
|
|
|
nsSprocketLayout::Shutdown()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(gInstance);
|
|
|
|
}
|
|
|
|
|
2000-04-05 04:19:00 +04:00
|
|
|
nsSprocketLayout::nsSprocketLayout()
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2016-04-21 07:28:34 +03:00
|
|
|
nsSprocketLayout::IsXULHorizontal(nsIFrame* aBox)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2004-09-28 22:37:50 +04:00
|
|
|
return (aBox->GetStateBits() & NS_STATE_IS_HORIZONTAL) != 0;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-06 07:00:57 +04:00
|
|
|
nsSprocketLayout::GetFrameState(nsIFrame* aBox, nsFrameState& aState)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2004-09-28 22:37:50 +04:00
|
|
|
aState = aBox->GetStateBits();
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint8_t
|
2012-08-06 07:00:57 +04:00
|
|
|
GetFrameDirection(nsIFrame* aBox)
|
2004-09-07 00:18:23 +04:00
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
return aBox->StyleVisibility()->mDirection;
|
2004-09-07 00:18:23 +04:00
|
|
|
}
|
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
static void
|
2012-08-06 07:00:57 +04:00
|
|
|
HandleBoxPack(nsIFrame* aBox, const nsFrameState& aFrameState, nscoord& aX, nscoord& aY,
|
2001-08-15 08:09:41 +04:00
|
|
|
const nsRect& aOriginalRect, const nsRect& aClientRect)
|
|
|
|
{
|
|
|
|
// In the normal direction we lay out our kids in the positive direction (e.g., |x| will get
|
|
|
|
// bigger for a horizontal box, and |y| will get bigger for a vertical box). In the reverse
|
|
|
|
// direction, the opposite is true. We'll be laying out each child at a smaller |x| or
|
|
|
|
// |y|.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t frameDirection = GetFrameDirection(aBox);
|
2004-09-07 00:18:23 +04:00
|
|
|
|
|
|
|
if (aFrameState & NS_STATE_IS_HORIZONTAL) {
|
|
|
|
if (aFrameState & NS_STATE_IS_DIRECTION_NORMAL) {
|
|
|
|
// The normal direction. |x| increases as we move through our children.
|
|
|
|
aX = aClientRect.x;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// The reverse direction. |x| decreases as we move through our children.
|
|
|
|
aX = aClientRect.x + aOriginalRect.width;
|
|
|
|
}
|
|
|
|
// |y| is always in the normal direction in horizontal boxes
|
|
|
|
aY = aClientRect.y;
|
2001-08-15 08:09:41 +04:00
|
|
|
}
|
|
|
|
else {
|
2004-09-07 00:18:23 +04:00
|
|
|
// take direction property into account for |x| in vertical boxes
|
|
|
|
if (frameDirection == NS_STYLE_DIRECTION_LTR) {
|
|
|
|
// The normal direction. |x| increases as we move through our children.
|
|
|
|
aX = aClientRect.x;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// The reverse direction. |x| decreases as we move through our children.
|
|
|
|
aX = aClientRect.x + aOriginalRect.width;
|
|
|
|
}
|
|
|
|
if (aFrameState & NS_STATE_IS_DIRECTION_NORMAL) {
|
|
|
|
// The normal direction. |y| increases as we move through our children.
|
|
|
|
aY = aClientRect.y;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// The reverse direction. |y| decreases as we move through our children.
|
|
|
|
aY = aClientRect.y + aOriginalRect.height;
|
|
|
|
}
|
2001-08-15 08:09:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get our pack/alignment information.
|
2016-04-21 07:28:33 +03:00
|
|
|
nsIFrame::Halignment halign = aBox->GetXULHAlign();
|
2016-04-21 07:28:33 +03:00
|
|
|
nsIFrame::Valignment valign = aBox->GetXULVAlign();
|
2001-08-15 08:09:41 +04:00
|
|
|
|
|
|
|
// The following code handles box PACKING. Packing comes into play in the case where the computed size for
|
|
|
|
// all of our children (now stored in our client rect) is smaller than the size available for
|
|
|
|
// the box (stored in |aOriginalRect|).
|
|
|
|
//
|
|
|
|
// Here we adjust our |x| and |y| variables accordingly so that we start at the beginning,
|
|
|
|
// middle, or end of the box.
|
|
|
|
//
|
|
|
|
// XXXdwh JUSTIFY needs to be implemented!
|
|
|
|
if (aFrameState & NS_STATE_IS_HORIZONTAL) {
|
|
|
|
switch(halign) {
|
|
|
|
case nsBoxFrame::hAlign_Left:
|
|
|
|
break; // Nothing to do. The default initialized us properly.
|
|
|
|
|
|
|
|
case nsBoxFrame::hAlign_Center:
|
|
|
|
if (aFrameState & NS_STATE_IS_DIRECTION_NORMAL)
|
|
|
|
aX += (aOriginalRect.width - aClientRect.width)/2;
|
|
|
|
else
|
|
|
|
aX -= (aOriginalRect.width - aClientRect.width)/2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsBoxFrame::hAlign_Right:
|
|
|
|
if (aFrameState & NS_STATE_IS_DIRECTION_NORMAL)
|
|
|
|
aX += (aOriginalRect.width - aClientRect.width);
|
|
|
|
else
|
|
|
|
aX -= (aOriginalRect.width - aClientRect.width);
|
|
|
|
break; // Nothing to do for the reverse dir. The default initialized us properly.
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch(valign) {
|
|
|
|
case nsBoxFrame::vAlign_Top:
|
|
|
|
case nsBoxFrame::vAlign_BaseLine: // This value is technically impossible to specify for pack.
|
|
|
|
break; // Don't do anything. We were initialized correctly.
|
|
|
|
|
|
|
|
case nsBoxFrame::vAlign_Middle:
|
|
|
|
if (aFrameState & NS_STATE_IS_DIRECTION_NORMAL)
|
|
|
|
aY += (aOriginalRect.height - aClientRect.height)/2;
|
|
|
|
else
|
|
|
|
aY -= (aOriginalRect.height - aClientRect.height)/2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsBoxFrame::vAlign_Bottom:
|
|
|
|
if (aFrameState & NS_STATE_IS_DIRECTION_NORMAL)
|
|
|
|
aY += (aOriginalRect.height - aClientRect.height);
|
|
|
|
else
|
|
|
|
aY -= (aOriginalRect.height - aClientRect.height);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
NS_IMETHODIMP
|
2016-04-21 07:28:32 +03:00
|
|
|
nsSprocketLayout::XULLayout(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2001-08-15 08:09:41 +04:00
|
|
|
// See if we are collapsed. If we are, then simply iterate over all our
|
|
|
|
// children and give them a rect of 0 width and height.
|
2016-04-21 07:28:32 +03:00
|
|
|
if (aBox->IsXULCollapsed()) {
|
2016-04-21 07:28:32 +03:00
|
|
|
nsIFrame* child = nsBox::GetChildXULBox(aBox);
|
2000-05-17 00:46:08 +04:00
|
|
|
while(child)
|
|
|
|
{
|
2004-09-28 22:37:50 +04:00
|
|
|
nsBoxFrame::LayoutChildAt(aState, child, nsRect(0,0,0,0));
|
2016-04-21 07:28:32 +03:00
|
|
|
child = nsBox::GetNextXULBox(child);
|
2000-05-17 00:46:08 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-04 04:14:02 +04:00
|
|
|
nsBoxLayoutState::AutoReflowDepth depth(aState);
|
|
|
|
mozilla::AutoStackArena arena;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
// ----- figure out our size ----------
|
2009-10-22 04:05:25 +04:00
|
|
|
const nsSize originalSize = aBox->GetSize();
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
// -- make sure we remove our border and padding ----
|
|
|
|
nsRect clientRect;
|
2016-04-21 07:28:33 +03:00
|
|
|
aBox->GetXULClientRect(clientRect);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// |originalClientRect| represents the rect of the entire box (excluding borders
|
|
|
|
// and padding). We store it here because we're going to use |clientRect| to hold
|
|
|
|
// the required size for all our kids. As an example, consider an hbox with a
|
|
|
|
// specified width of 300. If the kids total only 150 pixels of width, then
|
|
|
|
// we have 150 pixels left over. |clientRect| is going to hold a width of 150 and
|
|
|
|
// is going to be adjusted based off the value of the PACK property. If flexible
|
|
|
|
// objects are in the box, then the two rects will match.
|
2000-03-31 11:02:06 +04:00
|
|
|
nsRect originalClientRect(clientRect);
|
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// The frame state contains cached knowledge about our box, such as our orientation
|
|
|
|
// and direction.
|
2014-02-05 05:59:39 +04:00
|
|
|
nsFrameState frameState = nsFrameState(0);
|
2000-03-31 11:02:06 +04:00
|
|
|
GetFrameState(aBox, frameState);
|
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// Build a list of our children's desired sizes and computed sizes
|
2012-07-30 18:20:58 +04:00
|
|
|
nsBoxSize* boxSizes = nullptr;
|
|
|
|
nsComputedBoxSize* computedBoxSizes = nullptr;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2000-04-26 08:00:29 +04:00
|
|
|
nscoord min = 0;
|
|
|
|
nscoord max = 0;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t flexes = 0;
|
2009-10-22 04:05:25 +04:00
|
|
|
PopulateBoxSizes(aBox, aState, boxSizes, min, max, flexes);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// The |size| variable will hold the total size of children along the axis of
|
|
|
|
// the box. Continuing with the example begun in the comment above, size would
|
|
|
|
// be 150 pixels.
|
2000-04-25 11:10:48 +04:00
|
|
|
nscoord size = clientRect.width;
|
2016-04-21 07:28:34 +03:00
|
|
|
if (!IsXULHorizontal(aBox))
|
2001-08-15 08:09:41 +04:00
|
|
|
size = clientRect.height;
|
2000-04-25 11:10:48 +04:00
|
|
|
ComputeChildSizes(aBox, aState, size, boxSizes, computedBoxSizes);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// After the call to ComputeChildSizes, the |size| variable contains the
|
|
|
|
// total required size of all the children. We adjust our clientRect in the
|
|
|
|
// appropriate dimension to match this size. In our example, we now assign
|
|
|
|
// 150 pixels into the clientRect.width.
|
|
|
|
//
|
|
|
|
// The variables |min| and |max| hold the minimum required size box must be
|
|
|
|
// in the OPPOSITE orientation, e.g., for a horizontal box, |min| is the minimum
|
|
|
|
// height we require to enclose our children, and |max| is the maximum height
|
|
|
|
// required to enclose our children.
|
2016-04-21 07:28:34 +03:00
|
|
|
if (IsXULHorizontal(aBox)) {
|
2001-08-15 08:09:41 +04:00
|
|
|
clientRect.width = size;
|
|
|
|
if (clientRect.height < min)
|
|
|
|
clientRect.height = min;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
if (frameState & NS_STATE_AUTO_STRETCH) {
|
|
|
|
if (clientRect.height > max)
|
|
|
|
clientRect.height = max;
|
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
} else {
|
2001-08-15 08:09:41 +04:00
|
|
|
clientRect.height = size;
|
|
|
|
if (clientRect.width < min)
|
|
|
|
clientRect.width = min;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
if (frameState & NS_STATE_AUTO_STRETCH) {
|
|
|
|
if (clientRect.width > max)
|
|
|
|
clientRect.width = max;
|
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// With the sizes computed, now it's time to lay out our children.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool finished;
|
2000-03-31 11:02:06 +04:00
|
|
|
nscoord passes = 0;
|
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// We flow children at their preferred locations (along with the appropriate computed flex).
|
|
|
|
// After we flow a child, it is possible that the child will change its size. If/when this happens,
|
|
|
|
// we have to do another pass. Typically only 2 passes are required, but the code is prepared to
|
|
|
|
// do as many passes as are necessary to achieve equilibrium.
|
2000-03-31 11:02:06 +04:00
|
|
|
nscoord x = 0;
|
|
|
|
nscoord y = 0;
|
|
|
|
nscoord origX = 0;
|
|
|
|
nscoord origY = 0;
|
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// |childResized| lets us know if a child changed its size after we attempted to lay it out at
|
|
|
|
// the specified size. If this happens, we usually have to do another pass.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool childResized = false;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// |passes| stores our number of passes. If for any reason we end up doing more than, say, 10
|
|
|
|
// passes, we assert to indicate that something is seriously screwed up.
|
2000-03-31 11:02:06 +04:00
|
|
|
passes = 0;
|
|
|
|
do
|
|
|
|
{
|
2001-08-15 08:09:41 +04:00
|
|
|
#ifdef DEBUG_REFLOW
|
2000-03-31 11:02:06 +04:00
|
|
|
if (passes > 0) {
|
|
|
|
AddIndents();
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("ChildResized doing pass: %d\n", passes);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
2001-08-15 08:09:41 +04:00
|
|
|
#endif
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// Always assume that we're done. This will change if, for example, children don't stay
|
|
|
|
// the same size after being flowed.
|
2011-10-17 18:59:28 +04:00
|
|
|
finished = true;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// Handle box packing.
|
|
|
|
HandleBoxPack(aBox, frameState, x, y, originalClientRect, clientRect);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// Now that packing is taken care of we set up a few additional
|
|
|
|
// tracking variables.
|
2000-03-31 11:02:06 +04:00
|
|
|
origX = x;
|
|
|
|
origY = y;
|
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// Now we iterate over our box children and our box size lists in
|
|
|
|
// parallel. For each child, we look at its sizes and figure out
|
|
|
|
// where to place it.
|
2000-03-31 11:02:06 +04:00
|
|
|
nsComputedBoxSize* childComputedBoxSize = computedBoxSizes;
|
|
|
|
nsBoxSize* childBoxSize = boxSizes;
|
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
nsIFrame* child = nsBox::GetChildXULBox(aBox);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = 0;
|
2000-04-12 03:55:15 +04:00
|
|
|
while (child || (childBoxSize && childBoxSize->bogus))
|
2001-08-15 08:09:41 +04:00
|
|
|
{
|
|
|
|
// If for some reason, our lists are not the same length, we guard
|
|
|
|
// by bailing out of the loop.
|
2012-07-30 18:20:58 +04:00
|
|
|
if (childBoxSize == nullptr) {
|
2003-06-02 00:03:13 +04:00
|
|
|
NS_NOTREACHED("Lists not the same length.");
|
2001-06-07 03:16:38 +04:00
|
|
|
break;
|
2003-06-02 00:03:13 +04:00
|
|
|
}
|
2001-06-07 03:16:38 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
nscoord width = clientRect.width;
|
|
|
|
nscoord height = clientRect.height;
|
|
|
|
|
2000-04-12 03:55:15 +04:00
|
|
|
if (!childBoxSize->bogus) {
|
2001-08-15 08:09:41 +04:00
|
|
|
// We have a valid box size entry. This entry already contains information about our
|
|
|
|
// sizes along the axis of the box (e.g., widths in a horizontal box). If our default
|
|
|
|
// ALIGN is not stretch, however, then we also need to know the child's size along the
|
|
|
|
// opposite axis.
|
2000-04-12 03:55:15 +04:00
|
|
|
if (!(frameState & NS_STATE_AUTO_STRETCH)) {
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSize prefSize = child->GetXULPrefSize(aState);
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSize minSize = child->GetXULMinSize(aState);
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSize maxSize = child->GetXULMaxSize(aState);
|
2008-01-05 08:49:44 +03:00
|
|
|
prefSize = nsBox::BoundsCheck(minSize, prefSize, maxSize);
|
2000-04-12 03:55:15 +04:00
|
|
|
|
|
|
|
AddMargin(child, prefSize);
|
2013-01-15 16:22:03 +04:00
|
|
|
width = std::min(prefSize.width, originalClientRect.width);
|
|
|
|
height = std::min(prefSize.height, originalClientRect.height);
|
2000-04-12 03:55:15 +04:00
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// Obtain the computed size along the axis of the box for this child from the computedBoxSize entry.
|
|
|
|
// We store the result in |width| for horizontal boxes and |height| for vertical boxes.
|
|
|
|
if (frameState & NS_STATE_IS_HORIZONTAL)
|
2000-03-31 11:02:06 +04:00
|
|
|
width = childComputedBoxSize->size;
|
2001-08-15 08:09:41 +04:00
|
|
|
else
|
2000-03-31 11:02:06 +04:00
|
|
|
height = childComputedBoxSize->size;
|
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// Adjust our x/y for the left/right spacing.
|
2003-06-02 00:03:13 +04:00
|
|
|
if (frameState & NS_STATE_IS_HORIZONTAL) {
|
2001-08-15 08:09:41 +04:00
|
|
|
if (frameState & NS_STATE_IS_DIRECTION_NORMAL)
|
|
|
|
x += (childBoxSize->left);
|
|
|
|
else
|
|
|
|
x -= (childBoxSize->right);
|
2003-06-02 00:03:13 +04:00
|
|
|
} else {
|
2001-08-15 08:09:41 +04:00
|
|
|
if (frameState & NS_STATE_IS_DIRECTION_NORMAL)
|
|
|
|
y += (childBoxSize->left);
|
|
|
|
else
|
|
|
|
y -= (childBoxSize->right);
|
2003-06-02 00:03:13 +04:00
|
|
|
}
|
2000-06-03 02:15:09 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// Now we build a child rect.
|
|
|
|
nscoord rectX = x;
|
|
|
|
nscoord rectY = y;
|
|
|
|
if (!(frameState & NS_STATE_IS_DIRECTION_NORMAL)) {
|
|
|
|
if (frameState & NS_STATE_IS_HORIZONTAL)
|
|
|
|
rectX -= width;
|
|
|
|
else
|
|
|
|
rectY -= height;
|
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// We now create an accurate child rect based off our computed size information.
|
|
|
|
nsRect childRect(rectX, rectY, width, height);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// Sanity check against our clientRect. It is possible that a child specified
|
|
|
|
// a size that is too large to fit. If that happens, then we have to grow
|
|
|
|
// our client rect. Remember, clientRect is not the total rect of the enclosing
|
|
|
|
// box. It currently holds our perception of how big the children needed to
|
|
|
|
// be.
|
2009-10-22 04:05:25 +04:00
|
|
|
if (childRect.width > clientRect.width)
|
|
|
|
clientRect.width = childRect.width;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2009-10-22 04:05:25 +04:00
|
|
|
if (childRect.height > clientRect.height)
|
|
|
|
clientRect.height = childRect.height;
|
2001-08-15 08:09:41 +04:00
|
|
|
|
2009-10-22 04:11:25 +04:00
|
|
|
// Either |nextX| or |nextY| is updated by this function call, according
|
|
|
|
// to our axis.
|
2015-03-19 23:00:03 +03:00
|
|
|
nscoord nextX = x;
|
|
|
|
nscoord nextY = y;
|
|
|
|
|
2009-10-22 04:11:25 +04:00
|
|
|
ComputeChildsNextPosition(aBox, x, y, nextX, nextY, childRect);
|
|
|
|
|
|
|
|
// Now we further update our nextX/Y along our axis.
|
|
|
|
// We also set childRect.y/x along the opposite axis appropriately for a
|
|
|
|
// stretch alignment. (Non-stretch alignment is handled below.)
|
2001-08-15 08:09:41 +04:00
|
|
|
if (frameState & NS_STATE_IS_HORIZONTAL) {
|
|
|
|
if (frameState & NS_STATE_IS_DIRECTION_NORMAL)
|
|
|
|
nextX += (childBoxSize->right);
|
|
|
|
else
|
|
|
|
nextX -= (childBoxSize->left);
|
2009-10-22 04:11:25 +04:00
|
|
|
childRect.y = originalClientRect.y;
|
2001-08-15 08:09:41 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (frameState & NS_STATE_IS_DIRECTION_NORMAL)
|
|
|
|
nextY += (childBoxSize->right);
|
|
|
|
else
|
|
|
|
nextY -= (childBoxSize->left);
|
Bug 1150021. Make sure that boxes inside vertical RTL boxes are placed on the right. r=roc
nsSprocketLayout::Layout lays out its children by looping from first child to last child updating local variables x, y as it goes that keep track of the position where to layout the current child.
If the box is horizontal it works left-to-right or right-to-left according to wheather the direction of the box is normal or not. Vertical boxes work similarly top-to-bottom or bottom-to-top. Vertical boxes also respond to CSS direction styles, so that in an LTR box the child boxes are laid out flush left, but flush right in an RTL box. Herein lies the bug, some code assumes the child boxes are laid out flush right in RTL, but the code to actually position the children positions them flush left.
The code that assumes the child are laid out flush right is HandleBoxPack, which determines the origin to start laying out children at, and the code which uses HandleBoxPack to determine if the origin changed during the laying out of the children, and then shifts the children by the amount the origin shifted. The size of our box changing will, in general, change the position of the origin. So the children aren't laid out to the origin that HandleBoxPack expects they will get moved to wrong positions.
2015-04-07 10:28:57 +03:00
|
|
|
if (GetFrameDirection(aBox) == NS_STYLE_DIRECTION_LTR) {
|
|
|
|
childRect.x = originalClientRect.x;
|
|
|
|
} else {
|
|
|
|
// keep the right edge of the box the same
|
|
|
|
childRect.x = clientRect.x + originalClientRect.width - childRect.width;
|
|
|
|
}
|
2001-08-15 08:09:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we encounter a completely bogus box size, we just leave this child completely
|
|
|
|
// alone and continue through the loop to the next child.
|
2000-04-12 03:55:15 +04:00
|
|
|
if (childBoxSize->bogus)
|
|
|
|
{
|
|
|
|
childComputedBoxSize = childComputedBoxSize->next;
|
|
|
|
childBoxSize = childBoxSize->next;
|
|
|
|
count++;
|
|
|
|
x = nextX;
|
|
|
|
y = nextY;
|
|
|
|
continue;
|
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2000-04-12 03:55:15 +04:00
|
|
|
nsMargin margin(0,0,0,0);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool layout = true;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// Deflate the rect of our child by its margin.
|
2016-04-21 07:28:33 +03:00
|
|
|
child->GetXULMargin(margin);
|
2000-06-01 00:14:28 +04:00
|
|
|
childRect.Deflate(margin);
|
|
|
|
if (childRect.width < 0)
|
2000-06-03 02:15:09 +04:00
|
|
|
childRect.width = 0;
|
2000-06-01 00:14:28 +04:00
|
|
|
if (childRect.height < 0)
|
2000-06-03 02:15:09 +04:00
|
|
|
childRect.height = 0;
|
2000-04-12 03:55:15 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// Now we're trying to figure out if we have to lay out this child, i.e., to call
|
2016-04-21 07:28:32 +03:00
|
|
|
// the child's XULLayout method.
|
2000-03-31 11:02:06 +04:00
|
|
|
if (passes > 0) {
|
2011-10-17 18:59:28 +04:00
|
|
|
layout = false;
|
2000-03-31 11:02:06 +04:00
|
|
|
} else {
|
2001-08-15 08:09:41 +04:00
|
|
|
// Always perform layout if we are dirty or have dirty children
|
2007-05-06 23:16:51 +04:00
|
|
|
if (!NS_SUBTREE_DIRTY(child))
|
2011-10-17 18:59:28 +04:00
|
|
|
layout = false;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2009-10-22 04:11:25 +04:00
|
|
|
nsRect oldRect(child->GetRect());
|
|
|
|
|
|
|
|
// Non-stretch alignment will be handled in AlignChildren(), so don't
|
|
|
|
// change child out-of-axis positions yet.
|
|
|
|
if (!(frameState & NS_STATE_AUTO_STRETCH)) {
|
|
|
|
if (frameState & NS_STATE_IS_HORIZONTAL) {
|
|
|
|
childRect.y = oldRect.y;
|
|
|
|
} else {
|
|
|
|
childRect.x = oldRect.x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// We computed a childRect. Now we want to set the bounds of the child to be that rect.
|
|
|
|
// If our old rect is different, then we know our size changed and we cache that fact
|
|
|
|
// in the |sizeChanged| variable.
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
child->SetXULBounds(aState, childRect);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool sizeChanged = (childRect.width != oldRect.width ||
|
2009-10-22 04:11:25 +04:00
|
|
|
childRect.height != oldRect.height);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
if (sizeChanged) {
|
2001-08-15 08:09:41 +04:00
|
|
|
// Our size is different. Sanity check against our maximum allowed size to ensure
|
|
|
|
// we didn't exceed it.
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSize minSize = child->GetXULMinSize(aState);
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSize maxSize = child->GetXULMaxSize(aState);
|
2008-01-05 08:49:44 +03:00
|
|
|
maxSize = nsBox::BoundsCheckMinMax(minSize, maxSize);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// make sure the size is in our max size.
|
|
|
|
if (childRect.width > maxSize.width)
|
|
|
|
childRect.width = maxSize.width;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
if (childRect.height > maxSize.height)
|
|
|
|
childRect.height = maxSize.height;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// set it again
|
2016-04-21 07:28:32 +03:00
|
|
|
child->SetXULBounds(aState, childRect);
|
2001-08-15 08:09:41 +04:00
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// If we already determined that layout was required or if our size has changed, then
|
|
|
|
// we make sure to call layout on the child, since its children may need to be shifted
|
|
|
|
// around as a result of the size change.
|
|
|
|
if (layout || sizeChanged)
|
2016-04-21 07:28:32 +03:00
|
|
|
child->XULLayout(aState);
|
2000-04-12 03:55:15 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// If the child was a block or inline (e.g., HTML) it may have changed its rect *during* layout.
|
|
|
|
// We have to check for this.
|
2004-09-28 22:37:50 +04:00
|
|
|
nsRect newChildRect(child->GetRect());
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2011-05-22 20:55:02 +04:00
|
|
|
if (!newChildRect.IsEqualInterior(childRect)) {
|
2000-06-03 02:15:09 +04:00
|
|
|
#ifdef DEBUG_GROW
|
2016-04-21 07:28:34 +03:00
|
|
|
child->XULDumpBox(stdout);
|
2001-08-15 08:09:41 +04:00
|
|
|
printf(" GREW from (%d,%d) -> (%d,%d)\n", childRect.width, childRect.height, newChildRect.width, newChildRect.height);
|
2000-06-03 02:15:09 +04:00
|
|
|
#endif
|
2001-08-15 08:09:41 +04:00
|
|
|
newChildRect.Inflate(margin);
|
|
|
|
childRect.Inflate(margin);
|
|
|
|
|
|
|
|
// The child changed size during layout. The ChildResized method handles this
|
|
|
|
// scenario.
|
|
|
|
ChildResized(aBox,
|
|
|
|
aState,
|
|
|
|
child,
|
|
|
|
childBoxSize,
|
|
|
|
childComputedBoxSize,
|
|
|
|
boxSizes,
|
|
|
|
computedBoxSizes,
|
|
|
|
childRect,
|
|
|
|
newChildRect,
|
|
|
|
clientRect,
|
|
|
|
flexes,
|
|
|
|
finished);
|
|
|
|
|
|
|
|
// We note that a child changed size, which means that another pass will be required.
|
2011-10-17 18:59:28 +04:00
|
|
|
childResized = true;
|
2001-08-15 08:09:41 +04:00
|
|
|
|
|
|
|
// Now that a child resized, it's entirely possible that OUR rect is too small. Now we
|
|
|
|
// ensure that |originalClientRect| is grown to accommodate the size of |clientRect|.
|
2009-10-22 04:05:25 +04:00
|
|
|
if (clientRect.width > originalClientRect.width)
|
|
|
|
originalClientRect.width = clientRect.width;
|
2001-08-15 08:09:41 +04:00
|
|
|
|
2009-10-22 04:05:25 +04:00
|
|
|
if (clientRect.height > originalClientRect.height)
|
|
|
|
originalClientRect.height = clientRect.height;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2005-01-15 22:35:19 +03:00
|
|
|
if (!(frameState & NS_STATE_IS_DIRECTION_NORMAL)) {
|
|
|
|
// Our childRect had its XMost() or YMost() (depending on our layout
|
|
|
|
// direction), positioned at a certain point. Ensure that the
|
|
|
|
// newChildRect satisfies the same constraint. Note that this is
|
|
|
|
// just equivalent to adjusting the x/y by the difference in
|
|
|
|
// width/height between childRect and newChildRect. So we don't need
|
|
|
|
// to reaccount for the left and right of the box layout state again.
|
|
|
|
if (frameState & NS_STATE_IS_HORIZONTAL)
|
|
|
|
newChildRect.x = childRect.XMost() - newChildRect.width;
|
|
|
|
else
|
|
|
|
newChildRect.y = childRect.YMost() - newChildRect.height;
|
|
|
|
}
|
|
|
|
|
Bug 1150021. Make sure that boxes inside vertical RTL boxes are placed on the right. r=roc
nsSprocketLayout::Layout lays out its children by looping from first child to last child updating local variables x, y as it goes that keep track of the position where to layout the current child.
If the box is horizontal it works left-to-right or right-to-left according to wheather the direction of the box is normal or not. Vertical boxes work similarly top-to-bottom or bottom-to-top. Vertical boxes also respond to CSS direction styles, so that in an LTR box the child boxes are laid out flush left, but flush right in an RTL box. Herein lies the bug, some code assumes the child boxes are laid out flush right in RTL, but the code to actually position the children positions them flush left.
The code that assumes the child are laid out flush right is HandleBoxPack, which determines the origin to start laying out children at, and the code which uses HandleBoxPack to determine if the origin changed during the laying out of the children, and then shifts the children by the amount the origin shifted. The size of our box changing will, in general, change the position of the origin. So the children aren't laid out to the origin that HandleBoxPack expects they will get moved to wrong positions.
2015-04-07 10:28:57 +03:00
|
|
|
if (!(frameState & NS_STATE_IS_HORIZONTAL)) {
|
|
|
|
if (GetFrameDirection(aBox) != NS_STYLE_DIRECTION_LTR) {
|
|
|
|
// keep the right edge the same
|
|
|
|
newChildRect.x = childRect.XMost() - newChildRect.width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// If the child resized then recompute its position.
|
2009-10-22 04:11:25 +04:00
|
|
|
ComputeChildsNextPosition(aBox, x, y, nextX, nextY, newChildRect);
|
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
if (newChildRect.width >= margin.left + margin.right && newChildRect.height >= margin.top + margin.bottom)
|
|
|
|
newChildRect.Deflate(margin);
|
|
|
|
|
|
|
|
if (childRect.width >= margin.left + margin.right && childRect.height >= margin.top + margin.bottom)
|
|
|
|
childRect.Deflate(margin);
|
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
child->SetXULBounds(aState, newChildRect);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// If we are the first box that changed size, then we don't need to do a second pass
|
|
|
|
if (count == 0)
|
2011-10-17 18:59:28 +04:00
|
|
|
finished = true;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// Now update our x/y finally.
|
|
|
|
x = nextX;
|
|
|
|
y = nextY;
|
|
|
|
|
|
|
|
// Move to the next child.
|
2000-03-31 11:02:06 +04:00
|
|
|
childComputedBoxSize = childComputedBoxSize->next;
|
|
|
|
childBoxSize = childBoxSize->next;
|
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
child = nsBox::GetNextXULBox(child);
|
2000-03-31 11:02:06 +04:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// Sanity-checking code to ensure we don't do an infinite # of passes.
|
2000-03-31 11:02:06 +04:00
|
|
|
passes++;
|
2000-04-26 08:00:29 +04:00
|
|
|
NS_ASSERTION(passes < 10, "A Box's child is constantly growing!!!!!");
|
2001-08-15 08:09:41 +04:00
|
|
|
if (passes > 10)
|
2000-03-31 11:02:06 +04:00
|
|
|
break;
|
2011-10-17 18:59:28 +04:00
|
|
|
} while (false == finished);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// Get rid of our size lists.
|
2000-03-31 11:02:06 +04:00
|
|
|
while(boxSizes)
|
|
|
|
{
|
2001-08-15 08:09:41 +04:00
|
|
|
nsBoxSize* toDelete = boxSizes;
|
|
|
|
boxSizes = boxSizes->next;
|
|
|
|
delete toDelete;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
while(computedBoxSizes)
|
|
|
|
{
|
2001-08-15 08:09:41 +04:00
|
|
|
nsComputedBoxSize* toDelete = computedBoxSizes;
|
|
|
|
computedBoxSizes = computedBoxSizes->next;
|
|
|
|
delete toDelete;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (childResized) {
|
2001-08-15 08:09:41 +04:00
|
|
|
// See if one of our children forced us to get bigger
|
2000-03-31 11:02:06 +04:00
|
|
|
nsRect tmpClientRect(originalClientRect);
|
|
|
|
nsMargin bp(0,0,0,0);
|
2016-04-21 07:28:32 +03:00
|
|
|
aBox->GetXULBorderAndPadding(bp);
|
2000-03-31 11:02:06 +04:00
|
|
|
tmpClientRect.Inflate(bp);
|
|
|
|
|
2007-01-31 19:02:42 +03:00
|
|
|
if (tmpClientRect.width > originalSize.width || tmpClientRect.height > originalSize.height)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
|
|
|
// if it did reset our bounds.
|
2004-09-28 22:37:50 +04:00
|
|
|
nsRect bounds(aBox->GetRect());
|
2007-01-31 19:02:42 +03:00
|
|
|
if (tmpClientRect.width > originalSize.width)
|
2000-03-31 11:02:06 +04:00
|
|
|
bounds.width = tmpClientRect.width;
|
|
|
|
|
2007-01-31 19:02:42 +03:00
|
|
|
if (tmpClientRect.height > originalSize.height)
|
2000-03-31 11:02:06 +04:00
|
|
|
bounds.height = tmpClientRect.height;
|
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
aBox->SetXULBounds(aState, bounds);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// Because our size grew, we now have to readjust because of box packing. Repack
|
|
|
|
// in order to update our x and y to the correct values.
|
|
|
|
HandleBoxPack(aBox, frameState, x, y, originalClientRect, clientRect);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// Compare against our original x and y and only worry about adjusting the children if
|
|
|
|
// we really did have to change the positions because of packing (typically for 'center'
|
|
|
|
// or 'end' pack values).
|
|
|
|
if (x != origX || y != origY) {
|
2016-04-21 07:28:32 +03:00
|
|
|
nsIFrame* child = nsBox::GetChildXULBox(aBox);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2007-02-22 21:05:14 +03:00
|
|
|
// reposition all our children
|
2001-08-15 08:09:41 +04:00
|
|
|
while (child)
|
|
|
|
{
|
2004-09-28 22:37:50 +04:00
|
|
|
nsRect childRect(child->GetRect());
|
2001-08-15 08:09:41 +04:00
|
|
|
childRect.x += (x - origX);
|
|
|
|
childRect.y += (y - origY);
|
2016-04-21 07:28:32 +03:00
|
|
|
child->SetXULBounds(aState, childRect);
|
2016-04-21 07:28:32 +03:00
|
|
|
child = nsBox::GetNextXULBox(child);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
2001-08-15 08:09:41 +04:00
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2009-10-22 04:11:25 +04:00
|
|
|
// Perform out-of-axis alignment for non-stretch alignments
|
|
|
|
if (!(frameState & NS_STATE_AUTO_STRETCH)) {
|
2012-10-17 01:30:37 +04:00
|
|
|
AlignChildren(aBox, aState);
|
2009-10-22 04:11:25 +04:00
|
|
|
}
|
2012-10-17 01:30:37 +04:00
|
|
|
|
2001-08-15 08:09:41 +04:00
|
|
|
// That's it! If you made it this far without having a nervous breakdown,
|
|
|
|
// congratulations! Go get yourself a beer.
|
2000-03-31 11:02:06 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSprocketLayout::PopulateBoxSizes(nsIFrame* aBox, nsBoxLayoutState& aState, nsBoxSize*& aBoxSizes, nscoord& aMinSize, nscoord& aMaxSize, int32_t& aFlexes)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2000-06-23 09:15:04 +04:00
|
|
|
// used for the equal size flag
|
|
|
|
nscoord biggestPrefWidth = 0;
|
|
|
|
nscoord biggestMinWidth = 0;
|
|
|
|
nscoord smallestMaxWidth = NS_INTRINSICSIZE;
|
|
|
|
|
2014-02-05 05:59:39 +04:00
|
|
|
nsFrameState frameState = nsFrameState(0);
|
2000-03-31 11:02:06 +04:00
|
|
|
GetFrameState(aBox, frameState);
|
|
|
|
|
|
|
|
//if (frameState & NS_STATE_CURRENTLY_IN_DEBUG)
|
2000-10-29 02:17:53 +04:00
|
|
|
// printf("In debug\n");
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
aMinSize = 0;
|
|
|
|
aMaxSize = NS_INTRINSICSIZE;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isHorizontal;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2016-04-21 07:28:34 +03:00
|
|
|
if (IsXULHorizontal(aBox))
|
2011-10-17 18:59:28 +04:00
|
|
|
isHorizontal = true;
|
2000-03-31 11:02:06 +04:00
|
|
|
else
|
2011-10-17 18:59:28 +04:00
|
|
|
isHorizontal = false;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
// this is a nice little optimization
|
|
|
|
// it turns out that if we only have 1 flexable child
|
2002-03-19 07:30:17 +03:00
|
|
|
// then it does not matter what its preferred size is
|
2000-03-31 11:02:06 +04:00
|
|
|
// there is nothing to flex it relative. This is great
|
|
|
|
// because we can avoid asking for a preferred size in this
|
|
|
|
// case. Why is this good? Well you might have html inside it
|
|
|
|
// and asking html for its preferred size is rather expensive.
|
|
|
|
// so we can just optimize it out this way.
|
|
|
|
|
|
|
|
// set flexes
|
2016-04-21 07:28:32 +03:00
|
|
|
nsIFrame* child = nsBox::GetChildXULBox(aBox);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
aFlexes = 0;
|
2012-07-30 18:20:58 +04:00
|
|
|
nsBoxSize* currentBox = nullptr;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2003-06-02 00:03:13 +04:00
|
|
|
#if 0
|
2000-04-18 04:17:00 +04:00
|
|
|
nsBoxSize* start = aBoxSizes;
|
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
while(child)
|
|
|
|
{
|
2000-04-18 04:17:00 +04:00
|
|
|
// ok if we started with a list move down the list
|
|
|
|
// until we reach the end. Then start looking at childen.
|
|
|
|
// This feature is used extensively for Grid.
|
2000-03-31 11:02:06 +04:00
|
|
|
nscoord flex = 0;
|
|
|
|
|
2000-04-18 04:17:00 +04:00
|
|
|
if (!start) {
|
|
|
|
if (!currentBox) {
|
|
|
|
aBoxSizes = new (aState) nsBoxSize();
|
|
|
|
currentBox = aBoxSizes;
|
|
|
|
} else {
|
|
|
|
currentBox->next = new (aState) nsBoxSize();
|
|
|
|
currentBox = currentBox->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-21 07:28:31 +03:00
|
|
|
flex = child->GetXULFlex();
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2000-04-18 04:17:00 +04:00
|
|
|
currentBox->flex = flex;
|
2016-04-21 07:28:32 +03:00
|
|
|
currentBox->collapsed = child->IsXULCollapsed();
|
2000-04-18 04:17:00 +04:00
|
|
|
} else {
|
|
|
|
flex = start->flex;
|
|
|
|
start = start->next;
|
|
|
|
}
|
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
if (flex > 0)
|
|
|
|
aFlexes++;
|
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
child = GetNextXULBox(child);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
2003-06-02 00:03:13 +04:00
|
|
|
#endif
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
// get pref, min, max
|
2016-04-21 07:28:32 +03:00
|
|
|
child = nsBox::GetChildXULBox(aBox);
|
2000-03-31 11:02:06 +04:00
|
|
|
currentBox = aBoxSizes;
|
2012-07-30 18:20:58 +04:00
|
|
|
nsBoxSize* last = nullptr;
|
2000-04-18 04:17:00 +04:00
|
|
|
|
2006-08-15 05:08:00 +04:00
|
|
|
nscoord maxFlex = 0;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t childCount = 0;
|
2006-08-15 05:08:00 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
while(child)
|
|
|
|
{
|
2007-12-21 20:59:35 +03:00
|
|
|
while (currentBox && currentBox->bogus) {
|
|
|
|
last = currentBox;
|
2007-06-21 14:25:06 +04:00
|
|
|
currentBox = currentBox->next;
|
2007-12-21 20:59:35 +03:00
|
|
|
}
|
2006-08-15 05:08:00 +04:00
|
|
|
++childCount;
|
2000-03-31 11:02:06 +04:00
|
|
|
nsSize pref(0,0);
|
2008-02-27 04:51:57 +03:00
|
|
|
nsSize minSize(0,0);
|
|
|
|
nsSize maxSize(NS_INTRINSICSIZE,NS_INTRINSICSIZE);
|
2000-05-17 00:46:08 +04:00
|
|
|
nscoord ascent = 0;
|
2016-04-21 07:28:32 +03:00
|
|
|
bool collapsed = child->IsXULCollapsed();
|
2000-04-18 04:17:00 +04:00
|
|
|
|
2000-05-17 00:46:08 +04:00
|
|
|
if (!collapsed) {
|
2000-04-18 04:17:00 +04:00
|
|
|
// only one flexible child? Cool we will just make its preferred size
|
|
|
|
// 0 then and not even have to ask for it.
|
|
|
|
//if (flexes != 1) {
|
2000-05-17 00:46:08 +04:00
|
|
|
|
2016-04-21 07:28:31 +03:00
|
|
|
pref = child->GetXULPrefSize(aState);
|
2016-04-21 07:28:31 +03:00
|
|
|
minSize = child->GetXULMinSize(aState);
|
2016-04-21 07:28:31 +03:00
|
|
|
maxSize = nsBox::BoundsCheckMinMax(minSize, child->GetXULMaxSize(aState));
|
2016-04-21 07:28:32 +03:00
|
|
|
ascent = child->GetXULBoxAscent(aState);
|
2000-05-17 00:46:08 +04:00
|
|
|
nsMargin margin;
|
2016-04-21 07:28:33 +03:00
|
|
|
child->GetXULMargin(margin);
|
2001-12-04 02:41:13 +03:00
|
|
|
ascent += margin.top;
|
2000-04-18 04:17:00 +04:00
|
|
|
//}
|
|
|
|
|
2008-02-27 04:51:57 +03:00
|
|
|
pref = nsBox::BoundsCheck(minSize, pref, maxSize);
|
2000-04-18 04:17:00 +04:00
|
|
|
|
2000-05-17 00:46:08 +04:00
|
|
|
AddMargin(child, pref);
|
2008-02-27 04:51:57 +03:00
|
|
|
AddMargin(child, minSize);
|
|
|
|
AddMargin(child, maxSize);
|
2000-05-17 00:46:08 +04:00
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2000-04-18 04:17:00 +04:00
|
|
|
if (!currentBox) {
|
|
|
|
// create one.
|
|
|
|
currentBox = new (aState) nsBoxSize();
|
|
|
|
if (!aBoxSizes) {
|
|
|
|
aBoxSizes = currentBox;
|
|
|
|
last = aBoxSizes;
|
2000-03-31 11:02:06 +04:00
|
|
|
} else {
|
2000-04-18 04:17:00 +04:00
|
|
|
last->next = currentBox;
|
|
|
|
last = currentBox;
|
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2000-04-18 04:17:00 +04:00
|
|
|
nscoord minWidth;
|
|
|
|
nscoord maxWidth;
|
|
|
|
nscoord prefWidth;
|
|
|
|
|
|
|
|
// get sizes from child
|
|
|
|
if (isHorizontal) {
|
2008-02-27 04:51:57 +03:00
|
|
|
minWidth = minSize.width;
|
|
|
|
maxWidth = maxSize.width;
|
2000-04-18 04:17:00 +04:00
|
|
|
prefWidth = pref.width;
|
|
|
|
} else {
|
2008-02-27 04:51:57 +03:00
|
|
|
minWidth = minSize.height;
|
|
|
|
maxWidth = maxSize.height;
|
2000-04-18 04:17:00 +04:00
|
|
|
prefWidth = pref.height;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2016-04-21 07:28:31 +03:00
|
|
|
nscoord flex = child->GetXULFlex();
|
2000-04-18 04:17:00 +04:00
|
|
|
|
2000-05-17 00:46:08 +04:00
|
|
|
// set them if you collapsed you are not flexible.
|
2006-08-15 05:08:00 +04:00
|
|
|
if (collapsed) {
|
|
|
|
currentBox->flex = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (flex > maxFlex) {
|
|
|
|
maxFlex = flex;
|
|
|
|
}
|
|
|
|
currentBox->flex = flex;
|
|
|
|
}
|
2000-05-17 00:46:08 +04:00
|
|
|
|
2005-11-21 01:05:24 +03:00
|
|
|
// we specified all our children are equal size;
|
2000-06-23 09:15:04 +04:00
|
|
|
if (frameState & NS_STATE_EQUAL_SIZE) {
|
2000-04-18 04:17:00 +04:00
|
|
|
|
2000-06-23 09:15:04 +04:00
|
|
|
if (prefWidth > biggestPrefWidth)
|
|
|
|
biggestPrefWidth = prefWidth;
|
|
|
|
|
|
|
|
if (minWidth > biggestMinWidth)
|
|
|
|
biggestMinWidth = minWidth;
|
|
|
|
|
|
|
|
if (maxWidth < smallestMaxWidth)
|
|
|
|
smallestMaxWidth = maxWidth;
|
|
|
|
} else { // not we can set our children right now.
|
|
|
|
currentBox->pref = prefWidth;
|
|
|
|
currentBox->min = minWidth;
|
|
|
|
currentBox->max = maxWidth;
|
|
|
|
}
|
2000-05-17 00:46:08 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
NS_ASSERTION(minWidth <= prefWidth && prefWidth <= maxWidth,"Bad min, pref, max widths!");
|
|
|
|
|
2000-04-18 04:17:00 +04:00
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2000-04-18 04:17:00 +04:00
|
|
|
if (!isHorizontal) {
|
2008-02-27 04:51:57 +03:00
|
|
|
if (minSize.width > aMinSize)
|
|
|
|
aMinSize = minSize.width;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2008-02-27 04:51:57 +03:00
|
|
|
if (maxSize.width < aMaxSize)
|
|
|
|
aMaxSize = maxSize.width;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2000-04-18 04:17:00 +04:00
|
|
|
} else {
|
2008-02-27 04:51:57 +03:00
|
|
|
if (minSize.height > aMinSize)
|
|
|
|
aMinSize = minSize.height;
|
2000-04-18 04:17:00 +04:00
|
|
|
|
2008-02-27 04:51:57 +03:00
|
|
|
if (maxSize.height < aMaxSize)
|
|
|
|
aMaxSize = maxSize.height;
|
2000-04-18 04:17:00 +04:00
|
|
|
}
|
|
|
|
|
2000-06-23 09:15:04 +04:00
|
|
|
currentBox->collapsed = collapsed;
|
2000-04-18 04:17:00 +04:00
|
|
|
aFlexes += currentBox->flex;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
child = nsBox::GetNextXULBox(child);
|
2000-04-18 04:17:00 +04:00
|
|
|
|
|
|
|
last = currentBox;
|
2000-03-31 11:02:06 +04:00
|
|
|
currentBox = currentBox->next;
|
2000-04-18 04:17:00 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
2000-06-23 09:15:04 +04:00
|
|
|
|
2006-08-15 05:08:00 +04:00
|
|
|
if (childCount > 0) {
|
|
|
|
nscoord maxAllowedFlex = nscoord_MAX / childCount;
|
|
|
|
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_UNLIKELY(maxFlex > maxAllowedFlex)) {
|
2006-08-15 05:08:00 +04:00
|
|
|
// clamp all the flexes
|
|
|
|
currentBox = aBoxSizes;
|
|
|
|
while (currentBox) {
|
2013-01-15 16:22:03 +04:00
|
|
|
currentBox->flex = std::min(currentBox->flex, maxAllowedFlex);
|
2006-08-15 05:08:00 +04:00
|
|
|
currentBox = currentBox->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(maxFlex == 0, "How did that happen?");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-11-21 01:05:24 +03:00
|
|
|
// we specified all our children are equal size;
|
2000-06-23 09:15:04 +04:00
|
|
|
if (frameState & NS_STATE_EQUAL_SIZE) {
|
2013-01-15 16:22:03 +04:00
|
|
|
smallestMaxWidth = std::max(smallestMaxWidth, biggestMinWidth);
|
2008-01-05 08:49:44 +03:00
|
|
|
biggestPrefWidth = nsBox::BoundsCheck(biggestMinWidth, biggestPrefWidth, smallestMaxWidth);
|
2007-06-04 00:46:59 +04:00
|
|
|
|
2000-06-23 09:15:04 +04:00
|
|
|
currentBox = aBoxSizes;
|
|
|
|
|
|
|
|
while(currentBox)
|
|
|
|
{
|
|
|
|
if (!currentBox->collapsed) {
|
|
|
|
currentBox->pref = biggestPrefWidth;
|
|
|
|
currentBox->min = biggestMinWidth;
|
|
|
|
currentBox->max = smallestMaxWidth;
|
|
|
|
} else {
|
|
|
|
currentBox->pref = 0;
|
|
|
|
currentBox->min = 0;
|
|
|
|
currentBox->max = 0;
|
|
|
|
}
|
|
|
|
currentBox = currentBox->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-06 07:00:57 +04:00
|
|
|
nsSprocketLayout::ComputeChildsNextPosition(nsIFrame* aBox,
|
2009-10-22 04:11:25 +04:00
|
|
|
const nscoord& aCurX,
|
|
|
|
const nscoord& aCurY,
|
2000-03-31 11:02:06 +04:00
|
|
|
nscoord& aNextX,
|
|
|
|
nscoord& aNextY,
|
2009-10-22 04:11:25 +04:00
|
|
|
const nsRect& aCurrentChildSize)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2009-10-22 04:11:25 +04:00
|
|
|
// Get the position along the box axis for the child.
|
|
|
|
// The out-of-axis position is not set.
|
2014-02-05 05:59:39 +04:00
|
|
|
nsFrameState frameState = nsFrameState(0);
|
2000-03-31 11:02:06 +04:00
|
|
|
GetFrameState(aBox, frameState);
|
|
|
|
|
2016-04-21 07:28:34 +03:00
|
|
|
if (IsXULHorizontal(aBox)) {
|
2009-10-22 04:11:25 +04:00
|
|
|
// horizontal box's children.
|
2001-08-15 08:09:41 +04:00
|
|
|
if (frameState & NS_STATE_IS_DIRECTION_NORMAL)
|
|
|
|
aNextX = aCurX + aCurrentChildSize.width;
|
2009-10-22 04:11:25 +04:00
|
|
|
else
|
|
|
|
aNextX = aCurX - aCurrentChildSize.width;
|
2001-08-15 08:09:41 +04:00
|
|
|
|
|
|
|
} else {
|
2009-10-22 04:11:25 +04:00
|
|
|
// vertical box's children.
|
2001-08-15 08:09:41 +04:00
|
|
|
if (frameState & NS_STATE_IS_DIRECTION_NORMAL)
|
|
|
|
aNextY = aCurY + aCurrentChildSize.height;
|
|
|
|
else
|
|
|
|
aNextY = aCurY - aCurrentChildSize.height;
|
2009-10-22 04:11:25 +04:00
|
|
|
}
|
|
|
|
}
|
2001-08-15 08:09:41 +04:00
|
|
|
|
2009-10-22 04:11:25 +04:00
|
|
|
void
|
2012-08-06 07:00:57 +04:00
|
|
|
nsSprocketLayout::AlignChildren(nsIFrame* aBox,
|
2012-10-17 01:30:37 +04:00
|
|
|
nsBoxLayoutState& aState)
|
2009-10-22 04:11:25 +04:00
|
|
|
{
|
2014-02-05 05:59:39 +04:00
|
|
|
nsFrameState frameState = nsFrameState(0);
|
2009-10-22 04:11:25 +04:00
|
|
|
GetFrameState(aBox, frameState);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isHorizontal = (frameState & NS_STATE_IS_HORIZONTAL) != 0;
|
2009-10-22 04:11:25 +04:00
|
|
|
nsRect clientRect;
|
2016-04-21 07:28:33 +03:00
|
|
|
aBox->GetXULClientRect(clientRect);
|
2009-10-22 04:11:25 +04:00
|
|
|
|
|
|
|
NS_PRECONDITION(!(frameState & NS_STATE_AUTO_STRETCH),
|
|
|
|
"Only AlignChildren() with non-stretch alignment");
|
|
|
|
|
|
|
|
// These are only calculated if needed
|
2012-08-06 07:00:57 +04:00
|
|
|
nsIFrame::Halignment halign;
|
|
|
|
nsIFrame::Valignment valign;
|
2016-10-13 15:33:07 +03:00
|
|
|
nscoord maxAscent = 0;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isLTR;
|
2009-10-22 04:11:25 +04:00
|
|
|
|
|
|
|
if (isHorizontal) {
|
2016-04-21 07:28:33 +03:00
|
|
|
valign = aBox->GetXULVAlign();
|
2009-10-22 04:11:25 +04:00
|
|
|
if (valign == nsBoxFrame::vAlign_BaseLine) {
|
2016-04-21 07:28:32 +03:00
|
|
|
maxAscent = aBox->GetXULBoxAscent(aState);
|
2009-10-22 04:11:25 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
isLTR = GetFrameDirection(aBox) == NS_STYLE_DIRECTION_LTR;
|
2016-04-21 07:28:33 +03:00
|
|
|
halign = aBox->GetXULHAlign();
|
2009-10-22 04:11:25 +04:00
|
|
|
}
|
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
nsIFrame* child = nsBox::GetChildXULBox(aBox);
|
2009-10-22 04:11:25 +04:00
|
|
|
while (child) {
|
|
|
|
|
|
|
|
nsMargin margin;
|
2016-04-21 07:28:33 +03:00
|
|
|
child->GetXULMargin(margin);
|
2009-10-22 04:11:25 +04:00
|
|
|
nsRect childRect = child->GetRect();
|
|
|
|
|
|
|
|
if (isHorizontal) {
|
|
|
|
const nscoord startAlign = clientRect.y + margin.top;
|
|
|
|
const nscoord endAlign =
|
|
|
|
clientRect.YMost() - margin.bottom - childRect.height;
|
|
|
|
|
2016-10-13 15:33:07 +03:00
|
|
|
nscoord y = 0;
|
2009-10-22 04:11:25 +04:00
|
|
|
switch (valign) {
|
|
|
|
case nsBoxFrame::vAlign_Top:
|
|
|
|
y = startAlign;
|
|
|
|
break;
|
|
|
|
case nsBoxFrame::vAlign_Middle:
|
|
|
|
// Should this center the border box?
|
|
|
|
// This centers the margin box, the historical behavior.
|
|
|
|
y = (startAlign + endAlign) / 2;
|
|
|
|
break;
|
|
|
|
case nsBoxFrame::vAlign_Bottom:
|
|
|
|
y = endAlign;
|
|
|
|
break;
|
|
|
|
case nsBoxFrame::vAlign_BaseLine:
|
|
|
|
// Alignments don't force the box to grow (only sizes do),
|
|
|
|
// so keep the children within the box.
|
2016-04-21 07:28:32 +03:00
|
|
|
y = maxAscent - child->GetXULBoxAscent(aState);
|
2013-01-15 16:22:03 +04:00
|
|
|
y = std::max(startAlign, y);
|
|
|
|
y = std::min(y, endAlign);
|
2009-10-22 04:11:25 +04:00
|
|
|
break;
|
2001-08-15 08:09:41 +04:00
|
|
|
}
|
2009-10-22 04:11:25 +04:00
|
|
|
|
|
|
|
childRect.y = y;
|
|
|
|
|
|
|
|
} else { // vertical box
|
|
|
|
const nscoord leftAlign = clientRect.x + margin.left;
|
|
|
|
const nscoord rightAlign =
|
|
|
|
clientRect.XMost() - margin.right - childRect.width;
|
|
|
|
|
2016-10-13 15:33:07 +03:00
|
|
|
nscoord x = 0;
|
2009-10-22 04:11:25 +04:00
|
|
|
switch (halign) {
|
|
|
|
case nsBoxFrame::hAlign_Left: // start
|
|
|
|
x = isLTR ? leftAlign : rightAlign;
|
|
|
|
break;
|
|
|
|
case nsBoxFrame::hAlign_Center:
|
|
|
|
x = (leftAlign + rightAlign) / 2;
|
|
|
|
break;
|
|
|
|
case nsBoxFrame::hAlign_Right: // end
|
|
|
|
x = isLTR ? rightAlign : leftAlign;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
childRect.x = x;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
2009-10-22 04:11:25 +04:00
|
|
|
|
|
|
|
if (childRect.TopLeft() != child->GetPosition()) {
|
2016-04-21 07:28:32 +03:00
|
|
|
child->SetXULBounds(aState, childRect);
|
2009-10-22 04:11:25 +04:00
|
|
|
}
|
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
child = nsBox::GetNextXULBox(child);
|
2001-08-15 08:09:41 +04:00
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-06 07:00:57 +04:00
|
|
|
nsSprocketLayout::ChildResized(nsIFrame* aBox,
|
2000-03-31 11:02:06 +04:00
|
|
|
nsBoxLayoutState& aState,
|
2012-08-06 07:00:57 +04:00
|
|
|
nsIFrame* aChild,
|
2000-03-31 11:02:06 +04:00
|
|
|
nsBoxSize* aChildBoxSize,
|
|
|
|
nsComputedBoxSize* aChildComputedSize,
|
|
|
|
nsBoxSize* aBoxSizes,
|
|
|
|
nsComputedBoxSize* aComputedBoxSizes,
|
|
|
|
const nsRect& aChildLayoutRect,
|
|
|
|
nsRect& aChildActualRect,
|
|
|
|
nsRect& aContainingRect,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aFlexes,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aFinished)
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
nsRect childCurrentRect(aChildLayoutRect);
|
|
|
|
|
2016-04-21 07:28:34 +03:00
|
|
|
bool isHorizontal = IsXULHorizontal(aBox);
|
2000-03-31 11:02:06 +04:00
|
|
|
nscoord childLayoutWidth = GET_WIDTH(aChildLayoutRect,isHorizontal);
|
|
|
|
nscoord& childActualWidth = GET_WIDTH(aChildActualRect,isHorizontal);
|
|
|
|
nscoord& containingWidth = GET_WIDTH(aContainingRect,isHorizontal);
|
|
|
|
|
2000-04-26 08:00:29 +04:00
|
|
|
//nscoord childLayoutHeight = GET_HEIGHT(aChildLayoutRect,isHorizontal);
|
2000-03-31 11:02:06 +04:00
|
|
|
nscoord& childActualHeight = GET_HEIGHT(aChildActualRect,isHorizontal);
|
|
|
|
nscoord& containingHeight = GET_HEIGHT(aContainingRect,isHorizontal);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool recompute = false;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
// if we are a horizontal box see if the child will fit inside us.
|
|
|
|
if ( childActualHeight > containingHeight) {
|
2005-11-21 01:05:24 +03:00
|
|
|
// if we are a horizontal box and the child is bigger than our height
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
// ok if the height changed then we need to reflow everyone but us at the new height
|
|
|
|
// so we will set the changed index to be us. And signal that we need a new pass.
|
|
|
|
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSize min = aChild->GetXULMinSize(aState);
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSize max = nsBox::BoundsCheckMinMax(min, aChild->GetXULMaxSize(aState));
|
2000-04-06 03:46:48 +04:00
|
|
|
AddMargin(aChild, max);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
if (isHorizontal)
|
|
|
|
childActualHeight = max.height < childActualHeight ? max.height : childActualHeight;
|
|
|
|
else
|
|
|
|
childActualHeight = max.width < childActualHeight ? max.width : childActualHeight;
|
|
|
|
|
|
|
|
// only set if it changes
|
|
|
|
if (childActualHeight > containingHeight) {
|
|
|
|
containingHeight = childActualHeight;
|
|
|
|
|
|
|
|
// remember we do not need to clear the resized list because changing the height of a horizontal box
|
|
|
|
// will not affect the width of any of its children because block flow left to right, top to bottom. Just trust me
|
|
|
|
// on this one.
|
2011-10-17 18:59:28 +04:00
|
|
|
aFinished = false;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
// only recompute if there are flexes.
|
|
|
|
if (aFlexes > 0) {
|
|
|
|
// relayout everything
|
2011-10-17 18:59:28 +04:00
|
|
|
recompute = true;
|
2000-03-31 11:02:06 +04:00
|
|
|
InvalidateComputedSizes(aComputedBoxSizes);
|
|
|
|
nsComputedBoxSize* node = aComputedBoxSizes;
|
|
|
|
|
|
|
|
while(node) {
|
2011-10-17 18:59:28 +04:00
|
|
|
node->resized = false;
|
2000-03-31 11:02:06 +04:00
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (childActualWidth > childLayoutWidth) {
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSize min = aChild->GetXULMinSize(aState);
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSize max = nsBox::BoundsCheckMinMax(min, aChild->GetXULMaxSize(aState));
|
2008-01-05 08:49:44 +03:00
|
|
|
|
2000-04-06 03:46:48 +04:00
|
|
|
AddMargin(aChild, max);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
// our width now becomes the new size
|
|
|
|
|
|
|
|
if (isHorizontal)
|
|
|
|
childActualWidth = max.width < childActualWidth ? max.width : childActualWidth;
|
|
|
|
else
|
|
|
|
childActualWidth = max.height < childActualWidth ? max.height : childActualWidth;
|
|
|
|
|
|
|
|
if (childActualWidth > childLayoutWidth) {
|
|
|
|
aChildComputedSize->size = childActualWidth;
|
|
|
|
aChildBoxSize->min = childActualWidth;
|
|
|
|
if (aChildBoxSize->pref < childActualWidth)
|
|
|
|
aChildBoxSize->pref = childActualWidth;
|
2007-11-16 00:49:08 +03:00
|
|
|
if (aChildBoxSize->max < childActualWidth)
|
|
|
|
aChildBoxSize->max = childActualWidth;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
// if we have flexible elements with us then reflex things. Otherwise we can skip doing it.
|
|
|
|
if (aFlexes > 0) {
|
|
|
|
InvalidateComputedSizes(aComputedBoxSizes);
|
|
|
|
|
|
|
|
nsComputedBoxSize* node = aComputedBoxSizes;
|
2011-10-17 18:59:28 +04:00
|
|
|
aChildComputedSize->resized = true;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
while(node) {
|
|
|
|
if (node->resized)
|
2011-10-17 18:59:28 +04:00
|
|
|
node->valid = true;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
recompute = true;
|
|
|
|
aFinished = false;
|
2000-03-31 11:02:06 +04:00
|
|
|
} else {
|
|
|
|
containingWidth += aChildComputedSize->size - childLayoutWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (recompute)
|
2000-04-03 07:55:38 +04:00
|
|
|
ComputeChildSizes(aBox, aState, containingWidth, aBoxSizes, aComputedBoxSizes);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2011-05-22 20:55:02 +04:00
|
|
|
if (!childCurrentRect.IsEqualInterior(aChildActualRect)) {
|
2000-04-26 11:28:19 +04:00
|
|
|
// the childRect includes the margin
|
|
|
|
// make sure we remove it before setting
|
|
|
|
// the bounds.
|
|
|
|
nsMargin margin(0,0,0,0);
|
2016-04-21 07:28:33 +03:00
|
|
|
aChild->GetXULMargin(margin);
|
2000-04-26 11:28:19 +04:00
|
|
|
nsRect rect(aChildActualRect);
|
2000-05-17 00:46:08 +04:00
|
|
|
if (rect.width >= margin.left + margin.right && rect.height >= margin.top + margin.bottom)
|
|
|
|
rect.Deflate(margin);
|
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
aChild->SetXULBounds(aState, rect);
|
2016-04-21 07:28:32 +03:00
|
|
|
aChild->XULLayout(aState);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSprocketLayout::InvalidateComputedSizes(nsComputedBoxSize* aComputedBoxSizes)
|
|
|
|
{
|
|
|
|
while(aComputedBoxSizes) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aComputedBoxSizes->valid = false;
|
2000-03-31 11:02:06 +04:00
|
|
|
aComputedBoxSizes = aComputedBoxSizes->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-06 07:00:57 +04:00
|
|
|
nsSprocketLayout::ComputeChildSizes(nsIFrame* aBox,
|
2000-04-03 07:55:38 +04:00
|
|
|
nsBoxLayoutState& aState,
|
2000-03-31 11:02:06 +04:00
|
|
|
nscoord& aGivenSize,
|
|
|
|
nsBoxSize* aBoxSizes,
|
2000-04-05 10:41:27 +04:00
|
|
|
nsComputedBoxSize*& aComputedBoxSizes)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2000-05-23 03:23:04 +04:00
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
//nscoord onePixel = aState.PresContext()->IntScaledPixelsToTwips(1);
|
2000-05-23 03:23:04 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t sizeRemaining = aGivenSize;
|
|
|
|
int32_t spacerConstantsRemaining = 0;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-09-19 01:47:32 +04:00
|
|
|
// ----- calculate the spacers constants and the size remaining -----
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2000-05-15 08:12:31 +04:00
|
|
|
if (!aComputedBoxSizes)
|
2000-04-06 03:46:48 +04:00
|
|
|
aComputedBoxSizes = new (aState) nsComputedBoxSize();
|
2000-04-05 10:41:27 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
nsBoxSize* boxSizes = aBoxSizes;
|
|
|
|
nsComputedBoxSize* computedBoxSizes = aComputedBoxSizes;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = 0;
|
|
|
|
int32_t validCount = 0;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2000-05-15 08:12:31 +04:00
|
|
|
while (boxSizes)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2000-04-05 10:41:27 +04:00
|
|
|
|
2000-05-15 08:12:31 +04:00
|
|
|
NS_ASSERTION((boxSizes->min <= boxSizes->pref && boxSizes->pref <= boxSizes->max),"bad pref, min, max size");
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2000-05-17 00:46:08 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
// ignore collapsed children
|
2000-05-17 00:46:08 +04:00
|
|
|
// if (boxSizes->collapsed)
|
|
|
|
// {
|
2011-10-17 18:59:28 +04:00
|
|
|
// computedBoxSizes->valid = true;
|
2000-05-17 00:46:08 +04:00
|
|
|
// computedBoxSizes->size = boxSizes->pref;
|
|
|
|
// validCount++;
|
|
|
|
// boxSizes->flex = 0;
|
|
|
|
// }// else {
|
|
|
|
|
2000-05-15 08:12:31 +04:00
|
|
|
if (computedBoxSizes->valid) {
|
2000-03-31 11:02:06 +04:00
|
|
|
sizeRemaining -= computedBoxSizes->size;
|
|
|
|
validCount++;
|
|
|
|
} else {
|
2000-05-15 08:12:31 +04:00
|
|
|
if (boxSizes->flex == 0)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
computedBoxSizes->valid = true;
|
2000-05-15 08:12:31 +04:00
|
|
|
computedBoxSizes->size = boxSizes->pref;
|
|
|
|
validCount++;
|
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-09-19 01:47:32 +04:00
|
|
|
spacerConstantsRemaining += boxSizes->flex;
|
2000-05-15 08:12:31 +04:00
|
|
|
sizeRemaining -= boxSizes->pref;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
2000-06-03 02:15:09 +04:00
|
|
|
|
|
|
|
sizeRemaining -= (boxSizes->left + boxSizes->right);
|
|
|
|
|
2000-05-17 00:46:08 +04:00
|
|
|
//}
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2000-04-05 10:41:27 +04:00
|
|
|
boxSizes = boxSizes->next;
|
|
|
|
|
2000-06-03 02:15:09 +04:00
|
|
|
if (boxSizes && !computedBoxSizes->next)
|
2000-04-06 03:46:48 +04:00
|
|
|
computedBoxSizes->next = new (aState) nsComputedBoxSize();
|
2000-04-05 10:41:27 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
computedBoxSizes = computedBoxSizes->next;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// everything accounted for?
|
|
|
|
if (validCount < count)
|
|
|
|
{
|
|
|
|
// ----- Ok we are give a size to fit into so stretch or squeeze to fit
|
|
|
|
// ----- Make sure we look at our min and max size
|
2011-09-29 10:19:26 +04:00
|
|
|
bool limit = true;
|
2011-10-17 18:59:28 +04:00
|
|
|
for (int pass=1; true == limit; pass++)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
limit = false;
|
2000-03-31 11:02:06 +04:00
|
|
|
boxSizes = aBoxSizes;
|
|
|
|
computedBoxSizes = aComputedBoxSizes;
|
|
|
|
|
2000-05-15 08:12:31 +04:00
|
|
|
while (boxSizes) {
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-09-19 01:47:32 +04:00
|
|
|
// ignore collapsed spacers
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2000-05-17 00:46:08 +04:00
|
|
|
// if (!boxSizes->collapsed) {
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
nscoord pref = 0;
|
|
|
|
nscoord max = NS_INTRINSICSIZE;
|
|
|
|
nscoord min = 0;
|
|
|
|
nscoord flex = 0;
|
|
|
|
|
2000-05-15 08:12:31 +04:00
|
|
|
pref = boxSizes->pref;
|
|
|
|
min = boxSizes->min;
|
|
|
|
max = boxSizes->max;
|
|
|
|
flex = boxSizes->flex;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
// ----- look at our min and max limits make sure we aren't too small or too big -----
|
2000-05-15 08:12:31 +04:00
|
|
|
if (!computedBoxSizes->valid) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t newSize = pref + int32_t(int64_t(sizeRemaining) * flex / spacerConstantsRemaining);
|
2000-05-23 03:23:04 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
if (newSize<=min) {
|
2000-05-15 08:12:31 +04:00
|
|
|
computedBoxSizes->size = min;
|
2011-10-17 18:59:28 +04:00
|
|
|
computedBoxSizes->valid = true;
|
2001-09-19 01:47:32 +04:00
|
|
|
spacerConstantsRemaining -= flex;
|
2000-03-31 11:02:06 +04:00
|
|
|
sizeRemaining += pref;
|
|
|
|
sizeRemaining -= min;
|
2011-10-17 18:59:28 +04:00
|
|
|
limit = true;
|
2000-03-31 11:02:06 +04:00
|
|
|
} else if (newSize>=max) {
|
2000-05-15 08:12:31 +04:00
|
|
|
computedBoxSizes->size = max;
|
2011-10-17 18:59:28 +04:00
|
|
|
computedBoxSizes->valid = true;
|
2001-09-19 01:47:32 +04:00
|
|
|
spacerConstantsRemaining -= flex;
|
2000-03-31 11:02:06 +04:00
|
|
|
sizeRemaining += pref;
|
|
|
|
sizeRemaining -= max;
|
2011-10-17 18:59:28 +04:00
|
|
|
limit = true;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
}
|
2000-05-17 00:46:08 +04:00
|
|
|
// }
|
2000-03-31 11:02:06 +04:00
|
|
|
boxSizes = boxSizes->next;
|
|
|
|
computedBoxSizes = computedBoxSizes->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---- once we have removed and min and max issues just stretch us out in the remaining space
|
2001-09-19 01:47:32 +04:00
|
|
|
// ---- or shrink us. Depends on the size remaining and the spacer constants
|
2000-03-31 11:02:06 +04:00
|
|
|
aGivenSize = 0;
|
|
|
|
boxSizes = aBoxSizes;
|
|
|
|
computedBoxSizes = aComputedBoxSizes;
|
|
|
|
|
2000-05-15 08:12:31 +04:00
|
|
|
while (boxSizes) {
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-09-19 01:47:32 +04:00
|
|
|
// ignore collapsed spacers
|
2000-05-17 00:46:08 +04:00
|
|
|
// if (!(boxSizes && boxSizes->collapsed)) {
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
nscoord pref = 0;
|
|
|
|
nscoord flex = 0;
|
2000-05-15 08:12:31 +04:00
|
|
|
pref = boxSizes->pref;
|
|
|
|
flex = boxSizes->flex;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2000-05-15 08:12:31 +04:00
|
|
|
if (!computedBoxSizes->valid) {
|
2012-08-22 19:56:38 +04:00
|
|
|
computedBoxSizes->size = pref + int32_t(int64_t(sizeRemaining) * flex / spacerConstantsRemaining);
|
2011-10-17 18:59:28 +04:00
|
|
|
computedBoxSizes->valid = true;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
2000-05-15 08:12:31 +04:00
|
|
|
|
2000-06-03 02:15:09 +04:00
|
|
|
aGivenSize += (boxSizes->left + boxSizes->right);
|
2000-05-15 08:12:31 +04:00
|
|
|
aGivenSize += computedBoxSizes->size;
|
2000-06-03 02:15:09 +04:00
|
|
|
|
2000-05-17 00:46:08 +04:00
|
|
|
// }
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
boxSizes = boxSizes->next;
|
|
|
|
computedBoxSizes = computedBoxSizes->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
nsSize
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSprocketLayout::GetXULPrefSize(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2008-01-09 10:28:39 +03:00
|
|
|
nsSize vpref (0, 0);
|
2016-04-21 07:28:34 +03:00
|
|
|
bool isHorizontal = IsXULHorizontal(aBox);
|
2000-06-23 09:15:04 +04:00
|
|
|
|
|
|
|
nscoord biggestPref = 0;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2007-02-22 21:05:14 +03:00
|
|
|
// run through all the children and get their min, max, and preferred sizes
|
2000-03-31 11:02:06 +04:00
|
|
|
// return us the size of the box
|
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
nsIFrame* child = nsBox::GetChildXULBox(aBox);
|
2014-02-05 05:59:39 +04:00
|
|
|
nsFrameState frameState = nsFrameState(0);
|
2000-06-23 09:15:04 +04:00
|
|
|
GetFrameState(aBox, frameState);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isEqual = !!(frameState & NS_STATE_EQUAL_SIZE);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = 0;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
while (child)
|
|
|
|
{
|
|
|
|
// ignore collapsed children
|
2016-04-21 07:28:32 +03:00
|
|
|
if (!child->IsXULCollapsed())
|
2000-06-23 09:15:04 +04:00
|
|
|
{
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSize pref = child->GetXULPrefSize(aState);
|
2000-03-31 11:02:06 +04:00
|
|
|
AddMargin(child, pref);
|
2000-06-23 09:15:04 +04:00
|
|
|
|
|
|
|
if (isEqual) {
|
|
|
|
if (isHorizontal)
|
|
|
|
{
|
|
|
|
if (pref.width > biggestPref)
|
|
|
|
biggestPref = pref.width;
|
|
|
|
} else {
|
|
|
|
if (pref.height > biggestPref)
|
|
|
|
biggestPref = pref.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
AddLargestSize(vpref, pref, isHorizontal);
|
2000-06-23 09:15:04 +04:00
|
|
|
count++;
|
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
child = nsBox::GetNextXULBox(child);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2000-06-23 09:15:04 +04:00
|
|
|
if (isEqual) {
|
|
|
|
if (isHorizontal)
|
2008-01-09 10:28:39 +03:00
|
|
|
vpref.width = biggestPref*count;
|
2000-06-23 09:15:04 +04:00
|
|
|
else
|
2008-01-09 10:28:39 +03:00
|
|
|
vpref.height = biggestPref*count;
|
2000-06-23 09:15:04 +04:00
|
|
|
}
|
|
|
|
|
2007-02-22 21:05:14 +03:00
|
|
|
// now add our border and padding
|
2008-01-09 10:28:39 +03:00
|
|
|
AddBorderAndPadding(aBox, vpref);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
return vpref;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
nsSize
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSprocketLayout::GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2008-01-09 10:28:39 +03:00
|
|
|
nsSize minSize (0, 0);
|
2016-04-21 07:28:34 +03:00
|
|
|
bool isHorizontal = IsXULHorizontal(aBox);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2000-06-23 09:15:04 +04:00
|
|
|
nscoord biggestMin = 0;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
|
2007-02-22 21:05:14 +03:00
|
|
|
// run through all the children and get their min, max, and preferred sizes
|
2000-03-31 11:02:06 +04:00
|
|
|
// return us the size of the box
|
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
nsIFrame* child = nsBox::GetChildXULBox(aBox);
|
2014-02-05 05:59:39 +04:00
|
|
|
nsFrameState frameState = nsFrameState(0);
|
2000-06-23 09:15:04 +04:00
|
|
|
GetFrameState(aBox, frameState);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isEqual = !!(frameState & NS_STATE_EQUAL_SIZE);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = 0;
|
2000-06-23 09:15:04 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
while (child)
|
|
|
|
{
|
|
|
|
// ignore collapsed children
|
2016-04-21 07:28:32 +03:00
|
|
|
if (!child->IsXULCollapsed())
|
2000-06-23 09:15:04 +04:00
|
|
|
{
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSize min = child->GetXULMinSize(aState);
|
2000-03-31 11:02:06 +04:00
|
|
|
nsSize pref(0,0);
|
|
|
|
|
|
|
|
// if the child is not flexible then
|
|
|
|
// its min size is its pref size.
|
2016-04-21 07:28:31 +03:00
|
|
|
if (child->GetXULFlex() == 0) {
|
2016-04-21 07:28:31 +03:00
|
|
|
pref = child->GetXULPrefSize(aState);
|
2000-03-31 11:02:06 +04:00
|
|
|
if (isHorizontal)
|
|
|
|
min.width = pref.width;
|
|
|
|
else
|
|
|
|
min.height = pref.height;
|
|
|
|
}
|
|
|
|
|
2000-06-23 09:15:04 +04:00
|
|
|
if (isEqual) {
|
|
|
|
if (isHorizontal)
|
|
|
|
{
|
|
|
|
if (min.width > biggestMin)
|
|
|
|
biggestMin = min.width;
|
|
|
|
} else {
|
|
|
|
if (min.height > biggestMin)
|
|
|
|
biggestMin = min.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
AddMargin(child, min);
|
2008-01-09 10:28:39 +03:00
|
|
|
AddLargestSize(minSize, min, isHorizontal);
|
2000-06-23 09:15:04 +04:00
|
|
|
count++;
|
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
child = nsBox::GetNextXULBox(child);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2000-06-23 09:15:04 +04:00
|
|
|
|
|
|
|
if (isEqual) {
|
|
|
|
if (isHorizontal)
|
2008-01-09 10:28:39 +03:00
|
|
|
minSize.width = biggestMin*count;
|
2000-06-23 09:15:04 +04:00
|
|
|
else
|
2008-01-09 10:28:39 +03:00
|
|
|
minSize.height = biggestMin*count;
|
2000-06-23 09:15:04 +04:00
|
|
|
}
|
|
|
|
|
2007-02-22 21:05:14 +03:00
|
|
|
// now add our border and padding
|
2008-01-09 10:28:39 +03:00
|
|
|
AddBorderAndPadding(aBox, minSize);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
return minSize;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
nsSize
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSprocketLayout::GetXULMaxSize(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
|
|
|
|
2016-04-21 07:28:34 +03:00
|
|
|
bool isHorizontal = IsXULHorizontal(aBox);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2000-06-23 09:15:04 +04:00
|
|
|
nscoord smallestMax = NS_INTRINSICSIZE;
|
2008-01-09 10:28:39 +03:00
|
|
|
nsSize maxSize (NS_INTRINSICSIZE, NS_INTRINSICSIZE);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2007-02-22 21:05:14 +03:00
|
|
|
// run through all the children and get their min, max, and preferred sizes
|
2000-03-31 11:02:06 +04:00
|
|
|
// return us the size of the box
|
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
nsIFrame* child = nsBox::GetChildXULBox(aBox);
|
2014-02-05 05:59:39 +04:00
|
|
|
nsFrameState frameState = nsFrameState(0);
|
2000-06-23 09:15:04 +04:00
|
|
|
GetFrameState(aBox, frameState);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isEqual = !!(frameState & NS_STATE_EQUAL_SIZE);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = 0;
|
2000-06-23 09:15:04 +04:00
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
while (child)
|
|
|
|
{
|
|
|
|
// ignore collapsed children
|
2016-04-21 07:28:32 +03:00
|
|
|
if (!child->IsXULCollapsed())
|
2000-06-23 09:15:04 +04:00
|
|
|
{
|
2000-03-31 11:02:06 +04:00
|
|
|
// if completely redefined don't even ask our child for its size.
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSize min = child->GetXULMinSize(aState);
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSize max = nsBox::BoundsCheckMinMax(min, child->GetXULMaxSize(aState));
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
AddMargin(child, max);
|
2008-01-09 10:28:39 +03:00
|
|
|
AddSmallestSize(maxSize, max, isHorizontal);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2000-06-23 09:15:04 +04:00
|
|
|
if (isEqual) {
|
|
|
|
if (isHorizontal)
|
|
|
|
{
|
|
|
|
if (max.width < smallestMax)
|
|
|
|
smallestMax = max.width;
|
|
|
|
} else {
|
|
|
|
if (max.height < smallestMax)
|
|
|
|
smallestMax = max.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
child = nsBox::GetNextXULBox(child);
|
2000-06-23 09:15:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isEqual) {
|
|
|
|
if (isHorizontal) {
|
|
|
|
if (smallestMax != NS_INTRINSICSIZE)
|
2008-01-09 10:28:39 +03:00
|
|
|
maxSize.width = smallestMax*count;
|
2000-06-23 09:15:04 +04:00
|
|
|
else
|
2008-01-09 10:28:39 +03:00
|
|
|
maxSize.width = NS_INTRINSICSIZE;
|
2000-06-23 09:15:04 +04:00
|
|
|
} else {
|
|
|
|
if (smallestMax != NS_INTRINSICSIZE)
|
2008-01-09 10:28:39 +03:00
|
|
|
maxSize.height = smallestMax*count;
|
2000-06-23 09:15:04 +04:00
|
|
|
else
|
2008-01-09 10:28:39 +03:00
|
|
|
maxSize.height = NS_INTRINSICSIZE;
|
2000-06-23 09:15:04 +04:00
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2007-02-22 21:05:14 +03:00
|
|
|
// now add our border and padding
|
2008-01-09 10:28:39 +03:00
|
|
|
AddBorderAndPadding(aBox, maxSize);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
return maxSize;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-09 10:28:39 +03:00
|
|
|
nscoord
|
2012-08-06 07:00:57 +04:00
|
|
|
nsSprocketLayout::GetAscent(nsIFrame* aBox, nsBoxLayoutState& aState)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2008-01-09 10:28:39 +03:00
|
|
|
nscoord vAscent = 0;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2016-04-21 07:28:34 +03:00
|
|
|
bool isHorizontal = IsXULHorizontal(aBox);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2007-02-22 21:05:14 +03:00
|
|
|
// run through all the children and get their min, max, and preferred sizes
|
2000-03-31 11:02:06 +04:00
|
|
|
// return us the size of the box
|
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
nsIFrame* child = nsBox::GetChildXULBox(aBox);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
while (child)
|
|
|
|
{
|
|
|
|
// ignore collapsed children
|
2016-04-21 07:28:32 +03:00
|
|
|
//if (!child->IsXULCollapsed())
|
2000-05-17 00:46:08 +04:00
|
|
|
//{
|
2000-03-31 11:02:06 +04:00
|
|
|
// if completely redefined don't even ask our child for its size.
|
2016-04-21 07:28:32 +03:00
|
|
|
nscoord ascent = child->GetXULBoxAscent(aState);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
nsMargin margin;
|
2016-04-21 07:28:33 +03:00
|
|
|
child->GetXULMargin(margin);
|
2001-12-04 02:41:13 +03:00
|
|
|
ascent += margin.top;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
if (isHorizontal)
|
|
|
|
{
|
2008-01-09 10:28:39 +03:00
|
|
|
if (ascent > vAscent)
|
|
|
|
vAscent = ascent;
|
2000-03-31 11:02:06 +04:00
|
|
|
} else {
|
2008-01-09 10:28:39 +03:00
|
|
|
if (vAscent == 0)
|
|
|
|
vAscent = ascent;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
2000-05-17 00:46:08 +04:00
|
|
|
//}
|
2007-02-22 21:05:14 +03:00
|
|
|
|
2016-04-21 07:28:32 +03:00
|
|
|
child = nsBox::GetNextXULBox(child);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2009-10-22 04:11:25 +04:00
|
|
|
nsMargin borderPadding;
|
2016-04-21 07:28:32 +03:00
|
|
|
aBox->GetXULBorderAndPadding(borderPadding);
|
2009-10-22 04:11:25 +04:00
|
|
|
|
|
|
|
return vAscent + borderPadding.top;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSprocketLayout::SetLargestSize(nsSize& aSize1, const nsSize& aSize2, bool aIsHorizontal)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
|
|
|
if (aIsHorizontal)
|
|
|
|
{
|
|
|
|
if (aSize1.height < aSize2.height)
|
|
|
|
aSize1.height = aSize2.height;
|
|
|
|
} else {
|
|
|
|
if (aSize1.width < aSize2.width)
|
|
|
|
aSize1.width = aSize2.width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSprocketLayout::SetSmallestSize(nsSize& aSize1, const nsSize& aSize2, bool aIsHorizontal)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
|
|
|
if (aIsHorizontal)
|
|
|
|
{
|
|
|
|
if (aSize1.height > aSize2.height)
|
|
|
|
aSize1.height = aSize2.height;
|
|
|
|
} else {
|
|
|
|
if (aSize1.width > aSize2.width)
|
|
|
|
aSize1.width = aSize2.width;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSprocketLayout::AddLargestSize(nsSize& aSize, const nsSize& aSizeToAdd, bool aIsHorizontal)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
|
|
|
if (aIsHorizontal)
|
|
|
|
AddCoord(aSize.width, aSizeToAdd.width);
|
|
|
|
else
|
|
|
|
AddCoord(aSize.height, aSizeToAdd.height);
|
|
|
|
|
|
|
|
SetLargestSize(aSize, aSizeToAdd, aIsHorizontal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSprocketLayout::AddCoord(nscoord& aCoord, nscoord aCoordToAdd)
|
|
|
|
{
|
|
|
|
if (aCoord != NS_INTRINSICSIZE)
|
|
|
|
{
|
|
|
|
if (aCoordToAdd == NS_INTRINSICSIZE)
|
|
|
|
aCoord = aCoordToAdd;
|
|
|
|
else
|
|
|
|
aCoord += aCoordToAdd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSprocketLayout::AddSmallestSize(nsSize& aSize, const nsSize& aSizeToAdd, bool aIsHorizontal)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
|
|
|
if (aIsHorizontal)
|
|
|
|
AddCoord(aSize.width, aSizeToAdd.width);
|
|
|
|
else
|
|
|
|
AddCoord(aSize.height, aSizeToAdd.height);
|
|
|
|
|
|
|
|
SetSmallestSize(aSize, aSizeToAdd, aIsHorizontal);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSprocketLayout::GetDefaultFlex(int32_t& aFlex)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
|
|
|
aFlex = 0;
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsComputedBoxSize::nsComputedBoxSize()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
resized = false;
|
|
|
|
valid = false;
|
2000-03-31 11:02:06 +04:00
|
|
|
size = 0;
|
2012-07-30 18:20:58 +04:00
|
|
|
next = nullptr;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsBoxSize::nsBoxSize()
|
|
|
|
{
|
|
|
|
pref = 0;
|
|
|
|
min = 0;
|
|
|
|
max = NS_INTRINSICSIZE;
|
2011-10-17 18:59:28 +04:00
|
|
|
collapsed = false;
|
2000-03-31 11:02:06 +04:00
|
|
|
left = 0;
|
|
|
|
right = 0;
|
|
|
|
flex = 0;
|
2012-07-30 18:20:58 +04:00
|
|
|
next = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
bogus = false;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void*
|
2002-07-03 00:25:30 +04:00
|
|
|
nsBoxSize::operator new(size_t sz, nsBoxLayoutState& aState) CPP_THROW_NEW
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2012-05-04 04:14:02 +04:00
|
|
|
return mozilla::AutoStackArena::Allocate(sz);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2000-04-06 03:46:48 +04:00
|
|
|
nsBoxSize::operator delete(void* aPtr, size_t sz)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void*
|
2002-07-03 00:25:30 +04:00
|
|
|
nsComputedBoxSize::operator new(size_t sz, nsBoxLayoutState& aState) CPP_THROW_NEW
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2012-05-04 04:14:02 +04:00
|
|
|
return mozilla::AutoStackArena::Allocate(sz);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-04-06 03:46:48 +04:00
|
|
|
nsComputedBoxSize::operator delete(void* aPtr, size_t sz)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
|
|
|
}
|