Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 package org.chromium.distiller.webdocument.filters; | |
| 2 | |
| 3 import org.chromium.distiller.webdocument.WebDocument; | |
| 4 import org.chromium.distiller.webdocument.WebElement; | |
| 5 import org.chromium.distiller.webdocument.WebTag; | |
| 6 import org.chromium.distiller.webdocument.WebText; | |
| 7 | |
| 8 import java.util.Stack; | |
| 9 | |
| 10 public class WebTagStructureKeeper { | |
|
mdjones
2015/08/03 23:29:45
How about NestedElement{Builder|Organizer|Retainer
| |
| 11 public static void process(WebDocument document) { | |
| 12 boolean isContent = false; | |
| 13 int stackMark = -1; | |
| 14 Stack<WebTag> stack = new Stack<>(); | |
| 15 | |
| 16 for (WebElement e : document.getElements()) { | |
| 17 if (e instanceof WebText) { | |
|
mdjones
2015/08/03 23:29:45
Though I'm not sure it is a common case, this does
| |
| 18 if (!isContent) { | |
| 19 isContent = e.getIsContent(); | |
| 20 } | |
| 21 } else if (e instanceof WebTag) { | |
| 22 WebTag webTag = (WebTag) e; | |
| 23 if (webTag.isStartTag()) { | |
| 24 webTag.setIsContent(isContent); | |
| 25 stack.push(webTag); | |
| 26 isContent = false; | |
| 27 } else { | |
| 28 WebTag startWebTag = stack.pop(); | |
| 29 boolean content = isContent || stackMark >= stack.size(); | |
|
mdjones
2015/08/03 23:29:45
isContent |= stackMark >= stackSize();
Then just
| |
| 30 if (content) { | |
| 31 stackMark = stack.size() - 1; | |
| 32 } | |
| 33 startWebTag.setIsContent(content); | |
| 34 webTag.setIsContent(content); | |
| 35 isContent = startWebTag.getIsContent(); | |
|
wychen
2015/08/04 02:37:01
Does this pass the test? Moving this line 2 lines
| |
| 36 } | |
| 37 } | |
| 38 } | |
| 39 } | |
| 40 } | |
| OLD | NEW |