Bug 731041 - Tidy up addon inline preferences code, toolkit; r=mbrubeck, Unfocused

This commit is contained in:
Geoff Lankow 2012-03-07 00:41:25 +13:00
Родитель 28d175dae4
Коммит 8dc457643f
7 изменённых файлов: 99 добавлений и 123 удалений

Просмотреть файл

@ -2882,12 +2882,9 @@ var gDetailView = {
for (var i = 0; i < settings.length; i++) {
var setting = settings[i];
// Remove setting description, for replacement later
var desc = stripTextNodes(setting).trim();
if (setting.hasAttribute("desc")) {
desc = setting.getAttribute("desc").trim();
setting.removeAttribute("desc");
}
if (!setting.hasAttribute("desc"))
setting.setAttribute("desc", desc);
var type = setting.getAttribute("type");
if (type == "file" || type == "directory")
@ -2899,23 +2896,10 @@ var gDetailView = {
setting.setAttribute("first-row", true);
firstSetting = setting;
}
// Add a new row containing the description
if (desc) {
var row = document.createElement("row");
if (!visible) {
row.setAttribute("unsupported", "true");
}
var label = document.createElement("label");
label.className = "preferences-description";
label.textContent = desc;
row.appendChild(label);
rows.appendChild(row);
}
}
// Ensure the page has loaded and force the XBL bindings to be synchronously applied,
// then notify observers.
// Ensure the page has loaded and force the XBL bindings to be synchronously applied,
// then notify observers.
if (gViewController.viewPort.selectedPanel.hasAttribute("loading")) {
gDetailView.node.addEventListener("ViewChanged", function viewChangedEventListener() {
gDetailView.node.removeEventListener("ViewChanged", viewChangedEventListener, false);

Просмотреть файл

@ -51,7 +51,7 @@
<binding id="settings">
<content orient="vertical">
<xul:label class="settings-title" xbl:inherits="xbl:text=label" flex="1"/>
<children />
<children/>
</content>
</binding>
@ -160,7 +160,6 @@
<field name="_updatingInput">false</field>
<field name="input">document.getAnonymousElementByAttribute(this, "anonid", "input");</field>
<field name="settings">
this.parentNode.localName == "settings" ? this.parentNode : null;
</field>
@ -169,14 +168,14 @@
<binding id="setting-bool" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
<content>
<xul:vbox class="setting-label">
<xul:label class="preferences-title" xbl:inherits="xbl:text=title" flex="1"/>
<xul:label class="preferences-description" xbl:inherits="xbl:text=desc" flex="1">
<children/>
</xul:label>
<xul:vbox>
<xul:hbox class="preferences-alignment">
<xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
</xul:hbox>
<xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
</xul:vbox>
<xul:hbox anonid="input-container" class="setting-input">
<xul:checkbox anonid="input" xbl:inherits="disabled,onlabel,offlabel" oncommand="inputChanged();"/>
<xul:hbox class="preferences-alignment">
<xul:checkbox anonid="input" xbl:inherits="disabled,onlabel,offlabel,label=checkboxlabel" oncommand="inputChanged();"/>
</xul:hbox>
</content>
@ -204,19 +203,7 @@
</implementation>
</binding>
<binding id="setting-boolint" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
<content>
<xul:vbox class="setting-label">
<xul:label class="preferences-title" xbl:inherits="xbl:text=title" flex="1"/>
<xul:label class="preferences-description" xbl:inherits="xbl:text=desc" flex="1">
<children/>
</xul:label>
</xul:vbox>
<xul:hbox anonid="input-container" class="setting-input">
<xul:checkbox anonid="input" xbl:inherits="disabled" oncommand="inputChanged();"/>
</xul:hbox>
</content>
<binding id="setting-boolint" extends="chrome://mozapps/content/extensions/setting.xml#setting-bool">
<implementation>
<method name="valueFromPreference">
<body>
@ -234,9 +221,6 @@
]]>
</body>
</method>
<property name="value" onget="return this.input.checked;" onset="return this.input.setChecked(val);"/>
<property name="inverted" readonly="true" onget="return this.getAttribute('inverted');"/>
</implementation>
</binding>
@ -263,20 +247,20 @@
]]>
</body>
</method>
</implementation>
</binding>
<binding id="setting-integer" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
<content>
<xul:vbox class="setting-label">
<xul:label class="preferences-title" xbl:inherits="xbl:text=title" flex="1"/>
<xul:label class="preferences-description" xbl:inherits="xbl:text=desc" flex="1">
<children/>
</xul:label>
<xul:vbox>
<xul:hbox class="preferences-alignment">
<xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
</xul:hbox>
<xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
</xul:vbox>
<xul:hbox anonid="input-container" class="setting-input">
<xul:textbox type="number" anonid="input" xbl:inherits="disabled,emptytext,min,max,increment,hidespinbuttons,wraparound" oninput="inputChanged();" onchange="inputChanged();"/>
<xul:hbox class="preferences-alignment">
<xul:textbox type="number" anonid="input" flex="1" oninput="inputChanged();" onchange="inputChanged();"
xbl:inherits="disabled,emptytext,min,max,increment,hidespinbuttons,wraparound"/>
</xul:hbox>
</content>
@ -297,21 +281,18 @@
]]>
</body>
</method>
<property name="type" readonly="true" onget="return this.getAttribute('type');"/>
<property name="value" onget="return this.input.value;" onset="return this.input.value = val;"/>
</implementation>
</binding>
<binding id="setting-control" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
<content>
<xul:vbox class="setting-label">
<xul:label class="preferences-title" xbl:inherits="xbl:text=title" flex="1"/>
<xul:label class="preferences-description" xbl:inherits="xbl:text=desc" flex="1">
<children/>
</xul:label>
<xul:vbox>
<xul:hbox class="preferences-alignment">
<xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
</xul:hbox>
<xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
</xul:vbox>
<xul:hbox anonid="input-container" class="setting-input">
<xul:hbox class="preferences-alignment">
<children includes="button|menulist"/>
</xul:hbox>
</content>
@ -319,14 +300,15 @@
<binding id="setting-string" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
<content>
<xul:vbox class="setting-label">
<xul:label class="preferences-title" xbl:inherits="xbl:text=title" flex="1"/>
<xul:label class="preferences-description" xbl:inherits="xbl:text=desc" flex="1">
<children/>
</xul:label>
<xul:vbox>
<xul:hbox class="preferences-alignment">
<xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
</xul:hbox>
<xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
</xul:vbox>
<xul:hbox anonid="input-container" class="setting-input">
<xul:textbox xbl:inherits="disabled,emptytext,type=inputtype,min,max,increment,hidespinbuttons,decimalplaces,wraparound" anonid="input" oninput="inputChanged();"/>
<xul:hbox class="preferences-alignment">
<xul:textbox anonid="input" flex="1" oninput="inputChanged();"
xbl:inherits="disabled,emptytext,type=inputtype,min,max,increment,hidespinbuttons,decimalplaces,wraparound"/>
</xul:hbox>
</content>
@ -350,20 +332,18 @@
]]>
</body>
</method>
<property name="value" onget="return this.input.value;" onset="return this.input.value=val;"/>
</implementation>
</binding>
<binding id="setting-color" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
<content>
<xul:vbox class="setting-label">
<xul:label class="preferences-title" xbl:inherits="xbl:text=title" flex="1"/>
<xul:label class="preferences-description" xbl:inherits="xbl:text=desc" flex="1">
<children/>
</xul:label>
<xul:vbox>
<xul:hbox class="preferences-alignment">
<xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
</xul:hbox>
<xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
</xul:vbox>
<xul:hbox anonid="input-container" class="setting-input">
<xul:hbox class="preferences-alignment">
<xul:colorpicker type="button" anonid="input" xbl:inherits="disabled" onchange="document.getBindingParent(this).inputChanged();"/>
</xul:hbox>
</content>
@ -394,15 +374,15 @@
<binding id="setting-path" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
<content>
<xul:vbox class="setting-label">
<xul:label class="preferences-title" xbl:inherits="xbl:text=title" flex="1"/>
<xul:label class="preferences-description" xbl:inherits="xbl:text=desc" flex="1">
<children/>
</xul:label>
<xul:vbox>
<xul:hbox class="preferences-alignment">
<xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
</xul:hbox>
<xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
</xul:vbox>
<xul:hbox anonid="input-container" align="center" class="setting-input">
<xul:button type="button" anonid="button" label="&settings.path.button.label;" xbl:inherits="disabled" oncommand="showPicker();" />
<xul:label anonid="input" flex="1" crop="center" xbl:inherits="disabled" />
<xul:hbox class="preferences-alignment">
<xul:button type="button" anonid="button" label="&settings.path.button.label;" xbl:inherits="disabled" oncommand="showPicker();"/>
<xul:label anonid="input" flex="1" crop="center" xbl:inherits="disabled"/>
</xul:hbox>
</content>
@ -476,14 +456,14 @@
<binding id="setting-multi" extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
<content>
<xul:vbox class="setting-label">
<xul:label class="preferences-title" xbl:inherits="xbl:text=title" flex="1"/>
<xul:label class="preferences-description" xbl:inherits="xbl:text=desc" flex="1">
<children/>
</xul:label>
<xul:vbox>
<xul:hbox class="preferences-alignment">
<xul:label class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
</xul:hbox>
<xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
</xul:vbox>
<xul:hbox class="setting-input">
<children includes="radiogroup|menulist" />
<xul:hbox class="preferences-alignment">
<children includes="radiogroup|menulist"/>
</xul:hbox>
</content>

