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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     5 "use strict";
     7 Cu.import("resource://gre/modules/Services.jsm");
     9 var StartUI = {
    10   get startUI() { return document.getElementById("start-container"); },
    12   get chromeWin() {
    13     // XXX Not e10s friendly. We use this in a few places.
    14     return Services.wm.getMostRecentWindow('navigator:browser');
    15   },
    17   init: function init() {
    18     this.startUI.addEventListener("click", this, false);
    19     this.startUI.addEventListener("MozMousePixelScroll", this, false);
    21     // Update the input type on our local broadcaster
    22     document.getElementById("bcast_preciseInput").setAttribute("input",
    23       this.chromeWin.InputSourceHelper.isPrecise ? "precise" : "imprecise");
    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     }
    31     this._adjustDOMforViewState(this.chromeWin.ContentAreaObserver.viewstate);
    33     TopSitesStartView.init();
    34     BookmarksStartView.init();
    35     HistoryStartView.init();
    36     RemoteTabsStartView.init();
    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);
    43     Services.obs.addObserver(this, "metro_viewstate_changed", false);
    44   },
    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();
    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   },
    63   goToURI: function (aURI) {
    64     this.chromeWin.BrowserUI.goToURI(aURI);
    65   },
    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();
    72     if (aEvent.button == 0) {
    73       this.chromeWin.ContextUI.dismissTabs();
    74     }
    75   },
    77   onNarrowTitleClick: function onNarrowTitleClick(sectionId) {
    78     let section = document.getElementById(sectionId);
    80     if (section.hasAttribute("expanded"))
    81       return;
    83     for (let expandedSection of this.startUI.querySelectorAll(".meta-section[expanded]"))
    84       expandedSection.removeAttribute("expanded")
    86     section.setAttribute("expanded", "true");
    87   },
    89   _adjustDOMforViewState: function(aState) {
    90     document.getElementById("bcast_windowState").setAttribute("viewstate", aState);
    91   },
    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         }
   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;
   120       case "MozAfterPaint":
   121         this._disableZoom();
   122         this.chromeWin.removeEventListener("MozAfterPaint", this, true);
   123         break;
   124     }
   125   },
   127   observe: function (aSubject, aTopic, aData) {
   128     switch (aTopic) {
   129       case "metro_viewstate_changed":
   130         this._adjustDOMforViewState(aData);
   131         break;
   132     }
   133   },
   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     }
   144     let presShellId = {};
   145     utils.getPresShellId(presShellId);
   147     let notificationData = [
   148       presShellId.value,
   149       viewId].join(",");
   151     Services.obs.notifyObservers(null, "apzc-disable-zoom", notificationData);
   152   }
   153 };

mercurial