Skip to content

Commit 3b74b08

Browse files
committed
CSS blockSize support improved
1 parent 6e9a55e commit 3b74b08

File tree

7 files changed

+101
-20
lines changed

7 files changed

+101
-20
lines changed

src/changes/changes.xml

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
<body>
1010
<release version="4.12.0" date="April xx, 2025" description="Chrome/Edge 135, Firefox 137, Rhino RegExp, Bugfixes">
11+
<action type="update" dev="rbri">
12+
CSS blockSize support improved.
13+
</action>
1114
<action type="fix" dev="RhinoTeam">
1215
core-js: Complete reimplementation of 'String.prototype.search', 'String.prototype.replace',
1316
'String.prototype.replaceAll', and 'String.prototype.split'. The new impl is much closer to the spec.

src/main/java/org/htmlunit/css/AbstractCssStyleDeclaration.java

+8
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,14 @@ public String getBackgroundRepeat() {
437437
return value;
438438
}
439439

440+
/**
441+
* Gets the {@code blockSize} style attribute.
442+
* @return the style attribute
443+
*/
444+
public String getBlockSize() {
445+
return getStyleAttribute(Definition.BLOCK_SIZE, true);
446+
}
447+
440448
/**
441449
* Gets the {@code borderBottomColor} style attribute.
442450
* @return the style attribute

src/main/java/org/htmlunit/css/ComputedCssStyleDeclaration.java

+32
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,38 @@ public String getBackgroundRepeat() {
565565
return defaultIfEmpty(super.getBackgroundRepeat(), Definition.BACKGROUND_REPEAT);
566566
}
567567

568+
/**
569+
* {@inheritDoc}
570+
*/
571+
@Override
572+
public String getBlockSize() {
573+
if (NONE.equals(getDisplay())) {
574+
return defaultIfEmpty(super.getBlockSize(), Definition.BLOCK_SIZE);
575+
}
576+
577+
final DomElement domElem = getDomElement();
578+
if (!domElem.isAttachedToPage()) {
579+
return defaultIfEmpty(super.getBlockSize(), Definition.BLOCK_SIZE);
580+
}
581+
582+
return CssPixelValueConverter.pixelString(domElem, new CssPixelValueConverter.CssValue(0, 0) {
583+
@Override
584+
public String get(final ComputedCssStyleDeclaration style) {
585+
final String value = style.getStyleAttribute(Definition.HEIGHT, true);
586+
if (StringUtils.isEmpty(value)) {
587+
final String content = domElem.getVisibleText();
588+
// do this only for small content
589+
// at least for empty div's this is more correct
590+
if (null == content) {
591+
return getDefaultValue() + "px";
592+
}
593+
return getEmptyHeight(domElem) + "px";
594+
}
595+
return value;
596+
}
597+
});
598+
}
599+
568600
/**
569601
* {@inheritDoc}
570602
*/

src/main/java/org/htmlunit/css/StyleAttributes.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -2090,10 +2090,10 @@ public enum Definition {
20902090
MOZ_PERSPECTIVE__("-moz-perspective", "-moz-perspective", ffLatest("none")),
20912091

20922092
/** The style property {@code MozPerspectiveOrigin}. */
2093-
MOZ_PERSPECTIVE_ORIGIN("MozPerspectiveOrigin", "-moz-perspective-origin", ffLatest("620px 164.25px")),
2093+
MOZ_PERSPECTIVE_ORIGIN("MozPerspectiveOrigin", "-moz-perspective-origin", ffLatest("620px 9px")),
20942094

20952095
/** The style property {@code -moz-perspective-origin}. */
2096-
MOZ_PERSPECTIVE_ORIGIN__("-moz-perspective-origin", "-moz-perspective-origin", ffLatest("620px 164.25px")),
2096+
MOZ_PERSPECTIVE_ORIGIN__("-moz-perspective-origin", "-moz-perspective-origin", ffLatest("620px 9px")),
20972097

20982098
/** The style property {@code MozTabSize}. */
20992099
MOZ_TAB_SIZE("MozTabSize", "-moz-tab-size", ff("8")),
@@ -2125,11 +2125,11 @@ public enum Definition {
21252125

21262126
/** The style property {@code MozTransformOrigin}. */
21272127
MOZ_TRANSFORM_ORIGIN("MozTransformOrigin", "-moz-transform-origin",
2128-
ffEsr("622px 164.25px"), ffLatest("620px 164.25px")),
2128+
ffEsr("622px 9px"), ffLatest("620px 9px")),
21292129

21302130
/** The style property {@code -moz-transform-origin}. */
21312131
MOZ_TRANSFORM_ORIGIN__("-moz-transform-origin", "-moz-transform-origin",
2132-
ffEsr("622px 164.25px"), ffLatest("620px 164.25px")),
2132+
ffEsr("622px 9px"), ffLatest("620px 9px")),
21332133

