Skip to content

Commit

Permalink
WIP: styleDeclaration is always set (issue #708)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jan 23, 2024
1 parent bac5012 commit 1a5cc2a
Showing 1 changed file with 12 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -245,6 +244,9 @@ public CSSStyleDeclaration(final Element element, final AbstractCssStyleDeclarat

setDomNode(element.getDomNodeOrNull(), false);

if (styleDeclaration == null) {
throw new IllegalStateException("styleDeclaration can't be null");
}
styleDeclaration_ = styleDeclaration;
}

Expand All @@ -257,6 +259,9 @@ public CSSStyleDeclaration(final Element element, final AbstractCssStyleDeclarat
setParentScope(parentStyleSheet);
setPrototype(getPrototype(getClass()));

if (styleDeclaration == null) {
throw new IllegalStateException("styleDeclaration can't be null");
}
styleDeclaration_ = styleDeclaration;
}

Expand Down Expand Up @@ -288,19 +293,13 @@ protected Object getWithPreemption(final String name) {
* @return the element to which this style belongs
*/
protected Element getElement() {
if (styleDeclaration_ == null) {
return null;
}
return styleDeclaration_.getElementOrNull();
}

/**
* @return the dom element to which this style belongs
*/
protected DomElement getDomElement() {
if (styleDeclaration_ == null) {
return null;
}
return styleDeclaration_.getDomElementOrNull();
}

Expand All @@ -311,9 +310,6 @@ protected DomElement getDomElement() {
* @return the named style attribute value, or an empty string if it is not found
*/
protected String getStylePriority(final String name) {
if (styleDeclaration_ == null) {
return null;
}
return styleDeclaration_.getStylePriority(name);
}

Expand All @@ -325,9 +321,6 @@ protected String getStylePriority(final String name) {
* @return the StyleElement or null if not found
*/
private StyleElement getStyleElementCaseInSensitive(final String name) {
if (styleDeclaration_ == null) {
return null;
}
return styleDeclaration_.getStyleElementCaseInSensitive(name);
}

Expand Down Expand Up @@ -359,9 +352,6 @@ protected void setStyleAttribute(final String name, String newValue, final Strin
* @param name the attribute name (delimiter-separated, not camel-cased)
*/
private String removeStyleAttribute(final String name) {
if (styleDeclaration_ == null) {
return null;
}
return styleDeclaration_.removeStyleAttribute(name);
}

Expand All @@ -372,9 +362,6 @@ private String removeStyleAttribute(final String name) {
* @return a sorted map containing style elements, keyed on style element name
*/
private Map<String, StyleElement> getStyleMap() {
if (styleDeclaration_ == null) {
return Collections.emptyMap();
}
return styleDeclaration_.getStyleMap();
}

Expand Down Expand Up @@ -1059,9 +1046,6 @@ public void setCssFloat(final String value) {
*/
@JsxGetter
public String getCssText() {
if (styleDeclaration_ == null) {
return null;
}
return styleDeclaration_.getCssText();
}

Expand Down Expand Up @@ -1250,9 +1234,6 @@ public void setLeft(final Object left) {
*/
@JsxGetter
public int getLength() {
if (styleDeclaration_ == null) {
return 0;
}
return styleDeclaration_.getLength();
}

Expand All @@ -1263,9 +1244,6 @@ public int getLength() {
*/
@JsxFunction
public Object item(final int index) {
if (styleDeclaration_ == null) {
return null;
}
return styleDeclaration_.item(index);
}

Expand Down Expand Up @@ -1528,10 +1506,7 @@ public final String getStyleAttribute(final Definition definition) {
* @return the value
*/
public String getStyleAttribute(final Definition definition, final boolean getDefaultValueIfEmpty) {
if (styleDeclaration_ != null) {
return styleDeclaration_.getStyleAttribute(definition, getDefaultValueIfEmpty);
}
return "";
return styleDeclaration_.getStyleAttribute(definition, getDefaultValueIfEmpty);
}

@Override
Expand Down Expand Up @@ -1815,11 +1790,9 @@ public void setPaddingTop(final Object paddingTop) {
*/
@JsxGetter
public CSSRule getParentRule() {
if (null != styleDeclaration_) {
final AbstractCSSRuleImpl parentRule = styleDeclaration_.getParentRule();
if (parentRule != null) {
return CSSRule.create((CSSStyleSheet) getParentScope(), parentRule);
}
final AbstractCSSRuleImpl parentRule = styleDeclaration_.getParentRule();
if (parentRule != null) {
return CSSRule.create((CSSStyleSheet) getParentScope(), parentRule);
}
return null;
}
Expand Down Expand Up @@ -2436,10 +2409,7 @@ public String getPropertyValue(final String name) {
}
}

if (styleDeclaration_ != null) {
return styleDeclaration_.getStyleAttribute(name);
}
return "";
return styleDeclaration_.getStyleAttribute(name);
}

/**
Expand Down Expand Up @@ -2739,7 +2709,7 @@ static boolean isLength(String token) {
*/
@Override
public String toString() {
if (styleDeclaration_ != null || getDomElement() == null) {
if (getDomElement() == null) {
return "CSSStyleDeclaration for 'null'"; // for instance on prototype
}

Expand Down

0 comments on commit 1a5cc2a

Please sign in to comment.