michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: var StartUI = { michael@0: get startUI() { return document.getElementById("start-container"); }, michael@0: michael@0: get chromeWin() { michael@0: // XXX Not e10s friendly. We use this in a few places. michael@0: return Services.wm.getMostRecentWindow('navigator:browser'); michael@0: }, michael@0: michael@0: init: function init() { michael@0: this.startUI.addEventListener("click", this, false); michael@0: this.startUI.addEventListener("MozMousePixelScroll", this, false); michael@0: michael@0: // Update the input type on our local broadcaster michael@0: document.getElementById("bcast_preciseInput").setAttribute("input", michael@0: this.chromeWin.InputSourceHelper.isPrecise ? "precise" : "imprecise"); michael@0: michael@0: let firstRunCount = Services.prefs.getIntPref("browser.firstrun.count"); michael@0: if (firstRunCount > 0) { michael@0: document.loadOverlay("chrome://browser/content/FirstRunOverlay.xul", null); michael@0: Services.prefs.setIntPref("browser.firstrun.count", firstRunCount - 1); michael@0: } michael@0: michael@0: this._adjustDOMforViewState(this.chromeWin.ContentAreaObserver.viewstate); michael@0: michael@0: TopSitesStartView.init(); michael@0: BookmarksStartView.init(); michael@0: HistoryStartView.init(); michael@0: RemoteTabsStartView.init(); michael@0: michael@0: this.chromeWin.addEventListener("MozPrecisePointer", this, true); michael@0: this.chromeWin.addEventListener("MozImprecisePointer", this, true); michael@0: this.chromeWin.addEventListener("MozAfterPaint", this, true); michael@0: this.chromeWin.Elements.panelUI.addEventListener("ToolPanelHidden", this, false); michael@0: michael@0: Services.obs.addObserver(this, "metro_viewstate_changed", false); michael@0: }, michael@0: michael@0: uninit: function() { michael@0: if (TopSitesStartView) michael@0: TopSitesStartView.uninit(); michael@0: if (BookmarksStartView) michael@0: BookmarksStartView.uninit(); michael@0: if (HistoryStartView) michael@0: HistoryStartView.uninit(); michael@0: if (RemoteTabsStartView) michael@0: RemoteTabsStartView.uninit(); michael@0: michael@0: if (this.chromeWin) { michael@0: this.chromeWin.removeEventListener("MozPrecisePointer", this, true); michael@0: this.chromeWin.removeEventListener("MozImprecisePointer", this, true); michael@0: } michael@0: Services.obs.removeObserver(this, "metro_viewstate_changed"); michael@0: }, michael@0: michael@0: goToURI: function (aURI) { michael@0: this.chromeWin.BrowserUI.goToURI(aURI); michael@0: }, michael@0: michael@0: onClick: function onClick(aEvent) { michael@0: // If someone clicks / taps in empty grid space, take away michael@0: // focus from the nav bar edit so the soft keyboard will hide. michael@0: this.chromeWin.BrowserUI.blurNavBar(); michael@0: michael@0: if (aEvent.button == 0) { michael@0: this.chromeWin.ContextUI.dismissTabs(); michael@0: } michael@0: }, michael@0: michael@0: onNarrowTitleClick: function onNarrowTitleClick(sectionId) { michael@0: let section = document.getElementById(sectionId); michael@0: michael@0: if (section.hasAttribute("expanded")) michael@0: return; michael@0: michael@0: for (let expandedSection of this.startUI.querySelectorAll(".meta-section[expanded]")) michael@0: expandedSection.removeAttribute("expanded") michael@0: michael@0: section.setAttribute("expanded", "true"); michael@0: }, michael@0: michael@0: _adjustDOMforViewState: function(aState) { michael@0: document.getElementById("bcast_windowState").setAttribute("viewstate", aState); michael@0: }, michael@0: michael@0: handleEvent: function handleEvent(aEvent) { michael@0: switch (aEvent.type) { michael@0: case "MozPrecisePointer": michael@0: document.getElementById("bcast_preciseInput").setAttribute("input", "precise"); michael@0: break; michael@0: case "MozImprecisePointer": michael@0: document.getElementById("bcast_preciseInput").setAttribute("input", "imprecise"); michael@0: break; michael@0: case "click": michael@0: this.onClick(aEvent); michael@0: break; michael@0: case "MozMousePixelScroll": michael@0: let viewstate = this.startUI.getAttribute("viewstate"); michael@0: if (viewstate === "snapped" || viewstate === "portrait") { michael@0: window.scrollBy(0, aEvent.detail); michael@0: } else { michael@0: window.scrollBy(aEvent.detail, 0); michael@0: } michael@0: michael@0: aEvent.preventDefault(); michael@0: aEvent.stopPropagation(); michael@0: break; michael@0: case "ToolPanelHidden": michael@0: // After opening panel UI (console) set disableZoom again. michael@0: this.chromeWin.addEventListener("MozAfterPaint", this, true); michael@0: break; michael@0: michael@0: case "MozAfterPaint": michael@0: this._disableZoom(); michael@0: this.chromeWin.removeEventListener("MozAfterPaint", this, true); michael@0: break; michael@0: } michael@0: }, michael@0: michael@0: observe: function (aSubject, aTopic, aData) { michael@0: switch (aTopic) { michael@0: case "metro_viewstate_changed": michael@0: this._adjustDOMforViewState(aData); michael@0: break; michael@0: } michael@0: }, michael@0: michael@0: _disableZoom: function() { michael@0: let utils = Util.getWindowUtils(window); michael@0: let viewId; michael@0: try { michael@0: viewId = utils.getViewId(document.documentElement); michael@0: } catch(e) { michael@0: return; michael@0: } michael@0: michael@0: let presShellId = {}; michael@0: utils.getPresShellId(presShellId); michael@0: michael@0: let notificationData = [ michael@0: presShellId.value, michael@0: viewId].join(","); michael@0: michael@0: Services.obs.notifyObservers(null, "apzc-disable-zoom", notificationData); michael@0: } michael@0: };