21342134
/** The style property {@code MozTransformStyle}. */
21352135
MOZ_TRANSFORM_STYLE("MozTransformStyle", "-moz-transform-style", ffLatest("flat")),
@@ -2439,11 +2439,11 @@ public enum Definition {
24392439

24402440
/** The style property {@code perspectiveOrigin}. */
24412441
PERSPECTIVE_ORIGIN("perspectiveOrigin", "perspective-origin",
2442-
ffEsr("622px 164.25px"), ffLatest("620px 164.25px"), chrome("620px 164px"), edge("616px 162px")),
2442+
ffEsr("622px 9px"), ffLatest("620px 9px"), chrome("620px 9px"), edge("616px 9px")),
24432443

24442444
/** The style property {@code perspective-origin}. */
24452445
PERSPECTIVE_ORIGIN_("perspective-origin", "perspective-origin",
2446-
ffEsr("622px 164.25px"), ffLatest("620px 164.25px")),
2446+
ffEsr("622px 9px"), ffLatest("620px 9px")),
24472447

24482448
/** The style property {@code placeContent}. */
24492449
PLACE_CONTENT("placeContent", "place-content", chromeAndEdgeNormal(), ffNormal()),
@@ -3072,10 +3072,10 @@ public enum Definition {
30723072

30733073
/** The style property {@code transformOrigin}. */
30743074
TRANSFORM_ORIGIN("transformOrigin", "transform-origin",
3075-
ffEsr("622px 164.25px"), ffLatest("620px 164.25px"), chrome("620px 164px"), edge("616px 162px")),
3075+
ffEsr("622px 9px"), ffLatest("620px 9px"), chrome("620px 9px"), edge("616px 9px")),
30763076

30773077
/** The style property {@code transform-origin}. */
3078-
TRANSFORM_ORIGIN_("transform-origin", "transform-origin", ffEsr("622px 164.25px"), ffLatest("620px 164.25px")),
3078+
TRANSFORM_ORIGIN_("transform-origin", "transform-origin", ffEsr("622px 9px"), ffLatest("620px 9px")),
30793079

30803080
/** The style property {@code transformStyle}. */
30813081
TRANSFORM_STYLE("transformStyle", "transform-style", ff("flat"), chromeAndEdge("flat")),
@@ -3716,7 +3716,7 @@ public enum Definition {
37163716
WEBKIT_LOCALE("webkitLocale", "webkit-locale", chromeAndEdgeAuto()),
37173717

37183718
/** The style property {@code webkitLogicalHeight}. */
3719-
WEBKIT_LOGICAL_HEIGHT("webkitLogicalHeight", "webkit-logical-height", chromeAndEdge("328px")),
3719+
WEBKIT_LOGICAL_HEIGHT("webkitLogicalHeight", "webkit-logical-height", chromeAndEdge("18px")),
37203720

37213721
/** The style property {@code webkitLogicalWidth}. */
37223722
WEBKIT_LOGICAL_WIDTH("webkitLogicalWidth", "webkit-logical-width", chrome("1240px"), edge("1232px")),
@@ -3889,15 +3889,15 @@ public enum Definition {
38893889

38903890
/** The style property {@code webkitPerspectiveOrigin}. */
38913891
WEBKIT_PERSPECTIVE_ORIGIN("webkitPerspectiveOrigin", "webkit-perspective-origin",
3892-
ffEsr("622px 164.25px"), ffLatest("620px 164.25px"), chrome("620px 164px"), edge("616px 162px")),
3892+
ffEsr("622px 9px"), ffLatest("620px 9px"), chrome("620px 9px"), edge("616px 9px")),
38933893

38943894
/** The style property {@code WebkitPerspectiveOrigin}. */
38953895
WEBKIT_PERSPECTIVE_ORIGIN_("WebkitPerspectiveOrigin", "webkit-perspective-origin",
3896-
ffEsr("622px 164.25px"), ffLatest("620px 164.25px")),
3896+
ffEsr("622px 9px"), ffLatest("620px 9px")),
38973897

