Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Unified Diff: java/org/chromium/distiller/webdocument/WebFigure.java

Issue 2020403002: Add support for figure element (Closed) Base URL: https://github.com/chromium/dom-distiller.git@master
Patch Set: Handling plain texts with generateOutputFromTree. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698