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

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: mdjones' comments addressed 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..7c09b9ef19a933b3ae8184ac2470a4f50dac51fd
--- /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;
+ }
+
+ /**
+ * 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.
+ */
+ @Override
+ 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();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698