2009/dap/system-info battery-status.html,1.34,1.35

Update of /sources/public/2009/dap/system-info
In directory hutz:/tmp/cvs-serv5810

Modified Files:
	battery-status.html 
Log Message:
add status attribute, battery{low|critical|ok} event types

Index: battery-status.html
===================================================================
RCS file: /sources/public/2009/dap/system-info/battery-status.html,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- battery-status.html	23 Aug 2011 07:30:38 -0000	1.34
+++ battery-status.html	23 Aug 2011 10:56:39 -0000	1.35
@@ -139,10 +139,11 @@
         This is an example of poor resource management.
       </p>
       <p>
-        Using the <a>BatteryStatusEvent</a> interface, the web application is,
-        for example, able to throttle checking for emails if the device is low
-        on battery and stop checking for emails if the battery is critically
-        low:
+        Using the <a>batterylow</a>, <a>batterycritical</a> and
+        <a>batteryok</a> events, the web application is, for example, able to
+        throttle checking for emails if the device is low on battery, stop
+        checking for emails if the battery is critically low and resume
+        normal operation when the battery status is OK:
       </p>
       <pre class='example sh_javascript'>
         &lt;!DOCTYPE html&gt;
@@ -173,13 +174,6 @@
               mail.setTimer(!mail.interval ? mail.INTERVAL_DEFAULT : mail.interval);
             }, false);
             
-            window.addEventListener('batterystatus', function (battery) {
-              if (battery.isPlugged &amp;&amp; (mail.interval !== mail.INTERVAL_DEFAULT)) {
-                mail.setTimer(mail.INTERVAL_DEFAULT);
-                console.log('Plugged in, checking the server normally.');
-              }
-            }, false);
-            
             window.addEventListener('batterylow', function () {
               mail.setTimer(mail.INTERVAL_BATTERY_LOW);
               console.log('Low battery, checking the server less frequently.');
@@ -189,6 +183,11 @@
               mail.setTimer(null);
               console.log('Critically low battery, stopped checking the server.');
             }, false);
+            
+            window.addEventListener('batteryok', function () {
+              mail.setTimer(mail.INTERVAL_DEFAULT);
+              console.log('Battery ok, checking the server normally.');
+            }, false);
           &lt;/script&gt;
         &lt;/head&gt;
         &lt;body&gt;&lt;/body&gt;
@@ -207,8 +206,8 @@
     <section>
       <h2><a>BatteryStatusEvent</a> Interface</h2>
       <p>
-        This interface defines the <a>batterystatus</a>, <a>batterylow</a> and
-        <a>batterycritical</a> event types.
+        This interface defines the <a>batterystatus</a>, <a>batterylow</a>,
+        <a>batterycritical</a> and <a>batteryok</a> event types.
       <dl title='interface BatteryStatusEvent : Event'
           class='idl'>
         <dt>readonly attribute boolean isPlugged</dt>
@@ -227,6 +226,19 @@
           battery's level, then <code>level</code> MUST be
           set to <code>null</code>.
         </dd>
+        <dt>readonly attribute string? status</dt>
+        <dd>
+          One of <code>critical</code>, <code>low</code>, <code>ok</code>
+          or <code>null</code>.
+          Represents how much of the internal power source remains,
+          scaled from <code>critical</code> to <code>ok</code>. The
+          definitions of <code>critical</code>, <code>low</code>, and
+          <code>ok</code> mirror the definitions of
+          <a>batterycritical</a>, <a>batterylow</a> and <a>batteryok</a>
+          events respectively. If the implementation is unable to
+          report battery's level, then status MUST be set to
+          <code>null</code>.
+        </dd>
         <dt>void initBatteryStatusEvent ()</dt>
         <dd>
             Initializes a <a>BatteryStatusEvent</a> created
@@ -238,21 +250,23 @@
             <dt>boolean cancelable</dt><dd></dd>
             <dt>boolean isPlugged</dt><dd></dd>
             <dt>float? level</dt><dd></dd>
+            <dt>float? status</dt><dd></dd>
           </dl>
         </dd>
       </dl>
       <p>
-        The <a>batterystatus</a>, <a>batterylow</a> and <a>batterycritical</a>
-        event types MUST be available when the script's global object
-        [[!HTML5]] is either a <code>Window</code> object or an object
-        implementing the <code>WorkerUtils</code> interface [[!WEBWORKERS]].
+        The <a>batterystatus</a>, <a>batterylow</a>, <a>batterycritical</a>
+        and <a>batteryok</a> event types MUST be available when the
+        script's global object [[!HTML5]] is either a <code>Window</code>
+        object or an object implementing the <code>WorkerUtils</code>
+        interface [[!WEBWORKERS]].
       </p>
       <p>
         The <code>initBatteryStatusEvent()</code> method MUST initialize the
         event in a manner analogous to the <code>initEvent()</code> method in 
