| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 */ | 164 */ |
| 165 public static Node getNearestCommonAncestor(final Node n1, final Node n2) { | 165 public static Node getNearestCommonAncestor(final Node n1, final Node n2) { |
| 166 Node parent = n1; | 166 Node parent = n1; |
| 167 while (parent != null && !JavaScript.contains(parent, n2)) parent = pare
nt.getParentNode(); | 167 while (parent != null && !JavaScript.contains(parent, n2)) parent = pare
nt.getParentNode(); |
| 168 return parent; | 168 return parent; |
| 169 } | 169 } |
| 170 | 170 |
| 171 /** | 171 /** |
| 172 * Get the nearest common ancestor of nodes. | 172 * Get the nearest common ancestor of nodes. |
| 173 */ | 173 */ |
| 174 public static Node getNearestCommonAncestor(final NodeList ns) { | 174 public static Node getNearestCommonAncestor(final List<Element> ns) { |
| 175 if (ns.getLength() == 0) return null; | 175 if (ns.size() == 0) return null; |
| 176 Node parent = ns.getItem(0); | 176 Node parent = ns.get(0); |
| 177 for (int i = 1; i < ns.getLength(); i++) { | 177 for (int i = 1; i < ns.size(); i++) { |
| 178 parent = getNearestCommonAncestor(parent, ns.getItem(i)); | 178 parent = getNearestCommonAncestor(parent, ns.get(i)); |
| 179 } | 179 } |
| 180 return parent; | 180 return parent; |
| 181 } | 181 } |
| 182 | 182 |
| 183 /** | 183 /** |
| 184 * Get all text from a tree/sub-tree. | 184 * Get all text from a tree/sub-tree. |
| 185 * @param node The root of the tree. | 185 * @param node The root of the tree. |
| 186 * @return The text contained in this tree. | 186 * @return The text contained in this tree. |
| 187 */ | 187 */ |
| 188 public static String getTextFromTree(Node node) { | 188 public static String getTextFromTree(Node node) { |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 }-*/; | 394 }-*/; |
| 395 | 395 |
| 396 public static native Document createHTMLDocument(Document doc) /*-{ | 396 public static native Document createHTMLDocument(Document doc) /*-{ |
| 397 return doc.implementation.createHTMLDocument(); | 397 return doc.implementation.createHTMLDocument(); |
| 398 }-*/; | 398 }-*/; |
| 399 | 399 |
| 400 public static native Element getFirstElementChild(Document document) /*-{ | 400 public static native Element getFirstElementChild(Document document) /*-{ |
| 401 return document.firstElementChild; | 401 return document.firstElementChild; |
| 402 }-*/; | 402 }-*/; |
| 403 } | 403 } |
| OLD | NEW |