W3C home > Mailing lists > Public > www-validator-cvs@w3.org > October 2011

2002/css-validator/org/w3c/css/media AtRuleMedia.java,NONE,1.1 Media.java,NONE,1.1 MediaFeature.java,NONE,1.1

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Fri, 21 Oct 2011 01:49:09 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1RH4EP-0007WD-3M@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/media
In directory hutz:/tmp/cvs-serv28700/org/w3c/css/media

Added Files:
	AtRuleMedia.java Media.java MediaFeature.java 
Log Message:
redone the Media Features of media queries, up to date per http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/, todo, parsing of media in HTML form

--- NEW FILE: Media.java ---
package org.w3c.css.media;


import java.util.ArrayList;

public class Media {
    boolean only;
    boolean not;
    String media;
    ArrayList<MediaFeature> features;

    public Media() {
    }

    public Media(String media) {
        this.media = media;
    }

    public void setOnly(boolean only) {
        this.only = only;
    }

    public boolean getOnly() {
        return not;
    }

    public void setNot(boolean not) {
        this.not = not;
    }

    public boolean getNot() {
        return not;
    }

    public void setMedia(String media) {
        this.media = media;
    }

    public String getMedia() {
        return media;
    }

    public void addFeature(MediaFeature mf) {
        if (features == null) {
            features = new ArrayList<MediaFeature>();
        }
        features.add(mf);
    }

    public String toString() {
        // simple case, return the media string
        if (!only && !not && features == null) {
            return media;
        }
        StringBuilder sb = new StringBuilder();
        boolean printAnd = false;
        if (only) {
            sb.append("only ");
        } else if (not) {
            sb.append("not ");
        }
        // special case "media and (...)" or directly "(...)"
        if (media != null) {
            sb.append(media);
            printAnd = true;
        }
        if (features != null) {
            for (MediaFeature mf : features) {
                if (printAnd) {
                    sb.append(" and");
                } else {
                    printAnd = true;
                }
                sb.append(" (").append(mf.toString()).append(')');
            }
        }
        return sb.toString();
    }
}

--- NEW FILE: AtRuleMedia.java ---
// $Id: AtRuleMedia.java,v 1.1 2011/10/21 01:49:06 ylafon Exp $
//
// (c) COPYRIGHT MIT, ECIM and Keio University, 2011.
// Please first read the full copyright statement in file COPYRIGHT.html

package org.w3c.css.media;

import org.w3c.css.parser.AtRule;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.CssVersion;
import org.w3c.css.util.InvalidParamException;

import java.util.ArrayList;


public abstract class AtRuleMedia extends AtRule {

    public ArrayList<Media> allMedia = new ArrayList<Media>();

    /**
     * Adds a medium.
     *
     * @throws InvalidParamException the medium doesn't exist
     */
    public abstract AtRuleMedia addMedia(String restrictor, String medium,
                                         ApplContext ac) throws InvalidParamException;

    /**
     * Add a media feature to the current media, like (color:1)
     *
     * @param feature, the CssProperty
     * @since CSS3
     */
    public abstract void addMediaFeature(MediaFeature feature, ApplContext ac)
            throws InvalidParamException;

    /**
     * Returns the at rule keyword
     */
    public final String keyword() {
        return "media";
    }


    public boolean isEmpty() {
        return allMedia.isEmpty();
    }

    public ArrayList<Media> getMediaList() {
        return allMedia;
    }

    public String getCurrentMedia() {
        if (!allMedia.isEmpty()) {
            return allMedia.get(allMedia.size()-1).media;
        }
        return null;
    }

    /**
     * The second must be exactly the same of this one
     */
    public boolean canApply(AtRuleMedia atRule) {
        return false;
    }

    /**
     * See if two rules can match (ie: one have thing in common)
     */
    public boolean canMatch(AtRuleMedia atRule) {
        return false;
    }

    /**
     * Use to display the value part of the @media rule
     * used where the value is used, like as an option in @import
     *
     * @return a String
     */
    public abstract String getValueString();

    public static final AtRuleMedia getInstance(CssVersion version) {
        switch (version) {
            case CSS1:
                return new org.w3c.css.media.css1.AtRuleMedia();
            case CSS2:
                return new org.w3c.css.media.css2.AtRuleMedia();
            case CSS21:
                return new org.w3c.css.media.css21.AtRuleMedia();
            case CSS3:
                return new org.w3c.css.media.css3.AtRuleMedia();
        }
        return null;
    }
}




--- NEW FILE: MediaFeature.java ---
package org.w3c.css.media;

import org.w3c.css.css.StyleSheetOrigin;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssValue;

public abstract class MediaFeature implements StyleSheetOrigin {
    public CssValue value;
    public String modifier;

    /**
     * The origin of this property.
     * the author's style sheets override the reader's style sheet which
     * override the UA's default values. An imported style sheet has the same
     * origin as the style sheet from which it is imported.
     *
     * @see StyleSheetOrigin#BROWSER
     * @see StyleSheetOrigin#READER
     * @see StyleSheetOrigin#AUTHOR
     */
    public int origin;

    /**
     * the position of the first character of this value.
     */
    public int line;

    /**
     * the origin file.
     */
    public String sourceFile;


    public abstract boolean equals(MediaFeature other);

    public abstract String getFeatureName();

    // because of clashes in feature names / modifier, we can't check
// reliably unwanted modifiers, they are noy only unknown media features
    public void setModifier(ApplContext ac, String modifier)
            throws InvalidParamException {
//        if (modifier.equals("min") || modifier.equals("max")) {
        this.modifier = modifier;
//        } else {
//            throw new InvalidParamException("invalidmediafeaturemodifier",
//                    getFeatureName(), modifier, ac);
//        }
    }

    /**
     * Update the source file and the line.
     * Overrides this method for a macro
     *
     * @param line   The line number where this property is defined
     * @param source The source file where this property is defined
     */
    public void setInfo(int line, String source) {
        this.line = line;
        this.sourceFile = source;
    }

    /**
     * Fix the origin of this property
     * Overrides this method for a macro
     *
     * @param origin, an <EM>int</EM>
     * @see #BROWSER
     * @see #READER
     * @see #AUTHOR
     */
    public void setOrigin(int origin) {
        this.origin = origin;
    }

    /**
     * Returns the attribute origin
     *
     * @return the value of the attribute
     */
    public int getOrigin() {
        return origin;
    }

    /**
     * Returns the source file.
     */
    public final String getSourceFile() {
        return sourceFile;
    }

    /**
     * Returns the line number in the source file.
     */
    public final int getLine() {
        return line;
    }

    /**
     * Returns a string representation of the object.
     */
    public String toString() {
        if (value == null) {
            return getFeatureName();
        }
        StringBuilder sb = new StringBuilder();
        if (modifier != null) {
            sb.append(modifier).append('-');
        }
        sb.append(getFeatureName());
        sb.append(':').append(value.toString());
        return sb.toString();
    }
}
Received on Friday, 21 October 2011 01:49:11 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:17:47 UTC