| OLD | NEW |
| 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": |
| 37 // Special casing for drop cap letter with "float". |
| 38 // Having style "float" would imply "display: block". |
| 39 // Ref: http://crbug.com/593128 |
| 40 if (!"none".equals(style.getProperty("float")) && |
| 41 "SPAN".equals(tagName)) { |
| 42 break; |
| 43 } |
| 44 // Intentional fall through. |
| 35 // See http://www.w3.org/TR/CSS2/tables.html#table-display | 45 // See http://www.w3.org/TR/CSS2/tables.html#table-display |
| 36 // and http://www.w3.org/TR/css-flexbox-1/#flex-containers | 46 // and http://www.w3.org/TR/css-flexbox-1/#flex-containers |
| 37 // The default case includes the following display types: | 47 // The default case includes the following display types: |
| 38 // block | |
| 39 // list-item | 48 // list-item |
| 40 // inline-table | 49 // inline-table |
| 41 // table-row | 50 // table-row |
| 42 // table-row-group | 51 // table-row-group |
| 43 // table-header-group | 52 // table-header-group |
| 44 // table-footer-group | 53 // table-footer-group |
| 45 // table-column | 54 // table-column |
| 46 // table-column-group | 55 // table-column-group |
| 47 // table-cell | 56 // table-cell |
| 48 // table-caption | 57 // table-caption |
| 49 // flex | 58 // flex |
| 50 default: | 59 default: |
| 51 action.flush = true; | 60 action.flush = true; |
| 52 action.changesTagLevel = true; | 61 action.changesTagLevel = true; |
| 53 break; | 62 break; |
| 54 } | 63 } |
| 55 | 64 |
| 56 String tagName = element.getTagName(); | |
| 57 if (!"HTML".equals(tagName) && !"BODY".equals(tagName)) { | 65 if (!"HTML".equals(tagName) && !"BODY".equals(tagName)) { |
| 58 String className = element.getAttribute("class"); | 66 String className = element.getAttribute("class"); |
| 59 int classCount = DomUtil.getClassList(element).length(); | 67 int classCount = DomUtil.getClassList(element).length(); |
| 60 String id = element.getAttribute("id"); | 68 String id = element.getAttribute("id"); |
| 61 if ((REG_COMMENT.test(className) || REG_COMMENT.test(id)) && | 69 if ((REG_COMMENT.test(className) || REG_COMMENT.test(id)) && |
| 62 classCount <= MAX_CLASS_COUNT) { | 70 classCount <= MAX_CLASS_COUNT) { |
| 63 action.labels.push(DefaultLabels.STRICTLY_NOT_CONTENT); | 71 action.labels.push(DefaultLabels.STRICTLY_NOT_CONTENT); |
| 64 } | 72 } |
| 65 | 73 |
| 66 switch (tagName) { | 74 switch (tagName) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 91 action.isAnchor = true; | 99 action.isAnchor = true; |
| 92 } | 100 } |
| 93 break; | 101 break; |
| 94 } | 102 } |
| 95 } | 103 } |
| 96 return action; | 104 return action; |
| 97 } | 105 } |
| 98 | 106 |
| 99 private ElementAction() {} | 107 private ElementAction() {} |
| 100 } | 108 } |
| OLD | NEW |