Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 8 | |
michael@0 | 9 | var StartUI = { |
michael@0 | 10 | get startUI() { return document.getElementById("start-container"); }, |
michael@0 | 11 | |
michael@0 | 12 | get chromeWin() { |
michael@0 | 13 | // XXX Not e10s friendly. We use this in a few places. |
michael@0 | 14 | return Services.wm.getMostRecentWindow('navigator:browser'); |
michael@0 | 15 | }, |
michael@0 | 16 | |
michael@0 | 17 | init: function init() { |
michael@0 | 18 | this.startUI.addEventListener("click", this, false); |
michael@0 | 19 | this.startUI.addEventListener("MozMousePixelScroll", this, false); |
michael@0 | 20 | |
michael@0 | 21 | // Update the input type on our local broadcaster |
michael@0 | 22 | document.getElementById("bcast_preciseInput").setAttribute("input", |
michael@0 | 23 | this.chromeWin.InputSourceHelper.isPrecise ? "precise" : "imprecise"); |
michael@0 | 24 | |
michael@0 | 25 | let firstRunCount = Services.prefs.getIntPref("browser.firstrun.count"); |
michael@0 | 26 | if (firstRunCount > 0) { |
michael@0 | 27 | document.loadOverlay("chrome://browser/content/FirstRunOverlay.xul", null); |
michael@0 | 28 | Services.prefs.setIntPref("browser.firstrun.count", firstRunCount - 1); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | this._adjustDOMforViewState(this.chromeWin.ContentAreaObserver.viewstate); |
michael@0 | 32 | |
michael@0 | 33 | TopSitesStartView.init(); |
michael@0 | 34 | BookmarksStartView.init(); |
michael@0 | 35 | HistoryStartView.init(); |
michael@0 | 36 | RemoteTabsStartView.init(); |
michael@0 | 37 | |
michael@0 | 38 | this.chromeWin.addEventListener("MozPrecisePointer", this, true); |
michael@0 | 39 | this.chromeWin.addEventListener("MozImprecisePointer", this, true); |
michael@0 | 40 | this.chromeWin.addEventListener("MozAfterPaint", this, true); |
michael@0 | 41 | this.chromeWin.Elements.panelUI.addEventListener("ToolPanelHidden", this, false); |
michael@0 | 42 | |
michael@0 | 43 | Services.obs.addObserver(this, "metro_viewstate_changed", false); |
michael@0 | 44 | }, |
michael@0 | 45 | |
michael@0 | 46 | uninit: function() { |
michael@0 | 47 | if (TopSitesStartView) |
michael@0 | 48 | TopSitesStartView.uninit(); |
michael@0 | 49 | if (BookmarksStartView) |
michael@0 | 50 | BookmarksStartView.uninit(); |
michael@0 | 51 | if (HistoryStartView) |
michael@0 | 52 | HistoryStartView.uninit(); |
michael@0 | 53 | if (RemoteTabsStartView) |
michael@0 | 54 | RemoteTabsStartView.uninit(); |
michael@0 | 55 | |
michael@0 | 56 | if (this.chromeWin) { |
michael@0 | 57 | this.chromeWin.removeEventListener("MozPrecisePointer", this, true); |
michael@0 | 58 | this.chromeWin.removeEventListener("MozImprecisePointer", this, true); |
michael@0 | 59 | } |
michael@0 | 60 | Services.obs.removeObserver(this, "metro_viewstate_changed"); |
michael@0 | 61 | }, |
michael@0 | 62 | |
michael@0 | 63 | goToURI: function (aURI) { |
michael@0 | 64 | this.chromeWin.BrowserUI.goToURI(aURI); |
michael@0 | 65 | }, |
michael@0 | 66 | |
michael@0 | 67 | onClick: function onClick(aEvent) { |
michael@0 | 68 | // If someone clicks / taps in empty grid space, take away |
michael@0 | 69 | // focus from the nav bar edit so the soft keyboard will hide. |
michael@0 | 70 | this.chromeWin.BrowserUI.blurNavBar(); |
michael@0 | 71 | |
michael@0 | 72 | if (aEvent.button == 0) { |
michael@0 | 73 | this.chromeWin.ContextUI.dismissTabs(); |
michael@0 | 74 | } |
michael@0 | 75 | }, |
michael@0 | 76 | |
michael@0 | 77 | onNarrowTitleClick: function onNarrowTitleClick(sectionId) { |
michael@0 | 78 | let section = document.getElementById(sectionId); |
michael@0 | 79 | |
michael@0 | 80 | if (section.hasAttribute("expanded")) |
michael@0 | 81 | return; |
michael@0 | 82 | |
michael@0 | 83 | for (let expandedSection of this.startUI.querySelectorAll(".meta-section[expanded]")) |
michael@0 | 84 | expandedSection.removeAttribute("expanded") |
michael@0 | 85 | |
michael@0 | 86 | section.setAttribute("expanded", "true"); |
michael@0 | 87 | }, |
michael@0 | 88 | |
michael@0 | 89 | _adjustDOMforViewState: function(aState) { |
michael@0 | 90 | document.getElementById("bcast_windowState").setAttribute("viewstate", aState); |
michael@0 | 91 | }, |
michael@0 | 92 | |
michael@0 | 93 | handleEvent: function handleEvent(aEvent) { |
michael@0 | 94 | switch (aEvent.type) { |
michael@0 | 95 | case "MozPrecisePointer": |
michael@0 | 96 | document.getElementById("bcast_preciseInput").setAttribute("input", "precise"); |
michael@0 | 97 | break; |
michael@0 | 98 | case "MozImprecisePointer": |
michael@0 | 99 | document.getElementById("bcast_preciseInput").setAttribute("input", "imprecise"); |
michael@0 | 100 | break; |
michael@0 | 101 | case "click": |
michael@0 | 102 | this.onClick(aEvent); |
michael@0 | 103 | break; |
michael@0 | 104 | case "MozMousePixelScroll": |
michael@0 | 105 | let viewstate = this.startUI.getAttribute("viewstate"); |
michael@0 | 106 | if (viewstate === "snapped" || viewstate === "portrait") { |
michael@0 | 107 | window.scrollBy(0, aEvent.detail); |
michael@0 | 108 | } else { |
michael@0 | 109 | window.scrollBy(aEvent.detail, 0); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | aEvent.preventDefault(); |
michael@0 | 113 | aEvent.stopPropagation(); |
michael@0 | 114 | break; |
michael@0 | 115 | case "ToolPanelHidden": |
michael@0 | 116 | // After opening panel UI (console) set disableZoom again. |
michael@0 | 117 | this.chromeWin.addEventListener("MozAfterPaint", this, true); |
michael@0 | 118 | break; |
michael@0 | 119 | |
michael@0 | 120 | case "MozAfterPaint": |
michael@0 | 121 | this._disableZoom(); |
michael@0 | 122 | this.chromeWin.removeEventListener("MozAfterPaint", this, true); |
michael@0 | 123 | break; |
michael@0 | 124 | } |
michael@0 | 125 | }, |
michael@0 | 126 | |
michael@0 | 127 | observe: function (aSubject, aTopic, aData) { |
michael@0 | 128 | switch (aTopic) { |
michael@0 | 129 | case "metro_viewstate_changed": |
michael@0 | 130 | this._adjustDOMforViewState(aData); |
michael@0 | 131 | break; |
michael@0 | 132 | } |
michael@0 | 133 | }, |
michael@0 | 134 | |
michael@0 | 135 | _disableZoom: function() { |
michael@0 | 136 | let utils = Util.getWindowUtils(window); |
michael@0 | 137 | let viewId; |
michael@0 | 138 | try { |
michael@0 | 139 | viewId = utils.getViewId(document.documentElement); |
michael@0 | 140 | } catch(e) { |
michael@0 | 141 | return; |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | let presShellId = {}; |
michael@0 | 145 | utils.getPresShellId(presShellId); |
michael@0 | 146 | |
michael@0 | 147 | let notificationData = [ |
michael@0 | 148 | presShellId.value, |
michael@0 | 149 | viewId].join(","); |
michael@0 | 150 | |
michael@0 | 151 | Services.obs.notifyObservers(null, "apzc-disable-zoom", notificationData); |
michael@0 | 152 | } |
michael@0 | 153 | }; |