| 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 com.dom_distiller.client; | 5 package com.dom_distiller.client; |
| 6 | 6 |
| 7 import com.google.gwt.dom.client.AnchorElement; | 7 import com.google.gwt.dom.client.AnchorElement; |
| 8 import com.google.gwt.dom.client.Document; | 8 import com.google.gwt.dom.client.Document; |
| 9 import com.google.gwt.dom.client.Element; | 9 import com.google.gwt.dom.client.Element; |
| 10 import com.google.gwt.dom.client.Node; | 10 import com.google.gwt.dom.client.Node; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 stripIds(node.getChild(i)); | 135 stripIds(node.getChild(i)); |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 private static String getTextFromTree(Node node) { | 140 private static String getTextFromTree(Node node) { |
| 141 stripIds(node); | 141 stripIds(node); |
| 142 | 142 |
| 143 // Temporarily add the node to the DOM so that style is calculated. | 143 // Temporarily add the node to the DOM so that style is calculated. |
| 144 Document.get().getBody().appendChild(node); | 144 Document.get().getBody().appendChild(node); |
| 145 String output = javascriptInnerText(node); | 145 String output = DomUtil.getInnerText(node); |
| 146 | 146 |
| 147 // And remove it again. | 147 // And remove it again. |
| 148 Document.get().getBody().removeChild(node); | 148 Document.get().getBody().removeChild(node); |
| 149 return output; | 149 return output; |
| 150 } | 150 } |
| 151 | 151 |
| 152 /** | |
| 153 * Use jsni for direct access to javascript's inner text. This avoid's GWT's
implementation | |
| 154 * which is intentionally different to mimic an old IE behaviour. | |
| 155 */ | |
| 156 private static native String javascriptInnerText(Node node) /*-{ | |
| 157 return node.innerText; | |
| 158 }-*/; | |
| 159 | |
| 160 private static List<Node> getContentNodesForTextDocument(TextDocument docume
nt) { | 152 private static List<Node> getContentNodesForTextDocument(TextDocument docume
nt) { |
| 161 List<Node> contentTextNodes = new ArrayList<Node>(); | 153 List<Node> contentTextNodes = new ArrayList<Node>(); |
| 162 for (TextBlock tb : document.getTextBlocks()) { | 154 for (TextBlock tb : document.getTextBlocks()) { |
| 163 if (!tb.isContent()) { | 155 if (!tb.isContent()) { |
| 164 continue; | 156 continue; |
| 165 } | 157 } |
| 166 if (!tb.hasLabel(DefaultLabels.TITLE)) { | 158 if (!tb.hasLabel(DefaultLabels.TITLE)) { |
| 167 contentTextNodes.addAll(tb.getAllTextElements()); | 159 contentTextNodes.addAll(tb.getAllTextElements()); |
| 168 } | 160 } |
| 169 } | 161 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 return; | 194 return; |
| 203 } | 195 } |
| 204 var elementsWithSrc = root.querySelectorAll('img,source,track,video'); | 196 var elementsWithSrc = root.querySelectorAll('img,source,track,video'); |
| 205 for (var key in elementsWithSrc) { | 197 for (var key in elementsWithSrc) { |
| 206 if (elementsWithSrc[key].src) { | 198 if (elementsWithSrc[key].src) { |
| 207 elementsWithSrc[key].src = elementsWithSrc[key].src; | 199 elementsWithSrc[key].src = elementsWithSrc[key].src; |
| 208 } | 200 } |
| 209 } | 201 } |
| 210 }-*/; | 202 }-*/; |
| 211 } | 203 } |
| OLD | NEW |