summaryrefslogtreecommitdiff
path: root/toolkit/components/bindings/content/filefield.xml
blob: f81761eb582c9d157b5224c8ea6ca4f49152b4b7 (plain)
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
<?xml version="1.0"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->


<bindings id="filefieldBindings"
          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">

  <binding id="filefield" extends="chrome://global/content/bindings/general.xml#basetext">
    <resources>
      <stylesheet src="chrome://global/skin/filefield.css"/>
    </resources>
    <content>
      <xul:stringbundle anonid="bundle" src="chrome://global/locale/filefield.properties"/>
      <xul:hbox class="fileFieldContentBox" align="center" flex="1" xbl:inherits="disabled">
        <xul:image class="fileFieldIcon" xbl:inherits="src=image,disabled"/>
        <xul:textbox class="fileFieldLabel" xbl:inherits="value=label,disabled,accesskey,tabindex,aria-labelledby" flex="1" readonly="true"/>
      </xul:hbox>
    </content>
    <implementation implements="nsIDOMXULLabeledControlElement">
      <property name="label" onget="return this.getAttribute('label');">
        <setter>
          this.setAttribute('label', val);
          var elt = document.getAnonymousElementByAttribute(this, "class", "fileFieldLabel");
          return (elt.value = val);
        </setter>
      </property>

      <field name="_file">null</field>
      <property name="file"  onget="return this._file">
        <setter>
        <![CDATA[
          this._file = val;
          if (val) {
            this.image = this._getIconURLForFile(val);
            this.label = this._getDisplayNameForFile(val);
          }
          else {
            this.removeAttribute("image");
            var bundle = document.getAnonymousElementByAttribute(this, "anonid", "bundle");
            this.label = bundle.getString("downloadHelperNoneSelected");
          }
          return val;
        ]]>
        </setter>
      </property>
      <method name="_getDisplayNameForFile">
        <parameter name="aFile"/>
        <body>
        <![CDATA[
          if (/Win/.test(navigator.platform)) {
            var lfw = aFile.QueryInterface(Components.interfaces.nsILocalFileWin);
            try {
              return lfw.getVersionInfoField("FileDescription");
            }
            catch (e) {
              // fall through to the filename
            }
          } else if (/Mac/.test(navigator.platform)) {
            var lfm = aFile.QueryInterface(Components.interfaces.nsILocalFileMac);
            try {
              return lfm.bundleDisplayName;
            }
            catch (e) {
              // fall through to the file name
            }
          }
          var ios = Components.classes["@mozilla.org/network/io-service;1"]
                              .getService(Components.interfaces.nsIIOService);
          var url = ios.newFileURI(aFile).QueryInterface(Components.interfaces.nsIURL);
          return url.fileName;
        ]]>
        </body>
      </method>

      <method name="_getIconURLForFile">
        <parameter name="aFile"/>
        <body>
        <![CDATA[
          if (!aFile)
            return "";
          var ios = Components.classes["@mozilla.org/network/io-service;1"]
                              .getService(Components.interfaces.nsIIOService);
          var fph = ios.getProtocolHandler("file")
                       .QueryInterface(Components.interfaces.nsIFileProtocolHandler);
          var urlspec = fph.getURLSpecFromFile(aFile);
          return "moz-icon://" + urlspec + "?size=16";
        ]]>
        </body>
      </method>
    </implementation>
  </binding>
</bindings>