From: <rb...@us...> - 2013-06-14 17:39:51
|
Revision: 8343 http://sourceforge.net/p/htmlunit/code/8343 Author: rbri Date: 2013-06-14 17:39:48 +0000 (Fri, 14 Jun 2013) Log Message: ----------- static maps are factored out Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-06-14 07:22:00 UTC (rev 8342) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-06-14 17:39:48 UTC (rev 8343) @@ -113,15 +113,38 @@ "widows", "word-spacing")); + /** Maps element types to custom display types (display types that are not "block". */ + private static final Map<String, String> DEFAULT_DISPLAYS; + private static final Map<String, String> DEFAULT_DISPLAYS_CSS; + + static { + HashMap<String, String> map = new HashMap<String, String>(); + map.put("A", "inline"); + map.put("CODE", "inline"); + map.put("SPAN", "inline"); + DEFAULT_DISPLAYS = Collections.unmodifiableMap(map); + + map = new HashMap<String, String>(); + map.put("A", "inline"); + map.put("CODE", "inline"); + map.put("SPAN", "inline"); + + map.put("LI", "list-item"); + map.put("TABLE", "table"); + map.put("TBODY", "table-row-group"); + map.put("TD", "table-cell"); + map.put("TH", "table-cell"); + map.put("THEAD", "table-header-group"); + map.put("TR", "table-row"); + DEFAULT_DISPLAYS_CSS = Collections.unmodifiableMap(map); + } + /** * Local modifications maintained here rather than in the element. We use a sorted * map so that results are deterministic and thus easily testable. */ private final SortedMap<String, StyleElement> localModifications_ = new TreeMap<String, StyleElement>(); - /** Maps element types to custom display types (display types that are not "block". */ - private Map<String, String> defaultDisplays_; - /** The computed, cached width of the element to which this computed style belongs (no padding, borders, etc). */ private Integer width_; @@ -553,23 +576,12 @@ } private String getDefaultStyleDisplay() { - if (defaultDisplays_ == null) { - final Map<String, String> map = new HashMap<String, String>(); - map.put("A", "inline"); - map.put("CODE", "inline"); - map.put("SPAN", "inline"); - if (getBrowserVersion().hasFeature(CSS_DISPLAY_DEFAULT)) { - map.put("LI", "list-item"); - map.put("TABLE", "table"); - map.put("TBODY", "table-row-group"); - map.put("TD", "table-cell"); - map.put("TH", "table-cell"); - map.put("THEAD", "table-header-group"); - map.put("TR", "table-row"); - } - defaultDisplays_ = Collections.unmodifiableMap(map); + Map<String, String> map = DEFAULT_DISPLAYS; + if (getBrowserVersion().hasFeature(CSS_DISPLAY_DEFAULT)) { + map = DEFAULT_DISPLAYS_CSS; } - final String defaultValue = defaultDisplays_.get(getElement().getTagName()); + + final String defaultValue = map.get(getElement().getTagName()); if (defaultValue == null) { return "block"; } |