Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: java/org/chromium/distiller/webdocument/filters/NestedElementRetainer.java

Issue 1230583006: Fix for keeping lists structure (Closed) Base URL: https://github.com/chromium/dom-distiller.git@master
Patch Set: Fixed grammar Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698