Chromium Code Reviews| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 /** | 88 /** |
| 89 * @Return The CSS style of an element after applying the active stylesheet s and resolving any | 89 * @Return The CSS style of an element after applying the active stylesheet s and resolving any |
| 90 * basic computation the style's value(s) may contain. | 90 * basic computation the style's value(s) may contain. |
| 91 * @param el - DOM element | 91 * @param el - DOM element |
| 92 */ | 92 */ |
| 93 public static native Style getComputedStyle(Element el) /*-{ | 93 public static native Style getComputedStyle(Element el) /*-{ |
| 94 return getComputedStyle(el, null); | 94 return getComputedStyle(el, null); |
| 95 }-*/; | 95 }-*/; |
| 96 | 96 |
| 97 public static boolean isVisible(Element e) { | 97 public static boolean isVisible(Element e) { |
| 98 // Detect whether any of the ancestors has "display: none". | |
| 99 // Using offsetParent alone wouldn't work because it's also null when po sition is fixed. | |
| 100 return !(e.getOffsetParent() == null && e.getOffsetHeight() == 0 && e.ge tOffsetWidth() == 0); | |
|
mdjones
2015/12/08 00:04:33
why not:
return e.getOffsetParent() != null || ...
wychen
2015/12/08 00:41:46
Done.
| |
| 101 } | |
| 102 | |
| 103 // 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.
| |
| 104 public static boolean isVisibleAccurate(Element e) { | |
| 105 if (!isVisible(e)) | |
| 106 return false; | |
| 98 Style style = getComputedStyle(e); | 107 Style style = getComputedStyle(e); |
| 99 double opacity = JavaScript.parseFloat(style.getOpacity()); | 108 double opacity = JavaScript.parseFloat(style.getOpacity()); |
| 100 return !(style.getDisplay().equals("none") || | 109 return !(style.getDisplay().equals("none") || |
| 101 style.getVisibility().equals("hidden") || | 110 style.getVisibility().equals("hidden") || |
| 102 opacity == 0.0F); | 111 opacity == 0.0F); |
| 103 } | 112 } |
| 104 | 113 |
| 105 /* | 114 /* |
| 106 * We want to use jsni for direct access to javascript's innerText. This av oids GWT's | 115 * 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 | 116 * implementation of Element::getInnerText(), which is intentionally differe nt to mimic an old |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 }-*/; | 403 }-*/; |
| 395 | 404 |
| 396 public static native Document createHTMLDocument(Document doc) /*-{ | 405 public static native Document createHTMLDocument(Document doc) /*-{ |
| 397 return doc.implementation.createHTMLDocument(); | 406 return doc.implementation.createHTMLDocument(); |
| 398 }-*/; | 407 }-*/; |
| 399 | 408 |
| 400 public static native Element getFirstElementChild(Document document) /*-{ | 409 public static native Element getFirstElementChild(Document document) /*-{ |
| 401 return document.firstElementChild; | 410 return document.firstElementChild; |
| 402 }-*/; | 411 }-*/; |
| 403 } | 412 } |
| OLD | NEW |