Search in sources :

Example 1 with CSSValueImpl

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

the class CSSStyleSheet method isActive.

private static boolean isActive(final HtmlUnitScriptable scriptable, final MediaQuery mediaQuery) {
    final String mediaType = mediaQuery.getMedia();
    if ("screen".equalsIgnoreCase(mediaType) || "all".equalsIgnoreCase(mediaType)) {
        for (final Property property : mediaQuery.getProperties()) {
            final double val;
            switch(property.getName()) {
                case "max-width":
                    val = pixelValue(property.getValue(), scriptable);
                    if (val == -1 || val < scriptable.getWindow().getWebWindow().getInnerWidth()) {
                        return false;
                    }
                    break;
                case "min-width":
                    val = pixelValue(property.getValue(), scriptable);
                    if (val == -1 || val > scriptable.getWindow().getWebWindow().getInnerWidth()) {
                        return false;
                    }
                    break;
                case "max-device-width":
                    val = pixelValue(property.getValue(), scriptable);
                    if (val == -1 || val < scriptable.getWindow().getScreen().getWidth()) {
                        return false;
                    }
                    break;
                case "min-device-width":
                    val = pixelValue(property.getValue(), scriptable);
                    if (val == -1 || val > scriptable.getWindow().getScreen().getWidth()) {
                        return false;
                    }
                    break;
                case "max-height":
                    val = pixelValue(property.getValue(), scriptable);
                    if (val == -1 || val < scriptable.getWindow().getWebWindow().getInnerWidth()) {
                        return false;
                    }
                    break;
                case "min-height":
                    val = pixelValue(property.getValue(), scriptable);
                    if (val == -1 || val > scriptable.getWindow().getWebWindow().getInnerWidth()) {
                        return false;
                    }
                    break;
                case "max-device-height":
                    val = pixelValue(property.getValue(), scriptable);
                    if (val == -1 || val < scriptable.getWindow().getScreen().getWidth()) {
                        return false;
                    }
                    break;
                case "min-device-height":
                    val = pixelValue(property.getValue(), scriptable);
                    if (val == -1 || val > scriptable.getWindow().getScreen().getWidth()) {
                        return false;
                    }
                    break;
                case "resolution":
                    final CSSValueImpl propValue = property.getValue();
                    val = resolutionValue(propValue);
                    if (propValue == null) {
                        return true;
                    }
                    if (val == -1 || Math.round(val) != scriptable.getWindow().getScreen().getDeviceXDPI()) {
                        return false;
                    }
                    break;
                case "max-resolution":
                    val = resolutionValue(property.getValue());
                    if (val == -1 || val < scriptable.getWindow().getScreen().getDeviceXDPI()) {
                        return false;
                    }
                    break;
                case "min-resolution":
                    val = resolutionValue(property.getValue());
                    if (val == -1 || val > scriptable.getWindow().getScreen().getDeviceXDPI()) {
                        return false;
                    }
                    break;
                case "orientation":
                    final CSSValueImpl cssValue = property.getValue();
                    if (cssValue == null) {
                        if (LOG.isWarnEnabled()) {
                            LOG.warn("CSSValue is null not supported for feature 'orientation'");
                        }
                        return true;
                    }
                    final String orient = cssValue.getCssText();
                    final WebWindow window = scriptable.getWindow().getWebWindow();
                    if ("portrait".equals(orient)) {
                        if (window.getInnerWidth() > window.getInnerHeight()) {
                            return false;
                        }
                    } else if ("landscape".equals(orient)) {
                        if (window.getInnerWidth() < window.getInnerHeight()) {
                            return false;
                        }
                    } else {
                        if (LOG.isWarnEnabled()) {
                            LOG.warn("CSSValue '" + property.getValue().getCssText() + "' not supported for feature 'orientation'.");
                        }
                        return false;
                    }
                    break;
                default:
            }
        }
        return true;
    }
    return false;
}
Also used : CSSValueImpl(com.gargoylesoftware.css.dom.CSSValueImpl) Property(com.gargoylesoftware.css.dom.Property) WebWindow(com.gargoylesoftware.htmlunit.WebWindow)

Example 2 with CSSValueImpl

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

the class AbstractCSSProperties method getPropertyCSSValue.

/**
 * <p>getPropertyCSSValue.</p>
 * @param propertyName a {@link java.lang.String} object.
 * @return a {@link java.lang.String} object.
 */
public String getPropertyCSSValue(String propertyName) {
    AtomicReference<String> props = new AtomicReference<>();
    styleDeclarations.forEach(css -> {
        CSSValueImpl prop = css.getPropertyCSSValue(propertyName);
        if (prop != null) {
            props.set(prop.getStringValue());
        }
    });
    return props.get();
}
Also used : CSSValueImpl(com.gargoylesoftware.css.dom.CSSValueImpl) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 3 with CSSValueImpl

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

the class CSSOMParser method parsePropertyValue.

/**
 * Parses a input string into a CSSValue.
 *
 * @param propertyValue the input string
 * @return the css value
 * @throws IOException if the underlying SAC parser throws an IOException
 */
public CSSValueImpl parsePropertyValue(final String propertyValue) throws IOException {
    try (InputSource source = new InputSource(new StringReader(propertyValue))) {
        final CSSOMHandler handler = new CSSOMHandler();
        parser_.setDocumentHandler(handler);
        final LexicalUnit lu = parser_.parsePropertyValue(source);
        if (null == lu) {
            return null;
        }
        return new CSSValueImpl(lu);
    }
}
Also used : CSSValueImpl(com.gargoylesoftware.css.dom.CSSValueImpl) StringReader(java.io.StringReader)

Example 4 with CSSValueImpl

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

the class CSS3Parser method mediaExpression.

// 
// expression
// : '(' S* media_feature S* [ ':' S* expr ]? ')' S*
// ;
// 
public final Property mediaExpression() throws ParseException {
    String p;
    LexicalUnit e = null;
    Property prop;
    jj_consume_token(LROUND);
    label_18: while (true) {
        switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
            case S:
                {
                    ;
                    break;
                }
            default:
                jj_la1[30] = jj_gen;
                break label_18;
        }
        jj_consume_token(S);
    }
    p = property();
    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
        case COLON:
            {
                jj_consume_token(COLON);
                label_19: while (true) {
                    switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
                        case S:
                            {
                                ;
                                break;
                            }
                        default:
                            jj_la1[31] = jj_gen;
                            break label_19;
                    }
                    jj_consume_token(S);
                }
                e = expr();
                break;
            }
        default:
            jj_la1[32] = jj_gen;
            ;
    }
    jj_consume_token(RROUND);
    label_20: while (true) {
        switch((jj_ntk == -1) ? jj_ntk_f() : jj_ntk) {
            case S:
                {
                    ;
                    break;
                }
            default:
                jj_la1[33] = jj_gen;
                break label_20;
        }
        jj_consume_token(S);
    }
    if (e == null) {
        prop = new Property(p, null, false);
    } else {
        prop = new Property(p, new CSSValueImpl(e), false);
    }
    return prop;
}
Also used : CSSValueImpl(com.gargoylesoftware.css.dom.CSSValueImpl) Property(com.gargoylesoftware.css.dom.Property) LexicalUnit(com.gargoylesoftware.css.parser.LexicalUnit)

Aggregations

CSSValueImpl (com.gargoylesoftware.css.dom.CSSValueImpl)4 Property (com.gargoylesoftware.css.dom.Property)2 LexicalUnit (com.gargoylesoftware.css.parser.LexicalUnit)1 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)1 StringReader (java.io.StringReader)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1