Chromium Code Reviews| 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.Document; | 7 import com.google.gwt.dom.client.Document; |
| 8 import com.google.gwt.dom.client.Element; | 8 import com.google.gwt.dom.client.Element; |
| 9 import com.google.gwt.dom.client.ImageElement; | 9 import com.google.gwt.dom.client.ImageElement; |
| 10 | 10 |
| 11 import org.chromium.distiller.DomUtil; | 11 import org.chromium.distiller.DomUtil; |
| 12 | 12 |
| 13 import java.util.ArrayList; | |
| 14 import java.util.List; | |
| 15 | |
| 13 /** | 16 /** |
| 14 * WebImage represents an image in the WebDocument potentially needing extractio n. | 17 * WebImage represents an image in the WebDocument potentially needing extractio n. |
| 15 */ | 18 */ |
| 16 public class WebImage extends WebElement { | 19 public class WebImage extends WebElement { |
| 17 // The main image element. | 20 // The main image element. |
| 18 Element imgElement; | 21 Element imgElement; |
| 19 // The absolute source of the image. | 22 // The absolute source of the image. |
| 20 private String srcUrl; | 23 private String srcUrl; |
| 21 // The original width of the image in pixels. | 24 // The original width of the image in pixels. |
| 22 private int width; | 25 private int width; |
| 23 // The original height of the image in pixels. | 26 // The original height of the image in pixels. |
| 24 private int height; | 27 private int height; |
| 28 // The list of image URLs. | |
| 29 private List<String> list; | |
| 25 | 30 |
| 26 /** | 31 /** |
| 27 * Build an image element. | 32 * Build an image element. |
| 28 * @param e The element detected as an image. | 33 * @param e The element detected as an image. |
| 29 * @param w The original width of the image. | 34 * @param w The original width of the image. |
| 30 * @param h The original height of the image. | 35 * @param h The original height of the image. |
| 31 * @param src The source URL of the image being extracted. | 36 * @param src The source URL of the image being extracted. |
| 32 */ | 37 */ |
| 33 public WebImage(Element e, int w, int h, String src) { | 38 public WebImage(Element e, int w, int h, String src) { |
| 34 imgElement = e; | 39 imgElement = e; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 49 ie.setSrc(ie.getSrc()); | 54 ie.setSrc(ie.getSrc()); |
| 50 // If computed width or height is zero, do not override them | 55 // If computed width or height is zero, do not override them |
| 51 // to keep them visible. | 56 // to keep them visible. |
| 52 if (width > 0 && height > 0) { | 57 if (width > 0 && height > 0) { |
| 53 ie.setWidth(width); | 58 ie.setWidth(width); |
| 54 ie.setHeight(height); | 59 ie.setHeight(height); |
| 55 } | 60 } |
| 56 DomUtil.makeSrcSetAbsolute(ie); | 61 DomUtil.makeSrcSetAbsolute(ie); |
| 57 DomUtil.stripImageElement(ie); | 62 DomUtil.stripImageElement(ie); |
| 58 | 63 |
| 64 list = new ArrayList<>(); | |
| 65 list.add(srcUrl); | |
| 66 list.addAll(DomUtil.getSrcSetUrls(ie)); | |
| 67 | |
| 59 Element container = Document.get().createDivElement(); | 68 Element container = Document.get().createDivElement(); |
| 60 container.appendChild(ie); | 69 container.appendChild(ie); |
| 61 return container.getInnerHTML(); | 70 return container.getInnerHTML(); |
| 62 } | 71 } |
| 63 | 72 |
| 64 /** | 73 /** |
| 65 * Get the image element of this WebImage. | 74 * Get the image element of this WebImage. |
| 66 * @return Image element or null. | 75 * @return Image element or null. |
| 67 */ | 76 */ |
| 68 public Element getImageNode() { | 77 public Element getImageNode() { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 79 | 88 |
| 80 /** | 89 /** |
| 81 * Get the height of this image in pixels. | 90 * Get the height of this image in pixels. |
| 82 * @return The height of this image in pixels. | 91 * @return The height of this image in pixels. |
| 83 */ | 92 */ |
| 84 public int getHeight() { | 93 public int getHeight() { |
| 85 return height; | 94 return height; |
| 86 } | 95 } |
| 87 | 96 |
| 88 /** | 97 /** |
| 89 * Get the source URL of this image. | 98 * Get the list of source URLs of this image. |
| 90 * @return Source URL or an empty string. | 99 * It's more efficient to call after generateOutput(). |
| 100 * @return Source URLs or an empty List. | |
| 91 */ | 101 */ |
| 92 public String getSrc() { | 102 public List<String> getUrlList() { |
| 93 return srcUrl; | 103 if (list == null) { |
| 104 generateOutput(false); | |
|
wychen
2016/08/01 20:59:20
This feels entangled. :(
mdjones
2016/08/01 21:14:35
Can we instead cut the top part of generateOutput
wychen
2016/08/01 21:35:15
Done.
| |
| 105 } | |
| 106 return list; | |
| 94 } | 107 } |
| 95 } | 108 } |
| OLD | NEW |