toolkit/content/widgets/colorpicker.xml

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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="colorpickerBindings"
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="colorpicker" extends="chrome://global/content/bindings/general.xml#basecontrol">
michael@0 13 <resources>
michael@0 14 <stylesheet src="chrome://global/skin/colorpicker.css"/>
michael@0 15 </resources>
michael@0 16
michael@0 17 <content>
michael@0 18 <xul:vbox flex="1">
michael@0 19
michael@0 20 <xul:hbox>
michael@0 21 <xul:spacer class="colorpickertile cp-light" style="background-color: #FFFFFF" color="#FFFFFF"/>
michael@0 22 <xul:spacer class="colorpickertile cp-light" style="background-color: #FFCCCC" color="#FFCCCC"/>
michael@0 23 <xul:spacer class="colorpickertile cp-light" style="background-color: #FFCC99" color="#FFCC99"/>
michael@0 24 <xul:spacer class="colorpickertile cp-light" style="background-color: #FFFF99" color="#FFFF99"/>
michael@0 25 <xul:spacer class="colorpickertile cp-light" style="background-color: #FFFFCC" color="#FFFFCC"/>
michael@0 26 <xul:spacer class="colorpickertile cp-light" style="background-color: #99FF99" color="#99FF99"/>
michael@0 27 <xul:spacer class="colorpickertile cp-light" style="background-color: #99FFFF" color="#99FFFF"/>
michael@0 28 <xul:spacer class="colorpickertile cp-light" style="background-color: #CCFFFF" color="#CCFFFF"/>
michael@0 29 <xul:spacer class="colorpickertile cp-light" style="background-color: #CCCCFF" color="#CCCCFF"/>
michael@0 30 <xul:spacer class="colorpickertile cp-light" style="background-color: #FFCCFF" color="#FFCCFF"/>
michael@0 31 </xul:hbox>
michael@0 32 <xul:hbox>
michael@0 33 <xul:spacer class="colorpickertile" style="background-color: #CCCCCC" color="#CCCCCC"/>
michael@0 34 <xul:spacer class="colorpickertile" style="background-color: #FF6666" color="#FF6666"/>
michael@0 35 <xul:spacer class="colorpickertile" style="background-color: #FF9966" color="#FF9966"/>
michael@0 36 <xul:spacer class="colorpickertile cp-light" style="background-color: #FFFF66" color="#FFFF66"/>
michael@0 37 <xul:spacer class="colorpickertile cp-light" style="background-color: #FFFF33" color="#FFFF33"/>
michael@0 38 <xul:spacer class="colorpickertile cp-light" style="background-color: #66FF99" color="#66FF99"/>
michael@0 39 <xul:spacer class="colorpickertile cp-light" style="background-color: #33FFFF" color="#33FFFF"/>
michael@0 40 <xul:spacer class="colorpickertile cp-light" style="background-color: #66FFFF" color="#66FFFF"/>
michael@0 41 <xul:spacer class="colorpickertile" style="background-color: #9999FF" color="#9999FF"/>
michael@0 42 <xul:spacer class="colorpickertile" style="background-color: #FF99FF" color="#FF99FF"/>
michael@0 43 </xul:hbox>
michael@0 44 <xul:hbox>
michael@0 45 <xul:spacer class="colorpickertile" style="background-color: #C0C0C0" color="#C0C0C0"/>
michael@0 46 <xul:spacer class="colorpickertile" style="background-color: #FF0000" color="#FF0000"/>
michael@0 47 <xul:spacer class="colorpickertile" style="background-color: #FF9900" color="#FF9900"/>
michael@0 48 <xul:spacer class="colorpickertile" style="background-color: #FFCC66" color="#FFCC66"/>
michael@0 49 <xul:spacer class="colorpickertile cp-light" style="background-color: #FFFF00" color="#FFFF00"/>
michael@0 50 <xul:spacer class="colorpickertile cp-light" style="background-color: #33FF33" color="#33FF33"/>
michael@0 51 <xul:spacer class="colorpickertile" style="background-color: #66CCCC" color="#66CCCC"/>
michael@0 52 <xul:spacer class="colorpickertile" style="background-color: #33CCFF" color="#33CCFF"/>
michael@0 53 <xul:spacer class="colorpickertile" style="background-color: #6666CC" color="#6666CC"/>
michael@0 54 <xul:spacer class="colorpickertile" style="background-color: #CC66CC" color="#CC66CC"/>
michael@0 55 </xul:hbox>
michael@0 56 <xul:hbox>
michael@0 57 <xul:spacer class="colorpickertile" style="background-color: #999999" color="#999999"/>
michael@0 58 <xul:spacer class="colorpickertile" style="background-color: #CC0000" color="#CC0000"/>
michael@0 59 <xul:spacer class="colorpickertile" style="background-color: #FF6600" color="#FF6600"/>
michael@0 60 <xul:spacer class="colorpickertile" style="background-color: #FFCC33" color="#FFCC33"/>
michael@0 61 <xul:spacer class="colorpickertile" style="background-color: #FFCC00" color="#FFCC00"/>
michael@0 62 <xul:spacer class="colorpickertile" style="background-color: #33CC00" color="#33CC00"/>
michael@0 63 <xul:spacer class="colorpickertile" style="background-color: #00CCCC" color="#00CCCC"/>
michael@0 64 <xul:spacer class="colorpickertile" style="background-color: #3366FF" color="#3366FF"/>
michael@0 65 <xul:spacer class="colorpickertile" style="background-color: #6633FF" color="#6633FF"/>
michael@0 66 <xul:spacer class="colorpickertile" style="background-color: #CC33CC" color="#CC33CC"/>
michael@0 67 </xul:hbox>
michael@0 68 <xul:hbox>
michael@0 69 <xul:spacer class="colorpickertile" style="background-color: #666666" color="#666666"/>
michael@0 70 <xul:spacer class="colorpickertile" style="background-color: #990000" color="#990000"/>
michael@0 71 <xul:spacer class="colorpickertile" style="background-color: #CC6600" color="#CC6600"/>
michael@0 72 <xul:spacer class="colorpickertile" style="background-color: #CC9933" color="#CC9933"/>
michael@0 73 <xul:spacer class="colorpickertile" style="background-color: #999900" color="#999900"/>
michael@0 74 <xul:spacer class="colorpickertile" style="background-color: #009900" color="#009900"/>
michael@0 75 <xul:spacer class="colorpickertile" style="background-color: #339999" color="#339999"/>
michael@0 76 <xul:spacer class="colorpickertile" style="background-color: #3333FF" color="#3333FF"/>
michael@0 77 <xul:spacer class="colorpickertile" style="background-color: #6600CC" color="#6600CC"/>
michael@0 78 <xul:spacer class="colorpickertile" style="background-color: #993399" color="#993399"/>
michael@0 79 </xul:hbox>
michael@0 80 <xul:hbox>
michael@0 81 <xul:spacer class="colorpickertile" style="background-color: #333333" color="#333333"/>
michael@0 82 <xul:spacer class="colorpickertile" style="background-color: #660000" color="#660000"/>
michael@0 83 <xul:spacer class="colorpickertile" style="background-color: #993300" color="#993300"/>
michael@0 84 <xul:spacer class="colorpickertile" style="background-color: #996633" color="#996633"/>
michael@0 85 <xul:spacer class="colorpickertile" style="background-color: #666600" color="#666600"/>
michael@0 86 <xul:spacer class="colorpickertile" style="background-color: #006600" color="#006600"/>
michael@0 87 <xul:spacer class="colorpickertile" style="background-color: #336666" color="#336666"/>
michael@0 88 <xul:spacer class="colorpickertile" style="background-color: #000099" color="#000099"/>
michael@0 89 <xul:spacer class="colorpickertile" style="background-color: #333399" color="#333399"/>
michael@0 90 <xul:spacer class="colorpickertile" style="background-color: #663366" color="#663366"/>
michael@0 91 </xul:hbox>
michael@0 92 <xul:hbox>
michael@0 93 <xul:spacer class="colorpickertile" style="background-color: #000000" color="#000000"/>
michael@0 94 <xul:spacer class="colorpickertile" style="background-color: #330000" color="#330000"/>
michael@0 95 <xul:spacer class="colorpickertile" style="background-color: #663300" color="#663300"/>
michael@0 96 <xul:spacer class="colorpickertile" style="background-color: #663333" color="#663333"/>
michael@0 97 <xul:spacer class="colorpickertile" style="background-color: #333300" color="#333300"/>
michael@0 98 <xul:spacer class="colorpickertile" style="background-color: #003300" color="#003300"/>
michael@0 99 <xul:spacer class="colorpickertile" style="background-color: #003333" color="#003333"/>
michael@0 100 <xul:spacer class="colorpickertile" style="background-color: #000066" color="#000066"/>
michael@0 101 <xul:spacer class="colorpickertile" style="background-color: #330099" color="#330099"/>
michael@0 102 <xul:spacer class="colorpickertile" style="background-color: #330033" color="#330033"/>
michael@0 103 </xul:hbox>
michael@0 104 </xul:vbox>
michael@0 105 <!-- Something to take tab focus
michael@0 106 <button style="border : 0px; width: 0px; height: 0px;"/>
michael@0 107 -->
michael@0 108 </content>
michael@0 109
michael@0 110 <implementation implements="nsIDOMEventListener">
michael@0 111 <property name="color">
michael@0 112 <getter><![CDATA[
michael@0 113 return this.mSelectedCell ? this.mSelectedCell.getAttribute("color") : null;
michael@0 114 ]]></getter>
michael@0 115 <setter><![CDATA[
michael@0 116 if (!val)
michael@0 117 return val;
michael@0 118 var uppercaseVal = val.toUpperCase();
michael@0 119 // Translate standard HTML color strings:
michael@0 120 if (uppercaseVal[0] != "#") {
michael@0 121 switch (uppercaseVal) {
michael@0 122 case "GREEN":
michael@0 123 uppercaseVal = "#008000";
michael@0 124 break;
michael@0 125 case "LIME":
michael@0 126 uppercaseVal = "#00FF00";
michael@0 127 break;
michael@0 128 case "OLIVE":
michael@0 129 uppercaseVal = "#808000";
michael@0 130 break;
michael@0 131 case "TEAL":
michael@0 132 uppercaseVal = "#008080";
michael@0 133 break;
michael@0 134 case "YELLOW":
michael@0 135 uppercaseVal = "#FFFF00";
michael@0 136 break;
michael@0 137 case "RED":
michael@0 138 uppercaseVal = "#FF0000";
michael@0 139 break;
michael@0 140 case "MAROON":
michael@0 141 uppercaseVal = "#800000";
michael@0 142 break;
michael@0 143 case "PURPLE":
michael@0 144 uppercaseVal = "#800080";
michael@0 145 break;
michael@0 146 case "FUCHSIA":
michael@0 147 uppercaseVal = "#FF00FF";
michael@0 148 break;
michael@0 149 case "NAVY":
michael@0 150 uppercaseVal = "#000080";
michael@0 151 break;
michael@0 152 case "BLUE":
michael@0 153 uppercaseVal = "#0000FF";
michael@0 154 break;
michael@0 155 case "AQUA":
michael@0 156 uppercaseVal = "#00FFFF";
michael@0 157 break;
michael@0 158 case "WHITE":
michael@0 159 uppercaseVal = "#FFFFFF";
michael@0 160 break;
michael@0 161 case "SILVER":
michael@0 162 uppercaseVal = "#C0C0C0";
michael@0 163 break;
michael@0 164 case "GRAY":
michael@0 165 uppercaseVal = "#808080";
michael@0 166 break;
michael@0 167 default: // BLACK
michael@0 168 uppercaseVal = "#000000";
michael@0 169 break;
michael@0 170 }
michael@0 171 }
michael@0 172 var cells = this.mBox.getElementsByAttribute("color", uppercaseVal);
michael@0 173 if (cells.item(0)) {
michael@0 174 this.selectCell(cells[0]);
michael@0 175 this.hoverCell(this.mSelectedCell);
michael@0 176 }
michael@0 177 return val;
michael@0 178 ]]></setter>
michael@0 179 </property>
michael@0 180
michael@0 181 <method name="initColor">
michael@0 182 <parameter name="aColor"/>
michael@0 183 <body><![CDATA[
michael@0 184 // Use this to initialize color without
michael@0 185 // triggering the "onselect" handler,
michael@0 186 // which closes window when it's a popup
michael@0 187 this.mDoOnSelect = false;
michael@0 188 this.color = aColor;
michael@0 189 this.mDoOnSelect = true;
michael@0 190 ]]></body>
michael@0 191 </method>
michael@0 192
michael@0 193 <method name="initialize">
michael@0 194 <body><![CDATA[
michael@0 195 this.mSelectedCell = null;
michael@0 196 this.mHoverCell = null;
michael@0 197 this.mBox = document.getAnonymousNodes(this)[0];
michael@0 198 this.mIsPopup = false;
michael@0 199 this.mDoOnSelect = true;
michael@0 200
michael@0 201 this.hoverCell(this.mBox.childNodes[0].childNodes[0]);
michael@0 202
michael@0 203 // used to capture keydown at the document level
michael@0 204 this.mPickerKeyDown = function(aEvent)
michael@0 205 {
michael@0 206 document._focusedPicker.pickerKeyDown(aEvent);
michael@0 207 }
michael@0 208
michael@0 209 ]]></body>
michael@0 210 </method>
michael@0 211
michael@0 212 <method name="_fireEvent">
michael@0 213 <parameter name="aTarget"/>
michael@0 214 <parameter name="aEventName"/>
michael@0 215 <body>
michael@0 216 <![CDATA[
michael@0 217 try {
michael@0 218 var event = document.createEvent("Events");
michael@0 219 event.initEvent(aEventName, true, true);
michael@0 220 var cancel = !aTarget.dispatchEvent(event);
michael@0 221 if (aTarget.hasAttribute("on" + aEventName)) {
michael@0 222 var fn = new Function ("event", aTarget.getAttribute("on" + aEventName));
michael@0 223 var rv = fn.call(aTarget, event);
michael@0 224 if (rv == false)
michael@0 225 cancel = true;
michael@0 226 }
michael@0 227 return !cancel;
michael@0 228 }
michael@0 229 catch (e) {
michael@0 230 Components.utils.reportError(e);
michael@0 231 }
michael@0 232 return false;
michael@0 233 ]]>
michael@0 234 </body>
michael@0 235 </method>
michael@0 236
michael@0 237 <method name="resetHover">
michael@0 238 <body><![CDATA[
michael@0 239 if (this.mHoverCell)
michael@0 240 this.mHoverCell.removeAttribute("hover");
michael@0 241 ]]></body>
michael@0 242 </method>
michael@0 243
michael@0 244 <method name="getColIndex">
michael@0 245 <parameter name="aCell"/>
michael@0 246 <body><![CDATA[
michael@0 247 var cell = aCell;
michael@0 248 var idx;
michael@0 249 for (idx = -1; cell; idx++)
michael@0 250 cell = cell.previousSibling;
michael@0 251
michael@0 252 return idx;
michael@0 253 ]]></body>
michael@0 254 </method>
michael@0 255
michael@0 256 <method name="isColorCell">
michael@0 257 <parameter name="aCell"/>
michael@0 258 <body><![CDATA[
michael@0 259 return aCell && aCell.hasAttribute("color");
michael@0 260 ]]></body>
michael@0 261 </method>
michael@0 262
michael@0 263 <method name="hoverLeft">
michael@0 264 <body><![CDATA[
michael@0 265 var cell = this.mHoverCell.previousSibling;
michael@0 266 this.hoverCell(cell);
michael@0 267 ]]></body>
michael@0 268 </method>
michael@0 269
michael@0 270 <method name="hoverRight">
michael@0 271 <body><![CDATA[
michael@0 272 var cell = this.mHoverCell.nextSibling;
michael@0 273 this.hoverCell(cell);
michael@0 274 ]]></body>
michael@0 275 </method>
michael@0 276
michael@0 277 <method name="hoverUp">
michael@0 278 <body><![CDATA[
michael@0 279 var row = this.mHoverCell.parentNode.previousSibling;
michael@0 280 if (row) {
michael@0 281 var colIdx = this.getColIndex(this.mHoverCell);
michael@0 282 var cell = row.childNodes[colIdx];
michael@0 283 this.hoverCell(cell);
michael@0 284 }
michael@0 285 ]]></body>
michael@0 286 </method>
michael@0 287
michael@0 288 <method name="hoverDown">
michael@0 289 <body><![CDATA[
michael@0 290 var row = this.mHoverCell.parentNode.nextSibling;
michael@0 291 if (row) {
michael@0 292 var colIdx = this.getColIndex(this.mHoverCell);
michael@0 293 var cell = row.childNodes[colIdx];
michael@0 294 this.hoverCell(cell);
michael@0 295 }
michael@0 296 ]]></body>
michael@0 297 </method>
michael@0 298
michael@0 299 <method name="hoverTo">
michael@0 300 <parameter name="aRow"/>
michael@0 301 <parameter name="aCol"/>
michael@0 302
michael@0 303 <body><![CDATA[
michael@0 304 var row = this.mBox.childNodes[aRow];
michael@0 305 if (!row) return;
michael@0 306 var cell = row.childNodes[aCol];
michael@0 307 if (!cell) return;
michael@0 308 this.hoverCell(cell);
michael@0 309 ]]></body>
michael@0 310 </method>
michael@0 311
michael@0 312 <method name="hoverCell">
michael@0 313 <parameter name="aCell"/>
michael@0 314
michael@0 315 <body><![CDATA[
michael@0 316 if (this.isColorCell(aCell)) {
michael@0 317 this.resetHover();
michael@0 318 aCell.setAttribute("hover", "true");
michael@0 319 this.mHoverCell = aCell;
michael@0 320 var event = document.createEvent('Events');
michael@0 321 event.initEvent('DOMMenuItemActive', true, true);
michael@0 322 aCell.dispatchEvent(event);
michael@0 323 }
michael@0 324 ]]></body>
michael@0 325 </method>
michael@0 326
michael@0 327 <method name="selectHoverCell">
michael@0 328 <body><![CDATA[
michael@0 329 this.selectCell(this.mHoverCell);
michael@0 330 ]]></body>
michael@0 331 </method>
michael@0 332
michael@0 333 <method name="selectCell">
michael@0 334 <parameter name="aCell"/>
michael@0 335
michael@0 336 <body><![CDATA[
michael@0 337 if (this.isColorCell(aCell)) {
michael@0 338 if (this.mSelectedCell)
michael@0 339 this.mSelectedCell.removeAttribute("selected");
michael@0 340
michael@0 341 this.mSelectedCell = aCell;
michael@0 342 aCell.setAttribute("selected", "true");
michael@0 343
michael@0 344 if (this.mDoOnSelect)
michael@0 345 this._fireEvent(this, "select");
michael@0 346 }
michael@0 347 ]]></body>
michael@0 348 </method>
michael@0 349
michael@0 350 <method name="handleEvent">
michael@0 351 <parameter name="aEvent"/>
michael@0 352 <body><![CDATA[
michael@0 353 switch (aEvent.keyCode) {
michael@0 354 case 37: // left
michael@0 355 this.hoverLeft();
michael@0 356 break;
michael@0 357 case 38: // up
michael@0 358 this.hoverUp();
michael@0 359 break;
michael@0 360 case 39: // right
michael@0 361 this.hoverRight();
michael@0 362 break;
michael@0 363 case 40: // down
michael@0 364 this.hoverDown();
michael@0 365 break;
michael@0 366 case 13: // enter
michael@0 367 case 32: // space
michael@0 368 this.selectHoverCell();
michael@0 369 break;
michael@0 370 }
michael@0 371 ]]></body>
michael@0 372 </method>
michael@0 373
michael@0 374 <constructor><![CDATA[
michael@0 375 this.initialize();
michael@0 376 ]]></constructor>
michael@0 377
michael@0 378 </implementation>
michael@0 379
michael@0 380 <handlers>
michael@0 381 <handler event="mouseover"><![CDATA[
michael@0 382 this.hoverCell(event.originalTarget);
michael@0 383 ]]></handler>
michael@0 384
michael@0 385 <handler event="click"><![CDATA[
michael@0 386 if (event.originalTarget.hasAttribute("color")) {
michael@0 387 this.selectCell(event.originalTarget);
michael@0 388 this.hoverCell(this.mSelectedCell);
michael@0 389 }
michael@0 390 ]]></handler>
michael@0 391
michael@0 392
michael@0 393 <handler event="focus" phase="capturing">
michael@0 394 <![CDATA[
michael@0 395 if (!mIsPopup && this.getAttribute('focused') != 'true') {
michael@0 396 this.setAttribute('focused','true');
michael@0 397 document.addEventListener("keydown", this, true);
michael@0 398 if (this.mSelectedCell)
michael@0 399 this.hoverCell(this.mSelectedCell);
michael@0 400 }
michael@0 401 ]]>
michael@0 402 </handler>
michael@0 403
michael@0 404 <handler event="blur" phase="capturing">
michael@0 405 <![CDATA[
michael@0 406 if (!mIsPopup && this.getAttribute('focused') == 'true') {
michael@0 407 document.removeEventListener("keydown", this, true);
michael@0 408 this.removeAttribute('focused');
michael@0 409 this.resetHover();
michael@0 410 }
michael@0 411 ]]>
michael@0 412 </handler>
michael@0 413 </handlers>
michael@0 414 </binding>
michael@0 415
michael@0 416 <binding id="colorpicker-button" display="xul:menu" role="xul:colorpicker"
michael@0 417 extends="chrome://global/content/bindings/general.xml#basecontrol">
michael@0 418 <resources>
michael@0 419 <stylesheet src="chrome://global/skin/colorpicker.css"/>
michael@0 420 </resources>
michael@0 421
michael@0 422 <content>
michael@0 423 <xul:hbox class="colorpicker-button-colorbox" anonid="colorbox" flex="1" xbl:inherits="disabled"/>
michael@0 424
michael@0 425 <xul:panel class="colorpicker-button-menupopup"
michael@0 426 anonid="colorpopup" noautofocus="true" level="top"
michael@0 427 onmousedown="event.stopPropagation()"
michael@0 428 onpopupshowing="this._colorPicker.onPopupShowing()"
michael@0 429 onpopuphiding="this._colorPicker.onPopupHiding()"
michael@0 430 onselect="this._colorPicker.pickerChange()">
michael@0 431 <xul:colorpicker xbl:inherits="palettename,disabled" allowevents="true" anonid="colorpicker"/>
michael@0 432 </xul:panel>
michael@0 433 </content>
michael@0 434
michael@0 435 <implementation>
michael@0 436 <property name="open"
michael@0 437 onget="return this.getAttribute('open') == 'true'"
michael@0 438 onset="this.showPopup();"/>
michael@0 439 <property name="color">
michael@0 440 <getter><![CDATA[
michael@0 441 return this.getAttribute("color");
michael@0 442 ]]></getter>
michael@0 443 <setter><![CDATA[
michael@0 444 this.mColorBox.style.backgroundColor = val;
michael@0 445 this.setAttribute("color", val);
michael@0 446 return val;
michael@0 447 ]]></setter>
michael@0 448 </property>
michael@0 449
michael@0 450 <method name="initialize">
michael@0 451 <body><![CDATA[
michael@0 452 this.mColorBox = document.getAnonymousElementByAttribute(this, "anonid", "colorbox");
michael@0 453 this.mColorBox.style.backgroundColor = this.color;
michael@0 454
michael@0 455 var popup = document.getAnonymousElementByAttribute(this, "anonid", "colorpopup")
michael@0 456 popup._colorPicker = this;
michael@0 457
michael@0 458 this.mPicker = document.getAnonymousElementByAttribute(this, "anonid", "colorpicker")
michael@0 459 ]]></body>
michael@0 460 </method>
michael@0 461
michael@0 462 <method name="_fireEvent">
michael@0 463 <parameter name="aTarget"/>
michael@0 464 <parameter name="aEventName"/>
michael@0 465 <body>
michael@0 466 <![CDATA[
michael@0 467 try {
michael@0 468 var event = document.createEvent("Events");
michael@0 469 event.initEvent(aEventName, true, true);
michael@0 470 var cancel = !aTarget.dispatchEvent(event);
michael@0 471 if (aTarget.hasAttribute("on" + aEventName)) {
michael@0 472 var fn = new Function ("event", aTarget.getAttribute("on" + aEventName));
michael@0 473 var rv = fn.call(aTarget, event);
michael@0 474 if (rv == false)
michael@0 475 cancel = true;
michael@0 476 }
michael@0 477 return !cancel;
michael@0 478 }
michael@0 479 catch (e) {
michael@0 480 dump(e);
michael@0 481 }
michael@0 482 return false;
michael@0 483 ]]>
michael@0 484 </body>
michael@0 485 </method>
michael@0 486
michael@0 487 <method name="showPopup">
michael@0 488 <body><![CDATA[
michael@0 489 this.mPicker.parentNode.openPopup(this, "after_start", 0, 0, false, false);
michael@0 490 ]]></body>
michael@0 491 </method>
michael@0 492
michael@0 493 <method name="hidePopup">
michael@0 494 <body><![CDATA[
michael@0 495 this.mPicker.parentNode.hidePopup();
michael@0 496 ]]></body>
michael@0 497 </method>
michael@0 498
michael@0 499 <method name="onPopupShowing">
michael@0 500 <body><![CDATA[
michael@0 501 if ("resetHover" in this.mPicker)
michael@0 502 this.mPicker.resetHover();
michael@0 503 document.addEventListener("keydown", this.mPicker, true);
michael@0 504 this.mPicker.mIsPopup = true;
michael@0 505 // Initialize to current button's color
michael@0 506 this.mPicker.initColor(this.color);
michael@0 507 ]]></body>
michael@0 508 </method>
michael@0 509
michael@0 510 <method name="onPopupHiding">
michael@0 511 <body><![CDATA[
michael@0 512 // Removes the key listener
michael@0 513 document.removeEventListener("keydown", this.mPicker, true);
michael@0 514 this.mPicker.mIsPopup = false;
michael@0 515 ]]></body>
michael@0 516 </method>
michael@0 517
michael@0 518 <method name="pickerChange">
michael@0 519 <body><![CDATA[
michael@0 520 this.color = this.mPicker.color;
michael@0 521 setTimeout(function(aPopup) { aPopup.hidePopup() }, 1, this.mPicker.parentNode);
michael@0 522
michael@0 523 this._fireEvent(this, "change");
michael@0 524 ]]></body>
michael@0 525 </method>
michael@0 526
michael@0 527 <constructor><![CDATA[
michael@0 528 this.initialize();
michael@0 529 ]]></constructor>
michael@0 530
michael@0 531 </implementation>
michael@0 532
michael@0 533 <handlers>
michael@0 534 <handler event="keydown"><![CDATA[
michael@0 535 // open popup if key is space/up/left/right/down and popup is closed
michael@0 536 if ( (event.keyCode == 32 || (event.keyCode > 36 && event.keyCode < 41)) && !this.open)
michael@0 537 this.showPopup();
michael@0 538 else if ( (event.keyCode == 27) && this.open)
michael@0 539 this.hidePopup();
michael@0 540 ]]></handler>
michael@0 541 </handlers>
michael@0 542 </binding>
michael@0 543
michael@0 544 <binding id="colorpickertile" role="xul:colorpickertile">
michael@0 545 </binding>
michael@0 546
michael@0 547 </bindings>
michael@0 548

mercurial