browser/metro/base/content/startui/StartUI.js

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

mercurial