Record Class BrowserToolkitInfo
Toolkit's screen accessors need but a headless server JVM cannot
supply: the viewport size, device-pixel ratio, and whether the client is a
Mac / iOS device (used to choose the menu-shortcut modifier — META
on macOS / iOS, CTRL elsewhere).
Viewport, not physical screen (D_toolkit_screen_size). viewportWidth() /
viewportHeight() carry the browser window's inner size
(window.innerWidth/Height via
ExtendedClientDetails.getWindowInnerWidth()), not the monitor's
screen.width/height. The coordinate space our windows place in
(Window.setLocation/setBounds → Dialog overlay top/left) is the
viewport, so every migrated screen-math idiom — centering, edge-anchored
toasts, size-to-fraction-of-screen — only computes correctly against the
viewport. Physical monitor size has no placement use in a browser.
Sourced from Vaadin's ExtendedClientDetails — the same
client-details channel BrowserTimeZone uses, not a
bespoke executeJs. get() reads the cached
ExtendedClientDetails synchronously when it is already populated
(which it is in any app that wired BrowserTimeZone.fetch() at UI
init — the migration guide requires it for dates), so the screen accessors
work on any thread, including at frame-construction time on the
Vaadin request thread. When the details have not yet been fetched, it parks
the calling virtual thread on a refresh round-trip (the
WebClipboard VT-park pattern). See D_toolkit_full_surface, D_toolkit_from_client_details.
Live resize tracking (D_toolkit_screen_size). The viewport changes when the user
resizes the browser window, so the first cache(UI, BrowserToolkitInfo) for a UI also
registers a browser-window resize listener; each resize event replaces the cached
snapshot's viewport (dpr / mac carry over) via onBrowserResize(UI, int, int).
The registration dies with the UI — no teardown needed. Bounded staleness:
resizes between page load and the first get() aren't tracked (no
listener yet, and Vaadin doesn't auto-refresh ExtendedClientDetails),
so the first read reports load-time values — self-heals from the first read
onward, and no UI-init step is required, per D_toolkit_from_client_details.
Cache only real values. A populated/fetched (or
test-injected) snapshot is cached per-UI via
ComponentUtil.setData(Component, SerializableTriConsumer, T, U); the fallback returned when
the browser details are unavailable is never cached, so a later call
with details available upgrades to the real value.
Quiet fallback. When the details are neither populated nor
fetchable (no current UI, or the caller is off a virtual-thread carrier and
the browser has not reported in yet), get() returns DEFAULT
and logs at debug — deliberately not
EHelper.onUnimplemented(String, String, Object...): screen metrics are
implemented, so the default is a graceful not-yet-known degrade (R_best_effort_behaviour/R_layouts_close_enough), and
a WARN on a normal construction path would trip the zero-stub-WARN exit gates.
macOS detection is iOS/iPadOS only. mac() is read off
navigator.platform the way
Vaadin's isIOS() (deprecated in 25.3) did: iPhone / iPod / iPad,
or MacIntel with a touch screen (iPadOS reports itself as a Mac). Desktop
Mac clients (MacIntel, no touch) fall to CTRL for the menu-shortcut
modifier. Accepted limitation (R_best_effort_behaviour/R_layouts_close_enough) —
the accelerator modifier is cosmetic; revisit if a migration target needs Cmd
accelerators on desktop Mac.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BrowserToolkitInfoFallback returned when the browser details are unavailable. -
Constructor Summary
ConstructorsConstructorDescriptionBrowserToolkitInfo(int viewportWidth, int viewportHeight, double devicePixelRatio, boolean mac) Creates an instance of aBrowserToolkitInforecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidDrop any cached snapshot for the current UI (test convenience).doubleReturns the value of thedevicePixelRatiorecord component.final booleanIndicates whether some other object is "equal to" this one.static BrowserToolkitInfoget()The current UI's browser display snapshot.final inthashCode()Returns a hash code value for this object.booleanmac()Returns the value of themacrecord component.static voidsetTestInfo(int viewportWidth, int viewportHeight, double devicePixelRatio, boolean mac) Inject a deterministic snapshot for the current UI, bypassing the browser round-trip.final StringtoString()Returns a string representation of this record class.intReturns the value of theviewportHeightrecord component.intReturns the value of theviewportWidthrecord component.
-
Field Details
-
DEFAULT
Fallback returned when the browser details are unavailable. A common desktop-viewport ballpark at DPR 1.0, non-Mac (mac()false → the menu shortcut defaults toCTRL).
-
-
Constructor Details
-
BrowserToolkitInfo
public BrowserToolkitInfo(int viewportWidth, int viewportHeight, double devicePixelRatio, boolean mac) Creates an instance of aBrowserToolkitInforecord class.- Parameters:
viewportWidth- the value for theviewportWidthrecord componentviewportHeight- the value for theviewportHeightrecord componentdevicePixelRatio- the value for thedevicePixelRatiorecord componentmac- the value for themacrecord component
-
-
Method Details
-
get
The current UI's browser display snapshot. Returns the cached value if present; else derives it synchronously from an already-populatedExtendedClientDetails; else, on a virtual-thread carrier, fetches the details (parking the VT) and caches the result; else returnsDEFAULT(uncached, debug-logged). -
setTestInfo
public static void setTestInfo(int viewportWidth, int viewportHeight, double devicePixelRatio, boolean mac) Inject a deterministic snapshot for the current UI, bypassing the browser round-trip. Used by tests; also usable by a host app that already knows the client's display facts. Does NOT install the resize listener — injected snapshots stay exactly as injected until the next injection orclearCache(). -
clearCache
public static void clearCache()Drop any cached snapshot for the current UI (test convenience). -
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with thecomparemethod from their corresponding wrapper classes. -
viewportWidth
public int viewportWidth()Returns the value of theviewportWidthrecord component.- Returns:
- the value of the
viewportWidthrecord component
-
viewportHeight
public int viewportHeight()Returns the value of theviewportHeightrecord component.- Returns:
- the value of the
viewportHeightrecord component
-
devicePixelRatio
public double devicePixelRatio()Returns the value of thedevicePixelRatiorecord component.- Returns:
- the value of the
devicePixelRatiorecord component
-
mac
public boolean mac()Returns the value of themacrecord component.- Returns:
- the value of the
macrecord component
-