browser-customtitlebar.js (1955B)
1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- 2 * This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 var CustomTitlebar = { 7 init() { 8 this._readPref(); 9 Services.prefs.addObserver(this._prefName, this); 10 11 this._initialized = true; 12 this._update(); 13 }, 14 15 allowedBy(condition, allow) { 16 if (allow) { 17 if (condition in this._disallowed) { 18 delete this._disallowed[condition]; 19 this._update(); 20 } 21 } else if (!(condition in this._disallowed)) { 22 this._disallowed[condition] = null; 23 this._update(); 24 } 25 }, 26 27 get systemSupported() { 28 let isSupported = false; 29 switch (AppConstants.MOZ_WIDGET_TOOLKIT) { 30 case "windows": 31 case "cocoa": 32 isSupported = true; 33 break; 34 case "gtk": 35 isSupported = window.matchMedia("(-moz-gtk-csd-available)").matches; 36 break; 37 } 38 delete this.systemSupported; 39 return (this.systemSupported = isSupported); 40 }, 41 42 get enabled() { 43 return document.documentElement.hasAttribute("customtitlebar"); 44 }, 45 46 observe(subject, topic) { 47 if (topic == "nsPref:changed") { 48 this._readPref(); 49 } 50 }, 51 52 _initialized: false, 53 _disallowed: {}, 54 _prefName: "browser.tabs.inTitlebar", 55 56 _readPref() { 57 let hiddenTitlebar = Services.appinfo.drawInTitlebar; 58 this.allowedBy("pref", hiddenTitlebar); 59 }, 60 61 _update() { 62 if (!this._initialized) { 63 return; 64 } 65 66 let allowed = 67 this.systemSupported && 68 !window.fullScreen && 69 !Object.keys(this._disallowed).length; 70 71 document.documentElement.toggleAttribute("customtitlebar", allowed); 72 73 ToolbarIconColor.inferFromText("customtitlebar", allowed); 74 TabBarVisibility.update(true); 75 }, 76 77 uninit() { 78 Services.prefs.removeObserver(this._prefName, this); 79 }, 80 };