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

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

Issue 2638823002: Support <picture> in image extraction (Closed)
Patch Set: Created 3 years, 11 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/WebImage.java
diff --git a/java/org/chromium/distiller/webdocument/WebImage.java b/java/org/chromium/distiller/webdocument/WebImage.java
index c79d365ceccbe56576243d320490d028b5a9205f..329d4a58fd20b9c3c0a8b1bdf19d3b5c5d6c8b6e 100644
--- a/java/org/chromium/distiller/webdocument/WebImage.java
+++ b/java/org/chromium/distiller/webdocument/WebImage.java
@@ -17,7 +17,7 @@ import java.util.List;
* WebImage represents an image in the WebDocument potentially needing extraction.
*/
public class WebImage extends WebElement {
- // The main image element.
+ // The main image element. Could be <img>, or <picture> containing <img>.
Element imgElement;
// The absolute source of the image.
private String srcUrl;
@@ -26,7 +26,7 @@ public class WebImage extends WebElement {
// The original height of the image in pixels.
private int height;
// Cloned and processed element.
- private ImageElement clonedImg;
+ private Element clonedImg;
/**
* Build an image element.
@@ -46,19 +46,22 @@ public class WebImage extends WebElement {
}
private void cloneAndProcessNode() {
- ImageElement ie = ImageElement.as(Element.as(imgElement.cloneNode(false)));
- ie.setSrc(srcUrl);
- ie.setSrc(ie.getSrc());
- // If computed width or height is zero, do not override them
- // to keep them visible.
- if (width > 0 && height > 0) {
- ie.setWidth(width);
- ie.setHeight(height);
+ Element cloned = Element.as(imgElement.cloneNode(true));
+ if (imgElement.getTagName() == "IMG") {
+ ImageElement ie = ImageElement.as(cloned);
+ ie.setSrc(srcUrl);
+ // If computed width or height is zero, do not override them
+ // to keep them visible.
+ if (width > 0 && height > 0) {
+ ie.setWidth(width);
+ ie.setHeight(height);
+ }
+ DomUtil.stripImageElement(ie);
}
- DomUtil.makeSrcSetAbsolute(ie);
- DomUtil.stripImageElement(ie);
+ DomUtil.makeAllSrcAttributesAbsolute(cloned);
+ DomUtil.makeAllSrcSetAbsolute(cloned);
- clonedImg = ie;
+ clonedImg = cloned;
}
@Override
@@ -104,12 +107,14 @@ public class WebImage extends WebElement {
cloneAndProcessNode();
}
List<String> list = new ArrayList<>();
- list.add(srcUrl);
- list.addAll(DomUtil.getSrcSetUrls(clonedImg));
+ if (!srcUrl.isEmpty()) {
+ list.add(srcUrl);
mdjones 2017/01/17 17:41:47 nit: this can be in-lined, but it doesn't look lik
wychen 2017/01/18 17:29:54 Acknowledged.
+ }
+ list.addAll(DomUtil.getAllSrcSetUrls(clonedImg));
return list;
}
- protected ImageElement getProcessedNode() {
+ protected Element getProcessedNode() {
if (clonedImg == null) {
cloneAndProcessNode();
}

Powered by Google App Engine
This is Rietveld 408576698