Search in sources :

Example 1 with MediaQuery

use of com.gargoylesoftware.css.parser.media.MediaQuery in project htmlunit by HtmlUnit.

the class CSSStyleSheet method isActive.

/**
 * Returns whether the specified {@link MediaList} is active or not.
 * @param scriptable the scriptable
 * @param mediaList the media list
 * @return whether the specified {@link MediaList} is active or not
 */
static boolean isActive(final HtmlUnitScriptable scriptable, final MediaListImpl mediaList) {
    if (mediaList.getLength() == 0) {
        return true;
    }
    for (int i = 0; i < mediaList.getLength(); i++) {
        final MediaQuery mediaQuery = mediaList.mediaQuery(i);
        boolean isActive = isActive(scriptable, mediaQuery);
        if (mediaQuery.isNot()) {
            isActive = !isActive;
        }
        if (isActive) {
            return true;
        }
    }
    return false;
}
Also used : MediaQuery(com.gargoylesoftware.css.parser.media.MediaQuery)

Example 2 with MediaQuery

use of com.gargoylesoftware.css.parser.media.MediaQuery in project LoboEvolution by LoboEvolution.

the class CSS3Parser method mediaList.

public final void mediaList(MediaQueryList ml) throws ParseException {
    MediaQuery mq;
    try {
        mq = mediaQuery();
        ml.setLocator(createLocator(token));
        label_11: while (true) {
            switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                case COMMA:
                    {
                        ;
                        break;
                    }
                default:
                    jj_la1[20] = jj_gen;
                    break label_11;
            }
            jj_consume_token(COMMA);
            label_12: while (true) {
                switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                    case S:
                        {
                            ;
                            break;
                        }
                    default:
                        jj_la1[21] = jj_gen;
                        break label_12;
                }
                jj_consume_token(S);
            }
            ml.add(mq);
            mq = mediaQuery();
        }
        ml.add(mq);
    } catch (ParseException e) {
        throw toCSSParseException("invalidMediaList", e);
    }
}
Also used : MediaQuery(com.gargoylesoftware.css.parser.media.MediaQuery) CSSParseException(com.gargoylesoftware.css.parser.CSSParseException)

Example 3 with MediaQuery

use of com.gargoylesoftware.css.parser.media.MediaQuery in project LoboEvolution by LoboEvolution.

the class CSS3Parser method mediaQuery.

// 
// media_query
// : [ONLY | NOT]? S* media_type S* [ AND S* expression ]*
// | expression [ AND S* expression ]*
// ;
// 
public final MediaQuery mediaQuery() throws ParseException {
    String s;
    MediaQuery mq;
    Property p;
    boolean only = false;
    boolean not = false;
    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
        case NOT:
        case ONLY:
        case IDENT:
            {
                switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                    case NOT:
                    case ONLY:
                        {
                            switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                                case ONLY:
                                    {
                                        jj_consume_token(ONLY);
                                        only = true;
                                        break;
                                    }
                                case NOT:
                                    {
                                        jj_consume_token(NOT);
                                        not = true;
                                        break;
                                    }
                                default:
                                    jj_la1[22] = jj_gen;
                                    jj_consume_token(-1);
                                    throw new ParseException();
                            }
                            label_13: while (true) {
                                switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                                    case S:
                                        {
                                            ;
                                            break;
                                        }
                                    default:
                                        jj_la1[23] = jj_gen;
                                        break label_13;
                                }
                                jj_consume_token(S);
                            }
                            break;
                        }
                    default:
                        jj_la1[24] = jj_gen;
                        ;
                }
                s = medium();
                mq = new MediaQuery(s, only, not);
                mq.setLocator(createLocator(token));
                label_14: while (true) {
                    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                        case AND:
                            {
                                ;
                                break;
                            }
                        default:
                            jj_la1[25] = jj_gen;
                            break label_14;
                    }
                    jj_consume_token(AND);
                    label_15: while (true) {
                        switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                            case S:
                                {
                                    ;
                                    break;
                                }
                            default:
                                jj_la1[26] = jj_gen;
                                break label_15;
                        }
                        jj_consume_token(S);
                    }
                    p = mediaExpression();
                    mq.addMediaProperty(p);
                }
                break;
            }
        case LROUND:
            {
                p = mediaExpression();
                mq = new MediaQuery(null, only, not);
                mq.setLocator(createLocator(token));
                mq.addMediaProperty(p);
                label_16: while (true) {
                    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                        case AND:
                            {
                                ;
                                break;
                            }
                        default:
                            jj_la1[27] = jj_gen;
                            break label_16;
                    }
                    jj_consume_token(AND);
                    label_17: while (true) {
                        switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                            case S:
                                {
                                    ;
                                    break;
                                }
                            default:
                                jj_la1[28] = jj_gen;
                                break label_17;
                        }
                        jj_consume_token(S);
                    }
                    p = mediaExpression();
                    mq.addMediaProperty(p);
                }
                break;
            }
        default:
            jj_la1[29] = jj_gen;
            jj_consume_token(-1);
            throw new ParseException();
    }
    return mq;
}
Also used : MediaQuery(com.gargoylesoftware.css.parser.media.MediaQuery) CSSParseException(com.gargoylesoftware.css.parser.CSSParseException) Property(com.gargoylesoftware.css.dom.Property)

Example 4 with MediaQuery

use of com.gargoylesoftware.css.parser.media.MediaQuery in project LoboEvolution by LoboEvolution.

the class CSSStyleSheetImpl method setMediaText.

/**
 * Set the media text.
 *
 * @param mediaText the new media text
 */
public void setMediaText(final String mediaText) {
    if (mediaText == null || mediaText.length() == 0) {
        final MediaQueryList sml = new MediaQueryList();
        sml.add(new MediaQuery(null));
        media_ = new MediaListImpl(sml);
        return;
    }
    try {
        final CSSOMParser parser = new CSSOMParser();
        final MediaQueryList sml = parser.parseMedia(mediaText);
        media_ = new MediaListImpl(sml);
    } catch (final IOException e) {
    // TODO handle exception
    }
}
Also used : CSSOMParser(com.gargoylesoftware.css.parser.CSSOMParser) MediaQuery(com.gargoylesoftware.css.parser.media.MediaQuery) MediaQueryList(com.gargoylesoftware.css.parser.media.MediaQueryList) IOException(java.io.IOException)

Example 5 with MediaQuery

use of com.gargoylesoftware.css.parser.media.MediaQuery in project LoboEvolution by LoboEvolution.

the class MediaListImpl method getMediaText.

/**
 * <p>getMediaText.</p>
 *
 * @return the media text
 */
public String getMediaText() {
    final StringBuilder sb = new StringBuilder();
    boolean isNotFirst = false;
    for (final MediaQuery mediaQuery : mediaQueries_) {
        if (isNotFirst) {
            sb.append(", ");
        } else {
            isNotFirst = true;
        }
        sb.append(mediaQuery.toString());
    }
    return sb.toString();
}
Also used : MediaQuery(com.gargoylesoftware.css.parser.media.MediaQuery)

Aggregations

MediaQuery (com.gargoylesoftware.css.parser.media.MediaQuery)7 CSSParseException (com.gargoylesoftware.css.parser.CSSParseException)2 Property (com.gargoylesoftware.css.dom.Property)1 CSSOMParser (com.gargoylesoftware.css.parser.CSSOMParser)1 MediaQueryList (com.gargoylesoftware.css.parser.media.MediaQueryList)1 IOException (java.io.IOException)1