browser/metro/base/content/bindings/dialog.xml

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/metro/base/content/bindings/dialog.xml	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,109 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<!-- This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +   - License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     1.8 +
     1.9 +<bindings
    1.10 +    xmlns="http://www.mozilla.org/xbl"
    1.11 +    xmlns:xbl="http://www.mozilla.org/xbl"
    1.12 +    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.13 +
    1.14 +  <binding id="dialog">
    1.15 +    <content xbl:inherits="orient, closebutton" flex="1">
    1.16 +      <children/>
    1.17 +    </content>
    1.18 +
    1.19 +    <implementation implements="nsIDOMEventListener">
    1.20 +      <field name="arguments"/>
    1.21 +      <field name="parent"/>
    1.22 +      <property name="_scrollbox" readonly="true" onget="return this.getElementsByTagName('scrollbox')[0];"/>
    1.23 +
    1.24 +      <constructor><![CDATA[
    1.25 +        this._closed = false;
    1.26 +        if (this.hasAttribute("script")) {
    1.27 +          try {
    1.28 +            Services.scriptloader.loadSubScript(this.getAttribute("script"), this);
    1.29 +          } catch(e) {
    1.30 +            throw("Dialog : Unable to load script : " + this.getAttribute("script") + "\n");
    1.31 +          }
    1.32 +        }
    1.33 +        window.addEventListener("unload", this, true);
    1.34 +
    1.35 +        let scrollbox = this._scrollbox;
    1.36 +        if (scrollbox) {
    1.37 +          window.addEventListener("resize", this, true);
    1.38 +          scrollbox.addEventListener("overflow", this, true);
    1.39 +        }
    1.40 +        setTimeout(this.load.bind(this), 0);
    1.41 +      ]]></constructor>
    1.42 +
    1.43 +      <method name="handleEvent">
    1.44 +        <parameter name="aEvent"/>
    1.45 +        <body><![CDATA[
    1.46 +          switch(aEvent.type) {
    1.47 +            case "unload":
    1.48 +              if (aEvent.originalTarget == document)
    1.49 +                this._removeDialog();
    1.50 +              break;
    1.51 +
    1.52 +            case "resize":
    1.53 +            case "overflow":
    1.54 +              let scrollbox = this._scrollbox;
    1.55 +              let style = document.defaultView.getComputedStyle(scrollbox, null);
    1.56 +              let newHeight =  Math.ceil(scrollbox.firstChild.getBoundingClientRect().height) + 
    1.57 +                               parseInt(style.marginTop) +
    1.58 +                               parseInt(style.marginBottom);
    1.59 +              scrollbox.style.minHeight = Math.min(window.innerHeight / 2, newHeight) + "px";
    1.60 +              break;
    1.61 +          }
    1.62 +        ]]></body>
    1.63 +      </method>
    1.64 +
    1.65 +      <method name="load">
    1.66 +        <body><![CDATA[
    1.67 +          if (this.hasAttribute("onload")) {
    1.68 +            let func = new Function(this.getAttribute("onload"));
    1.69 +            func.call(this);
    1.70 +          }
    1.71 +        ]]></body>
    1.72 +      </method>
    1.73 +
    1.74 +      <method name="close">
    1.75 +        <body><![CDATA[
    1.76 +          if (this.hasAttribute("onclose")) {
    1.77 +            let func = new Function(this.getAttribute("onclose"));
    1.78 +            func.call(this);
    1.79 +          }
    1.80 +          this._removeDialog();
    1.81 +        ]]></body>
    1.82 +      </method>
    1.83 +
    1.84 +      <method name="_removeDialog">
    1.85 +        <body><![CDATA[
    1.86 +          window.removeEventListener("unload", this, true);
    1.87 +          let scrollbox = this._scrollbox;
    1.88 +          if (scrollbox) {
    1.89 +            window.removeEventListener("resize", this, true);
    1.90 +            scrollbox.removeEventListener("overflow", this, true);
    1.91 +          }
    1.92 +
    1.93 +          this.parentNode.parentNode.removeChild(this.parentNode);
    1.94 +          this._closed = true;
    1.95 +
    1.96 +          // emit DOMModalDialogClosed event
    1.97 +          let event = document.createEvent("Events");
    1.98 +          event.initEvent("DOMModalDialogClosed", true, false);
    1.99 +          let dispatcher = this.parent || getBrowser();
   1.100 +          dispatcher.dispatchEvent(event);
   1.101 +        ]]></body>
   1.102 +      </method>
   1.103 +      
   1.104 +      <method name="waitForClose">
   1.105 +        <body><![CDATA[
   1.106 +          while (!this._closed)
   1.107 +            Services.tm.currentThread.processNextEvent(true);
   1.108 +        ]]></body>
   1.109 +      </method>
   1.110 +    </implementation>
   1.111 +  </binding>
   1.112 +</bindings>

mercurial