Chromium Code Reviews| Index: java/org/chromium/distiller/webdocument/WebFigure.java |
| diff --git a/java/org/chromium/distiller/webdocument/WebFigure.java b/java/org/chromium/distiller/webdocument/WebFigure.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bdc525490dc0d8ca0cdd06b53abdfd301bf2178a |
| --- /dev/null |
| +++ b/java/org/chromium/distiller/webdocument/WebFigure.java |
| @@ -0,0 +1,44 @@ |
| +package org.chromium.distiller.webdocument; |
| + |
| +import com.google.gwt.dom.client.Document; |
| +import com.google.gwt.dom.client.Element; |
| +import org.chromium.distiller.DomUtil; |
| + |
| +/** |
| + * WebFigure represents a figure element, containing an image and optionally a caption. |
| + */ |
| +public class WebFigure extends WebImage { |
| + |
| + private Element figCaption; |
| + |
| + /** |
| + * Build a figure element. |
| + * @param e The element detected as an image. |
| + * @param w The original width of the image. |
| + * @param h The original height of the image. |
| + * @param src The source URL of the image being extracted. |
| + * @param caption The element containing the caption of the image. |
| + */ |
| + public WebFigure(Element e, int w, int h, String src, Element caption) { |
| + super(e, w, h, src); |
| + figCaption = caption; |
| + } |
| + |
| + @Override |
|
mdjones
2016/08/05 17:35:15
Move @Override under documentation.
|
| + /** |
| + * WebFigure extends WebImage so it can use WebImage generated output |
| + * and just handle the caption since an html figure is basically a |
| + * placeholder for an image and a caption. |
| + */ |
| + public String generateOutput(boolean textOnly) { |
| + Element figcaption = DomUtil.cloneAndProcessTree(figCaption); |
| + if (textOnly) return figcaption.getInnerText(); |
| + |
| + Element figure = Document.get().createElement("FIGURE"); |
| + figure.appendChild(getProcessedNode()); |
| + if (!figCaption.getInnerHTML().isEmpty()) { |
| + figure.appendChild(figcaption); |
| + } |
| + return figure.getString(); |
| + } |
| +} |