File: scrollbox.xml

package info (click to toggle)
iceweasel 2.0.0.19-0etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 298,784 kB
  • ctags: 317,912
  • sloc: cpp: 1,796,902; ansic: 987,677; xml: 109,036; makefile: 47,777; asm: 35,201; perl: 26,983; sh: 20,879; cs: 6,232; java: 5,513; python: 3,249; pascal: 459; lex: 306; php: 244; csh: 132; objc: 97; yacc: 79; ada: 49; awk: 14; sql: 4; sed: 4
file content (311 lines) | stat: -rw-r--r-- 11,244 bytes parent folder | download | duplicates (4)
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
<?xml version="1.0"?>

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

<bindings id="arrowscrollboxBindings"
   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="scrollbox-base" extends="chrome://global/content/bindings/general.xml#basecontrol">
    <resources>
      <stylesheet src="chrome://global/skin/scrollbox.css"/>
    </resources>
  </binding>

  <binding id="scrollbox" extends="chrome://global/content/bindings/scrollbox.xml#scrollbox-base">
    <content>
      <xul:box class="box-inherit scrollbox-innerbox" xbl:inherits="orient,align,pack,dir" flex="1">
        <children/>
      </xul:box>
    </content>
  </binding>

  <binding id="arrowscrollbox" extends="chrome://global/content/bindings/scrollbox.xml#scrollbox-base">
    <content>
      <xul:autorepeatbutton class="autorepeatbutton-up"
                            anonid="scrollbutton-up"
                            collapsed="true"
                            xbl:inherits="orient"
                            oncommand="scrollByPixels(this.parentNode.scrollIncrement * -1); event.stopPropagation();"/>
      <xul:scrollbox xbl:inherits="orient,align,pack,dir" flex="1" anonid="scrollbox">
        <children/>
      </xul:scrollbox>
      <xul:autorepeatbutton class="autorepeatbutton-down"
                            anonid="scrollbutton-down"
                            collapsed="true"
                            xbl:inherits="orient"
                            oncommand="scrollByPixels(this.parentNode.scrollIncrement); event.stopPropagation();"/>
    </content>
    
    <implementation>
      <field name="_scrollbox">
        document.getAnonymousElementByAttribute(this, "anonid", "scrollbox");
      </field>
      <field name="_scrollButtonUp">
        document.getAnonymousElementByAttribute(this, "anonid", "scrollbutton-up");
      </field>
      <field name="_scrollButtonDown">
        document.getAnonymousElementByAttribute(this, "anonid", "scrollbutton-down");
      </field>

      <field name="_scrollIncrement">20</field>
      <property name="scrollIncrement" readonly="true">
        <getter><![CDATA[
          if (!this._scrollIncrement) {
            var pb2 =
              Components.classes['@mozilla.org/preferences-service;1']
                        .getService(Components.interfaces.nsIPrefBranch2);
            try {
              this._scrollIncrement = pb2.getIntPref("toolkit.scrollbox.scrollIncrement");
            }
            catch (ex) {
            }
          }
          return this._scrollIncrement;
        ]]></getter>
      </property>

      <field name="_scrollBoxObject">null</field>
      <property name="scrollBoxObject" readonly="true">
        <getter><![CDATA[
          if (!this._scrollBoxObject) {
            this._scrollBoxObject =
              this._scrollbox.boxObject
                             .QueryInterface(Components.interfaces.nsIScrollBoxObject);
          }
          return this._scrollBoxObject;
        ]]></getter>
      </property>

      <field name="_isLTRScrollbox">
        window.getComputedStyle(this._scrollbox, "").direction == "ltr";
      </field>

      <method name="ensureElementIsVisible">
        <parameter name="aElement"/>
        <body><![CDATA[
          this.scrollBoxObject.ensureElementIsVisible(aElement);
        ]]></body>
      </method>

      <method name="scrollByIndex">
        <parameter name="lines"/>
        <body><![CDATA[
          this.scrollBoxObject.scrollByIndex(lines);
        ]]></body>
      </method>

      <method name="scrollByPixels">
        <parameter name="px"/>
        <body><![CDATA[
          if (this.getAttribute("orient") == "horizontal") {
            // if not ltr, we want to scroll the other direction
            var actualPx = this._isLTRScrollbox ? px : (-1 * px);
            this.scrollBoxObject.scrollBy(actualPx, 0);
          }
          else
            this.scrollBoxObject.scrollBy(0, px);
        ]]></body>
      </method>

      <method name="_updateScrollButtonsDisabledState">
        <body><![CDATA[
          var disableUpButton = false;
          var disableDownButton = false;

          if (this.getAttribute("orient") == "horizontal") {
            var width = { };
            this.scrollBoxObject.getScrolledSize(width, {});
            var xPos = { }
            this.scrollBoxObject.getPosition(xPos, {});
            if (xPos.value == 0) {
              // In the RTL case, this means the _last_ element in the
              // scrollbox is visible
              if (this._isLTRScrollbox) 
                disableUpButton = true;
              else
                disableDownButton = true;
            }
            else if (this._scrollbox.boxObject.width + xPos.value == width.value) {
              // In the RTL case, this means the _first_ element in the
              // scrollbox is visible
              if (this._isLTRScrollbox)
                disableDownButton = true;
              else
                disableUpButton = true;
            }
          }
          else {  // vertical scrollbox
            var height = { };
            this.scrollBoxObject.getScrolledSize({}, height);
            var yPos = { }
            this.scrollBoxObject.getPosition({}, yPos);
            if (yPos.value == 0)
              disableUpButton = true;
            else if (this._scrollbox.boxObject.height + yPos.value == height.value)
              disableDownButton = true;
          }

          this._scrollButtonUp.disabled = disableUpButton;
          this._scrollButtonDown.disabled = disableDownButton;

          var event = document.createEvent("Events");
          event.initEvent("UpdatedScrollButtonsDisabledState", true, false);
          this.dispatchEvent(event);
        ]]></body>
      </method>
    </implementation>    

    <handlers>
      <handler event="DOMMouseScroll" action="this.scrollByIndex(event.detail); event.stopPropagation();"/>

      <handler event="underflow"><![CDATA[
        // filter underflow events which were dispatched on nested scrollboxes
        if (event.target != this)
          return;

        this._scrollButtonUp.collapsed = true;
        this._scrollButtonDown.collapsed = true;
        try {
          // See bug 341047 and comments in overflow handler as to why 
          // try..catch is needed here
          var childNodes = document.getAnonymousNodes(this._scrollbox);
          if (childNodes && childNodes.length) {
            if (childNodes.length > 0)
              this.ensureElementIsVisible(childNodes[0]);
          }
        }
        catch(e) {
          this._scrollButtonUp.collapsed = false;
          this._scrollButtonDown.collapsed = false;
        }
      ]]></handler>

      <handler event="overflow"><![CDATA[
        // filter underflow events which were dispatched on nested scrollboxes
        if (event.target != this)
          return;

        this._scrollButtonUp.collapsed = false;
        this._scrollButtonDown.collapsed = false;
        try {
          // See bug 341047, the overflow event is dispatched when the 
          // scrollbox already is mostly destroyed. This causes some code in
          // _updateScrollButtonsDisabledState() to throw an error. It also
          // means that the scrollbarbuttons were uncollapsed when that should
          // not be happening, because the whole overflow event should not be
          // happening in that case.
          this._updateScrollButtonsDisabledState();
        } 
        catch(e) {
          this._scrollButtonUp.collapsed = true;
          this._scrollButtonDown.collapsed = true;
        }
      ]]></handler>

      <handler event="scroll" action="this._updateScrollButtonsDisabledState()"/>
    </handlers>
  </binding>

  <binding id="autorepeatbutton" extends="chrome://global/content/bindings/scrollbox.xml#scrollbox-base">
    <content chromedir="&locale.dir;">
      <xul:image class="autorepeatbutton-icon"/>
    </content>
  </binding>

  <binding id="arrowscrollbox-clicktoscroll" extends="chrome://global/content/bindings/scrollbox.xml#arrowscrollbox">
    <content>
      <xul:toolbarbutton class="scrollbutton-up" collapsed="true"
                         xbl:inherits="orient"
                         anonid="scrollbutton-up"
                         onmousedown="_startScroll(-1);"
                         onmouseup="_stopScroll();"
                         onmouseout="_stopScroll();"
                         chromedir="&locale.dir;"/>
      <xul:scrollbox xbl:inherits="orient,align,pack,dir" flex="1" anonid="scrollbox">
        <children/>
      </xul:scrollbox>
      <xul:toolbarbutton class="scrollbutton-down" collapsed="true"
                         xbl:inherits="orient"
                         anonid="scrollbutton-down"
                         onmousedown="_startScroll(1);"
                         onmouseup="_stopScroll();"
                         onmouseout="_stopScroll();"
                         chromedir="&locale.dir;"/>
    </content>
    <implementation implements="nsITimerCallback">
      <constructor><![CDATA[
        var pb2 =
          Components.classes['@mozilla.org/preferences-service;1']
                    .getService(Components.interfaces.nsIPrefBranch2);
        try {
          this._scrollDelay = pb2.getIntPref("toolkit.scrollbox.clickToScroll.scrollDelay");
        }
        catch (ex) {
        }
      ]]></constructor>

      <destructor><![CDATA[
        // Release timer to avoid reference cycles.
        if (this._scrollTimer) {
          this._scrollTimer.cancel();
          this._scrollTimer = null;
        }
      ]]></destructor>

      <field name="_scrollTimer">null</field>
      <field name="_scrollLines">0</field>
      <field name="_scrollDelay">150</field>

      <method name="notify">
        <parameter name="aTimer"/>
        <body>
        <![CDATA[
          if (!document)
            aTimer.cancel();
          
          this.scrollByIndex(this._scrollLines);
        ]]>
        </body>
      </method>

      <method name="_setUpScrollTimer">
        <body>
        <![CDATA[
          if (!this._scrollTimer) 
            this._scrollTimer = 
              Components.classes["@mozilla.org/timer;1"]
                        .createInstance(Components.interfaces.nsITimer);
          else
             this._scrollTimer.cancel();

          this._scrollTimer.initWithCallback(this, 
                        this._scrollDelay,
                        Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
        ]]>
        </body>
      </method>

      <method name="_startScroll">
        <parameter name="aScrollLines"/>
        <body><![CDATA[
          this._scrollLines = aScrollLines;
          this.scrollByIndex(this._scrollLines);
          this._setUpScrollTimer();
        ]]></body>
      </method>            

      <method name="_stopScroll">
        <body><![CDATA[
          if (this._scrollTimer) 
            this._scrollTimer.cancel();
        ]]></body>
      </method>            

    </implementation>
  </binding>
</bindings>