Bound the size of an alert that carries a formatted message - #2836
Open
Natalie-the-technician wants to merge 1 commit into
Open
Bound the size of an alert that carries a formatted message#2836Natalie-the-technician wants to merge 1 commit into
Natalie-the-technician wants to merge 1 commit into
Conversation
showOptionDialog puts a MarkdownView straight into the dialog pane when the message is HTML or Markdown. A MarkdownView is a VBox that asks for as much width as its longest paragraph needs, and DialogPane takes the preferred size of its content as its own, so a long message made the dialog as wide as the screen and taller than the screen. Measured on a 1024x768 screen, the pane asked for 1633px of width and the three buttons ended up at y=853..879, below the bottom edge: the dialog could only be closed with Escape. The message now goes into a scroll pane whose preferred width is bounded at 720px and whose preferred height is bounded at 60% of the screen. The same message now opens a 720x541 dialog with all of its buttons on the screen and a scroll bar for the rest of the text. A short message is untouched: modena gives a scroll pane the same 0.833em of padding it gives the content of a dialog pane, so leaving that padding alone puts the text back where it was. The one HTML message the application shows today, help.recover.autosaveInfo, opens the same 392x238 dialog it opened before, and a screenshot of it is identical to the pixel.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
UIFacadeImpl.showOptionDialogknows two message formats besides plain text,HTML_MESSAGE_FORMATandMARKDOWN_MESSAGE_FORMAT(UIFacade.java:82-83). Both take a different route from plain text: instead ofsetContentTextthey put aMarkdownViewstraight into the dialog pane (UIFacadeImpl.java:302-309).A
MarkdownViewis aVBox, and aVBoxasks for as much width as its widest child needs.DialogPanein turn takes the preferred size of its content as its own. Nothing bounds either dimension, so a long message makes the dialog as wide as the screen and taller than the screen, and the buttons go with it.Measured on a 1024x768 screen with a 2611 character HTML message, an error list of the kind a failing document reader would produce:
The dialog pane asks for 1633px of width, is clamped to the screen, and all three buttons sit at y=853..879 — below the bottom edge of a 768px screen. The dialog can then only be dismissed with Escape, which picks the cancel action whatever the user meant. The text is cut off as well: the message is 710px tall inside a 519px window.
What this changes
The formatted message goes into a scroll pane that bounds the preferred size in both directions:
MAX_CONTENT_WIDTH = 720, twice the 360px thatDialogPane.createContentLabelhard-codes for a plain text message. A formatted message may carry tables and code blocks that do not wrap, so it gets more room than plain text, but not the whole screen. It is a fixed number and not a share of the screen, because how wide a column may be before it becomes hard to read does not depend on the monitor.The bounds sit on the preferred size and not on the maximum, because the preferred size is the only one
DialogPaneever asks the content for.The same message now measures:
A short message is untouched
This is the part worth checking, because a width correction of this kind can quietly change every dialog in the application.
HTML_MESSAGE_FORMAThas exactly one call site today,HelpMenu.java:153, the question that offers to restore an autosaved document.MARKDOWN_MESSAGE_FORMAThas none. That one message must keep the dialog it has, and it does:A screenshot of the two dialogs differs in 0 of 93296 pixels.
The reason it survives is worth stating, because the obvious version of this change does not: modena gives a
ScrollPanethe same0.833emof padding it gives the content of aDialogPane. Zeroing the scroll pane's padding — which looks like the tidy thing to do — makes every short formatted dialog 22px narrower. Leaving the padding alone puts the text back on the pixel it was on.Only
-fx-background-coloris cleared, which takes modena's border and background box with it.-fx-backgroundis deliberately not touched: modena derives the text colour from it through-fx-text-background-color: ladder(-fx-background, ...), so setting it to transparent turns every label inside the scroll pane white on white.Tests
AlertContentSizeTest, four cases:MarkdownViewbuilt the way the code built it beforeAll four were run against the unfixed code first. The three defect cases fail there and the guard passes, which is what a guard is for. The guard was then made to fail on purpose by tightening the width bound to 200px, to check it can fail at all.
Whole suite: 375 tests before, 382 after, 0 failures.
Note on #2833
#2833 does the matching thing for the plain text branch of the same method. The two touch different branches of the same
if, so they do not conflict in behaviour, but they share one line:MAX_CONTENT_HEIGHT_RATIO = 0.6. Whichever lands second should drop that one declaration and use the other's. This PR stands on its own againstmasterand does not depend on #2833.