Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: chrome/content/ui/filters-search.js

Issue 5938722247802880: Support the new findbar API (Closed)
Left Patch Set: Created March 5, 2014, 9:56 p.m.
Right Patch Set: Added remaining stubs Created March 18, 2014, 3:51 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 30 findbar.browser = FilterSearch.fakeBrowser;
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 }
54 31
55 findbar.addEventListener("keypress", function(event) 32 findbar.addEventListener("keypress", function(event)
56 { 33 {
57 // Work-around for bug 490047 34 // Work-around for bug 490047
58 if (event.keyCode == KeyEvent.DOM_VK_RETURN) 35 if (event.keyCode == KeyEvent.DOM_VK_RETURN)
59 event.preventDefault(); 36 event.preventDefault();
60 }, false); 37 }, false);
61 38
62 // Hack to prevent "highlight all" from getting enabled 39 // Hack to prevent "highlight all" from getting enabled
63 findbar.toggleHighlight = function() {}; 40 findbar.toggleHighlight = function() {};
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 return result; 122 return result;
146 } 123 }
147 } 124 }
148 } 125 }
149 126
150 return Ci.nsITypeAheadFind.FIND_NOTFOUND; 127 return Ci.nsITypeAheadFind.FIND_NOTFOUND;
151 } 128 }
152 }; 129 };
153 130
154 /** 131 /**
155 * Finder implementation that searches in the filter list. 132 * Fake browser implementation to make findbar widget happy - searches in
133 * the filter list.
156 */ 134 */
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 */
186 FilterSearch.fakeBrowser = 135 FilterSearch.fakeBrowser =
187 { 136 {
137 finder:
138 {
139 _resultListeners: [],
140 searchString: null,
141 caseSensitive: false,
142 lastResult: null,
143
144 _notifyResultListeners: function(result, findBackwards)
145 {
146 this.lastResult = result;
147 for each (let listener in this._resultListeners)
148 listener.onFindResult(result, findBackwards);
149 },
150
151 fastFind: function(searchString, linksOnly, drawOutline)
152 {
153 this.searchString = searchString;
154 let result = FilterSearch.search(this.searchString, 0,
155 this.caseSensitive);
156 this._notifyResultListeners(result, false);
157 },
158
159 findAgain: function(findBackwards, linksOnly, drawOutline)
160 {
161 let result = FilterSearch.search(this.searchString,
162 findBackwards ? -1 : 1,
163 this.caseSensitive);
164 this._notifyResultListeners(result, findBackwards);
165 },
166
167 addResultListener: function(listener)
168 {
169 if (this._resultListeners.indexOf(listener) === -1)
170 this._resultListeners.push(listener);
171 },
172
173 removeResultListener: function(listener)
174 {
175 let index = this._resultListeners.indexOf(listener);
176 if (index !== -1)
177 this._resultListeners.splice(index, 1);
178 },
179
180 // Irrelevant for us
181 highlight: function(highlight, word) {},
182 enableSelection: function() {},
183 removeSelection: function() {},
184 focusContent: function() {},
185 keyPress: function() {}
186 },
187
188 get _lastSearchString()
189 {
190 return this.finder.searchString;
191 },
192
193 // This was used before Firefox 27 instead of the "finder" property.
188 fastFind: 194 fastFind:
189 { 195 {
190 get searchString() 196 get searchString()
191 { 197 {
192 return FilterSearch.finder.searchString; 198 return FilterSearch.fakeBrowser.finder.searchString;
193 }, 199 },
194 200
195 set searchString(searchString) 201 set searchString(searchString)
196 { 202 {
197 FilterSearch.finder.searchString = searchString; 203 FilterSearch.fakeBrowser.finder.searchString = searchString;
198 }, 204 },
199 205
200 foundLink: null, 206 foundLink: null,
201 foundEditable: null, 207 foundEditable: null,
202 208
203 get caseSensitive() 209 get caseSensitive()
204 { 210 {
205 return FilterSearch.finder.caseSensitive; 211 return FilterSearch.fakeBrowser.finder.caseSensitive;
206 }, 212 },
207 213
208 set caseSensitive(caseSensitive) 214 set caseSensitive(caseSensitive)
209 { 215 {
210 FilterSearch.finder.caseSensitive = caseSensitive; 216 FilterSearch.fakeBrowser.finder.caseSensitive = caseSensitive;
211 }, 217 },
212 218
213 get currentWindow() FilterSearch.fakeBrowser.contentWindow, 219 get currentWindow() FilterSearch.fakeBrowser.contentWindow,
214 220
215 find: function(searchString, linksOnly) 221 find: function(searchString, linksOnly)
216 { 222 {
217 FilterSearch.finder.fastFind(searchString, linksOnly); 223 FilterSearch.fakeBrowser.finder.fastFind(searchString, linksOnly);
224 return FilterSearch.fakeBrowser.finder.lastResult;
218 }, 225 },
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.
219 226
220 findAgain: function(findBackwards, linksOnly) 227 findAgain: function(findBackwards, linksOnly)
221 { 228 {
222 FilterSearch.finder.findAgain(findBackwards, linksOnly); 229 FilterSearch.fakeBrowser.finder.findAgain(findBackwards, linksOnly);
230 return FilterSearch.fakeBrowser.finder.lastResult;
223 }, 231 },
224 232
225 // Irrelevant for us 233 // Irrelevant for us
226 init: function() {}, 234 init: function() {},
227 setDocShell: function() {}, 235 setDocShell: function() {},
228 setSelectionModeAndRepaint: function() {}, 236 setSelectionModeAndRepaint: function() {},
229 collapseSelection: function() {} 237 collapseSelection: function() {}
230 }, 238 },
231 currentURI: Utils.makeURI("http://example.com/"), 239 currentURI: Utils.makeURI("http://example.com/"),
232 contentWindow: 240 contentWindow:
(...skipping 19 matching lines...) Expand all
252 removeEventListener: function(event, handler, capture) 260 removeEventListener: function(event, handler, capture)
253 { 261 {
254 E("filtersTree").addEventListener(event, handler, capture); 262 E("filtersTree").addEventListener(event, handler, capture);
255 }, 263 },
256 }; 264 };
257 265
258 window.addEventListener("load", function() 266 window.addEventListener("load", function()
259 { 267 {
260 FilterSearch.init(); 268 FilterSearch.init();
261 }, false); 269 }, false);
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld