Source

cappuccino-docs / cappuccino docs / cappuccino.org / learn / documentation / _c_p_run_loop_8j_source.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!-- Mirrored from cappuccino.org/learn/documentation/_c_p_run_loop_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:31 GMT -->
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Cappuccino API: Foundation/CPRunLoop.j Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>Foundation/CPRunLoop.j</h1><a href="_c_p_run_loop_8j.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * CPRunLoop.j</span>
<a name="l00003"></a>00003 <span class="comment"> * Foundation</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> * Created by Francisco Tolmasky.</span>
<a name="l00006"></a>00006 <span class="comment"> * Copyright 2008, 280 North, Inc.</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
<a name="l00009"></a>00009 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
<a name="l00010"></a>00010 <span class="comment"> * License as published by the Free Software Foundation; either</span>
<a name="l00011"></a>00011 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
<a name="l00014"></a>00014 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00015"></a>00015 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>
<a name="l00016"></a>00016 <span class="comment"> * Lesser General Public License for more details.</span>
<a name="l00017"></a>00017 <span class="comment"> *</span>
<a name="l00018"></a>00018 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
<a name="l00019"></a>00019 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
<a name="l00020"></a>00020 <span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA</span>
<a name="l00021"></a>00021 <span class="comment"> */</span>
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 @<span class="keyword">import</span> <span class="stringliteral">&quot;CPObject.j&quot;</span>
<a name="l00024"></a>00024 @<span class="keyword">import</span> <span class="stringliteral">&quot;CPArray.j&quot;</span>
<a name="l00025"></a>00025 @<span class="keyword">import</span> <span class="stringliteral">&quot;CPString.j&quot;</span>
<a name="l00026"></a>00026 
<a name="l00031"></a><a class="code" href="_c_p_run_loop_8j.html#a51e129fa61aa6aef4c036d4762d468ea">00031</a> <a class="code" href="_c_p_run_loop_8j.html#a51e129fa61aa6aef4c036d4762d468ea">CPDefaultRunLoopMode</a>    = <span class="stringliteral">@&quot;CPDefaultRunLoopMode&quot;</span>;
<a name="l00032"></a>00032 
<a name="l00033"></a>00033 function _CPRunLoopPerformCompare(lhs, rhs)
<a name="l00034"></a>00034 {
<a name="l00035"></a>00035     <span class="keywordflow">return</span> [rhs order] - [lhs order];
<a name="l00036"></a>00036 }
<a name="l00037"></a>00037 
<a name="l00038"></a>00038 var _CPRunLoopPerformPool           = [],
<a name="l00039"></a>00039     _CPRunLoopPerformPoolCapacity   = 5;
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 <span class="comment">/* @ignore */</span>
<a name="l00042"></a>00042 <span class="keyword">@implementation </span>_CPRunLoopPerform : <a class="code" href="class_c_p_object.html" title="The root class from which most classes are subclassed.">CPObject</a>
<a name="l00043"></a>00043 {
<a name="l00044"></a>00044     <span class="keywordtype">id</span>          _target;
<a name="l00045"></a>00045     <span class="keywordtype">SEL</span>         _selector;
<a name="l00046"></a>00046     <span class="keywordtype">id</span>          _argument;
<a name="l00047"></a>00047     <span class="keywordtype">unsigned</span>    _order;
<a name="l00048"></a>00048     <a class="code" href="class_c_p_array.html" title="A mutable array backed by a JavaScript Array.A mutable array class backed by a JavaScript...">CPArray</a>     _runLoopModes;
<a name="l00049"></a>00049     BOOL        _isValid;
<a name="l00050"></a>00050 }
<a name="l00051"></a>00051 
<a name="l00052"></a>00052 + (void)_poolPerform:(_CPRunLoopPerform)aPerform
<a name="l00053"></a>00053 {
<a name="l00054"></a>00054     <span class="keywordflow">if</span> (!aPerform || _CPRunLoopPerformPool.length &gt;= _CPRunLoopPerformPoolCapacity)
<a name="l00055"></a>00055         <span class="keywordflow">return</span>;
<a name="l00056"></a>00056     
<a name="l00057"></a>00057     _CPRunLoopPerformPool.push(aPerform);
<a name="l00058"></a>00058 }
<a name="l00059"></a>00059 
<a name="l00060"></a>00060 + (_CPRunLoopPerform)performWithSelector:(<span class="keywordtype">SEL</span>)aSelector target:(<span class="keywordtype">id</span>)aTarget argument:(<span class="keywordtype">id</span>)anArgument order:(<span class="keywordtype">unsigned</span>)anOrder modes:(<a class="code" href="class_c_p_array.html" title="A mutable array backed by a JavaScript Array.A mutable array class backed by a JavaScript...">CPArray</a>)modes
<a name="l00061"></a>00061 {
<a name="l00062"></a>00062     <span class="keywordflow">if</span> (_CPRunLoopPerformPool.length)
<a name="l00063"></a>00063     {
<a name="l00064"></a>00064         var perform = _CPRunLoopPerformPool.pop();
<a name="l00065"></a>00065         
<a name="l00066"></a>00066         perform._target = aTarget;
<a name="l00067"></a>00067         perform._selector = aSelector;
<a name="l00068"></a>00068         perform._argument = anArgument;
<a name="l00069"></a>00069         perform._order = anOrder;
<a name="l00070"></a>00070         perform._runLoopModes = modes;
<a name="l00071"></a>00071         perform._isValid = YES;
<a name="l00072"></a>00072         
<a name="l00073"></a>00073         <span class="keywordflow">return</span> perform;
<a name="l00074"></a>00074     }
<a name="l00075"></a>00075     
<a name="l00076"></a>00076     <span class="keywordflow">return</span> [[<span class="keyword">self</span> alloc] initWithSelector:aSelector target:aTarget argument:anArgument order:anOrder modes:modes];
<a name="l00077"></a>00077 }
<a name="l00078"></a>00078 
<a name="l00079"></a>00079 - (id)initWithSelector:(<span class="keywordtype">SEL</span>)aSelector target:(<span class="keywordtype">SEL</span>)aTarget argument:(<span class="keywordtype">id</span>)anArgument order:(<span class="keywordtype">unsigned</span>)anOrder modes:(<a class="code" href="class_c_p_array.html" title="A mutable array backed by a JavaScript Array.A mutable array class backed by a JavaScript...">CPArray</a>)modes
<a name="l00080"></a>00080 {
<a name="l00081"></a>00081     <span class="keyword">self</span> = [<span class="keyword">super</span> init];
<a name="l00082"></a>00082     
<a name="l00083"></a>00083     <span class="keywordflow">if</span> (<span class="keyword">self</span>)
<a name="l00084"></a>00084     {
<a name="l00085"></a>00085         _selector = aSelector;
<a name="l00086"></a>00086         _target = aTarget;
<a name="l00087"></a>00087         _argument = anArgument;
<a name="l00088"></a>00088         _order = anOrder;
<a name="l00089"></a>00089         _runLoopModes = modes;
<a name="l00090"></a>00090         _isValid = YES;
<a name="l00091"></a>00091     }
<a name="l00092"></a>00092     
<a name="l00093"></a>00093     <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00094"></a>00094 }
<a name="l00095"></a>00095 
<a name="l00096"></a>00096 - (SEL)<a class="code" href="_c_p_cib_control_connector_8j.html#a093b121866a6168a986e7ff004ddc5c4">selector</a>
<a name="l00097"></a>00097 {
<a name="l00098"></a>00098     <span class="keywordflow">return</span> _selector;
<a name="l00099"></a>00099 }
<a name="l00100"></a>00100 
<a name="l00101"></a>00101 - (id)target
<a name="l00102"></a>00102 {
<a name="l00103"></a>00103     <span class="keywordflow">return</span> _target;
<a name="l00104"></a>00104 }
<a name="l00105"></a>00105 
<a name="l00106"></a>00106 - (id)argument
<a name="l00107"></a>00107 {
<a name="l00108"></a>00108     <span class="keywordflow">return</span> _argument;
<a name="l00109"></a>00109 }
<a name="l00110"></a>00110 
<a name="l00111"></a>00111 - (unsigned)order
<a name="l00112"></a>00112 {
<a name="l00113"></a>00113     <span class="keywordflow">return</span> _order;
<a name="l00114"></a>00114 }
<a name="l00115"></a>00115 
<a name="l00116"></a>00116 - (BOOL)fireInMode:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aRunLoopMode
<a name="l00117"></a>00117 {
<a name="l00118"></a>00118     <span class="keywordflow">if</span> (!_isValid)
<a name="l00119"></a>00119         <span class="keywordflow">return</span> YES;
<a name="l00120"></a>00120     
<a name="l00121"></a>00121     <span class="keywordflow">if</span> ([_runLoopModes containsObject:aRunLoopMode])
<a name="l00122"></a>00122     {
<a name="l00123"></a>00123         [_target performSelector:_selector withObject:_argument];
<a name="l00124"></a>00124         
<a name="l00125"></a>00125         <span class="keywordflow">return</span> YES;
<a name="l00126"></a>00126     }
<a name="l00127"></a>00127     
<a name="l00128"></a>00128     <span class="keywordflow">return</span> NO;
<a name="l00129"></a>00129 }
<a name="l00130"></a>00130 
<a name="l00131"></a>00131 - (void)invalidate
<a name="l00132"></a>00132 {
<a name="l00133"></a>00133     _isValid = NO;
<a name="l00134"></a>00134 }
<a name="l00135"></a>00135 
<a name="l00136"></a>00136 <span class="keyword">@end</span>
<a name="l00137"></a>00137 
<a name="l00138"></a><a class="code" href="_c_p_run_loop_8j.html#aea87f8ade30a60e9eb4c73797c491efb">00138</a> var <a class="code" href="_c_p_run_loop_8j.html#aea87f8ade30a60e9eb4c73797c491efb">CPRunLoopLastNativeRunLoop</a> = 0;
<a name="l00139"></a>00139 
<a name="l00149"></a><a class="code" href="class_c_p_run_loop.html">00149</a> <span class="keyword">@implementation </span><a class="code" href="class_c_p_run_loop.html" title="The main run loop for the application.">CPRunLoop</a> : <a class="code" href="class_c_p_object.html" title="The root class from which most classes are subclassed.">CPObject</a>
<a name="l00150"></a>00150 {
<a name="l00151"></a>00151     BOOL    _runLoopLock;
<a name="l00152"></a>00152 
<a name="l00153"></a>00153     Object  _timersForModes; <span class="comment">//should be a dictionary to allow lookups by mode</span>
<a name="l00154"></a>00154     Object  _nativeTimersForModes;
<a name="l00155"></a>00155     <a class="code" href="class_c_p_date.html" title="A representation of a single point in time.">CPDate</a>  _nextTimerFireDatesForModes;
<a name="l00156"></a>00156     BOOL    _didAddTimer;
<a name="l00157"></a>00157     <a class="code" href="class_c_p_date.html" title="A representation of a single point in time.">CPDate</a>  _effectiveDate;
<a name="l00158"></a>00158 
<a name="l00159"></a>00159     <a class="code" href="class_c_p_array.html" title="A mutable array backed by a JavaScript Array.A mutable array class backed by a JavaScript...">CPArray</a> _orderedPerforms;
<a name="l00160"></a>00160 }
<a name="l00161"></a>00161 
<a name="l00162"></a>00162 <span class="comment">/*</span>
<a name="l00163"></a>00163 <span class="comment">    @ignore</span>
<a name="l00164"></a>00164 <span class="comment">*/</span>
<a name="l00165"></a><a class="code" href="class_c_p_run_loop.html#afdb02a67eda9973703746cbb201aa286">00165</a> + (void)initialize
<a name="l00166"></a>00166 {
<a name="l00167"></a>00167     <span class="keywordflow">if</span> (<span class="keyword">self</span> != [<a class="code" href="class_c_p_run_loop.html" title="The main run loop for the application.">CPRunLoop</a> <span class="keyword">class</span>])
<a name="l00168"></a>00168         <span class="keywordflow">return</span>;
<a name="l00169"></a>00169 
<a name="l00170"></a>00170     CPMainRunLoop = [[<a class="code" href="class_c_p_run_loop.html" title="The main run loop for the application.">CPRunLoop</a> alloc] init];
<a name="l00171"></a>00171 }
<a name="l00172"></a>00172 
<a name="l00173"></a><a class="code" href="class_c_p_run_loop.html#a7ffba7ebe9eb8cc441a2d6bf51924dad">00173</a> - (id)init
<a name="l00174"></a>00174 {
<a name="l00175"></a>00175     <span class="keyword">self</span> = [<span class="keyword">super</span> init];
<a name="l00176"></a>00176     
<a name="l00177"></a>00177     <span class="keywordflow">if</span> (<span class="keyword">self</span>)
<a name="l00178"></a>00178     {
<a name="l00179"></a>00179         _orderedPerforms = [];
<a name="l00180"></a>00180         
<a name="l00181"></a>00181         _timersForModes = {};
<a name="l00182"></a>00182         _nativeTimersForModes = {};
<a name="l00183"></a>00183         _nextTimerFireDatesForModes = {};
<a name="l00184"></a>00184     }
<a name="l00185"></a>00185     
<a name="l00186"></a>00186     <span class="keywordflow">return</span> <span class="keyword">self</span>;
<a name="l00187"></a>00187 }
<a name="l00188"></a>00188 
<a name="l00192"></a><a class="code" href="class_c_p_run_loop.html#aba93f1cef957bad4353ce060981c0b9d">00192</a> + (<a class="code" href="class_c_p_run_loop.html" title="The main run loop for the application.">CPRunLoop</a>)currentRunLoop
<a name="l00193"></a>00193 {
<a name="l00194"></a>00194     <span class="keywordflow">return</span> CPMainRunLoop;
<a name="l00195"></a>00195 }
<a name="l00196"></a>00196 
<a name="l00200"></a><a class="code" href="class_c_p_run_loop.html#a72897726b6fe227f34337d696b20ec99">00200</a> + (<a class="code" href="class_c_p_run_loop.html" title="The main run loop for the application.">CPRunLoop</a>)mainRunLoop
<a name="l00201"></a>00201 {
<a name="l00202"></a>00202     <span class="keywordflow">return</span> CPMainRunLoop;
<a name="l00203"></a>00203 }
<a name="l00204"></a>00204 
<a name="l00213"></a><a class="code" href="class_c_p_run_loop.html#a2b3b2247377a11043079b7949523156e">00213</a> - (void)performSelector:(<span class="keywordtype">SEL</span>)aSelector target:(<span class="keywordtype">id</span>)aTarget argument:(<span class="keywordtype">id</span>)anArgument order:(<span class="keywordtype">int</span>)anOrder modes:(<a class="code" href="class_c_p_array.html" title="A mutable array backed by a JavaScript Array.A mutable array class backed by a JavaScript...">CPArray</a>)modes
<a name="l00214"></a>00214 {
<a name="l00215"></a>00215     var perform = [_CPRunLoopPerform performWithSelector:aSelector target:aTarget argument:anArgument order:anOrder modes:modes],
<a name="l00216"></a>00216         count = _orderedPerforms.length;
<a name="l00217"></a>00217 
<a name="l00218"></a>00218     <span class="comment">// We sort ourselves in reverse because we iterate this list backwards.</span>
<a name="l00219"></a>00219     <span class="keywordflow">while</span> (count--)
<a name="l00220"></a>00220         <span class="keywordflow">if</span> (anOrder &lt; [_orderedPerforms[count] order])
<a name="l00221"></a>00221             <span class="keywordflow">break</span>;
<a name="l00222"></a>00222     
<a name="l00223"></a>00223     _orderedPerforms.splice(count + 1, 0, perform);
<a name="l00224"></a>00224 }
<a name="l00225"></a>00225 
<a name="l00232"></a><a class="code" href="class_c_p_run_loop.html#ae134cf7a94255ee21c385669a8321e7c">00232</a> - (void)cancelPerformSelector:(<span class="keywordtype">SEL</span>)aSelector target:(<span class="keywordtype">id</span>)aTarget argument:(<span class="keywordtype">id</span>)anArgument
<a name="l00233"></a>00233 {
<a name="l00234"></a>00234     var count = _orderedPerforms.length;
<a name="l00235"></a>00235     
<a name="l00236"></a>00236     <span class="keywordflow">while</span> (count--)
<a name="l00237"></a>00237     {
<a name="l00238"></a>00238         var perform = _orderedPerforms[count];
<a name="l00239"></a>00239         
<a name="l00240"></a>00240         <span class="keywordflow">if</span> ([perform <a class="code" href="_c_p_cib_control_connector_8j.html#a093b121866a6168a986e7ff004ddc5c4">selector</a>] === aSelector &amp;&amp; [perform target] == aTarget &amp;&amp; [perform argument] == anArgument)
<a name="l00241"></a>00241             [_orderedPerforms[count] invalidate];
<a name="l00242"></a>00242     }
<a name="l00243"></a>00243 }
<a name="l00244"></a>00244 
<a name="l00245"></a>00245 <span class="comment">/*</span>
<a name="l00246"></a>00246 <span class="comment">    @ignore</span>
<a name="l00247"></a>00247 <span class="comment">*/</span>
<a name="l00248"></a><a class="code" href="class_c_p_run_loop.html#a59741f09cac6a9346fcd5bb125a8b069">00248</a> - (void)performSelectors
<a name="l00249"></a>00249 {
<a name="l00250"></a>00250     [<span class="keyword">self</span> <a class="code" href="class_c_p_run_loop.html#aad8e51e44d4c17634d8c45c1ca540217">limitDateForMode</a>:CPDefaultRunLoopMode];
<a name="l00251"></a>00251 }
<a name="l00252"></a>00252 
<a name="l00256"></a><a class="code" href="class_c_p_run_loop.html#a383693dad4536420c4aca85ff964bb7b">00256</a> - (void)addTimer:(<a class="code" href="class_c_p_timer.html" title="A timer object that can send a message after the given time interval.">CPTimer</a>)aTimer forMode:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aMode
<a name="l00257"></a>00257 {
<a name="l00258"></a>00258     <span class="comment">// FIXME: Timer already added...</span>
<a name="l00259"></a>00259     <span class="keywordflow">if</span> (_timersForModes[aMode])
<a name="l00260"></a>00260         _timersForModes[aMode].push(aTimer);
<a name="l00261"></a>00261     <span class="keywordflow">else</span>
<a name="l00262"></a>00262         _timersForModes[aMode] = [aTimer];
<a name="l00263"></a>00263     
<a name="l00264"></a>00264     _didAddTimer = YES;
<a name="l00265"></a>00265     
<a name="l00266"></a>00266     <span class="keywordflow">if</span> (!aTimer._lastNativeRunLoopsForModes)
<a name="l00267"></a>00267         aTimer._lastNativeRunLoopsForModes = {};
<a name="l00268"></a>00268         
<a name="l00269"></a>00269     aTimer._lastNativeRunLoopsForModes[aMode] = <a class="code" href="_c_p_run_loop_8j.html#aea87f8ade30a60e9eb4c73797c491efb">CPRunLoopLastNativeRunLoop</a>;
<a name="l00270"></a>00270 }
<a name="l00271"></a>00271 
<a name="l00275"></a><a class="code" href="class_c_p_run_loop.html#aad8e51e44d4c17634d8c45c1ca540217">00275</a> - (<a class="code" href="class_c_p_date.html" title="A representation of a single point in time.">CPDate</a>)limitDateForMode:(<a class="code" href="class_c_p_string.html" title="An immutable string (collection of characters).">CPString</a>)aMode
<a name="l00276"></a>00276 {
<a name="l00277"></a>00277     <span class="comment">//simple locking to try to prevent concurrent iterating over timers</span>
<a name="l00278"></a>00278     <span class="keywordflow">if</span> (_runLoopLock)
<a name="l00279"></a>00279         <span class="keywordflow">return</span>;
<a name="l00280"></a>00280         
<a name="l00281"></a>00281     _runLoopLock = YES;
<a name="l00282"></a>00282     
<a name="l00283"></a>00283     var now = _effectiveDate ? [_effectiveDate laterDate:[<a class="code" href="class_c_p_date.html" title="A representation of a single point in time.">CPDate</a> <a class="code" href="class_c_p_date.html#a918222c4282c2e0626f3616403793554">date</a>]] : [<a class="code" href="class_c_p_date.html" title="A representation of a single point in time.">CPDate</a> <a class="code" href="class_c_p_date.html#a918222c4282c2e0626f3616403793554">date</a>],
<a name="l00284"></a>00284         nextFireDate = nil,
<a name="l00285"></a>00285         nextTimerFireDate = _nextTimerFireDatesForModes[aMode];
<a name="l00286"></a>00286     
<a name="l00287"></a>00287     <span class="comment">// Perform Timers if necessary</span>
<a name="l00288"></a>00288     <span class="keywordflow">if</span> (_didAddTimer || nextTimerFireDate &amp;&amp; nextTimerFireDate &lt;= now)
<a name="l00289"></a>00289     {
<a name="l00290"></a>00290         _didAddTimer = NO;
<a name="l00291"></a>00291     
<a name="l00292"></a>00292         <span class="comment">// Cancel existing window.setTimeout</span>
<a name="l00293"></a>00293         <span class="keywordflow">if</span> (_nativeTimersForModes[aMode] !== nil)
<a name="l00294"></a>00294         {
<a name="l00295"></a>00295             window.clearNativeTimeout(_nativeTimersForModes[aMode]);
<a name="l00296"></a>00296             
<a name="l00297"></a>00297             _nativeTimersForModes[aMode] = nil;
<a name="l00298"></a>00298         }
<a name="l00299"></a>00299     
<a name="l00300"></a>00300         <span class="comment">// Empty timers to avoid catastrophe if a timer is added during a timer fire.</span>
<a name="l00301"></a>00301         var timers = _timersForModes[aMode],
<a name="l00302"></a>00302             index = timers.length;
<a name="l00303"></a>00303         
<a name="l00304"></a>00304         _timersForModes[aMode] = nil;
<a name="l00305"></a>00305         
<a name="l00306"></a>00306         <span class="comment">//  Loop through timers looking for ones that had fired          </span>
<a name="l00307"></a>00307         <span class="keywordflow">while</span> (index--)
<a name="l00308"></a>00308         {
<a name="l00309"></a>00309             var timer = timers[index];
<a name="l00310"></a>00310             
<a name="l00311"></a>00311             <span class="keywordflow">if</span> (timer._lastNativeRunLoopsForModes[aMode] &lt; <a class="code" href="_c_p_run_loop_8j.html#aea87f8ade30a60e9eb4c73797c491efb">CPRunLoopLastNativeRunLoop</a> &amp;&amp; timer._isValid &amp;&amp; timer._fireDate &lt;= now)
<a name="l00312"></a>00312                 [timer fire];
<a name="l00313"></a>00313                     
<a name="l00314"></a>00314             <span class="comment">// Timer may or may not still be valid</span>
<a name="l00315"></a>00315             <span class="keywordflow">if</span> (timer._isValid)
<a name="l00316"></a>00316                 nextFireDate = (nextFireDate === nil) ? timer._fireDate : [nextFireDate earlierDate:timer._fireDate];
<a name="l00317"></a>00317             
<a name="l00318"></a>00318             <span class="keywordflow">else</span>
<a name="l00319"></a>00319             {
<a name="l00320"></a>00320                 <span class="comment">// FIXME: Is there an issue with reseting the fire date in -fire? or adding it back to the run loop?...</span>
<a name="l00321"></a>00321                 timer._lastNativeRunLoopsForModes[aMode] = 0;
<a name="l00322"></a>00322                 
<a name="l00323"></a>00323                 timers.splice(index, 1);
<a name="l00324"></a>00324             }
<a name="l00325"></a>00325         }
<a name="l00326"></a>00326         
<a name="l00327"></a>00327         <span class="comment">// Timers may have been added during the firing of timers</span>
<a name="l00328"></a>00328         <span class="comment">// They do NOT get a shot at firing, because they certainly </span>
<a name="l00329"></a>00329         <span class="comment">// haven&apos;t gone through one native timer.</span>
<a name="l00330"></a>00330         var newTimers = _timersForModes[aMode];
<a name="l00331"></a>00331         
<a name="l00332"></a>00332         <span class="keywordflow">if</span> (newTimers &amp;&amp; newTimers.length)
<a name="l00333"></a>00333         {
<a name="l00334"></a>00334             index = newTimers.length;
<a name="l00335"></a>00335             
<a name="l00336"></a>00336             <span class="keywordflow">while</span> (index--)
<a name="l00337"></a>00337             {
<a name="l00338"></a>00338                 var timer = newTimers[index];
<a name="l00339"></a>00339                 
<a name="l00340"></a>00340                 <span class="keywordflow">if</span> ([timer isValid])
<a name="l00341"></a>00341                     nextFireDate = (nextFireDate === nil) ? timer._fireDate : [nextFireDate earlierDate:timer._fireDate];
<a name="l00342"></a>00342                 <span class="keywordflow">else</span>
<a name="l00343"></a>00343                     newTimers.splice(index, 1);
<a name="l00344"></a>00344             }
<a name="l00345"></a>00345             
<a name="l00346"></a>00346             _timersForModes[aMode] = newTimers.concat(timers);
<a name="l00347"></a>00347         }
<a name="l00348"></a>00348         <span class="keywordflow">else</span>
<a name="l00349"></a>00349             _timersForModes[aMode] = timers;
<a name="l00350"></a>00350         
<a name="l00351"></a>00351         _nextTimerFireDatesForModes[aMode] = nextFireDate;
<a name="l00352"></a>00352         
<a name="l00353"></a>00353         <span class="comment">//initiate a new window.setTimeout if there are any timers</span>
<a name="l00354"></a>00354         <span class="keywordflow">if</span> (_nextTimerFireDatesForModes[aMode] !== nil)
<a name="l00355"></a>00355             _nativeTimersForModes[aMode] = window.setNativeTimeout(function() { _effectiveDate = nextFireDate; _nativeTimersForModes[aMode] = nil; ++<a class="code" href="_c_p_run_loop_8j.html#aea87f8ade30a60e9eb4c73797c491efb">CPRunLoopLastNativeRunLoop</a>; [<span class="keyword">self</span> <a class="code" href="class_c_p_run_loop.html#aad8e51e44d4c17634d8c45c1ca540217">limitDateForMode</a>:aMode]; _effectiveDate = nil; }, <a class="code" href="_c_p_obj_j_runtime_8j.html#a45f5f88d061da0c18bcb6b6a854fe898">MAX</a>(0, [nextFireDate timeIntervalSinceNow] * 1000));
<a name="l00356"></a>00356     }
<a name="l00357"></a>00357     
<a name="l00358"></a>00358     <span class="comment">// Run loop performers</span>
<a name="l00359"></a>00359     var performs = _orderedPerforms,
<a name="l00360"></a>00360         index = performs.length;
<a name="l00361"></a>00361     
<a name="l00362"></a>00362     _orderedPerforms = [];
<a name="l00363"></a>00363     
<a name="l00364"></a>00364     <span class="keywordflow">while</span> (index--)
<a name="l00365"></a>00365     {
<a name="l00366"></a>00366         var perform = performs[index];
<a name="l00367"></a>00367         
<a name="l00368"></a>00368         <span class="keywordflow">if</span> ([perform fireInMode:<a class="code" href="_c_p_run_loop_8j.html#a51e129fa61aa6aef4c036d4762d468ea">CPDefaultRunLoopMode</a>])
<a name="l00369"></a>00369         {
<a name="l00370"></a>00370             [_CPRunLoopPerform _poolPerform:perform];
<a name="l00371"></a>00371             
<a name="l00372"></a>00372             performs.splice(index, 1);
<a name="l00373"></a>00373         }
<a name="l00374"></a>00374     }
<a name="l00375"></a>00375     
<a name="l00376"></a>00376     <span class="keywordflow">if</span> (_orderedPerforms.length)
<a name="l00377"></a>00377     {
<a name="l00378"></a>00378         _orderedPerforms = _orderedPerforms.concat(performs);
<a name="l00379"></a>00379         _orderedPerforms.sort(_CPRunLoopPerformCompare);
<a name="l00380"></a>00380     }
<a name="l00381"></a>00381     <span class="keywordflow">else</span>
<a name="l00382"></a>00382         _orderedPerforms = performs;
<a name="l00383"></a>00383     
<a name="l00384"></a>00384     _runLoopLock = NO;
<a name="l00385"></a>00385     
<a name="l00386"></a>00386     <span class="keywordflow">return</span> nextFireDate;
<a name="l00387"></a>00387 }
<a name="l00388"></a>00388 
<a name="l00389"></a>00389 <span class="keyword">@end</span>
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated on Tue Apr 6 10:32:57 2010 for Cappuccino API by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>

<!-- Mirrored from cappuccino.org/learn/documentation/_c_p_run_loop_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:31 GMT -->
</html>