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..6d1d59411c6804b8045380786962df34ee0fb4a4 |
| --- /dev/null |
| +++ b/java/org/chromium/distiller/webdocument/WebFigure.java |
| @@ -0,0 +1,47 @@ |
| +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 html figure tag which contains an image and |
|
wychen
2016/08/05 02:13:03
... represents a figure element, containing an ima
|
| + * may or may not contain 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 |
| + /** |
| + * WebFigure extends WebImage so it can use WebImage generated output |
| + * and just handle he caption since an html figure is basically a |
|
wychen
2016/08/05 02:13:03
the
|
| + * placeholder for an image and a caption. |
| + */ |
| + public String generateOutput(boolean textOnly) { |
| + String caption = DomUtil.generateOutputFromTree(figCaption, textOnly); |
| + if (textOnly) return caption; |
| + |
| + Element figure = Document.get().createElement("FIGURE"); |
| + figure.setInnerHTML(super.generateOutput(false)); |
|
wychen
2016/08/05 02:13:03
Could you rebase and add to WebImage:
protected Im
|
| + if (!figCaption.getInnerHTML().isEmpty()) { |
| + Element container = Document.get().createElement("DIV"); |
|
wychen
2016/08/05 02:13:03
We could just use:
figure.appendChild(caption)
|
| + container.setInnerHTML(caption); |
| + figure.appendChild(container.getChild(0)); |
| + } |
| + return figure.getString(); |
| + } |
| +} |