Class RequestFullscreenAction

All Implemented Interfaces:
Serializable

public class RequestFullscreenAction extends PromiseAction<Void>
Asks the browser to enter fullscreen when the bound trigger fires.

Two modes:

  • Page — calls window.Vaadin.Flow.fullscreen .requestPageFullscreen() which fullscreens document.documentElement. Themes and overlay components keep working.
  • Component — calls window.Vaadin.Flow.fullscreen .requestComponentFullscreen(element, wrapper) which moves the target into the Vaadin wrapper element, hides the rest of the view, and fullscreens document.documentElement. The component is restored to its original position when fullscreen exits (programmatically, via Escape, or a superseding request).

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.

Outcome handling extends PromiseAction: use the fire-and-forget constructors, or the overloads 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()
      Creates a fire-and-forget page-level fullscreen action. The rendered JS calls requestPageFullscreen() and the server never sees the outcome.
    • RequestFullscreenAction

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

      public RequestFullscreenAction(Component target)
      Creates a fire-and-forget component-level fullscreen action. The component is moved into the UI's wrapper element so themes and overlay components keep working.
      Parameters:
      target - the component to fullscreen, not null; must be attached to a UI
    • RequestFullscreenAction

      public RequestFullscreenAction(Component target, SerializableRunnable onSuccess, SerializableConsumer<PromiseAction.Error> onError)
      Creates a component-level fullscreen action whose outcome is reported back to the server.
      Parameters:
      target - the component to fullscreen, not null; must be attached to a UI
      onSuccess - invoked on the UI thread after the client reports the request resolved, not null
      onError - invoked on the UI thread with the browser's error after the client reports the request 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