File: scrollWidthHeight-negative-margin-002.html

package info (click to toggle)
firefox 143.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,617,328 kB
  • sloc: cpp: 7,478,492; javascript: 6,417,157; ansic: 3,720,058; python: 1,396,372; xml: 627,523; asm: 438,677; java: 186,156; sh: 63,477; makefile: 19,171; objc: 13,059; perl: 12,983; yacc: 4,583; cs: 3,846; pascal: 3,405; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (105 lines) | stat: -rw-r--r-- 4,415 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!doctype html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>scroll{Width,Height} with visible overflow and negative margins.</title>
<link rel="help" href="https://drafts.csswg.org/cssom-view/#extension-to-the-element-interface">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1906475">
<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
<link rel="author" title="Mozilla" href="https://mozilla.org">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<style>
body { margin: 0 }
.wrapper {
  width: 80px;
  height: 80px;
  border: 1px solid #d1d1d2;
  padding: 1px 4px 8px 16px;
  border-width: 1px 2px 3px 4px;
  border-right-width: 50px;
  border-bottom-width: 40px;
}
.inner {
  margin: -100px;
  height: 300px;
  width: 300px;
  background-color: blue;
}
</style>
<div class="wrapper">
  <div class="inner"></div>
</div>
<script>
const wrapper = document.querySelector(".wrapper");
const contentBox = {
  width: 80,
  height: 80,
};
const paddingBox = {
  width: contentBox.width + 4 + 16,
  height: contentBox.height + 1 + 8,
};
function* writingModes() {
  yield "horizontal-tb";
  yield* ["vertical-lr", "vertical-rl"].filter(writingMode => CSS.supports("writing-mode", writingMode));
}
for (let display of ["flow-root", "flex", "grid"]) {
  for (let flexDirection of ["row", "row-reverse", "column", "column-reverse"]) {
    if (flexDirection != "row" && display != "flex") {
      // Don't bother retesting with all flexDirection values unless we're actually a flex container
      continue;
    }
    for (let flexWrap of ["", "wrap-reverse"]) {
      if (flexWrap != "" && display != "flex") {
        // Don't bother retesting with all flexWrap values unless we're actually a flex container
        continue;
      }
      for (let direction of ["ltr", "rtl"]) {
        for (let writingMode of writingModes()) {
          for (let overflow of ["visible", "hidden", "auto", "clip", "scroll"]) {
            wrapper.style.display = display;
            wrapper.style.overflow = overflow;
            wrapper.style.direction = direction;
            wrapper.style.writingMode = writingMode;
            wrapper.style.flexDirection = flexDirection;
            wrapper.style.flexWrap = flexWrap;
            // Suppress scrollbars because they get added to the padding are
            // and would need to account for them in flexbox.
            wrapper.style.scrollbarWidth = display == "flex" ? "none" : "";
            let vertical = writingMode.startsWith("vertical");
            let scrollToTop = vertical && direction == "rtl";
            let scrollToLeft = (!vertical && direction == "rtl") || writingMode == "vertical-rl";
            let flexMainAxisIsVertical = flexDirection.startsWith("row") == vertical;
            if (display == "flex") {
              if (flexDirection.endsWith("-reverse")) {
                if (flexMainAxisIsVertical) {
                  scrollToTop = !scrollToTop;
                } else {
                  scrollToLeft = !scrollToLeft;
                }
              }
              if (flexWrap == "wrap-reverse") {
                if (flexMainAxisIsVertical) {
                  scrollToLeft = !scrollToLeft;
                } else {
                  scrollToTop = !scrollToTop;
                }
              }
            }
            test(function() {
              assert_greater_than_equal(wrapper.scrollWidth, paddingBox.width, "scrollWidth should be at least padding box width");
              let padding = display == "flex" && !flexMainAxisIsVertical ? paddingBox.width - contentBox.width : 0;
              assert_equals(wrapper.scrollWidth, (scrollToLeft ? 204 : 216) - padding, "scrollWidth");
            }, "scrollWidth with negative margins: " + wrapper.style.cssText);
            test(function() {
              assert_greater_than_equal(wrapper.scrollHeight, paddingBox.height, "scrollHeight should be at least padding box height");
              let padding = display == "flex" && flexMainAxisIsVertical ? paddingBox.width - contentBox.width : 0;
              assert_equals(wrapper.scrollHeight, (scrollToTop ? 208 : 201) - padding, "scrollHeight");
            }, "scrollHeight with negative margins: " + wrapper.style.cssText);
          }
        }
      }
    }
  }
}
</script>