|
1 <?xml version="1.0"?> |
|
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 <bindings |
|
7 xmlns="http://www.mozilla.org/xbl" |
|
8 xmlns:xbl="http://www.mozilla.org/xbl" |
|
9 xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
10 |
|
11 <binding id="dialog"> |
|
12 <content xbl:inherits="orient, closebutton" flex="1"> |
|
13 <children/> |
|
14 </content> |
|
15 |
|
16 <implementation implements="nsIDOMEventListener"> |
|
17 <field name="arguments"/> |
|
18 <field name="parent"/> |
|
19 <property name="_scrollbox" readonly="true" onget="return this.getElementsByTagName('scrollbox')[0];"/> |
|
20 |
|
21 <constructor><![CDATA[ |
|
22 this._closed = false; |
|
23 if (this.hasAttribute("script")) { |
|
24 try { |
|
25 Services.scriptloader.loadSubScript(this.getAttribute("script"), this); |
|
26 } catch(e) { |
|
27 throw("Dialog : Unable to load script : " + this.getAttribute("script") + "\n"); |
|
28 } |
|
29 } |
|
30 window.addEventListener("unload", this, true); |
|
31 |
|
32 let scrollbox = this._scrollbox; |
|
33 if (scrollbox) { |
|
34 window.addEventListener("resize", this, true); |
|
35 scrollbox.addEventListener("overflow", this, true); |
|
36 } |
|
37 setTimeout(this.load.bind(this), 0); |
|
38 ]]></constructor> |
|
39 |
|
40 <method name="handleEvent"> |
|
41 <parameter name="aEvent"/> |
|
42 <body><![CDATA[ |
|
43 switch(aEvent.type) { |
|
44 case "unload": |
|
45 if (aEvent.originalTarget == document) |
|
46 this._removeDialog(); |
|
47 break; |
|
48 |
|
49 case "resize": |
|
50 case "overflow": |
|
51 let scrollbox = this._scrollbox; |
|
52 let style = document.defaultView.getComputedStyle(scrollbox, null); |
|
53 let newHeight = Math.ceil(scrollbox.firstChild.getBoundingClientRect().height) + |
|
54 parseInt(style.marginTop) + |
|
55 parseInt(style.marginBottom); |
|
56 scrollbox.style.minHeight = Math.min(window.innerHeight / 2, newHeight) + "px"; |
|
57 break; |
|
58 } |
|
59 ]]></body> |
|
60 </method> |
|
61 |
|
62 <method name="load"> |
|
63 <body><![CDATA[ |
|
64 if (this.hasAttribute("onload")) { |
|
65 let func = new Function(this.getAttribute("onload")); |
|
66 func.call(this); |
|
67 } |
|
68 ]]></body> |
|
69 </method> |
|
70 |
|
71 <method name="close"> |
|
72 <body><![CDATA[ |
|
73 if (this.hasAttribute("onclose")) { |
|
74 let func = new Function(this.getAttribute("onclose")); |
|
75 func.call(this); |
|
76 } |
|
77 this._removeDialog(); |
|
78 ]]></body> |
|
79 </method> |
|
80 |
|
81 <method name="_removeDialog"> |
|
82 <body><![CDATA[ |
|
83 window.removeEventListener("unload", this, true); |
|
84 let scrollbox = this._scrollbox; |
|
85 if (scrollbox) { |
|
86 window.removeEventListener("resize", this, true); |
|
87 scrollbox.removeEventListener("overflow", this, true); |
|
88 } |
|
89 |
|
90 this.parentNode.parentNode.removeChild(this.parentNode); |
|
91 this._closed = true; |
|
92 |
|
93 // emit DOMModalDialogClosed event |
|
94 let event = document.createEvent("Events"); |
|
95 event.initEvent("DOMModalDialogClosed", true, false); |
|
96 let dispatcher = this.parent || getBrowser(); |
|
97 dispatcher.dispatchEvent(event); |
|
98 ]]></body> |
|
99 </method> |
|
100 |
|
101 <method name="waitForClose"> |
|
102 <body><![CDATA[ |
|
103 while (!this._closed) |
|
104 Services.tm.currentThread.processNextEvent(true); |
|
105 ]]></body> |
|
106 </method> |
|
107 </implementation> |
|
108 </binding> |
|
109 </bindings> |