Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 /********************************* | 15 /********************************* |
16 * Minimal element creation code * | 16 * Minimal element creation code * |
17 *********************************/ | 17 *********************************/ |
18 | 18 |
19 function Element(el) | 19 function createElement(doc, tagName, attrs, children) |
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 { | 20 { |
34 let el = doc.createElement(tagName); | 21 let el = doc.createElement(tagName); |
35 if (attrs) | 22 if (attrs) |
36 for (let key in attrs) | 23 for (let key in attrs) |
37 el.setAttribute(key, attrs[key]); | 24 el.setAttribute(key, attrs[key]); |
38 if (typeof callback == "function") | 25 if (children) |
39 callback(new Element(el)); | 26 for (let child of children) |
27 el.appendChild(child) | |
40 return el; | 28 return el; |
41 }; | 29 }; |
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 | 30 |
43 /********************************** | 31 /********************************** |
44 * General element selection code * | 32 * General element selection code * |
45 **********************************/ | 33 **********************************/ |
46 | 34 |
47 let Aardvark = exports.Aardvark = | 35 let Aardvark = exports.Aardvark = |
48 { | 36 { |
49 window: null, | 37 window: null, |
50 browser: null, | 38 browser: null, |
51 anchorElem: null, | 39 anchorElem: null, |
(...skipping 26 matching lines...) Expand all Loading... | |
78 this.browser.addEventListener("DOMMouseScroll", this.onMouseScroll, true); | 66 this.browser.addEventListener("DOMMouseScroll", this.onMouseScroll, true); |
79 this.browser.addEventListener("keypress", this.onKeyPress, true); | 67 this.browser.addEventListener("keypress", this.onKeyPress, true); |
80 this.browser.addEventListener("mousemove", this.onMouseMove, true); | 68 this.browser.addEventListener("mousemove", this.onMouseMove, true); |
81 this.browser.addEventListener("select", this.quit, false); | 69 this.browser.addEventListener("select", this.quit, false); |
82 this.browser.contentWindow.addEventListener("pagehide", this.onPageHide, tru e); | 70 this.browser.contentWindow.addEventListener("pagehide", this.onPageHide, tru e); |
83 | 71 |
84 this.browser.contentWindow.focus(); | 72 this.browser.contentWindow.focus(); |
85 | 73 |
86 let doc = this.browser.contentDocument; | 74 let doc = this.browser.contentDocument; |
87 let {elementMarkerClass} = require("main"); | 75 let {elementMarkerClass} = require("main"); |
88 this.boxElem = Element.create(doc, "div", {"class": elementMarkerClass}, fun ction(el) | 76 this.boxElem = createElement(doc, "div", {"class": elementMarkerClass}, [ |
89 { | 77 createElement(doc, "div", {"class": "ehh-border"}), |
90 el.child("div", {"class": "ehh-border"}); | 78 createElement(doc, "div", {"class": "ehh-label"}, [ |
91 el.child("div", {"class": "ehh-label"}, function(el) | 79 createElement(doc, "span", {"class": "ehh-labelTag"}), |
92 { | 80 createElement(doc, "span", {"class": "ehh-labelAddition"}) |
93 el.child("span", {"class": "ehh-labelTag"}) | 81 ]) |
94 el.child("span", {"class": "ehh-labelAddition"}); | 82 ]); |
95 }); | |
96 }); | |
97 | 83 |
98 this.initHelpBox(); | 84 this.initHelpBox(); |
99 | 85 |
100 if (Prefs.showhelp) | 86 if (Prefs.showhelp) |
101 this.showMenu(); | 87 this.showMenu(); |
102 | 88 |
103 // 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) |
104 let [wndWidth, wndHeight] = this.getWindowSize(doc.defaultView); | 90 let [wndWidth, wndHeight] = this.getWindowSize(doc.defaultView); |
105 this.isUserSelected = false; | 91 this.isUserSelected = false; |
106 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 this.boxElem.parentNode.removeChild(this.boxElem); | 397 this.boxElem.parentNode.removeChild(this.boxElem); |
412 | 398 |
413 if (this.paintNode) | 399 if (this.paintNode) |
414 this.paintNode.removeEventListener("MozAfterPaint", this.onAfterPaint, fal se); | 400 this.paintNode.removeEventListener("MozAfterPaint", this.onAfterPaint, fal se); |
415 this.paintNode = null; | 401 this.paintNode = null; |
416 this.prevPos = null; | 402 this.prevPos = null; |
417 }, | 403 }, |
418 | 404 |
419 getWindowSize: function(wnd) | 405 getWindowSize: function(wnd) |
420 { | 406 { |
421 return [wnd.innerWidth, wnd.innerHeight]; | 407 return [wnd.innerWidth, wnd.document.documentElement.clientHeight]; |
422 }, | 408 }, |
423 | 409 |
424 getElementPosition: function(element) | 410 getElementPosition: function(element) |
425 { | 411 { |
426 // Restrict rectangle coordinates by the boundaries of a window's client are a | 412 // Restrict rectangle coordinates by the boundaries of a window's client are a |
427 function intersectRect(rect, wnd) | 413 function intersectRect(rect, wnd) |
428 { | 414 { |
429 let [wndWidth, wndHeight] = this.getWindowSize(wnd); | 415 let [wndWidth, wndHeight] = this.getWindowSize(wnd); |
430 rect.left = Math.max(rect.left, 0); | 416 rect.left = Math.max(rect.left, 0); |
431 rect.top = Math.max(rect.top, 0); | 417 rect.top = Math.max(rect.top, 0); |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
761 // Show help box | 747 // Show help box |
762 helpBox.showPopup(this.browser, -1, -1, "tooltip", "topleft", "topleft"); | 748 helpBox.showPopup(this.browser, -1, -1, "tooltip", "topleft", "topleft"); |
763 return true; | 749 return true; |
764 } | 750 } |
765 } | 751 } |
766 | 752 |
767 // Makes sure event handlers like Aardvark.onKeyPress always have the correct | 753 // Makes sure event handlers like Aardvark.onKeyPress always have the correct |
768 // this pointer set. | 754 // this pointer set. |
769 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"]) |
770 Aardvark[method] = Aardvark[method].bind(Aardvark); | 756 Aardvark[method] = Aardvark[method].bind(Aardvark); |
LEFT | RIGHT |