Skip to content

Commit

Permalink
Merge mozilla-central to autoland a=merge
Browse files Browse the repository at this point in the history
  • Loading branch information
ccoroiu committed Nov 29, 2018
2 parents ed44165 + e92b0f1 commit 3ba5c15
Show file tree
Hide file tree
Showing 149 changed files with 4,015 additions and 873 deletions.
1 change: 1 addition & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ xpcom/tests/.*
.*/.*.pb.cc

# Autogenerated file
gfx/gl/GLConsts.h
gfx/webrender_bindings/webrender_ffi_generated.h
intl/unicharutil/util/nsUnicodePropertyData.cpp
intl/unicharutil/util/nsUnicodeScriptCodes.h
Expand Down
5 changes: 5 additions & 0 deletions browser/components/aboutconfig/content/aboutconfig.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@
.cell-value {
word-break: break-all;
}

td.cell-value > form > input[type="text"] {
width: 100%;
box-sizing: border-box;
}
190 changes: 179 additions & 11 deletions browser/components/aboutconfig/content/aboutconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ ChromeUtils.import("resource://gre/modules/Preferences.jsm");

let gDefaultBranch = Services.prefs.getDefaultBranch("");
let gPrefArray;
let gPrefRowInEdit;
let gPrefInEdit;

function getPrefName(prefRow) {
return prefRow.getAttribute("aria-label");
}

