1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/metro/base/content/startui/StartUI.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,153 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +Cu.import("resource://gre/modules/Services.jsm"); 1.11 + 1.12 +var StartUI = { 1.13 + get startUI() { return document.getElementById("start-container"); }, 1.14 + 1.15 + get chromeWin() { 1.16 + // XXX Not e10s friendly. We use this in a few places. 1.17 + return Services.wm.getMostRecentWindow('navigator:browser'); 1.18 + }, 1.19 + 1.20 + init: function init() { 1.21 + this.startUI.addEventListener("click", this, false); 1.22 + this.startUI.addEventListener("MozMousePixelScroll", this, false); 1.23 + 1.24 + // Update the input type on our local broadcaster 1.25 + document.getElementById("bcast_preciseInput").setAttribute("input", 1.26 + this.chromeWin.InputSourceHelper.isPrecise ? "precise" : "imprecise"); 1.27 + 1.28 + let firstRunCount = Services.prefs.getIntPref("browser.firstrun.count"); 1.29 + if (firstRunCount > 0) { 1.30 + document.loadOverlay("chrome://browser/content/FirstRunOverlay.xul", null); 1.31 + Services.prefs.setIntPref("browser.firstrun.count", firstRunCount - 1); 1.32 + } 1.33 + 1.34 + this._adjustDOMforViewState(this.chromeWin.ContentAreaObserver.viewstate); 1.35 + 1.36 + TopSitesStartView.init(); 1.37 + BookmarksStartView.init(); 1.38 + HistoryStartView.init(); 1.39 + RemoteTabsStartView.init(); 1.40 + 1.41 + this.chromeWin.addEventListener("MozPrecisePointer", this, true); 1.42 + this.chromeWin.addEventListener("MozImprecisePointer", this, true); 1.43 + this.chromeWin.addEventListener("MozAfterPaint", this, true); 1.44 + this.chromeWin.Elements.panelUI.addEventListener("ToolPanelHidden", this, false); 1.45 + 1.46 + Services.obs.addObserver(this, "metro_viewstate_changed", false); 1.47 + }, 1.48 + 1.49 + uninit: function() { 1.50 + if (TopSitesStartView) 1.51 + TopSitesStartView.uninit(); 1.52 + if (BookmarksStartView) 1.53 + BookmarksStartView.uninit(); 1.54 + if (HistoryStartView) 1.55 + HistoryStartView.uninit(); 1.56 + if (RemoteTabsStartView) 1.57 + RemoteTabsStartView.uninit(); 1.58 + 1.59 + if (this.chromeWin) { 1.60 + this.chromeWin.removeEventListener("MozPrecisePointer", this, true); 1.61 + this.chromeWin.removeEventListener("MozImprecisePointer", this, true); 1.62 + } 1.63 + Services.obs.removeObserver(this, "metro_viewstate_changed"); 1.64 + }, 1.65 + 1.66 + goToURI: function (aURI) { 1.67 + this.chromeWin.BrowserUI.goToURI(aURI); 1.68 + }, 1.69 + 1.70 + onClick: function onClick(aEvent) { 1.71 + // If someone clicks / taps in empty grid space, take away 1.72 + // focus from the nav bar edit so the soft keyboard will hide. 1.73 + this.chromeWin.BrowserUI.blurNavBar(); 1.74 + 1.75 + if (aEvent.button == 0) { 1.76 + this.chromeWin.ContextUI.dismissTabs(); 1.77 + } 1.78 + }, 1.79 + 1.80 + onNarrowTitleClick: function onNarrowTitleClick(sectionId) { 1.81 + let section = document.getElementById(sectionId); 1.82 + 1.83 + if (section.hasAttribute("expanded")) 1.84 + return; 1.85 + 1.86 + for (let expandedSection of this.startUI.querySelectorAll(".meta-section[expanded]")) 1.87 + expandedSection.removeAttribute("expanded") 1.88 + 1.89 + section.setAttribute("expanded", "true"); 1.90 + }, 1.91 + 1.92 + _adjustDOMforViewState: function(aState) { 1.93 + document.getElementById("bcast_windowState").setAttribute("viewstate", aState); 1.94 + }, 1.95 + 1.96 + handleEvent: function handleEvent(aEvent) { 1.97 + switch (aEvent.type) { 1.98 + case "MozPrecisePointer": 1.99 + document.getElementById("bcast_preciseInput").setAttribute("input", "precise"); 1.100 + break; 1.101 + case "MozImprecisePointer": 1.102 + document.getElementById("bcast_preciseInput").setAttribute("input", "imprecise"); 1.103 + break; 1.104 + case "click": 1.105 + this.onClick(aEvent); 1.106 + break; 1.107 + case "MozMousePixelScroll": 1.108 + let viewstate = this.startUI.getAttribute("viewstate"); 1.109 + if (viewstate === "snapped" || viewstate === "portrait") { 1.110 + window.scrollBy(0, aEvent.detail); 1.111 + } else { 1.112 + window.scrollBy(aEvent.detail, 0); 1.113 + } 1.114 + 1.115 + aEvent.preventDefault(); 1.116 + aEvent.stopPropagation(); 1.117 + break; 1.118 + case "ToolPanelHidden": 1.119 + // After opening panel UI (console) set disableZoom again. 1.120 + this.chromeWin.addEventListener("MozAfterPaint", this, true); 1.121 + break; 1.122 + 1.123 + case "MozAfterPaint": 1.124 + this._disableZoom(); 1.125 + this.chromeWin.removeEventListener("MozAfterPaint", this, true); 1.126 + break; 1.127 + } 1.128 + }, 1.129 + 1.130 + observe: function (aSubject, aTopic, aData) { 1.131 + switch (aTopic) { 1.132 + case "metro_viewstate_changed": 1.133 + this._adjustDOMforViewState(aData); 1.134 + break; 1.135 + } 1.136 + }, 1.137 + 1.138 + _disableZoom: function() { 1.139 + let utils = Util.getWindowUtils(window); 1.140 + let viewId; 1.141 + try { 1.142 + viewId = utils.getViewId(document.documentElement); 1.143 + } catch(e) { 1.144 + return; 1.145 + } 1.146 + 1.147 + let presShellId = {}; 1.148 + utils.getPresShellId(presShellId); 1.149 + 1.150 + let notificationData = [ 1.151 + presShellId.value, 1.152 + viewId].join(","); 1.153 + 1.154 + Services.obs.notifyObservers(null, "apzc-disable-zoom", notificationData); 1.155 + } 1.156 +};