[Pkg-mozext-commits] [adblock-plus] 40/98: Issue 4510 - Filter preferences: replace the built-in findbar widget by our own look-alike
David Prévot
taffit at moszumanska.debian.org
Tue Oct 24 01:30:16 UTC 2017
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit 752215ec33fe6af5daf92282653d52c5f9098249
Author: Wladimir Palant <trev at adblockplus.org>
Date: Tue Oct 11 10:39:24 2016 +0200
Issue 4510 - Filter preferences: replace the built-in findbar widget by our own look-alike
---
chrome/content/ui/filters-search.js | 260 ++++++++++++------------------------
chrome/content/ui/filters.xul | 21 ++-
chrome/locale/en-US/filters.dtd | 7 +
chrome/skin/filters.css | 47 ++++++-
4 files changed, 154 insertions(+), 181 deletions(-)
diff --git a/chrome/content/ui/filters-search.js b/chrome/content/ui/filters-search.js
index 68078d6..a6983f6 100644
--- a/chrome/content/ui/filters-search.js
+++ b/chrome/content/ui/filters-search.js
@@ -21,50 +21,85 @@
*/
var FilterSearch =
{
+ lastSearchString: null,
+
/**
- * Initializes findbar widget.
+ * Handles keypress events on the findbar widget.
*/
- init: function()
+ keyPress: function(/**Event*/ event)
{
- let filters = E("filtersTree");
- for (let prop in FilterSearch.fakeBrowser)
- filters[prop] = FilterSearch.fakeBrowser[prop];
- Object.defineProperty(filters, "_lastSearchString", {
- get: function()
- {
- return this.finder.searchString;
- },
- enumerable: true,
- configurable: true
- });
-
- let findbar = E("findbar");
- findbar.browser = filters;
-
- findbar.addEventListener("keypress", function(event)
+ if (event.keyCode == KeyEvent.DOM_VK_RETURN)
+ event.preventDefault();
+ else if (event.keyCode == KeyEvent.DOM_VK_ESCAPE)
+ {
+ event.preventDefault();
+ this.close();
+ }
+ else if (event.keyCode == KeyEvent.DOM_VK_UP)
+ {
+ event.preventDefault();
+ this.search(-1);
+ }
+ else if (event.keyCode == KeyEvent.DOM_VK_DOWN)
+ {
+ event.preventDefault();
+ this.search(1);
+ }
+ else if (event.keyCode == KeyEvent.DOM_VK_PAGE_UP)
+ {
+ event.preventDefault();
+ E("filtersTree").treeBoxObject.scrollByPages(-1);
+ }
+ else if (event.keyCode == KeyEvent.DOM_VK_PAGE_DOWN)
{
- // Work-around for bug 490047
- if (event.keyCode == KeyEvent.DOM_VK_RETURN)
- event.preventDefault();
- }, false);
+ event.preventDefault();
+ E("filtersTree").treeBoxObject.scrollByPages(1);
+ }
+ },
+
+ /**
+ * Makes the find bar visible and focuses it.
+ */
+ open: function()
+ {
+ E("findbar").hidden = false;
+ E("findbar-textbox").focus();
+ },
- // Hack to prevent "highlight all" from getting enabled
- findbar.toggleHighlight = function() {};
+ /**
+ * Closes the find bar.
+ */
+ close: function()
+ {
+ E("findbar").hidden = true;
},
/**
- * Performs a text search.
- * @param {String} text text to be searched
- * @param {Integer} direction search direction: -1 (backwards), 0 (forwards
- * starting with current), 1 (forwards starting with next)
- * @param {Boolean} caseSensitive if true, a case-sensitive search is performed
- * @result {Integer} one of the nsITypeAheadFind constants
+ * Performs a filter search.
+ * @param {Integer} [direction]
+ * See @link{FilterSearch#search}
+ * @return {String}
+ * result status, one of "" (success), "notFound", "wrappedEnd",
+ * "wrappedStart"
*/
- search: function(text, direction, caseSensitive)
+ _search: function(direction)
{
- function normalizeString(string) caseSensitive ? string : string.toLowerCase();
+ let text = E("findbar-textbox").value.trim();
+ if (!text)
+ return "";
+
+ let caseSensitive = E("findbar-case-sensitive").checked;
+
+ if (typeof direction == "undefined")
+ direction = (text == this.lastSearchString ? 1 : 0);
+ this.lastSearchString = text;
+
+ function normalizeString(string)
+ {
+ return caseSensitive ? string : string.toLowerCase();
+ }
- function findText(text, direction, startIndex)
+ function findText(startIndex)
{
let list = E("filtersTree");
let col = list.columns.getNamedColumn("col-filter");
@@ -84,11 +119,11 @@ var FilterSearch =
text = normalizeString(text);
// First try to find the entry in the current list
- if (findText(text, direction, E("filtersTree").currentIndex))
- return Ci.nsITypeAheadFind.FIND_FOUND;
+ if (findText(E("filtersTree").currentIndex))
+ return "";
// Now go through the other subscriptions
- let result = Ci.nsITypeAheadFind.FIND_FOUND;
+ let result = "";
let subscriptions = FilterStorage.subscriptions.slice();
subscriptions.sort((s1, s2) => (s1 instanceof SpecialSubscription) - (s2 instanceof SpecialSubscription));
let current = subscriptions.indexOf(FilterView.subscription);
@@ -98,12 +133,12 @@ var FilterSearch =
if (i < 0)
{
i = subscriptions.length - 1;
- result = Ci.nsITypeAheadFind.FIND_WRAPPED;
+ result = "wrappedStart";
}
else if (i >= subscriptions.length)
{
i = 0;
- result = Ci.nsITypeAheadFind.FIND_WRAPPED;
+ result = "wrappedEnd";
}
if (i == current)
break;
@@ -130,151 +165,28 @@ var FilterSearch =
Utils.runAsync(() => oldFocus.focus());
}
- Utils.runAsync(() => findText(text, direction, direction == 1 ? -1 : subscription.filters.length));
+ Utils.runAsync(() => findText(direction == 1 ? -1 : subscription.filters.length));
return result;
}
}
}
- return Ci.nsITypeAheadFind.FIND_NOTFOUND;
- }
-};
-
-/**
- * Fake browser implementation to make findbar widget happy - searches in
- * the filter list.
- */
-FilterSearch.fakeBrowser =
-{
- finder:
- {
- _resultListeners: [],
- searchString: null,
- caseSensitive: false,
- lastResult: null,
-
- _notifyResultListeners: function(result, findBackwards)
- {
- this.lastResult = result;
- for (let listener of this._resultListeners)
- {
- // See https://bugzilla.mozilla.org/show_bug.cgi?id=958101, starting
- // with Gecko 29 only one parameter is expected.
- try
- {
- if (listener.onFindResult.length == 1)
- {
- listener.onFindResult({searchString: this.searchString,
- result: result, findBackwards: findBackwards});
- }
- else
- listener.onFindResult(result, findBackwards);
- }
- catch (e)
- {
- Cu.reportError(e);
- }
- }
- },
-
- fastFind: function(searchString, linksOnly, drawOutline)
- {
- this.searchString = searchString;
- let result = FilterSearch.search(this.searchString, 0,
- this.caseSensitive);
- this._notifyResultListeners(result, false);
- },
-
- findAgain: function(findBackwards, linksOnly, drawOutline)
- {
- let result = FilterSearch.search(this.searchString,
- findBackwards ? -1 : 1,
- this.caseSensitive);
- this._notifyResultListeners(result, findBackwards);
- },
-
- addResultListener: function(listener)
- {
- if (this._resultListeners.indexOf(listener) === -1)
- this._resultListeners.push(listener);
- },
-
- removeResultListener: function(listener)
- {
- let index = this._resultListeners.indexOf(listener);
- if (index !== -1)
- this._resultListeners.splice(index, 1);
- },
-
- getInitialSelection: function()
- {
- for (let listener of this._resultListeners)
- listener.onCurrentSelection(null, true);
- },
-
- // Irrelevant for us
- requestMatchesCount: function(searchString, matchLimit, linksOnly) {},
- highlight: function(highlight, word) {},
- enableSelection: function() {},
- removeSelection: function() {},
- focusContent: function() {},
- keyPress: function() {}
+ return "notFound";
},
- currentURI: Utils.makeURI("http://example.com/"),
- contentWindow:
- {
- focus: function()
- {
- E("filtersTree").focus();
- },
- scrollByLines: function(num)
- {
- E("filtersTree").boxObject.scrollByLines(num);
- },
- scrollByPages: function(num)
- {
- E("filtersTree").boxObject.scrollByPages(num);
- },
- },
-
- messageManager:
+ /**
+ * Performs a filter search and displays the resulting search status.
+ * @param {Integer} [direction]
+ * search direction: -1 (backwards), 0 (forwards starting with current),
+ * 1 (forwards starting with next)
+ */
+ search: function(direction)
{
- _messageMap: {
- "Findbar:Mouseup": "mouseup",
- "Findbar:Keypress": "keypress"
- },
-
- _messageFromEvent: function(event)
- {
- for (let message in this._messageMap)
- if (this._messageMap[message] == event.type)
- return {target: event.currentTarget, name: message, data: event};
- return null;
- },
-
- addMessageListener: function(message, listener)
- {
- if (!this._messageMap.hasOwnProperty(message))
- return;
-
- if (!("_ABPHandler" in listener))
- listener._ABPHandler = (event) => listener.receiveMessage(this._messageFromEvent(event));
-
- E("filtersTree").addEventListener(this._messageMap[message], listener._ABPHandler, false);
- },
-
- removeMessageListener: function(message, listener)
- {
- if (this._messageMap.hasOwnProperty(message) && listener._ABPHandler)
- E("filtersTree").removeEventListener(this._messageMap[message], listener._ABPHandler, false);
- },
-
- sendAsyncMessage: function() {}
+ E("findbar").setAttribute("data-status", this._search(direction));
}
};
-window.addEventListener("load", function()
+window.addEventListener("load", event =>
{
- FilterSearch.init();
-}, false);
+ E("findbar").setAttribute("data-os", Services.appinfo.OS.toLowerCase());
+});
diff --git a/chrome/content/ui/filters.xul b/chrome/content/ui/filters.xul
index a083634..9298b2f 100644
--- a/chrome/content/ui/filters.xul
+++ b/chrome/content/ui/filters.xul
@@ -86,9 +86,9 @@
<command id="filters-copy-command" oncommand="FilterActions.copySelected(true);"/>
<command id="filters-cut-command" oncommand="FilterActions.copySelected(false);"/>
<command id="filters-paste-command" oncommand="FilterActions.paste();"/>
- <command id="find-command" oncommand="E('findbar').startFind(E('findbar').FIND_NORMAL)"/>
- <command id="find-again-command" oncommand="E('findbar').onFindAgainCommand(false)"/>
- <command id="find-previous-command" oncommand="E('findbar').onFindAgainCommand(true)"/>
+ <command id="find-command" oncommand="FilterSearch.open();"/>
+ <command id="find-again-command" oncommand="FilterSearch.search(1);"/>
+ <command id="find-previous-command" oncommand="FilterSearch.search(-1);"/>
</commandset>
<popupset id="filtersPopupset">
@@ -343,6 +343,7 @@
</button>
<button id="addFilterButton" label="&addFilter.label;" command="filters-add-command"/>
</hbox>
+
<tree id="filtersTree"
flex="1"
editable="true"
@@ -370,11 +371,21 @@
ondragstart="FilterActions.startDrag(event);"
ondragend="FilterActions.endDrag(event);"/>
</tree>
+
+ <hbox id="findbar" hidden="true" align="center" onkeypress="FilterSearch.keyPress(event);">
+ <toolbarbutton id="findbar-closebutton" tooltiptext="&findbar.close;" oncommand="FilterSearch.close();"/>
+ <textbox id="findbar-textbox" type="search" placeholder="&findbar.placeholder;" flex="1" oncommand="FilterSearch.search();"/>
+ <spinbuttons id="findbar-findAgain" onup="FilterSearch.search(-1);" ondown="FilterSearch.search(1);"/>
+ <button id="findbar-case-sensitive" type="checkbox" label="&findbar.caseSensitive;" oncommand="FilterSearch.search(0);"/>
+ <stack>
+ <label id="findbar-status-wrappedStart" class="findbar-status" value="&findbar.statusWrappedStart;"/>
+ <label id="findbar-status-wrappedEnd" class="findbar-status" value="&findbar.statusWrappedEnd;"/>
+ <label id="findbar-status-notFound" class="findbar-status" value="&findbar.statusNotFound;"/>
+ </stack>
+ </hbox>
</vbox>
</hbox>
-<findbar id="findbar"/>
-
<hbox id="buttons">
<button id="backupButton" type="menu"
label="&backupButton.label;"
diff --git a/chrome/locale/en-US/filters.dtd b/chrome/locale/en-US/filters.dtd
index 1ab4720..0041793 100644
--- a/chrome/locale/en-US/filters.dtd
+++ b/chrome/locale/en-US/filters.dtd
@@ -90,3 +90,10 @@
<!ENTITY find.label "Fi&nd">
<!ENTITY close.label "Close">
+
+<!ENTITY findbar.placeholder "Find filter">
+<!ENTITY findbar.close "Close find bar">
+<!ENTITY findbar.caseSensitive "Match Case">
+<!ENTITY findbar.statusWrappedStart "Reached top, continuing from bottom">
+<!ENTITY findbar.statusWrappedEnd "Reached bottom, continuing from top">
+<!ENTITY findbar.statusNotFound "Phrase not found">
diff --git a/chrome/skin/filters.css b/chrome/skin/filters.css
index 6a65632..a89023e 100644
--- a/chrome/skin/filters.css
+++ b/chrome/skin/filters.css
@@ -217,7 +217,50 @@ treechildren::-moz-tree-image(col-slow, slow-true)
list-style-image: url(slow.png);
}
-.findbar-highlight
+/* Findbar */
+
+#findbar-closebutton
{
- display: none;
+ list-style-image: url(close.png);
+ -moz-image-region: rect(0px, 14px, 14px, 0px);
+}
+
+#findbar-closebutton:hover
+{
+ -moz-image-region: rect(0px, 28px, 14px, 14px);
+}
+
+#findbar-closebutton:active
+{
+ -moz-image-region: rect(0px, 42px, 14px, 28px);
+}
+
+#findbar[data-status="notFound"] > #findbar-textbox
+{
+ /* We cannot change background color because of -moz-appearance but a red */
+ /* shadow works. */
+ box-shadow: 0 0 1.5px 1px red;
+}
+
+#findbar[data-status="notFound"] > #findbar-textbox[focused="true"]
+{
+ box-shadow: 0 0 2px 2px rgba(255, 0, 0, 0.4);
+}
+
+#findbar[data-os="darwin"] > #findbar-case-sensitive[checked="true"]
+{
+ /* Firefox on Mac doesn't indicate checked buttons, do it ourselves */
+ filter: brightness(70%);
+}
+
+.findbar-status
+{
+ font-size: 80%;
+}
+
+#findbar:not([data-status="wrappedStart"]) #findbar-status-wrappedStart,
+#findbar:not([data-status="wrappedEnd"]) #findbar-status-wrappedEnd,
+#findbar:not([data-status="notFound"]) #findbar-status-notFound
+{
+ visibility: hidden;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git
More information about the Pkg-mozext-commits
mailing list