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 Style style = getComputedStyle(e); | 98 // Detect whether any of the ancestors has "display: none". |
99 double opacity = JavaScript.parseFloat(style.getOpacity()); | 99 // Using offsetParent alone wouldn't work because it's also null when po
sition is fixed. |
100 return !(style.getDisplay().equals("none") || | 100 // Using offsetHeight/Width alone makes sense in production, but we have
too many |
101 style.getVisibility().equals("hidden") || | 101 // zero-sized elements in our tests. |
102 opacity == 0.0F); | 102 return e.getOffsetParent() != null || e.getOffsetHeight() != 0 || e.getO
ffsetWidth() != 0; |
103 } | 103 } |
104 | 104 |
105 /* | 105 /* |
106 * We want to use jsni for direct access to javascript's innerText. This av
oids GWT's | 106 * 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 | 107 * implementation of Element::getInnerText(), which is intentionally differe
nt to mimic an old |
108 * IE behaviour, which returns text within <script> tags. | 108 * IE behaviour, which returns text within <script> tags. |
109 */ | 109 */ |
110 public static native String getInnerText(Node node) /*-{ | 110 public static native String getInnerText(Node node) /*-{ |
111 return node.innerText; | 111 return node.innerText; |
112 }-*/; | 112 }-*/; |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 }-*/; | 394 }-*/; |
395 | 395 |
396 public static native Document createHTMLDocument(Document doc) /*-{ | 396 public static native Document createHTMLDocument(Document doc) /*-{ |
397 return doc.implementation.createHTMLDocument(); | 397 return doc.implementation.createHTMLDocument(); |
398 }-*/; | 398 }-*/; |
399 | 399 |
400 public static native Element getFirstElementChild(Document document) /*-{ | 400 public static native Element getFirstElementChild(Document document) /*-{ |
401 return document.firstElementChild; | 401 return document.firstElementChild; |
402 }-*/; | 402 }-*/; |
403 } | 403 } |
OLD | NEW |