| 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 return ""; | 206 return ""; |
| 207 } | 207 } |
| 208 | 208 |
| 209 NodeTree expanded = NodeListExpander.expand(outputNodes); | 209 NodeTree expanded = NodeListExpander.expand(outputNodes); |
| 210 Node clonedSubtree = expanded.cloneSubtreeRetainDirection(); | 210 Node clonedSubtree = expanded.cloneSubtreeRetainDirection(); |
| 211 | 211 |
| 212 if (clonedSubtree.getNodeType() != Node.ELEMENT_NODE) return ""; | 212 if (clonedSubtree.getNodeType() != Node.ELEMENT_NODE) return ""; |
| 213 | 213 |
| 214 stripIds(clonedSubtree); | 214 stripIds(clonedSubtree); |
| 215 makeAllLinksAbsolute(clonedSubtree); | 215 makeAllLinksAbsolute(clonedSubtree); |
| 216 stripTargetAttributes(clonedSubtree); |
| 216 stripFontColorAttributes(clonedSubtree); | 217 stripFontColorAttributes(clonedSubtree); |
| 217 stripTableBackgroundColorAttributes(clonedSubtree); | 218 stripTableBackgroundColorAttributes(clonedSubtree); |
| 218 stripStyleAttributes(clonedSubtree); | 219 stripStyleAttributes(clonedSubtree); |
| 219 stripImageElements(clonedSubtree); | 220 stripImageElements(clonedSubtree); |
| 220 | 221 |
| 221 if (textOnly) { | 222 if (textOnly) { |
| 222 return DomUtil.getTextFromTree(clonedSubtree); | 223 return DomUtil.getTextFromTree(clonedSubtree); |
| 223 } | 224 } |
| 224 return Element.as(clonedSubtree).getString(); | 225 return Element.as(clonedSubtree).getString(); |
| 225 } | 226 } |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 } | 396 } |
| 396 | 397 |
| 397 /** | 398 /** |
| 398 * Strips all "style" attributes from all nodes in the tree rooted at |rootN
ode| | 399 * Strips all "style" attributes from all nodes in the tree rooted at |rootN
ode| |
| 399 */ | 400 */ |
| 400 public static void stripStyleAttributes(Node rootNode) { | 401 public static void stripStyleAttributes(Node rootNode) { |
| 401 stripAttributeFromTags(rootNode, "STYLE", new String[]{"*"}); | 402 stripAttributeFromTags(rootNode, "STYLE", new String[]{"*"}); |
| 402 } | 403 } |
| 403 | 404 |
| 404 /** | 405 /** |
| 406 * Strips all "target" attributes from anchor nodes in the tree rooted at |r
ootNode| |
| 407 */ |
| 408 public static void stripTargetAttributes(Node rootNode) { |
| 409 stripAttributeFromTags(rootNode, "TARGET", new String[]{"A"}); |
| 410 } |
| 411 |
| 412 /** |
| 405 * Get a list of relevant nodes from a subtree. | 413 * Get a list of relevant nodes from a subtree. |
| 406 * @param root The root of the subtree. | 414 * @param root The root of the subtree. |
| 407 * @return A list of relevant nodes. | 415 * @return A list of relevant nodes. |
| 408 */ | 416 */ |
| 409 public static List<Node> getOutputNodes(Node root) { | 417 public static List<Node> getOutputNodes(Node root) { |
| 410 final List<Node> nodes = new ArrayList<>(); | 418 final List<Node> nodes = new ArrayList<>(); |
| 411 new DomWalker(new DomWalker.Visitor() { | 419 new DomWalker(new DomWalker.Visitor() { |
| 412 @Override | 420 @Override |
| 413 public boolean visit(Node n) { | 421 public boolean visit(Node n) { |
| 414 switch (n.getNodeType()) { | 422 switch (n.getNodeType()) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 }-*/; | 473 }-*/; |
| 466 | 474 |
| 467 public static native Document createHTMLDocument(Document doc) /*-{ | 475 public static native Document createHTMLDocument(Document doc) /*-{ |
| 468 return doc.implementation.createHTMLDocument(); | 476 return doc.implementation.createHTMLDocument(); |
| 469 }-*/; | 477 }-*/; |
| 470 | 478 |
| 471 public static native Element getFirstElementChild(Document document) /*-{ | 479 public static native Element getFirstElementChild(Document document) /*-{ |
| 472 return document.firstElementChild; | 480 return document.firstElementChild; |
| 473 }-*/; | 481 }-*/; |
| 474 } | 482 } |
| OLD | NEW |