Chromium Code Reviews| 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 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 } | 467 } |
| 468 | 468 |
| 469 /** | 469 /** |
| 470 * Strips all "target" attributes from anchor nodes in the tree rooted at |r ootNode| | 470 * Strips all "target" attributes from anchor nodes in the tree rooted at |r ootNode| |
| 471 */ | 471 */ |
| 472 public static void stripTargetAttributes(Node rootNode) { | 472 public static void stripTargetAttributes(Node rootNode) { |
| 473 stripAttributeFromTags(rootNode, "TARGET", new String[]{"A"}); | 473 stripAttributeFromTags(rootNode, "TARGET", new String[]{"A"}); |
| 474 } | 474 } |
| 475 | 475 |
| 476 /** | 476 /** |
| 477 * Strips unwanted classNames from all nodes in the tree rooted at |root|. | |
|
mdjones
2016/10/07 23:03:37
Can you mention here and in the CL description wha
wychen
2016/10/07 23:11:52
Will do.
wychen
2016/10/07 23:32:20
Done.
| |
| 478 */ | |
| 479 public static void stripUnwantedClassNames(Node root) { | |
| 480 if (root.getNodeType() == Node.ELEMENT_NODE) { | |
| 481 Element element = Element.as(root); | |
| 482 if (element.hasAttribute("class")) { | |
| 483 stripUnwantedClassName(element); | |
| 484 } | |
| 485 } | |
| 486 NodeList<Element> elems = DomUtil.querySelectorAll(root, "[class]"); | |
|
mdjones
2016/10/07 23:03:37
Why not select all elements and iterate over the r
wychen
2016/10/07 23:11:53
Not all elements have class attribute, so skipping
| |
| 487 for (int i = 0; i < elems.getLength(); i++) { | |
| 488 stripUnwantedClassName(elems.getItem(i)); | |
| 489 } | |
| 490 } | |
| 491 | |
| 492 public static void stripUnwantedClassName(Element elem) { | |
| 493 if (elem.getClassName().contains("caption")) { | |
| 494 elem.setClassName("caption"); | |
| 495 } else { | |
| 496 elem.removeAttribute("class"); | |
| 497 } | |
| 498 } | |
| 499 | |
| 500 /** | |
| 477 * Get a list of relevant nodes from a subtree. | 501 * Get a list of relevant nodes from a subtree. |
| 478 * @param root The root of the subtree. | 502 * @param root The root of the subtree. |
| 479 * @return A list of relevant nodes. | 503 * @return A list of relevant nodes. |
| 480 */ | 504 */ |
| 481 public static List<Node> getOutputNodes(Node root) { | 505 public static List<Node> getOutputNodes(Node root) { |
| 482 final List<Node> nodes = new ArrayList<>(); | 506 final List<Node> nodes = new ArrayList<>(); |
| 483 new DomWalker(new DomWalker.Visitor() { | 507 new DomWalker(new DomWalker.Visitor() { |
| 484 @Override | 508 @Override |
| 485 public boolean visit(Node n) { | 509 public boolean visit(Node n) { |
| 486 switch (n.getNodeType()) { | 510 switch (n.getNodeType()) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 }-*/; | 560 }-*/; |
| 537 | 561 |
| 538 public static native Document createHTMLDocument(Document doc) /*-{ | 562 public static native Document createHTMLDocument(Document doc) /*-{ |
| 539 return doc.implementation.createHTMLDocument(); | 563 return doc.implementation.createHTMLDocument(); |
| 540 }-*/; | 564 }-*/; |
| 541 | 565 |
| 542 public static native Element getFirstElementChild(Document document) /*-{ | 566 public static native Element getFirstElementChild(Document document) /*-{ |
| 543 return document.firstElementChild; | 567 return document.firstElementChild; |
| 544 }-*/; | 568 }-*/; |
| 545 } | 569 } |
| OLD | NEW |