Bug 596778 - Stop setting cache size with each user keystroke in size input field, by only setting the cache size pref when the field is loses focus. r=mak77

This commit is contained in:
aceman 2015-05-13 11:36:47 -07:00
parent 8013b41a02
commit 38676f1ead
4 changed files with 41 additions and 29 deletions

View File

@ -48,6 +48,7 @@ var gAdvancedPane = {
this.initSubmitHealthReport();
#endif
this.updateCacheSizeInputField();
this.updateActualCacheSize();
this.updateActualAppCacheSize();
@ -378,24 +379,31 @@ var gAdvancedPane = {
},
/**
* Converts the cache size from units of KB to units of MB and returns that
* value.
* Converts the cache size from units of KB to units of MB and stores it in
* the textbox element.
*/
readCacheSize: function ()
updateCacheSizeInputField()
{
var preference = document.getElementById("browser.cache.disk.capacity");
return preference.value / 1024;
let cacheSizeElem = document.getElementById("cacheSize");
let cachePref = document.getElementById("browser.cache.disk.capacity");
cacheSizeElem.value = cachePref.value / 1024;
if (cachePref.locked)
cacheSizeElem.disabled = true;
},
/**
* Converts the cache size as specified in UI (in MB) to KB and returns that
* value.
* Updates the cache size preference once user enters a new value.
* We intentionally do not set preference="browser.cache.disk.capacity"
* onto the textbox directly, as that would update the pref at each keypress
* not only after the final value is entered.
*/
writeCacheSize: function ()
updateCacheSizePref()
{
var cacheSize = document.getElementById("cacheSize");
var intValue = parseInt(cacheSize.value, 10);
return isNaN(intValue) ? 0 : intValue * 1024;
let cacheSizeElem = document.getElementById("cacheSize");
let cachePref = document.getElementById("browser.cache.disk.capacity");
// Converts the cache size as specified in UI (in MB) to KB.
let intValue = parseInt(cacheSizeElem.value, 10);
cachePref.value = isNaN(intValue) ? 0 : intValue * 1024;
},
/**

View File

@ -250,9 +250,7 @@
accesskey="&limitCacheSizeBefore.accesskey;"
value="&limitCacheSizeBefore.label;"/>
<textbox id="cacheSize" type="number" size="4" max="1024"
preference="browser.cache.disk.capacity"
onsyncfrompreference="return gAdvancedPane.readCacheSize();"
onsynctopreference="return gAdvancedPane.writeCacheSize();"
onchange="gAdvancedPane.updateCacheSizePref();"
aria-labelledby="useCacheBefore cacheSize useCacheAfter"/>
<label id="useCacheAfter" flex="1">&limitCacheSizeAfter.label;</label>
</hbox>

View File

@ -45,6 +45,7 @@ var gAdvancedPane = {
#ifdef MOZ_SERVICES_HEALTHREPORT
this.initSubmitHealthReport();
#endif
this.updateCacheSizeInputField();
this.updateActualCacheSize();
this.updateActualAppCacheSize();
@ -413,24 +414,31 @@ var gAdvancedPane = {
},
/**
* Converts the cache size from units of KB to units of MB and returns that
* value.
* Converts the cache size from units of KB to units of MB and stores it in
* the textbox element.
*/
readCacheSize: function ()
updateCacheSizeInputField()
{
var preference = document.getElementById("browser.cache.disk.capacity");
return preference.value / 1024;
let cacheSizeElem = document.getElementById("cacheSize");
let cachePref = document.getElementById("browser.cache.disk.capacity");
cacheSizeElem.value = cachePref.value / 1024;
if (cachePref.locked)
cacheSizeElem.disabled = true;
},
/**
* Converts the cache size as specified in UI (in MB) to KB and returns that
* value.
* Updates the cache size preference once user enters a new value.
* We intentionally do not set preference="browser.cache.disk.capacity"
* onto the textbox directly, as that would update the pref at each keypress
* not only after the final value is entered.
*/
writeCacheSize: function ()
updateCacheSizePref()
{
var cacheSize = document.getElementById("cacheSize");
var intValue = parseInt(cacheSize.value, 10);
return isNaN(intValue) ? 0 : intValue * 1024;
let cacheSizeElem = document.getElementById("cacheSize");
let cachePref = document.getElementById("browser.cache.disk.capacity");
// Converts the cache size as specified in UI (in MB) to KB.
let intValue = parseInt(cacheSizeElem.value, 10);
cachePref.value = isNaN(intValue) ? 0 : intValue * 1024;
},
/**

View File

@ -271,10 +271,8 @@
&limitCacheSizeBefore.label;
</label>
<textbox id="cacheSize" type="number" size="4" max="1024"
preference="browser.cache.disk.capacity"
onsyncfrompreference="return gAdvancedPane.readCacheSize();"
onsynctopreference="return gAdvancedPane.writeCacheSize();"
aria-labelledby="useCacheBefore cacheSize useCacheAfter"/>
onchange="gAdvancedPane.updateCacheSizePref();"
aria-labelledby="useCacheBefore cacheSize useCacheAfter"/>
<label id="useCacheAfter" flex="1">&limitCacheSizeAfter.label;</label>
</hbox>
</groupbox>