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

Side by Side Diff: java/org/chromium/distiller/webdocument/ElementAction.java

Issue 1793583002: Handle drop cap letters (Closed) Base URL: git@github.com:chromium/dom-distiller.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | javatests/org/chromium/distiller/ContentExtractorTest.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.labels.DefaultLabels; 8 import org.chromium.distiller.labels.DefaultLabels;
9 9
10 import com.google.gwt.core.client.JavaScriptObject; 10 import com.google.gwt.core.client.JavaScriptObject;
11 import com.google.gwt.core.client.JsArrayString; 11 import com.google.gwt.core.client.JsArrayString;
12 import com.google.gwt.dom.client.Element; 12 import com.google.gwt.dom.client.Element;
13 import com.google.gwt.dom.client.Style; 13 import com.google.gwt.dom.client.Style;
14 import com.google.gwt.regexp.shared.RegExp; 14 import com.google.gwt.regexp.shared.RegExp;
15 15
16 public class ElementAction { 16 public class ElementAction {
17 public boolean changesTagLevel = false; 17 public boolean changesTagLevel = false;
18 public boolean flush = false; 18 public boolean flush = false;
19 public boolean isAnchor = false; 19 public boolean isAnchor = false;
20 public JsArrayString labels = JavaScriptObject.createArray().<JsArrayString> cast(); 20 public JsArrayString labels = JavaScriptObject.createArray().<JsArrayString> cast();
21 21
22 private static final RegExp REG_COMMENT = RegExp.compile("\\bcomments?\\b"); 22 private static final RegExp REG_COMMENT = RegExp.compile("\\bcomments?\\b");
23 private static final int MAX_CLASS_COUNT = 5; 23 private static final int MAX_CLASS_COUNT = 5;
24 24
25 public static ElementAction getForElement(Element element) { 25 public static ElementAction getForElement(Element element) {
26 Style style = DomUtil.getComputedStyle(element); 26 Style style = DomUtil.getComputedStyle(element);
27 ElementAction action = new ElementAction(); 27 ElementAction action = new ElementAction();
28 String tagName = element.getTagName();
28 switch (style.getDisplay()) { 29 switch (style.getDisplay()) {
29 case "inline": 30 case "inline":
30 break; 31 break;
31 case "inline-block": 32 case "inline-block":
32 case "inline-flex": 33 case "inline-flex":
33 action.changesTagLevel = true; 34 action.changesTagLevel = true;
34 break; 35 break;
36 case "block":
mdjones 2016/03/14 16:58:27 Please add a comment outlining that the float prop
wychen 2016/03/15 20:47:59 Done.
37 // Special casing for drop cap letter with "float".
38 // Ref: http://crbug.com/593128
39 if (!"none".equals(style.getProperty("float")) &&
40 "SPAN".equals(tagName)) {
41 break;
42 }
43 // Intentional fall through.
35 // See http://www.w3.org/TR/CSS2/tables.html#table-display 44 // See http://www.w3.org/TR/CSS2/tables.html#table-display
36 // and http://www.w3.org/TR/css-flexbox-1/#flex-containers 45 // and http://www.w3.org/TR/css-flexbox-1/#flex-containers
37 // The default case includes the following display types: 46 // The default case includes the following display types:
38 // block
39 // list-item 47 // list-item
40 // inline-table 48 // inline-table
41 // table-row 49 // table-row
42 // table-row-group 50 // table-row-group
43 // table-header-group 51 // table-header-group
44 // table-footer-group 52 // table-footer-group
45 // table-column 53 // table-column
46 // table-column-group 54 // table-column-group
47 // table-cell 55 // table-cell
48 // table-caption 56 // table-caption
49 // flex 57 // flex
50 default: 58 default:
51 action.flush = true; 59 action.flush = true;
52 action.changesTagLevel = true; 60 action.changesTagLevel = true;
53 break; 61 break;
54 } 62 }
55 63
56 String tagName = element.getTagName();
57 if (!"HTML".equals(tagName) && !"BODY".equals(tagName)) { 64 if (!"HTML".equals(tagName) && !"BODY".equals(tagName)) {
58 String className = element.getAttribute("class"); 65 String className = element.getAttribute("class");
59 int classCount = DomUtil.getClassList(element).length(); 66 int classCount = DomUtil.getClassList(element).length();
60 String id = element.getAttribute("id"); 67 String id = element.getAttribute("id");
61 if ((REG_COMMENT.test(className) || REG_COMMENT.test(id)) && 68 if ((REG_COMMENT.test(className) || REG_COMMENT.test(id)) &&
62 classCount <= MAX_CLASS_COUNT) { 69 classCount <= MAX_CLASS_COUNT) {
63 action.labels.push(DefaultLabels.STRICTLY_NOT_CONTENT); 70 action.labels.push(DefaultLabels.STRICTLY_NOT_CONTENT);
64 } 71 }
65 72
66 switch (tagName) { 73 switch (tagName) {
(...skipping 24 matching lines...) Expand all
91 action.isAnchor = true; 98 action.isAnchor = true;
92 } 99 }
93 break; 100 break;
94 } 101 }
95 } 102 }
96 return action; 103 return action;
97 } 104 }
98 105
99 private ElementAction() {} 106 private ElementAction() {}
100 } 107 }
OLDNEW
« no previous file with comments | « no previous file | javatests/org/chromium/distiller/ContentExtractorTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698