Search in sources :

Example 1 with ImageElement

use of org.gwtproject.dom.client.ImageElement in project gwtproject by treblereel.

the class ImageLoadingCellTest method testRenderNegativeIndex.

@Override
public void testRenderNegativeIndex() {
    Cell<String> cell = createCell();
    String value = createCellValue();
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    Context context = new Context(-1, -1, null);
    cell.render(context, value, sb);
    // Render the html.
    Element elem = Document.get().createDivElement();
    elem.setInnerSafeHtml(sb.toSafeHtml());
    // Verify the image.
    assertEquals(2, elem.getChildCount());
    Element imgWrapper = elem.getChild(1).cast();
    ImageElement img = imgWrapper.getFirstChildElement().cast();
    assertEquals("img", img.getTagName().toLowerCase(Locale.ROOT));
    assertTrue(img.getSrc().toLowerCase(Locale.ROOT).endsWith("test.png"));
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) ImageElement(org.gwtproject.dom.client.ImageElement) ImageElement(org.gwtproject.dom.client.ImageElement) Element(org.gwtproject.dom.client.Element) SafeHtmlBuilder(org.gwtproject.safehtml.shared.SafeHtmlBuilder)

Example 2 with ImageElement

use of org.gwtproject.dom.client.ImageElement in project gwtproject by treblereel.

the class ImageLoadingCellTest method testRender.

@Override
public void testRender() {
    Cell<String> cell = createCell();
    String value = createCellValue();
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    Context context = new Context(0, 0, null);
    cell.render(context, value, sb);
    // Render the html.
    Element elem = Document.get().createDivElement();
    elem.setInnerSafeHtml(sb.toSafeHtml());
    // Verify the image.
    assertEquals(2, elem.getChildCount());
    Element imgWrapper = elem.getChild(1).cast();
    ImageElement img = imgWrapper.getFirstChildElement().cast();
    assertEquals("img", img.getTagName().toLowerCase(Locale.ROOT));
    assertTrue(img.getSrc().toLowerCase(Locale.ROOT).endsWith("test.png"));
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) ImageElement(org.gwtproject.dom.client.ImageElement) ImageElement(org.gwtproject.dom.client.ImageElement) Element(org.gwtproject.dom.client.Element) SafeHtmlBuilder(org.gwtproject.safehtml.shared.SafeHtmlBuilder)

Example 3 with ImageElement

use of org.gwtproject.dom.client.ImageElement in project gwtproject by treblereel.

the class Image method prefetch.

/**
 * Causes the browser to pre-fetch the image at a given URL.
 *
 * @param url the URL of the image to be prefetched
 */
public static void prefetch(String url) {
    ImageElement img = Document.get().createImageElement();
    img.setSrc(url);
    prefetchImages.put(url, img);
}
Also used : ImageElement(org.gwtproject.dom.client.ImageElement)

Aggregations

ImageElement (org.gwtproject.dom.client.ImageElement)3 Context (org.gwtproject.cell.client.Cell.Context)2 Element (org.gwtproject.dom.client.Element)2 SafeHtmlBuilder (org.gwtproject.safehtml.shared.SafeHtmlBuilder)2