From cba3fe4258e13f24e723e1630023d6eba89cb490 Mon Sep 17 00:00:00 2001 From: Paola De Bartolo Date: Mon, 10 Jun 2024 19:04:36 -0300 Subject: [PATCH] feat: add listener to know if map is in full screen mode --- .../vaadin/addons/googlemaps/GoogleMap.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java b/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java index eff7e16..c79f4cc 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java +++ b/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java @@ -789,4 +789,56 @@ public void setCustomControls(CustomControl... customControls) { } this.getElement().setPropertyJson("customControls", jsonArray); } + + /** + * Adds a FullScreenEvent listener. The listener is called to notify whether the map is in full + * screen mode. + * + * @param listener a FullScreenEvent listener + * @return Registration object to allow removing the listener + */ + public Registration addFullScreenListener(ComponentEventListener listener) { + DomListenerRegistration registration = + this.getElement().addEventListener("fullscreenchange", ev -> { + this.getElement() + .executeJs( + "var isFullScreen = document.fullScreen ||\r\n" + + " document.mozFullScreen ||\r\n" + + " document.webkitIsFullScreen;\r\n" + + " return isFullScreen;") + .then(Boolean.class, isFullScreen -> listener + .onComponentEvent(new FullScreenEvent(this, true, isFullScreen))); + }); + return registration::remove; + } + + /** + * Event fired when the full screen mode changes on the map. + */ + public static class FullScreenEvent extends ComponentEvent { + + private boolean isFullScreen; + + /** + * Creates a new FullScreenEvent. + * + * @param source the source component + * @param fromClient whether the event originated from the client side + * @param isFullScreen the full screen state + */ + public FullScreenEvent(GoogleMap source, boolean fromClient, boolean isFullScreen) { + super(source, true); + this.isFullScreen = isFullScreen; + } + + /** + * Checks if the map is in full screen mode. + * + * @return true if the map is in full screen mode, false otherwise + */ + public boolean isFullScreen() { + return isFullScreen; + } + } + }