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 (920bcf17a9e1)

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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
<?xml version="1.0"?>

<!DOCTYPE bindings [
<!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd">
%globalDTD;
]>

<bindings id="placesBindings"
          xmlns="http://www.mozilla.org/xbl"
          xmlns:xbl="http://www.mozilla.org/xbl"
          xmlns:html="http://www.w3.org/1999/xhtml"
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  
  <binding id="command-button" extends="chrome://global/content/bindings/button.xml#button">
    <implementation>
      <method name="updateActiveView">
        <body><![CDATA[ 
          if (this.hasAttribute("view"))
            PlacesController.activeView = document.getElementById(this.getAttribute("view"));
        ]]></body>
      </method>
    </implementation>
    <handlers>
      <handler event="click" button="0" action="this.updateActiveView();"/>
      <handler event="keypress" keycode="VK_SPACE" action="this.updateActiveView();"/>
    </handlers>
  </binding>
  
  <binding id="filter-button" extends="chrome://global/content/bindings/button.xml#menu">
    <content>
      <xul:stack flex="1" class="box-inherit button-box">
        <xul:image class="button-icon" xbl:inherits="src=image"/>
        <xul:dropmarker class="button-menu-dropmarker" xbl:inherits="open,disabled"/>
      </xul:stack>
      <children includes="menupopup"/>
    </content>
    <handlers>
      <handler event="command"><![CDATA[
        PlacesSearchBox.filterCollection = event.target.getAttribute("value");
      ]]></handler>
    </handlers>
  </binding>

