mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 06:45:42 +00:00
Bug 593157 - Use a pref to keep track of Panorama "first run" experience. r=dolske, a=dolske
This commit is contained in:
parent
0683b09215
commit
b086460b49
@ -32,6 +32,12 @@ XPCOMUtils.defineLazyGetter(this, "tabviewBundle", function() {
|
||||
|
||||
function tabviewString(name) tabviewBundle.GetStringFromName('tabview.' + name);
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "gPrefBranch", function() {
|
||||
return Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefService).
|
||||
getBranch("browser.panorama.");
|
||||
});
|
||||
|
||||
# NB: Certain files need to evaluate before others
|
||||
|
||||
#include iq.js
|
||||
|
@ -155,9 +155,11 @@ let UI = {
|
||||
|
||||
GroupItems.init();
|
||||
|
||||
var groupItemsData = Storage.readGroupItemsData(gWindow);
|
||||
var firstTime = !groupItemsData || Utils.isEmptyObject(groupItemsData);
|
||||
var groupItemData = Storage.readGroupItemData(gWindow);
|
||||
let firstTime = true;
|
||||
if (gPrefBranch.prefHasUserValue("experienced_first_run"))
|
||||
firstTime = !gPrefBranch.getBoolPref("experienced_first_run");
|
||||
let groupItemsData = Storage.readGroupItemsData(gWindow);
|
||||
let groupItemData = Storage.readGroupItemData(gWindow);
|
||||
GroupItems.reconstitute(groupItemsData, groupItemData);
|
||||
GroupItems.killNewTabGroup(); // temporary?
|
||||
|
||||
@ -165,45 +167,9 @@ let UI = {
|
||||
TabItems.init();
|
||||
TabItems.pausePainting();
|
||||
|
||||
if (firstTime) {
|
||||
var padding = 10;
|
||||
var infoWidth = 350;
|
||||
var infoHeight = 232;
|
||||
var pageBounds = Items.getPageBounds();
|
||||
pageBounds.inset(padding, padding);
|
||||
|
||||
// ___ make a fresh groupItem
|
||||
var box = new Rect(pageBounds);
|
||||
box.width =
|
||||
Math.min(box.width * 0.667, pageBounds.width - (infoWidth + padding));
|
||||
box.height = box.height * 0.667;
|
||||
var options = {
|
||||
bounds: box
|
||||
};
|
||||
|
||||
var groupItem = new GroupItem([], options);
|
||||
|
||||
var items = TabItems.getItems();
|
||||
items.forEach(function(item) {
|
||||
if (item.parent)
|
||||
item.parent.remove(item);
|
||||
|
||||
groupItem.add(item);
|
||||
});
|
||||
|
||||
// ___ make info item
|
||||
let video = "http://videos-cdn.mozilla.net/firefox4beta/tabcandy_howto.webm";
|
||||
var html =
|
||||
"<div class='intro'>"
|
||||
+ "<video src='" + video + "' width='100%' preload controls>"
|
||||
+ "</div>";
|
||||
|
||||
box.left = box.right + padding;
|
||||
box.width = infoWidth;
|
||||
box.height = infoHeight;
|
||||
var infoItem = new InfoItem(box);
|
||||
infoItem.html(html);
|
||||
}
|
||||
// if first time in Panorama or no group data:
|
||||
if (firstTime || !groupItemsData || Utils.isEmptyObject(groupItemsData))
|
||||
this.reset(firstTime);
|
||||
|
||||
// ___ resizing
|
||||
if (this._pageBounds)
|
||||
@ -263,6 +229,51 @@ let UI = {
|
||||
this._reorderTabsOnHide = null;
|
||||
this._frameInitialized = false;
|
||||
},
|
||||
|
||||
// Function: reset
|
||||
// Resets the Panorama view to have just one group with all tabs
|
||||
// and, if firstTime == true, add the welcome video/tab
|
||||
reset: function UI_reset(firstTime) {
|
||||
let padding = 10;
|
||||
let infoWidth = 350;
|
||||
let infoHeight = 232;
|
||||
let pageBounds = Items.getPageBounds();
|
||||
pageBounds.inset(padding, padding);
|
||||
|
||||
// ___ make a fresh groupItem
|
||||
let box = new Rect(pageBounds);
|
||||
box.width =
|
||||
Math.min(box.width * 0.667, pageBounds.width - (infoWidth + padding));
|
||||
box.height = box.height * 0.667;
|
||||
|
||||
GroupItems.groupItems.forEach(function(group) {
|
||||
group.close();
|
||||
});
|
||||
|
||||
let groupItem = new GroupItem([], {bounds: box});
|
||||
let items = TabItems.getItems();
|
||||
items.forEach(function(item) {
|
||||
if (item.parent)
|
||||
item.parent.remove(item);
|
||||
groupItem.add(item);
|
||||
});
|
||||
|
||||
if (firstTime) {
|
||||
gPrefBranch.setBoolPref("experienced_first_run", true);
|
||||
|
||||
// ___ make info item
|
||||
let video =
|
||||
"http://videos-cdn.mozilla.net/firefox4beta/tabcandy_howto.webm";
|
||||
let html =
|
||||
"<div class='intro'>"
|
||||
+ "<video src='" + video + "' width='100%' preload controls>"
|
||||
+ "</div>";
|
||||
let infoBox = new Rect(box.right + padding, box.top,
|
||||
infoWidth, infoHeight);
|
||||
let infoItem = new InfoItem(infoBox);
|
||||
infoItem.html(html);
|
||||
}
|
||||
},
|
||||
|
||||
// Function: blurAll
|
||||
// Blurs any currently focused element
|
||||
@ -1006,7 +1017,7 @@ let UI = {
|
||||
}, {
|
||||
name: "reset",
|
||||
code: function() {
|
||||
self._reset();
|
||||
self.reset();
|
||||
}
|
||||
}, {
|
||||
*/
|
||||
@ -1029,14 +1040,6 @@ let UI = {
|
||||
}
|
||||
},
|
||||
|
||||
// -----------
|
||||
// Function: _reset
|
||||
// Wipes all TabView storage and refreshes, giving you the "first-run" state.
|
||||
_reset: function UI__reset() {
|
||||
Storage.wipe();
|
||||
location.href = "";
|
||||
},
|
||||
|
||||
// ----------
|
||||
// Function: storageSanity
|
||||
// Given storage data for this object, returns true if it looks valid.
|
||||
|
@ -58,6 +58,7 @@ _BROWSER_FILES = \
|
||||
browser_tabview_search.js \
|
||||
browser_tabview_snapping.js \
|
||||
browser_tabview_undo_group.js \
|
||||
browser_tabview_firstrun_pref.js \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_BROWSER_FILES)
|
||||
|
@ -0,0 +1,103 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Tab View first run (Bug 593157) test.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Michael Yoshitaka Erlewine <mitcho@mitcho.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
var prefsBranch = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefService).
|
||||
getBranch("browser.panorama.");
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
ok(!TabView.isVisible(), "Main window TabView is hidden");
|
||||
|
||||
prefsBranch.setBoolPref("experienced_first_run", false);
|
||||
ok(!experienced(), "not experienced");
|
||||
|
||||
newWindowWithTabView(checkFirstRun, part2);
|
||||
}
|
||||
|
||||
function experienced() {
|
||||
return prefsBranch.prefHasUserValue("experienced_first_run") &&
|
||||
prefsBranch.getBoolPref("experienced_first_run");
|
||||
}
|
||||
|
||||
function checkFirstRun(win) {
|
||||
let contentWindow = win.document.getElementById("tab-view").contentWindow;
|
||||
|
||||
let infoItems = contentWindow.iQ(".info-item");
|
||||
is(infoItems.length, 1, "There should be an info item");
|
||||
|
||||
let groupItems = contentWindow.GroupItems.groupItems;
|
||||
is(groupItems.length, 1, "There should be one group");
|
||||
|
||||
ok(experienced(), "we're now experienced");
|
||||
}
|
||||
|
||||
function part2() {
|
||||
newWindowWithTabView(checkNotFirstRun, endGame);
|
||||
}
|
||||
|
||||
function checkNotFirstRun(win) {
|
||||
let contentWindow = win.document.getElementById("tab-view").contentWindow;
|
||||
|
||||
let infoItems = contentWindow.iQ(".info-item");
|
||||
is(infoItems.length, 0, "There should be no info items");
|
||||
}
|
||||
|
||||
function endGame() {
|
||||
ok(!TabView.isVisible(), "Main window TabView is still hidden");
|
||||
finish();
|
||||
}
|
||||
|
||||
function newWindowWithTabView(callback, completeCallback) {
|
||||
let charsetArg = "charset=" + window.content.document.characterSet;
|
||||
let win = window.openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no,height=800,width=800",
|
||||
"about:blank", charsetArg, null, null, true);
|
||||
let onLoad = function() {
|
||||
win.removeEventListener("load", onLoad, false);
|
||||
let onShown = function() {
|
||||
win.removeEventListener("tabviewshown", onShown, false);
|
||||
callback(win);
|
||||
win.close();
|
||||
if (typeof completeCallback == "function")
|
||||
completeCallback();
|
||||
};
|
||||
win.addEventListener("tabviewshown", onShown, false);
|
||||
win.TabView.toggle();
|
||||
}
|
||||
win.addEventListener("load", onLoad, false);
|
||||
}
|
Loading…
Reference in New Issue
Block a user