DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (47b55c578f95)

VCS Links

Line Code
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
<?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/. -->

<!DOCTYPE bindings>

<bindings id="groupBindings"
          xmlns="http://www.mozilla.org/xbl"
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
          xmlns:xbl="http://www.mozilla.org/xbl">

  <binding id="group" extends="chrome://global/content/bindings/richlistbox.xml#richlistitem">
    <content persist="closed" collapsed="true">
      <xul:image class="twisty"/>
      <xul:label flex="1" crop="end" xbl:inherits="value=name"/>
    </content>
    <implementation>
     <constructor>
      <![CDATA[
        if (this.hasAttribute("closed"))
          this.setAttribute("aria-expanded", "false");
        else
          this.setAttribute("aria-expanded", "true");
      ]]>
     </constructor>

     <!-- Takes as input two contact elements (imIContact type) and compares
          - their nicknames alphabetically (case insensitive). This method
          - behaves as a callback that Array.sort accepts as a parameter.
          -->
     <method name="sortComparator">
      <parameter name="aContactA"/>
      <parameter name="aContactB"/>
      <body>
      <![CDATA[
        if (aContactA.statusType != aContactB.statusType)
          return aContactB.statusType - aContactA.statusType;
        let a = aContactA.displayName.toLowerCase();
        let b = aContactB.displayName.toLowerCase();
        return a.localeCompare(b);
      ]]>
      </body>
     </method>

     <field name="contacts">[]</field>
     <field name="contactsById">({})</field>

     <method name="addContact">
      <parameter name="aContact"/>
      <parameter name="aTagName"/>
      <body>
      <![CDATA[
        if (this.contactsById.hasOwnProperty(aContact.id))
          return null;

        let contactElt = document.createElement(aTagName || "imcontact");
        if (this.hasAttribute("closed"))
          contactElt.setAttribute("collapsed", "true");

        let end = this.contacts.length;
        // Avoid the binary search loop if the contacts were already sorted.
        if (end != 0 &&
            this.sortComparator(aContact, this.contacts[end - 1].contact) < 0) {
          let start = 0;
          while (start < end) {
            let middle = start + Math.floor((end - start) / 2);
            if (this.sortComparator(aContact, this.contacts[middle].contact) < 0)
              end = middle;
            else
              start = middle + 1;
          }
        }
        let last = end == 0 ? this : this.contacts[end - 1];
        this.parentNode.insertBefore(contactElt, last.nextSibling);
        contactElt.build(aContact);//, this);
        contactElt.group = this;
        this.contacts.splice(end, 0, contactElt);
        this.contactsById[aContact.id] = contactElt;
        this.removeAttribute("collapsed");
        this._updateGroupLabel();
        return contactElt;
      ]]>
      </body>
     </method>

     <method name="updateContactPosition">
      <parameter name="aSubject"/>
      <body>
      <![CDATA[
        let contactElt = this.contactsById[aSubject.id];
        let index = this.contacts.indexOf(contactElt);
        if (index == -1) {
          // Sometimes we get a display-name-changed notification for
          // an offline contact, if it's not in the list, just ignore it.
          return;
        }
        // See if the position of the contact should be changed.
        if (index != 0 &&
            this.sortComparator(contactElt.contact, this.contacts[index - 1].contact) < 0 ||
            index != this.contacts.length - 1 &&
            this.sortComparator(contactElt.contact, this.contacts[index + 1].contact) > 0) {
          let oldItem = this.removeContact(aSubject);
          let newItem = this.addContact(aSubject);
          let list = this.parentNode;
          if (list.selectedItem == oldItem)
            list.selectedItem = newItem;
        }
      ]]>
      </body>
     </method>

     <method name="removeContact">
      <parameter name="aContact"/>
      <body>
      <![CDATA[
        let contact = this.contactsById[aContact.id];
        if (!contact)
          throw "Removing a contact that isn't here?";

        // create a new array to remove without breaking for each loops.
        this.contacts = this.contacts.filter(function(c) c !== contact);
        delete this.contactsById[contact.contact.id];

        contact.destroy();

        // Check if some contacts remain in the group, if empty hide it.
        if (!this.contacts.length)
          this.setAttribute("collapsed", "true");
        else
          this._updateGroupLabel();

        return contact;
      ]]>
      </body>
     </method>

     <method name="_updateClosedState">
      <parameter name="aClosed"/>
      <body>
      <![CDATA[
        for each (let contact in this.contacts)
          contact.collapsed = aClosed;
      ]]>
      </body>
     </method>

     <method name="close">
      <body>
      <![CDATA[
        if (this.hasAttribute("closed")) {
          this.removeAttribute("closed");
          this.setAttribute("aria-expanded", "true");
          this._updateClosedState(false);
        }
        else {
          this.setAttribute("closed", "true");
          this.setAttribute("aria-expanded", "false");
          this._updateClosedState(true);
        }

        this._updateGroupLabel();
      ]]>
      </body>
     </method>

     <field name="displayName"></field>
     <method name="_updateGroupLabel">
      <body>
      <![CDATA[
        if (!this.displayName)
          this.displayName = this.getAttribute("name");
        let name = this.displayName;
        if (this.hasAttribute("closed"))
          name += " (" + this.contacts.length + ")";

        this.setAttribute("name", name);
      ]]>
      </body>
     </method>

     <method name="keyPress">
      <parameter name="aEvent"/>
      <body>
      <![CDATA[
        switch (aEvent.keyCode) {
          case aEvent.DOM_VK_RETURN:
            this.close();
            break;

          case aEvent.DOM_VK_LEFT:
            if (!this.hasAttribute("closed"))
              this.close();
            break;

          case aEvent.DOM_VK_RIGHT:
            if (this.hasAttribute("closed"))
              this.close();
            break;
        }
      ]]>
      </body>
     </method>
    </implementation>
    <handlers>
     <handler event="click">
     <![CDATA[
        // Check if there was 1 click on the image or 2 clicks on the label
        if ((event.detail == 1 && event.originalTarget.localName == "image") ||
            (event.detail == 2 && event.originalTarget.localName == "label"))
          this.close();

        if (event.originalTarget.localName == "button")
          this.hide();
     ]]>
     </handler>
    </handlers>
  </binding>
</bindings>