root/trunk/chrome/content/common/bindings.xml

Revision 1754, 20.2 kB (checked in by MaierMan, 7 months ago)

New more "compatible" icons

Line 
1 <?xml version="1.0"?>
2 <!-- ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is DownThemAll
16  *
17  * The Initial Developer of the Original Code is Nils Maier
18  * Portions created by the Initial Developer are Copyright (C) 2007
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  *   Nils Maier <MaierMan@web.de>
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** -->
37 <!DOCTYPE bindings [
38   <!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd">
39   %globalDTD;
40   <!ENTITY % mirrorsDTD SYSTEM "chrome://dta/locale/mirrors.dtd">
41   %mirrorsDTD;
42 ]>
43
44 <bindings xmlns="http://www.mozilla.org/xbl" xmlns:xbl="http://www.mozilla.org/xbl"
45   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
46   <!-- closebox -->
47   <binding id="closebox"
48     extends="chrome://global/content/bindings/groupbox.xml#groupbox">
49     <content>
50       <xul:hbox class="groupbox-title" align="center" pack="start">
51         <children includes="caption" />
52       </xul:hbox>
53       <xul:box flex="1" class="childrenbox" xbl:inherits="orient,align,pack,collapsed=closed">
54         <children />
55       </xul:box>
56     </content>
57     <implementation implements="nsIAccessibleProvider">
58       <property name="closed">
59         <getter>
60           return this.getAttribute('closed') == 'true';
61         </getter>
62         <setter>
63           this.setAttribute('closed', val ? 'true' : 'false');
64         </setter>
65       </property>
66       <property name="shouldResize">
67         <getter>
68           return this.getAttribute('shouldResize') == 'true';
69         </getter>
70         <setter>
71           this.setAttribute('shouldResize', val ? 'true' : 'false');
72         </setter>
73       </property>
74       <property name="accessibleType" readonly="true">
75         <getter>
76           <![CDATA[
77             return Components.interfaces.nsIAccessibleProvider.XULGroupbox;
78           ]]>
79         </getter>
80       </property>
81     </implementation>
82   </binding>
83   <binding id="closebox-caption"
84     extends="chrome://global/content/bindings/groupbox.xml#caption">
85     <handlers>
86       <handler event="click">
87         this.parentNode.closed =
88         !this.parentNode.closed; if (this.parentNode.shouldResize) {
89         window.sizeToContent(); }
90       </handler>
91     </handlers>
92   </binding>
93
94   <binding id="saveddropdown">
95     <content>
96       <xul:menulist anonid="list" editable="true"
97         xbl:inherits="crop,readonly,disabled,flex,tooltiptext,oninput=onchange,onselect=onchange,error">
98         <xul:menupopup anonid="popup"
99           xbl:inherits="crop,onselect=onchange,oncommand=onchange" />
100       </xul:menulist>
101     </content>
102     <implementation>
103       <constructor><![CDATA[
104         try {
105           var hist = {};
106           Components.utils.import("resource://dta/historymanager.jsm", hist);
107           this.hist = hist.getHistory(this._pref, this.getAttribute('default'));         
108           this._load();
109         }
110         catch (ex) {
111           DTA.Debug.log("Loading of saveddropdown failed:", ex);
112         }
113       ]]></constructor>
114       <field name="modified">false</field>
115       <property name="_list"
116         onget="return document.getAnonymousElementByAttribute(this, 'anonid', 'list');" />
117       <property name="_popup"
118         onget="return document.getAnonymousElementByAttribute(this, 'anonid', 'popup');" />
119       <property name="_pref" onget="return this.getAttribute('preference')" />
120       <property name="_values">
121         <getter><![CDATA[
122           return this.hist.values;       
123         ]]></getter>
124       </property>
125       <property name="inputField" onget="return this._list.inputField" />
126       <property name="value" onget="return this._list.label">
127         <setter>
128           val = val.toString();
129           if (this.value == val) {
130             return;
131           }
132           this._list.label = val;
133           this._modified = true;
134         </setter>
135       </property>
136       <method name="_load">
137         <body><![CDATA[
138           var values = this._values;
139           var popup = this._popup;
140           
141           while (popup.hasChildNodes()) {
142             popup.removeChild(popup.lastChild);
143           }
144
145           for each (var val in values) {
146             var node = document.createElement('menuitem');
147             node.setAttribute('label', val);
148             if (this.hasAttribute('crop')) {
149               node.setAttribute('crop', this.getAttribute('crop'));
150             }
151             popup.appendChild(node);
152           }
153
154           if (values.length) {
155             this._list.selectedIndex = 0;
156             this.value = values[0];
157           }       
158           if (this.hasAttribute('readonly')) {
159             this._list.removeAttribute('editable');
160           }
161           this._modified = false;
162         ]]></body>
163       </method>
164       <method name="reload">
165         <body>this._load();</body>
166       </method>
167       <method name="save">
168         <body><![CDATA[
169           var n = this.value;
170           if ((!this.modified && this._list.selectedIndex == 0) || (n.length == 0 && !this.hasAttribute('allowempty'))) {
171             return;
172           }
173           this.hist.push(n);
174         ]]></body>
175       </method>
176       <method name="clear">
177         <body>
178           this.hist.reset();
179         </body>
180       </method>
181     </implementation>
182   </binding>
183
184   <binding id="metalinker-item"
185     extends="chrome://global/content/bindings/richlistbox.xml#richlistitem">
186     <content>
187       <xul:vbox flex="1">
188         <xul:hbox class="metalink-mainbox" flex="1">
189           <xul:image class="metalinker-icon" xbl:inherits="src=iconURL" />
190           <xul:vbox class="metalink-infobox" flex="1">
191             <xul:checkbox anonid="check" xbl:inherits="label=identity,checked" />
192             <xul:hbox flex="1" anonid="additionallinks" />
193             <xul:hbox>
194               <xul:description flex="1" crop="center"
195                 xbl:inherits="value=url" />
196             </xul:hbox>
197           </xul:vbox>
198           <xul:vbox class="metalinker-additional" anonid="additional" />
199         </xul:hbox>
200         <xul:description class="metalinker-description"
201           flex="1" anonid="desc" />
202       </xul:vbox>
203     </content>
204
205     <implementation>
206       <constructor><![CDATA[
207         var dl = this.download;
208         this.setAttribute('checked', dl.selected);
209         var id = '';
210         if (dl.identity) {
211           id = dl.identity + ' (' + dl.fileName + ')';
212         }
213         else {
214           id = dl.fileName;
215         }
216         this.setAttribute('identity', id);
217         this.setAttribute('iconURL', dl.logo ? dl.logo : getIcon(dl.url.usable, false, 32));
218         this.setAttribute('url', dl.url.usable);
219         
220         function addSimple(e) {
221           if (dl[e]) {
222             var n = document.createElement('description');
223             n.appendChild(document.createTextNode(_(e, [dl[e]])));
224             n.setAttribute('crop', 'end');
225             this._additional.appendChild(n);
226           }
227         };
228         function addLink(e) {
229           if (dl[e]) {
230             var n = document.createElement('description');
231             n.setAttribute('class', 'text-link');
232             n.setAttribute('onclick', 'Metalinker.openLink(this)');
233             n.setAttribute('crop', 'center');
234             n.setAttribute('flex', '1');
235             n.link = dl[e][1];             
236             n.appendChild(document.createTextNode(dl[e][0]));
237             this._additionalLinks.appendChild(n);
238           }
239         };
240         ['size', 'version', 'sys', 'lang', 'copyright', 'mirrors'].forEach(addSimple, this);
241         ['publisher', 'license'].forEach(addLink, this);
242         
243         if (dl.description) {
244           this._desc.appendChild(document.createTextNode(dl.description));
245         }
246       ]]></constructor>
247       <field name="_checkbox">document.getAnonymousElementByAttribute(this,
248         'anonid', 'check');</field>
249       <field name="_additional">document.getAnonymousElementByAttribute(this,
250         'anonid', 'additional');</field>
251       <field name="_additionalLinks">document.getAnonymousElementByAttribute(this,
252         'anonid', 'additionallinks');</field>
253       <field name="_desc">document.getAnonymousElementByAttribute(this,
254         'anonid', 'desc');</field>
255       <property name="checked" onget="return this._checkbox.checked;"
256         onset="this._checkbox.checked = !!val; return !!val;" />
257     </implementation>
258   </binding>
259
260   <binding id="hashinput">
261     <content>
262       <xul:hbox flex="1">
263         <xul:menulist anonid="type" readonly="true"
264           xbl:inherits="disabled,error">
265           <xul:menupopup anonid="types" />
266         </xul:menulist>
267         <xul:textbox anonid="hash" flex="1" xbl:inherits="readonly,disabled"
268           type="autocomplete" />
269       </xul:hbox>
270     </content>
271     <implementation>
272       <constructor><![CDATA[
273         this._typemap = {};
274         for (x in DTA.SUPPORTED_HASHES) {
275           var e = document.createElement('menuitem');
276           e.setAttribute('value', x);
277           e.setAttribute('label', x);
278           this._types.appendChild(e);
279           this._typemap[x] = e;
280         }     
281       ]]></constructor>
282       <property name="_type"
283         onget="return document.getAnonymousElementByAttribute(this, 'anonid', 'type');" />
284       <property name="_types"
285         onget="return document.getAnonymousElementByAttribute(this, 'anonid', 'types');" />
286       <property name="_hash"
287         onget="return document.getAnonymousElementByAttribute(this, 'anonid', 'hash');" />
288       <property name="checked" onget="return this._checkbox.checked;" />
289       <property name="inputField" onget="return this._hash.inputField;" />
290       <property name="isValid">
291         <getter><![CDATA[
292           try {
293             if (this._hash.value.length) {
294               new DTA.Hash(this._hash.value, this._type.value);
295             }
296             return true;
297           }
298           catch(ex) {
299             return false;
300           }
301         ]]></getter>
302       </property>
303       <property name="value">
304         <getter><![CDATA[
305           if (this._hash.value.length) {
306             return new DTA.Hash(this._hash.value, this._type.value);
307           }
308           return null;
309         ]]></getter>
310         <setter><![CDATA[
311           if (val) {
312             this._hash.value = val.sum;
313             this._type.selectedItem = this._typemap[val.type];
314           }
315           else {
316             this._hash.value = '';
317           }
318           return val;
319         ]]></setter>
320       </property>
321     </implementation>
322   </binding>
323
324   <binding id="menu-iconic-addressable"
325     extends="chrome://global/content/bindings/menu.xml#menu-base">
326     <content>
327       <xul:hbox class="menu-iconic-left" align="center" pack="center">
328         <xul:image class="menu-iconic-icon" xbl:inherits="src=image" />
329       </xul:hbox>
330       <xul:label class="menu-iconic-text" flex="1"
331         xbl:inherits="value=label,accesskey,crop" crop="right" />
332       <xul:hbox class="menu-accel-container" anonid="accel">
333         <xul:label class="menu-iconic-accel" xbl:inherits="value=acceltext" />
334       </xul:hbox>
335       <xul:hbox class="menu-right" chromedir="&locale.dir;"
336         xbl:inherits="_moz-menuactive,disabled" align="center" pack="center">
337         <xul:image />
338       </xul:hbox>
339       <children includes="menupopup|template" />
340     </content>
341   </binding>
342
343   <binding id="speed-limit-list-popup"
344     extends="chrome://global/content/bindings/popup.xml#popup-scrollbars">
345     <implementation>
346       <constructor><![CDATA[
347         this.limit = -1;
348         this.fill();
349       ]]></constructor>
350       <property name="hint">
351         <getter>
352           return this._hint || 0;
353         </getter>
354         <setter>
355           if (!isFinite(val)) {
356             throw new Error("Provide a valid number");
357           }
358           if (this._hint != val) {
359             this._hint = val;
360           }
361         </setter>
362       </property>
363       <property name="limit">
364         <getter>
365           return parseInt(this.parentNode.value) || -1;
366         </getter>
367         <setter><![CDATA[
368           if (!isFinite(val)) {
369             throw new Error("Provide a valid number");
370           }
371           if (this.parentNode.value != val) {
372             this.parentNode.value = val;
373             this.fill();
374           }
375         ]]></setter>
376       </property>
377       <property name="selectedItem">
378         <setter><![CDATA[
379           let pn = this.parentNode;
380           if (pn.localName == 'menulist') {
381             pn.selectedItem = val;
382           }
383           else {
384             val.setAttribute('checked', 'true');
385           }
386         ]]></setter>
387       </property>
388       <method name="appendItem">
389         <parameter name="label"/>
390         <parameter name="value"/>
391         <parameter name="description"/>
392         <body><![CDATA[
393           let item = document.createElement('menuitem');
394           item.setAttribute("label", label);
395           item.setAttribute("value", value);
396           if (description) {
397             item.setAttribute("description", description);
398           }
399           this.appendChild(item);
400           return item;
401         ]]></body>
402       </method>
403       <method name="fill">
404         <body><![CDATA[
405           function scale(e) e >= 1000 ? Math.round(e / 50) * 50 : (e >= 400 ? Math.round(e / 5) * 5 : e);
406
407           while (this.firstChild) {
408             this.removeChild(this.firstChild);
409           }
410           
411           let iv = Math.max(this.limit, -1);
412           let m = Math.round((iv > 0 ? iv : this.hint / 2) / 1024);
413           m = scale(iv > 1 ? m : 150);
414           let vals = [0,1,2,5,10,20,50];
415           if (m >= 1000) {
416             vals = [0,100,200,500,1000];
417           }
418           else if (m > 400) {
419             vals = [0,50,100,200,500];
420           }
421           
422           let items = [10, 50, 100, 250, 1000]; // always include these
423           for each (let v in vals) {
424             if (v && m - v > 1) {
425               items.push(m - v);
426             }
427             items.push(m + v);
428           }
429           items = items
430             .map(scale)
431             .filter(function(e) !((e in this) || (this[e] = null)), {}) // makes array unique
432             .sort(function(a, b) a - b);
433           let sep = document.createElement('menuseparator');
434           for each (let v in items.map(function(e) e * 1024)) {
435             let item = this.appendItem(Utils.formatKBytes(v, 0) + '/s', v);
436             if (v == iv) {
437               if (item.previousSibling) {
438                 this.insertBefore(sep.cloneNode(false), item);
439               }
440               this.selectedItem = item;
441               this.appendChild(sep.cloneNode(false));
442             }
443           }
444           this.appendChild(sep);
445           let item = this.appendItem(_('unlimitedspeed'), -1);
446           item.className = "menuitem-iconic";
447           if (iv == -1) {
448             this.selectedItem = item;
449           }
450           return true;
451         ]]></body>
452       </method>
453     </implementation>
454     <handlers>
455       <handler phase="capturing" event="popupshowing"><![CDATA[
456         this.fill();
457       ]]></handler>
458       <handler phase="capturing" event="command"><![CDATA[
459         this.parentNode.blur();
460         let nv = parseInt(event.originalTarget.value);
461         if (nv != this.limit) {
462           this.limit = nv;
463         }
464       ]]></handler>
465     </handlers>
466   </binding>
467  
468   <binding id="mirror-item-base" extends="chrome://global/content/bindings/richlistbox.xml#richlistitem">
469     <implementation>
470       <property name="mirror" onget="return this.getAttribute('mirror');" onset="this.setAttribute('mirror', nv);"/>
471       <property name="preference" onget="return parseInt(this.getAttribute('preference')) || 50;">
472         <setter><![CDATA[
473           val = parseInt(val);
474           if (isFinite(val)){
475             val = Math.min(200, Math.max(1, val));
476             this.setAttribute('preference', val);
477           }
478           val = this.preference;
479           let tt;
480           if (val > 130) {
481             tt = _("prefHigh", [val]);
482           }
483           else if (val > 80) {
484             tt = _("prefMedium", [val]);
485           }
486           else {
487             tt = _("prefLow", [val]);
488           }
489           this.setAttribute("_preftooltip", tt);
490         ]]></setter>
491       </property>
492       <property name="charset" onget="return this.getAttribute('charset');"/>
493     </implementation>
494   </binding>
495   <binding id="mirror-item" extends="chrome://dta/content/common/bindings.xml#mirror-item-base">
496     <content>
497       <xul:vbox>
498         <xul:hbox>
499           <xul:spacer flex="1" />
500           <xul:image class="mirror-item-icon" />
501           <xul:spacer flex="1" />
502         </xul:hbox>
503         <xul:label value="" class="mirror-item-error" xbl:inherits="value=error"/>
504       </xul:vbox>
505       <xul:hbox flex="1" align="center">
506         <xul:label anonid="mirror" flex="1" crop="center" class="mirror-item-url text-link" xbl:inherits="value=mirror" />
507       </xul:hbox>
508       <xul:hbox align="center">
509         <xul:label value="&preference;" />
510         <xul:scale anonid="preference" class="mirror-item-preference" min="1" max="200" increment="5" pageincrement="30" xbl:inherits="value=preference,tooltiptext=_preftooltip" />
511       </xul:hbox>
512     </content>
513     <implementation>
514       <field name="mirrorElement">document.getAnonymousElementByAttribute(this, 'anonid', 'mirror');</field>
515       <field name="preferenceElement">document.getAnonymousElementByAttribute(this, 'anonid', 'preference');</field>
516       <constructor><![CDATA[
517         // cheat to init
518         this.preference = this.getAttribute('preference');
519       ]]></constructor>
520     </implementation>
521     <handlers>
522       <handler event="click" clickcount="1"><![CDATA[
523         if (event.originalTarget == this.mirrorElement) {
524           this.setAttribute("editing", true);
525         }
526       ]]></handler>
527       <handler event="click" clickcount="2">
528         this.setAttribute("editing", true);
529       </handler>
530       <handler event="change"><![CDATA[
531         if (event.originalTarget == this.preferenceElement) {
532           this.preference = this.preferenceElement.value;
533         }
534       ]]></handler>
535     </handlers>
536   </binding>
537   <binding id="mirror-item-editing" extends="chrome://dta/content/common/bindings.xml#mirror-item-base">
538     <content>
539       <xul:vbox>
540         <xul:spacer flex="1" />
541         <xul:image class="mirror-item-icon" />
542         <xul:spacer flex="1" />
543       </xul:vbox>
544       <xul:hbox flex="1" align="center">
545         <xul:label value="&mirrorurl;" />
546         <xul:textbox class="mirror-item-textbox" xbl:inherits="value=mirror" type="autocomplete" wantreturns="true" autocompletesearch="history" completedefaultindex="true" flex="1"/>
547       </xul:hbox>
548     </content>
549     <implementation>
550       <field name="textbox">document.getAnonymousElementByAttribute(this, 'class', 'mirror-item-textbox');</field>
551       <constructor><![CDATA[
552         this.parentNode.selectedItem = this;
553         this.textbox.focus();
554         
555         // looks a little nasty, but else we will immediately blur/focus :p
556         let tp = this;
557         setTimeout(function() tp.textbox.addEventListener('blur', function() tp.commit(), false), 0);
558       ]]></constructor>
559       <method name="commit">
560         <parameter name="forget"/>
561         <body><![CDATA[
562           let original = this.getAttribute('mirror');
563           let uri = this.textbox.value;
564           
565           if (!!forget) {
566             uri = "";
567           }
568           
569           if (!!uri) {
570             let fs = Cc['@mozilla.org/docshell/urifixup;1'].getService(Ci.nsIURIFixup);
571             uri = fs.createFixupURI(uri, 0).spec;
572           }
573           if (!!uri) {
574             let evt = document.createEvent('MutationEvents');
575             evt.initMutationEvent('MirrorChanging', true, true, this, original, uri, 'mirror', evt.MODIFICATION);
576             if (this.dispatchEvent(evt)) {
577               this.setAttribute('mirror', uri);
578             }
579           }
580           try {
581             this.textbox.blur();
582           }
583           catch (ex) {}
584           this.removeAttribute('editing');
585           this.blur();
586           let evt = document.createEvent('UIEvents');
587           evt.initUIEvent('MirrorEditDone', true, true, null, 0);
588           this.dispatchEvent(evt);         
589         ]]></body>
590       </method>
591     </implementation>
592     <handlers>
593       <handler event="keydown" phase="capturing"><![CDATA[
594         switch(event.keyCode) {
595         case KeyEvent.DOM_VK_RETURN:
596         case KeyEvent.DOM_VK_ESCAPE:
597           event.stopPropagation();
598           event.preventDefault();
599           break;
600         }       
601       ]]></handler>
602       <handler event="keyup" phase="capturing"><![CDATA[
603         if (event.keyCode == KeyEvent.DOM_VK_RETURN) {
604           event.stopPropagation();
605           event.preventDefault();
606           this.commit();
607         }
608         if (event.keyCode == KeyEvent.DOM_VK_ESCAPE) {
609           event.stopPropagation();
610           event.preventDefault();
611           this.commit(true);
612           this.removeAttribute('editing');
613         }       
614       ]]></handler>
615     </handlers>
616   </binding>
617
618 </bindings>
619        
620    
Note: See TracBrowser for help on using the browser.