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 createElement(doc, tagName, attrs, children) |
| 20 { |
| 21 let el = doc.createElement(tagName); |
| 22 if (attrs) |
| 23 for (let key in attrs) |
| 24 el.setAttribute(key, attrs[key]); |
| 25 if (children) |
| 26 for (let child of children) |
| 27 el.appendChild(child) |
| 28 return el; |
| 29 }; |
| 30 |
15 /********************************** | 31 /********************************** |
16 * General element selection code * | 32 * General element selection code * |
17 **********************************/ | 33 **********************************/ |
18 | 34 |
19 let Aardvark = exports.Aardvark = | 35 let Aardvark = exports.Aardvark = |
20 { | 36 { |
21 window: null, | 37 window: null, |
22 browser: null, | 38 browser: null, |
23 anchorElem: null, | 39 anchorElem: null, |
24 selectedElem: null, | 40 selectedElem: null, |
(...skipping 24 matching lines...) Expand all Loading... |
49 this.browser.addEventListener("click", this.onMouseClick, true); | 65 this.browser.addEventListener("click", this.onMouseClick, true); |
50 this.browser.addEventListener("DOMMouseScroll", this.onMouseScroll, true); | 66 this.browser.addEventListener("DOMMouseScroll", this.onMouseScroll, true); |
51 this.browser.addEventListener("keypress", this.onKeyPress, true); | 67 this.browser.addEventListener("keypress", this.onKeyPress, true); |
52 this.browser.addEventListener("mousemove", this.onMouseMove, true); | 68 this.browser.addEventListener("mousemove", this.onMouseMove, true); |
53 this.browser.addEventListener("select", this.quit, false); | 69 this.browser.addEventListener("select", this.quit, false); |
54 this.browser.contentWindow.addEventListener("pagehide", this.onPageHide, tru
e); | 70 this.browser.contentWindow.addEventListener("pagehide", this.onPageHide, tru
e); |
55 | 71 |
56 this.browser.contentWindow.focus(); | 72 this.browser.contentWindow.focus(); |
57 | 73 |
58 let doc = this.browser.contentDocument; | 74 let doc = this.browser.contentDocument; |
59 this.boxElem = doc.importNode(E("ehh-elementmarker").firstElementChild.clone
Node(true), true); | 75 let {elementMarkerClass} = require("main"); |
| 76 this.boxElem = createElement(doc, "div", {"class": elementMarkerClass}, [ |
| 77 createElement(doc, "div", {"class": "ehh-border"}), |
| 78 createElement(doc, "div", {"class": "ehh-label"}, [ |
| 79 createElement(doc, "span", {"class": "ehh-labelTag"}), |
| 80 createElement(doc, "span", {"class": "ehh-labelAddition"}) |
| 81 ]) |
| 82 ]); |
60 | 83 |
61 this.initHelpBox(); | 84 this.initHelpBox(); |
62 | 85 |
63 if (Prefs.showhelp) | 86 if (Prefs.showhelp) |
64 this.showMenu(); | 87 this.showMenu(); |
65 | 88 |
66 // Make sure to select some element immeditely (whichever is in the center o
f the browser window) | 89 // 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); | 90 let [wndWidth, wndHeight] = this.getWindowSize(doc.defaultView); |
68 this.isUserSelected = false; | 91 this.isUserSelected = false; |
69 this.onMouseMove({clientX: wndWidth / 2, clientY: wndHeight / 2, screenX: -1
, screenY: -1, target: null}); | 92 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 | 747 // Show help box |
725 helpBox.showPopup(this.browser, -1, -1, "tooltip", "topleft", "topleft"); | 748 helpBox.showPopup(this.browser, -1, -1, "tooltip", "topleft", "topleft"); |
726 return true; | 749 return true; |
727 } | 750 } |
728 } | 751 } |
729 | 752 |
730 // Makes sure event handlers like Aardvark.onKeyPress always have the correct | 753 // Makes sure event handlers like Aardvark.onKeyPress always have the correct |
731 // this pointer set. | 754 // this pointer set. |
732 for each (let method in ["onMouseClick", "onMouseScroll", "onKeyPress", "onPageH
ide", "onMouseMove", "onAfterPaint", "quit"]) | 755 for each (let method in ["onMouseClick", "onMouseScroll", "onKeyPress", "onPageH
ide", "onMouseMove", "onAfterPaint", "quit"]) |
733 Aardvark[method] = Aardvark[method].bind(Aardvark); | 756 Aardvark[method] = Aardvark[method].bind(Aardvark); |
OLD | NEW |