toolkit/content/widgets/progressmeter.xml

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/widgets/progressmeter.xml	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,116 @@
     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 +
    1.10 +<bindings id="progressmeterBindings"
    1.11 +   xmlns="http://www.mozilla.org/xbl"
    1.12 +   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.13 +   xmlns:xbl="http://www.mozilla.org/xbl">
    1.14 +
    1.15 +  <binding id="progressmeter" role="xul:progressmeter">
    1.16 +    <resources>
    1.17 +      <stylesheet src="chrome://global/skin/progressmeter.css"/>
    1.18 +    </resources>
    1.19 +
    1.20 +    <content>
    1.21 +      <xul:spacer class="progress-bar" xbl:inherits="mode"/>
    1.22 +      <xul:spacer class="progress-remainder" xbl:inherits="mode"/>
    1.23 +    </content>
    1.24 +    
    1.25 +    <implementation>
    1.26 +      <property name="mode" onset="if (this.mode != val) this.setAttribute('mode', val); return val;"
    1.27 +                            onget="return this.getAttribute('mode');"/>
    1.28 +
    1.29 +      <property name="value" onget="return this.getAttribute('value') || '0';">
    1.30 +        <setter><![CDATA[
    1.31 +          var p = Math.round(val);
    1.32 +          var max = Math.round(this.max);
    1.33 +          if (p < 0)
    1.34 +            p = 0;
    1.35 +          else if (p > max)
    1.36 +            p = max;
    1.37 +          var c = this.value; 
    1.38 +          if (p != c) {
    1.39 +            var delta = p - c;
    1.40 +            if (delta < 0)
    1.41 +              delta = -delta;
    1.42 +            if (delta > 3 || p == 0 || p == max) {
    1.43 +              this.setAttribute("value", p);
    1.44 +              // Fire DOM event so that accessible value change events occur
    1.45 +              var event = document.createEvent('Events');
    1.46 +              event.initEvent('ValueChange', true, true);
    1.47 +              this.dispatchEvent(event);
    1.48 +            }
    1.49 +          }
    1.50 +          
    1.51 +          return val;
    1.52 +        ]]></setter>
    1.53 +      </property>
    1.54 +      <property name="max"
    1.55 +                onget="return this.getAttribute('max') || '100';"
    1.56 +                onset="this.setAttribute('max', isNaN(val) ? 100 : Math.max(val, 1));
    1.57 +                       this.value = this.value;
    1.58 +                       return val;" />
    1.59 +    </implementation>
    1.60 +  </binding>
    1.61 +
    1.62 +  <binding id="progressmeter-undetermined"
    1.63 +           extends="chrome://global/content/bindings/progressmeter.xml#progressmeter">
    1.64 +    <content>
    1.65 +      <xul:stack class="progress-remainder" flex="1" anonid="stack" style="overflow: -moz-hidden-unscrollable;">
    1.66 +        <xul:spacer class="progress-bar" anonid="spacer" top="0" style="margin-right: -1000px;"/>
    1.67 +      </xul:stack>
    1.68 +    </content>
    1.69 +
    1.70 +    <implementation>
    1.71 +      <field name="_alive">true</field>
    1.72 +      <method name="_init">
    1.73 +        <body><![CDATA[
    1.74 +          var stack =
    1.75 +            document.getAnonymousElementByAttribute(this, "anonid", "stack");
    1.76 +          var spacer =
    1.77 +            document.getAnonymousElementByAttribute(this, "anonid", "spacer");
    1.78 +          var isLTR =
    1.79 +           document.defaultView.getComputedStyle(this, null).direction == "ltr";
    1.80 +          var startTime = window.mozAnimationStartTime;
    1.81 +          var self = this;
    1.82 +
    1.83 +          function nextStep(t) {
    1.84 +            try {
    1.85 +              var width = stack.boxObject.width;
    1.86 +              if (!width) {
    1.87 +                // Maybe we've been removed from the document.
    1.88 +                if (self._alive)
    1.89 +                  mozRequestAnimationFrame(nextStep);
    1.90 +                return;
    1.91 +              }
    1.92 +
    1.93 +              var elapsedTime = t - startTime;
    1.94 +
    1.95 +              // Width of chunk is 1/5 (determined by the ratio 2000:400) of the
    1.96 +              // total width of the progress bar. The left edge of the chunk
    1.97 +              // starts at -1 and moves all the way to 4. It covers the distance
    1.98 +              // in 2 seconds.
    1.99 +              var position = isLTR ? ((elapsedTime % 2000) / 400) - 1 :
   1.100 +                                     ((elapsedTime % 2000) / -400) + 4;
   1.101 +
   1.102 +              width = width >> 2;
   1.103 +              spacer.height = stack.boxObject.height;
   1.104 +              spacer.width = width;
   1.105 +              spacer.left = width * position;
   1.106 +
   1.107 +              mozRequestAnimationFrame(nextStep);
   1.108 +            } catch (e) {
   1.109 +            }
   1.110 +          }
   1.111 +          mozRequestAnimationFrame(nextStep);
   1.112 +        ]]></body>
   1.113 +      </method>
   1.114 +
   1.115 +      <constructor>this._init();</constructor>
   1.116 +    </implementation>
   1.117 +  </binding>
   1.118 +
   1.119 +</bindings>

mercurial