Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 let {BrowserUtils} = Cu.import("resource://gre/modules/BrowserUtils.jsm"); | |
19 | |
18 /** | 20 /** |
19 * Implementation of the filter search functionality. | 21 * Implementation of the filter search functionality. |
20 * @class | 22 * @class |
21 */ | 23 */ |
22 var FilterSearch = | 24 var FilterSearch = |
23 { | 25 { |
24 /** | 26 /** |
25 * Initializes findbar widget. | 27 * Initializes findbar widget. |
26 */ | 28 */ |
27 init: function() | 29 init: function() |
(...skipping 15 matching lines...) Expand all Loading... | |
43 | 45 |
44 findbar.addEventListener("keypress", function(event) | 46 findbar.addEventListener("keypress", function(event) |
45 { | 47 { |
46 // Work-around for bug 490047 | 48 // Work-around for bug 490047 |
47 if (event.keyCode == KeyEvent.DOM_VK_RETURN) | 49 if (event.keyCode == KeyEvent.DOM_VK_RETURN) |
48 event.preventDefault(); | 50 event.preventDefault(); |
49 }, false); | 51 }, false); |
50 | 52 |
51 // Hack to prevent "highlight all" from getting enabled | 53 // Hack to prevent "highlight all" from getting enabled |
52 findbar.toggleHighlight = function() {}; | 54 findbar.toggleHighlight = function() {}; |
53 | |
54 // Ignore accessibility.typeaheadfind preference to avoid findbar | |
55 // being opened when interacting with filter tree | |
56 Object.defineProperty(findbar, "_findAsYouType", { | |
57 get: () => false, | |
58 enumerable: true, | |
59 configurable: true | |
60 }); | |
Wladimir Palant
2015/10/05 14:17:20
I don't think we need to disable the functionality
Thomas Greiner
2015/10/05 16:45:20
Thanks for the link, I wasn't aware of this implem
| |
61 }, | 55 }, |
62 | 56 |
63 /** | 57 /** |
64 * Performs a text search. | 58 * Performs a text search. |
65 * @param {String} text text to be searched | 59 * @param {String} text text to be searched |
66 * @param {Integer} direction search direction: -1 (backwards), 0 (forwards | 60 * @param {Integer} direction search direction: -1 (backwards), 0 (forwards |
67 * starting with current), 1 (forwards starting with next) | 61 * starting with current), 1 (forwards starting with next) |
68 * @param {Boolean} caseSensitive if true, a case-sensitive search is perform ed | 62 * @param {Boolean} caseSensitive if true, a case-sensitive search is perform ed |
69 * @result {Integer} one of the nsITypeAheadFind constants | 63 * @result {Integer} one of the nsITypeAheadFind constants |
70 */ | 64 */ |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 E("filtersTree").boxObject.scrollByLines(num); | 229 E("filtersTree").boxObject.scrollByLines(num); |
236 }, | 230 }, |
237 scrollByPages: function(num) | 231 scrollByPages: function(num) |
238 { | 232 { |
239 E("filtersTree").boxObject.scrollByPages(num); | 233 E("filtersTree").boxObject.scrollByPages(num); |
240 }, | 234 }, |
241 }, | 235 }, |
242 | 236 |
243 messageManager: | 237 messageManager: |
244 { | 238 { |
239 FAYT_LINKS_KEY: "'".charCodeAt(0), | |
240 FAYT_TEXT_KEY: "/".charCodeAt(0), | |
245 _messageMap: { | 241 _messageMap: { |
246 "Findbar:Mouseup": "mouseup", | 242 "Findbar:Mouseup": "mouseup", |
247 "Findbar:Keypress": "keypress" | 243 "Findbar:Keypress": "keypress" |
248 }, | 244 }, |
249 | 245 |
250 _messageFromEvent: function(event) | 246 _messageFromEvent: function(event) |
251 { | 247 { |
252 for (let message in this._messageMap) | 248 for (let message in this._messageMap) |
253 if (this._messageMap[message] == event.type) | 249 if (this._messageMap[message] == event.type) |
254 return {target: event.currentTarget, name: message, data: event}; | 250 return {target: event.currentTarget, name: message, data: event}; |
255 return null; | 251 return null; |
256 }, | 252 }, |
257 | 253 |
258 addMessageListener: function(message, listener) | 254 addMessageListener: function(message, listener) |
259 { | 255 { |
260 if (!this._messageMap.hasOwnProperty(message)) | 256 if (!this._messageMap.hasOwnProperty(message)) |
261 return; | 257 return; |
262 | 258 |
263 if (!("_ABPHandler" in listener)) | 259 if (!("_ABPHandler" in listener)) |
264 listener._ABPHandler = (event) => listener.receiveMessage(this._messageF romEvent(event)); | 260 { |
261 listener._ABPHandler = (event) => { | |
262 if (event.type == "keypress") | |
263 { | |
264 if (event.ctrlKey || event.altKey || event.metaKey | |
265 || event.defaultPrevented) | |
266 return; | |
267 | |
268 let findbar = E("findbar"); | |
269 if (findbar.findMode == findbar.FIND_NORMAL | |
270 && !findbar.findAsYouType | |
271 && event.charCode != this.FAYT_LINKS_KEY | |
272 && event.charCode != this.FAYT_TEXT_KEY) | |
273 return; | |
274 | |
275 let target = Services.focus.getFocusedElementForWindow(window, true, {}); | |
276 if (!BrowserUtils.shouldFastFind(target, window)) | |
277 return; | |
278 } | |
279 | |
280 listener.receiveMessage(this._messageFromEvent(event)); | |
281 }; | |
282 } | |
265 | 283 |
266 E("filtersTree").addEventListener(this._messageMap[message], listener._ABP Handler, false); | 284 E("filtersTree").addEventListener(this._messageMap[message], listener._ABP Handler, false); |
267 }, | 285 }, |
268 | 286 |
269 removeMessageListener: function(message, listener) | 287 removeMessageListener: function(message, listener) |
270 { | 288 { |
271 if (this._messageMap.hasOwnProperty(message) && listener._ABPHandler) | 289 if (this._messageMap.hasOwnProperty(message) && listener._ABPHandler) |
272 E("filtersTree").removeEventListener(this._messageMap[message], listener ._ABPHandler, false); | 290 E("filtersTree").removeEventListener(this._messageMap[message], listener ._ABPHandler, false); |
273 }, | 291 }, |
274 | 292 |
275 sendAsyncMessage: function() {} | 293 sendAsyncMessage: function() {} |
276 } | 294 } |
277 }; | 295 }; |
278 | 296 |
279 window.addEventListener("load", function() | 297 window.addEventListener("load", function() |
280 { | 298 { |
281 FilterSearch.init(); | 299 FilterSearch.init(); |
282 }, false); | 300 }, false); |
LEFT | RIGHT |