Bug 1334444 - Fix "[compact layout] Add "Your Top Sites" heading" r=gijs, a=jcristau
authorDão Gottwald <dao+bmo>
Tue, 31 Jan 2017 03:33:00 +0100
changeset 375797 594b1915813622cc282e1878f7b6d2875ff7aa99
parent 375796 3c3be02271337ec3d23c4515f2aa7041c8ee4c09
child 375798 086d2492f20bc1dd6759027511e57156cd145400
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgijs, jcristau
bugs1334444
milestone53.0a2
Bug 1334444 - Fix "[compact layout] Add "Your Top Sites" heading" r=gijs, a=jcristau
browser/base/content/newtab/grid.js
browser/base/content/newtab/newTab.css
browser/base/content/newtab/newTab.xhtml
browser/themes/shared/newtab/newTab.inc.css
--- a/browser/base/content/newtab/grid.js
+++ b/browser/base/content/newtab/grid.js
@@ -14,16 +14,17 @@ const SPONSORED_TAG_BUFFER = 2; // 2px b
 /**
  * This singleton represents the grid that contains all sites.
  */
 var gGrid = {
   /**
    * The DOM node of the grid.
    */
   _node: null,
+  _gridDefaultContent: null,
   get node() { return this._node; },
 
   /**
    * The cached DOM fragment for sites.
    */
   _siteFragment: null,
 
   /**
@@ -44,16 +45,17 @@ var gGrid = {
   get isDocumentLoaded() { return document.readyState == "complete"; },
 
   /**
    * Initializes the grid.
    * @param aSelector The query selector of the grid.
    */
   init: function Grid_init() {
     this._node = document.getElementById("newtab-grid");
+    this._gridDefaultContent = this._node.lastChild;
     this._createSiteFragment();
 
     gLinks.populateCache(() => {
       this._refreshGrid();
       this._ready = true;
 
       // If fetching links took longer than loading the page itself then
       // we need to resize the grid as that was blocked until now.
@@ -142,17 +144,19 @@ var gGrid = {
     let numLinks = Math.min(links.length, cells.length);
     for (let i = 0; i < numLinks; i++) {
       if (links[i]) {
         this.createSite(links[i], cells[i]);
       }
     }
 
     this._cells = cells;
-    this._node.innerHTML = "";
+    while (this._gridDefaultContent.nextSibling) {
+      this._gridDefaultContent.nextSibling.remove();
+    }
     this._node.appendChild(fragment);
   },
 
   /**
    * Calculate the height for a number of rows up to the maximum rows
    * @param rows Number of rows defaulting to the max
    */
   _computeHeight: function Grid_computeHeight(aRows) {
--- a/browser/base/content/newtab/newTab.css
+++ b/browser/base/content/newtab/newTab.css
@@ -117,16 +117,20 @@ input[type=button] {
   opacity: 0;
 }
 
 #newtab-grid[locked],
 #newtab-grid[page-disabled] {
   pointer-events: none;
 }
 
+body:not(.compact) #topsites-heading {
+  display: none;
+}
+
 /*
  * If you change the sizes here, make sure you
  * change the preferences:
  * toolkit.pageThumbs.minWidth
  * toolkit.pageThumbs.minHeight
  */
 /* CELLS */
 .newtab-cell {
--- a/browser/base/content/newtab/newTab.xhtml
+++ b/browser/base/content/newtab/newTab.xhtml
@@ -50,16 +50,17 @@
             <label>&newtab.customize.cog.learn;</label>
           </div>
         </div>
     </div>
   </div>
 
   <div id="newtab-vertical-margin">
     <div id="newtab-margin-top"/>
+
     <div id="newtab-margin-undo-container">
       <div id="newtab-undo-container" undo-disabled="true">
         <label id="newtab-undo-label">&newtab.undo.removedLabel;</label>
         <button id="newtab-undo-button" tabindex="-1"
                 class="newtab-undo-button">&newtab.undo.undoButton;</button>
         <button id="newtab-undo-restore-button" tabindex="-1"
                 class="newtab-undo-button">&newtab.undo.restoreButton;</button>
         <button id="newtab-undo-close-button" tabindex="-1" title="&newtab.undo.closeTooltip;"/>
@@ -74,19 +75,21 @@
         <input id="newtab-search-submit" type="button"
              title="&contentSearchSubmit.tooltip;"/>
       </div>
     </div>
 
     <div id="newtab-horizontal-margin">
       <div class="newtab-side-margin"/>
       <div id="newtab-grid">
+        <h1 id="topsites-heading">Your Top Sites</h1>
       </div>
       <div class="newtab-side-margin"/>
     </div>
+
     <div id="newtab-margin-bottom"/>
   </div>
   <input id="newtab-customize-button" type="button" dir="&locale.dir;"
          value="&#x2699;"
          title="&newtab.customize.title;"/>
 </body>
 <script type="text/javascript;version=1.8" src="chrome://browser/content/contentSearchUI.js"/>
 <script type="text/javascript;version=1.8" src="chrome://browser/content/newtab/newTab.js"/>
--- a/browser/themes/shared/newtab/newTab.inc.css
+++ b/browser/themes/shared/newtab/newTab.inc.css
@@ -94,16 +94,37 @@
 
 #newtab-customize-button:-moz-any(:hover, :active, [active]) {
   background-image: -moz-image-rect(url(chrome://browser/skin/newtab/controls.svg), 0, 64, 32, 32);
   background-color: #FFFFFF;
   border: solid 1px #CCCCCC;
   border-radius: 2px;
 }
 
+/* GRID */
+body.compact #newtab-grid {
+  /* Allow #topsites-heading to use position:absolute such that it doesn't
+     affect how many cells we can fit into the grid. */
+  position: relative;
+  padding-top: 1em;
+  margin-top: -1em;
+}
+
+#topsites-heading {
+  color: #7A7A7A;
+  font-size: 1em;
+  font-weight: normal;
+  /* Position the heading such that it doesn't affect how many cells we
+     can fit into the grid. */
+  position: absolute;
+  top: 0;
+  /* The horizontal margin aligns the heading with the cells. */
+  margin: 0 10px;
+}
+
 /* CELLS */
 .newtab-cell {
   --cell-corner-radius: 8px;
   background-color: rgba(255,255,255,.2);
   border-radius: var(--cell-corner-radius);
 }
 
 body.compact .newtab-cell {