function onLoad() {
gPrefArray = Services.prefs.getChildList("").map(function(name) {
Expand All @@ -33,7 +39,7 @@ function onLoad() {
gPrefArray.sort((a, b) => a.name > b.name);

document.getElementById("search").addEventListener("keypress", function(e) {
if (e.code == "Enter") {
if (e.key == "Enter") {
filterPrefs();
}
});
Expand All @@ -43,32 +49,68 @@ function onLoad() {
return;
}
let prefRow = event.target.closest("tr");
let prefName = prefRow.getAttribute("aria-label");
let prefName = getPrefName(prefRow);
let pref = gPrefArray.find(p => p.name == prefName);
let button = event.target.closest("button");
if (button.classList.contains("button-reset")) {
// Reset pref and update gPrefArray.
Services.prefs.clearUserPref(prefName);
let pref = gPrefArray.find(p => p.name == prefName);
pref.value = Preferences.get(prefName);
pref.hasUserValue = false;
// Update UI.
prefRow.textContent = "";
prefRow.classList.remove("has-user-value");
prefRow.appendChild(getPrefRow(pref));
prefRow.querySelector("td.cell-edit").firstChild.focus();
} else if (button.classList.contains("add-true")) {
addNewPref(prefRow.firstChild.innerHTML, true);
} else if (button.classList.contains("add-false")) {
addNewPref(prefRow.firstChild.innerHTML, false);
} else if (button.classList.contains("add-Number") ||
button.classList.contains("add-String")) {
addNewPref(prefRow.firstChild.innerHTML,
button.classList.contains("add-Number") ? 0 : "");
prefRow = [...document.getElementById("prefs").getElementsByTagName("tr")]
.find(row => row.querySelector("td").textContent == prefName);
startEditingPref(prefRow, gPrefArray.find(p => p.name == prefName));
prefRow.querySelector("td.cell-value").firstChild.firstChild.focus();
} else if (button.classList.contains("button-toggle")) {
// Toggle the pref and update gPrefArray.
Services.prefs.setBoolPref(prefName, !pref.value);
pref.value = !pref.value;
pref.hasUserValue = Services.prefs.prefHasUserValue(pref.name);
// Update UI.
prefRow.textContent = "";
if (pref.hasUserValue) {
prefRow.classList.add("has-user-value");
} else {
prefRow.classList.remove("has-user-value");
}
prefRow.appendChild(getPrefRow(pref));
prefRow.querySelector("td.cell-edit").firstChild.focus();
} else if (button.classList.contains("button-edit")) {
startEditingPref(prefRow, pref);
prefRow.querySelector("td.cell-value").firstChild.firstChild.focus();
} else if (button.classList.contains("button-save")) {
endEditingPref(prefRow);
prefRow.querySelector("td.cell-edit").firstChild.focus();
} else {
Services.prefs.clearUserPref(prefName);
gPrefArray.splice(gPrefArray.findIndex(pref => pref.name == prefName), 1);
gPrefArray.splice(gPrefArray.findIndex(p => p.name == prefName), 1);
prefRow.remove();
}
});

document.getElementById("prefs").appendChild(createPrefsFragment(gPrefArray));
filterPrefs();
}

function filterPrefs() {
let substring = document.getElementById("search").value.trim();
let fragment = createPrefsFragment(gPrefArray.filter(pref => pref.name.includes(substring)));
document.getElementById("prefs").textContent = "";
if (substring && !gPrefArray.some(pref => pref.name == substring)) {
document.getElementById("prefs").appendChild(createNewPrefFragment(substring));
}
let fragment = createPrefsFragment(gPrefArray.filter(pref => pref.name.includes(substring)));
document.getElementById("prefs").appendChild(fragment);
}

Expand All @@ -87,6 +129,38 @@ function createPrefsFragment(prefArray) {
return fragment;
}

function createNewPrefFragment(name) {
let fragment = document.createDocumentFragment();
let row = document.createElement("tr");
row.classList.add("has-user-value");
row.setAttribute("aria-label", name);
let nameCell = document.createElement("td");
nameCell.append(name);
row.appendChild(nameCell);

let valueCell = document.createElement("td");
valueCell.classList.add("cell-value");
let guideText = document.createElement("span");
document.l10n.setAttributes(guideText, "about-config-pref-add");
valueCell.appendChild(guideText);
for (let item of ["true", "false", "Number", "String"]) {
let optionBtn = document.createElement("button");
optionBtn.textContent = item;
optionBtn.classList.add("add-" + item);
valueCell.appendChild(optionBtn);
}
row.appendChild(valueCell);

let editCell = document.createElement("td");
row.appendChild(editCell);

let buttonCell = document.createElement("td");
row.appendChild(buttonCell);

fragment.appendChild(row);
return fragment;
}

function getPrefRow(pref) {
let rowFragment = document.createDocumentFragment();
let nameCell = document.createElement("td");
Expand All @@ -103,21 +177,103 @@ function getPrefRow(pref) {
valueCell.textContent = pref.value;
rowFragment.appendChild(valueCell);

let editCell = document.createElement("td");
editCell.className = "cell-edit";
let button = document.createElement("button");
if (Services.prefs.getPrefType(pref.name) == Services.prefs.PREF_BOOL) {
document.l10n.setAttributes(button, "about-config-pref-toggle");
button.className = "button-toggle";
} else {
document.l10n.setAttributes(button, "about-config-pref-edit");
button.className = "button-edit";
}
editCell.appendChild(button);
rowFragment.appendChild(editCell);

let buttonCell = document.createElement("td");
if (pref.hasUserValue) {
let button = document.createElement("button");
let resetButton = document.createElement("button");
if (!pref.hasDefaultValue) {
document.l10n.setAttributes(button, "about-config-pref-delete");
document.l10n.setAttributes(resetButton, "about-config-pref-delete");
} else {
document.l10n.setAttributes(button, "about-config-pref-reset");
button.className = "button-reset";
document.l10n.setAttributes(resetButton, "about-config-pref-reset");
resetButton.className = "button-reset";
}
buttonCell.appendChild(button);
buttonCell.appendChild(resetButton);
}
rowFragment.appendChild(buttonCell);
return rowFragment;
}

function startEditingPref(row, arrayEntry) {
if (gPrefRowInEdit != undefined) {
// Abort editing-process first.
gPrefRowInEdit.textContent = "";
gPrefRowInEdit.appendChild(getPrefRow(gPrefInEdit));
}
gPrefRowInEdit = row;

let name = getPrefName(row);
gPrefInEdit = arrayEntry;

let valueCell = row.querySelector("td.cell-value");
let oldValue = valueCell.textContent;
valueCell.textContent = "";
// The form is needed for the invalid-tooltip to appear.
let form = document.createElement("form");
form.id = "form-" + name;
let inputField = document.createElement("input");
inputField.type = "text";
inputField.value = oldValue;
if (Services.prefs.getPrefType(name) == Services.prefs.PREF_INT) {
inputField.setAttribute("pattern", "-?[0-9]*");
document.l10n.setAttributes(inputField, "about-config-pref-input-number");
} else {
document.l10n.setAttributes(inputField, "about-config-pref-input-string");
}
inputField.placeholder = oldValue;
form.appendChild(inputField);
valueCell.appendChild(form);

let buttonCell = row.querySelector("td.cell-edit");
buttonCell.childNodes[0].remove();
let button = document.createElement("button");
button.classList.add("primary", "button-save");
document.l10n.setAttributes(button, "about-config-pref-save");
button.setAttribute("form", form.id);
buttonCell.appendChild(button);
}

function endEditingPref(row) {
let name = gPrefInEdit.name;
let input = row.querySelector("td.cell-value").firstChild.firstChild;
let newValue = input.value;

if (Services.prefs.getPrefType(name) == Services.prefs.PREF_INT) {
let numberValue = parseInt(newValue);
if (!/^-?[0-9]*$/.test(newValue) || isNaN(numberValue)) {
input.setCustomValidity(input.title);
return;
}
newValue = numberValue;
Services.prefs.setIntPref(name, newValue);
} else {
Services.prefs.setStringPref(name, newValue);
}

// Update gPrefArray.
gPrefInEdit.value = newValue;
gPrefInEdit.hasUserValue = Services.prefs.prefHasUserValue(name);
// Update UI.
row.textContent = "";
if (gPrefInEdit.hasUserValue) {
row.classList.add("has-user-value");
} else {
row.classList.remove("has-user-value");
}
row.appendChild(getPrefRow(gPrefInEdit));
}

function prefHasDefaultValue(name) {
try {
switch (Services.prefs.getPrefType(name)) {
Expand All @@ -134,3 +290,15 @@ function prefHasDefaultValue(name) {
} catch (ex) {}
return false;
}

function addNewPref(name, value) {
Preferences.set(name, value);
gPrefArray.push({
name,
value,
hasUserValue: true,
hasDefaultValue: false,
});
gPrefArray.sort((a, b) => a.name > b.name);
filterPrefs();
}
8 changes: 8 additions & 0 deletions browser/components/aboutconfig/content/aboutconfig.notftl
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@ about-config-title = about:config
about-config-search =
.placeholder = Search

about-config-pref-add = Add as:
about-config-pref-toggle = Toggle
about-config-pref-edit = Edit
about-config-pref-input-number =
.title = Please enter an integer value
about-config-pref-input-string =
.title = Please enter the value
about-config-pref-save = Save
about-config-pref-reset = Reset
about-config-pref-delete = Delete
Loading

0 comments on commit 3ba5c15

Please sign in to comment.