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

Side by Side Diff: java/org/chromium/distiller/DomUtil.java

Issue 2203563002: Extract image URLs in srcset as well (Closed) Base URL: git@github.com:chromium/dom-distiller.git@master
Patch Set: minor fixes 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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; 5 package org.chromium.distiller;
6 6
7 import com.google.gwt.core.client.JsArray; 7 import com.google.gwt.core.client.JsArray;
8 import com.google.gwt.core.client.JsArrayString; 8 import com.google.gwt.core.client.JsArrayString;
9 import com.google.gwt.dom.client.AnchorElement; 9 import com.google.gwt.dom.client.AnchorElement;
10 import com.google.gwt.dom.client.Document; 10 import com.google.gwt.dom.client.Document;
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 if (size.isEmpty()) continue; 341 if (size.isEmpty()) continue;
342 String[] comp = size.split(" "); 342 String[] comp = size.split(" ");
343 ie.setSrc(comp[0]); 343 ie.setSrc(comp[0]);
344 comp[0] = ie.getSrc(); 344 comp[0] = ie.getSrc();
345 sizes[i] = StringUtil.join(comp, " "); 345 sizes[i] = StringUtil.join(comp, " ");
346 } 346 }
347 ie.setAttribute("srcset", StringUtil.join(sizes, ", ")); 347 ie.setAttribute("srcset", StringUtil.join(sizes, ", "));
348 ie.setSrc(oldsrc); 348 ie.setSrc(oldsrc);
349 } 349 }
350 350
351 public static List<String> getSrcSetUrls(ImageElement ie) {
352 List<String> list = new ArrayList<>();
353 String srcset = ie.getAttribute("srcset");
354 if (srcset == "") {
mdjones 2016/08/01 21:14:35 srcset.isEmpty() or .equals please.
wychen 2016/08/01 21:35:15 Done.
355 return list;
356 }
357
358 String[] sizes = StringUtil.jsSplit(srcset, ",");
359 for(int i = 0; i < sizes.length; i++) {
360 String size = StringUtil.jsTrim(sizes[i]);
361 if (size.isEmpty()) continue;
362 String[] comp = size.split(" ");
363 list.add(comp[0]);
364 }
365 return list;
366 }
367
351 public static void stripImageElements(Node root) { 368 public static void stripImageElements(Node root) {
352 if (root.getNodeType() == Node.ELEMENT_NODE) { 369 if (root.getNodeType() == Node.ELEMENT_NODE) {
353 Element element = Element.as(root); 370 Element element = Element.as(root);
354 if (element.getTagName().equals("IMG")) { 371 if (element.getTagName().equals("IMG")) {
355 stripImageElement(ImageElement.as(element)); 372 stripImageElement(ImageElement.as(element));
356 } 373 }
357 } 374 }
358 NodeList<Element> imgs = DomUtil.querySelectorAll(root, "IMG"); 375 NodeList<Element> imgs = DomUtil.querySelectorAll(root, "IMG");
359 for (int i = 0; i < imgs.getLength(); i++) { 376 for (int i = 0; i < imgs.getLength(); i++) {
360 stripImageElement(ImageElement.as(imgs.getItem(i))); 377 stripImageElement(ImageElement.as(imgs.getItem(i)));
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 }-*/; 541 }-*/;
525 542
526 public static native Document createHTMLDocument(Document doc) /*-{ 543 public static native Document createHTMLDocument(Document doc) /*-{
527 return doc.implementation.createHTMLDocument(); 544 return doc.implementation.createHTMLDocument();
528 }-*/; 545 }-*/;
529 546
530 public static native Element getFirstElementChild(Document document) /*-{ 547 public static native Element getFirstElementChild(Document document) /*-{
531 return document.firstElementChild; 548 return document.firstElementChild;
532 }-*/; 549 }-*/;
533 } 550 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698