Bug 1798836 - Improve sizing of the profile manager (again). r=Gijs,webidl,smaug

Instead of imposing the min-width as a max-size, make prefwidth act as
it should (as suggesting a preferred width, but with min-content as a
minimum).

This can be reproduced locally by applying a patch like:

```
diff --git a/toolkit/profile/content/profileSelection.xhtml b/toolkit/profile/content/profileSelection.xhtml
index 3dd1c864f79f1..7e8cbf8ce8c3e 100644
--- a/toolkit/profile/content/profileSelection.xhtml
+++ b/toolkit/profile/content/profileSelection.xhtml
@@ -17,7 +17,7 @@
   data-l10n-id="profile-selection-window"
   orient="vertical"
   prefwidth="min-width"
-  style="min-width: 30em;"
+  style="min-width: 10em;"
   onload="startup();">
 <dialog id="profileWindow"
   buttons="accept,cancel"
```

Before patch, stuff overflowed. This patch guarantees that everything is
on-screen.

Differential Revision: https://phabricator.services.mozilla.com/D161229
This commit is contained in:
Emilio Cobos Álvarez 2022-11-05 19:24:31 +00:00
Родитель 3348f20292
Коммит 25e4585462
9 изменённых файлов: 48 добавлений и 26 удалений

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

@ -277,19 +277,24 @@ interface nsIContentViewer : nsISupports
/**
* Returns the preferred width and height of the content, constrained to the
* given maximum values. If either maxWidth or maxHeight is less than zero,
* that dimension is not constrained.
* given maximum values. If either maxWidth or maxHeight is less than or
* equal to zero, that dimension is not constrained.
*
* If a pref width is provided, it is max'd with the min-content size.
*
* All input and output values are in CSS pixels.
*/
void getContentSize(in long maxWidth, in long maxHeight,
out long width, out long height);
void getContentSize(in long maxWidth,
in long maxHeight,
in long prefWidth,
out long width,
out long height);
%{C++
mozilla::Maybe<mozilla::CSSIntSize> GetContentSize(int32_t aMaxWidth = 0, int32_t aMaxHeight = 0) {
mozilla::Maybe<mozilla::CSSIntSize> GetContentSize(int32_t aMaxWidth = 0, int32_t aMaxHeight = 0, int32_t aPrefWidth = 0) {
int32_t w = 0;
int32_t h = 0;
if (NS_SUCCEEDED(GetContentSize(aMaxWidth, aMaxHeight, &w, &h))) {
if (NS_SUCCEEDED(GetContentSize(aMaxWidth, aMaxHeight, aPrefWidth, &w, &h))) {
return mozilla::Some(mozilla::CSSIntSize(w, h));
}
return mozilla::Nothing();

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

@ -3932,16 +3932,14 @@ void nsGlobalWindowInner::ResizeBy(int32_t aWidthDif, int32_t aHeightDif,
void nsGlobalWindowInner::SizeToContent(CallerType aCallerType,
ErrorResult& aError) {
FORWARD_TO_OUTER_OR_THROW(SizeToContentOuter, (aCallerType, 0, 0, aError),
FORWARD_TO_OUTER_OR_THROW(SizeToContentOuter, (aCallerType, {}, aError),
aError, );
}
void nsGlobalWindowInner::SizeToContentConstrained(int32_t aMaxWidth,
int32_t aMaxHeight,
ErrorResult& aError) {
FORWARD_TO_OUTER_OR_THROW(SizeToContentOuter,
(CallerType::System, aMaxWidth, aMaxHeight, aError),
aError, );
void nsGlobalWindowInner::SizeToContentConstrained(
const SizeToContentConstraints& aConstraints, ErrorResult& aError) {
FORWARD_TO_OUTER_OR_THROW(
SizeToContentOuter, (CallerType::System, aConstraints, aError), aError, );
}
already_AddRefed<nsPIWindowRoot> nsGlobalWindowInner::GetTopWindowRoot() {

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

@ -125,6 +125,7 @@ struct RequestInit;
class RequestOrUSVString;
class SharedWorker;
class Selection;
struct SizeToContentConstraints;
class WebTaskScheduler;
class WebTaskSchedulerMainThread;
class SpeechSynthesis;
@ -862,8 +863,8 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
mozilla::ErrorResult& aError);
void SizeToContent(mozilla::dom::CallerType aCallerType,
mozilla::ErrorResult& aError);
void SizeToContentConstrained(int32_t aMaxWidth, int32_t aMaxHeight,
mozilla::ErrorResult& aError);
void SizeToContentConstrained(const mozilla::dom::SizeToContentConstraints&,
mozilla::ErrorResult&);
mozilla::dom::Crypto* GetCrypto(mozilla::ErrorResult& aError);
mozilla::dom::U2F* GetU2f(mozilla::ErrorResult& aError);
nsIControllers* GetControllers(mozilla::ErrorResult& aError);

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

@ -5466,8 +5466,7 @@ void nsGlobalWindowOuter::ResizeByOuter(int32_t aWidthDif, int32_t aHeightDif,
}
void nsGlobalWindowOuter::SizeToContentOuter(CallerType aCallerType,
int32_t aMaxWidth,
int32_t aMaxHeight,
const SizeToContentConstraints& aConstraints,
ErrorResult& aError) {
if (!mDocShell) {
return;
@ -5490,7 +5489,7 @@ void nsGlobalWindowOuter::SizeToContentOuter(CallerType aCallerType,
return aError.Throw(NS_ERROR_FAILURE);
}
auto contentSize = cv->GetContentSize(aMaxWidth, aMaxHeight);
auto contentSize = cv->GetContentSize(aConstraints.mMaxWidth, aConstraints.mMaxHeight, aConstraints.mPrefWidth);
if (!contentSize) {
return aError.Throw(NS_ERROR_FAILURE);
}

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

@ -109,6 +109,7 @@ class PrintPreviewResultInfo;
struct RequestInit;
class RequestOrUSVString;
class Selection;
struct SizeToContentConstraints;
class SpeechSynthesis;
class Timeout;
class U2F;
@ -624,9 +625,9 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
double GetScrollYOuter();
MOZ_CAN_RUN_SCRIPT_BOUNDARY
void SizeToContentOuter(mozilla::dom::CallerType aCallerType,
int32_t aMaxWidth, int32_t aMaxHeight,
mozilla::ErrorResult& aError);
void SizeToContentOuter(mozilla::dom::CallerType,
const mozilla::dom::SizeToContentConstraints&,
mozilla::ErrorResult&);
nsIControllers* GetControllersOuter(mozilla::ErrorResult& aError);
nsresult GetControllers(nsIControllers** aControllers) override;
float GetMozInnerScreenXOuter(mozilla::dom::CallerType aCallerType);

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

@ -401,6 +401,12 @@ Window includes GlobalCrypto;
// https://fidoalliance.org/specifications/download/
Window includes GlobalU2F;
dictionary SizeToContentConstraints {
long maxWidth = 0;
long maxHeight = 0;
long prefWidth = 0;
};
#ifdef MOZ_WEBSPEECH
// http://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi.html
interface mixin SpeechSynthesisGetter {
@ -434,7 +440,7 @@ partial interface Window {
* Chrome-only method for sizing to content with a maximum-size constraint on
* either (or both) directions.
*/
[Throws, ChromeOnly] undefined sizeToContentConstrained(long width, long height);
[Throws, ChromeOnly] undefined sizeToContentConstrained(optional SizeToContentConstraints constraints = {});
// XXX Shouldn't this be in nsIDOMChromeWindow?
[ChromeOnly, Replaceable, Throws] readonly attribute XULControllers controllers;

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

@ -2598,7 +2598,8 @@ nsDocumentViewer::ForgetReloadEncoding() {
}
MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP nsDocumentViewer::GetContentSize(
int32_t aMaxWidth, int32_t aMaxHeight, int32_t* aWidth, int32_t* aHeight) {
int32_t aMaxWidth, int32_t aMaxHeight, int32_t aPrefWidth, int32_t* aWidth,
int32_t* aHeight) {
RefPtr<BrowsingContext> bc = mContainer->GetBrowsingContext();
NS_ENSURE_TRUE(bc, NS_ERROR_NOT_AVAILABLE);
@ -2606,7 +2607,7 @@ MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP nsDocumentViewer::GetContentSize(
// sub-frames.
NS_ENSURE_TRUE(bc->IsTop(), NS_ERROR_FAILURE);
// Convert max-width/height to app units.
// Convert max-width/height and pref-width to app units.
if (aMaxWidth > 0) {
aMaxWidth = CSSPixel::ToAppUnits(aMaxWidth);
} else {
@ -2617,6 +2618,11 @@ MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP nsDocumentViewer::GetContentSize(
} else {
aMaxHeight = NS_UNCONSTRAINEDSIZE;
}
if (aPrefWidth > 0) {
aPrefWidth = CSSPixel::ToAppUnits(aPrefWidth);
} else {
aPrefWidth = 0;
}
RefPtr<PresShell> presShell = GetPresShell();
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
@ -2634,7 +2640,12 @@ MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP nsDocumentViewer::GetContentSize(
{
RefPtr<gfxContext> rcx(presShell->CreateReferenceRenderingContext());
nscoord maxISize = wm.IsVertical() ? aMaxHeight : aMaxWidth;
prefISize = std::min(root->GetPrefISize(rcx), maxISize);
if (aPrefWidth) {
prefISize = std::max(root->GetMinISize(rcx), aPrefWidth);
} else {
prefISize = root->GetPrefISize(rcx);
}
prefISize = std::min(prefISize, maxISize);
}
// We should never intentionally get here with this sentinel value, but it's

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

@ -263,6 +263,7 @@ const BrowserListener = {
docShell.contentViewer.getContentSize(
this.maxWidth,
this.maxHeight,
/* prefWidth = */ 0,
w,
h
);

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

@ -213,7 +213,7 @@
}
return 0;
})();
window.sizeToContentConstrained(prefWidth, 0);
window.sizeToContentConstrained({ prefWidth });
}
moveToAlertPosition() {