From b4a27bb58df03cd2f9ccd9937147cace131161ed Mon Sep 17 00:00:00 2001 From: Alexis Beingessner Date: Mon, 15 Apr 2019 23:16:13 +0000 Subject: [PATCH] Bug 1412179 - implement fieldsets with nonempty legends. r=kats Differential Revision: https://phabricator.services.mozilla.com/D27350 --HG-- extra : moz-landing-system : lando --- gfx/webrender_bindings/WebRenderAPI.h | 8 ++++++ layout/forms/nsFieldSetFrame.cpp | 27 ++++++++++++++++--- layout/reftests/box-shadow/reftest.list | 2 +- .../fieldset-vertical.html.ini | 4 --- .../legend-auto-margins.html.ini | 3 +++ 5 files changed, 36 insertions(+), 8 deletions(-) delete mode 100644 testing/web-platform/meta/html/rendering/non-replaced-elements/the-fieldset-and-legend-elements/fieldset-vertical.html.ini create mode 100644 testing/web-platform/meta/html/rendering/non-replaced-elements/the-fieldset-and-legend-elements/legend-auto-margins.html.ini diff --git a/gfx/webrender_bindings/WebRenderAPI.h b/gfx/webrender_bindings/WebRenderAPI.h index 9e5621b1543cf..c24d14f29e171 100644 --- a/gfx/webrender_bindings/WebRenderAPI.h +++ b/gfx/webrender_bindings/WebRenderAPI.h @@ -654,6 +654,14 @@ class MOZ_RAII SpaceAndClipChainHelper final { aBuilder.mCurrentSpaceAndClipChain.space = aSpatialId; MOZ_GUARD_OBJECT_NOTIFIER_INIT; } + SpaceAndClipChainHelper(DisplayListBuilder& aBuilder, + wr::WrClipChainId aClipChainId + MOZ_GUARD_OBJECT_NOTIFIER_PARAM) + : mBuilder(aBuilder), + mOldSpaceAndClipChain(aBuilder.mCurrentSpaceAndClipChain) { + aBuilder.mCurrentSpaceAndClipChain.clip_chain = aClipChainId.id; + MOZ_GUARD_OBJECT_NOTIFIER_INIT; + } ~SpaceAndClipChainHelper() { mBuilder.mCurrentSpaceAndClipChain = mOldSpaceAndClipChain; diff --git a/layout/forms/nsFieldSetFrame.cpp b/layout/forms/nsFieldSetFrame.cpp index d54b3bad12258..4f9c25a9bde05 100644 --- a/layout/forms/nsFieldSetFrame.cpp +++ b/layout/forms/nsFieldSetFrame.cpp @@ -167,15 +167,36 @@ bool nsDisplayFieldSetBorder::CreateWebRenderCommands( auto frame = static_cast(mFrame); auto offset = ToReferenceFrame(); nsRect rect; + Maybe clipOut; if (nsIFrame* legend = frame->GetLegend()) { rect = frame->VisualBorderRectRelativeToSelf() + offset; - // Legends require a "negative" clip around the text, which WR doesn't - // support yet. nsRect legendRect = legend->GetNormalRect() + offset; + + // Make sure we clip all of the border in case the legend is smaller. + nscoord borderTopWidth = frame->GetUsedBorder().top; + if (legendRect.height < borderTopWidth) { + legendRect.height = borderTopWidth; + legendRect.y = offset.y; + } + if (!legendRect.IsEmpty()) { - return false; + // We need to clip out the part of the border where the legend would go + auto appUnitsPerDevPixel = frame->PresContext()->AppUnitsPerDevPixel(); + auto layoutRect = wr::ToRoundedLayoutRect( + LayoutDeviceRect::FromAppUnits(rect, appUnitsPerDevPixel)); + + wr::ComplexClipRegion region; + region.rect = wr::ToRoundedLayoutRect( + LayoutDeviceRect::FromAppUnits(legendRect, appUnitsPerDevPixel)); + region.mode = wr::ClipMode::ClipOut; + region.radii = wr::EmptyBorderRadius(); + nsTArray array{region}; + + auto clip = aBuilder.DefineClip(Nothing(), layoutRect, &array, nullptr); + auto clipChain = aBuilder.DefineClipChain({clip}); + clipOut.emplace(aBuilder, clipChain); } } else { rect = nsRect(offset, frame->GetRect().Size()); diff --git a/layout/reftests/box-shadow/reftest.list b/layout/reftests/box-shadow/reftest.list index 57cc2997f8a7c..58af6c8a2162c 100644 --- a/layout/reftests/box-shadow/reftest.list +++ b/layout/reftests/box-shadow/reftest.list @@ -40,7 +40,7 @@ fuzzy(0-13,0-9445) fuzzy-if(d2d,0-13,0-10926) fuzzy-if(webrender,14-15,11263-132 == overflow-not-scrollable-2.html overflow-not-scrollable-2-ref.html fuzzy-if(webrender,0-1,0-655) == 611574-1.html 611574-1-ref.html fuzzy-if(webrender,0-4,0-144) == 611574-2.html 611574-2-ref.html -fuzzy-if(winWidget,0-5,0-30) fuzzy-if(skiaContent,0-16,0-10) fuzzy-if(webrender,20-34,82-84) == fieldset.html fieldset-ref.html # minor anti-aliasing problem on Windows +fuzzy-if(winWidget,0-5,0-30) fuzzy-if(skiaContent,0-16,0-10) == fieldset.html fieldset-ref.html # minor anti-aliasing problem on Windows fuzzy-if(winWidget,0-5,0-30) fuzzy-if(skiaContent,0-16,0-10) fails-if(webrender) == fieldset-inset.html fieldset-inset-ref.html # minor anti-aliasing problem on Windows == 1178575.html 1178575-ref.html == 1178575-2.html 1178575-2-ref.html diff --git a/testing/web-platform/meta/html/rendering/non-replaced-elements/the-fieldset-and-legend-elements/fieldset-vertical.html.ini b/testing/web-platform/meta/html/rendering/non-replaced-elements/the-fieldset-and-legend-elements/fieldset-vertical.html.ini deleted file mode 100644 index 6ca151328b57d..0000000000000 --- a/testing/web-platform/meta/html/rendering/non-replaced-elements/the-fieldset-and-legend-elements/fieldset-vertical.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[fieldset-vertical.html] - expected: - if webrender and (os == "linux"): FAIL - if webrender and (os == "win"): FAIL diff --git a/testing/web-platform/meta/html/rendering/non-replaced-elements/the-fieldset-and-legend-elements/legend-auto-margins.html.ini b/testing/web-platform/meta/html/rendering/non-replaced-elements/the-fieldset-and-legend-elements/legend-auto-margins.html.ini new file mode 100644 index 0000000000000..25471be3f9818 --- /dev/null +++ b/testing/web-platform/meta/html/rendering/non-replaced-elements/the-fieldset-and-legend-elements/legend-auto-margins.html.ini @@ -0,0 +1,3 @@ +[legend-auto-margins.html] + fuzzy: + if webrender and (os == "linux"): legend-auto-margins-ref.html:maxDifference=8;totalPixels=8-10