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

Unified Diff: java/org/chromium/distiller/DomUtil.java

Issue 1508963003: Make isVisible() faster and more accurate Base URL: git@github.com:chromium/dom-distiller.git@master
Patch Set: address mdjones' comments Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | javatests/org/chromium/distiller/DomUtilTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: java/org/chromium/distiller/DomUtil.java
diff --git a/java/org/chromium/distiller/DomUtil.java b/java/org/chromium/distiller/DomUtil.java
index d0bcb1bfd7330c1cc8c56be59fdbc6320918284f..dcc96e4de0dcd06290c5c3f42d62963e138e2d25 100644
--- a/java/org/chromium/distiller/DomUtil.java
+++ b/java/org/chromium/distiller/DomUtil.java
@@ -95,11 +95,11 @@ public class DomUtil {
}-*/;
public static boolean isVisible(Element e) {
- Style style = getComputedStyle(e);
- double opacity = JavaScript.parseFloat(style.getOpacity());
- return !(style.getDisplay().equals("none") ||
- style.getVisibility().equals("hidden") ||
- opacity == 0.0F);
+ // Detect whether any of the ancestors has "display: none".
+ // Using offsetParent alone wouldn't work because it's also null when position is fixed.
+ // Using offsetHeight/Width alone makes sense in production, but we have too many
+ // zero-sized elements in our tests.
+ return e.getOffsetParent() != null || e.getOffsetHeight() != 0 || e.getOffsetWidth() != 0;
}
/*
« no previous file with comments | « no previous file | javatests/org/chromium/distiller/DomUtilTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698