-
Notifications
You must be signed in to change notification settings - Fork 29
/
bindings.xml
131 lines (119 loc) · 5.7 KB
/
bindings.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?xml version="1.0"?>
<bindings xmlns="http://www.mozilla.org/xbl"
xmlns:xbl="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<!-- This is just a toolbarbutton, with a few added methods to make our lives a bit easier -->
<binding id="ttbutton" extends="chrome://global/content/bindings/toolbarbutton.xml#toolbarbutton">
<implementation>
<!-- remember to keep this up to date with changes to ttpinnedtab's structure below -->
<property name="tPos" readonly="true" onget="return this.parentNode.parentNode.tPos;"/>
</implementation>
</binding>
<!-- element representing a pinned tab; contains the toolbarbutton itself and
an image that can be overlaid on it to show e.g. sound is playing -->
<binding id="ttpinnedtab">
<content>
<children includes="observes|template|menupopup|panel|tooltip"/>
<xul:stack>
<xul:hbox anonid="titlechanged-placeholder" xbl:inherits="titlechanged" />
<xul:toolbarbutton anonid="button" class="tt-tab-button"
xbl:inherits="accesskey,autocheck,checkState,checked,command,crop,dir,disabled,dlgtype,group,image,label,oncommand,open,orient,tabindex,title,type,validate,titlechanged"/>
<xul:image anonid="overlay" class="tt-tab-overlay" xbl:inherits="tooltiptext=overlaytext,muted,soundplaying" top="0" end="0"/>
</xul:stack>
</content>
<implementation>
<property name="button" readonly="true" onget="return document.getAnonymousElementByAttribute(this, 'anonid', 'button');"/>
<property name="_overlay" readonly="true" onget="return document.getAnonymousElementByAttribute(this, 'anonid', 'overlay');"/>
<property name="checked" onget="return this.button.checked;" onset="this.button.checked = val;"/>
<property name="image" onget="return this.button.getAttribute('image');" onset="val ? this.button.setAttribute('image','val') : this.button.removeAttribute('image')"/>
<field name="_tab">null</field>
<property name="tab">
<getter><![CDATA[
if(this._tab == null) throw "ttpinnedtab.tab get without set";
return this._tab;
]]></getter>
<setter><![CDATA[
if (val.localName != 'tab') throw "invalid tab";
this._tab = val;
this.repaint();
return this._tab;
]]></setter>
</property>
<property name="_browser" readonly="true">
<getter><![CDATA[
if(this._tab == null) throw "ttpinnedtab.tab get without set";
return this._tab.parentNode.tabbrowser;
]]></getter>
</property>
<method name="repaint">
<body><![CDATA[
/* global ShortcutUtils */
let tab = this._tab;
this.setAttribute('tooltiptext', tab.label);
this.setAttribute('type', 'radio');
this.setAttribute('group', 'RadioGroup');
this.setAttribute('context', 'tabContextMenu');
this.checked = tab.selected;
if (tab.hasAttribute('progress') && tab.hasAttribute('busy')) {
this.setAttribute('image', 'chrome://global/skin/icons/loading.png');
} else if (this.tab.hasAttribute('busy')) {
this.setAttribute('image', 'chrome://browser/skin/tabbrowser/connecting.png');
} else {
// See bootstrap.js -> "view.getImageSrc" for more comments about the following line:
this.setAttribute('image', (tab.image ? tab.linkedBrowser.mIconURL + "#-moz-resolution=16,16" : "chrome://mozapps/skin/places/defaultFavicon.png"));
}
[
'titlechanged',
'muted',
'soundplaying',
].forEach((x) => {
if (tab.hasAttribute(x))
this.setAttribute(x, 'true');
else
this.removeAttribute(x);
});
// Taken from createTooltip() in chrome://browser/content/tabbrowser.xml
if (this.hasAttribute('muted') || this.hasAttribute('soundplaying')) {
let stringID = tab.linkedBrowser.audioMuted ?
"tabs.unmuteAudio.tooltip" :
"tabs.muteAudio.tooltip";
let key = document.getElementById("key_toggleMute");
let shortcut = ShortcutUtils.prettifyShortcut(key);
let label = this._browser.mStringBundle.getFormattedString(stringID, [shortcut]);
this.setAttribute('overlaytext', label);
} else {
this.removeAttribute('overlaytext');
}
]]></body>
</method>
<property name="tPos" readonly="true" onget="return this.tab._tPos;"/>
<property name="mOverOverlay" readonly="true">
<getter><![CDATA[
if(!this.hasAttribute("overlay")) return false;
return this._overlay && this._overlay.mozMatchesSelector(":hover");
]]></getter>
</property>
</implementation>
<handlers>
<handler event="command"><![CDATA[
if (this.tab) {
if (this.tab === this._browser.mCurrentTab) {
// Tab flip
if (Services.prefs.getBoolPref("extensions.tabtree.tab-flip")) {
let recentlyUsedTabs = Array.filter(this._browser.tabs, (tab) => !tab.closing).sort((tab1, tab2) => tab2.lastAccessed - tab1.lastAccessed);
this._browser.selectedTab = recentlyUsedTabs[0] === this._browser.mCurrentTab ? recentlyUsedTabs[1] : recentlyUsedTabs[0];
}
} else {
this._browser.selectTabAtIndex(this.tab._tPos);
}
}
]]></handler>
<handler event="click" button="0"><![CDATA[
if (event.originalTarget === this._overlay) {
event.stopPropagation();
this.tab.toggleMuteAudio();
}
]]></handler>
</handlers>
</binding>
</bindings>