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"));
}
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;
}
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);
}
}
}
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;");
}
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());
}
}
Aggregations