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

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: Added accurate visibility test Created 5 years, 1 month 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 }-*/; 95 }-*/;
96 96
97 public static boolean isVisible(Element e) { 97 public static boolean isVisible(Element e) {
98 Style style = getComputedStyle(e); 98 Style style = getComputedStyle(e);
99 double opacity = JavaScript.parseFloat(style.getOpacity()); 99 double opacity = JavaScript.parseFloat(style.getOpacity());
100 return !(style.getDisplay().equals("none") || 100 return !(style.getDisplay().equals("none") ||
101 style.getVisibility().equals("hidden") || 101 style.getVisibility().equals("hidden") ||
102 opacity == 0.0F); 102 opacity == 0.0F);
103 } 103 }
104 104
105 /**
106 * Verifies if a given element is visible by checking its offset.
107 */
108 public static boolean isVisibleByItsOffset(Element e) {
109 return !(e.getOffsetHeight() <= 0 || e.getOffsetWidth() <= 0);
110 }
111
105 /* 112 /*
106 * We want to use jsni for direct access to javascript's innerText. This av oids GWT's 113 * We want to use jsni for direct access to javascript's innerText. This av oids GWT's
107 * implementation of Element::getInnerText(), which is intentionally differe nt to mimic an old 114 * implementation of Element::getInnerText(), which is intentionally differe nt to mimic an old
108 * IE behaviour, which returns text within <script> tags. 115 * IE behaviour, which returns text within <script> tags.
109 */ 116 */
110 public static native String getInnerText(Node node) /*-{ 117 public static native String getInnerText(Node node) /*-{
111 return node.innerText; 118 return node.innerText;
112 }-*/; 119 }-*/;
113 120
114 public static native double getTime() /*-{ 121 public static native double getTime() /*-{
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 */ 171 */
165 public static Node getNearestCommonAncestor(final Node n1, final Node n2) { 172 public static Node getNearestCommonAncestor(final Node n1, final Node n2) {
166 Node parent = n1; 173 Node parent = n1;
167 while (parent != null && !JavaScript.contains(parent, n2)) parent = pare nt.getParentNode(); 174 while (parent != null && !JavaScript.contains(parent, n2)) parent = pare nt.getParentNode();
168 return parent; 175 return parent;
169 } 176 }
170 177
171 /** 178 /**
172 * Get the nearest common ancestor of nodes. 179 * Get the nearest common ancestor of nodes.
173 */ 180 */
174 public static Node getNearestCommonAncestor(final NodeList ns) { 181 public static Node getNearestCommonAncestor(final List<Element> ns) {
175 if (ns.getLength() == 0) return null; 182 if (ns.size() == 0) return null;
176 Node parent = ns.getItem(0); 183 Node parent = ns.get(0);
177 for (int i = 1; i < ns.getLength(); i++) { 184 for (int i = 1; i < ns.size(); i++) {
178 parent = getNearestCommonAncestor(parent, ns.getItem(i)); 185 parent = getNearestCommonAncestor(parent, ns.get(i));
179 } 186 }
180 return parent; 187 return parent;
181 } 188 }
182 189
183 /** 190 /**
184 * Get all text from a tree/sub-tree. 191 * Get all text from a tree/sub-tree.
185 * @param node The root of the tree. 192 * @param node The root of the tree.
186 * @return The text contained in this tree. 193 * @return The text contained in this tree.
187 */ 194 */
188 public static String getTextFromTree(Node node) { 195 public static String getTextFromTree(Node node) {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 }-*/; 401 }-*/;
395 402
396 public static native Document createHTMLDocument(Document doc) /*-{ 403 public static native Document createHTMLDocument(Document doc) /*-{
397 return doc.implementation.createHTMLDocument(); 404 return doc.implementation.createHTMLDocument();
398 }-*/; 405 }-*/;
399 406
400 public static native Element getFirstElementChild(Document document) /*-{ 407 public static native Element getFirstElementChild(Document document) /*-{
401 return document.firstElementChild; 408 return document.firstElementChild;
402 }-*/; 409 }-*/;
403 } 410 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698