#ifdef PLACES_QUERY_BUILDER
  <binding id="calendar">
    <content>
      <xul:vbox class="calendar-box">
        <xul:hbox class="calendar-header">
          <xul:label anonid="prevmonth" class="calendar-month-jump">&#xab;</xul:label>
          <xul:label anonid="monthtitle" class="calendar-month-title" flex="1"/>
          <xul:label anonid="nextmonth" class="calendar-month-jump">&#xbb;</xul:label>
        </xul:hbox>
        <xul:tooltip anonid="calendartooltip">
          <!-- FIXME -->
        </xul:tooltip>
        <xul:grid anonid="calendargrid" class="calendar-grid">
         <xul:columns><xul:column flex="1"/><xul:column flex="1"/><xul:column flex="1"/><xul:column flex="1"/><xul:column flex="1"/><xul:column flex="1"/><xul:column flex="1"/></xul:columns>
          <xul:rows>
            <xul:row class="calendar-day-header">
              <xul:label anonid="calendarhead0"></xul:label>
              <xul:label anonid="calendarhead1"></xul:label>
              <xul:label anonid="calendarhead2"></xul:label>
              <xul:label anonid="calendarhead3"></xul:label>
              <xul:label anonid="calendarhead4"></xul:label>
              <xul:label anonid="calendarhead5"></xul:label>
              <xul:label anonid="calendarhead6"></xul:label>
            </xul:row>
            <!-- The "00" is so that the table has the correct dimensions (most
                 numbers are the same width) when it is first displayed. The
                 default definition for "calendar-day" should have the same color
                 fore- and background so you won't see this. -->
            <xul:row>
              <xul:label anonid="calendar0" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar1" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar2" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar3" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar4" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar5" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar6" class="calendar-day" tooltip="calendartooltip">00</xul:label>
            </xul:row>
            <xul:row>
              <xul:label anonid="calendar7" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar8" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar9" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar10" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar11" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar12" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar13" class="calendar-day" tooltip="calendartooltip">00</xul:label>
            </xul:row>
            <xul:row>
              <xul:label anonid="calendar14" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar15" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar16" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar17" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar18" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar19" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar20" class="calendar-day" tooltip="calendartooltip">00</xul:label>
            </xul:row>
            <xul:row>
              <xul:label anonid="calendar21" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar22" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar23" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar24" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar25" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar26" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar27" class="calendar-day" tooltip="calendartooltip">00</xul:label>
            </xul:row>
            <xul:row>
              <xul:label anonid="calendar28" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar29" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar30" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar31" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar32" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar33" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar34" class="calendar-day" tooltip="calendartooltip">00</xul:label>
            </xul:row>
            <xul:row>
              <xul:label anonid="calendar35" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar36" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar37" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar38" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar39" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar40" class="calendar-day" tooltip="calendartooltip">00</xul:label>
              <xul:label anonid="calendar41" class="calendar-day" tooltip="calendartooltip">00</xul:label>
            </xul:row>
          </xul:rows>
        </xul:grid>
      </xul:vbox>
    </content>
    <implementation>
      <constructor><![CDATA[
        var grid = document.getAnonymousElementByAttribute(this, "anonid",
                                                           "calendargrid");
        this._numCells = 42; // max number of cells displayable in the calendar
        this._cellPrefix = "calendar"; // value before the number in the ID of cells

        this._currentMonth = -1;
        this._currentYear = -1;
        this._cell0Date = null; // date for top left of calendar
        this._selectNothing = false;
        this._selectBegin = null;
        this._selectEnd = null;

        // localized stuff, FIXME: move somewhere else
        this._pref_firstDayOfWeek = 0; // 0 = Sunday, 1 = Monday
        this._pref_dayHeaders = ["S", "M", "T", "W", "T", "F", "S"];
        this._pref_shortMonthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
                            "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

        // day headers
        for (var i = 0; i < 7; i ++) {
          var cell = document.getAnonymousElementByAttribute(this, "anonid",
                                                             "calendarhead" + i);
          cell.value = this._pref_dayHeaders[i];
        }

        // cell item
        var calendargrid = document.getAnonymousElementByAttribute(this, "anonid", "calendargrid");
        this._days = new Array(this._numCells);
        this._selected = new Array(this._numCells);
        for (var i = 0; i < this._numCells; i ++) {
          this._days[i] = document.getAnonymousElementByAttribute(this, "anonid", this._cellPrefix + i);
          this._selected[i] = false;
        }

        // month navigation hooks
        var myself = this;
        document.getAnonymousElementByAttribute(this, "anonid", "prevmonth").
          addEventListener("click", function() { myself.jumpMonth(-1); }, false);
        document.getAnonymousElementByAttribute(this, "anonid", "nextmonth").
          addEventListener("click", function() { myself.jumpMonth(1); }, false);

        // day selection hooks
        calendargrid.addEventListener("mousedown", function(event) { myself.mouseDown(event); }, false);
        calendargrid.addEventListener("mouseup", function(event) { myself.mouseUp(event); }, false);
        calendargrid.addEventListener("mousemove", function(event) { myself.mouseMove(event); }, false);

        this.visibleMonth = new Date(); // today
      ]]></constructor>

      <property name="visibleMonth">
        <getter>
          return new Date(this._visibleMonth);
        </getter>
        <setter>
          this._visibleMonth = new Date(val.getFullYear(), val.getMonth(), 1);
          this.drawMonth();
        </setter>
      </property>

      <property name="beginrange">
        <getter>
          if (! this._selectBegin)
            return null;
          else
            return new Date(this._selectBegin);
        </getter>
        <setter>
          this._selectNothing = false;
          this._selectBegin = val;
          this.updateSelection(this._selectBegin, this._selectEnd);
          this.fireRangeEvent();
        </setter>
      </property>
      <property name="endrange">
        <getter>
          if (! this._selectEnd)
            return null;
          else
            return new Date(this._selectEnd);
        </getter>
        <setter>
          this._selectNothing = false;
          this._selectEnd = val;
          this.updateSelection(this._selectBegin, this._selectEnd);
          this.fireRangeEvent();
        </setter>
      </property>

      <!-- Use this to set the range at once. It will be more efficient than
           setting begin and end independently since there will be only one
           redraw. Set updateVisible to have the calendar change the active
           month if necessary. -->
      <method name="setRange">
        <parameter name="begin"/>
        <parameter name="end"/>
        <parameter name="updateVisible"/>
        <body><![CDATA[
          if (updateVisible && end) {
            // this just tries to make the end range visible. If there is no
            // end range, we don't do anything. We might want to set the visible
            // month to the begin range in this case, but I don't think this
            // situation arises in practice.
            var daysToEnd = this.daysBetweenDates(end, this._cell0Date);
            if (daysToEnd < 0 || daysToEnd >= this._numCells) {
              // reselect month for end range
              this.visibleMonth = end;
            }
          }
          this._selectNothing = false;
          this.updateSelection(begin, end);
          this.fireRangeEvent();
        ]]></body>
      </method>

      <!-- Normally, null begin and end means select all, so you can set
           this if you don't want anything selected.-->
      <property name="selectNothing">
        <getter>
          return this._selectNothing;
        </getter>
        <setter>
          this._selectNothing = val;
        </setter>
      </property>

      <!--===== jumpMonth =====-->
      <method name="jumpMonth">
        <parameter name="relative"/>
        <body><![CDATA[
          var newMonth = this._visibleMonth.getMonth() + relative;
          var newYear = this._visibleMonth.getFullYear() + Math.floor(newMonth / 12);
          newMonth = (newMonth + 12) % 12;
          this._visibleMonth = new Date(newYear, newMonth, 1);
          this.drawMonth();
        ]]></body>
      </method>

      <!--===== mouseDown =====-->
      <method name="mouseDown">
        <parameter name="event"/>
        <body><![CDATA[
          var date = this.cellToDate(event.target.getAttribute("anonid"));
          if (! date)
            return;
          this._selectNothing = false;
          this._dragging = true;
          this._mouseDownOn = date;
          this.updateSelection(date, date);
        ]]></body>
      </method>

      <!--===== mouseUp =====-->
      <method name="mouseUp">
        <parameter name="event"/>
        <body><![CDATA[
          this._dragging = false;
          this.fireRangeEvent();
        ]]></body>
      </method>

      <!--===== mouseMove =====-->
      <method name="mouseMove">
        <parameter name="event"/>
        <body><![CDATA[
          if (! this._dragging)
            return;
          var date = this.cellToDate(event.target.getAttribute("anonid"));
          if (! date)
            return;
          this.updateSelection(this._mouseDownOn, date);
        ]]></body>
      </method>

      <!--===== updateSelection =====-->
      <method name="updateSelection">
        <parameter name="begin"/>
        <parameter name="end"/>
        <body><![CDATA[
          var realBegin = begin;
          var realEnd = end;
          if (begin && end && begin.getTime() > end.getTime()) {
            this._selectBegin = end;
            this._selectEnd = begin;
          } else {
            this._selectBegin = begin;
            this._selectEnd = end;
          }
          this.drawSelection();
        ]]></body>
      </method>

      <!--===== daysBetweenDates =====-->
      <method name="daysBetweenDates">
        <parameter name="a"/>
        <parameter name="b"/>
        <body>
          var msDiff = a.getTime() - b.getTime();
          return Math.floor(msDiff / 86400000); // 1000ms/s * 60s/m * 60m/h * 24h/d = 86400000ms/d
        </body>
      </method>

      <!--===== suppressRangeEvents =====-->
      <field name="suppressRangeEvents">false</field>
      
      <!--===== fireRangeEvent =====-->
      <method name="fireRangeEvent"><body><![CDATA[
        if (this.suppressRangeEvents)
          return true;
        var event = document.createEvent("Events");
        event.initEvent("selectionchanged", false, true);

        // handle dom event handlers
        var noCancel = this.dispatchEvent(event);

        // handle any xml attribute event handlers
        var handler = this.getAttribute("onselectionchanged");
        if (handler != "") {
          var fn = new Function("event", handler);
          var returned = fn(event);
          if (returned == false)
            noCancel = false;
        }
        return noCancel;
      ]]></body></method>

      <!--===== drawSelection =====-->
      <method name="drawSelection"><body><![CDATA[
        var beginIndex;
        var endIndex;
        if (this._selectNothing) {
          beginIndex = -1;
          endIndex = -1;
        } else {
          if (! this._selectBegin) {
            beginIndex = 0;
          } else {
            beginIndex = this.daysBetweenDates(this._selectBegin, this._cell0Date);
          }
          if (! this._selectEnd) {
            endIndex = this._numCells - 1;
          } else {
            endIndex = this.daysBetweenDates(this._selectEnd, this._cell0Date);
          }
        }

        for (var i = 0; i < this._numCells; i ++) {
          var sel = (i >= beginIndex && i <= endIndex);
          if (sel != this._selected[i]) {
            this._days[i].setAttribute("selected", sel ? "true" : "");
            this._selected[i] = sel;
          }
        }
      ]]></body></method>

      <!--===== cellToDate =====-->
      <method name="cellToDate">
        <parameter name="cellName"/>
        <body><![CDATA[
          if (! cellName)
            return null;
          var tail = cellName.substring(this._cellPrefix.length);
          if (tail[0] < "0" || tail[0] > '9') {
            return null;
          }
          var cellNumber = Number(tail);
          var d = new Date(this._cell0Date);
          d.setDate(d.getDate() + cellNumber);
          return d;
        ]]></body>
      </method>

      <!--===== drawMonth =====-->
      <method name="drawMonth"><body><![CDATA[

        var curCell = 0;
        var monthIndex = this._visibleMonth.getMonth();
        var yearNumber = this._visibleMonth.getFullYear();
        var firstOfMonth = new Date(yearNumber, monthIndex, 1);

        // update title
        document.getAnonymousElementByAttribute(this, "anonid", "monthtitle").value =
          this._pref_shortMonthNames[monthIndex] + " " + yearNumber;

        // first, fill in any days of the previous month in the first week
        var numPrefixDays = firstOfMonth.getDay() - this._pref_firstDayOfWeek;
        var curDay = firstOfMonth;
        curDay.setDate(firstOfMonth.getDate() - numPrefixDays);
        this._cell0Date = new Date(curDay); // save the first cell
        for (var i = 0; i < numPrefixDays; i ++) {
          var cell = document.getAnonymousElementByAttribute(this, "anonid", this._cellPrefix + curCell);
          cell.setAttribute("month", "other");
          cell.value = curDay.getDate();
          curCell ++;
          curDay.setDate(curDay.getDate() + 1);
        }

        // now fill in the rest of this month
        while (curDay.getMonth() == monthIndex) {
          var cell = document.getAnonymousElementByAttribute(this, "anonid", this._cellPrefix + curCell);
          cell.setAttribute("month", "this");
          cell.value = curDay.getDate();
          curCell ++;
          curDay.setDate(curDay.getDate() + 1);
        }

        // fill out the end of this week with next month
        while (curDay.getDay() != this._pref_firstDayOfWeek) {
          var cell = document.getAnonymousElementByAttribute(this, "anonid", this._cellPrefix + curCell);
          cell.setAttribute("month", "other");
          cell.value = curDay.getDate();
          curCell ++;
          curDay.setDate(curDay.getDate() + 1);
        }

        // fill the bottom row with days from the next month
        while (curCell < this._numCells) {
          var cell = document.getAnonymousElementByAttribute(this, "anonid", this._cellPrefix + curCell);
          cell.setAttribute("month", "other");
          cell.value = curDay.getDate();
          curCell ++;
          curDay.setDate(curDay.getDate() + 1);
        }

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

    </implementation>
  </binding> <!-- end calendar -->
#endif
  
</bindings>