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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 return nodes; | 444 return nodes; |
445 } | 445 } |
446 | 446 |
447 public static int getArea(Element e) { | 447 public static int getArea(Element e) { |
448 if (e != null) { | 448 if (e != null) { |
449 return e.getOffsetHeight() * e.getOffsetWidth(); | 449 return e.getOffsetHeight() * e.getOffsetWidth(); |
450 } | 450 } |
451 return 0; | 451 return 0; |
452 } | 452 } |
453 | 453 |
| 454 public static String escapeHTML(String string) { |
| 455 return string.replaceAll("&", "&") |
| 456 .replaceAll("<", "<") |
| 457 .replaceAll(">", ">") |
| 458 .replaceAll("\"", """) |
| 459 .replaceAll("'", "'") |
| 460 .replaceAll("/", "/"); |
| 461 } |
| 462 |
454 /** | 463 /** |
455 * Generate HTML/text output for a given node tree/subtree. This will ignore
hidden | 464 * Generate HTML/text output for a given node tree/subtree. This will ignore
hidden |
456 * elements. | 465 * elements. |
457 * @param subtree The root of the subtree. | 466 * @param subtree The root of the subtree. |
458 * @param textOnly If this function should return text only and not HTML. | 467 * @param textOnly If this function should return text only and not HTML. |
459 * @return The output for the provided subtree. | 468 * @return The output for the provided subtree. |
460 */ | 469 */ |
461 public static String generateOutputFromTree(Node subtree, boolean textOnly)
{ | 470 public static String generateOutputFromTree(Node subtree, boolean textOnly)
{ |
462 return generateOutputFromList(getOutputNodes(subtree), textOnly); | 471 return generateOutputFromList(getOutputNodes(subtree), textOnly); |
463 } | 472 } |
464 | 473 |
465 // Returns whether querySelectorAll is available | 474 // Returns whether querySelectorAll is available |
466 public static native boolean supportQuerySelectorAll(Element root) /*-{ | 475 public static native boolean supportQuerySelectorAll(Element root) /*-{ |
467 return (typeof(root.querySelectorAll) == 'function'); | 476 return (typeof(root.querySelectorAll) == 'function'); |
468 }-*/; | 477 }-*/; |
469 | 478 |
470 // GWT doesn't support querySelectorAll, so testing the caller could be hard
er. | 479 // GWT doesn't support querySelectorAll, so testing the caller could be hard
er. |
471 public static native NodeList<Element> querySelectorAll(Node l, String selec
tors) /*-{ | 480 public static native NodeList<Element> querySelectorAll(Node l, String selec
tors) /*-{ |
472 return l.querySelectorAll(selectors); | 481 return l.querySelectorAll(selectors); |
473 }-*/; | 482 }-*/; |
474 | 483 |
475 public static native Document createHTMLDocument(Document doc) /*-{ | 484 public static native Document createHTMLDocument(Document doc) /*-{ |
476 return doc.implementation.createHTMLDocument(); | 485 return doc.implementation.createHTMLDocument(); |
477 }-*/; | 486 }-*/; |
478 | 487 |
479 public static native Element getFirstElementChild(Document document) /*-{ | 488 public static native Element getFirstElementChild(Document document) /*-{ |
480 return document.firstElementChild; | 489 return document.firstElementChild; |
481 }-*/; | 490 }-*/; |
482 } | 491 } |
OLD | NEW |