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.extractors.embeds; | 5 package org.chromium.distiller.extractors.embeds; |
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 org.chromium.distiller.webdocument.WebImage; | 9 import org.chromium.distiller.webdocument.WebImage; |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 public Set<String> getRelevantTagNames() { | 26 public Set<String> getRelevantTagNames() { |
27 return relevantTags; | 27 return relevantTags; |
28 } | 28 } |
29 | 29 |
30 @Override | 30 @Override |
31 public WebImage extract(Element e) { | 31 public WebImage extract(Element e) { |
32 if (!relevantTags.contains(e.getTagName())) { | 32 if (!relevantTags.contains(e.getTagName())) { |
33 return null; | 33 return null; |
34 } | 34 } |
35 String imgSrc = ""; | 35 String imgSrc = ""; |
| 36 // Getting OffSetWidth/Height as default values, even they are |
| 37 // affected by padding, border, etc. |
| 38 int width = e.getOffsetWidth(); |
| 39 int height = e.getOffsetHeight(); |
36 if ("IMG".equals(e.getTagName())) { | 40 if ("IMG".equals(e.getTagName())) { |
37 // This will get the absolute URL of the image. | 41 // This will get the absolute URL of the image and |
38 imgSrc = ImageElement.as(e).getSrc(); | 42 // the displayed image dimension. |
| 43 ImageElement imageElement = ImageElement.as(e); |
| 44 imgSrc = imageElement.getSrc(); |
| 45 // As an ImageElement is manipulated here, it is possible |
| 46 // to get the real dimensions. |
| 47 width = imageElement.getWidth(); |
| 48 height = imageElement.getHeight(); |
39 } | 49 } |
40 | 50 |
41 return new WebImage(e, e.getOffsetWidth(), e.getOffsetHeight(), imgSrc); | 51 return new WebImage(e, width, height, imgSrc); |
42 } | 52 } |
43 } | 53 } |
OLD | NEW |