-        [[!DOM-LEVEL-3-EVENTS]]. The <code>isPlugged</code> and
-        <code>level</code> arguments MUST initialize the attributes with the
-        same names.
+        [[!DOM-LEVEL-3-EVENTS]]. The <code>isPlugged</code>, <code>level</code>
+        and <code>status</code> arguments MUST initialize the attributes with
+        the same names.
       </p>
       
       <section>
@@ -269,7 +283,10 @@
             <code>isPlugged</code> changes its value, or
           </li>
           <li>
-            <code>level</code> changes by at least 1
+            <code>level</code> changes by at least 1, or
+          </li>
+          <li>
+            <code>status</code> changes its value
           </li>
         </ul>
         <p>
@@ -339,6 +356,10 @@
         <p>
           The definition of a low battery condition is left to the
           implementation.
+        <p>
+          The condition corresponds to the value of <code>low</code> of
+          the <code>status</code> attribute on the <a>BatteryStatusEvent</a>
+          interface.
         </p>
         <table class='event-type-battery'>
           <tr>
@@ -402,6 +423,11 @@
           than in the low battery condition. Otherwise, the definition of a
           critically low battery condition is left to the implementation.
         </p>
+        <p>
+          The condition corresponds to the value of <code>critical</code> of
+          the <code>status</code> attribute on the <a>BatteryStatusEvent</a>
+          interface. 
+        </p>
         <table class='event-type-battery'>
           <tr>
             <th>Type</th>
@@ -441,6 +467,68 @@
           </tr>
         </table>
       </section>
+
+      <section>
+        <h3 id='event-batteryok'>The <dfn class='event'>batteryok</dfn>
+        event</h3>
+        <p>
+          The <a class="product-ua" href="#ua">user agent</a> MUST dispatch
+          this event type on the <code>Window</code> [[!HTML5]] and
+          <code>WorkerGlobalScope</code> [[!WEBWORKERS]] objects when a change
+          in the battery status of the hosting device occurs as follows:
+        </p>
+        <ul>
+          <li>
+            the battery is plugged in, and
+          </li>
+          <li>
+            the battery is being charged or is at its full capacity
+          </li>
+        </ul>
+        <p>
+          The condition corresponds to the value of <code>ok</code> of the
+          <code>status</code> attribute on the <a>BatteryStatusEvent</a>
+          interface.
+        </p>
+        <table class='event-type-battery'>
+          <tr>
+            <th>Type</th>
+            <td>
+              <code>batteryok</code>
+            </td>
+          </tr>
+          <tr>
+            <th>Interface</th>
+            <td>
+              <a>BatteryStatusEvent</a> if generated by the user agent,
+              <code>Event</code> otherwise.
+            </td>
+          </tr>
+          <tr>
+            <th>Sync / Async</th>
+            <td>Async</td></tr>
+          <tr>
+            <th>Bubbles</th>
+            <td>No</td>
+          </tr>
+          <tr>
+            <th>Target</th>
+            <td><code>defaultView</code></td>
+          </tr>
+          <tr>
+            <th>Cancelable</th>
+            <td>No</td>
+          </tr>
+          <tr>
+            <th>Default action</th>
+            <td>none</td>
+          </tr>
+          <tr>
+            <th>Context info</th>
+            <td><code>Event.target: defaultView</code></td>
+          </tr>
+        </table>
+      </section>
     </section>
     
     <section class='informative'>
@@ -491,8 +579,21 @@
         </pre>
       </div>
       <p>
+        Register to receive a <a>BatteryStatusEvent</a> event when the 
+        battery is plugged in, and the battery is being charged or is
+        at its full capacity:
+      </p>
+      <div class='example'>
+        <pre class='example sh_javascript'>
+          window.addEventListener('batteryok', function () {
+            console.log('The battery is ok.');
+          }, true);
+        </pre>
+      </div>
+      <p>
         The following example updates the indicators to show whether or not
-        the device is plugged in and what is the current battery level:
+        the device is plugged in and what is the current battery level and
+        status:
       </p>
       <div class='example'>
         <pre class='example sh_javascript'>
@@ -504,12 +605,14 @@
               window.addEventListener('batterystatus', function (battery) {
                 document.querySelector('#plugged').textContent = battery.isPlugged ? 'plugged' : 'not plugged';
                 document.querySelector('#level').textContent = battery.level;
+                document.querySelector('#status').textContent = battery.status;
               }, false);
             &lt;/script&gt;
           &lt;/head&gt;
           &lt;body&gt;
             &lt;div id="plugged"&gt;(plugged state unknown)&lt;/div&gt;
             &lt;div id="level"&gt;(battery level unknown)&lt;/div&gt;
+            &lt;div id="status"&gt;(battery status unknown)&lt;/div&gt;
           &lt;/body&gt;
           &lt;/html&gt;
         </pre>

Received on Tuesday, 23 August 2011 10:56:46 UTC