Skip to content
Permalink
Browse files
[css-values-4] logical *vi(inline) and *vb (block) viewport units…
… should be based on the current element's `writing-mode`

https://bugs.webkit.org/show_bug.cgi?id=234373
<rdar://problem/86832561>

Reviewed by Tim Nguyen.

Previously, we only looked at the root element's `writing-mode`. Looking at the current element's
`writing-mode` allows for non-root elements to have a `writing-mode` independent of the root element,
as well as having styles based on that. This was changed in <w3c/csswg-drafts#6873>.

Tests: CSSViewportUnits.AllSame
       CSSViewportUnits.MinimumViewportInsetWithWritingMode
       CSSViewportUnits.MaximumViewportInsetWithWritingMode
       CSSViewportUnits.EmptyUnobscuredSizeOverrides
       CSSViewportUnits.SameUnobscuredSizeOverrides
       CSSViewportUnits.DifferentUnobscuredSizeOverrides
       CSSViewportUnits.SVGDocument

* Source/WebCore/css/CSSPrimitiveValue.cpp:
(WebCore::lengthOfViewportPhysicalAxisForLogicalAxis):
(WebCore::CSSPrimitiveValue::computeNonCalcLengthDouble):

* Tools/TestWebKitAPI/Tests/WebKitCocoa/CSSViewportUnits.mm:
(changeCSSPropertyOfElements): Added.
(TEST.CSSViewportUnits.AllSame):
(TEST.CSSViewportUnits.MinimumViewportInsetWithWritingMode):
(TEST.CSSViewportUnits.MaximumViewportInsetWithWritingMode):
(TEST.CSSViewportUnits.EmptyUnobscuredSizeOverrides):
(TEST.CSSViewportUnits.SameUnobscuredSizeOverrides):
(TEST.CSSViewportUnits.DifferentUnobscuredSizeOverrides):
(TEST.CSSViewportUnits.SVGDocument):

Canonical link: https://commits.webkit.org/250835@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294609 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
dcrousso committed May 21, 2022
1 parent 5325a9e commit 706e3063ae335e1dcfdf8213c05409d3112e85a5
Showing 2 changed files with 275 additions and 20 deletions.
@@ -695,12 +695,12 @@ static constexpr double mmPerInch = 25.4;
static constexpr double cmPerInch = 2.54;
static constexpr double QPerInch = 25.4 * 4.0;

static double lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis logicalAxis, const FloatSize& size, const RenderStyle* rootElementStyle)
static double lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis logicalAxis, const FloatSize& size, const RenderStyle* style)
{
if (!rootElementStyle)
if (!style)
return 0;

switch (mapLogicalAxisToPhysicalAxis(makeTextFlow(rootElementStyle->writingMode(), rootElementStyle->direction()), logicalAxis)) {
switch (mapLogicalAxisToPhysicalAxis(makeTextFlow(style->writingMode(), style->direction()), logicalAxis)) {
case BoxAxis::Horizontal:
return size.width();

@@ -883,10 +883,10 @@ double CSSPrimitiveValue::computeNonCalcLengthDouble(const CSSToLengthConversion
return value * conversionData.defaultViewportFactor().minDimension();

case CSSUnitType::CSS_VB:
return value * lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis::Block, conversionData.defaultViewportFactor(), conversionData.rootStyle());
return value * lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis::Block, conversionData.defaultViewportFactor(), conversionData.style());

case CSSUnitType::CSS_VI:
return value * lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis::Inline, conversionData.defaultViewportFactor(), conversionData.rootStyle());
return value * lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis::Inline, conversionData.defaultViewportFactor(), conversionData.style());

case CSSUnitType::CSS_SVH:
return value * conversionData.smallViewportFactor().height();
@@ -901,10 +901,10 @@ double CSSPrimitiveValue::computeNonCalcLengthDouble(const CSSToLengthConversion
return value * conversionData.smallViewportFactor().minDimension();

case CSSUnitType::CSS_SVB:
return value * lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis::Block, conversionData.smallViewportFactor(), conversionData.rootStyle());
return value * lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis::Block, conversionData.smallViewportFactor(), conversionData.style());

case CSSUnitType::CSS_SVI:
return value * lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis::Inline, conversionData.smallViewportFactor(), conversionData.rootStyle());
return value * lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis::Inline, conversionData.smallViewportFactor(), conversionData.style());

case CSSUnitType::CSS_LVH:
return value * conversionData.largeViewportFactor().height();
@@ -919,10 +919,10 @@ double CSSPrimitiveValue::computeNonCalcLengthDouble(const CSSToLengthConversion
return value * conversionData.largeViewportFactor().minDimension();

case CSSUnitType::CSS_LVB:
return value * lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis::Block, conversionData.largeViewportFactor(), conversionData.rootStyle());
return value * lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis::Block, conversionData.largeViewportFactor(), conversionData.style());

case CSSUnitType::CSS_LVI:
return value * lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis::Inline, conversionData.largeViewportFactor(), conversionData.rootStyle());
return value * lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis::Inline, conversionData.largeViewportFactor(), conversionData.style());

case CSSUnitType::CSS_DVH:
return value * conversionData.dynamicViewportFactor().height();
@@ -937,10 +937,10 @@ double CSSPrimitiveValue::computeNonCalcLengthDouble(const CSSToLengthConversion
return value * conversionData.dynamicViewportFactor().minDimension();

case CSSUnitType::CSS_DVB:
return value * lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis::Block, conversionData.dynamicViewportFactor(), conversionData.rootStyle());
return value * lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis::Block, conversionData.dynamicViewportFactor(), conversionData.style());

case CSSUnitType::CSS_DVI:
return value * lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis::Inline, conversionData.dynamicViewportFactor(), conversionData.rootStyle());
return value * lengthOfViewportPhysicalAxisForLogicalAxis(LogicalBoxAxis::Inline, conversionData.dynamicViewportFactor(), conversionData.style());

case CSSUnitType::CSS_LHS:
ASSERT(conversionData.style());

0 comments on commit 706e306

Please sign in to comment.