| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.distiller.webdocument; | 5 package org.chromium.distiller.webdocument; |
| 6 | 6 |
| 7 import com.google.gwt.dom.client.Element; | 7 import com.google.gwt.dom.client.Element; |
| 8 import com.google.gwt.dom.client.ImageElement; | 8 import com.google.gwt.dom.client.ImageElement; |
| 9 import com.google.gwt.dom.client.NodeList; | 9 import com.google.gwt.dom.client.NodeList; |
| 10 | 10 |
| 11 import org.chromium.distiller.DomUtil; | 11 import org.chromium.distiller.DomUtil; |
| 12 | 12 |
| 13 import java.util.ArrayList; | 13 import java.util.ArrayList; |
| 14 import java.util.List; | 14 import java.util.List; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * WebImage represents an image in the WebDocument potentially needing extractio
n. | 17 * WebImage represents an image in the WebDocument potentially needing extractio
n. |
| 18 */ | 18 */ |
| 19 public class WebImage extends WebElement { | 19 public class WebImage extends WebElement { |
| 20 // The main image element. Could be <img>, or <picture> containing <img>. | 20 // The main image element. Could be <img>, or <picture> containing <img>. |
| 21 Element imgElement; | 21 Element imgElement; |
| 22 // The absolute source of the image. | 22 // The source of the image. Could be relative before cloneAndProcessNode(). |
| 23 private String srcUrl; | 23 private String srcUrl; |
| 24 // The original width of the image in pixels. | 24 // The original width of the image in pixels. |
| 25 private int width; | 25 private int width; |
| 26 // The original height of the image in pixels. | 26 // The original height of the image in pixels. |
| 27 private int height; | 27 private int height; |
| 28 // Cloned and processed element. | 28 // Cloned and processed element. |
| 29 private Element clonedImg; | 29 private Element clonedImg; |
| 30 | 30 |
| 31 private static final String[] LAZY_SRCSET_ATTRIBUTES = | 31 private static final String[] LAZY_SRCSET_ATTRIBUTES = |
| 32 {"data-srcset"}; | 32 {"data-srcset"}; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 47 srcUrl = ""; | 47 srcUrl = ""; |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 private void cloneAndProcessNode() { | 51 private void cloneAndProcessNode() { |
| 52 Element cloned = Element.as(imgElement.cloneNode(true)); | 52 Element cloned = Element.as(imgElement.cloneNode(true)); |
| 53 ImageElement ie = ImageElement.as( | 53 ImageElement ie = ImageElement.as( |
| 54 DomUtil.getFirstElementByTagNameInc(cloned, "IMG")); | 54 DomUtil.getFirstElementByTagNameInc(cloned, "IMG")); |
| 55 if (!srcUrl.isEmpty()) { | 55 if (!srcUrl.isEmpty()) { |
| 56 ie.setSrc(srcUrl); | 56 ie.setSrc(srcUrl); |
| 57 srcUrl = ie.getSrc(); |
| 57 } | 58 } |
| 58 // If computed width or height is zero, do not override them | 59 // If computed width or height is zero, do not override them |
| 59 // to keep them visible. | 60 // to keep them visible. |
| 60 if (width > 0 && height > 0) { | 61 if (width > 0 && height > 0) { |
| 61 ie.setWidth(width); | 62 ie.setWidth(width); |
| 62 ie.setHeight(height); | 63 ie.setHeight(height); |
| 63 } | 64 } |
| 64 DomUtil.stripImageElement(ie); | 65 DomUtil.stripImageElement(ie); |
| 65 | 66 |
| 66 NodeList<Element> srcs = cloned.getElementsByTagName("SOURCE"); | 67 NodeList<Element> srcs = cloned.getElementsByTagName("SOURCE"); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 return list; | 132 return list; |
| 132 } | 133 } |
| 133 | 134 |
| 134 protected Element getProcessedNode() { | 135 protected Element getProcessedNode() { |
| 135 if (clonedImg == null) { | 136 if (clonedImg == null) { |
| 136 cloneAndProcessNode(); | 137 cloneAndProcessNode(); |
| 137 } | 138 } |
| 138 return clonedImg; | 139 return clonedImg; |
| 139 } | 140 } |
| 140 } | 141 } |
| OLD | NEW |