1 /* 2 * PresentationFrame.java 3 * 4 * Copyright (C) 2021 by RStudio, PBC 5 * 6 * Unless you have received this program directly from RStudio pursuant 7 * to the terms of a commercial license agreement with RStudio, then 8 * this program is licensed to you under the terms of version 3 of the 9 * GNU Affero General Public License. This program is distributed WITHOUT 10 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 12 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. 13 * 14 */ 15 16 package org.rstudio.studio.client.workbench.views.presentation; 17 18 import org.rstudio.core.client.StringUtil; 19 import org.rstudio.core.client.dom.WindowEx; 20 import org.rstudio.core.client.widget.AnchorableFrame; 21 22 import com.google.gwt.core.client.JavaScriptObject; 23 import com.google.gwt.dom.client.Element; 24 import com.google.gwt.event.dom.client.LoadEvent; 25 import com.google.gwt.event.dom.client.LoadHandler; 26 import com.google.gwt.user.client.ui.HasText; 27 28 public class PresentationFrame extends AnchorableFrame 29 { PresentationFrame(boolean autoFocus)30 public PresentationFrame(boolean autoFocus) 31 { 32 this(autoFocus, false); 33 } 34 PresentationFrame(boolean autoFocus, boolean allowFullScreen)35 public PresentationFrame(boolean autoFocus, 36 boolean allowFullScreen) 37 { 38 this(autoFocus, allowFullScreen, null); 39 } 40 PresentationFrame(boolean autoFocus, boolean allowFullScreen, final HasText titleWidget)41 public PresentationFrame(boolean autoFocus, 42 boolean allowFullScreen, 43 final HasText titleWidget) 44 { 45 super("Presentation Frame", autoFocus); 46 47 // allow full-screen view of iframe 48 if (allowFullScreen) 49 { 50 Element el = getElement(); 51 el.setAttribute("webkitallowfullscreen", ""); 52 el.setAttribute("mozallowfullscreen", ""); 53 el.setAttribute("allowfullscreen", ""); 54 } 55 56 addLoadHandler(new LoadHandler() { 57 58 @Override 59 public void onLoad(LoadEvent event) 60 { 61 // set title 62 title_ = StringUtil.notNull( 63 getWindow().getDocument().getTitle()); 64 65 if (titleWidget != null) 66 titleWidget.setText(title_); 67 } 68 }); 69 } 70 getFrameTitle()71 public String getFrameTitle() 72 { 73 return title_; 74 } 75 clear()76 public void clear() 77 { 78 getWindow().replaceLocationHref("about:blank"); 79 } 80 home()81 public void home() 82 { 83 Reveal.fromWindow(getWindow()).home(); 84 } 85 slide(int index)86 public void slide(int index) 87 { 88 Reveal.fromWindow(getWindow()).slide(index); 89 } 90 next()91 public void next() 92 { 93 Reveal.fromWindow(getWindow()).next(); 94 } 95 prev()96 public void prev() 97 { 98 Reveal.fromWindow(getWindow()).prev(); 99 } 100 101 private static class Reveal extends JavaScriptObject 102 { Reveal()103 protected Reveal() 104 { 105 } 106 fromWindow(WindowEx window)107 public static final native Reveal fromWindow(WindowEx window) /*-{ 108 return window.Reveal; 109 }-*/; 110 home()111 public final native void home() /*-{ 112 this.slide(0); 113 }-*/; 114 slide(int index)115 public final native void slide(int index) /*-{ 116 this.slide(index); 117 }-*/; 118 next()119 public final native void next() /*-{ 120 this.next(); 121 }-*/; 122 prev()123 public final native void prev() /*-{ 124 this.prev(); 125 }-*/; 126 } 127 128 129 private String title_ = ""; 130 131 } 132