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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 public static Node getNearestCommonAncestor(final NodeList ns) { | 174 public static Node getNearestCommonAncestor(final NodeList ns) { |
175 if (ns.getLength() == 0) return null; | 175 if (ns.getLength() == 0) return null; |
176 Node parent = ns.getItem(0); | 176 Node parent = ns.getItem(0); |
177 for (int i = 1; i < ns.getLength(); i++) { | 177 for (int i = 1; i < ns.getLength(); i++) { |
178 parent = getNearestCommonAncestor(parent, ns.getItem(i)); | 178 parent = getNearestCommonAncestor(parent, ns.getItem(i)); |
179 } | 179 } |
180 return parent; | 180 return parent; |
181 } | 181 } |
182 | 182 |
183 /** | 183 /** |
| 184 * Get the nearest common ancestor of nodes. |
| 185 */ |
| 186 public static Node getNearestCommonAncestor(final List<Element> ns) { |
| 187 if (ns.size() == 0) return null; |
| 188 Node parent = ns.get(0); |
| 189 for (int i = 1; i < ns.size(); i++) { |
| 190 parent = getNearestCommonAncestor(parent, ns.get(i)); |
| 191 } |
| 192 return parent; |
| 193 } |
| 194 |
| 195 /** |
184 * Get all text from a tree/sub-tree. | 196 * Get all text from a tree/sub-tree. |
185 * @param node The root of the tree. | 197 * @param node The root of the tree. |
186 * @return The text contained in this tree. | 198 * @return The text contained in this tree. |
187 */ | 199 */ |
188 public static String getTextFromTree(Node node) { | 200 public static String getTextFromTree(Node node) { |
189 // Temporarily add the node to the DOM so that style is calculated. | 201 // Temporarily add the node to the DOM so that style is calculated. |
190 Document.get().getBody().appendChild(node); | 202 Document.get().getBody().appendChild(node); |
191 String output = DomUtil.getInnerText(node); | 203 String output = DomUtil.getInnerText(node); |
192 | 204 |
193 // And remove it again. | 205 // And remove it again. |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 }-*/; | 406 }-*/; |
395 | 407 |
396 public static native Document createHTMLDocument(Document doc) /*-{ | 408 public static native Document createHTMLDocument(Document doc) /*-{ |
397 return doc.implementation.createHTMLDocument(); | 409 return doc.implementation.createHTMLDocument(); |
398 }-*/; | 410 }-*/; |
399 | 411 |
400 public static native Element getFirstElementChild(Document document) /*-{ | 412 public static native Element getFirstElementChild(Document document) /*-{ |
401 return document.firstElementChild; | 413 return document.firstElementChild; |
402 }-*/; | 414 }-*/; |
403 } | 415 } |
OLD | NEW |