Bug 908079 - Don't display code segments in the metrofx console by default, avoids a bad hang when displaying the console for the first time. r=ally

This commit is contained in:
Jim Mathies 2014-02-13 07:33:57 -06:00
parent 31c737cc71
commit 3c95c29c04
5 changed files with 68 additions and 33 deletions

View File

@ -3,7 +3,6 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<!DOCTYPE bindings [
<!ENTITY % browserDTD SYSTEM "chrome://browser/locale/browser.dtd">
%browserDTD;
@ -13,7 +12,6 @@
xmlns="http://www.mozilla.org/xbl"
xmlns:xbl="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="error" extends="chrome://browser/content/bindings/bindings.xml#richlistitem">
<content orient="vertical">
<xul:hbox class="console-row-internal-box" flex="1">
@ -22,7 +20,6 @@
<xul:label class="label title" xbl:inherits="value=typetext"/>
<xul:description class="console-error-msg title" xbl:inherits="xbl:text=msg" flex="1"/>
</xul:hbox>
<xul:hbox class="console-row-file" xbl:inherits="hidden=hideSource">
<xul:label class="label title" value="&consoleErrFile.label;"/>
<xul:label class="title" xbl:inherits="value=href" crop="right"/>
@ -32,20 +29,13 @@
<xul:label class="label title" xbl:inherits="value=line"/>
</xul:hbox>
</xul:hbox>
<xul:vbox class="console-row-code" xbl:inherits="hidden=hideCode">
<xul:label class="monospace console-code" xbl:inherits="value=code" crop="end"/>
<xul:hbox xbl:inherits="hidden=hideCaret">
<xul:label class="monospace console-dots title" xbl:inherits="value=errorDots"/>
<xul:label class="monospace console-caret title" xbl:inherits="value=errorCaret"/>
<xul:spacer flex="1"/>
</xul:hbox>
</xul:vbox>
</xul:vbox>
</xul:hbox>
</content>
</binding>
<binding id="message" extends="chrome://browser/content/bindings/bindings.xml#richlistitem">
<content>
<xul:hbox class="console-internal-box" flex="1">
@ -57,5 +47,4 @@
</xul:hbox>
</content>
</binding>
</bindings>

View File

@ -588,7 +588,9 @@ Desktop browser's sync prefs.
</hbox>
<hbox align="center"
pack="end">
<radiogroup id="console-filter"
<checkbox id="console-follow-checkbox" label="&consoleFollowCheckbox.label;" checked="true"/>
<spacer flex="1"/>
<radiogroup id="console-filter" orient="horizontal"
oncommand="ConsolePanelView.changeMode();">
<radio id="console-filter-all"
value="all"

View File

@ -13,6 +13,14 @@ let ConsolePanelView = {
_showChromeErrors: -1,
_enabledPref: "devtools.errorconsole.enabled",
get enabled() {
return Services.prefs.getBoolPref(this._enabledPref);
},
get follow() {
return document.getElementById("console-follow-checkbox").checked;
},
init: function cv_init() {
if (this._list)
return;
@ -23,6 +31,7 @@ let ConsolePanelView = {
this._count = 0;
this.limit = 250;
this.fieldMaxLength = 140;
try {
// update users using the legacy pref
@ -63,10 +72,6 @@ let ConsolePanelView = {
Services.prefs.removeObserver(this._enabledPref, this, false);
},
get enabled() {
return Services.prefs.getBoolPref(this._enabledPref);
},
observe: function(aSubject, aTopic, aData) {
if (aTopic == "nsPref:changed") {
// We may choose to create a new menu in v2
@ -89,6 +94,7 @@ let ConsolePanelView = {
},
appendItem: function cv_appendItem(aObject) {
let index = -1;
try {
// Try to QI it to a script error to get more info
let scriptError = aObject.QueryInterface(Ci.nsIScriptError);
@ -96,7 +102,7 @@ let ConsolePanelView = {
// filter chrome urls
if (!this.showChromeErrors && scriptError.sourceName.substr(0, 9) == "chrome://")
return;
this.appendError(scriptError);
index = this.appendError(scriptError);
}
catch (ex) {
try {
@ -104,15 +110,31 @@ let ConsolePanelView = {
let msg = aObject.QueryInterface(Ci.nsIConsoleMessage);
if (msg.message)
this.appendMessage(msg.message);
index = this.appendMessage(msg.message);
else // observed a null/"clear" message
this.clearConsole();
}
catch (ex2) {
// Give up and append the object itself as a string
this.appendMessage(aObject);
index = this.appendMessage(aObject);
}
}
if (this.follow) {
Util.dumpLn(index);
this._list.ensureIndexIsVisible(index);
}
},
truncateIfNecessary: function (aString) {
if (!aString || aString.length <= this.fieldMaxLength) {
return aString;
}
let truncatedString = aString.substring(0, this.fieldMaxLength);
let Ci = Components.interfaces;
let ellipsis = Services.prefs.getComplexValue("intl.ellipsis",
Ci.nsIPrefLocalizedString).data;
truncatedString = truncatedString + ellipsis;
return truncatedString;
},
appendError: function cv_appendError(aObject) {
@ -134,26 +156,26 @@ let ConsolePanelView = {
else {
row.setAttribute("hideSource", "true");
}
// hide code by default, otherwise initial item display will
// hang the browser.
row.setAttribute("hideCode", "true");
row.setAttribute("hideCaret", "true");
if (aObject.sourceLine) {
row.setAttribute("code", aObject.sourceLine.replace(/\s/g, " "));
row.setAttribute("code", this.truncateIfNecessary(aObject.sourceLine.replace(/\s/g, " ")));
if (aObject.columnNumber) {
row.setAttribute("col", aObject.columnNumber);
row.setAttribute("errorDots", this.repeatChar(" ", aObject.columnNumber));
row.setAttribute("errorCaret", " ");
}
else {
row.setAttribute("hideCaret", "true");
}
}
else {
row.setAttribute("hideCode", "true");
}
let mode = document.getElementById("console-filter").value;
if (mode != "all" && mode != row.getAttribute("type"))
if (mode != "all" && mode != row.getAttribute("type")) {
row.collapsed = true;
}
row.setAttribute("onclick", "ConsolePanelView.onRowClick(this)");
this.appendConsoleRow(row);
return this._list.getIndexOfItem(row);
},
appendMessage: function cv_appendMessage (aMessage) {
@ -166,6 +188,7 @@ let ConsolePanelView = {
row.collapsed = true;
this.appendConsoleRow(row);
return this._list.getIndexOfItem(row);
},
createConsoleRow: function cv_createConsoleRow() {
@ -176,8 +199,9 @@ let ConsolePanelView = {
appendConsoleRow: function cv_appendConsoleRow(aRow) {
this._list.appendChild(aRow);
if (++this._count > this.limit)
if (++this._count > this.limit) {
this.deleteFirst();
}
},
deleteFirst: function cv_deleteFirst() {
@ -187,6 +211,7 @@ let ConsolePanelView = {
},
appendInitialItems: function cv_appendInitialItems() {
this._list.collapsed = true;
let messages = Services.console.getMessageArray();
// In case getMessageArray returns 0-length array as null
@ -198,13 +223,17 @@ let ConsolePanelView = {
limit = 0;
// Checks if console ever been cleared
for (var i = messages.length - 1; i >= limit; --i)
if (!messages[i].message)
for (var i = messages.length - 1; i >= limit; --i) {
if (!messages[i].message) {
break;
}
}
// Populate with messages after latest "clear"
while (++i < messages.length)
while (++i < messages.length) {
this.appendItem(messages[i]);
}
this._list.collapsed = false;
},
clearConsole: function cv_clearConsole() {
@ -250,6 +279,15 @@ let ConsolePanelView = {
});
},
onRowClick: function (aRow) {
if (aRow.hasAttribute("code")) {
aRow.setAttribute("hideCode", "false");
}
if (aRow.hasAttribute("col")) {
aRow.setAttribute("hideCaret", "false");
}
},
onEvalKeyPress: function cv_onEvalKeyPress(aEvent) {
if (aEvent.keyCode == 13)
this.evaluateTypein();

View File

@ -63,6 +63,7 @@
<!ENTITY consoleErrFile.label "Source File:">
<!ENTITY consoleErrLine.label "Line:">
<!ENTITY consoleErrColumn.label "Column:">
<!ENTITY consoleFollowCheckbox.label "Follow">
<!-- TEXT CONTEXT MENU -->
<!ENTITY contextTextCut.label "Cut">

View File

@ -922,3 +922,8 @@ appbar toolbar[labelled] toolbarbutton > .toolbarbutton-text {
.flyout-narrow .flyoutpanel-hack {
max-width: calc(346px - 2 * 40px);
}
.console-row-code {
padding-top: 2px;
font-size: small;
}