Class RequestFullscreenAction

All Implemented Interfaces:
Serializable

public class RequestFullscreenAction extends PromiseAction<Void>
Asks the browser to fullscreen the target component's root element via Element.requestFullscreen() when the bound trigger fires.

The Fullscreen API requires transient user activation (a click, key press, …) — calling requestFullscreen from a server push or constructor is rejected by the browser. Bind this action to a Trigger that fires during such a gesture, typically a ClickTrigger, so the call happens synchronously inside the handler and inherits the gesture.

This action is intentionally low-level: it calls requestFullscreen directly on the target's root element. That doesn't interact well with Vaadin theming or overlay components, which expect the fullscreen element to be document.documentElement. A higher-level Component.requestFullscreen() facade — see PR vaadin/flow#24326 — handles the wrapping needed for full Vaadin compatibility; this action is the trigger-framework primitive it builds on (or a direct option when the Vaadin wrapping isn't needed).

Outcome handling extends PromiseAction: use the target-only constructor for fire-and-forget, or the overload taking onSuccess/onError consumers. The promise resolves with undefined so onSuccess is a SerializableRunnable with no value, but onError receives a PromiseAction.Error record with the browser's error name and message — the spec-documented rejection is NotAllowedError (no gesture / permissions policy).


 RequestFullscreenAction goFs = new RequestFullscreenAction(panel,
         () -> notification.show("Fullscreen entered"),
         err -> notification.show("Fullscreen denied: " + err.message()));
 new ClickTrigger(button).triggers(goFs);
 
For internal use only. May be renamed or removed in a future release.
See Also:
  • Constructor Details

    • RequestFullscreenAction

      public RequestFullscreenAction(Component target)
      Creates a fire-and-forget fullscreen action: the rendered JS just calls requestFullscreen() and the server never sees the outcome.
      Parameters:
      target - the component whose root element to fullscreen, not null
    • RequestFullscreenAction

      public RequestFullscreenAction(Component target, SerializableRunnable onSuccess, SerializableConsumer<PromiseAction.Error> onError)
      Creates a fullscreen action whose outcome is reported back to the server.
      Parameters:
      target - the component whose root element to fullscreen, not null
      onSuccess - invoked on the UI thread after the client reports requestFullscreen resolved, not null
      onError - invoked on the UI thread with the browser's error after the client reports requestFullscreen rejected, not null
  • Method Details

    • toPromiseJs

      protected JsFunction toPromiseJs(Trigger trigger)
      Description copied from class: PromiseAction
      Subclasses return a JsFunction that, when invoked with the trigger's event, evaluates to a Promise. The value the promise resolves with is decoded to T on the server and handed to onSuccess. To deliver a typed value, subclasses can wrap their API call in an IIFE inside the function body — for example, copying a string and resolving with it:
      
       return JsFunction.of(
               "return ((v) => navigator.clipboard.writeText(v).then(() => v))($0(event))",
               textInput.toJs(trigger)).withArguments("event");
       
      Specified by:
      toPromiseJs in class PromiseAction<Void>
      Parameters:
      trigger - the surrounding trigger this render is for, not null
      Returns:
      the promise-yielding JS function, not null