Skip to content

Commit

Permalink
WIP: code cleanup (issue #708)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jan 26, 2024
1 parent c8a4884 commit 0d3e021
Showing 1 changed file with 37 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,6 @@
import static org.htmlunit.css.CssStyleSheet.RELATIVE;
import static org.htmlunit.css.CssStyleSheet.SCROLL;
import static org.htmlunit.css.CssStyleSheet.STATIC;
import static org.htmlunit.css.StyleAttributes.Definition.BACKGROUND_ATTACHMENT;
import static org.htmlunit.css.StyleAttributes.Definition.BACKGROUND_COLOR;
import static org.htmlunit.css.StyleAttributes.Definition.BACKGROUND_IMAGE;
import static org.htmlunit.css.StyleAttributes.Definition.BACKGROUND_POSITION;
import static org.htmlunit.css.StyleAttributes.Definition.BACKGROUND_REPEAT;
import static org.htmlunit.css.StyleAttributes.Definition.BORDER_BOTTOM_COLOR;
import static org.htmlunit.css.StyleAttributes.Definition.BORDER_BOTTOM_STYLE;
import static org.htmlunit.css.StyleAttributes.Definition.BORDER_BOTTOM_WIDTH;
import static org.htmlunit.css.StyleAttributes.Definition.BORDER_LEFT_COLOR;
import static org.htmlunit.css.StyleAttributes.Definition.BORDER_LEFT_STYLE;
import static org.htmlunit.css.StyleAttributes.Definition.BOX_SIZING;
import static org.htmlunit.css.StyleAttributes.Definition.CSS_FLOAT;
import static org.htmlunit.css.StyleAttributes.Definition.HEIGHT;
import static org.htmlunit.css.StyleAttributes.Definition.LEFT;
import static org.htmlunit.css.StyleAttributes.Definition.LINE_HEIGHT;
import static org.htmlunit.css.StyleAttributes.Definition.MARGIN;
import static org.htmlunit.css.StyleAttributes.Definition.MARGIN_LEFT;
import static org.htmlunit.css.StyleAttributes.Definition.MARGIN_RIGHT;
import static org.htmlunit.css.StyleAttributes.Definition.ORPHANS;
import static org.htmlunit.css.StyleAttributes.Definition.OVERFLOW;
import static org.htmlunit.css.StyleAttributes.Definition.PADDING;
import static org.htmlunit.css.StyleAttributes.Definition.POSITION;
import static org.htmlunit.css.StyleAttributes.Definition.TOP;
import static org.htmlunit.css.StyleAttributes.Definition.WIDOWS;
import static org.htmlunit.css.StyleAttributes.Definition.WIDTH;
import static org.htmlunit.css.StyleAttributes.Definition.WORD_SPACING;
import static org.htmlunit.javascript.configuration.SupportedBrowser.FF;
import static org.htmlunit.javascript.configuration.SupportedBrowser.FF_ESR;

Expand Down Expand Up @@ -239,7 +213,7 @@ public String getAccelerator() {
*/
@Override
public String getBackgroundAttachment() {
return defaultIfEmpty(super.getBackgroundAttachment(), BACKGROUND_ATTACHMENT);
return defaultIfEmpty(super.getBackgroundAttachment(), Definition.BACKGROUND_ATTACHMENT);
}

/**
Expand All @@ -249,7 +223,7 @@ public String getBackgroundAttachment() {
public String getBackgroundColor() {
final String value = super.getBackgroundColor();
if (StringUtils.isEmpty(value)) {
return BACKGROUND_COLOR.getDefaultComputedValue(getBrowserVersion());
return Definition.BACKGROUND_COLOR.getDefaultComputedValue(getBrowserVersion());
}
return CssColors.toRGBColor(value);
}
Expand All @@ -259,7 +233,7 @@ public String getBackgroundColor() {
*/
@Override
public String getBackgroundImage() {
return defaultIfEmpty(super.getBackgroundImage(), BACKGROUND_IMAGE);
return defaultIfEmpty(super.getBackgroundImage(), Definition.BACKGROUND_IMAGE);
}

/**
Expand All @@ -268,55 +242,55 @@ public String getBackgroundImage() {
*/
@Override
public String getBackgroundPosition() {
return defaultIfEmpty(super.getBackgroundPosition(), BACKGROUND_POSITION);
return defaultIfEmpty(super.getBackgroundPosition(), Definition.BACKGROUND_POSITION);
}

/**
* {@inheritDoc}
*/
@Override
public String getBackgroundRepeat() {
return defaultIfEmpty(super.getBackgroundRepeat(), BACKGROUND_REPEAT);
return defaultIfEmpty(super.getBackgroundRepeat(), Definition.BACKGROUND_REPEAT);
}

/**
* {@inheritDoc}
*/
@Override
public String getBorderBottomColor() {
return defaultIfEmpty(super.getBorderBottomColor(), BORDER_BOTTOM_COLOR);
return defaultIfEmpty(super.getBorderBottomColor(), Definition.BORDER_BOTTOM_COLOR);
}

/**
* {@inheritDoc}
*/
@Override
public String getBorderBottomStyle() {
return defaultIfEmpty(super.getBorderBottomStyle(), BORDER_BOTTOM_STYLE);
return defaultIfEmpty(super.getBorderBottomStyle(), Definition.BORDER_BOTTOM_STYLE);
}

/**
* {@inheritDoc}
*/
@Override
public String getBorderBottomWidth() {
return pixelString(defaultIfEmpty(super.getBorderBottomWidth(), BORDER_BOTTOM_WIDTH));
return pixelString(defaultIfEmpty(super.getBorderBottomWidth(), Definition.BORDER_BOTTOM_WIDTH));
}

/**
* {@inheritDoc}
*/
@Override
public String getBorderLeftColor() {
return defaultIfEmpty(super.getBorderLeftColor(), BORDER_LEFT_COLOR);
return defaultIfEmpty(super.getBorderLeftColor(), Definition.BORDER_LEFT_COLOR);
}

/**
* {@inheritDoc}
*/
@Override
public String getBorderLeftStyle() {
return defaultIfEmpty(super.getBorderLeftStyle(), BORDER_LEFT_STYLE);
return defaultIfEmpty(super.getBorderLeftStyle(), Definition.BORDER_LEFT_STYLE);
}

/**
Expand Down Expand Up @@ -396,7 +370,7 @@ public String getColor() {
*/
@Override
public String getCssFloat() {
return defaultIfEmpty(super.getCssFloat(), CSS_FLOAT);
return defaultIfEmpty(super.getCssFloat(), Definition.CSS_FLOAT);
}

/**
Expand Down Expand Up @@ -436,7 +410,7 @@ public String getFontSize() {
*/
@Override
public String getLineHeight() {
return defaultIfEmpty(super.getLineHeight(), LINE_HEIGHT);
return defaultIfEmpty(super.getLineHeight(), Definition.LINE_HEIGHT);
}

/**
Expand All @@ -453,7 +427,7 @@ public String getHeight() {
if (getBrowserVersion().hasFeature(CSS_STYLE_PROP_DISCONNECTED_IS_EMPTY)) {
return "";
}
if (getStyleAttribute(HEIGHT, true).isEmpty()) {
if (getStyleAttribute(Definition.HEIGHT, true).isEmpty()) {
return AUTO;
}
}
Expand All @@ -463,7 +437,7 @@ public String getHeight() {
@Override
public String get(final ComputedCssStyleDeclaration style) {
final String offsetHeight = ((HTMLElement) elem).getOffsetHeight() + "px";
return defaultIfEmpty(style.getStyleAttribute(HEIGHT, true), offsetHeight, AUTO);
return defaultIfEmpty(style.getStyleAttribute(Definition.HEIGHT, true), offsetHeight, AUTO);
}
});
}
Expand All @@ -483,9 +457,9 @@ public String getLeft() {
@Override
public String get(final ComputedCssStyleDeclaration style) {
if (style.getDomElement() == element) {
return style.getStyleAttribute(LEFT, true);
return style.getStyleAttribute(Definition.LEFT, true);
}
return style.getStyleAttribute(WIDTH, true);
return style.getStyleAttribute(Definition.WIDTH, true);
}
});
}
Expand All @@ -503,7 +477,7 @@ public String getLetterSpacing() {
*/
@Override
public String getMargin() {
return defaultIfEmpty(super.getMargin(), MARGIN, true);
return defaultIfEmpty(super.getMargin(), Definition.MARGIN, true);
}

/**
Expand All @@ -519,15 +493,15 @@ public String getMarginBottom() {
*/
@Override
public String getMarginLeft() {
return getMarginX(super.getMarginLeft(), MARGIN_LEFT);
return getMarginX(super.getMarginLeft(), Definition.MARGIN_LEFT);
}

/**
* {@inheritDoc}
*/
@Override
public String getMarginRight() {
return getMarginX(super.getMarginRight(), MARGIN_RIGHT);
return getMarginX(super.getMarginRight(), Definition.MARGIN_RIGHT);
}

private String getMarginX(final String superMarginX, final Definition definition) {
Expand All @@ -548,7 +522,7 @@ public String get(final ComputedCssStyleDeclaration style) {
if (style.getDomElement() == element) {
return style.getStyleAttribute(definition, true);
}
return style.getStyleAttribute(WIDTH, true);
return style.getStyleAttribute(Definition.WIDTH, true);
}
});
}
Expand Down Expand Up @@ -614,7 +588,7 @@ public String getOutlineWidth() {
*/
@Override
public String getPadding() {
return defaultIfEmpty(super.getPadding(), PADDING, true);
return defaultIfEmpty(super.getPadding(), Definition.PADDING, true);
}

/**
Expand Down Expand Up @@ -677,16 +651,16 @@ && getBrowserVersion().hasFeature(CSS_STYLE_PROP_DISCONNECTED_IS_EMPTY)) {
}
final String superTop = super.getTop();
if (!superTop.endsWith("%")) {
return defaultIfEmpty(superTop, TOP);
return defaultIfEmpty(superTop, Definition.TOP);
}

return CssPixelValueConverter.pixelString(element, new CssPixelValueConverter.CssValue(0, 0) {
@Override
public String get(final ComputedCssStyleDeclaration style) {
if (style.getDomElement() == element) {
return style.getStyleAttribute(TOP, true);
return style.getStyleAttribute(Definition.TOP, true);
}
return style.getStyleAttribute(HEIGHT, true);
return style.getStyleAttribute(Definition.HEIGHT, true);
}
});
}
Expand All @@ -704,23 +678,23 @@ public String getVerticalAlign() {
*/
@Override
public String getWidows() {
return defaultIfEmpty(super.getWidows(), WIDOWS);
return defaultIfEmpty(super.getWidows(), Definition.WIDOWS);
}

/**
* {@inheritDoc}
*/
@Override
public String getOrphans() {
return defaultIfEmpty(super.getOrphans(), ORPHANS);
return defaultIfEmpty(super.getOrphans(), Definition.ORPHANS);
}

/**
* {@inheritDoc}
*/
@Override
public String getPosition() {
return defaultIfEmpty(super.getPosition(), POSITION);
return defaultIfEmpty(super.getPosition(), Definition.POSITION);
}

/**
Expand All @@ -744,7 +718,7 @@ public int getCalculatedWidth(final boolean includeBorder, final boolean include
return 0;
}
int width = getCalculatedWidth();
if (!"border-box".equals(getStyleAttribute(BOX_SIZING))) {
if (!"border-box".equals(getStyleAttribute(Definition.BOX_SIZING))) {
if (includeBorder) {
width += getBorderHorizontal();
}
Expand Down Expand Up @@ -788,7 +762,7 @@ private int getCalculatedWidth() {

// Width not explicitly set.
final String cssFloat = getCssFloat();
final String position = getStyleAttribute(POSITION, true);
final String position = getStyleAttribute(Definition.POSITION, true);
if ("right".equals(cssFloat) || "left".equals(cssFloat)
|| ABSOLUTE.equals(position) || FIXED.equals(position)) {
// We're floating; simplistic approximation: text content * pixels per character.
Expand Down Expand Up @@ -859,7 +833,7 @@ else if (AUTO.equals(styleWidth)) {
width = CssPixelValueConverter.pixelValue(element,
new CssPixelValueConverter.CssValue(0, element.getPage().getEnclosingWindow().getInnerWidth()) {
@Override public String get(final ComputedCssStyleDeclaration style) {
return style.getStyleAttribute(WIDTH, true);
return style.getStyleAttribute(Definition.WIDTH, true);
}
});
}
Expand Down Expand Up @@ -917,7 +891,7 @@ public int getCalculatedHeight(final boolean includeBorder, final boolean includ
return 0;
}
int height = getCalculatedHeight();
if (!"border-box".equals(getStyleAttribute(BOX_SIZING))) {
if (!"border-box".equals(getStyleAttribute(Definition.BOX_SIZING))) {
if (includeBorder) {
height += getBorderVertical();
}
Expand Down Expand Up @@ -1050,12 +1024,12 @@ else if (element instanceof HtmlInlineFrame) {

if (element instanceof HtmlDivision
|| element instanceof HtmlSpan) {
String width = getStyleAttribute(WIDTH, false);
String width = getStyleAttribute(Definition.WIDTH, false);

// maybe we are enclosed something that forces a width
Element parent = getParentElement();
while (width.isEmpty() && parent != null) {
width = getWindow().getComputedStyle(parent, null).getStyleAttribute(WIDTH, false);
width = getWindow().getComputedStyle(parent, null).getStyleAttribute(Definition.WIDTH, false);
parent = parent.getParentElement();
}
final int pixelWidth = CssPixelValueConverter.pixelValue(width);
Expand Down Expand Up @@ -1091,7 +1065,7 @@ else if (element instanceof HtmlInlineFrame) {
if (isInline) {
return "";
}
return style.getStyleAttribute(HEIGHT, true);
return style.getStyleAttribute(Definition.HEIGHT, true);
}
});

Expand Down Expand Up @@ -1178,7 +1152,7 @@ public boolean isScrollable(final boolean horizontal) {
private boolean isScrollable(final boolean horizontal, final boolean ignoreSize) {
final boolean scrollable;
final DomElement element = getDomElement();
final String overflow = getStyleAttribute(OVERFLOW, true);
final String overflow = getStyleAttribute(Definition.OVERFLOW, true);
if (horizontal) {
// TODO: inherit, overflow-x
scrollable = (element instanceof HtmlBody || SCROLL.equals(overflow) || AUTO.equals(overflow))
Expand Down Expand Up @@ -1424,7 +1398,7 @@ else if (prevScriptable instanceof Text) {
* @return the CSS {@code position} attribute, replacing inherited values with the actual parent values
*/
public String getPositionWithInheritance() {
String p = getStyleAttribute(POSITION, true);
String p = getStyleAttribute(Definition.POSITION, true);
if (INHERIT.equals(p)) {
final HTMLElement parent = (HTMLElement) getElement().getParentElement();
if (parent == null) {
Expand Down Expand Up @@ -1655,7 +1629,7 @@ private int getBorderVertical() {
*/
@Override
public String getWordSpacing() {
return defaultIfEmpty(super.getWordSpacing(), WORD_SPACING);
return defaultIfEmpty(super.getWordSpacing(), Definition.WORD_SPACING);
}

/**
Expand Down

0 comments on commit 0d3e021

Please sign in to comment.