Bug 1421497 - Change engines per row to be a CSS variable. r=dao draft
authorTim Nguyen <ntim.bugs@gmail.com>
Wed, 10 Jan 2018 17:31:32 +0000
changeset 718603 a9a9edb61bff73286a0bf6a1df0918b046b6380f
parent 718602 a0cf492f27587a106d6079b2a2ae73264aba607f
child 745555 af2be19cec7d39805f75e298a7c669eee0749e70
push id95001
push userbmo:ntim.bugs@gmail.com
push dateWed, 10 Jan 2018 17:32:06 +0000
reviewersdao
bugs1421497
milestone59.0a1
Bug 1421497 - Change engines per row to be a CSS variable. r=dao MozReview-Commit-ID: 78zWGBxXtkr
browser/components/search/content/search.xml
browser/themes/shared/searchbar.inc.css
--- a/browser/components/search/content/search.xml
+++ b/browser/components/search/content/search.xml
@@ -1578,20 +1578,17 @@
                             .getInterface(Ci.nsIDOMWindowUtils)
                             .screenPixelsPerCSSPixel;
           if (Math.floor(scale) != scale) {
             --panelWidth;
           }
 
           // The + 1 is because the last button doesn't have a right border.
           let enginesPerRow = Math.floor((panelWidth + 1) / this.buttonWidth);
-          let buttonWidth = Math.floor(panelWidth / enginesPerRow);
-          // There will be an emtpy area of:
-          //   panelWidth - enginesPerRow * buttonWidth  px
-          // at the end of each row.
+          this.buttons.style.setProperty("--engines-per-row", enginesPerRow);
 
           // If the <description> tag with the list of search engines doesn't have
           // a fixed height, the panel will be sized incorrectly, causing the bottom
           // of the suggestion <tree> to be hidden.
           if (this.compact)
             ++oneOffCount;
           let rowCount = Math.ceil(oneOffCount / enginesPerRow);
           let height = rowCount * 33; // 32px per row, 1px border.
@@ -1612,57 +1609,39 @@
             button.id = this._buttonIDForEngine(engine);
             let uri = "chrome://browser/skin/search-engine-placeholder.png";
             if (engine.iconURI) {
               uri = engine.iconURI.spec;
             }
             button.setAttribute("image", uri);
             button.setAttribute("class", "searchbar-engine-one-off-item");
             button.setAttribute("tooltiptext", engine.name);
-            button.setAttribute("width", buttonWidth);
             button.engine = engine;
 
             if ((i + 1) % enginesPerRow == 0)
               button.classList.add("last-of-row");
 
             if (i + 1 == engines.length)
               button.classList.add("last-engine");
 
             if (i >= oneOffCount + dummyItems - enginesPerRow)
               button.classList.add("last-row");
 
             this.buttons.insertBefore(button, this.settingsButtonCompact);
           }
 
-          let hasDummyItems = !!dummyItems;
           while (dummyItems) {
             let button = document.createElementNS(kXULNS, "button");
             button.setAttribute("class", "searchbar-engine-one-off-item dummy last-row");
-            button.setAttribute("width", buttonWidth);
 
             if (!--dummyItems)
               button.classList.add("last-of-row");
 
             this.buttons.insertBefore(button, this.settingsButtonCompact);
           }
-
-          if (this.compact) {
-            this.settingsButtonCompact.setAttribute("width", buttonWidth);
-            if (rowCount == 1 && hasDummyItems) {
-              // When there's only one row, make the compact settings button
-              // hug the right edge of the panel.  It may not due to the panel's
-              // width not being an integral multiple of the button width.  (See
-              // the "There will be an emtpy area" comment above.)  Increase the
-              // width of the last dummy item by the remainder.
-              let remainder = panelWidth - (enginesPerRow * buttonWidth);
-              let width = remainder + buttonWidth;
-              let lastDummyItem = this.settingsButtonCompact.previousSibling;
-              lastDummyItem.setAttribute("width", width);
-            }
-          }
         ]]></body>
       </method>
 
       <!-- If a page offers more than this number of engines, the add-engines
            menu button is shown, instead of showing the engines directly in the
            popup. -->
       <field name="_addEngineMenuThreshold">5</field>
 
--- a/browser/themes/shared/searchbar.inc.css
+++ b/browser/themes/shared/searchbar.inc.css
@@ -69,17 +69,17 @@
   background-color: var(--arrowpanel-dimmed);
   /* Bug 1108841: prevent font-size from affecting the layout */
   line-height: 0;
 }
 
 .searchbar-engine-one-off-item {
   -moz-appearance: none;
   display: inline-block;
-  min-width: 48px;
+  min-width: calc(100% / var(--engines-per-row));
   height: 32px;
   margin: 0;
   padding: 0;
   background: linear-gradient(transparent 15%, var(--panel-separator-color) 15%, var(--panel-separator-color) 85%, transparent 85%);
   background-size: 1px auto;
   background-repeat: no-repeat;
   background-position: right center;
   color: GrayText;