/** * Recalculate the height and width of a native scrollbar. */ private static void maybeRecalculateNativeScrollbarSize() { // Check if the size has already been calculated. if (nativeHeight > -1) { return; } // Create a scrollable element and attach it to the body. Element scrollable = Document.get().createDivElement(); scrollable.getStyle().setPosition(Position.ABSOLUTE); scrollable.getStyle().setTop(-1000.0, Unit.PX); scrollable.getStyle().setLeft(-1000.0, Unit.PX); scrollable.getStyle().setHeight(100.0, Unit.PX); scrollable.getStyle().setWidth(100.0, Unit.PX); scrollable.getStyle().setOverflow(Overflow.SCROLL); scrollable.getStyle().setProperty("direction", "rtl"); Document.get().getBody().appendChild(scrollable); // Add some content. Element content = Document.get().createDivElement(); content.setInnerText("content"); scrollable.appendChild(content); // Measure the height and width. nativeHeight = scrollable.getOffsetHeight() - scrollable.getClientHeight(); nativeWidth = scrollable.getOffsetWidth() - scrollable.getClientWidth(); nativeRtl = (content.getAbsoluteLeft() > scrollable.getAbsoluteLeft()); // Detach the scrollable element. scrollable.removeFromParent(); }
/** * Creates an Anchor widget that wraps an existing <a> element. * * This element must already be attached to the document. If the element is * removed from the document, you must call * {@link RootPanel#detachNow(Widget)}. * * @param element the element to be wrapped */ public static Anchor wrap(Element element) { // Assert that the element is attached. assert Document.get().getBody().isOrHasChild(element); Anchor anchor = new Anchor(element); // Mark it attached and remember it for cleanup. anchor.onAttach(); RootPanel.detachOnWindowClose(anchor); return anchor; }
/** * IE6 does not allow direct access to event handlers on the parent window, * so we must embed a script in the parent window that will set the event * handlers in the correct context. * * @param initFunc the string representation of the init function * @param cmd the command to execute the init function */ private void initHandler(String initFunc, ScheduledCommand cmd) { if (GWT.isClient()) { // Embed the init script on the page ScriptElement scriptElem = Document.get().createScriptElement(initFunc); Document.get().getBody().appendChild(scriptElem); // Initialize the handler cmd.execute(); // Remove the script element Document.get().getBody().removeChild(scriptElem); } }
Document.get().getScrollWidth()); int height = Math.max(Window.getClientHeight(), Document.get().getScrollHeight()); glassElem.getStyle().setHeight(height, Unit.PX); glassElem.getStyle().setWidth(width, Unit.PX); Document.get().getBody().appendChild(glassElem); mouseDown = false; glassElem.removeFromParent();
protected HtmlGraphics(HtmlPlatform.Config config) { Document doc = Document.get(); dummyCanvas = doc.createCanvasElement(); dummyCtx = dummyCanvas.getContext2d(); rootElement = doc.getElementById(config.rootId); if (rootElement == null) { rootElement = doc.createDivElement(); rootElement.setAttribute("style", "width: 640px; height: 480px"); doc.getBody().appendChild(rootElement); } else { rootElement.setInnerHTML(""); measureElement = doc.createDivElement(); measureElement.getStyle().setVisibility(Style.Visibility.HIDDEN); measureElement.getStyle().setPosition(Style.Position.ABSOLUTE); measureElement.getStyle().setTop(-500, Unit.PX); measureElement.getStyle().setOverflow(Style.Overflow.VISIBLE); measureElement.getStyle().setWhiteSpace(Style.WhiteSpace.NOWRAP);
@PostConstruct private void init() { popup = uiBinder.createAndBindUi(this); //Setup drop indicator if (dropTargetHighlight == null) { dropTargetHighlight = Document.get().createDivElement(); dropTargetHighlight.getStyle().setPosition(Style.Position.ABSOLUTE); dropTargetHighlight.getStyle().setVisibility(Visibility.HIDDEN); dropTargetHighlight.setClassName(WorkbenchResources.INSTANCE.CSS().dropTargetHighlight()); Document.get().getBody().appendChild(dropTargetHighlight); } north.ensureDebugId("CompassWidget-north"); south.ensureDebugId("CompassWidget-south"); east.ensureDebugId("CompassWidget-east"); west.ensureDebugId("CompassWidget-west"); centre.ensureDebugId("CompassWidget-centre"); }
@Override public void showDevMode() { final Element overlayDiv = Document.get().createDivElement(); final Element dialog = Document.get().createDivElement(); final Element onButton = createButton("Super Dev Mode On"); final Element offButton = createButton("Super Dev Mode Off"); final Element closeButton = createButton("Close Dialog"); overlayDiv.getStyle().setZIndex(1000); overlayDiv.getStyle().setPosition(Position.ABSOLUTE); overlayDiv.getStyle().setTop(0, Unit.PX); overlayDiv.getStyle().setLeft(0, Unit.PX); overlayDiv.getStyle().setRight(0, Unit.PX); overlayDiv.getStyle().setBackgroundColor("#000"); Document.get().getBody().appendChild(overlayDiv); dialog.getStyle().setPadding(1, Unit.EM); Document.get().getBody().appendChild(dialog);
protected LoadTracker() { if(Document.get().getElementById(m_trackerDivId) == null) { Element div = DOM.createDiv(); div.getStyle().setPosition(Position.ABSOLUTE); div.getStyle().setTop(0.0, Unit.PX); div.getStyle().setLeft(-9999.0, Unit.PX); div.getStyle().setVisibility(Visibility.HIDDEN); div.setId("loadTracker"); Document.get().getBody().appendChild(div); } }
rootLayer = new GroupLayerCanvas(createXform()); int rwidth = rootElement.getOffsetWidth(), rheight = rootElement.getOffsetHeight(); if (rwidth == 0 || rheight == 0) { Element rootClone = (Element) rootElement.cloneNode(false); Style style = rootClone.getStyle(); style.setPosition(Style.Position.ABSOLUTE); style.setDisplay(Style.Display.BLOCK); style.setTop(-9999, Style.Unit.PX); Document.get().getBody().appendChild(rootClone); rwidth = rootElement.getOffsetWidth(); rheight = rootElement.getOffsetHeight(); rootHeight = rheight; elem = Document.get().createCanvasElement(); elem.setWidth(rwidth); elem.setHeight(rheight);
Document.get().getScrollWidth()); int height = Math.max(Window.getClientHeight(), Document.get().getScrollHeight()); glassElem.getStyle().setHeight(height, Unit.PX); glassElem.getStyle().setWidth(width, Unit.PX); Document.get().getBody().appendChild(glassElem); event.preventDefault(); Document.get().getBody().appendChild(mouseTracker); break; mouseDown = false; glassElem.removeFromParent(); event.preventDefault(); mouseTracker.getStyle().setLeft(event.getClientX() - mouseTracker.getOffsetWidth() / 2, Unit.PX); mouseTracker.getStyle().setTop(event.getClientY() - mouseTracker.getOffsetHeight() / 2,
/** * Determine the thickness of a scroll-bar if it was visible. Assumes width of vertical scrollbar and height * of a horizontal scrollbar are the same. * @return The height in PX. */ public static int determineScrollbarThickness() { Element panel = DOM.createDiv(); panel.getStyle().setWidth(100, Unit.PX); panel.getStyle().setHeight(100, Unit.PX); panel.getStyle().setOverflow(Overflow.SCROLL); Document.get().getBody().appendChild(panel); int scrollbarHeight = panel.getOffsetHeight() - panel.getClientHeight(); Document.get().getBody().removeChild(panel); return scrollbarHeight; }
Document document = Document.get(); TextAreaElement element = document.createTextAreaElement(); style.setFontSize(12, Style.Unit.PT); style.setBorderWidth(0, Style.Unit.PX); style.setMargin(0, Style.Unit.PX); style.setPadding(0, Style.Unit.PX); element.setValue(text); Document.get().getBody().appendChild(element);
@Override protected void onDetach() { super.onDetach(); // Unhook the iframe's onLoad when detached. impl.unhookEvents(synthesizedFrame, getElement()); if (synthesizedFrame != null) { // And remove it from the document. Document.get().getBody().removeChild(synthesizedFrame); synthesizedFrame = null; } }
@Override protected int getNativeWidth() { Element e = DOM.createDiv(); e.setInnerText(getValue().get() != null ? getValue().get() : "I"); e.getStyle().setPosition(Style.Position.ABSOLUTE); Document.get().getBody().appendChild(e); int width = e.getOffsetWidth(); e.removeFromParent(); return width + MAGIC_PADDING; }
private <X> X doWithClone(Function<Element, X> callback) { Element clon = DOM.clone(control.getElement(), true); clon.getStyle().setPosition(Position.ABSOLUTE); clon.getStyle().clearPadding(); clon.getStyle().clearWidth(); clon.getStyle().clearHeight(); Document.get().getBody().appendChild(clon); X returnValue = callback.apply(clon); clon.removeFromParent(); return returnValue; } }
@Override public void onModuleLoad() { canvas = Document.get().createElement("canvas").cast(); Document.get().getBody().appendChild(canvas); canvas.setWidth(CANVAS_WIDTH); canvas.setHeight(CANVAS_HEIGHT); gl = WebGLRenderingContext.getContext(canvas); gl.viewport(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT); init(); new Timer() { @Override public void run() { draw(); } }.scheduleRepeating(100); }
@Override protected void onAttach() { super.onAttach(); if (frameName != null) { // Create and attach a hidden iframe to the body element. createFrame(); Document.get().getBody().appendChild(synthesizedFrame); } // Hook up the underlying iframe's onLoad event when attached to the DOM. // Making this connection only when attached avoids memory-leak issues. // The FormPanel cannot use the built-in GWT event-handling mechanism // because there is no standard onLoad event on iframes that works across // browsers. impl.hookEvents(synthesizedFrame, getElement(), this); }
@Override public void onResize(ResizeEvent event) { if (fullScreenWidth() == event.getWidth() && fullScreenHeight() == event.getHeight()) { float width = viewSize.width(), height = viewSize.height(); experimentalScale = Math.min(fullScreenWidth() / width, fullScreenHeight() / height); // less distance to the top int yOfs = (int) ((fullScreenHeight() - height * experimentalScale) / 3.f); int xOfs = (int) ((fullScreenWidth() - width * experimentalScale) / 2.f); rootElement.setAttribute("style", "width:" + experimentalScale * width + "px; " + "height:" + experimentalScale*height + "px; " + "position:absolute; left:" + xOfs + "px; top:" + yOfs); // This is needed to work around a focus bug in Chrome :( Window.alert("Switching to fullscreen mode."); Document.get().getBody().addClassName("fullscreen"); } else { experimentalScale = 1; rootElement.removeAttribute("style"); Document.get().getBody().removeClassName("fullscreen"); } }}); }
private static void ensureFrame() { com.google.gwt.dom.client.Element frame = Document.get().getElementById( "__printingFrame" ); if( frame == null ) { frame = DOM.createIFrame(); frame.setId( "__printingFrame" ); frame.setAttribute( "style", "width:0;height:0;border:0" ); Document.get().getBody().appendChild( frame ); } }
/** * Creates an xml block structure from a model, and injects it into the page. */ private XmlStructure createXml(ConversationView model) { String xml = XmlRenderer.render(new ViewIdMapper(ModelIdMapperImpl.create(model, "empty")), model); Element dom = Document.get().createElement("xml"); dom.setInnerHTML(xml); Document.get().getBody().appendChild(dom); return XmlStructure.create(XmlRenderer.ROOT_ID); }