Skip to content

Commit 9c21927

Browse files
committed
Add support for new CSS viewport units (dvw, dvh, lvw, lvh, svw, svh, and *min/*max variants)
1 parent 4f3594d commit 9c21927

4 files changed

Lines changed: 902 additions & 18 deletions

File tree

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,42 @@ else if (value.endsWith("%")) {
100100
i = i * 16 / 100;
101101
}
102102
else if (value.endsWith("ex")) {
103-
i = i * 10;
104-
}
105-
else if (value.endsWith("in")) {
106-
i = i * 150;
103+
i = i * 8;
107104
}
108105
else if (value.endsWith("cm")) {
109-
i = i * 50;
106+
i = i * 38;
110107
}
111108
else if (value.endsWith("mm")) {
112-
i = i * 5;
109+
i = i * 4;
113110
}
114111
else if (value.endsWith("pt")) {
115112
i = i * 2;
116113
}
117114
else if (value.endsWith("pc")) {
118115
i = i * 24;
119116
}
117+
else if (value.endsWith("ch")) {
118+
i = i * 8;
119+
}
120+
else if (value.endsWith("ch")) {
121+
i = i * 8;
122+
}
123+
else if (value.endsWith("vh")
124+
|| value.endsWith("vmin")) {
125+
// this matches also
126+
// "dvh" "dvmin" "lvh" "lvmin" "svh" "svmin"
127+
i = i * 6;
128+
}
129+
else if (value.endsWith("vw")
130+
|| value.endsWith("vmax")) {
131+
// this matches also
132+
// "dvw" "dvmax" "lvw" "lvmax" "svw" "svmax"
133+
i = i * 12;
134+
}
135+
// placed at the end to handle min before
136+
else if (value.endsWith("in")) {
137+
i = i * 150;
138+
}
120139
return Math.round(i);
121140
}
122141

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

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,9 @@ else if ("print".equalsIgnoreCase(mediaType)) {
14641464
private static double pixelValue(final CSSValueImpl cssValue, final WebWindow webWindow) {
14651465
if (cssValue == null) {
14661466
LOG.warn("CSSValue is null but has to be a 'px', 'em', '%', 'ex', 'ch', "
1467-
+ "'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.");
1467+
+ "'vw', 'vh', 'vmin', 'vmax', 'dvw', 'dvh', 'dvmin', 'dvmax', "
1468+
+ "'lvw', 'lvh', 'lvmin', 'lvmax', 'svw', 'svh', 'svmin', 'svmax', "
1469+
+ "'rem', 'mm', 'cm', 'Q', or 'pt' value.");
14681470
return -1;
14691471
}
14701472

@@ -1499,6 +1501,42 @@ private static double pixelValue(final CSSValueImpl cssValue, final WebWindow we
14991501
case VMAX:
15001502
// hard coded default for the moment 16px = 100%
15011503
return 0.16f * cssValue.getDoubleValue();
1504+
case DVW:
1505+
// hard coded default for the moment 16px = 100%
1506+
return 0.16f * cssValue.getDoubleValue();
1507+
case DVH:
1508+
// hard coded default for the moment 16px = 100%
1509+
return 0.16f * cssValue.getDoubleValue();
1510+
case DVMIN:
1511+
// hard coded default for the moment 16px = 100%
1512+
return 0.16f * cssValue.getDoubleValue();
1513+
case DVMAX:
1514+
// hard coded default for the moment 16px = 100%
1515+
return 0.16f * cssValue.getDoubleValue();
1516+
case LVW:
1517+
// hard coded default for the moment 16px = 100%
1518+
return 0.16f * cssValue.getDoubleValue();
1519+
case LVH:
1520+
// hard coded default for the moment 16px = 100%
1521+
return 0.16f * cssValue.getDoubleValue();
1522+
case LVMIN:
1523+
// hard coded default for the moment 16px = 100%
1524+
return 0.16f * cssValue.getDoubleValue();
1525+
case LVMAX:
1526+
// hard coded default for the moment 16px = 100%
1527+
return 0.16f * cssValue.getDoubleValue();
1528+
case SVW:
1529+
// hard coded default for the moment 16px = 100%
1530+
return 0.16f * cssValue.getDoubleValue();
1531+
case SVH:
1532+
// hard coded default for the moment 16px = 100%
1533+
return 0.16f * cssValue.getDoubleValue();
1534+
case SVMIN:
1535+
// hard coded default for the moment 16px = 100%
1536+
return 0.16f * cssValue.getDoubleValue();
1537+
case SVMAX:
1538+
// hard coded default for the moment 16px = 100%
1539+
return 0.16f * cssValue.getDoubleValue();
15021540
case REM:
15031541
// hard coded default for the moment 16px = 100%
15041542
return 0.16f * cssValue.getDoubleValue();
@@ -1522,7 +1560,9 @@ private static double pixelValue(final CSSValueImpl cssValue, final WebWindow we
15221560
if (LOG.isWarnEnabled()) {
15231561
LOG.warn("CSSValue '" + cssValue.getCssText()
15241562
+ "' has to be a 'px', 'em', '%', 'ex', 'ch', "
1525-
+ "'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.");
1563+
+ "'vw', 'vh', 'vmin', 'vmax', 'dvw', 'dvh', 'dvmin', 'dvmax', "
1564+
+ "'lvw', 'lvh', 'lvmin', 'lvmax', 'svw', 'svh', 'svmin', 'svmax', "
1565+
+ "'rem', 'mm', 'cm', 'Q', or 'pt' value.");
15261566
}
15271567
return -1;
15281568
}

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2004,10 +2004,25 @@ else if (valueString.endsWith("px")
20042004
}
20052005
else if (valueString.endsWith("rem")
20062006
|| valueString.endsWith("vmin")
2007-
|| valueString.endsWith("vmax")) {
2007+
|| valueString.endsWith("vmax")
2008+
|| valueString.endsWith("dvw")
2009+
|| valueString.endsWith("dvh")
2010+
|| valueString.endsWith("lvw")
2011+
|| valueString.endsWith("lvh")
2012+
|| valueString.endsWith("svw")
2013+
|| valueString.endsWith("svh")) {
20082014
unit = valueString.substring(valueString.length() - 3);
20092015
valueString = valueString.substring(0, valueString.length() - 3);
20102016
}
2017+
else if (valueString.endsWith("dvmin")
2018+
|| valueString.endsWith("dvmax")
2019+
|| valueString.endsWith("lvmin")
2020+
|| valueString.endsWith("lvmax")
2021+
|| valueString.endsWith("svmin")
2022+
|| valueString.endsWith("svmax")) {
2023+
unit = valueString.substring(valueString.length() - 5);
2024+
valueString = valueString.substring(0, valueString.length() - 5);
2025+
}
20112026
else {
20122027
return;
20132028
}

0 commit comments

Comments
 (0)