Use the parent's content size as the available size for the rendered legend so we calculate auto-margins correctly.

The reason we use ComputedSizeWithPadding for the inner
anonymous block (innerAvailSize) is that it inherits the padding:
https://searchfox.org/mozilla-central/source/layout/style/res/forms.css#22
so we artificially inflate it.

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1488301
gecko-commit: 5f71217eb8a6eed2703b4a1c3570986692a9d2ed
gecko-integration-branch: mozilla-inbound
gecko-reviewers: emilio
diff --git a/html/rendering/non-replaced-elements/the-fieldset-and-legend-elements/legend-auto-margins-ref.html b/html/rendering/non-replaced-elements/the-fieldset-and-legend-elements/legend-auto-margins-ref.html
new file mode 100644
index 0000000..8b12587
--- /dev/null
+++ b/html/rendering/non-replaced-elements/the-fieldset-and-legend-elements/legend-auto-margins-ref.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>legend inline auto margins</title>
+<link rel="author" title="Mats Palmgren" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1488301">
+<style>
+body, html { padding:0; margin: 0; }
+div {
+  border: 1px solid black;
+  border-width: 10px 17px 7px 23px;
+  padding: 0;
+  margin: 0;
+  width: 448px;
+  height: 5px;
+  margin-top: 5px;
+  position: relative;
+}
+span {
+  position: absolute;
+  top: -15px;
+  width: 200px;
+  height: 20px;
+  padding: 0;
+  margin: 0;
+  background: grey;
+}
+center { width: 200px; height: 20px; background: red; }
+</style>
+</head>
+<body>
+  <div><span style="right:17px"></span></div>
+  <div><span style="left:31px"></span></div>
+  <div><span style="left:131px"></span></div>
+  <div><span style="right:32px"></span></div>
+  <div><span style="left:46px"></span></div>
+</body>
+</html>
diff --git a/html/rendering/non-replaced-elements/the-fieldset-and-legend-elements/legend-auto-margins.html b/html/rendering/non-replaced-elements/the-fieldset-and-legend-elements/legend-auto-margins.html
new file mode 100644
index 0000000..dd1964b
--- /dev/null
+++ b/html/rendering/non-replaced-elements/the-fieldset-and-legend-elements/legend-auto-margins.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>legend inline auto margins</title>
+<link rel="author" title="Mats Palmgren" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1488301">
+<link rel="match" href="legend-auto-margins-ref.html">
+<style>
+body, html { padding:0; margin: 0; }
+fieldset {
+  border: 1px solid black;
+  border-width: 10px 17px 7px 23px;
+  padding: 0 17px 0 31px;
+  margin: 0;
+  width: 400px;
+}
+legend {
+  width: 200px;
+  height: 20px;
+  padding: 0;
+  margin: 0;
+  background: grey;
+}
+</style>
+</head>
+<body>
+  <fieldset><legend style="margin-left:auto"></legend></fieldset>
+  <fieldset><legend style="margin-right:auto"></legend></fieldset>
+  <fieldset><legend style="margin:0 auto"></legend></fieldset>
+  <fieldset><legend style="margin:0 15px 0 auto"></legend></fieldset>
+  <fieldset><legend style="margin:0 auto 0 15px"></legend></fieldset>
+</body>
+</html>