Ignore:
Timestamp:
2015-02-19T15:22:49+01:00 (9 years ago)
Author:
bastiK
Message:

MapCSS: new @supports rule

Implementation should be mostly compatible with
the CSS Conditional 3 draft [2].

This is similar to @media, which was previously misused
for this purpose and is now deprecated.

refs:
[1] https://wiki.openstreetmap.org/wiki/MapCSS/0.2/Proposal_media_query
[2] http://dev.w3.org/csswg/css-conditional/

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r8086 r8087  
    99import java.io.IOException;
    1010import java.io.InputStream;
     11import java.lang.reflect.Field;
    1112import java.nio.charset.StandardCharsets;
    1213import java.text.MessageFormat;
     
    3334import org.openstreetmap.josm.gui.mappaint.Cascade;
    3435import org.openstreetmap.josm.gui.mappaint.Environment;
     36import org.openstreetmap.josm.gui.mappaint.LineElemStyle;
    3537import org.openstreetmap.josm.gui.mappaint.MultiCascade;
    3638import org.openstreetmap.josm.gui.mappaint.Range;
     39import org.openstreetmap.josm.gui.mappaint.StyleKeys;
    3740import org.openstreetmap.josm.gui.mappaint.StyleSetting;
    3841import org.openstreetmap.josm.gui.mappaint.StyleSetting.BooleanStyleSetting;
     
    8184     */
    8285    public final static ReadWriteLock STYLE_SOURCE_LOCK = new ReentrantReadWriteLock();
     86
     87    /**
     88     * Set of all supported MapCSS keys.
     89     */
     90    public static final Set<String> SUPPORTED_KEYS = new HashSet<>();
     91    static {
     92        Field[] declaredFields = StyleKeys.class.getDeclaredFields();
     93        for (Field f : declaredFields) {
     94            try {
     95                SUPPORTED_KEYS.add((String) f.get(null));
     96                if (!f.getName().toLowerCase().replace("_", "-").equals(f.get(null))) {
     97                    throw new RuntimeException(f.getName());
     98                }
     99            } catch (IllegalArgumentException | IllegalAccessException ex) {
     100                throw new RuntimeException(ex);
     101            }
     102        }
     103        for (LineElemStyle.LineType lt : LineElemStyle.LineType.values()) {
     104            SUPPORTED_KEYS.add(lt.prefix + StyleKeys.COLOR);
     105            SUPPORTED_KEYS.add(lt.prefix + StyleKeys.DASHES);
     106            SUPPORTED_KEYS.add(lt.prefix + StyleKeys.DASHES_BACKGROUND_COLOR);
     107            SUPPORTED_KEYS.add(lt.prefix + StyleKeys.DASHES_BACKGROUND_OPACITY);
     108            SUPPORTED_KEYS.add(lt.prefix + StyleKeys.DASHES_OFFSET);
     109            SUPPORTED_KEYS.add(lt.prefix + StyleKeys.LINECAP);
     110            SUPPORTED_KEYS.add(lt.prefix + StyleKeys.LINEJOIN);
     111            SUPPORTED_KEYS.add(lt.prefix + StyleKeys.MITERLIMIT);
     112            SUPPORTED_KEYS.add(lt.prefix + StyleKeys.OFFSET);
     113            SUPPORTED_KEYS.add(lt.prefix + StyleKeys.OPACITY);
     114            SUPPORTED_KEYS.add(lt.prefix + StyleKeys.REAL_WIDTH);
     115            SUPPORTED_KEYS.add(lt.prefix + StyleKeys.WIDTH);
     116        }
     117    }
    83118
    84119    /**
     
    484519    }
    485520
    486     public boolean evalMediaExpression(String feature, Object val) {
     521    public boolean evalSupportsDeclCondition(String feature, Object val) {
    487522        if (feature == null) return false;
     523        if (SUPPORTED_KEYS.contains(feature)) return true;
    488524        switch (feature) {
    489525            case "user-agent":
Note: See TracChangeset for help on using the changeset viewer.