2017-10-27 17:33:53 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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 07:02:06 +00:00
|
|
|
|
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
#include "nsBox.h"
|
|
|
|
#include "nsBoxFrame.h"
|
2018-01-20 23:48:36 +00:00
|
|
|
#include "nsDOMAttributeMap.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2000-03-31 07:02:06 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIContent.h"
|
2011-12-27 20:18:48 +00:00
|
|
|
#include "nsContainerFrame.h"
|
2014-02-27 23:04:46 +00:00
|
|
|
#include "nsNameSpaceManager.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2001-12-17 22:51:39 +00:00
|
|
|
#include "nsITheme.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2011-07-11 14:05:10 +00:00
|
|
|
#include "nsBoxLayout.h"
|
2010-08-31 00:49:13 +00:00
|
|
|
#include "FrameLayerBuilder.h"
|
2018-01-20 23:48:36 +00:00
|
|
|
#include "mozilla/dom/Attr.h"
|
|
|
|
#include "mozilla/dom/Element.h"
|
2013-01-15 12:22:03 +00:00
|
|
|
#include <algorithm>
|
2010-08-31 00:49:13 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2016-04-21 04:28:34 +00:00
|
|
|
nsresult nsBox::BeginXULLayout(nsBoxLayoutState& aState) {
|
2004-09-28 18:37:50 +00:00
|
|
|
// mark ourselves as dirty so no child under us
|
|
|
|
// can post an incremental layout.
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
// XXXldb Is this still needed?
|
2017-08-24 11:09:42 +00:00
|
|
|
AddStateBits(NS_FRAME_HAS_DIRTY_CHILDREN);
|
2004-09-28 18:37:50 +00:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
if (GetStateBits() & NS_FRAME_IS_DIRTY) {
|
2016-07-21 10:36:35 +00:00
|
|
|
// If the parent is dirty, all the children are dirty (ReflowInput
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
// does this too).
|
|
|
|
nsIFrame* box;
|
2016-04-21 04:28:32 +00:00
|
|
|
for (box = GetChildXULBox(this); box; box = GetNextXULBox(box))
|
2019-07-01 21:56:43 +00:00
|
|
|
box->MarkSubtreeDirty();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 10:36:35 +00:00
|
|
|
// Another copy-over from ReflowInput.
|
2010-03-02 01:57:43 +00:00
|
|
|
// Since we are in reflow, we don't need to store these properties anymore.
|
2017-05-27 11:36:00 +00:00
|
|
|
DeleteProperty(UsedBorderProperty());
|
|
|
|
DeleteProperty(UsedPaddingProperty());
|
|
|
|
DeleteProperty(UsedMarginProperty());
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
|
2000-07-07 22:24:06 +00:00
|
|
|
return NS_OK;
|
2000-05-15 04:12:31 +00:00
|
|
|
}
|
|
|
|
|
2000-07-07 22:24:06 +00:00
|
|
|
NS_IMETHODIMP
|
2016-04-21 04:28:35 +00:00
|
|
|
nsBox::DoXULLayout(nsBoxLayoutState& aState) { return NS_OK; }
|
2000-07-07 22:24:06 +00:00
|
|
|
|
2016-04-21 04:28:35 +00:00
|
|
|
nsresult nsBox::EndXULLayout(nsBoxLayoutState& aState) {
|
2000-07-07 22:24:06 +00:00
|
|
|
return SyncLayout(aState);
|
2000-05-15 04:12:31 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 16:51:01 +00:00
|
|
|
bool nsBox::gGotTheme = false;
|
|
|
|
StaticRefPtr<nsITheme> nsBox::gTheme;
|
|
|
|
|
2019-02-05 16:45:54 +00:00
|
|
|
nsBox::nsBox(ComputedStyle* aStyle, nsPresContext* aPresContext, ClassID aID)
|
|
|
|
: nsIFrame(aStyle, aPresContext, aID) {
|
2002-12-11 02:33:33 +00:00
|
|
|
MOZ_COUNT_CTOR(nsBox);
|
2019-09-13 16:51:01 +00:00
|
|
|
if (!gGotTheme) {
|
|
|
|
gTheme = do_GetNativeTheme();
|
|
|
|
if (gTheme) {
|
|
|
|
gGotTheme = true;
|
|
|
|
}
|
|
|
|
}
|
2001-12-17 22:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsBox::~nsBox() {
|
2002-12-11 02:33:33 +00:00
|
|
|
// NOTE: This currently doesn't get called for |nsBoxToBlockAdaptor|
|
|
|
|
// objects, so don't rely on putting anything here.
|
|
|
|
MOZ_COUNT_DTOR(nsBox);
|
|
|
|
}
|
|
|
|
|
2019-09-13 16:51:01 +00:00
|
|
|
/* static */
|
|
|
|
void nsBox::Shutdown() {
|
|
|
|
gGotTheme = false;
|
|
|
|
gTheme = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:34 +00:00
|
|
|
nsresult nsBox::XULRelayoutChildAtOrdinal(nsIFrame* aChild) { return NS_OK; }
|
2001-09-25 22:17:00 +00:00
|
|
|
|
2016-04-21 04:28:33 +00:00
|
|
|
nsresult nsIFrame::GetXULClientRect(nsRect& aClientRect) {
|
2007-01-31 16:02:42 +00:00
|
|
|
aClientRect = mRect;
|
|
|
|
aClientRect.MoveTo(0, 0);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
nsMargin borderPadding;
|
2016-04-21 04:28:32 +00:00
|
|
|
GetXULBorderAndPadding(borderPadding);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
aClientRect.Deflate(borderPadding);
|
|
|
|
|
|
|
|
if (aClientRect.width < 0) aClientRect.width = 0;
|
|
|
|
|
|
|
|
if (aClientRect.height < 0) aClientRect.height = 0;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:32 +00:00
|
|
|
void nsBox::SetXULBounds(nsBoxLayoutState& aState, const nsRect& aRect,
|
|
|
|
bool aRemoveOverflowAreas) {
|
2004-09-28 18:37:50 +00:00
|
|
|
nsRect rect(mRect);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2019-08-08 19:48:19 +00:00
|
|
|
ReflowChildFlags flags = GetXULLayoutFlags() | aState.LayoutFlags();
|
2000-04-25 07:10:48 +00:00
|
|
|
|
2019-08-08 19:48:19 +00:00
|
|
|
if ((flags & ReflowChildFlags::NoMoveFrame) ==
|
|
|
|
ReflowChildFlags::NoMoveFrame) {
|
2013-08-14 12:27:20 +00:00
|
|
|
SetSize(aRect.Size());
|
2019-08-08 19:48:19 +00:00
|
|
|
} else {
|
2004-09-28 18:37:50 +00:00
|
|
|
SetRect(aRect);
|
2019-08-08 19:48:19 +00:00
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2004-07-16 16:56:21 +00:00
|
|
|
// Nuke the overflow area. The caller is responsible for restoring
|
|
|
|
// it if necessary.
|
2010-10-07 04:25:47 +00:00
|
|
|
if (aRemoveOverflowAreas) {
|
2004-09-28 18:37:50 +00:00
|
|
|
// remove the previously stored overflow area
|
2010-10-07 04:25:47 +00:00
|
|
|
ClearOverflowRects();
|
2004-07-16 16:56:21 +00:00
|
|
|
}
|
|
|
|
|
2019-08-08 19:48:19 +00:00
|
|
|
if (!(flags & ReflowChildFlags::NoMoveView)) {
|
2004-12-27 15:05:18 +00:00
|
|
|
nsContainerFrame::PositionFrameView(this);
|
2001-09-21 00:53:29 +00:00
|
|
|
if ((rect.x != aRect.x) || (rect.y != aRect.y))
|
2004-12-27 15:05:18 +00:00
|
|
|
nsContainerFrame::PositionChildViews(this);
|
2000-04-25 07:10:48 +00:00
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:32 +00:00
|
|
|
nsresult nsIFrame::GetXULBorderAndPadding(nsMargin& aBorderAndPadding) {
|
2004-09-28 18:37:50 +00:00
|
|
|
aBorderAndPadding.SizeTo(0, 0, 0, 0);
|
2016-04-21 04:28:33 +00:00
|
|
|
nsresult rv = GetXULBorder(aBorderAndPadding);
|
2001-01-20 22:46:54 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-01-25 02:58:12 +00:00
|
|
|
nsMargin padding;
|
2016-04-21 04:28:33 +00:00
|
|
|
rv = GetXULPadding(padding);
|
2001-02-07 09:57:26 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
aBorderAndPadding += padding;
|
|
|
|
|
2000-04-25 07:10:48 +00:00
|
|
|
return rv;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:33 +00:00
|
|
|
nsresult nsBox::GetXULBorder(nsMargin& aMargin) {
|
2001-12-17 22:51:39 +00:00
|
|
|
aMargin.SizeTo(0, 0, 0, 0);
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2013-02-16 21:51:02 +00:00
|
|
|
const nsStyleDisplay* disp = StyleDisplay();
|
2019-09-13 16:51:01 +00:00
|
|
|
if (disp->HasAppearance() && gTheme) {
|
|
|
|
// Go to the theme for the border.
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext* context = PresContext();
|
2019-09-13 16:51:01 +00:00
|
|
|
if (gTheme->ThemeSupportsWidget(context, this, disp->mAppearance)) {
|
|
|
|
LayoutDeviceIntMargin margin = gTheme->GetWidgetBorder(
|
|
|
|
context->DeviceContext(), this, disp->mAppearance);
|
|
|
|
aMargin =
|
|
|
|
LayoutDevicePixel::ToAppUnits(margin, context->AppUnitsPerDevPixel());
|
|
|
|
return NS_OK;
|
2001-12-17 22:51:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-16 21:51:02 +00:00
|
|
|
aMargin = StyleBorder()->GetComputedBorder();
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2003-05-15 03:42:21 +00:00
|
|
|
return NS_OK;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2018-05-17 15:30:35 +00:00
|
|
|
nsresult nsBox::GetXULPadding(nsMargin& aPadding) {
|
2013-02-16 21:51:02 +00:00
|
|
|
const nsStyleDisplay* disp = StyleDisplay();
|
2019-09-13 16:51:01 +00:00
|
|
|
if (disp->HasAppearance() && gTheme) {
|
|
|
|
// Go to the theme for the padding.
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext* context = PresContext();
|
2019-09-13 16:51:01 +00:00
|
|
|
if (gTheme->ThemeSupportsWidget(context, this, disp->mAppearance)) {
|
|
|
|
LayoutDeviceIntMargin padding;
|
|
|
|
bool useThemePadding = gTheme->GetWidgetPadding(
|
|
|
|
context->DeviceContext(), this, disp->mAppearance, &padding);
|
|
|
|
if (useThemePadding) {
|
|
|
|
aPadding = LayoutDevicePixel::ToAppUnits(
|
|
|
|
padding, context->AppUnitsPerDevPixel());
|
|
|
|
return NS_OK;
|
2004-09-06 03:59:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 15:30:35 +00:00
|
|
|
aPadding.SizeTo(0, 0, 0, 0);
|
|
|
|
StylePadding()->GetPadding(aPadding);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2003-05-15 03:42:21 +00:00
|
|
|
return NS_OK;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:33 +00:00
|
|
|
nsresult nsBox::GetXULMargin(nsMargin& aMargin) {
|
2000-03-31 07:02:06 +00:00
|
|
|
aMargin.SizeTo(0, 0, 0, 0);
|
2013-02-16 21:51:02 +00:00
|
|
|
StyleMargin()->GetMargin(aMargin);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsBox::SizeNeedsRecalc(nsSize& aSize) {
|
|
|
|
aSize.width = -1;
|
|
|
|
aSize.height = -1;
|
|
|
|
}
|
|
|
|
|
2010-04-03 11:36:19 +00:00
|
|
|
void nsBox::CoordNeedsRecalc(nscoord& aFlex) { aFlex = -1; }
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
bool nsBox::DoesNeedRecalc(const nsSize& aSize) {
|
|
|
|
return (aSize.width == -1 || aSize.height == -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsBox::DoesNeedRecalc(nscoord aCoord) { return (aCoord == -1); }
|
|
|
|
|
2016-04-21 04:28:31 +00:00
|
|
|
nsSize nsBox::GetXULPrefSize(nsBoxLayoutState& aState) {
|
2007-04-29 22:24:59 +00:00
|
|
|
NS_ASSERTION(aState.GetRenderingContext(), "must have rendering context");
|
|
|
|
|
2007-01-08 02:57:59 +00:00
|
|
|
nsSize pref(0, 0);
|
|
|
|
DISPLAY_PREF_SIZE(this, pref);
|
2000-05-16 20:46:08 +00:00
|
|
|
|
2016-04-21 04:28:32 +00:00
|
|
|
if (IsXULCollapsed()) return pref;
|
2004-06-15 01:10:09 +00:00
|
|
|
|
2007-01-08 02:57:59 +00:00
|
|
|
AddBorderAndPadding(pref);
|
2011-09-29 06:19:26 +00:00
|
|
|
bool widthSet, heightSet;
|
2016-04-21 04:28:34 +00:00
|
|
|
nsIFrame::AddXULPrefSize(this, pref, widthSet, heightSet);
|
2004-06-15 01:10:09 +00:00
|
|
|
|
2016-04-21 04:28:31 +00:00
|
|
|
nsSize minSize = GetXULMinSize(aState);
|
2016-04-21 04:28:31 +00:00
|
|
|
nsSize maxSize = GetXULMaxSize(aState);
|
2008-01-05 05:49:44 +00:00
|
|
|
return BoundsCheck(minSize, pref, maxSize);
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:31 +00:00
|
|
|
nsSize nsBox::GetXULMinSize(nsBoxLayoutState& aState) {
|
2007-04-29 22:24:59 +00:00
|
|
|
NS_ASSERTION(aState.GetRenderingContext(), "must have rendering context");
|
|
|
|
|
2007-01-08 02:57:59 +00:00
|
|
|
nsSize min(0, 0);
|
|
|
|
DISPLAY_MIN_SIZE(this, min);
|
2000-05-16 20:46:08 +00:00
|
|
|
|
2016-04-21 04:28:32 +00:00
|
|
|
if (IsXULCollapsed()) return min;
|
2000-05-16 20:46:08 +00:00
|
|
|
|
2007-01-08 02:57:59 +00:00
|
|
|
AddBorderAndPadding(min);
|
2011-09-29 06:19:26 +00:00
|
|
|
bool widthSet, heightSet;
|
2016-04-21 04:28:34 +00:00
|
|
|
nsIFrame::AddXULMinSize(aState, this, min, widthSet, heightSet);
|
2007-01-08 02:57:59 +00:00
|
|
|
return min;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:31 +00:00
|
|
|
nsSize nsBox::GetXULMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) {
|
2004-11-03 02:52:16 +00:00
|
|
|
return nsSize(0, 0);
|
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:31 +00:00
|
|
|
nsSize nsBox::GetXULMaxSize(nsBoxLayoutState& aState) {
|
2007-04-29 22:24:59 +00:00
|
|
|
NS_ASSERTION(aState.GetRenderingContext(), "must have rendering context");
|
|
|
|
|
2019-06-04 23:41:20 +00:00
|
|
|
nsSize maxSize(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
2008-02-27 01:51:57 +00:00
|
|
|
DISPLAY_MAX_SIZE(this, maxSize);
|
2000-05-16 20:46:08 +00:00
|
|
|
|
2016-04-21 04:28:32 +00:00
|
|
|
if (IsXULCollapsed()) return maxSize;
|
2000-05-16 20:46:08 +00:00
|
|
|
|
2008-02-27 01:51:57 +00:00
|
|
|
AddBorderAndPadding(maxSize);
|
2011-09-29 06:19:26 +00:00
|
|
|
bool widthSet, heightSet;
|
2016-04-21 04:28:34 +00:00
|
|
|
nsIFrame::AddXULMaxSize(this, maxSize, widthSet, heightSet);
|
2008-02-27 01:51:57 +00:00
|
|
|
return maxSize;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:31 +00:00
|
|
|
nscoord nsBox::GetXULFlex() {
|
2007-01-31 16:02:42 +00:00
|
|
|
nscoord flex = 0;
|
2000-05-16 20:46:08 +00:00
|
|
|
|
2016-04-21 04:28:34 +00:00
|
|
|
nsIFrame::AddXULFlex(this, flex);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2007-01-31 16:02:42 +00:00
|
|
|
return flex;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-21 18:35:31 +00:00
|
|
|
int32_t nsIFrame::GetXULOrdinal() {
|
|
|
|
int32_t ordinal = StyleXUL()->mBoxOrdinal;
|
2010-03-18 19:58:15 +00:00
|
|
|
|
2011-04-20 04:22:39 +00:00
|
|
|
// When present, attribute value overrides CSS.
|
2010-03-18 19:58:15 +00:00
|
|
|
nsIContent* content = GetContent();
|
2015-03-03 11:08:59 +00:00
|
|
|
if (content && content->IsXULElement()) {
|
2012-07-27 13:59:29 +00:00
|
|
|
nsresult error;
|
2010-03-18 19:58:15 +00:00
|
|
|
nsAutoString value;
|
|
|
|
|
2017-12-07 18:13:50 +00:00
|
|
|
content->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::ordinal, value);
|
2010-03-18 19:58:15 +00:00
|
|
|
if (!value.IsEmpty()) {
|
|
|
|
ordinal = value.ToInteger(&error);
|
|
|
|
}
|
|
|
|
}
|
2001-09-25 22:17:00 +00:00
|
|
|
|
2007-01-31 16:02:42 +00:00
|
|
|
return ordinal;
|
2001-09-25 22:17:00 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:32 +00:00
|
|
|
nscoord nsBox::GetXULBoxAscent(nsBoxLayoutState& aState) {
|
2016-04-21 04:28:32 +00:00
|
|
|
if (IsXULCollapsed()) return 0;
|
2000-05-16 20:46:08 +00:00
|
|
|
|
2016-04-21 04:28:31 +00:00
|
|
|
return GetXULPrefSize(aState).height;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:32 +00:00
|
|
|
bool nsBox::IsXULCollapsed() {
|
2013-02-16 21:51:02 +00:00
|
|
|
return StyleVisibility()->mVisible == NS_STYLE_VISIBILITY_COLLAPSE;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:32 +00:00
|
|
|
nsresult nsIFrame::XULLayout(nsBoxLayoutState& aState) {
|
2007-04-29 22:24:59 +00:00
|
|
|
NS_ASSERTION(aState.GetRenderingContext(), "must have rendering context");
|
|
|
|
|
2007-07-08 07:08:04 +00:00
|
|
|
nsBox* box = static_cast<nsBox*>(this);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
DISPLAY_LAYOUT(box);
|
|
|
|
|
2016-04-21 04:28:34 +00:00
|
|
|
box->BeginXULLayout(aState);
|
2000-05-15 04:12:31 +00:00
|
|
|
|
2016-04-21 04:28:35 +00:00
|
|
|
box->DoXULLayout(aState);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2016-04-21 04:28:35 +00:00
|
|
|
box->EndXULLayout(aState);
|
2000-05-15 04:12:31 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-11 22:03:23 +00:00
|
|
|
bool nsBox::DoesClipChildren() {
|
2013-02-16 21:51:02 +00:00
|
|
|
const nsStyleDisplay* display = StyleDisplay();
|
2018-12-11 00:50:32 +00:00
|
|
|
NS_ASSERTION(
|
|
|
|
(display->mOverflowY == StyleOverflow::MozHiddenUnscrollable) ==
|
|
|
|
(display->mOverflowX == StyleOverflow::MozHiddenUnscrollable),
|
|
|
|
"If one overflow is -moz-hidden-unscrollable, the other should be too");
|
|
|
|
return display->mOverflowX == StyleOverflow::MozHiddenUnscrollable;
|
2005-04-11 22:03:23 +00:00
|
|
|
}
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
nsresult nsBox::SyncLayout(nsBoxLayoutState& aState) {
|
|
|
|
/*
|
2016-04-21 04:28:32 +00:00
|
|
|
if (IsXULCollapsed()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
CollapseChild(aState, this, true);
|
2000-03-31 07:02:06 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
*/
|
2017-07-06 12:00:35 +00:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
if (GetStateBits() & NS_FRAME_IS_DIRTY) XULRedraw(aState);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2004-09-28 18:37:50 +00:00
|
|
|
RemoveStateBits(NS_FRAME_HAS_DIRTY_CHILDREN | NS_FRAME_IS_DIRTY |
|
|
|
|
NS_FRAME_FIRST_REFLOW | NS_FRAME_IN_REFLOW);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext* presContext = aState.PresContext();
|
2000-04-25 07:10:48 +00:00
|
|
|
|
2019-08-08 19:48:19 +00:00
|
|
|
ReflowChildFlags flags = GetXULLayoutFlags() | aState.LayoutFlags();
|
2000-04-25 07:10:48 +00:00
|
|
|
|
2010-10-07 04:25:46 +00:00
|
|
|
nsRect visualOverflow;
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2004-07-16 16:56:21 +00:00
|
|
|
if (ComputesOwnOverflowArea()) {
|
2010-10-07 04:25:46 +00:00
|
|
|
visualOverflow = GetVisualOverflowRect();
|
2008-02-20 07:08:55 +00:00
|
|
|
} else {
|
2010-10-07 04:25:46 +00:00
|
|
|
nsRect rect(nsPoint(0, 0), GetSize());
|
|
|
|
nsOverflowAreas overflowAreas(rect, rect);
|
2016-04-21 04:28:32 +00:00
|
|
|
if (!DoesClipChildren() && !IsXULCollapsed()) {
|
2004-07-16 16:56:21 +00:00
|
|
|
// See if our child frames caused us to overflow after being laid
|
|
|
|
// out. If so, store the overflow area. This normally can't happen
|
|
|
|
// in XUL, but it can happen with the CSS 'outline' property and
|
|
|
|
// possibly with other exotic stuff (e.g. relatively positioned
|
|
|
|
// frames in HTML inside XUL).
|
2011-06-15 21:03:49 +00:00
|
|
|
nsLayoutUtils::UnionChildOverflow(this, overflowAreas);
|
2004-07-15 18:57:47 +00:00
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2010-10-07 04:25:46 +00:00
|
|
|
FinishAndStoreOverflow(overflowAreas, GetSize());
|
|
|
|
visualOverflow = overflowAreas.VisualOverflow();
|
2004-07-16 16:56:21 +00:00
|
|
|
}
|
|
|
|
|
2013-01-03 13:23:11 +00:00
|
|
|
nsView* view = GetView();
|
2000-03-31 07:02:06 +00:00
|
|
|
if (view) {
|
|
|
|
// Make sure the frame's view is properly sized and positioned and has
|
|
|
|
// things like opacity correct
|
2011-12-27 20:18:48 +00:00
|
|
|
nsContainerFrame::SyncFrameViewAfterReflow(presContext, this, view,
|
|
|
|
visualOverflow, flags);
|
2017-07-06 12:00:35 +00:00
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:34 +00:00
|
|
|
nsresult nsIFrame::XULRedraw(nsBoxLayoutState& aState) {
|
2004-06-22 02:55:04 +00:00
|
|
|
if (aState.PaintingDisabled()) return NS_OK;
|
2000-10-07 00:49:08 +00:00
|
|
|
|
2010-08-31 00:49:13 +00:00
|
|
|
// nsStackLayout, at least, expects us to repaint descendants even
|
|
|
|
// if a damage rect is provided
|
2012-08-29 05:39:31 +00:00
|
|
|
InvalidateFrameSubtree();
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:34 +00:00
|
|
|
bool nsIFrame::AddXULPrefSize(nsIFrame* aBox, nsSize& aSize, bool& aWidthSet,
|
|
|
|
bool& aHeightSet) {
|
2011-10-17 14:59:28 +00:00
|
|
|
aWidthSet = false;
|
|
|
|
aHeightSet = false;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
// add in the css min, max, pref
|
2013-02-16 21:51:02 +00:00
|
|
|
const nsStylePosition* position = aBox->StylePosition();
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
// see if the width or height was specifically set
|
2007-05-09 08:48:38 +00:00
|
|
|
// XXX Handle eStyleUnit_Enumerated?
|
2007-05-03 23:11:00 +00:00
|
|
|
// (Handling the eStyleUnit_Enumerated types requires
|
2016-04-21 04:28:31 +00:00
|
|
|
// GetXULPrefSize/GetXULMinSize methods that don't consider
|
2008-07-17 23:37:12 +00:00
|
|
|
// (min-/max-/)(width/height) properties.)
|
2019-02-10 12:55:16 +00:00
|
|
|
const auto& width = position->mWidth;
|
|
|
|
if (width.ConvertsToLength()) {
|
|
|
|
aSize.width = std::max(0, width.ToLength());
|
2011-10-17 14:59:28 +00:00
|
|
|
aWidthSet = true;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2019-02-10 12:55:16 +00:00
|
|
|
const auto& height = position->mHeight;
|
|
|
|
if (height.ConvertsToLength()) {
|
|
|
|
aSize.height = std::max(0, height.ToLength());
|
2011-10-17 14:59:28 +00:00
|
|
|
aHeightSet = true;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2010-08-25 10:17:55 +00:00
|
|
|
nsIContent* content = aBox->GetContent();
|
|
|
|
// ignore 'height' and 'width' attributes if the actual element is not XUL
|
|
|
|
// For example, we might be magic XUL frames whose primary content is an HTML
|
2003-05-19 23:24:51 +00:00
|
|
|
// <select>
|
2015-03-03 11:08:59 +00:00
|
|
|
if (content && content->IsXULElement()) {
|
2010-08-25 10:17:55 +00:00
|
|
|
nsAutoString value;
|
|
|
|
nsresult error;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2010-08-25 10:17:55 +00:00
|
|
|
content->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::width, value);
|
2017-11-20 05:30:27 +00:00
|
|
|
if (!value.IsEmpty()) {
|
2000-03-31 07:02:06 +00:00
|
|
|
value.Trim("%");
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2017-11-20 05:30:27 +00:00
|
|
|
aSize.width = nsPresContext::CSSPixelsToAppUnits(value.ToInteger(&error));
|
2011-10-17 14:59:28 +00:00
|
|
|
aWidthSet = true;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
2010-08-25 10:17:55 +00:00
|
|
|
|
2017-12-07 18:13:50 +00:00
|
|
|
content->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::height, value);
|
2005-10-28 11:25:24 +00:00
|
|
|
if (!value.IsEmpty()) {
|
2000-03-31 07:02:06 +00:00
|
|
|
value.Trim("%");
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2007-02-07 07:46:44 +00:00
|
|
|
aSize.height =
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(value.ToInteger(&error));
|
2011-10-17 14:59:28 +00:00
|
|
|
aHeightSet = true;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2010-03-18 19:58:15 +00:00
|
|
|
return (aWidthSet && aHeightSet);
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 18:50:33 +00:00
|
|
|
// This returns the scrollbar width we want to use when either native
|
|
|
|
// theme is disabled, or the native theme claims that it doesn't support
|
|
|
|
// scrollbar.
|
|
|
|
static nscoord GetScrollbarWidthNoTheme(nsIFrame* aBox) {
|
|
|
|
ComputedStyle* scrollbarStyle = nsLayoutUtils::StyleForScrollbar(aBox);
|
|
|
|
switch (scrollbarStyle->StyleUIReset()->mScrollbarWidth) {
|
|
|
|
default:
|
|
|
|
case StyleScrollbarWidth::Auto:
|
2018-08-24 07:40:07 +00:00
|
|
|
return 12 * AppUnitsPerCSSPixel();
|
2018-08-20 18:50:33 +00:00
|
|
|
case StyleScrollbarWidth::Thin:
|
2018-08-24 07:40:07 +00:00
|
|
|
return 6 * AppUnitsPerCSSPixel();
|
2018-08-20 18:50:33 +00:00
|
|
|
case StyleScrollbarWidth::None:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2016-04-21 04:28:34 +00:00
|
|
|
bool nsIFrame::AddXULMinSize(nsBoxLayoutState& aState, nsIFrame* aBox,
|
2011-09-29 06:19:26 +00:00
|
|
|
nsSize& aSize, bool& aWidthSet, bool& aHeightSet) {
|
2011-10-17 14:59:28 +00:00
|
|
|
aWidthSet = false;
|
|
|
|
aHeightSet = false;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool canOverride = true;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2001-12-17 22:51:39 +00:00
|
|
|
// See if a native theme wants to supply a minimum size.
|
2013-02-16 21:51:02 +00:00
|
|
|
const nsStyleDisplay* display = aBox->StyleDisplay();
|
2018-07-25 13:03:45 +00:00
|
|
|
if (display->HasAppearance()) {
|
2004-07-29 19:41:39 +00:00
|
|
|
nsITheme* theme = aState.PresContext()->GetTheme();
|
2017-05-21 09:15:00 +00:00
|
|
|
if (theme && theme->ThemeSupportsWidget(aState.PresContext(), aBox,
|
|
|
|
display->mAppearance)) {
|
2015-03-30 15:36:14 +00:00
|
|
|
LayoutDeviceIntSize size;
|
2014-06-27 09:19:00 +00:00
|
|
|
theme->GetMinimumWidgetSize(aState.PresContext(), aBox,
|
2017-05-21 09:15:00 +00:00
|
|
|
display->mAppearance, &size, &canOverride);
|
2014-06-27 09:19:00 +00:00
|
|
|
if (size.width) {
|
|
|
|
aSize.width = aState.PresContext()->DevPixelsToAppUnits(size.width);
|
2011-10-17 14:59:28 +00:00
|
|
|
aWidthSet = true;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2014-06-27 09:19:00 +00:00
|
|
|
if (size.height) {
|
|
|
|
aSize.height = aState.PresContext()->DevPixelsToAppUnits(size.height);
|
2011-10-17 14:59:28 +00:00
|
|
|
aHeightSet = true;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-08-20 18:50:33 +00:00
|
|
|
switch (display->mAppearance) {
|
|
|
|
case StyleAppearance::ScrollbarVertical:
|
|
|
|
aSize.width = GetScrollbarWidthNoTheme(aBox);
|
2014-06-27 09:19:00 +00:00
|
|
|
aWidthSet = true;
|
|
|
|
break;
|
|
|
|
case StyleAppearance::ScrollbarHorizontal:
|
|
|
|
aSize.height = GetScrollbarWidthNoTheme(aBox);
|
|
|
|
aHeightSet = true;
|
2018-08-20 18:50:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2001-12-17 22:51:39 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2001-12-17 22:51:39 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
// add in the css min, max, pref
|
2013-02-16 21:51:02 +00:00
|
|
|
const nsStylePosition* position = aBox->StylePosition();
|
2019-02-10 12:55:16 +00:00
|
|
|
const auto& minWidth = position->mMinWidth;
|
|
|
|
if (minWidth.ConvertsToLength()) {
|
|
|
|
nscoord min = minWidth.ToLength();
|
2010-08-25 10:17:56 +00:00
|
|
|
if (!aWidthSet || (min > aSize.width && canOverride)) {
|
2000-03-31 07:02:06 +00:00
|
|
|
aSize.width = min;
|
2011-10-17 14:59:28 +00:00
|
|
|
aWidthSet = true;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
2019-02-10 12:55:16 +00:00
|
|
|
} else if (minWidth.ConvertsToPercentage()) {
|
|
|
|
NS_ASSERTION(minWidth.ToPercentage() == 0.0f,
|
2008-09-20 13:42:03 +00:00
|
|
|
"Non-zero percentage values not currently supported");
|
2010-08-25 10:17:55 +00:00
|
|
|
aSize.width = 0;
|
2011-10-17 14:59:28 +00:00
|
|
|
aWidthSet = true; // FIXME: should we really do this for
|
2010-08-25 10:17:56 +00:00
|
|
|
// nonzero values?
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2019-02-10 12:55:16 +00:00
|
|
|
// XXX Handle ExtremumLength?
|
|
|
|
// (Handling them requires GetXULPrefSize/GetXULMinSize methods that don't
|
|
|
|
// consider (min-/max-/)(width/height) properties.
|
2010-08-25 10:17:56 +00:00
|
|
|
// calc() with percentage is treated like '0' (unset)
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2019-02-10 12:55:16 +00:00
|
|
|
const auto& minHeight = position->mMinHeight;
|
|
|
|
if (minHeight.ConvertsToLength()) {
|
|
|
|
nscoord min = minHeight.ToLength();
|
2010-08-25 10:17:55 +00:00
|
|
|
if (!aHeightSet || (min > aSize.height && canOverride)) {
|
2000-03-31 07:02:06 +00:00
|
|
|
aSize.height = min;
|
2011-10-17 14:59:28 +00:00
|
|
|
aHeightSet = true;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
2019-02-10 12:55:16 +00:00
|
|
|
} else if (minHeight.ConvertsToPercentage()) {
|
|
|
|
NS_ASSERTION(position->mMinHeight.ToPercentage() == 0.0f,
|
2008-09-20 13:42:03 +00:00
|
|
|
"Non-zero percentage values not currently supported");
|
2004-11-03 12:20:13 +00:00
|
|
|
aSize.height = 0;
|
2011-10-17 14:59:28 +00:00
|
|
|
aHeightSet = true; // FIXME: should we really do this for
|
2010-08-25 10:17:55 +00:00
|
|
|
// nonzero values?
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2010-08-25 10:17:55 +00:00
|
|
|
// calc() with percentage is treated like '0' (unset)
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2004-09-28 18:37:50 +00:00
|
|
|
nsIContent* content = aBox->GetContent();
|
2015-03-03 11:08:59 +00:00
|
|
|
if (content && content->IsXULElement()) {
|
2000-03-31 07:02:06 +00:00
|
|
|
nsAutoString value;
|
2012-07-27 13:59:29 +00:00
|
|
|
nsresult error;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2017-12-07 18:13:50 +00:00
|
|
|
content->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::minwidth,
|
2018-11-30 10:46:48 +00:00
|
|
|
value);
|
2005-10-28 11:25:24 +00:00
|
|
|
if (!value.IsEmpty()) {
|
2000-03-31 07:02:06 +00:00
|
|
|
value.Trim("%");
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2007-02-07 07:46:44 +00:00
|
|
|
nscoord val = nsPresContext::CSSPixelsToAppUnits(value.ToInteger(&error));
|
2001-11-07 02:32:58 +00:00
|
|
|
if (val > aSize.width) aSize.width = val;
|
2014-06-27 09:19:00 +00:00
|
|
|
aWidthSet = true;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2017-12-07 18:13:50 +00:00
|
|
|
content->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::minheight,
|
|
|
|
value);
|
2005-10-28 11:25:24 +00:00
|
|
|
if (!value.IsEmpty()) {
|
2000-12-07 10:18:40 +00:00
|
|
|
value.Trim("%");
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2007-02-07 07:46:44 +00:00
|
|
|
nscoord val = nsPresContext::CSSPixelsToAppUnits(value.ToInteger(&error));
|
2001-11-07 02:32:58 +00:00
|
|
|
if (val > aSize.height) aSize.height = val;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
aHeightSet = true;
|
2000-12-07 10:18:40 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2000-12-07 10:18:40 +00:00
|
|
|
|
2010-03-18 19:58:15 +00:00
|
|
|
return (aWidthSet && aHeightSet);
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:34 +00:00
|
|
|
bool nsIFrame::AddXULMaxSize(nsIFrame* aBox, nsSize& aSize, bool& aWidthSet,
|
|
|
|
bool& aHeightSet) {
|
2011-10-17 14:59:28 +00:00
|
|
|
aWidthSet = false;
|
|
|
|
aHeightSet = false;
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
// add in the css min, max, pref
|
2013-02-16 21:51:02 +00:00
|
|
|
const nsStylePosition* position = aBox->StylePosition();
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
// and max
|
2008-07-17 23:37:12 +00:00
|
|
|
// see if the width or height was specifically set
|
2007-05-09 08:48:38 +00:00
|
|
|
// XXX Handle eStyleUnit_Enumerated?
|
2007-05-03 23:11:00 +00:00
|
|
|
// (Handling the eStyleUnit_Enumerated types requires
|
2016-04-21 04:28:31 +00:00
|
|
|
// GetXULPrefSize/GetXULMinSize methods that don't consider
|
2008-07-17 23:37:12 +00:00
|
|
|
// (min-/max-/)(width/height) properties.)
|
2019-02-10 12:55:16 +00:00
|
|
|
const auto& maxWidth = position->mMaxWidth;
|
2010-08-25 10:17:56 +00:00
|
|
|
if (maxWidth.ConvertsToLength()) {
|
2019-02-10 12:55:16 +00:00
|
|
|
aSize.width = maxWidth.ToLength();
|
2011-10-17 14:59:28 +00:00
|
|
|
aWidthSet = true;
|
2008-07-17 23:37:12 +00:00
|
|
|
}
|
2010-08-25 10:17:56 +00:00
|
|
|
// percentages and calc() with percentages are treated like 'none'
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2019-02-10 12:55:16 +00:00
|
|
|
const auto& maxHeight = position->mMaxHeight;
|
2010-08-25 10:17:55 +00:00
|
|
|
if (maxHeight.ConvertsToLength()) {
|
2019-02-10 12:55:16 +00:00
|
|
|
aSize.height = maxHeight.ToLength();
|
2011-10-17 14:59:28 +00:00
|
|
|
aHeightSet = true;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
2010-08-25 10:17:55 +00:00
|
|
|
// percentages and calc() with percentages are treated like 'none'
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2004-09-28 18:37:50 +00:00
|
|
|
nsIContent* content = aBox->GetContent();
|
2015-03-03 11:08:59 +00:00
|
|
|
if (content && content->IsXULElement()) {
|
2001-09-20 07:46:13 +00:00
|
|
|
nsAutoString value;
|
2012-07-27 13:59:29 +00:00
|
|
|
nsresult error;
|
2001-09-20 07:46:13 +00:00
|
|
|
|
2017-12-07 18:13:50 +00:00
|
|
|
content->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::maxwidth,
|
|
|
|
value);
|
2005-10-28 11:25:24 +00:00
|
|
|
if (!value.IsEmpty()) {
|
2001-09-20 07:46:13 +00:00
|
|
|
value.Trim("%");
|
|
|
|
|
2007-02-07 07:46:44 +00:00
|
|
|
nscoord val = nsPresContext::CSSPixelsToAppUnits(value.ToInteger(&error));
|
2001-09-20 07:46:13 +00:00
|
|
|
aSize.width = val;
|
2011-10-17 14:59:28 +00:00
|
|
|
aWidthSet = true;
|
2001-09-20 07:46:13 +00:00
|
|
|
}
|
|
|
|
|
2017-12-07 18:13:50 +00:00
|
|
|
content->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::maxheight,
|
|
|
|
value);
|
2005-10-28 11:25:24 +00:00
|
|
|
if (!value.IsEmpty()) {
|
2001-09-20 07:46:13 +00:00
|
|
|
value.Trim("%");
|
|
|
|
|
2007-02-07 07:46:44 +00:00
|
|
|
nscoord val = nsPresContext::CSSPixelsToAppUnits(value.ToInteger(&error));
|
2001-09-20 07:46:13 +00:00
|
|
|
aSize.height = val;
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
aHeightSet = true;
|
2001-09-20 07:46:13 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2001-09-20 07:46:13 +00:00
|
|
|
|
2010-03-18 19:58:15 +00:00
|
|
|
return (aWidthSet || aHeightSet);
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:34 +00:00
|
|
|
bool nsIFrame::AddXULFlex(nsIFrame* aBox, nscoord& aFlex) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool flexSet = false;
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
// get the flexibility
|
2013-02-16 21:51:02 +00:00
|
|
|
aFlex = aBox->StyleXUL()->mBoxFlex;
|
2011-04-23 01:36:24 +00:00
|
|
|
|
|
|
|
// attribute value overrides CSS
|
2004-09-28 18:37:50 +00:00
|
|
|
nsIContent* content = aBox->GetContent();
|
2015-03-03 11:08:59 +00:00
|
|
|
if (content && content->IsXULElement()) {
|
2012-07-27 13:59:29 +00:00
|
|
|
nsresult error;
|
2000-03-31 07:02:06 +00:00
|
|
|
nsAutoString value;
|
|
|
|
|
2017-12-07 18:13:50 +00:00
|
|
|
content->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::flex, value);
|
2005-10-28 11:25:24 +00:00
|
|
|
if (!value.IsEmpty()) {
|
2000-03-31 07:02:06 +00:00
|
|
|
value.Trim("%");
|
|
|
|
aFlex = value.ToInteger(&error);
|
2011-10-17 14:59:28 +00:00
|
|
|
flexSet = true;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2006-07-24 10:46:36 +00:00
|
|
|
if (aFlex < 0) aFlex = 0;
|
|
|
|
if (aFlex >= nscoord_MAX) aFlex = nscoord_MAX - 1;
|
|
|
|
|
2011-04-23 01:36:24 +00:00
|
|
|
return flexSet || aFlex > 0;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsBox::AddBorderAndPadding(nsSize& aSize) {
|
|
|
|
AddBorderAndPadding(this, aSize);
|
|
|
|
}
|
|
|
|
|
2012-08-06 03:00:57 +00:00
|
|
|
void nsBox::AddBorderAndPadding(nsIFrame* aBox, nsSize& aSize) {
|
2000-03-31 07:02:06 +00:00
|
|
|
nsMargin borderPadding(0, 0, 0, 0);
|
2016-04-21 04:28:32 +00:00
|
|
|
aBox->GetXULBorderAndPadding(borderPadding);
|
2000-03-31 07:02:06 +00:00
|
|
|
AddMargin(aSize, borderPadding);
|
|
|
|
}
|
|
|
|
|
2012-08-06 03:00:57 +00:00
|
|
|
void nsBox::AddMargin(nsIFrame* aChild, nsSize& aSize) {
|
2000-03-31 07:02:06 +00:00
|
|
|
nsMargin margin(0, 0, 0, 0);
|
2016-04-21 04:28:33 +00:00
|
|
|
aChild->GetXULMargin(margin);
|
2000-03-31 07:02:06 +00:00
|
|
|
AddMargin(aSize, margin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsBox::AddMargin(nsSize& aSize, const nsMargin& aMargin) {
|
2019-06-04 23:41:20 +00:00
|
|
|
if (aSize.width != NS_UNCONSTRAINEDSIZE)
|
2000-03-31 07:02:06 +00:00
|
|
|
aSize.width += aMargin.left + aMargin.right;
|
|
|
|
|
2019-06-04 23:41:20 +00:00
|
|
|
if (aSize.height != NS_UNCONSTRAINEDSIZE)
|
2000-03-31 07:02:06 +00:00
|
|
|
aSize.height += aMargin.top + aMargin.bottom;
|
|
|
|
}
|
|
|
|
|
2008-01-05 05:49:44 +00:00
|
|
|
nscoord nsBox::BoundsCheck(nscoord aMin, nscoord aPref, nscoord aMax) {
|
2001-10-09 21:02:29 +00:00
|
|
|
if (aPref > aMax) aPref = aMax;
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2001-10-09 21:02:29 +00:00
|
|
|
if (aPref < aMin) aPref = aMin;
|
2008-01-05 05:49:44 +00:00
|
|
|
|
|
|
|
return aPref;
|
2001-10-09 21:02:29 +00:00
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2008-01-05 05:49:44 +00:00
|
|
|
nsSize nsBox::BoundsCheckMinMax(const nsSize& aMinSize,
|
|
|
|
const nsSize& aMaxSize) {
|
2013-01-15 12:22:03 +00:00
|
|
|
return nsSize(std::max(aMaxSize.width, aMinSize.width),
|
|
|
|
std::max(aMaxSize.height, aMinSize.height));
|
2004-11-03 12:20:13 +00:00
|
|
|
}
|
|
|
|
|
2008-01-05 05:49:44 +00:00
|
|
|
nsSize nsBox::BoundsCheck(const nsSize& aMinSize, const nsSize& aPrefSize,
|
|
|
|
const nsSize& aMaxSize) {
|
|
|
|
return nsSize(
|
|
|
|
BoundsCheck(aMinSize.width, aPrefSize.width, aMaxSize.width),
|
|
|
|
BoundsCheck(aMinSize.height, aPrefSize.height, aMaxSize.height));
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 22:09:24 +00:00
|
|
|
/*static*/
|
|
|
|
nsIFrame* nsBox::GetChildXULBox(const nsIFrame* aFrame) {
|
2014-05-24 22:20:41 +00:00
|
|
|
// box layout ends at box-wrapped frames, so don't allow these frames
|
|
|
|
// to report child boxes.
|
2016-04-21 04:28:30 +00:00
|
|
|
return aFrame->IsXULBoxFrame() ? aFrame->PrincipalChildList().FirstChild()
|
|
|
|
: nullptr;
|
2014-05-24 22:20:41 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 22:09:24 +00:00
|
|
|
/*static*/
|
|
|
|
nsIFrame* nsBox::GetNextXULBox(const nsIFrame* aFrame) {
|
2016-04-21 04:28:30 +00:00
|
|
|
return aFrame->GetParent() && aFrame->GetParent()->IsXULBoxFrame()
|
|
|
|
? aFrame->GetNextSibling()
|
|
|
|
: nullptr;
|
2014-05-24 22:20:41 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 22:09:24 +00:00
|
|
|
/*static*/
|
|
|
|
nsIFrame* nsBox::GetParentXULBox(const nsIFrame* aFrame) {
|
2016-04-21 04:28:30 +00:00
|
|
|
return aFrame->GetParent() && aFrame->GetParent()->IsXULBoxFrame()
|
|
|
|
? aFrame->GetParent()
|
|
|
|
: nullptr;
|
2014-05-24 22:20:41 +00:00
|
|
|
}
|