mobile/android/chrome/content/FindHelper.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4 "use strict";
michael@0 5
michael@0 6 var FindHelper = {
michael@0 7 _finder: null,
michael@0 8 _targetTab: null,
michael@0 9 _initialViewport: null,
michael@0 10 _viewportChanged: false,
michael@0 11
michael@0 12 observe: function(aMessage, aTopic, aData) {
michael@0 13 switch(aTopic) {
michael@0 14 case "FindInPage:Find":
michael@0 15 this.doFind(aData);
michael@0 16 break;
michael@0 17
michael@0 18 case "FindInPage:Prev":
michael@0 19 this.findAgain(aData, true);
michael@0 20 break;
michael@0 21
michael@0 22 case "FindInPage:Next":
michael@0 23 this.findAgain(aData, false);
michael@0 24 break;
michael@0 25
michael@0 26 case "Tab:Selected":
michael@0 27 case "FindInPage:Closed":
michael@0 28 this.findClosed();
michael@0 29 break;
michael@0 30 }
michael@0 31 },
michael@0 32
michael@0 33 doFind: function(aSearchString) {
michael@0 34 if (!this._finder) {
michael@0 35 this._targetTab = BrowserApp.selectedTab;
michael@0 36 this._finder = this._targetTab.browser.finder;
michael@0 37 this._finder.addResultListener(this);
michael@0 38 this._initialViewport = JSON.stringify(this._targetTab.getViewport());
michael@0 39 this._viewportChanged = false;
michael@0 40 }
michael@0 41
michael@0 42 this._finder.fastFind(aSearchString, false);
michael@0 43 },
michael@0 44
michael@0 45 findAgain: function(aString, aFindBackwards) {
michael@0 46 // This can happen if the user taps next/previous after re-opening the search bar
michael@0 47 if (!this._finder) {
michael@0 48 this.doFind(aString);
michael@0 49 return;
michael@0 50 }
michael@0 51
michael@0 52 this._finder.findAgain(aFindBackwards, false, false);
michael@0 53 },
michael@0 54
michael@0 55 findClosed: function() {
michael@0 56 // If there's no find in progress, there's nothing to clean up
michael@0 57 if (!this._finder)
michael@0 58 return;
michael@0 59
michael@0 60 this._finder.removeSelection();
michael@0 61 this._finder.removeResultListener(this);
michael@0 62 this._finder = null;
michael@0 63 this._targetTab = null;
michael@0 64 this._initialViewport = null;
michael@0 65 this._viewportChanged = false;
michael@0 66 },
michael@0 67
michael@0 68 onFindResult: function(aData) {
michael@0 69 if (aData.result == Ci.nsITypeAheadFind.FIND_NOTFOUND) {
michael@0 70 if (this._viewportChanged) {
michael@0 71 if (this._targetTab != BrowserApp.selectedTab) {
michael@0 72 // this should never happen
michael@0 73 Cu.reportError("Warning: selected tab changed during find!");
michael@0 74 // fall through and restore viewport on the initial tab anyway
michael@0 75 }
michael@0 76 this._targetTab.setViewport(JSON.parse(this._initialViewport));
michael@0 77 this._targetTab.sendViewportUpdate();
michael@0 78 }
michael@0 79 } else {
michael@0 80 // Disabled until bug 1014113 is fixed
michael@0 81 //ZoomHelper.zoomToRect(aData.rect, -1, false, true);
michael@0 82 this._viewportChanged = true;
michael@0 83 }
michael@0 84 }
michael@0 85 };

mercurial