Bug 1470176 - Implement contain:size for Select. draft
authorMorgan Rae Reschenberg <mreschenberg@mozilla.com>
Wed, 27 Jun 2018 15:46:31 -0700
changeset 820902 52a2ee8d711ba9997325ebdc7a66951923eca1b8
parent 820878 05b30b899a17c565ac158d509898b7800ed82f1c
push id116982
push userbmo:mreschenberg@berkeley.edu
push dateFri, 20 Jul 2018 16:36:34 +0000
bugs1470176
milestone63.0a1
Bug 1470176 - Implement contain:size for Select. MozReview-Commit-ID: JPD1BInDeT0
layout/forms/nsComboboxControlFrame.cpp
layout/forms/nsListControlFrame.cpp
layout/reftests/w3c-css/submitted/contain/contain-size-select-001-ref.html
layout/reftests/w3c-css/submitted/contain/contain-size-select-001.html
layout/reftests/w3c-css/submitted/contain/contain-size-select-002-ref.html
layout/reftests/w3c-css/submitted/contain/contain-size-select-002.html
layout/reftests/w3c-css/submitted/contain/reftest.list
--- a/layout/forms/nsComboboxControlFrame.cpp
+++ b/layout/forms/nsComboboxControlFrame.cpp
@@ -776,37 +776,34 @@ nsComboboxControlFrame::GetIntrinsicISiz
   if (mListControlFrame) {
     nsIScrollableFrame* scrollable = do_QueryFrame(mListControlFrame);
     NS_ASSERTION(scrollable, "List must be a scrollable frame");
     scrollbarWidth = scrollable->GetNondisappearingScrollbarWidth(
       presContext, aRenderingContext, GetWritingMode());
   }
 
   nscoord displayISize = 0;
