Bug 1561326 - Support CSS min/max width/height for top level windows with root HTML element. r=emilio

Helps support migrating from XUL DOM to an HTML DOM structure. I attempted
to remove the early return when the root element is not a XUL element, but
it appears setting the transparency on a non XUL root is still broken
(test widget/tests/test_mouse_scroll.xul started failing on windows).

Differential Revision: https://phabricator.services.mozilla.com/D40734

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Brian Grinstead 2019-08-07 18:20:35 +00:00
Родитель 41c580344f
Коммит 9dac9754e5
1 изменённых файлов: 40 добавлений и 26 удалений

Просмотреть файл

@ -569,22 +569,7 @@ void nsContainerFrame::SyncWindowProperties(nsPresContext* aPresContext,
if (aView != rootView) return;
Element* rootElement = aPresContext->Document()->GetRootElement();
if (!rootElement || !rootElement->IsXULElement()) {
// Scrollframes use native widgets which don't work well with
// translucent windows, at least in Windows XP. So if the document
// has a root scrollrame it's useless to try to make it transparent,
// we'll just get something broken.
// nsCSSFrameConstructor::ConstructRootFrame constructs root
// scrollframes whenever the root element is not a XUL element, so
// we test for that here. We can't just call
// presShell->GetRootScrollFrame() since that might not have
// been constructed yet.
// We can change this to allow translucent toplevel HTML documents
// (e.g. to do something like Dashboard widgets), once we
// have broad support for translucent scrolled documents, but be
// careful because apparently some Firefox extensions expect
// openDialog("something.html") to produce an opaque window
// even if the HTML doesn't have a background-color set.
if (!rootElement) {
return;
}
@ -600,12 +585,24 @@ void nsContainerFrame::SyncWindowProperties(nsPresContext* aPresContext,
RefPtr<nsPresContext> kungFuDeathGrip(aPresContext);
AutoWeakFrame weak(rootFrame);
nsTransparencyMode mode =
nsLayoutUtils::GetFrameTransparency(aFrame, rootFrame);
int32_t shadow = rootFrame->StyleUIReset()->mWindowShadow;
nsCOMPtr<nsIWidget> viewWidget = aView->GetWidget();
viewWidget->SetTransparencyMode(mode);
windowWidget->SetWindowShadowStyle(shadow);
if (!aPresContext->PresShell()->GetRootScrollFrame()) {
// Scrollframes use native widgets which don't work well with
// translucent windows, at least in Windows XP. So if the document
// has a root scrollrame it's useless to try to make it transparent,
// we'll just get something broken.
// We can change this to allow translucent toplevel HTML documents
// (e.g. to do something like Dashboard widgets), once we
// have broad support for translucent scrolled documents, but be
// careful because apparently some Firefox extensions expect
// openDialog("something.html") to produce an opaque window
// even if the HTML doesn't have a background-color set.
nsTransparencyMode mode =
nsLayoutUtils::GetFrameTransparency(aFrame, rootFrame);
int32_t shadow = rootFrame->StyleUIReset()->mWindowShadow;
nsCOMPtr<nsIWidget> viewWidget = aView->GetWidget();
viewWidget->SetTransparencyMode(mode);
windowWidget->SetWindowShadowStyle(shadow);
}
if (!aRC) return;
@ -613,10 +610,27 @@ void nsContainerFrame::SyncWindowProperties(nsPresContext* aPresContext,
return;
}
nsBoxLayoutState aState(aPresContext, aRC);
nsSize minSize = rootFrame->GetXULMinSize(aState);
nsSize maxSize = rootFrame->GetXULMaxSize(aState);
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();
}
}
SetSizeConstraints(aPresContext, windowWidget, minSize, maxSize);
#endif
}