Bug 1609446 - Make default window-constraints always show the content. r=mats,mstange
This code is used to determine the sizes of the top-level windows. However the code doesn't cause quite desirable behavior (see the bug, and comment 15). This patch does two things: * Unifies the html / xul code-paths. This shouldn't change behavior (because GetXULMinSize returns the fixed min-* property if present anyways), but makes the patch a bit simpler. * Makes the min-width of the XUL window be the pref size instead of the min-size (for the cases where you have no explicit min-width). This looks a bit counter intuitive, but it's the only way to guarantee that the content will be shown. This matches the sizing algorithm that dialogs use by default (via calling window.sizeToContent()), while allowing to undersize the window via a fixed min-width property. This in turn makes sizeToContent() work "by default" on XUL windows, avoiding having to make JS listen to everything that possibly could change the layout of the document (like resolution changes). Differential Revision: https://phabricator.services.mozilla.com/D70209
This commit is contained in:
@@ -551,18 +551,22 @@ static bool IsTopLevelWidget(nsIWidget* aWidget) {
|
||||
void nsContainerFrame::SyncWindowProperties(nsPresContext* aPresContext,
|
||||
nsIFrame* aFrame, nsView* aView,
|
||||
gfxContext* aRC, uint32_t aFlags) {
|
||||
#ifdef MOZ_XUL
|
||||
if (!aView || !nsCSSRendering::IsCanvasFrame(aFrame) || !aView->HasWidget())
|
||||
if (!aView || !nsCSSRendering::IsCanvasFrame(aFrame) || !aView->HasWidget()) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIWidget> windowWidget =
|
||||
GetPresContextContainerWidget(aPresContext);
|
||||
if (!windowWidget || !IsTopLevelWidget(windowWidget)) return;
|
||||
if (!windowWidget || !IsTopLevelWidget(windowWidget)) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsViewManager* vm = aView->GetViewManager();
|
||||
nsView* rootView = vm->GetRootView();
|
||||
|
||||
if (aView != rootView) return;
|
||||
if (aView != rootView) {
|
||||
return;
|
||||
}
|
||||
|
||||
Element* rootElement = aPresContext->Document()->GetRootElement();
|
||||
if (!rootElement) {
|
||||
@@ -571,7 +575,9 @@ void nsContainerFrame::SyncWindowProperties(nsPresContext* aPresContext,
|
||||
|
||||
nsIFrame* rootFrame =
|
||||
aPresContext->PresShell()->FrameConstructor()->GetRootElementStyleFrame();
|
||||
if (!rootFrame) return;
|
||||
if (!rootFrame) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (aFlags & SET_ASYNC) {
|
||||
aView->SetNeedsWindowPropertiesSync();
|
||||
@@ -600,7 +606,9 @@ void nsContainerFrame::SyncWindowProperties(nsPresContext* aPresContext,
|
||||
windowWidget->SetWindowShadowStyle(shadow);
|
||||
}
|
||||
|
||||
if (!aRC) return;
|
||||
if (!aRC) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!weak.IsAlive()) {
|
||||
return;
|
||||
@@ -608,36 +616,49 @@ void nsContainerFrame::SyncWindowProperties(nsPresContext* aPresContext,
|
||||
|
||||
nsSize minSize(0, 0);
|
||||
nsSize maxSize(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
||||
if (rootElement->IsXULElement()) {
|
||||
nsBoxLayoutState aState(aPresContext, aRC);
|
||||
minSize = rootFrame->GetXULMinSize(aState);
|
||||
maxSize = rootFrame->GetXULMaxSize(aState);
|
||||
} else {
|
||||
auto* pos = rootFrame->StylePosition();
|
||||
if (pos->mMinWidth.ConvertsToLength()) {
|
||||
minSize.width = pos->mMinWidth.ToLength();
|
||||
}
|
||||
if (pos->mMinHeight.ConvertsToLength()) {
|
||||
minSize.height = pos->mMinHeight.ToLength();
|
||||
}
|
||||
if (pos->mMaxWidth.ConvertsToLength()) {
|
||||
maxSize.width = pos->mMaxWidth.ToLength();
|
||||
}
|
||||
if (pos->mMaxHeight.ConvertsToLength()) {
|
||||
maxSize.height = pos->mMaxHeight.ToLength();
|
||||
|
||||
const auto& pos = *rootFrame->StylePosition();
|
||||
#ifdef MOZ_XUL
|
||||
if (rootFrame->IsXULBoxFrame()) {
|
||||
nsBoxLayoutState xulState(aPresContext, aRC);
|
||||
minSize = rootFrame->GetXULMinSize(xulState);
|
||||
const bool isMinContent =
|
||||
pos.mMinWidth.IsExtremumLength() &&
|
||||
pos.mMinWidth.AsExtremumLength() == StyleExtremumLength::MinContent;
|
||||
// By default we behave with min-width: max-content, to ensure that all
|
||||
// content is shown (i.e., the GetXULPrefSize call below).
|
||||
//
|
||||
// It can be overridden to min-content (i.e., leave GetXULMinSize()) and
|
||||
// a fixed width (handled below).
|
||||
if (!isMinContent && !pos.mMinWidth.ConvertsToLength()) {
|
||||
minSize.width = rootFrame->GetXULPrefSize(xulState).width;
|
||||
}
|
||||
maxSize = rootFrame->GetXULMaxSize(xulState);
|
||||
}
|
||||
SetSizeConstraints(aPresContext, windowWidget, minSize, maxSize);
|
||||
#endif
|
||||
|
||||
if (pos.mMinWidth.ConvertsToLength()) {
|
||||
minSize.width = pos.mMinWidth.ToLength();
|
||||
}
|
||||
if (pos.mMinHeight.ConvertsToLength()) {
|
||||
minSize.height = pos.mMinHeight.ToLength();
|
||||
}
|
||||
if (pos.mMaxWidth.ConvertsToLength()) {
|
||||
maxSize.width = pos.mMaxWidth.ToLength();
|
||||
}
|
||||
if (pos.mMaxHeight.ConvertsToLength()) {
|
||||
maxSize.height = pos.mMaxHeight.ToLength();
|
||||
}
|
||||
|
||||
SetSizeConstraints(aPresContext, windowWidget, minSize, maxSize);
|
||||
}
|
||||
|
||||
void nsContainerFrame::SetSizeConstraints(nsPresContext* aPresContext,
|
||||
nsIWidget* aWidget,
|
||||
const nsSize& aMinSize,
|
||||
const nsSize& aMaxSize) {
|
||||
LayoutDeviceIntSize devMinSize(
|
||||
aPresContext->AppUnitsToDevPixels(aMinSize.width),
|
||||
aPresContext->AppUnitsToDevPixels(aMinSize.height));
|
||||
auto devMinSize = LayoutDeviceIntSize::FromAppUnitsToOutside(
|
||||
aMinSize, aPresContext->AppUnitsPerDevPixel());
|
||||
LayoutDeviceIntSize devMaxSize(
|
||||
aMaxSize.width == NS_UNCONSTRAINEDSIZE
|
||||
? NS_MAXSIZE
|
||||
@@ -647,9 +668,8 @@ void nsContainerFrame::SetSizeConstraints(nsPresContext* aPresContext,
|
||||
: aPresContext->AppUnitsToDevPixels(aMaxSize.height));
|
||||
|
||||
// MinSize has a priority over MaxSize
|
||||
if (devMinSize.width > devMaxSize.width) devMaxSize.width = devMinSize.width;
|
||||
if (devMinSize.height > devMaxSize.height)
|
||||
devMaxSize.height = devMinSize.height;
|
||||
devMaxSize.width = std::max(devMinSize.width, devMaxSize.width);
|
||||
devMaxSize.height = std::max(devMinSize.height, devMaxSize.height);
|
||||
|
||||
widget::SizeConstraints constraints(devMinSize, devMaxSize);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user