-  if (MOZ_LIKELY(mDisplayFrame)) {
+  if (MOZ_LIKELY(mDisplayFrame) && !StyleDisplay()->IsContainSize()) {
     displayISize = nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
                                                         mDisplayFrame,
                                                         aType);
   }
 
   if (mDropdownFrame) {
-    nscoord dropdownContentISize;
+    nscoord dropdownContentISize = 0;
     bool isUsingOverlayScrollbars =
       LookAndFeel::GetInt(LookAndFeel::eIntID_UseOverlayScrollbars) != 0;
-    if (aType == nsLayoutUtils::MIN_ISIZE) {
+    if (aType == nsLayoutUtils::MIN_ISIZE && !StyleDisplay()->IsContainSize()) {
       dropdownContentISize = mDropdownFrame->GetMinISize(aRenderingContext);
-      if (isUsingOverlayScrollbars) {
-        dropdownContentISize += scrollbarWidth;
-      }
-    } else {
+    } else if (!StyleDisplay()->IsContainSize()) {
       NS_ASSERTION(aType == nsLayoutUtils::PREF_ISIZE, "Unexpected type");
       dropdownContentISize = mDropdownFrame->GetPrefISize(aRenderingContext);
-      if (isUsingOverlayScrollbars) {
-        dropdownContentISize += scrollbarWidth;
-      }
+    }
+    if (isUsingOverlayScrollbars) {
+      dropdownContentISize += scrollbarWidth;
     }
     dropdownContentISize = NSCoordSaturatingSubtract(dropdownContentISize,
                                                      scrollbarWidth,
                                                      nscoord_MAX);
 
     displayISize = std::max(dropdownContentISize, displayISize);
   }
 
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -310,19 +310,20 @@ nsListControlFrame::CalcBSizeOfARow()
   // Calculate the block size in our writing mode of a single row in the
   // listbox or dropdown list by using the tallest thing in the subtree,
   // since there may be option groups in addition to option elements,
   // either of which may be visible or invisible, may use different
   // fonts, etc.
   int32_t blockSizeOfARow = GetMaxOptionBSize(GetOptionsContainer(),
                                               GetWritingMode());
 
-  // Check to see if we have zero items (and optimize by checking
-  // blockSizeOfARow first)
-  if (blockSizeOfARow == 0 && GetNumberOfOptions() == 0) {
+  // Check to see if we have zero items or are size contained
+  // (and optimize by checking blockSizeOfARow first)
+  if ((blockSizeOfARow == 0 && GetNumberOfOptions() == 0) ||
+      StyleDisplay()->IsContainSize()) {
     float inflation = nsLayoutUtils::FontSizeInflationFor(this);
     blockSizeOfARow = CalcFallbackRowBSize(inflation);
   }
 
   return blockSizeOfARow;
 }
 
 nscoord
new file mode 100644
--- /dev/null
+++ b/layout/reftests/w3c-css/submitted/contain/contain-size-select-001-ref.html
@@ -0,0 +1,32 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>CSS Reftest Reference</title>
+  <link rel="author" title="Morgan Rae Reschenberg" href="mailto:mreschenberg@berkeley.edu">
+  <style>
+  .minWidth {
+    min-width: 100px;
+  }
+  .width {
+    width: 100px;
+  }
+  .floatLWidth {
+    float: left;
+    width: 100px;
+  }
+  </style>
+</head>
+<body>
+  <select class="floatLWidth">
+  </select>
+  <br style="clear:both;">
+
+  <select class="minWidth">
+  </select>
+  <br>
+
+  <select class="width">
+  </select>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/w3c-css/submitted/contain/contain-size-select-001.html
@@ -0,0 +1,48 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>CSS Test: 'contain: size' on select objects should cause them to behave as if they have no contents.</title>
+  <link rel="author" title="Morgan Rae Reschenberg" href="mailto:mreschenberg@berkeley.edu">
+  <link rel="match" href="contain-size-select-001-ref.html">
+  <style>
+  select {
+    contain: size;
+    color: transparent;
+  }
+  .minWidth {
+    min-width: 100px;
+  }
+  .width {
+    width: 100px;
+  }
+  .floatLWidth {
+    float: left;
+    width: 100px;
+  }
+  </style>
+</head>
+<body>
+  <select class="floatLWidth">
+    <option>CSS Test: A size-contained floated select with specified width and no specified height should size itself as if it had no contents.</option>
+    <option>a</option>
+    <option>b</option>
+    <option>c</option>
+  </select>
+  <br style="clear:both;">
+
+  <select class="minWidth">
+    <option>CSS Test: A size-contained select with specified min-width should size itself as if it had no contents.</option>
+    <option>a</option>
+    <option>b</option>
+    <option>c</option>
+  </select>
+  <br>
+
+  <select class="width">
+    <option>CSS Test: A size-contained select with specified width should size itself as if it had no contents.</option>
+    <option>a</option>
+    <option>b</option>
+    <option>c</option>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/w3c-css/submitted/contain/contain-size-select-002-ref.html
@@ -0,0 +1,32 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>CSS Reftest Reference</title>
+  <link rel="author" title="Morgan Rae Reschenberg" href="mailto:mreschenberg@berkeley.edu">
+  <style>
+  .floatLBasic {
+    float: left;
+  }
+  .iFlexBasic {
+    display: inline-flex;
+  }
+  </style>
+</head>
+<body>
+  <select>
+  </select>
+  <br>
+
+  <select class="floatLBasic">
+  </select>
+  <br style="clear:both;">
+
+  <select class="iFlexBasic">
+  </select>
+  <br>
+
+  outside before<select>
+  </select>outside after
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/w3c-css/submitted/contain/contain-size-select-002.html
@@ -0,0 +1,43 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>CSS Test: 'contain: size' on select objects should cause them to behave as if they have no contents.</title>
+  <link rel="author" title="Morgan Rae Reschenberg" href="mailto:mreschenberg@berkeley.edu">
+  <link rel="match" href="contain-size-select-002-ref.html">
+  <style>
+  select {
+    contain: size;
+    color: transparent;
+  }
+  .floatLBasic {
+    float: left;
+  }
+  </style>
+</head>
+<body>
+  <select>
+    <option>CSS Test: A size-contained select with no specified size should size itself as if it had no contents.</option>
+    <option>aaaaaa</option>
+    <option>b</option>
+    <option>c</option>
+  </select>
+  <br>
+
+
+  <select class="floatLBasic">
+    <option>CSS Test: A size-contained floated select with auto width and no specified height should size itself as if it had no contents.</option>
+    <option>a</option>
+    <option>b</option>
+    <option>c</option>
+  </select>
+  <br style="clear:both;">
+
+  outside before<select>
+    <option>CSS Test: A size-contained select should perform baseline alignment as if the container were empty.</option>
+    <option>a</option>
+    <option>b</option>
+    <option>c</option>
+  </select>outside after
+</body>
+</html>
--- a/layout/reftests/w3c-css/submitted/contain/reftest.list
+++ b/layout/reftests/w3c-css/submitted/contain/reftest.list
@@ -18,10 +18,12 @@ pref(layout.css.overflow-clip-box.enable
 == contain-paint-stacking-context-001a.html contain-paint-stacking-context-001-ref.html
 == contain-paint-stacking-context-001b.html contain-paint-stacking-context-001-ref.html
 == contain-size-button-001.html contain-size-button-001-ref.html
 == contain-size-block-001.html contain-size-block-001-ref.html
 == contain-size-inline-block-001.html contain-size-inline-block-001-ref.html
 == contain-size-flex-001.html contain-size-flex-001-ref.html
 fuzzy-if(webrender&&winWidget,3,2) == contain-size-inline-flex-001.html contain-size-inline-flex-001-ref.html # bug 1474093
 == contain-size-multicol-001.html contain-size-multicol-001-ref.html
+== contain-size-select-001.html contain-size-select-001-ref.html
+fails == contain-size-select-002.html contain-size-select-002-ref.html # bug 1476127
 == contain-size-fieldset-001.html contain-size-fieldset-001-ref.html
 == contain-size-fieldset-002.html contain-size-fieldset-002-ref.html