Search in sources :

Example 6 with CSSStyleDeclarationImpl

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

the class HTMLDocumentTest method testCompatComputedStyle.

@Test
public void testCompatComputedStyle() {
    HTMLElementImpl elm = (HTMLElementImpl) document.getElementById("cell12");
    assertNotNull(elm);
    assertNotNull(elm.getCurrentStyle());
    assertNotNull(elm.getCurrentStyle().getStyleDeclarations());
    CSSStyleDeclarationImpl styledecl = elm.getCurrentStyle().getStyleDeclarations().get(0);
    assertEquals("padding: 4pt 6pt; margin-left: 5pt", styledecl.toString());
    assertEquals(2, styledecl.getLength());
    assertEquals("5pt", styledecl.getPropertyValue("margin-left"));
    assertNull(styledecl.getPropertyCSSValue("does-not-exist"));
    assertEquals("", styledecl.getPropertyValue("does-not-exist"));
}
Also used : CSSStyleDeclarationImpl(com.gargoylesoftware.css.dom.CSSStyleDeclarationImpl) Test(org.junit.Test) LoboUnitTest(org.loboevolution.driver.LoboUnitTest)

Example 7 with CSSStyleDeclarationImpl

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

the class HTMLElementImpl method addStyleSheetDeclarations.

/**
 * Adds style sheet declarations applicable to this element. A properties object
 * is created if necessary when the one passed is null.
 *
 * @param style a {@link org.loboevolution.html.style.AbstractCSSProperties} object.
 * @param mouseOver a {@link java.lang.Boolean } object.
 * @return a {@link org.loboevolution.html.style.AbstractCSSProperties} object.
 */
protected final AbstractCSSProperties addStyleSheetDeclarations(AbstractCSSProperties style, boolean mouseOver) {
    final Node pn = this.parentNode;
    if (pn == null) {
        return style;
    }
    final String classNames = getClassName();
    final String elementName = getTagName();
    final String[] classNameArray = Strings.isNotBlank(classNames) ? Strings.split(classNames) : null;
    final List<CSSStyleSheetImpl.SelectorEntry> matchingRules = findStyleDeclarations(elementName, classNameArray, mouseOver);
    for (CSSStyleSheetImpl.SelectorEntry entry : matchingRules) {
        final CSSStyleDeclarationImpl cssStyleDeclarationImpl = entry.getRule().getStyle();
        if (style == null) {
            style = new AbstractCSSProperties(this);
        }
        style.addStyleDeclaration(cssStyleDeclarationImpl);
    }
    return style;
}
Also used : CSSStyleSheetImpl(com.gargoylesoftware.css.dom.CSSStyleSheetImpl) Node(org.loboevolution.html.node.Node) CSSStyleDeclarationImpl(com.gargoylesoftware.css.dom.CSSStyleDeclarationImpl)

Example 8 with CSSStyleDeclarationImpl

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

the class AbstractCSSProperties method setCssText.

/**
 * <p>setCssText.</p>
 *
 * @param cssText a {@link java.lang.String} object.
 */
public void setCssText(final String cssText) throws DOMException {
    AbstractCSSProperties sds = new AbstractCSSProperties(null);
    if (Strings.isNotBlank(cssText)) {
        final CSSOMParser parser = new CSSOMParser(new CSS3Parser());
        try {
            final CSSStyleDeclarationImpl sd = parser.parseStyleDeclaration(cssText);
            sds.addStyleDeclaration(sd);
            setLocalStyleProperties(sds);
            if (Strings.isBlank(this.cssText)) {
                this.cssText = cssText;
                context.setAttribute("style", cssText);
            }
        } catch (final Exception err) {
            logger.log(Level.WARNING, "Unable to parse style attribute value", err);
        }
    }
}
Also used : CSSOMParser(com.gargoylesoftware.css.parser.CSSOMParser) CSS3Parser(com.gargoylesoftware.css.parser.javacc.CSS3Parser) CSSStyleDeclarationImpl(com.gargoylesoftware.css.dom.CSSStyleDeclarationImpl) DOMException(com.gargoylesoftware.css.dom.DOMException)

Example 9 with CSSStyleDeclarationImpl

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

the class HTMLDocumentTest method getElementgetComputedStylePresentationalAttribute.

@Test
public void getElementgetComputedStylePresentationalAttribute() {
    HTMLDocumentImpl doc = (HTMLDocumentImpl) document;
    HTMLElementImpl elm = (HTMLElementImpl) doc.getElementById("fooimg");
    assertNotNull(elm);
    CSSStyleDeclarationImpl styledecl = elm.getStyle().getStyleDeclarations().get(0);
    assertEquals(2, styledecl.getLength());
    assertEquals("200px", styledecl.getPropertyValue("width"));
    assertEquals("180px", styledecl.getPropertyValue("height"));
    elm.setAttribute("style", "width: 220px; height: 193px;");
}
Also used : CSSStyleDeclarationImpl(com.gargoylesoftware.css.dom.CSSStyleDeclarationImpl) Test(org.junit.Test) LoboUnitTest(org.loboevolution.driver.LoboUnitTest)

Example 10 with CSSStyleDeclarationImpl

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

the class CSSStyleSheet method modifyIfNecessary.

/**
 * Modifies the specified style object by adding any style rules which apply to the specified
 * element.
 *
 * @param style the style to modify
 * @param element the element to which style rules must apply in order for them to be added to
 *        the specified style
 * @param pseudoElement a string specifying the pseudo-element to match (may be {@code null})
 */
public void modifyIfNecessary(final ComputedCSSStyleDeclaration style, final DomElement element, final String pseudoElement) {
    final BrowserVersion browser = getBrowserVersion();
    final List<CSSStyleSheetImpl.SelectorEntry> matchingRules = selects(getRuleIndex(), this, browser, element, pseudoElement, false);
    for (final CSSStyleSheetImpl.SelectorEntry entry : matchingRules) {
        final CSSStyleDeclarationImpl dec = entry.getRule().getStyle();
        style.applyStyleFromSelector(dec, entry.getSelector());
    }
}
Also used : CSSStyleSheetImpl(com.gargoylesoftware.css.dom.CSSStyleSheetImpl) CSSStyleDeclarationImpl(com.gargoylesoftware.css.dom.CSSStyleDeclarationImpl) BrowserVersion(com.gargoylesoftware.htmlunit.BrowserVersion)

Aggregations

CSSStyleDeclarationImpl (com.gargoylesoftware.css.dom.CSSStyleDeclarationImpl)10 CSSStyleSheetImpl (com.gargoylesoftware.css.dom.CSSStyleSheetImpl)3 Test (org.junit.Test)3 LoboUnitTest (org.loboevolution.driver.LoboUnitTest)3 DOMException (com.gargoylesoftware.css.dom.DOMException)2 CSSOMParser (com.gargoylesoftware.css.parser.CSSOMParser)2 CSS3Parser (com.gargoylesoftware.css.parser.javacc.CSS3Parser)2 HTMLElementImpl (org.loboevolution.html.dom.domimpl.HTMLElementImpl)2 Node (org.loboevolution.html.node.Node)2 Property (com.gargoylesoftware.css.dom.Property)1 CSSException (com.gargoylesoftware.css.parser.CSSException)1 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)1 StyleElement (com.gargoylesoftware.htmlunit.css.StyleElement)1 java.awt (java.awt)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1