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 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 focusContent: function() {} |
| 184 }, |
| 185 |
| 186 get _lastSearchString() |
| 187 { |
| 188 return this.finder.searchString; |
| 189 }, |
| 190 |
| 191 // This was used before Firefox 27 instead of the "finder" property. |
137 fastFind: | 192 fastFind: |
138 { | 193 { |
139 searchString: null, | 194 get searchString() |
| 195 { |
| 196 return FilterSearch.fakeBrowser.finder.searchString; |
| 197 }, |
| 198 |
| 199 set searchString(searchString) |
| 200 { |
| 201 FilterSearch.fakeBrowser.finder.searchString = searchString; |
| 202 }, |
| 203 |
140 foundLink: null, | 204 foundLink: null, |
141 foundEditable: null, | 205 foundEditable: null, |
142 caseSensitive: false, | 206 |
| 207 get caseSensitive() |
| 208 { |
| 209 return FilterSearch.fakeBrowser.finder.caseSensitive; |
| 210 }, |
| 211 |
| 212 set caseSensitive(caseSensitive) |
| 213 { |
| 214 FilterSearch.fakeBrowser.finder.caseSensitive = caseSensitive; |
| 215 }, |
| 216 |
143 get currentWindow() FilterSearch.fakeBrowser.contentWindow, | 217 get currentWindow() FilterSearch.fakeBrowser.contentWindow, |
144 | 218 |
145 find: function(searchString, linksOnly) | 219 find: function(searchString, linksOnly) |
146 { | 220 { |
147 this.searchString = searchString; | 221 FilterSearch.fakeBrowser.finder.fastFind(searchString, linksOnly); |
148 return FilterSearch.search(this.searchString, 0, this.caseSensitive); | 222 return FilterSearch.fakeBrowser.finder.lastResult; |
149 }, | 223 }, |
150 | 224 |
151 findAgain: function(findBackwards, linksOnly) | 225 findAgain: function(findBackwards, linksOnly) |
152 { | 226 { |
153 return FilterSearch.search(this.searchString, findBackwards ? -1 : 1, this
.caseSensitive); | 227 FilterSearch.fakeBrowser.finder.findAgain(findBackwards, linksOnly); |
| 228 return FilterSearch.fakeBrowser.finder.lastResult; |
154 }, | 229 }, |
155 | 230 |
156 // Irrelevant for us | 231 // Irrelevant for us |
157 init: function() {}, | 232 init: function() {}, |
158 setDocShell: function() {}, | 233 setDocShell: function() {}, |
159 setSelectionModeAndRepaint: function() {}, | 234 setSelectionModeAndRepaint: function() {}, |
160 collapseSelection: function() {} | 235 collapseSelection: function() {} |
161 }, | 236 }, |
162 currentURI: Utils.makeURI("http://example.com/"), | 237 currentURI: Utils.makeURI("http://example.com/"), |
163 contentWindow: | 238 contentWindow: |
(...skipping 19 matching lines...) Expand all Loading... |
183 removeEventListener: function(event, handler, capture) | 258 removeEventListener: function(event, handler, capture) |
184 { | 259 { |
185 E("filtersTree").addEventListener(event, handler, capture); | 260 E("filtersTree").addEventListener(event, handler, capture); |
186 }, | 261 }, |
187 }; | 262 }; |
188 | 263 |
189 window.addEventListener("load", function() | 264 window.addEventListener("load", function() |
190 { | 265 { |
191 FilterSearch.init(); | 266 FilterSearch.init(); |
192 }, false); | 267 }, false); |
OLD | NEW |