Bug 1382601 - update inspector to use new event emitter. r=nchevobbe,pbro

MozReview-Commit-ID: 8hGCpkC1eHz

--HG--
extra : rebase_source : bb5333bf3cf38a8c0d13249477e40fcd668eb71c
This commit is contained in:
yulia 2018-03-16 14:27:46 +01:00
parent 7ba09e30ed
commit 254e553c41
13 changed files with 35 additions and 19 deletions

View File

@ -56,7 +56,7 @@ function isNodeVisible(node) {
*/
function waitForUpdate(inspector, waitForSelectionUpdate) {
return new Promise(resolve => {
inspector.on("boxmodel-view-updated", function onUpdate(e, reasons) {
inspector.on("boxmodel-view-updated", function onUpdate(reasons) {
// Wait for another update event if we are waiting for a selection related event.
if (waitForSelectionUpdate && !reasons.includes("new-selection")) {
return;

View File

@ -15,7 +15,7 @@ const MAX_LABEL_LENGTH = 40;
const NS_XHTML = "http://www.w3.org/1999/xhtml";
const SCROLL_REPEAT_MS = 100;
const EventEmitter = require("devtools/shared/old-event-emitter");
const EventEmitter = require("devtools/shared/event-emitter");
const KeyShortcuts = require("devtools/client/shared/key-shortcuts");
// Some margin may be required for visible element detection.
@ -401,11 +401,12 @@ HTMLBreadcrumbs.prototype = {
this.breadcrumbsWidgetItemId = 0;
this.update = this.update.bind(this);
this.updateWithMutations = this.updateWithMutations.bind(this);
this.updateSelectors = this.updateSelectors.bind(this);
this.selection.on("new-node-front", this.update);
this.selection.on("pseudoclass", this.updateSelectors);
this.selection.on("attribute-changed", this.updateSelectors);
this.inspector.on("markupmutation", this.update);
this.inspector.on("markupmutation", this.updateWithMutations);
this.update();
},
@ -612,7 +613,7 @@ HTMLBreadcrumbs.prototype = {
this.selection.off("new-node-front", this.update);
this.selection.off("pseudoclass", this.updateSelectors);
this.selection.off("attribute-changed", this.updateSelectors);
this.inspector.off("markupmutation", this.update);
this.inspector.off("markupmutation", this.updateWithMutations);
this.container.removeEventListener("click", this, true);
this.container.removeEventListener("mouseover", this, true);
@ -829,6 +830,16 @@ HTMLBreadcrumbs.prototype = {
return false;
},
/**
* Update the breadcrumbs display when a new node is selected and there are
* mutations.
* @param {Array} mutations An array of mutations in case this was called as
* the "markupmutation" event listener.
*/
updateWithMutations(mutations) {
return this.update("markupmutation", mutations);
},
/**
* Update the breadcrumbs display when a new node is selected.
* @param {String} reason The reason for the update, if any.

View File

@ -8,7 +8,7 @@ const promise = require("promise");
const {Task} = require("devtools/shared/task");
const {KeyCodes} = require("devtools/client/shared/keycodes");
const EventEmitter = require("devtools/shared/old-event-emitter");
const EventEmitter = require("devtools/shared/event-emitter");
const AutocompletePopup = require("devtools/client/shared/autocomplete-popup");
const Services = require("Services");

View File

@ -10,7 +10,7 @@
const Services = require("Services");
const promise = require("promise");
const EventEmitter = require("devtools/shared/old-event-emitter");
const EventEmitter = require("devtools/shared/event-emitter");
const {executeSoon} = require("devtools/shared/DevToolsUtils");
const {Task} = require("devtools/shared/task");
const {PrefObserver} = require("devtools/client/shared/prefs");
@ -123,6 +123,7 @@ function Inspector(toolbox) {
this._onBeforeNavigate = this._onBeforeNavigate.bind(this);
this._onMarkupFrameLoad = this._onMarkupFrameLoad.bind(this);
this._updateSearchResultsLabel = this._updateSearchResultsLabel.bind(this);
this._clearSearchResultsLabel = this._clearSearchResultsLabel.bind(this);
this.onDetached = this.onDetached.bind(this);
this.onMarkupLoaded = this.onMarkupLoaded.bind(this);
@ -383,7 +384,7 @@ Inspector.prototype = {
this.searchResultsLabel = this.panelDoc.getElementById("inspector-searchlabel");
this.search = new InspectorSearch(this, this.searchBox, this.searchClearButton);
this.search.on("search-cleared", this._updateSearchResultsLabel);
this.search.on("search-cleared", this._clearSearchResultsLabel);
this.search.on("search-result", this._updateSearchResultsLabel);
let shortcuts = new KeyShortcuts({
@ -405,9 +406,13 @@ Inspector.prototype = {
return this.search.autocompleter;
},
_updateSearchResultsLabel: function(event, result) {
_clearSearchResultsLabel: function(result) {
return this._updateSearchResultsLabel(result, true);
},
_updateSearchResultsLabel: function(result, clear = false) {
let str = "";
if (event !== "search-cleared") {
if (!clear) {
if (result) {
str = INSPECTOR_L10N.getFormatStr(
"inspector.searchResultsCount2", result.resultsIndex + 1, result.resultsLength);
@ -559,7 +564,7 @@ Inspector.prototype = {
this.toolbox.emit("inspector-sidebar-resized", { width, height });
},
onSidebarSelect: function(event, toolId) {
onSidebarSelect: function(toolId) {
// Save the currently selected sidebar panel
Services.prefs.setCharPref("devtools.inspector.activeSidebar", toolId);

View File

@ -1283,7 +1283,7 @@ MarkupView.prototype = {
let parentContainer = this.getContainer(removedNode.parentNode());
let childIndex = parentContainer.getChildContainers().indexOf(oldContainer);
let onMutations = this._removedNodeObserver = (e, mutations) => {
let onMutations = this._removedNodeObserver = mutations => {
let isNodeRemovalMutation = false;
for (let mutation of mutations) {
let containsRemovedNode = mutation.removed &&

View File

@ -272,6 +272,6 @@ add_task(function* () {
});
// Record all containers that are created dynamically into elms object.
function memorizeContainer(event, container) {
function memorizeContainer(container) {
elms[`container-${containerID++}`] = container;
}

View File

@ -319,7 +319,7 @@ add_task(function* () {
// event or possibly in multiples.
let seenMutations = 0;
let promise = new Promise(resolve => {
inspector.on("markupmutation", function onmutation(e, mutations) {
inspector.on("markupmutation", function onmutation(mutations) {
seenMutations += mutations.length;
info("Receieved " + seenMutations +
" mutations, expecting at least " + numMutations);

View File

@ -547,7 +547,7 @@ ElementEditor.prototype = {
.filter(el => el.style.display != "none");
let attributeIndex = activeAttrs.indexOf(attrNode);
let onMutations = this._editedAttributeObserver = (e, mutations) => {
let onMutations = this._editedAttributeObserver = mutations => {
let isDeletedAttribute = false;
let isNewAttribute = false;

View File

@ -478,7 +478,7 @@ function* sendKeysAndWaitForFocus(view, element, keys) {
*/
function waitForStyleModification(inspector) {
return new Promise(function(resolve) {
function checkForStyleModification(name, mutations) {
function checkForStyleModification(mutations) {
for (let mutation of mutations) {
if (mutation.type === "attributes" && mutation.attributeName === "style") {
inspector.off("markupmutation", checkForStyleModification);

View File

@ -169,7 +169,7 @@ ClassListPreviewerModel.prototype = {
return mod.apply();
},
onMutations(e, mutations) {
onMutations(mutations) {
for (let {type, target, attributeName} of mutations) {
// Only care if this mutation is for the class attribute.
if (type !== "attributes" || attributeName !== "class") {

View File

@ -261,7 +261,7 @@ DomNodePreview.prototype = {
}
},
onMarkupMutations: function(e, mutations) {
onMarkupMutations: function(mutations) {
if (!this.nodeFront) {
return;
}

View File

@ -861,7 +861,7 @@ class HighlightersOverlay {
* Handler function for "markupmutation" events. Hides the flexbox/grid/shapes
* highlighter if the flexbox/grid/shapes container is no longer in the DOM tree.
*/
async onMarkupMutation(evt, mutations) {
async onMarkupMutation(mutations) {
let hasInterestingMutation = mutations.some(mut => mut.type === "childList");
if (!hasInterestingMutation) {
// Bail out if the mutations did not remove nodes, or if no grid highlighter is

View File

@ -6,7 +6,7 @@
"use strict";
var EventEmitter = require("devtools/shared/old-event-emitter");
var EventEmitter = require("devtools/shared/event-emitter");
var Telemetry = require("devtools/client/shared/telemetry");
var { Task } = require("devtools/shared/task");