| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * This Source Code is subject to the terms of the Mozilla Public License | 2 * This Source Code is subject to the terms of the Mozilla Public License |
| 3 * version 2.0 (the "License"). You can obtain a copy of the License at | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
| 4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 let {Prefs} = require("prefs"); | 7 let {Prefs} = require("prefs"); |
| 8 | 8 |
| 9 // Make sure to stop selection when we are uninstalled | 9 // Make sure to stop selection when we are uninstalled |
| 10 onShutdown.add(function() Aardvark.quit()); | 10 onShutdown.add(function() Aardvark.quit()); |
| 11 | 11 |
| 12 // To be replaced when selection starts | 12 // To be replaced when selection starts |
| 13 function E(id) {return null;} | 13 function E(id) {return null;} |
| 14 | 14 |
| 15 /********************************* | |
| 16 * Minimal element creation code * | |
| 17 *********************************/ | |
| 18 | |
| 19 function Element(el) | |
| 20 { | |
| 21 this._el = el; | |
| 22 } | |
| 23 Element.prototype = | |
| 24 { | |
| 25 _el: null, | |
| 26 child: function(tagName, attrs, callback) | |
| 27 { | |
| 28 let child = Element.create(this._el.ownerDocument, tagName, attrs, callback) ; | |
| 29 this._el.appendChild(child); | |
| 30 } | |
| 31 }; | |
| 32 Element.create = function(doc, tagName, attrs, callback) | |
| 33 { | |
| 34 let el = doc.createElement(tagName); | |
| 35 if (attrs) | |
| 36 for (let key in attrs) | |
| 37 el.setAttribute(key, attrs[key]); | |
| 38 if (typeof callback == "function") | |
| 39 callback(new Element(el)); | |
| 40 return el; | |
| 41 }; | |
|
Thomas Greiner
2014/07/23 13:55:52
What's the reason for introducing a custom type he
Wladimir Palant
2014/09/11 16:52:13
This code went through several iteration, particul
| |
| 42 | |
| 15 /********************************** | 43 /********************************** |
| 16 * General element selection code * | 44 * General element selection code * |
| 17 **********************************/ | 45 **********************************/ |
| 18 | 46 |
| 19 let Aardvark = exports.Aardvark = | 47 let Aardvark = exports.Aardvark = |
| 20 { | 48 { |
| 21 window: null, | 49 window: null, |
| 22 browser: null, | 50 browser: null, |
| 23 anchorElem: null, | 51 anchorElem: null, |
| 24 selectedElem: null, | 52 selectedElem: null, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 49 this.browser.addEventListener("click", this.onMouseClick, true); | 77 this.browser.addEventListener("click", this.onMouseClick, true); |
| 50 this.browser.addEventListener("DOMMouseScroll", this.onMouseScroll, true); | 78 this.browser.addEventListener("DOMMouseScroll", this.onMouseScroll, true); |
| 51 this.browser.addEventListener("keypress", this.onKeyPress, true); | 79 this.browser.addEventListener("keypress", this.onKeyPress, true); |
| 52 this.browser.addEventListener("mousemove", this.onMouseMove, true); | 80 this.browser.addEventListener("mousemove", this.onMouseMove, true); |
| 53 this.browser.addEventListener("select", this.quit, false); | 81 this.browser.addEventListener("select", this.quit, false); |
| 54 this.browser.contentWindow.addEventListener("pagehide", this.onPageHide, tru e); | 82 this.browser.contentWindow.addEventListener("pagehide", this.onPageHide, tru e); |
| 55 | 83 |
| 56 this.browser.contentWindow.focus(); | 84 this.browser.contentWindow.focus(); |
| 57 | 85 |
| 58 let doc = this.browser.contentDocument; | 86 let doc = this.browser.contentDocument; |
| 59 this.boxElem = doc.importNode(E("ehh-elementmarker").firstElementChild.clone Node(true), true); | 87 let {elementMarkerClass} = require("main"); |
| 88 this.boxElem = Element.create(doc, "div", {"class": elementMarkerClass}, fun ction(el) | |
| 89 { | |
| 90 el.child("div", {"class": "ehh-border"}); | |
| 91 el.child("div", {"class": "ehh-label"}, function(el) | |
| 92 { | |
| 93 el.child("span", {"class": "ehh-labelTag"}) | |
| 94 el.child("span", {"class": "ehh-labelAddition"}); | |
| 95 }); | |
| 96 }); | |
| 60 | 97 |
| 61 this.initHelpBox(); | 98 this.initHelpBox(); |
| 62 | 99 |
| 63 if (Prefs.showhelp) | 100 if (Prefs.showhelp) |
| 64 this.showMenu(); | 101 this.showMenu(); |
| 65 | 102 |
| 66 // Make sure to select some element immeditely (whichever is in the center o f the browser window) | 103 // Make sure to select some element immeditely (whichever is in the center o f the browser window) |
| 67 let [wndWidth, wndHeight] = this.getWindowSize(doc.defaultView); | 104 let [wndWidth, wndHeight] = this.getWindowSize(doc.defaultView); |
| 68 this.isUserSelected = false; | 105 this.isUserSelected = false; |
| 69 this.onMouseMove({clientX: wndWidth / 2, clientY: wndHeight / 2, screenX: -1 , screenY: -1, target: null}); | 106 this.onMouseMove({clientX: wndWidth / 2, clientY: wndHeight / 2, screenX: -1 , screenY: -1, target: null}); |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 724 // Show help box | 761 // Show help box |
| 725 helpBox.showPopup(this.browser, -1, -1, "tooltip", "topleft", "topleft"); | 762 helpBox.showPopup(this.browser, -1, -1, "tooltip", "topleft", "topleft"); |
| 726 return true; | 763 return true; |
| 727 } | 764 } |
| 728 } | 765 } |
| 729 | 766 |
| 730 // Makes sure event handlers like Aardvark.onKeyPress always have the correct | 767 // Makes sure event handlers like Aardvark.onKeyPress always have the correct |
| 731 // this pointer set. | 768 // this pointer set. |
| 732 for each (let method in ["onMouseClick", "onMouseScroll", "onKeyPress", "onPageH ide", "onMouseMove", "onAfterPaint", "quit"]) | 769 for each (let method in ["onMouseClick", "onMouseScroll", "onKeyPress", "onPageH ide", "onMouseMove", "onAfterPaint", "quit"]) |
| 733 Aardvark[method] = Aardvark[method].bind(Aardvark); | 770 Aardvark[method] = Aardvark[method].bind(Aardvark); |
| OLD | NEW |