protected Widget getContent(AssetContentItem contentItem) { // Add the content HTML contentHTML = new HTML(contentItem.getContent()); // So that lightbox centering in firefox works, enclose each sized <object> // with a div styled to exactly that size. NodeList<Element> objectElements = contentHTML.getElement().getElementsByTagName("object"); Document document = Document.get(); for (int i = 0, len = objectElements.getLength(); i < len; i++) { Element objectElement = objectElements.getItem(i); String width = objectElement.getAttribute("width"); String height = objectElement.getAttribute("height"); if (width.matches("[0-9]+%?") && height.matches("[0-9]+%?")) { DivElement div = document.createDivElement(); div.getStyle().setProperty("width", width + (width.endsWith("%") ? "" : "px")); div.getStyle().setProperty("height", height + (height.endsWith("%") ? "" : "px")); objectElement.getParentElement().replaceChild(div, objectElement); div.appendChild(objectElement); } } // In case there are images within the content, we should fire a PopupImageLoadedEvent // so that any popup window displaying this view has a chance to reposition itself. NodeList<Element> imageElements = contentHTML.getElement().getElementsByTagName("img"); for (int i = 0; i < imageElements.getLength(); i++) { ImageElement image = imageElements.getItem(i).cast(); addImageLoadHandler(image); } return contentHTML; }
@Test public void checkCreateElement() { Assert.assertEquals("a", d.createAnchorElement().getTagName()); Assert.assertEquals("area", d.createAreaElement().getTagName()); Assert.assertEquals("base", d.createBaseElement().getTagName()); Assert.assertEquals("body", d.createElement("body").getTagName()); Assert.assertEquals("br", d.createBRElement().getTagName()); Assert.assertEquals("div", d.createDivElement().getTagName()); Assert.assertEquals("dl", d.createDLElement().getTagName()); Assert.assertEquals("fieldset", d.createFieldSetElement().getTagName()); Assert.assertEquals("form", d.createFormElement().getTagName()); Assert.assertEquals("frame", d.createFrameElement().getTagName()); Assert.assertEquals("frameset", d.createFrameSetElement().getTagName()); Assert.assertEquals("head", d.createHeadElement().getTagName()); Assert.assertEquals("h1", d.createHElement(1).getTagName()); Assert.assertEquals("h2", d.createHElement(2).getTagName()); Assert.assertEquals("h3", d.createHElement(3).getTagName()); Assert.assertEquals("h4", d.createHElement(4).getTagName()); Assert.assertEquals("h5", d.createHElement(5).getTagName()); Assert.assertEquals("h6", d.createHElement(6).getTagName()); Assert.assertEquals("hr", d.createHRElement().getTagName()); Assert.assertEquals("iframe", d.createIFrameElement().getTagName()); Assert.assertEquals("img", d.createImageElement().getTagName()); Assert.assertEquals("input", d.createElement("input").getTagName()); Assert.assertEquals("label", d.createLabelElement().getTagName()); Assert.assertEquals("legend", d.createLegendElement().getTagName()); Assert.assertEquals("li", d.createLIElement().getTagName()); Assert.assertEquals("link", d.createLinkElement().getTagName()); Assert.assertEquals("map", d.createMapElement().getTagName()); Assert.assertEquals("meta", d.createMetaElement().getTagName()); Assert.assertEquals("ins", d.createInsElement().getTagName()); Assert.assertEquals("del", d.createDelElement().getTagName()); Assert.assertEquals("object", d.createObjectElement().getTagName()); Assert.assertEquals("ol", d.createOLElement().getTagName()); Assert.assertEquals("optgroup", d.createOptGroupElement().getTagName()); Assert.assertEquals("option", d.createOptionElement().getTagName()); Assert.assertEquals("p", d.createPElement().getTagName()); Assert.assertEquals("param", d.createParamElement().getTagName()); Assert.assertEquals("pre", d.createPreElement().getTagName()); Assert.assertEquals("q", d.createQElement().getTagName()); Assert.assertEquals("blockquote", d.createBlockQuoteElement().getTagName()); Assert.assertEquals("script", d.createScriptElement().getTagName()); Assert.assertEquals("select", d.createSelectElement().getTagName()); Assert.assertEquals("span", d.createSpanElement().getTagName()); Assert.assertEquals("style", d.createStyleElement().getTagName()); Assert.assertEquals("caption", d.createCaptionElement().getTagName()); Assert.assertEquals("td", d.createTDElement().getTagName()); Assert.assertEquals("th", d.createTHElement().getTagName()); Assert.assertEquals("col", d.createColElement().getTagName()); Assert.assertEquals("colgroup", d.createColGroupElement().getTagName()); Assert.assertEquals("table", d.createTableElement().getTagName()); Assert.assertEquals("tbody", d.createTBodyElement().getTagName()); Assert.assertEquals("tfoot", d.createTFootElement().getTagName()); Assert.assertEquals("thead", d.createTHeadElement().getTagName()); Assert.assertEquals("textarea", d.createTextAreaElement().getTagName()); Assert.assertEquals("title", d.createTitleElement().getTagName()); Assert.assertEquals("ul", d.createULElement().getTagName()); }
public GWTGraphics(final Panel panel, final LGame game, final GWTSetting cfg) { super(game, new GWTGL20(), new Scale(cfg.scaleFactor)); this.config = cfg; Document doc = Document.get(); this.dummyCanvas = doc.createCanvasElement(); this.dummyCtx = dummyCanvas.getContext2d(); Element root = panel.getElement(); this.rootElement = root; 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); root.appendChild(measureElement); mouseScale = config.scaleFactor / Loon.devicePixelRatio(); canvas = Document.get().createCanvasElement(); root.appendChild(canvas); if (config.scaling()) { setSize( config.width_zoom > 0 ? config.width_zoom : root.getOffsetWidth(), config.height_zoom > 0 ? config.height_zoom : root.getOffsetHeight()); } else { setSize( config.width > 0 ? config.width : root.getOffsetWidth(), config.height > 0 ? config.height : root.getOffsetHeight()); } WebGLContextAttributes attrs = WebGLContextAttributes.create(); attrs.setAntialias(config.antiAliasing); attrs.setStencil(config.stencil); attrs.setAlpha(config.transparentCanvas); attrs.setPremultipliedAlpha(config.premultipliedAlpha); attrs.setPreserveDrawingBuffer(config.preserveDrawingBuffer); WebGLRenderingContext glc = WebGLRenderingContext.getContext(canvas, attrs); if (glc == null) { throw new RuntimeException("Unable to create GL context"); } ((GWTGL20) gl).init(glc); if (config.scaling()) { glc.viewport(0, 0, config.width_zoom, config.height_zoom); } else { glc.viewport(0, 0, config.width, config.height); } if (config.fullscreen) { Window.addResizeHandler( new ResizeHandler() { @Override public void onResize(ResizeEvent event) { if (getScreenWidthJSNI() == event.getWidth() && getScreenHeightJSNI() == event.getHeight()) { float width = LSystem.viewSize.width(), height = LSystem.viewSize.height(); experimentalScale = Math.min(getScreenWidthJSNI() / width, getScreenHeightJSNI() / height); int yOfs = (int) ((getScreenHeightJSNI() - height * experimentalScale) / 3.f); int xOfs = (int) ((getScreenWidthJSNI() - width * experimentalScale) / 2.f); rootElement.setAttribute( "style", "width:" + experimentalScale * width + "px; " + "height:" + experimentalScale * height + "px; " + "position:absolute; left:" + xOfs + "px; top:" + yOfs); Document.get().getBody().addClassName("fullscreen"); } else { experimentalScale = 1; rootElement.removeAttribute("style"); Document.get().getBody().removeClassName("fullscreen"); } } }); } Loon.self.addHandler( new OrientationChangedHandler() { @Override public void onChanged(Orientation newOrientation) { int width = Loon.self.getContainerWidth(); int height = Loon.self.getContainerHeight(); game.log().info("update screen size width :" + width + " height :" + height); setSize(width, height); } }); }