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

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: 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..4fc01d015d0fcf2e05b771f0695ddbb8b8fada2c 100644
--- a/java/org/chromium/distiller/DomUtil.java
+++ b/java/org/chromium/distiller/DomUtil.java
@@ -95,6 +95,15 @@ public class DomUtil {
}-*/;
public static boolean isVisible(Element e) {
+ // Detect whether any of the ancestors has "display: none".
+ // Using offsetParent alone wouldn't work because it's also null when position is fixed.
+ return !(e.getOffsetParent() == null && e.getOffsetHeight() == 0 && e.getOffsetWidth() == 0);
mdjones 2015/12/08 00:04:33 why not: return e.getOffsetParent() != null || ...
wychen 2015/12/08 00:41:46 Done.
+ }
+
+ // Currently not used by anyone.
mdjones 2015/12/08 00:04:33 I think it's okay if we remove this if not used.
wychen 2015/12/08 00:41:46 Done.
+ public static boolean isVisibleAccurate(Element e) {
+ if (!isVisible(e))
+ return false;
Style style = getComputedStyle(e);
double opacity = JavaScript.parseFloat(style.getOpacity());
return !(style.getDisplay().equals("none") ||
« 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