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 | |
| 7 import java.util.Stack; | |
| 8 | |
| 9 public class NestedElementRetainer { | |
|
mdjones
2015/08/05 15:44:35
Add some documentation about what this class is an
| |
| 10 public static void process(WebDocument document) { | |
| 11 boolean isContent = false; | |
| 12 int stackMark = -1; | |
| 13 Stack<WebTag> stack = new Stack<>(); | |
| 14 | |
| 15 for (WebElement e : document.getElements()) { | |
| 16 if (!(e instanceof WebTag)) { | |
| 17 if (!isContent) { | |
| 18 isContent = e.getIsContent(); | |
| 19 } | |
| 20 } else { | |
| 21 WebTag webTag = (WebTag) e; | |
| 22 if (webTag.isStartTag()) { | |
| 23 webTag.setIsContent(isContent); | |
| 24 stack.push(webTag); | |
| 25 isContent = false; | |
| 26 } else { | |
| 27 WebTag startWebTag = stack.pop(); | |
| 28 isContent |= stackMark >= stack.size(); | |
| 29 if (isContent) { | |
| 30 stackMark = stack.size() - 1; | |
| 31 } | |
| 32 boolean wasContent = startWebTag.getIsContent(); | |
| 33 startWebTag.setIsContent(isContent); | |
| 34 webTag.setIsContent(isContent); | |
| 35 isContent = wasContent; | |
| 36 } | |
| 37 } | |
| 38 } | |
| 39 } | |
| 40 } | |
| OLD | NEW |