38983898
/** The style property {@code -webkit-perspective-origin}. */
38993899
WEBKIT_PERSPECTIVE_ORIGIN__("-webkit-perspective-origin", "webkit-perspective-origin",
3900-
ffEsr("622px 164.25px"), ffLatest("620px 164.25px")),
3900+
ffEsr("622px 9px"), ffLatest("620px 9px")),
39013901

39023902
/** The style property {@code webkitPerspectiveOriginX}. */
39033903
WEBKIT_PERSPECTIVE_ORIGIN_X("webkitPerspectiveOriginX", "webkit-perspective-origin-x", chromeAndEdgeEmpty()),
@@ -4023,15 +4023,15 @@ public enum Definition {
40234023

40244024
/** The style property {@code webkitTransformOrigin}. */
40254025
WEBKIT_TRANSFORM_ORIGIN("webkitTransformOrigin", "webkit-transform-origin",
4026-
ffEsr("622px 164.25px"), ffLatest("620px 164.25px"), chrome("620px 164px"), edge("616px 162px")),
4026+
ffEsr("622px 9px"), ffLatest("620px 9px"), chrome("620px 9px"), edge("616px 9px")),
40274027

40284028
/** The style property {@code WebkitTransformOrigin}. */
40294029
WEBKIT_TRANSFORM_ORIGIN_("WebkitTransformOrigin", "webkit-transform-origin",
4030-
ffEsr("622px 164.25px"), ffLatest("620px 164.25px")),
4030+
ffEsr("622px 9px"), ffLatest("620px 9px")),
40314031

40324032
/** The style property {@code -webkit-transform-origin}. */
40334033
WEBKIT_TRANSFORM_ORIGIN__("-webkit-transform-origin", "webkit-transform-origin",
4034-
ffEsr("622px 164.25px"), ffLatest("620px 164.25px")),
4034+
ffEsr("622px 9px"), ffLatest("620px 9px")),
40354035

40364036
/** The style property {@code webkitTransformOriginX}. */
40374037
WEBKIT_TRANSFORM_ORIGIN_X("webkitTransformOriginX", "webkit-transform-origin-x", chromeAndEdgeEmpty()),

src/main/java/org/htmlunit/javascript/host/css/CSSStyleDeclaration.java

+21
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,27 @@ public void setBackgroundRepeat(final String backgroundRepeat) {
339339
setStyleAttribute(Definition.BACKGROUND_REPEAT.getAttributeName(), backgroundRepeat);
340340
}
341341

342+
/**
343+
* Gets the {@code blockSize} style attribute.
344+
* @return the style attribute
345+
*/
346+
@JsxGetter
347+
public String getBlockSize() {
348+
if (styleDeclaration_ == null) {
349+
return null; // prototype
350+
}
351+
return styleDeclaration_.getBlockSize();
352+
}
353+
354+
/**
355+
* Sets the {@code blockSize} style attribute.
356+
* @param blockSize the new attribute
357+
*/
358+
@JsxSetter
359+
public void setBlockSize(final String blockSize) {
360+
setStyleAttribute(Definition.BLOCK_SIZE.getAttributeName(), blockSize);
361+
}
362+
342363
/**
343364
* Gets the {@code borderBottomColor} style attribute.
344365
* @return the style attribute

src/main/java/org/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java

+8
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ public String getBackgroundRepeat() {
138138
return getCssStyleDeclaration().getBackgroundRepeat();
139139
}
140140

141+
/**
142+
* {@inheritDoc}
143+
*/
144+
@Override
145+
public String getBlockSize() {
146+
return getCssStyleDeclaration().getBlockSize();
147+
}
148+
141149
/**
142150
* {@inheritDoc}
143151
*/

