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

Unified Diff: src/com/dom_distiller/client/DomUtil.java

Issue 449923002: gwt getInnerText -> javascript innerText or textContent (Closed) Base URL: https://code.google.com/p/dom-distiller/@master
Patch Set: Created 6 years, 4 months 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
Index: src/com/dom_distiller/client/DomUtil.java
diff --git a/src/com/dom_distiller/client/DomUtil.java b/src/com/dom_distiller/client/DomUtil.java
index 342e218b5bed5380044e5f787de65352bb728e87..23122a778d9f38e33ef8183e870483f66507187c 100644
--- a/src/com/dom_distiller/client/DomUtil.java
+++ b/src/com/dom_distiller/client/DomUtil.java
@@ -78,4 +78,33 @@ public class DomUtil {
style.getVisibility().equals("hidden") ||
opacity == 0.0F);
}
+
+ /*
+ * We want to use jsni for direct access to javascript's innerText. This avoids GWT's
+ * implementation of Element::getInnerText(), which is intentionally different to mimic an old
+ * IE behaviour, which returns text within <script> tags.
+ * However, in GWT, javascript innerText always returns null, so we fall back to the GWT
+ * implementation in that case to cater to GWT tests.
+ */
+ public static String getInnerText(Node node) {
+ String text = javascriptInnerText(node);
+ if (text != null) return text;
+ return node.getNodeType() == Node.ELEMENT_NODE ? Element.as(node).getInnerText() : "";
+ }
+
+ private static native String javascriptInnerText(Node node) /*-{
+ return node.innerText;
+ }-*/;
+
+ /**
+ * Use jsni for direct access to javascript's textContent. textContent is different from
+ * innerText (see http://www.kellegous.com/j/2013/02/27/innertext-vs-textcontent):
+ * - textContent is the raw textual content, doesn't require layout, and is basically a
+ * concatenation of the values of all text nodes within a subtree.
+ * - innerText is what is presented to the user, requires layout, and excludes text in invisible
+ * elements, e.g. <title> tags.
+ */
+ public static native String javascriptTextContent(Node node) /*-{
+ return node.textContent;
+ }-*/;
}
« no previous file with comments | « src/com/dom_distiller/client/DocumentTitleGetter.java ('k') | src/com/dom_distiller/client/IEReadingViewParser.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698