Bug 867163 - Clear context actions when dismissing the appbar [r=sfoster]
authorMatt Brubeck <mbrubeck@mozilla.com>
Tue, 07 May 2013 11:38:08 -0700
changeset 142096 c39614efd2637b174d3a5272c1633762a2d1259e
parent 142095 f0653eab4d95719c829b118174382cfa679a296e
child 142097 e3dcea95f1613007334844001faf1980e428dc52
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfoster
bugs867163
milestone23.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 867163 - Clear context actions when dismissing the appbar [r=sfoster]
browser/metro/base/content/TopSites.js
browser/metro/base/content/appbar.js
browser/metro/base/content/bookmarks.js
browser/metro/base/content/history.js
--- a/browser/metro/base/content/TopSites.js
+++ b/browser/metro/base/content/TopSites.js
@@ -252,17 +252,16 @@ TopSitesView.prototype = {
       },0);
     }
   },
   handleEvent: function(aEvent) {
     switch (aEvent.type){
       case "MozAppbarDismissing":
         // clean up when the context appbar is dismissed - we don't remember selections
         this._lastSelectedSites = null;
-        this._set.clearSelection();
     }
   },
 
   update: function() {
     // called by the NewTabUtils.allPages.update, notifying us of data-change in topsites
     let grid = this._set,
         dirtySites = TopSites.dirty();
 
--- a/browser/metro/base/content/appbar.js
+++ b/browser/metro/base/content/appbar.js
@@ -1,23 +1,29 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
 var Appbar = {
   get appbar()        { return document.getElementById('appbar'); },
   get consoleButton() { return document.getElementById('console-button'); },
   get jsShellButton() { return document.getElementById('jsshell-button'); },
   get zoomInButton()  { return document.getElementById('zoomin-button'); },
   get zoomOutButton() { return document.getElementById('zoomout-button'); },
   get starButton()    { return document.getElementById('star-button'); },
   get pinButton()     { return document.getElementById('pin-button'); },
   get moreButton()    { return document.getElementById('more-button'); },
 
   // track selected/active richgrid/tilegroup - the context for contextual action buttons
   activeTileset: null,
 
   init: function Appbar_init() {
     window.addEventListener('MozAppbarShowing', this, false);
+    window.addEventListener('MozAppbarDismissing', this, false);
     window.addEventListener('MozPrecisePointer', this, false);
     window.addEventListener('MozImprecisePointer', this, false);
     window.addEventListener('MozContextActionsChange', this, false);
     Elements.browsers.addEventListener('URLChanged', this, true);
     Elements.tabList.addEventListener('TabSelect', this, true);
     Elements.panelUI.addEventListener('ToolPanelShown', this, false);
     Elements.panelUI.addEventListener('ToolPanelHidden', this, false);
 
@@ -35,16 +41,23 @@ var Appbar = {
       case 'ToolPanelShown':
       case 'ToolPanelHidden':
         this.appbar.dismiss();
         break;
       case 'MozAppbarShowing':
         this._updatePinButton();
         this._updateStarButton();
         break;
+      case 'MozAppbarDismissing':
+        if (this.activeTileset) {
+          this.activeTileset.clearSelection();
+        }
+        this.clearContextualActions();
+        this.activeTileset = null;
+        break;
       case 'MozPrecisePointer':
       case 'MozImprecisePointer':
         this._updateZoomButtons();
         break;
       case 'MozContextActionsChange':
         let actions = aEvent.actions;
         // could transition in old, new buttons?
         this.showContextualActions(actions);
@@ -157,17 +170,18 @@ var Appbar = {
       event.initEvent("context-action", true, true); // is cancelable
       activeTileset.dispatchEvent(event);
       if (!event.defaultPrevented) {
         activeTileset.clearSelection();
         this.appbar.dismiss();
       }
     }
   },
-  showContextualActions: function(aVerbs){
+
+  showContextualActions: function(aVerbs) {
     let doc = document;
     // button element id to action verb lookup
     let buttonsMap = new Map();
     for (let verb of aVerbs) {
       let id = verb + "-selected-button";
       if (!doc.getElementById(id)) {
         throw new Error("Appbar.showContextualActions: no button for " + verb);
       }
@@ -190,16 +204,21 @@ var Appbar = {
       if (toHide.length) {
         yield Util.transitionElementVisibility(toHide, false);
       }
       if (toShow.length) {
         yield Util.transitionElementVisibility(toShow, true);
       }
     });
   },
+
+  clearContextualActions: function() {
+    this.showContextualActions([]);
+  },
+
   _onTileSelectionChanged: function _onTileSelectionChanged(aEvent){
     let activeTileset = aEvent.target;
 
     // deselect tiles in other tile groups
     if (this.activeTileset && this.activeTileset !== activeTileset) {
       this.activeTileset.clearSelection();
     }
     // keep track of which view is the target/scope for the contextual actions
--- a/browser/metro/base/content/bookmarks.js
+++ b/browser/metro/base/content/bookmarks.js
@@ -349,24 +349,17 @@ BookmarksView.prototype = {
   handleEvent: function bv_handleEvent(aEvent) {
     switch (aEvent.type){
       case "MozAppbarDismissing":
         // If undo wasn't pressed, time to do definitive actions.
         if (this._toRemove) {
           for (let bookmarkId of this._toRemove) {
             this._bookmarkService.removeItem(bookmarkId);
           }
-
           this._toRemove = null;
-          this._set.clearSelection();
-
-          // Clear context app bar
-          let event = document.createEvent("Events");
-          event.initEvent("MozContextActionsChange", true, false);
-          this._set.dispatchEvent(event);
         }
         break;
 
       case "BookmarksNeedsRefresh":
         this.getBookmarks(true);
         break;
     }
   }
--- a/browser/metro/base/content/history.js
+++ b/browser/metro/base/content/history.js
@@ -189,17 +189,16 @@ HistoryView.prototype = {
           }
 
           // Clear context app bar
           let event = document.createEvent("Events");
           event.initEvent("MozContextActionsChange", true, false);
           this._set.dispatchEvent(event);
 
           this._toRemove = null;
-          this._set.clearSelection();
         }
         break;
 
       case "HistoryNeedsRefresh":
         this.populateGrid(true);
         break;
     }
   },