Просмотреть файл

@ -1,6 +1,6 @@
<?xml version="1.0" ?>
<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<setting pref="extensions.inlinesettings1.bool" type="bool" title="Bool"/>
<setting pref="extensions.inlinesettings1.bool" type="bool" title="Bool" checkboxlabel="Check box label"/>
<setting pref="extensions.inlinesettings1.boolint" type="boolint" on="1" off="2" title="BoolInt"/>
<setting pref="extensions.inlinesettings1.integer" type="integer" title="Integer"/>
<setting pref="extensions.inlinesettings1.string" type="string" title="String"/>

Просмотреть файл

@ -21,7 +21,7 @@ var observer = {
// Test if the binding has applied before the observers are notified. We test the second setting here,
// because the code operates on the first setting and we want to check it applies to all.
var setting = aSubject.querySelector("rows > setting[first-row] ~ setting");
var input = gManagerWindow.document.getAnonymousElementByAttribute(setting, "class", "setting-label");
var input = gManagerWindow.document.getAnonymousElementByAttribute(setting, "class", "preferences-title");
isnot(input, null, "XBL binding should be applied");
// Add some extra height to the scrolling pane to ensure that it needs to scroll when appropriate.
@ -174,6 +174,7 @@ add_test(function() {
Services.prefs.setBoolPref("extensions.inlinesettings1.bool", false);
var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[0], "anonid", "input");
isnot(input.checked, true, "Checkbox should have initial value");
is(input.label, "Check box label", "Checkbox should be labelled");
EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow);
is(input.checked, true, "Checkbox should have updated value");
is(Services.prefs.getBoolPref("extensions.inlinesettings1.bool"), true, "Bool pref should have been updated");
@ -381,45 +382,26 @@ add_test(function() {
is(node.nodeName, "setting", "Should be a setting node");
ok(node.hasAttribute("first-row"), "First visible row should have first-row attribute");
var description = gManagerWindow.document.getAnonymousElementByAttribute(node, "class", "preferences-description");
is(description.textContent.trim(), "", "Description node should be empty");
node = node.nextSibling;
is(node.nodeName, "row", "Setting should be followed by a row node");
is_element_visible(node, "Description should be visible");
is(node.textContent, "Description Attribute", "Description should be in this row");
is(description.textContent, "Description Attribute", "Description node should contain description");
node = settings[2];
is(node.nodeName, "setting", "Should be a setting node");
ok(!node.hasAttribute("first-row"), "Not the first row");
description = gManagerWindow.document.getAnonymousElementByAttribute(node, "class", "preferences-description");
is(description.textContent.trim(), "", "Description node should be empty");
node = node.nextSibling;
is(node.nodeName, "row", "Setting should be followed by a row node");
is_element_visible(node, "Description should be visible");
is(node.textContent, "Description Text Node", "Description should be in this row");
is(description.textContent, "Description Text Node", "Description node should contain description");
node = settings[3];
is(node.nodeName, "setting", "Should be a setting node");
ok(!node.hasAttribute("first-row"), "Not the first row");
description = gManagerWindow.document.getAnonymousElementByAttribute(node, "class", "preferences-description");
is(description.textContent.trim(), "", "Description node should be empty");
is(description.textContent, "This is a test, all this text should be visible", "Description node should contain description");
var button = node.firstElementChild;
isnot(button, null, "There should be a button");
node = node.nextSibling;
is(node.nodeName, "row", "Setting should be followed by a row node");
is_element_visible(node, "Description should be visible");
is(node.textContent.trim(), "This is a test, all this text should be visible", "Description should be in this row");
node = settings[4];
is_element_hidden(node, "Unsupported settings should not be visible");
ok(!node.hasAttribute("first-row"), "Hidden row is not the first row");
node = node.nextSibling;
is(node.nodeName, "row", "Setting should be followed by a row node");
is_element_hidden(node, "Descriptions of unsupported settings should not be visible");
var button = gManagerWindow.document.getElementById("detail-prefs-btn");
is_element_hidden(button, "Preferences button should not be visible");

Просмотреть файл

@ -739,7 +739,7 @@ setting[first-row="true"] {
setting {
border-top: 1px solid ThreeDShadow;
-moz-box-align: center;
min-height: 33px;
min-height: 32px;
}
#detail-controls {
@ -755,15 +755,25 @@ setting[first-row="true"] {
margin-top: 2em;
}
setting {
-moz-box-align: start;
}
.preferences-alignment {
min-height: 32px;
-moz-box-align: center;
}
.preferences-description {
font-size: 90.9%;
color: graytext;
margin-top: -2px;
-moz-margin-start: 2em;
white-space: pre-wrap;
}
setting[type="string"] > .setting-input > textbox {
-moz-box-flex: 1;
.preferences-description:empty {
display: none;
}
menulist { /* Fixes some styling inconsistencies */

Просмотреть файл

@ -934,15 +934,25 @@ setting[first-row="true"] {
margin-top: 2em;
}
setting {
-moz-box-align: start;
}
.preferences-alignment {
min-height: 30px;
-moz-box-align: center;
}
.preferences-description {
font-size: 90.9%;
color: graytext;
margin-top: -2px;
-moz-margin-start: 2em;
white-space: pre-wrap;
}
setting[type="string"] > .setting-input > textbox {
-moz-box-flex: 1;
.preferences-description:empty {
display: none;
}
setting[type="radio"] > radiogroup {

Просмотреть файл

@ -913,15 +913,25 @@ setting[first-row="true"] {
margin-top: 2em;
}
setting {
-moz-box-align: start;
}
.preferences-alignment {
min-height: 30px;
-moz-box-align: center;
}
.preferences-description {
font-size: 90.9%;
color: graytext;
margin-top: -2px;
-moz-margin-start: 2em;
white-space: pre-wrap;
}
setting[type="string"] > .setting-input > textbox {
-moz-box-flex: 1;
.preferences-description:empty {
display: none;
}
setting[type="radio"] > radiogroup {