Bug 904317 - observe viewstate in view markup, call _adjustDOMforViewState at init and from onViewStateChange. r=rsilveira
authorSam Foster <sfoster@mozilla.com>
Fri, 16 Aug 2013 16:56:50 -0700
changeset 143029 dd9d2871a6f2886d0a411d7fc9c8aab01fbef6ab
parent 143028 734f0dc3958eea48da89ff5401954372946b7159
child 143030 5a5d5ebec1fc0d025b8fa30817387cd0c2080e49
push id32605
push userphilringnalda@gmail.com
push dateMon, 19 Aug 2013 00:51:46 +0000
treeherdermozilla-inbound@7f882e063eaf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrsilveira
bugs904317
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 904317 - observe viewstate in view markup, call _adjustDOMforViewState at init and from onViewStateChange. r=rsilveira
browser/metro/base/content/startui/BookmarksView.js
browser/metro/base/content/startui/HistoryView.js
browser/metro/base/content/startui/RemoteTabsView.js
browser/metro/base/content/startui/Start.xul
browser/metro/base/content/startui/StartUI.js
browser/metro/base/content/startui/TopSitesView.js
browser/metro/modules/View.jsm
--- a/browser/metro/base/content/startui/BookmarksView.js
+++ b/browser/metro/base/content/startui/BookmarksView.js
@@ -25,16 +25,17 @@ function BookmarksView(aSet, aLimit, aRo
   this._changes = new BookmarkChangeListener(this);
   this._pinHelper = new ItemPinHelper("metro.bookmarks.unpinned");
   this._bookmarkService.addObserver(this._changes, false);
   Services.obs.addObserver(this, "metro_viewstate_changed", false);
   StartUI.chromeWin.addEventListener('MozAppbarDismissing', this, false);
   StartUI.chromeWin.addEventListener('BookmarksNeedsRefresh', this, false);
   window.addEventListener("TabClose", this, true);
 
+  this._adjustDOMforViewState();
   this.root = aRoot;
 }
 
 BookmarksView.prototype = Util.extend(Object.create(View.prototype), {
   _limit: null,
   _set: null,
   _changes: null,
   _root: null,
--- a/browser/metro/base/content/startui/HistoryView.js
+++ b/browser/metro/base/content/startui/HistoryView.js
@@ -15,16 +15,18 @@ function HistoryView(aSet, aLimit, aFilt
   this._navHistoryService = gHistSvc;
 
   this._pinHelper = new ItemPinHelper("metro.history.unpinned");
   this._historyService.addObserver(this, false);
   Services.obs.addObserver(this, "metro_viewstate_changed", false);
   StartUI.chromeWin.addEventListener('MozAppbarDismissing', this, false);
   StartUI.chromeWin.addEventListener('HistoryNeedsRefresh', this, false);
   window.addEventListener("TabClose", this, true);
+
+  this._adjustDOMforViewState();
 }
 
 HistoryView.prototype = Util.extend(Object.create(View.prototype), {
   _set: null,
   _toRemove: null,
 
   destruct: function destruct() {
     this._historyService.removeObserver(this);
--- a/browser/metro/base/content/startui/RemoteTabsView.js
+++ b/browser/metro/base/content/startui/RemoteTabsView.js
@@ -32,16 +32,17 @@ function RemoteTabsView(aSet, aSetUIAcce
   Services.obs.addObserver(this, "metro_viewstate_changed", false);
 
   if (this.isSyncEnabled() ) {
     this.populateGrid();
   }
   else {
     this.setUIAccessVisible(false);
   }
+  this._adjustDOMforViewState();
 }
 
 RemoteTabsView.prototype = Util.extend(Object.create(View.prototype), {
   _set: null,
   _uiAccessElements: [],
 
   handleItemClick: function tabview_handleItemClick(aItem) {
     let url = aItem.getAttribute("value");
--- a/browser/metro/base/content/startui/Start.xul
+++ b/browser/metro/base/content/startui/Start.xul
@@ -40,39 +40,39 @@
 
   <hbox id="start-container" observes="bcast_windowState">
   <!-- the start-container element has a max-height set in StartUI.js -->
       <vbox id="start-topsites" class="meta-section" expanded="true">
         <label class="meta-section-title wide-title" value="&topSitesHeader.label;"/>
         <html:div class="meta-section-title narrow-title" onclick="StartUI.onNarrowTitleClick('start-topsites')">
           &narrowTopSitesHeader.label;
         </html:div>
-        <richgrid id="start-topsites-grid" set-name="topSites" rows="3" columns="3" tiletype="thumbnail" seltype="multiple" flex="1"/>
+        <richgrid id="start-topsites-grid" observes="bcast_windowState" set-name="topSites" rows="3" columns="3" tiletype="thumbnail" seltype="multiple" flex="1"/>
       </vbox>
 
       <vbox id="start-bookmarks" class="meta-section">
         <label class="meta-section-title wide-title" value="&bookmarksHeader.label;"/>
         <html:div class="meta-section-title narrow-title" onclick="StartUI.onNarrowTitleClick('start-bookmarks')">
           &narrowBookmarksHeader.label;
         </html:div>
-        <richgrid id="start-bookmarks-grid" set-name="bookmarks" seltype="multiple" flex="1"/>
+        <richgrid id="start-bookmarks-grid" observes="bcast_windowState" set-name="bookmarks" seltype="multiple" flex="1"/>
       </vbox>
 
       <vbox id="start-history" class="meta-section">
         <label class="meta-section-title wide-title" value="&recentHistoryHeader.label;"/>
         <html:div class="meta-section-title narrow-title" onclick="StartUI.onNarrowTitleClick('start-history')">
           &narrowRecentHistoryHeader.label;
         </html:div>
-        <richgrid id="start-history-grid" set-name="recentHistory" seltype="multiple" flex="1"/>
+        <richgrid id="start-history-grid" observes="bcast_windowState" set-name="recentHistory" seltype="multiple" flex="1"/>
       </vbox>
 
 #ifdef MOZ_SERVICES_SYNC
       <vbox id="start-remotetabs" class="meta-section">
         <label class="meta-section-title wide-title" value="&remoteTabsHeader.label;"/>
         <html:div id="snappedRemoteTabsLabel" class="meta-section-title narrow-title" onclick="StartUI.onNarrowTitleClick('start-remotetabs')">
           &narrowRemoteTabsHeader.label;
         </html:div>
-        <richgrid id="start-remotetabs-grid" set-name="remoteTabs" seltype="multiple" flex="1"/>
+        <richgrid id="start-remotetabs-grid" observes="bcast_windowState" set-name="remoteTabs" seltype="multiple" flex="1"/>
       </vbox>
 #endif
   </hbox>
   </html:body>
 </html:html>
--- a/browser/metro/base/content/startui/StartUI.js
+++ b/browser/metro/base/content/startui/StartUI.js
@@ -8,17 +8,17 @@ Cu.import("resource://gre/modules/Servic
 
 // When setting the max-height of the start tab contents, this is the buffer we subtract
 // for the nav bar plus white space above it.
 const kBottomContentMargin = 50;
 
 var StartUI = {
   get startUI() { return document.getElementById("start-container"); },
 
-  get maxResultsPerSection() { 
+  get maxResultsPerSection() {
     return Services.prefs.getIntPref("browser.display.startUI.maxresults");
   },
 
   get chromeWin() {
     // XXX Not e10s friendly. We use this in a few places.
     return Services.wm.getMostRecentWindow('navigator:browser');
   },
 
@@ -26,16 +26,17 @@ var StartUI = {
     this.startUI.addEventListener("click", this, false);
     this.startUI.addEventListener("MozMousePixelScroll", this, false);
 
     // Update the input type on our local broadcaster
     document.getElementById("bcast_preciseInput").setAttribute("input",
       this.chromeWin.InputSourceHelper.isPrecise ? "precise" : "imprecise");
 
     this._updateStartHeight();
+    this._adjustDOMforViewState();
 
     TopSitesStartView.init();
     BookmarksStartView.init();
     HistoryStartView.init();
     RemoteTabsStartView.init();
 
     TopSitesStartView.show();
     BookmarksStartView.show();
@@ -140,16 +141,21 @@ var StartUI = {
         case Ci.nsIWinMetroUtils.filled:
           currViewState = "filled";
           break;
         case Ci.nsIWinMetroUtils.snapped:
           currViewState = "snapped";
           break;
       }
       document.getElementById("bcast_windowState").setAttribute("viewstate", currViewState);
+      if (currViewState == "snapped") {
+        document.getElementById("start-topsites-grid").removeAttribute("tiletype");
+      } else {
+        document.getElementById("start-topsites-grid").setAttribute("tiletype", "thumbnail");
+      }
     }
   },
 
   observe: function (aSubject, aTopic, aData) {
     switch (aTopic) {
       case "metro_viewstate_changed":
         this._adjustDOMforViewState();
         break;
--- a/browser/metro/base/content/startui/TopSitesView.js
+++ b/browser/metro/base/content/startui/TopSitesView.js
@@ -20,16 +20,18 @@ function TopSitesView(aGrid, aMaxSites) 
   let history = Cc["@mozilla.org/browser/nav-history-service;1"].
                 getService(Ci.nsINavHistoryService);
   history.addObserver(this, false);
 
   PageThumbs.addExpirationFilter(this);
   Services.obs.addObserver(this, "Metro:RefreshTopsiteThumbnail", false);
   Services.obs.addObserver(this, "metro_viewstate_changed", false);
 
+  this._adjustDOMforViewState();
+
   NewTabUtils.allPages.register(this);
   TopSites.prepareCache().then(function(){
     this.populateGrid();
   }.bind(this));
 }
 
 TopSitesView.prototype = Util.extend(Object.create(View.prototype), {
   _set:null,
@@ -219,31 +221,43 @@ TopSitesView.prototype = Util.extend(Obj
   filterForThumbnailExpiration: function filterForThumbnailExpiration(aCallback) {
     aCallback([item.getAttribute("value") for (item of this._set.children)]);
   },
 
   isFirstRun: function isFirstRun() {
     return prefs.getBoolPref("browser.firstrun.show.localepicker");
   },
 
+  _adjustDOMforViewState: function _adjustDOMforViewState(aState) {
+    if (!this._set)
+      return;
+    if (!aState)
+      aState = this._set.getAttribute("viewstate");
+
+    View.prototype._adjustDOMforViewState.call(this, aState);
+
+    // propogate tiletype changes down to tile children
+    let tileType = this._set.getAttribute("tiletype");
+    for (let item of this._set.children) {
+      if (tileType) {
+        item.setAttribute("tiletype", tileType);
+      } else {
+        item.removeAttribute("tiletype");
+      }
+    }
+  },
+
   // nsIObservers
   observe: function (aSubject, aTopic, aState) {
     switch(aTopic) {
       case "Metro:RefreshTopsiteThumbnail":
         this.forceReloadOfThumbnail(aState);
         break;
       case "metro_viewstate_changed":
         this.onViewStateChange(aState);
-        for (let item of this._set.children) {
-          if (aState == "snapped") {
-            item.removeAttribute("tiletype");
-          } else {
-            item.setAttribute("tiletype", "thumbnail");
-          }
-        }
         break;
     }
   },
 
   // nsINavHistoryObserver
   onBeginUpdateBatch: function() {
   },
 
--- a/browser/metro/modules/View.jsm
+++ b/browser/metro/modules/View.jsm
@@ -22,21 +22,26 @@ function makeURI(aURL, aOriginCharset, a
 
 // --------------------------------
 // View prototype for shared functionality
 
 function View() {
 }
 
 View.prototype = {
+  _adjustDOMforViewState: function _adjustDOMforViewState(aState) {
+    if (this._set) {
+        if (undefined == aState)
+          aState = this._set.getAttribute("viewstate");
+      this._set.setAttribute("suppressonselect", (aState == "snapped"));
+    }
+  },
 
   onViewStateChange: function (aState) {
-    if (this._set) {
-      this._set.setAttribute("suppressonselect", (aState == "snapped"));
-    }
+    this._adjustDOMforViewState(aState);
   },
 
   _updateFavicon: function pv__updateFavicon(aItem, aUri) {
     if ("string" == typeof aUri) {
       aUri = makeURI(aUri);
     }
     PlacesUtils.favicons.getFaviconURLForPage(aUri, this._gotIcon.bind(this, aItem));
   },