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

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

Issue 1230583006: Fix for keeping lists structure (Closed) Base URL: https://github.com/chromium/dom-distiller.git@master
Patch Set: Using a new approach to keep list structure. 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.filters; 5 package org.chromium.distiller.webdocument.filters;
6 6
7 import org.chromium.distiller.webdocument.WebDocument; 7 import org.chromium.distiller.webdocument.WebDocument;
8 import org.chromium.distiller.webdocument.WebElement; 8 import org.chromium.distiller.webdocument.WebElement;
9 import org.chromium.distiller.webdocument.WebText; 9 import org.chromium.distiller.webdocument.WebText;
10 import org.chromium.distiller.webdocument.PlaceHolderStart;
11 import org.chromium.distiller.webdocument.PlaceHolderEnd;
12 import java.util.List;
13 import java.util.Stack;
10 14
11 public class RelevantElements { 15 public class RelevantElements {
12 public static boolean process(WebDocument document) { 16 public static boolean process(WebDocument document) {
13 boolean changes = false; 17 boolean changes = false;
14 boolean inContent = false; 18 boolean inContent = false;
15 19
16 for (WebElement e : document.getElements()) { 20 for (WebElement e : document.getElements()) {
17 if (e.getIsContent()) { 21 if (e.getIsContent()) {
18 inContent = true; 22 inContent = true;
19 } else if (e instanceof WebText) { 23 } else if (e instanceof WebText) {
20 inContent = false; 24 inContent = false;
21 } else { 25 } else {
22 if (inContent) { 26 if (inContent) {
23 e.setIsContent(true); 27 e.setIsContent(true);
24 changes = true; 28 changes = true;
25 } 29 }
26 } 30 }
27 } 31 }
32 handlePlaceHolderElements(document.getElements());
28 return changes; 33 return changes;
29 } 34 }
35
36 public static void handlePlaceHolderElements(List<WebElement> elements) {
37 class PlaceHolder {
38 public PlaceHolder(WebElement start, boolean flush) {
mdjones 2015/07/29 17:12:16 What if there were only one class for a placeholde
39 this.start = start;
40 this.flush = flush;
41 }
42
43 WebElement start;
44 boolean flush;
45 }
46 boolean flush = false;
47 int stackMark = -1;
mdjones 2015/07/29 17:12:16 I don't understand what this var is for. The only
48 Stack<PlaceHolder> holderStack = new Stack<>();
49
50 for (WebElement e : elements) {
51 if (e instanceof WebText) {
52 if (!flush) {
53 flush = e.getIsContent();
54 }
55 } else if (e instanceof PlaceHolderStart) {
56 holderStack.push(new PlaceHolder(e, flush));
57 flush = false;
58 } else if (e instanceof PlaceHolderEnd) {
59 PlaceHolder placeHolder = holderStack.pop();
60 boolean isContent;
mdjones 2015/07/29 21:00:24 Set isContent to flush here instead, or just use f
61 if ((isContent = flush || stackMark >= holderStack.size())) {
62 stackMark = holderStack.size() - 1;
63 }
64 placeHolder.start.setIsContent(isContent);
65 e.setIsContent(isContent);
66 flush = placeHolder.flush;
67 }
68 }
69 }
30 } 70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698