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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 switch (e.getTagName()) { | 102 switch (e.getTagName()) { |
103 case "OL": | |
104 case "UL": | |
105 case "LI": | |
106 builder.list(new WebTag(e.getTagName(), WebTag.TagType.START)); | |
wychen
2015/08/04 02:37:01
If we skip this when there's no child element, the
Marcelo Correa
2015/08/04 16:34:48
I don't think we can do such thing.
There are a fe
wychen
2015/08/05 00:01:02
I see. You are right. The tag is copied to WebText
| |
107 break; | |
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) { |
112 builder.dataTable(e); | 117 builder.dataTable(e); |
(...skipping 22 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 switch (e.getTagName()) { | |
153 case "OL": | |
154 case "UL": | |
155 case "LI": | |
156 builder.list(new WebTag(e.getTagName(), WebTag.TagType.END)) ; | |
157 break; | |
158 } | |
159 } | |
145 builder.endElement(); | 160 builder.endElement(); |
146 } | 161 } |
147 | 162 |
148 private static void logVisibilityInfo(Element e, boolean visible) { | 163 private static void logVisibilityInfo(Element e, boolean visible) { |
149 if (!LogUtil.isLoggable(LogUtil.DEBUG_LEVEL_VISIBILITY_INFO)) return; | 164 if (!LogUtil.isLoggable(LogUtil.DEBUG_LEVEL_VISIBILITY_INFO)) return; |
150 Style style = DomUtil.getComputedStyle(e); | 165 Style style = DomUtil.getComputedStyle(e); |
151 LogUtil.logToConsole((visible ? "KEEP " : "SKIP ") + e.getTagName() + | 166 LogUtil.logToConsole((visible ? "KEEP " : "SKIP ") + e.getTagName() + |
152 ": id=" + e.getId() + | 167 ": id=" + e.getId() + |
153 ", dsp=" + style.getDisplay() + | 168 ", dsp=" + style.getDisplay() + |
154 ", vis=" + style.getVisibility() + | 169 ", vis=" + style.getVisibility() + |
155 ", opaq=" + style.getOpacity()); | 170 ", opaq=" + style.getOpacity()); |
156 } | 171 } |
157 | 172 |
158 private static void logTableInfo(Element e, TableClassifier.Type type) { | 173 private static void logTableInfo(Element e, TableClassifier.Type type) { |
159 if (!LogUtil.isLoggable(LogUtil.DEBUG_LEVEL_VISIBILITY_INFO)) return; | 174 if (!LogUtil.isLoggable(LogUtil.DEBUG_LEVEL_VISIBILITY_INFO)) return; |
160 Element parent = e.getParentElement(); | 175 Element parent = e.getParentElement(); |
161 LogUtil.logToConsole("TABLE: " + type + | 176 LogUtil.logToConsole("TABLE: " + type + |
162 ", id=" + e.getId() + | 177 ", id=" + e.getId() + |
163 ", class=" + e.getClassName() + | 178 ", class=" + e.getClassName() + |
164 ", parent=[" + parent.getTagName() + | 179 ", parent=[" + parent.getTagName() + |
165 ", id=" + parent.getId() + | 180 ", id=" + parent.getId() + |
166 ", class=" + parent.getClassName() + | 181 ", class=" + parent.getClassName() + |
167 "]"); | 182 "]"); |
168 } | 183 } |
169 } | 184 } |
OLD | NEW |