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

Side by Side Diff: chrome/content/ui/filters-search.js

Issue 5938722247802880: Support the new findbar API (Closed)
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:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 return Ci.nsITypeAheadFind.FIND_NOTFOUND; 127 return Ci.nsITypeAheadFind.FIND_NOTFOUND;
128 } 128 }
129 }; 129 };
130 130
131 /** 131 /**
132 * Fake browser implementation to make findbar widget happy - searches in 132 * Fake browser implementation to make findbar widget happy - searches in
133 * the filter list. 133 * the filter list.
134 */ 134 */
135 FilterSearch.fakeBrowser = 135 FilterSearch.fakeBrowser =
136 { 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.
137 fastFind: 194 fastFind:
138 { 195 {
139 searchString: null, 196 get searchString()
197 {
198 return FilterSearch.fakeBrowser.finder.searchString;
199 },
200
201 set searchString(searchString)
202 {
203 FilterSearch.fakeBrowser.finder.searchString = searchString;
204 },
205
140 foundLink: null, 206 foundLink: null,
141 foundEditable: null, 207 foundEditable: null,
142 caseSensitive: false, 208
209 get caseSensitive()
210 {
211 return FilterSearch.fakeBrowser.finder.caseSensitive;
212 },
213
214 set caseSensitive(caseSensitive)
215 {
216 FilterSearch.fakeBrowser.finder.caseSensitive = caseSensitive;
217 },
218
143 get currentWindow() FilterSearch.fakeBrowser.contentWindow, 219 get currentWindow() FilterSearch.fakeBrowser.contentWindow,
144 220
145 find: function(searchString, linksOnly) 221 find: function(searchString, linksOnly)
146 { 222 {
147 this.searchString = searchString; 223 FilterSearch.fakeBrowser.finder.fastFind(searchString, linksOnly);
148 return FilterSearch.search(this.searchString, 0, this.caseSensitive); 224 return FilterSearch.fakeBrowser.finder.lastResult;
149 }, 225 },
150 226
151 findAgain: function(findBackwards, linksOnly) 227 findAgain: function(findBackwards, linksOnly)
152 { 228 {
153 return FilterSearch.search(this.searchString, findBackwards ? -1 : 1, this .caseSensitive); 229 FilterSearch.fakeBrowser.finder.findAgain(findBackwards, linksOnly);
230 return FilterSearch.fakeBrowser.finder.lastResult;
154 }, 231 },
155 232
156 // Irrelevant for us 233 // Irrelevant for us
157 init: function() {}, 234 init: function() {},
158 setDocShell: function() {}, 235 setDocShell: function() {},
159 setSelectionModeAndRepaint: function() {}, 236 setSelectionModeAndRepaint: function() {},
160 collapseSelection: function() {} 237 collapseSelection: function() {}
161 }, 238 },
162 currentURI: Utils.makeURI("http://example.com/"), 239 currentURI: Utils.makeURI("http://example.com/"),
163 contentWindow: 240 contentWindow:
(...skipping 19 matching lines...) Expand all
183 removeEventListener: function(event, handler, capture) 260 removeEventListener: function(event, handler, capture)
184 { 261 {
185 E("filtersTree").addEventListener(event, handler, capture); 262 E("filtersTree").addEventListener(event, handler, capture);
186 }, 263 },
187 }; 264 };
188 265
189 window.addEventListener("load", function() 266 window.addEventListener("load", function()
190 { 267 {
191 FilterSearch.init(); 268 FilterSearch.init();
192 }, false); 269 }, false);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld