| OLD | NEW |
| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 NodeList<Element> imgs = DomUtil.querySelectorAll(root, "IMG"); | 306 NodeList<Element> imgs = DomUtil.querySelectorAll(root, "IMG"); |
| 307 for (int i = 0; i < imgs.getLength(); i++) { | 307 for (int i = 0; i < imgs.getLength(); i++) { |
| 308 stripImageElement(ImageElement.as(imgs.getItem(i))); | 308 stripImageElement(ImageElement.as(imgs.getItem(i))); |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 | 311 |
| 312 /** | 312 /** |
| 313 * Only keep some attributes for image elements. | 313 * Only keep some attributes for image elements. |
| 314 * @param ie The image element to strip in-place. | 314 * @param imgElement The image element to strip in-place. |
| 315 */ | 315 */ |
| 316 public static void stripImageElement(ImageElement imgElement) { | 316 public static void stripImageElement(ImageElement imgElement) { |
| 317 JsArray<Node> attrs = getAttributes(imgElement); | 317 JsArray<Node> attrs = getAttributes(imgElement); |
| 318 for (int i = 0; i < attrs.length(); ) { | 318 for (int i = 0; i < attrs.length(); ) { |
| 319 String name = attrs.get(i).getNodeName(); | 319 String name = attrs.get(i).getNodeName(); |
| 320 if (!"src".equals(name) && | 320 if (!"src".equals(name) && |
| 321 !"alt".equals(name) && | 321 !"alt".equals(name) && |
| 322 !"srcset".equals(name) && | 322 !"srcset".equals(name) && |
| 323 !"dir".equals(name) && | 323 !"dir".equals(name) && |
| 324 !"title".equals(name)) { | 324 !"title".equals(name)) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 345 if (elementsWithSrc[key].src) { | 345 if (elementsWithSrc[key].src) { |
| 346 elementsWithSrc[key].src = elementsWithSrc[key].src; | 346 elementsWithSrc[key].src = elementsWithSrc[key].src; |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 }-*/; | 349 }-*/; |
| 350 | 350 |
| 351 /** | 351 /** |
| 352 * Strips some attribute from certain tags in the tree rooted at |rootNode|,
including root. | 352 * Strips some attribute from certain tags in the tree rooted at |rootNode|,
including root. |
| 353 * @param tagNames The tag names to be processed. ["*"] means all. | 353 * @param tagNames The tag names to be processed. ["*"] means all. |
| 354 */ | 354 */ |
| 355 @SuppressWarnings("unused") |
| 355 public static void stripAttributeFromTags(Node rootNode, String attribute, S
tring[] tagNames) { | 356 public static void stripAttributeFromTags(Node rootNode, String attribute, S
tring[] tagNames) { |
| 356 Element root = Element.as(rootNode); | 357 Element root = Element.as(rootNode); |
| 357 for (String tag: tagNames) { | 358 for (String tag: tagNames) { |
| 358 if (root.getTagName().equals(tag) || tag.equals("*")) { | 359 if (root.getTagName().equals(tag) || tag.equals("*")) { |
| 359 root.removeAttribute(attribute); | 360 root.removeAttribute(attribute); |
| 360 } | 361 } |
| 361 } | 362 } |
| 362 | 363 |
| 363 for (String tag: tagNames) { | 364 for (String tag: tagNames) { |
| 364 tag += "[" + attribute + "]"; | 365 tag += "[" + attribute + "]"; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 }-*/; | 456 }-*/; |
| 456 | 457 |
| 457 public static native Document createHTMLDocument(Document doc) /*-{ | 458 public static native Document createHTMLDocument(Document doc) /*-{ |
| 458 return doc.implementation.createHTMLDocument(); | 459 return doc.implementation.createHTMLDocument(); |
| 459 }-*/; | 460 }-*/; |
| 460 | 461 |
| 461 public static native Element getFirstElementChild(Document document) /*-{ | 462 public static native Element getFirstElementChild(Document document) /*-{ |
| 462 return document.firstElementChild; | 463 return document.firstElementChild; |
| 463 }-*/; | 464 }-*/; |
| 464 } | 465 } |
| OLD | NEW |