зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1265759 - Create an HTML replacement for inspector Search Box;r=gl
MozReview-Commit-ID: Elt4NGNh3Pf
This commit is contained in:
Родитель
bf696aae6c
Коммит
40b39ddc7b
|
@ -353,9 +353,10 @@ InspectorPanel.prototype = {
|
|||
*/
|
||||
setupSearchBox: function () {
|
||||
this.searchBox = this.panelDoc.getElementById("inspector-searchbox");
|
||||
this.searchClearButton = this.panelDoc.getElementById("inspector-searchinput-clear");
|
||||
this.searchResultsLabel = this.panelDoc.getElementById("inspector-searchlabel");
|
||||
|
||||
this.search = new InspectorSearch(this, this.searchBox);
|
||||
this.search = new InspectorSearch(this, this.searchBox, this.searchClearButton);
|
||||
this.search.on("search-cleared", this._updateSearchResultsLabel);
|
||||
this.search.on("search-result", this._updateSearchResultsLabel);
|
||||
|
||||
|
@ -1456,7 +1457,8 @@ InspectorPanel.prototype = {
|
|||
|
||||
/**
|
||||
* Paste the contents of the clipboard as adjacent HTML to the selected Node.
|
||||
* @param position The position as specified for Element.insertAdjacentHTML
|
||||
* @param position
|
||||
* The position as specified for Element.insertAdjacentHTML
|
||||
* (i.e. "beforeBegin", "afterBegin", "beforeEnd", "afterEnd").
|
||||
*/
|
||||
pasteAdjacentHTML: function (position) {
|
||||
|
@ -1516,8 +1518,8 @@ InspectorPanel.prototype = {
|
|||
/**
|
||||
* Copy the content of a longString (via a promise resolving a
|
||||
* LongStringActor) to the clipboard
|
||||
* @param {Promise} longStringActorPromise promise expected to
|
||||
* resolve a LongStringActor instance
|
||||
* @param {Promise} longStringActorPromise
|
||||
* promise expected to resolve a LongStringActor instance
|
||||
* @return {Promise} promise resolving (with no argument) when the
|
||||
* string is sent to the clipboard
|
||||
*/
|
||||
|
@ -1529,8 +1531,8 @@ InspectorPanel.prototype = {
|
|||
|
||||
/**
|
||||
* Retrieve the content of a longString (via a promise resolving a LongStringActor)
|
||||
* @param {Promise} longStringActorPromise promise expected to
|
||||
* resolve a LongStringActor instance
|
||||
* @param {Promise} longStringActorPromise
|
||||
* promise expected to resolve a LongStringActor instance
|
||||
* @return {Promise} promise resolving with the retrieved string as argument
|
||||
*/
|
||||
_getLongString: function (longStringActorPromise) {
|
||||
|
|
|
@ -4,9 +4,6 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
/* eslint-disable mozilla/reject-some-requires */
|
||||
const {Ci} = require("chrome");
|
||||
/* eslint-enable mozilla/reject-some-requires */
|
||||
const promise = require("promise");
|
||||
const {Task} = require("devtools/shared/task");
|
||||
|
||||
|
@ -20,24 +17,33 @@ const MAX_SUGGESTIONS = 15;
|
|||
/**
|
||||
* Converts any input field into a document search box.
|
||||
*
|
||||
* @param {InspectorPanel} inspector The InspectorPanel whose `walker` attribute
|
||||
* should be used for document traversal.
|
||||
* @param {DOMNode} input The input element to which the panel will be attached
|
||||
* and from where search input will be taken.
|
||||
* @param {InspectorPanel} inspector
|
||||
* The InspectorPanel whose `walker` attribute should be used for
|
||||
* document traversal.
|
||||
* @param {DOMNode} input
|
||||
* The input element to which the panel will be attached and from where
|
||||
* search input will be taken.
|
||||
* @param {DOMNode} clearBtn
|
||||
* The clear button in the input field that will clear the input value.
|
||||
*
|
||||
* Emits the following events:
|
||||
* - search-cleared: when the search box is emptied
|
||||
* - search-result: when a search is made and a result is selected
|
||||
*/
|
||||
function InspectorSearch(inspector, input) {
|
||||
function InspectorSearch(inspector, input, clearBtn) {
|
||||
this.inspector = inspector;
|
||||
this.searchBox = input;
|
||||
this.searchClearButton = clearBtn;
|
||||
this._lastSearched = null;
|
||||
|
||||
this.searchClearButton.hidden = true;
|
||||
|
||||
this._onKeyDown = this._onKeyDown.bind(this);
|
||||
this._onCommand = this._onCommand.bind(this);
|
||||
this._onInput = this._onInput.bind(this);
|
||||
this._onClearSearch = this._onClearSearch.bind(this);
|
||||
this.searchBox.addEventListener("keydown", this._onKeyDown, true);
|
||||
this.searchBox.addEventListener("command", this._onCommand, true);
|
||||
this.searchBox.addEventListener("input", this._onInput, true);
|
||||
this.searchClearButton.addEventListener("click", this._onClearSearch);
|
||||
|
||||
// For testing, we need to be able to wait for the most recent node request
|
||||
// to finish. Tests can watch this promise for that.
|
||||
|
@ -56,8 +62,10 @@ InspectorSearch.prototype = {
|
|||
|
||||
destroy: function () {
|
||||
this.searchBox.removeEventListener("keydown", this._onKeyDown, true);
|
||||
this.searchBox.removeEventListener("command", this._onCommand, true);
|
||||
this.searchBox.removeEventListener("input", this._onInput, true);
|
||||
this.searchClearButton.removeEventListener("click", this._onClearSearch);
|
||||
this.searchBox = null;
|
||||
this.searchClearButton = null;
|
||||
this.autocompleter.destroy();
|
||||
},
|
||||
|
||||
|
@ -97,7 +105,7 @@ InspectorSearch.prototype = {
|
|||
}
|
||||
}),
|
||||
|
||||
_onCommand: function () {
|
||||
_onInput: function () {
|
||||
if (this.searchBox.value.length === 0) {
|
||||
this._onSearch();
|
||||
}
|
||||
|
@ -105,8 +113,10 @@ InspectorSearch.prototype = {
|
|||
|
||||
_onKeyDown: function (event) {
|
||||
if (this.searchBox.value.length === 0) {
|
||||
this.searchClearButton.hidden = true;
|
||||
this.searchBox.removeAttribute("filled");
|
||||
} else {
|
||||
this.searchClearButton.hidden = false;
|
||||
this.searchBox.setAttribute("filled", true);
|
||||
}
|
||||
if (event.keyCode === event.DOM_VK_RETURN) {
|
||||
|
@ -115,10 +125,15 @@ InspectorSearch.prototype = {
|
|||
|
||||
const modifierKey = system.constants.platform === "macosx"
|
||||
? event.metaKey : event.ctrlKey;
|
||||
if (event.keyCode === Ci.nsIDOMKeyEvent.DOM_VK_G && modifierKey) {
|
||||
if (event.keyCode === event.DOM_VK_G && modifierKey) {
|
||||
this._onSearch(event.shiftKey);
|
||||
event.preventDefault();
|
||||
}
|
||||
},
|
||||
|
||||
_onClearSearch: function () {
|
||||
this.searchBox.value = "";
|
||||
this.searchClearButton.hidden = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -40,11 +40,12 @@
|
|||
class="devtools-button" />
|
||||
<html:div class="devtools-toolbar-spacer" />
|
||||
<html:span id="inspector-searchlabel" />
|
||||
<textbox id="inspector-searchbox"
|
||||
<html:div id="inspector-search" class="devtools-searchbox">
|
||||
<html:input id="inspector-searchbox" class="devtools-searchinput"
|
||||
type="search"
|
||||
timeout="50"
|
||||
class="devtools-searchinput"
|
||||
placeholder="&inspectorSearchHTML.label3;"/>
|
||||
<html:button id="inspector-searchinput-clear" class="devtools-searchinput-clear" tabindex="-1"></html:button>
|
||||
</html:div>
|
||||
<html:button id="inspector-eyedropper-toggle"
|
||||
title="&inspectorEyeDropper.label;"
|
||||
class="devtools-button command-button-invertable" />
|
||||
|
|
|
@ -141,7 +141,7 @@ add_task(function* () {
|
|||
for (let { key, suggestions } of TEST_DATA) {
|
||||
info("Pressing " + key + " to get " + formatSuggestions(suggestions));
|
||||
|
||||
let command = once(searchBox, "command");
|
||||
let command = once(searchBox, "input");
|
||||
EventUtils.synthesizeKey(key, {}, inspector.panelWin);
|
||||
yield command;
|
||||
|
||||
|
|
|
@ -222,7 +222,7 @@ add_task(function* () {
|
|||
for (let { key, suggestions } of TEST_DATA) {
|
||||
info("Pressing " + key + " to get " + formatSuggestions(suggestions));
|
||||
|
||||
let command = once(searchBox, "command");
|
||||
let command = once(searchBox, "input");
|
||||
EventUtils.synthesizeKey(key, {}, inspector.panelWin);
|
||||
yield command;
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ add_task(function* () {
|
|||
for (let {key, suggestions} of TEST_DATA) {
|
||||
info("Pressing " + key + " to get " + formatSuggestions(suggestions));
|
||||
|
||||
let command = once(searchBox, "command");
|
||||
let command = once(searchBox, "input");
|
||||
EventUtils.synthesizeKey(key, {}, inspector.panelWin);
|
||||
yield command;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ add_task(function* () {
|
|||
for (let {key, suggestions} of TEST_DATA) {
|
||||
info("Pressing " + key + " to get " + suggestions);
|
||||
|
||||
let command = once(searchBox, "command");
|
||||
let command = once(searchBox, "input");
|
||||
EventUtils.synthesizeKey(key, {}, inspector.panelWin);
|
||||
yield command;
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ add_task(function* () {
|
|||
for (let {key, suggestions} of TEST_DATA) {
|
||||
info("Pressing " + key + " to get " + suggestions.join(", "));
|
||||
|
||||
let command = once(searchBox, "command");
|
||||
let command = once(searchBox, "input");
|
||||
EventUtils.synthesizeKey(key, {}, inspector.panelWin);
|
||||
yield command;
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ add_task(function* () {
|
|||
for (let { key, suggestions } of TEST_DATA) {
|
||||
info("Pressing " + key + " to get " + formatSuggestions(suggestions));
|
||||
|
||||
let command = once(searchBox, "command");
|
||||
let command = once(searchBox, "input");
|
||||
EventUtils.synthesizeKey(key, {}, inspector.panelWin);
|
||||
yield command;
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ add_task(function* () {
|
|||
info("pressing key " + key + " to get suggestions " +
|
||||
JSON.stringify(expectedSuggestions));
|
||||
|
||||
let onCommand = once(searchBox, "command", true);
|
||||
let onCommand = once(searchBox, "input", true);
|
||||
EventUtils.synthesizeKey(key, {}, inspector.panelWin);
|
||||
yield onCommand;
|
||||
|
||||
|
|
|
@ -27,6 +27,18 @@
|
|||
|
||||
#inspector-searchlabel {
|
||||
overflow: hidden;
|
||||
margin-inline-end: 2px;
|
||||
}
|
||||
|
||||
#inspector-search {
|
||||
flex: unset;
|
||||
}
|
||||
|
||||
/* TODO: bug 1265759: should apply to .devtools-searchinput once all searchbox
|
||||
is converted to html*/
|
||||
#inspector-searchbox {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Make sure the text is vertically centered in Inspector's
|
||||
|
|
|
@ -26,9 +26,7 @@
|
|||
let inspector = toolbox.getPanel("inspector");
|
||||
inspector.searchBox.focus();
|
||||
|
||||
// Use the binding element since inspector.searchBox is a XUL element.
|
||||
let activeElement = getActiveElement(inspector.panelDoc);
|
||||
activeElement = activeElement.ownerDocument.getBindingParent(activeElement);
|
||||
is(activeElement, inspector.searchBox, "Search box is focused");
|
||||
|
||||
yield toolbox.openSplitConsole();
|
||||
|
@ -45,9 +43,7 @@
|
|||
|
||||
info("Making sure that the search box is refocused after closing the " +
|
||||
"split console");
|
||||
// Use the binding element since inspector.searchBox is a XUL element.
|
||||
activeElement = getActiveElement(inspector.panelDoc);
|
||||
activeElement = activeElement.ownerDocument.getBindingParent(activeElement);
|
||||
is(activeElement, inspector.searchBox, "Search box is focused");
|
||||
|
||||
yield toolbox.destroy();
|
||||
|
|
Загрузка…
Ссылка в новой задаче