0

Is there a way use findbar for non-browser element?

I'm trying adopt findbar to use it on listbox in a prefwindow.

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
vanowm
  • 9,466
  • 2
  • 21
  • 37

1 Answers1

1

Unfortunately, the <findbar> widget is really meant to be used with a browser element. You can use it with other data if you fake the necessary browser APIs but there is no guarantee whatsoever that it will continue to work in future. In particular, the APIs in question changed from synchronous to asynchonous in Firefox 26 which broke every extension that was implementing them such as Adblock Plus or Stylish.

In the implementation of the <findbar> widget you can see what it currently expects from a browser:

Components.utils.import("resource://gre/modules/Services.jsm");

var fakeBrowser = {
  finder: new Finder(),
  _lastSearchString: "",
  _lastSearchHighlight: false,
  currentURI: Services.io.newURI("http://example.com/"),
  contentWindow: null,
  addEventListener: function() {}
  removeEventListener: function() {},
};

This fake browser can be assigned to the findbar.browser property. The important part here is the finder property, normally that's a Finder object defined by Finder.jsm. You would want to implement your own object providing the same API of course.

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
  • Thank you. I started playing around with Finder.jsm and for listbox I think I'd be better off just start from scratch using fakeBrowser as you suggested. And perhaps for better compatibility I should probably use my own copy of findbar.xml xbl too, in case it changes in the future. – vanowm Apr 15 '14 at 02:00
  • @vanowm: Been there, done that. The downside here is that you cannot style your findbar widget the same way the browser does. You can leave the styling up to the browser but then you risk breakage again if styles meant for a newer findbar version apply to yours. You can use your own copy of the findbar styles - but the browser actually has different findbar styles for each operating system (plus custom themes of course). And even if you include all three style files in your extension then your findbar might start looking outdated after a few browser releases. – Wladimir Palant Apr 15 '14 at 05:42