Bug 355846 - Add a pref to disable sliding effect for alerts. r=enndeakin
authorJavi Rueda <leofigueres@yahoo.com>
Mon, 22 Aug 2011 18:43:37 +0200
changeset 75781 87a72f57507e6c882e657b9d40f8f6a9b8da4c7c
parent 75780 ed2e6e93a0deba90e9c23853273c61c0341a1402
child 75782 0432558816ac53af208768975ffe1f6b0c70a13f
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersenndeakin
bugs355846
milestone9.0a1
Bug 355846 - Add a pref to disable sliding effect for alerts. r=enndeakin
modules/libpref/src/init/all.js
toolkit/components/alerts/resources/content/alert.js
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -3326,10 +3326,16 @@ pref("xpinstall.whitelist.required", tru
 pref("extensions.alwaysUnpack", false);
 
 pref("network.buffer.cache.count", 24);
 pref("network.buffer.cache.size",  32768);
 
 // Desktop Notification
 pref("notification.feature.enabled", false);
 
+// Alert sliding effect
+pref("alerts.slideIncrement", 1);
+pref("alerts.slideIncrementTime", 10);
+pref("alerts.totalOpenTime", 4000);
+pref("alerts.disableSlidingEffect", false);
+ 
 //3D Transforms
 pref("layout.3d-transforms.enabled, false);
--- a/toolkit/components/alerts/resources/content/alert.js
+++ b/toolkit/components/alerts/resources/content/alert.js
@@ -43,17 +43,18 @@ const NS_ALERT_TOP = 4;
 
 var gFinalSize;
 var gCurrentSize = 1;
 
 var gSlideIncrement = 1;
 var gSlideTime = 10;
 var gOpenTime = 3000; // total time the alert should stay up once we are done animating.
 var gOrigin = 0; // Default value: alert from bottom right, sliding in vertically.
-
+var gDisableSlideEffect = false;
+ 
 var gAlertListener = null;
 var gAlertTextClickable = false;
 var gAlertCookie = "";
 
 function prefillAlertInfo()
 {
   // unwrap all the args....
   // arguments[0] --> the image src url
@@ -87,30 +88,24 @@ function prefillAlertInfo()
       document.getElementById('alertImage').setAttribute('src', window.arguments[0]);
     case 0:
       break;
   }
 }
 
 function onAlertLoad()
 {
-  // Read out our initial settings from prefs.
-  try 
-  {
-    var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService();
-    prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
-    var prefBranch = prefService.getBranch(null);
-    gSlideIncrement = prefBranch.getIntPref("alerts.slideIncrement");
-    gSlideTime = prefBranch.getIntPref("alerts.slideIncrementTime");
-    gOpenTime = prefBranch.getIntPref("alerts.totalOpenTime");
-  }
-  catch (ex)
-  {
-  }
-
+  var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService();
+  prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
+  var prefBranch = prefService.getBranch(null);
+  gSlideIncrement = prefBranch.getIntPref("alerts.slideIncrement");
+  gSlideTime = prefBranch.getIntPref("alerts.slideIncrementTime");
+  gOpenTime = prefBranch.getIntPref("alerts.totalOpenTime");
+  gDisableSlideEffect = prefBranch.getBoolPref("alerts.disableSlidingEffect");
+ 
   // Make sure that the contents are fixed at the window edge facing the
   // screen's center so that the window looks like "sliding in" and not
   // like "unfolding". The default packing of "start" only works for
   // vertical-bottom and horizontal-right positions, so we change it here.
   if (gOrigin & NS_ALERT_HORIZONTAL)
   {
     if (gOrigin & NS_ALERT_LEFT)
       document.documentElement.pack = "end";
@@ -165,16 +160,19 @@ function onAlertLoad()
 
   setTimeout(animateAlert, gSlideTime);
 }
 
 function animate(step)
 {
   gCurrentSize += step;
 
+  if (gFinalSize < gCurrentSize)
+    gCurrentSize = gFinalSize;
+
   if (gOrigin & NS_ALERT_HORIZONTAL)
   {
     if (!(gOrigin & NS_ALERT_LEFT))
       window.screenX -= step;
     window.outerWidth = gCurrentSize;
   }
   else
   {
@@ -183,26 +181,29 @@ function animate(step)
     window.outerHeight = gCurrentSize;
   }
 }
 
 function animateAlert()
 {
   if (gCurrentSize < gFinalSize)
   {
-    animate(gSlideIncrement);
+    if (gDisableSlideEffect)
+      animate(gFinalSize); // We don't begin on zero.
+    else
+      animate(gSlideIncrement);
     setTimeout(animateAlert, gSlideTime);
   }
   else
     setTimeout(animateCloseAlert, gOpenTime);  
 }
 
 function animateCloseAlert()
 {
-  if (gCurrentSize > 1)
+  if (gCurrentSize > 1 && !gDisableSlideEffect)
   {
     animate(-gSlideIncrement);
     setTimeout(animateCloseAlert, gSlideTime);
   }
   else
     closeAlert();
 }