src/test/java/org/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java

+14-5
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,7 @@ public void widthAndHeightEmptySpanElement() throws Exception {
15111511
@Test
15121512
@Alerts(DEFAULT = {"0", "0", "0", "0", "0", "0"},
15131513
FF_ESR = {"0", "0", "0", "0", "0", "17"})
1514+
@HtmlUnitNYI(FF_ESR = {"0", "0", "0", "0", "0", "0"})
15141515
public void widthAndHeightScriptElement() throws Exception {
15151516
final String content = DOCTYPE_HTML
15161517
+ "<html><head><script id='headScript'>\n"
@@ -1572,6 +1573,7 @@ public void widthAndHeightChildDisplayNone() throws Exception {
15721573
@Test
15731574
@Alerts(DEFAULT = {"0", "0"},
15741575
FF_ESR = {"0", "17"})
1576+
@HtmlUnitNYI(FF_ESR = {"0", "0"})
15751577
public void widthAndHeightChildDisplayNoneWidth() throws Exception {
15761578
final String content = DOCTYPE_HTML
15771579
+ "<html><head><script>\n"
@@ -1594,6 +1596,7 @@ public void widthAndHeightChildDisplayNoneWidth() throws Exception {
15941596
@Test
15951597
@Alerts(DEFAULT = {"0", "0"},
15961598
FF_ESR = {"0", "17"})
1599+
@HtmlUnitNYI(FF_ESR = {"0", "0"})
15971600
public void widthAndHeightChildDisplayNoneWidthLineBreak() throws Exception {
15981601
//see https://github.com/HtmlUnit/htmlunit/pull/356
15991602
final String content = DOCTYPE_HTML
@@ -3228,29 +3231,35 @@ public void animationDuration() throws Exception {
32283231
* @throws Exception if the test fails
32293232
*/
32303233
@Test
3231-
@Alerts({"0px", "0px", "auto", "auto"})
3234+
@Alerts({"0px", "0px", "18px", "18px", "auto", "auto"})
32323235
public void blockSize() throws Exception {
32333236
final String html = DOCTYPE_HTML
32343237
+ "<html>\n"
32353238
+ "<head>\n"
32363239
+ "<script>\n"
32373240
+ LOG_TITLE_FUNCTION
32383241
+ " function test() {\n"
3239-
+ " var d = document.getElementById('myDiv');\n"
3242+
+ " var d = document.getElementById('myDivEmpty');\n"
32403243
+ " var style = window.getComputedStyle(d, null);\n"
32413244
+ " log(style['blockSize']);\n"
32423245
+ " log(style.blockSize);\n"
32433246

3247+
+ " d = document.getElementById('myDivText');\n"
3248+
+ " style = window.getComputedStyle(d, null);\n"
3249+
+ " log(style['blockSize']);\n"
3250+
+ " log(style.blockSize);\n"
3251+
32443252
+ " d = document.getElementById('myDivNone');\n"
3245-
+ " var style = window.getComputedStyle(d, null);\n"
3253+
+ " style = window.getComputedStyle(d, null);\n"
32463254
+ " log(style['blockSize']);\n"
32473255
+ " log(style.blockSize);\n"
32483256
+ " }\n"
32493257
+ "</script>\n"
32503258
+ "</head>\n"
32513259
+ "<body onload='test()'>\n"
3252-
+ " <div id='myDiv'></div>\n"
3253-
+ " <div id='myDivNone' style='display: none'><br>\n"
3260+
+ " <div id='myDivEmpty'></div>\n"
3261+
+ " <div id='myDivText'>HtmlUnit</div>\n"
3262+
+ " <div id='myDivNone' style='display: none'>A<br>B</div>\n"
32543263
+ "</body></html>";
32553264

32563265
loadPageVerifyTitle2(html);

0 commit comments

Comments
 (0)