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.webdocument; | 5 package org.chromium.distiller.webdocument; |
6 | 6 |
7 import org.chromium.distiller.DomUtil; | 7 import org.chromium.distiller.DomUtil; |
8 import org.chromium.distiller.DomWalker; | 8 import org.chromium.distiller.DomWalker; |
9 import org.chromium.distiller.LogUtil; | 9 import org.chromium.distiller.LogUtil; |
10 import org.chromium.distiller.TableClassifier; | 10 import org.chromium.distiller.TableClassifier; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // If the tag is marked as interesting, check the extractors. | 92 // If the tag is marked as interesting, check the extractors. |
93 for (EmbedExtractor extractor : extractors) { | 93 for (EmbedExtractor extractor : extractors) { |
94 WebElement embed = extractor.extract(e); | 94 WebElement embed = extractor.extract(e); |
95 if (embed != null) { | 95 if (embed != null) { |
96 builder.embed(embed); | 96 builder.embed(embed); |
97 return false; | 97 return false; |
98 } | 98 } |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
| 102 // Create a placeholder for the elements we want to preserve. |
| 103 if (WebTag.canBeNested(e.getTagName())) { |
| 104 builder.tag(new WebTag(e.getTagName(), WebTag.TagType.START)); |
| 105 } |
| 106 |
102 switch (e.getTagName()) { | 107 switch (e.getTagName()) { |
103 case "BR": | 108 case "BR": |
104 builder.lineBreak(e); | 109 builder.lineBreak(e); |
105 return false; | 110 return false; |
106 // Skip data tables, keep track of them to be extracted by RelevantE
lementsFinder | 111 // Skip data tables, keep track of them to be extracted by RelevantE
lementsFinder |
107 // later. | 112 // later. |
108 case "TABLE": | 113 case "TABLE": |
109 TableClassifier.Type type = TableClassifier.table(TableElement.a
s(e)); | 114 TableClassifier.Type type = TableClassifier.table(TableElement.a
s(e)); |
110 logTableInfo(e, type); | 115 logTableInfo(e, type); |
111 if (type == TableClassifier.Type.DATA) { | 116 if (type == TableClassifier.Type.DATA) { |
(...skipping 23 matching lines...) Expand all Loading... |
135 case "LINK": | 140 case "LINK": |
136 case "NOSCRIPT": | 141 case "NOSCRIPT": |
137 return false; | 142 return false; |
138 } | 143 } |
139 builder.startElement(e); | 144 builder.startElement(e); |
140 return true; | 145 return true; |
141 } | 146 } |
142 | 147 |
143 @Override | 148 @Override |
144 public void exit(Node n) { | 149 public void exit(Node n) { |
| 150 if (n.getNodeType() == Node.ELEMENT_NODE) { |
| 151 Element e = Element.as(n); |
| 152 if (WebTag.canBeNested(e.getTagName())) { |
| 153 builder.tag(new WebTag(e.getTagName(), WebTag.TagType.END)); |
| 154 } |
| 155 } |
145 builder.endElement(); | 156 builder.endElement(); |
146 } | 157 } |
147 | 158 |
148 private static void logVisibilityInfo(Element e, boolean visible) { | 159 private static void logVisibilityInfo(Element e, boolean visible) { |
149 if (!LogUtil.isLoggable(LogUtil.DEBUG_LEVEL_VISIBILITY_INFO)) return; | 160 if (!LogUtil.isLoggable(LogUtil.DEBUG_LEVEL_VISIBILITY_INFO)) return; |
150 Style style = DomUtil.getComputedStyle(e); | 161 Style style = DomUtil.getComputedStyle(e); |
151 LogUtil.logToConsole((visible ? "KEEP " : "SKIP ") + e.getTagName() + | 162 LogUtil.logToConsole((visible ? "KEEP " : "SKIP ") + e.getTagName() + |
152 ": id=" + e.getId() + | 163 ": id=" + e.getId() + |
153 ", dsp=" + style.getDisplay() + | 164 ", dsp=" + style.getDisplay() + |
154 ", vis=" + style.getVisibility() + | 165 ", vis=" + style.getVisibility() + |
155 ", opaq=" + style.getOpacity()); | 166 ", opaq=" + style.getOpacity()); |
156 } | 167 } |
157 | 168 |
158 private static void logTableInfo(Element e, TableClassifier.Type type) { | 169 private static void logTableInfo(Element e, TableClassifier.Type type) { |
159 if (!LogUtil.isLoggable(LogUtil.DEBUG_LEVEL_VISIBILITY_INFO)) return; | 170 if (!LogUtil.isLoggable(LogUtil.DEBUG_LEVEL_VISIBILITY_INFO)) return; |
160 Element parent = e.getParentElement(); | 171 Element parent = e.getParentElement(); |
161 LogUtil.logToConsole("TABLE: " + type + | 172 LogUtil.logToConsole("TABLE: " + type + |
162 ", id=" + e.getId() + | 173 ", id=" + e.getId() + |
163 ", class=" + e.getClassName() + | 174 ", class=" + e.getClassName() + |
164 ", parent=[" + parent.getTagName() + | 175 ", parent=[" + parent.getTagName() + |
165 ", id=" + parent.getId() + | 176 ", id=" + parent.getId() + |
166 ", class=" + parent.getClassName() + | 177 ", class=" + parent.getClassName() + |
167 "]"); | 178 "]"); |
168 } | 179 } |
169 } | 180 } |
OLD | NEW |