toolkit/content/widgets/progressmeter.xml

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <?xml version="1.0"?>
michael@0 2 <!-- This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 - License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
michael@0 5
michael@0 6
michael@0 7 <bindings id="progressmeterBindings"
michael@0 8 xmlns="http://www.mozilla.org/xbl"
michael@0 9 xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
michael@0 10 xmlns:xbl="http://www.mozilla.org/xbl">
michael@0 11
michael@0 12 <binding id="progressmeter" role="xul:progressmeter">
michael@0 13 <resources>
michael@0 14 <stylesheet src="chrome://global/skin/progressmeter.css"/>
michael@0 15 </resources>
michael@0 16
michael@0 17 <content>
michael@0 18 <xul:spacer class="progress-bar" xbl:inherits="mode"/>
michael@0 19 <xul:spacer class="progress-remainder" xbl:inherits="mode"/>
michael@0 20 </content>
michael@0 21
michael@0 22 <implementation>
michael@0 23 <property name="mode" onset="if (this.mode != val) this.setAttribute('mode', val); return val;"
michael@0 24 onget="return this.getAttribute('mode');"/>
michael@0 25
michael@0 26 <property name="value" onget="return this.getAttribute('value') || '0';">
michael@0 27 <setter><![CDATA[
michael@0 28 var p = Math.round(val);
michael@0 29 var max = Math.round(this.max);
michael@0 30 if (p < 0)
michael@0 31 p = 0;
michael@0 32 else if (p > max)
michael@0 33 p = max;
michael@0 34 var c = this.value;
michael@0 35 if (p != c) {
michael@0 36 var delta = p - c;
michael@0 37 if (delta < 0)
michael@0 38 delta = -delta;
michael@0 39 if (delta > 3 || p == 0 || p == max) {
michael@0 40 this.setAttribute("value", p);
michael@0 41 // Fire DOM event so that accessible value change events occur
michael@0 42 var event = document.createEvent('Events');
michael@0 43 event.initEvent('ValueChange', true, true);
michael@0 44 this.dispatchEvent(event);
michael@0 45 }
michael@0 46 }
michael@0 47
michael@0 48 return val;
michael@0 49 ]]></setter>
michael@0 50 </property>
michael@0 51 <property name="max"
michael@0 52 onget="return this.getAttribute('max') || '100';"
michael@0 53 onset="this.setAttribute('max', isNaN(val) ? 100 : Math.max(val, 1));
michael@0 54 this.value = this.value;
michael@0 55 return val;" />
michael@0 56 </implementation>
michael@0 57 </binding>
michael@0 58
michael@0 59 <binding id="progressmeter-undetermined"
michael@0 60 extends="chrome://global/content/bindings/progressmeter.xml#progressmeter">
michael@0 61 <content>
michael@0 62 <xul:stack class="progress-remainder" flex="1" anonid="stack" style="overflow: -moz-hidden-unscrollable;">
michael@0 63 <xul:spacer class="progress-bar" anonid="spacer" top="0" style="margin-right: -1000px;"/>
michael@0 64 </xul:stack>
michael@0 65 </content>
michael@0 66
michael@0 67 <implementation>
michael@0 68 <field name="_alive">true</field>
michael@0 69 <method name="_init">
michael@0 70 <body><![CDATA[
michael@0 71 var stack =
michael@0 72 document.getAnonymousElementByAttribute(this, "anonid", "stack");
michael@0 73 var spacer =
michael@0 74 document.getAnonymousElementByAttribute(this, "anonid", "spacer");
michael@0 75 var isLTR =
michael@0 76 document.defaultView.getComputedStyle(this, null).direction == "ltr";
michael@0 77 var startTime = window.mozAnimationStartTime;
michael@0 78 var self = this;
michael@0 79
michael@0 80 function nextStep(t) {
michael@0 81 try {
michael@0 82 var width = stack.boxObject.width;
michael@0 83 if (!width) {
michael@0 84 // Maybe we've been removed from the document.
michael@0 85 if (self._alive)
michael@0 86 mozRequestAnimationFrame(nextStep);
michael@0 87 return;
michael@0 88 }
michael@0 89
michael@0 90 var elapsedTime = t - startTime;
michael@0 91
michael@0 92 // Width of chunk is 1/5 (determined by the ratio 2000:400) of the
michael@0 93 // total width of the progress bar. The left edge of the chunk
michael@0 94 // starts at -1 and moves all the way to 4. It covers the distance
michael@0 95 // in 2 seconds.
michael@0 96 var position = isLTR ? ((elapsedTime % 2000) / 400) - 1 :
michael@0 97 ((elapsedTime % 2000) / -400) + 4;
michael@0 98
michael@0 99 width = width >> 2;
michael@0 100 spacer.height = stack.boxObject.height;
michael@0 101 spacer.width = width;
michael@0 102 spacer.left = width * position;
michael@0 103
michael@0 104 mozRequestAnimationFrame(nextStep);
michael@0 105 } catch (e) {
michael@0 106 }
michael@0 107 }
michael@0 108 mozRequestAnimationFrame(nextStep);
michael@0 109 ]]></body>
michael@0 110 </method>
michael@0 111
michael@0 112 <constructor>this._init();</constructor>
michael@0 113 </implementation>
michael@0 114 </binding>
michael@0 115
michael@0 116 </bindings>

mercurial