Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: java/org/chromium/distiller/DomUtil.java

Issue 1411603004: Discard hidden articles when using fast path (Closed) Base URL: https://github.com/chromium/dom-distiller.git@master
Patch Set: Fixed inconsistent indentation Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 NodeList ns) {
mdjones 2015/10/21 18:15:02 Is this used any more?
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698