Search in sources :

Example 6 with MediaListImpl

use of com.gargoylesoftware.css.dom.MediaListImpl in project htmlunit by HtmlUnit.

the class CSSMediaRule method getMedia.

/**
 * Returns the media types that the imported CSS style sheet applies to.
 * @return the media types that the imported CSS style sheet applies to
 */
@JsxGetter
public MediaList getMedia() {
    if (media_ == null) {
        final CSSStyleSheet parent = getParentStyleSheet();
        final MediaListImpl ml = getMediaRule().getMediaList();
        media_ = new MediaList(parent, ml);
    }
    return media_;
}
Also used : MediaList(com.gargoylesoftware.htmlunit.javascript.host.dom.MediaList) MediaListImpl(com.gargoylesoftware.css.dom.MediaListImpl) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 7 with MediaListImpl

use of com.gargoylesoftware.css.dom.MediaListImpl in project LoboEvolution by LoboEvolution.

the class MediaQueryListImpl method isMatches.

/**
 * <p>isMatches.</p>
 *
 * @return a boolean.
 * @throws java.lang.Exception if any.
 */
public boolean isMatches() throws Exception {
    final String processedText = CSSUtilities.preProcessCss(media);
    MediaListImpl media = CSSUtilities.parseMedia(processedText);
    return StyleSheetAggregator.isActive(window, media);
}
Also used : MediaListImpl(com.gargoylesoftware.css.dom.MediaListImpl)

Example 8 with MediaListImpl

use of com.gargoylesoftware.css.dom.MediaListImpl in project htmlunit by HtmlUnit.

the class CSSStyleSheet method parseMedia.

/**
 * Parses the given media string. If anything at all goes wrong, this
 * method returns an empty MediaList list.
 *
 * @param source the source from which to retrieve the media to be parsed
 * @return the media parsed from the specified input source
 */
static MediaListImpl parseMedia(final CSSErrorHandler errorHandler, final String mediaString) {
    MediaListImpl media = media_.get(mediaString);
    if (media != null) {
        return media;
    }
    try {
        final CSSOMParser parser = new CSSOMParser(new CSS3Parser());
        parser.setErrorHandler(errorHandler);
        media = new MediaListImpl(parser.parseMedia(mediaString));
        media_.put(mediaString, media);
        return media;
    } catch (final Exception e) {
        if (LOG.isErrorEnabled()) {
            LOG.error("Error parsing CSS media from '" + mediaString + "': " + e.getMessage(), e);
        }
    }
    media = new MediaListImpl(null);
    media_.put(mediaString, media);
    return media;
}
Also used : CSSOMParser(com.gargoylesoftware.css.parser.CSSOMParser) CSS3Parser(com.gargoylesoftware.css.parser.javacc.CSS3Parser) MediaListImpl(com.gargoylesoftware.css.dom.MediaListImpl) FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) CSSException(com.gargoylesoftware.css.parser.CSSException) IOException(java.io.IOException) CSSParseException(com.gargoylesoftware.css.parser.CSSParseException) DOMException(org.w3c.dom.DOMException) MalformedURLException(java.net.MalformedURLException)

Example 9 with MediaListImpl

use of com.gargoylesoftware.css.dom.MediaListImpl in project htmlunit by HtmlUnit.

the class CSSImportRule method getMedia.

/**
 * Returns the media types that the imported CSS style sheet applies to.
 * @return the media types that the imported CSS style sheet applies to
 */
@JsxGetter
public MediaList getMedia() {
    if (media_ == null) {
        final CSSStyleSheet parent = getParentStyleSheet();
        final MediaListImpl ml = getImportRule().getMedia();
        media_ = new MediaList(parent, ml);
    }
    return media_;
}
Also used : MediaList(com.gargoylesoftware.htmlunit.javascript.host.dom.MediaList) MediaListImpl(com.gargoylesoftware.css.dom.MediaListImpl) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Aggregations

MediaListImpl (com.gargoylesoftware.css.dom.MediaListImpl)9 JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)3 CSSErrorHandler (com.gargoylesoftware.css.parser.CSSErrorHandler)2 WebClient (com.gargoylesoftware.htmlunit.WebClient)2 HtmlLink (com.gargoylesoftware.htmlunit.html.HtmlLink)2 MediaList (com.gargoylesoftware.htmlunit.javascript.host.dom.MediaList)2 AbstractCSSRuleImpl (com.gargoylesoftware.css.dom.AbstractCSSRuleImpl)1 CSSImportRuleImpl (com.gargoylesoftware.css.dom.CSSImportRuleImpl)1 CSSMediaRuleImpl (com.gargoylesoftware.css.dom.CSSMediaRuleImpl)1 CSSRuleListImpl (com.gargoylesoftware.css.dom.CSSRuleListImpl)1 CSSStyleRuleImpl (com.gargoylesoftware.css.dom.CSSStyleRuleImpl)1 CSSException (com.gargoylesoftware.css.parser.CSSException)1 CSSOMParser (com.gargoylesoftware.css.parser.CSSOMParser)1 CSSParseException (com.gargoylesoftware.css.parser.CSSParseException)1 Condition (com.gargoylesoftware.css.parser.condition.Condition)1 CSS3Parser (com.gargoylesoftware.css.parser.javacc.CSS3Parser)1 ChildSelector (com.gargoylesoftware.css.parser.selector.ChildSelector)1 DescendantSelector (com.gargoylesoftware.css.parser.selector.DescendantSelector)1 DirectAdjacentSelector (com.gargoylesoftware.css.parser.selector.DirectAdjacentSelector)1 ElementSelector (com.gargoylesoftware.css.parser.selector.ElementSelector)1