Skip to content

Commit

Permalink
ComputedCssStyleDeclaration.isScrollable(boolean, boolean) now checks…
Browse files Browse the repository at this point in the history
… also for the overflow-x/overflow-y style (#742)
  • Loading branch information
rbri committed May 15, 2024
1 parent e104703 commit 94684a9
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
for the XMLHttpRequest ActiveX object that is no longer there.
</action>

<action type="fix" dev="rbri" issue="#742">
ComputedCssStyleDeclaration.isScrollable(boolean, boolean) now checks also for the overflow-x/overflow-y styles.
</action>
<action type="fix" dev="Lai Quang Duong">
Make HtmlElement.type() allow full-width space (\u3000), six-per-em space (\u2006) and tab (\t) characters.
</action>
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/org/htmlunit/css/ComputedCssStyleDeclaration.java
Original file line number Diff line number Diff line change
Expand Up @@ -1893,14 +1893,30 @@ 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(Definition.OVERFLOW, true);

String overflow;
if (horizontal) {
// TODO: inherit, overflow-x
overflow = getStyleAttribute(Definition.OVERFLOW_Y_, false);
if (StringUtils.isEmpty(overflow)) {
overflow = getStyleAttribute(Definition.OVERFLOW_Y, false);
}
// fall back to default
if (StringUtils.isEmpty(overflow)) {
overflow = getStyleAttribute(Definition.OVERFLOW, true);
}
scrollable = (element instanceof HtmlBody || SCROLL.equals(overflow) || AUTO.equals(overflow))
&& (ignoreSize || getContentWidth() > getCalculatedWidth());
}
else {
// TODO: inherit, overflow-y
overflow = getStyleAttribute(Definition.OVERFLOW_X_, false);
if (StringUtils.isEmpty(overflow)) {
overflow = getStyleAttribute(Definition.OVERFLOW_X, false);
}
// fall back to default
if (StringUtils.isEmpty(overflow)) {
overflow = getStyleAttribute(Definition.OVERFLOW, true);
}

scrollable = (element instanceof HtmlBody || SCROLL.equals(overflow) || AUTO.equals(overflow))
&& (ignoreSize || getContentHeight() > getEmptyHeight());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,30 @@ public void scrollbarWidth() throws Exception {
+ " log(scroller.offsetWidth - scroller.clientWidth == 0);\n"
+ " document.body.appendChild(scroller);\n"
+ " log(scroller.offsetWidth - scroller.clientWidth == 0);\n"
+ " document.body.removeChild(scroller);\n"
+ " }\n"
+ "</script>\n"
+ "</head>\n"
+ "<body onload='test()'>\n"
+ "</body></html>";
loadPageVerifyTitle2(html);
}

/**
* @throws Exception if the test fails
*/
@Test
@Alerts({"true", "false"})
public void scrollbarWidthOverflowY() throws Exception {
final String html = "<html><head><script>\n"
+ LOG_TITLE_FUNCTION
+ " function test() {\n"
+ " var scroller = document.createElement('div');\n"
+ " scroller.style['width'] = '50px';\n"
+ " scroller.style['height'] = '50px';\n"
+ " scroller.style['overflowY'] = 'scroll';\n"
+ " log(scroller.offsetWidth - scroller.clientWidth == 0);\n"
+ " document.body.appendChild(scroller);\n"
+ " log(scroller.offsetWidth - scroller.clientWidth == 0);\n"
+ " }\n"
+ "</script>\n"
+ "</head>\n"
Expand All @@ -1851,7 +1874,30 @@ public void scrollbarHeight() throws Exception {
+ " log(scroller.offsetHeight - scroller.clientHeight == 0);\n"
+ " document.body.appendChild(scroller);\n"
+ " log(scroller.offsetHeight - scroller.clientHeight == 0);\n"
+ " document.body.removeChild(scroller);\n"
+ " }\n"
+ "</script>\n"
+ "</head>\n"
+ "<body onload='test()'>\n"
+ "</body></html>";
loadPageVerifyTitle2(html);
}

/**
* @throws Exception if the test fails
*/
@Test
@Alerts({"true", "false"})
public void scrollbarHeightOverflowX() throws Exception {
final String html = "<html><head><script>\n"
+ LOG_TITLE_FUNCTION
+ " function test() {\n"
+ " var scroller = document.createElement('div');\n"
+ " scroller.style['width'] = '50px';\n"
+ " scroller.style['height'] = '50px';\n"
+ " scroller.style['overflowX'] = 'scroll';\n"
+ " log(scroller.offsetHeight - scroller.clientHeight == 0);\n"
+ " document.body.appendChild(scroller);\n"
+ " log(scroller.offsetHeight - scroller.clientHeight == 0);\n"
+ " }\n"
+ "</script>\n"
+ "</head>\n"
Expand Down

0 comments on commit 94684a9

Please sign in to comment.