Search in sources :

Example 1 with Definition

use of com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition in project htmlunit by HtmlUnit.

the class StyleAttributesTest method lexicographicOrder.

/**
 * Test of alphabetical order.
 */
@Test
public void lexicographicOrder() {
    String lastName = null;
    for (final Definition definition : StyleAttributes.Definition.values()) {
        final String name = definition.name();
        if (lastName != null && name.compareToIgnoreCase(lastName) < 1) {
            fail("StyleAttributes.Definition: '" + name + "' should be before '" + lastName + "'");
        }
        lastName = name;
    }
}
Also used : Definition(com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition) Test(org.junit.Test)

Example 2 with Definition

use of com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition in project htmlunit by HtmlUnit.

the class CSSStyleDeclarationTest method styleAttributes.

/**
 * Tests that all getters and setters {@link CSSStyleDeclaration} have correct browser support
 * as defined in {@link StyleAttributes}.
 *
 * @throws Exception if an error occurs
 */
@Test
public void styleAttributes() throws Exception {
    final List<String> allProperties = new ArrayList<>();
    for (final BrowserVersion browserVersion : allBrowsers()) {
        final ClassConfiguration config = AbstractJavaScriptConfiguration.getClassConfiguration(CSSStyleDeclaration.class, browserVersion);
        for (final Definition definition : StyleAttributes.getDefinitions(browserVersion)) {
            if (!definition.name().endsWith("_")) {
                final String propertyName = definition.getPropertyName();
                final PropertyInfo info = config.getPropertyMap().get(propertyName);
                if (info != null) {
                    allProperties.add(propertyName);
                }
            }
        }
    }
    final BrowserVersion browserVersion = getBrowserVersion();
    final ClassConfiguration config = AbstractJavaScriptConfiguration.getClassConfiguration(CSSStyleDeclaration.class, browserVersion);
    for (final Definition definition : StyleAttributes.getDefinitions(browserVersion)) {
        if (!definition.name().endsWith("_")) {
            final String propertyName = definition.getPropertyName();
            final PropertyInfo info = config.getPropertyMap().get(propertyName);
            if (allProperties.contains(propertyName) && (info == null || info.getReadMethod() == null || info.getWriteMethod() == null)) {
                fail("CSSStyleDeclaration: " + propertyName + " must support " + browserVersion.getNickname());
            }
        }
    }
    for (final String propertyName : config.getPropertyMap().keySet()) {
        if (!"length".equals(propertyName) && !"parentRule".equals(propertyName) && !"cssText".equals(propertyName) && StyleAttributes.getDefinition(propertyName, browserVersion) == null) {
            fail("CSSStyleDeclaration: incorrectly defines " + propertyName + " for " + browserVersion.getNickname());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Definition(com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition) PropertyInfo(com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration.PropertyInfo) BrowserVersion(com.gargoylesoftware.htmlunit.BrowserVersion) ClassConfiguration(com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration) Test(org.junit.Test)

Example 3 with Definition

use of com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition in project htmlunit by HtmlUnit.

the class CSSStyleDeclaration method getIds.

@Override
public Object[] getIds() {
    final List<Object> ids = new ArrayList<>();
    for (final Definition styleAttribute : StyleAttributes.getDefinitions(getBrowserVersion())) {
        ids.add(styleAttribute.getPropertyName());
    }
    final Object[] normalIds = super.getIds();
    for (final Object o : normalIds) {
        if (!ids.contains(o)) {
            ids.add(o);
        }
    }
    return ids.toArray();
}
Also used : ArrayList(java.util.ArrayList) Definition(com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition)

Example 4 with Definition

use of com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition in project htmlunit by HtmlUnit.

the class CSSStyleDeclaration method get.

/**
 * {@inheritDoc}
 */
@Override
public Object get(final String name, final Scriptable start) {
    if (this != start) {
        return super.get(name, start);
    }
    Scriptable prototype = getPrototype();
    while (prototype != null) {
        Object value = prototype.get(name, start);
        if (value != Scriptable.NOT_FOUND) {
            return value;
        }
        final String camel = camelize(name);
        if (!name.equals(camel)) {
            value = prototype.get(camel, start);
            if (value != Scriptable.NOT_FOUND) {
                return value;
            }
        }
        prototype = prototype.getPrototype();
    }
    final Definition style = StyleAttributes.getDefinition(name, getBrowserVersion());
    if (style != null) {
        return getStyleAttribute(style);
    }
    return super.get(name, start);
}
Also used : Definition(com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition) Scriptable(net.sourceforge.htmlunit.corejs.javascript.Scriptable) HtmlUnitScriptable(com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable)

Example 5 with Definition

use of com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition in project htmlunit by HtmlUnit.

the class CSSStyleDeclaration method put.

@Override
public void put(final String name, final Scriptable start, final Object value) {
    if (this != start) {
        super.put(name, start, value);
        return;
    }
    final Scriptable prototype = getPrototype();
    if (prototype != null && !"constructor".equals(name)) {
        if (prototype.get(name, start) != Scriptable.NOT_FOUND) {
            prototype.put(name, start, value);
            return;
        }
        final String camel = camelize(name);
        if (!name.equals(camel) && prototype.get(camel, start) != Scriptable.NOT_FOUND) {
            prototype.put(camel, start, value);
            return;
        }
    }
    if (getDomNodeOrNull() != null) {
        // check if prototype or not
        final Definition style = StyleAttributes.getDefinition(name, getBrowserVersion());
        if (style != null) {
            final String stringValue = Context.toString(value);
            setStyleAttribute(style.getAttributeName(), stringValue);
            return;
        }
    }
    super.put(name, start, value);
}
Also used : Definition(com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition) Scriptable(net.sourceforge.htmlunit.corejs.javascript.Scriptable) HtmlUnitScriptable(com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable)

Aggregations

Definition (com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition)6 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 HtmlUnitScriptable (com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable)2 Scriptable (net.sourceforge.htmlunit.corejs.javascript.Scriptable)2 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)1 ClassConfiguration (com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration)1 PropertyInfo (com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration.PropertyInfo)1