Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 /** | 18 /** |
19 * Implementation of the filter search functionality. | 19 * Implementation of the filter search functionality. |
20 * @class | 20 * @class |
21 */ | 21 */ |
22 var FilterSearch = | 22 var FilterSearch = |
23 { | 23 { |
24 /** | 24 /** |
25 * Initializes findbar widget. | 25 * Initializes findbar widget. |
26 */ | 26 */ |
27 init: function() | 27 init: function() |
28 { | 28 { |
29 let findbar = E("findbar"); | 29 let findbar = E("findbar"); |
30 findbar.browser = FilterSearch.fakeBrowser; | 30 |
31 // The findbar API changed in Firefox 27, we still support the old one for | |
32 // backwards compatibility. | |
33 let oldFindBar = false; | |
34 try | |
35 { | |
36 Components.utils.import("resource://gre/modules/Finder.jsm", {}); | |
37 } | |
38 catch (e) | |
39 { | |
40 oldFindBar = true; | |
41 } | |
Wladimir Palant
2014/03/06 13:20:51
Does this check make sense? From the look of it, t
Felix Dahlke
2014/03/10 22:19:56
Yeah, we can just use fakeBrowser instead of filte
| |
42 | |
43 if (oldFindBar) | |
44 findbar.browser = FilterSearch.fakeBrowser; | |
45 else | |
46 { | |
47 let container = document.getElementById("filtersContainer"); | |
Wladimir Palant
2014/03/06 13:20:51
We have a shortcut function for that, E("filtersCo
Felix Dahlke
2014/03/10 22:19:56
Got rid of that code anyway.
| |
48 container.finder = FilterSearch.finder; | |
49 findbar.browser = container; | |
50 | |
51 // Without this, the initial search string will be "undefined" | |
52 findbar._findField.value = ""; | |
Wladimir Palant
2014/03/06 13:20:51
That's a rather unreliable hack. Instead please ad
Felix Dahlke
2014/03/10 22:19:56
Done.
| |
53 } | |
31 | 54 |
32 findbar.addEventListener("keypress", function(event) | 55 findbar.addEventListener("keypress", function(event) |
33 { | 56 { |
34 // Work-around for bug 490047 | 57 // Work-around for bug 490047 |
35 if (event.keyCode == KeyEvent.DOM_VK_RETURN) | 58 if (event.keyCode == KeyEvent.DOM_VK_RETURN) |
36 event.preventDefault(); | 59 event.preventDefault(); |
37 }, false); | 60 }, false); |
38 | 61 |
39 // Hack to prevent "highlight all" from getting enabled | 62 // Hack to prevent "highlight all" from getting enabled |
40 findbar.toggleHighlight = function() {}; | 63 findbar.toggleHighlight = function() {}; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 return result; | 145 return result; |
123 } | 146 } |
124 } | 147 } |
125 } | 148 } |
126 | 149 |
127 return Ci.nsITypeAheadFind.FIND_NOTFOUND; | 150 return Ci.nsITypeAheadFind.FIND_NOTFOUND; |
128 } | 151 } |
129 }; | 152 }; |
130 | 153 |
131 /** | 154 /** |
132 * Fake browser implementation to make findbar widget happy - searches in | 155 * Finder implementation that searches in the filter list. |
133 * the filter list. | |
134 */ | 156 */ |
157 FilterSearch.finder = | |
158 { | |
159 searchString: null, | |
160 caseSensitive: false, | |
161 | |
162 fastFind: function(searchString, linksOnly, drawOutline) | |
163 { | |
164 this.searchString = searchString; | |
165 FilterSearch.search(this.searchString, 0, this.caseSensitive); | |
Wladimir Palant
2014/03/06 13:20:51
The return value of the search function should not
Felix Dahlke
2014/03/10 22:19:56
Done.
| |
166 }, | |
167 | |
168 findAgain: function(findBackwards, linksOnly, drawOutline) | |
169 { | |
170 FilterSearch.search(this.searchString, findBackwards ? -1 : 1, | |
171 this.caseSensitive); | |
172 }, | |
173 | |
174 // Irrelevant for us | |
175 addResultListener: function(listener) {}, | |
176 removeResultListener: function(listener) {}, | |
Wladimir Palant
2014/03/06 13:20:51
Actually, the listeners are not irrelevant - that'
Felix Dahlke
2014/03/10 22:19:56
Done.
| |
177 highlight: function(highlight, word) {}, | |
178 enableSelection: function() {}, | |
179 focusContent: function() {} | |
Wladimir Palant
2014/03/06 13:20:51
What about removeSelection and keyPress? The latte
Felix Dahlke
2014/03/10 22:19:56
Neither is actually being called in practice, at l
Wladimir Palant
2014/03/13 11:40:01
Yes, we definitely need stubs at the very least -
Felix Dahlke
2014/03/18 15:51:50
Added stubs for removeSelection and keyPress. Judg
| |
180 }; | |
181 | |
182 /** | |
183 * Fake browser implementation to make findbar widget happy - searches in | |
184 * the filter list. | |
185 */ | |
135 FilterSearch.fakeBrowser = | 186 FilterSearch.fakeBrowser = |
136 { | 187 { |
137 fastFind: | 188 fastFind: |
138 { | 189 { |
139 searchString: null, | 190 get searchString() |
191 { | |
192 return FilterSearch.finder.searchString; | |
193 }, | |
194 | |
195 set searchString(searchString) | |
196 { | |
197 FilterSearch.finder.searchString = searchString; | |
198 }, | |
199 | |
140 foundLink: null, | 200 foundLink: null, |
141 foundEditable: null, | 201 foundEditable: null, |
142 caseSensitive: false, | 202 |
203 get caseSensitive() | |
204 { | |
205 return FilterSearch.finder.caseSensitive; | |
206 }, | |
207 | |
208 set caseSensitive(caseSensitive) | |
209 { | |
210 FilterSearch.finder.caseSensitive = caseSensitive; | |
211 }, | |
212 | |
143 get currentWindow() FilterSearch.fakeBrowser.contentWindow, | 213 get currentWindow() FilterSearch.fakeBrowser.contentWindow, |
144 | 214 |
145 find: function(searchString, linksOnly) | 215 find: function(searchString, linksOnly) |
146 { | 216 { |
147 this.searchString = searchString; | 217 FilterSearch.finder.fastFind(searchString, linksOnly); |
148 return FilterSearch.search(this.searchString, 0, this.caseSensitive); | |
149 }, | 218 }, |
Wladimir Palant
2014/03/06 13:20:51
How about:
find: FilterSearch.finder.bind(Filte
Felix Dahlke
2014/03/10 22:19:56
Not relevant anymore since the code changed.
| |
150 | 219 |
151 findAgain: function(findBackwards, linksOnly) | 220 findAgain: function(findBackwards, linksOnly) |
152 { | 221 { |
153 return FilterSearch.search(this.searchString, findBackwards ? -1 : 1, this .caseSensitive); | 222 FilterSearch.finder.findAgain(findBackwards, linksOnly); |
154 }, | 223 }, |
155 | 224 |
156 // Irrelevant for us | 225 // Irrelevant for us |
157 init: function() {}, | 226 init: function() {}, |
158 setDocShell: function() {}, | 227 setDocShell: function() {}, |
159 setSelectionModeAndRepaint: function() {}, | 228 setSelectionModeAndRepaint: function() {}, |
160 collapseSelection: function() {} | 229 collapseSelection: function() {} |
161 }, | 230 }, |
162 currentURI: Utils.makeURI("http://example.com/"), | 231 currentURI: Utils.makeURI("http://example.com/"), |
163 contentWindow: | 232 contentWindow: |
(...skipping 19 matching lines...) Expand all Loading... | |
183 removeEventListener: function(event, handler, capture) | 252 removeEventListener: function(event, handler, capture) |
184 { | 253 { |
185 E("filtersTree").addEventListener(event, handler, capture); | 254 E("filtersTree").addEventListener(event, handler, capture); |
186 }, | 255 }, |
187 }; | 256 }; |
188 | 257 |
189 window.addEventListener("load", function() | 258 window.addEventListener("load", function() |
190 { | 259 { |
191 FilterSearch.init(); | 260 FilterSearch.init(); |
192 }, false); | 261 }, false); |
OLD | NEW |