@@ -15,6 +15,64 @@ cls.EventName = function(name)
1515 this . obj_id = 0 ;
1616} ;
1717
18+ cls . EventName . prototype = new function ( )
19+ {
20+ var SEARCH_TYPE_EVENT = 5 ;
21+
22+ this . search_dom = function ( rt_id , obj_id , ev_name , cb )
23+ {
24+ this . rt_id = rt_id ;
25+ this . obj_id = obj_id ;
26+ this . model = new cls . InspectableDOMNode ( rt_id , obj_id ) ;
27+ this . model . search ( ev_name , SEARCH_TYPE_EVENT , 0 , 0 , cb ) ;
28+ } ;
29+ } ;
30+
31+ cls . RTListUpdateCTX = function ( rt_id_list , cb )
32+ {
33+ this . _init ( rt_id_list , cb ) ;
34+ } ;
35+
36+ cls . RTListUpdateCTX . prototype = new function ( )
37+ {
38+ this . _handle_expand_listener = function ( ev_name_obj )
39+ {
40+ var list = this . expanded_map [ ev_name_obj . rt_id ] ;
41+ var index = list . indexOf ( ev_name_obj . name ) ;
42+ if ( index > - 1 )
43+ list . splice ( index , 1 ) ;
44+ else
45+ opera . postError ( ui_strings . S_DRAGONFLY_INFO_MESSAGE +
46+ "_handle_expand_listener failed in cls.EvenetListeners." )
47+
48+ this . check_is_updated ( ) ;
49+ } ;
50+
51+ this . _check_rt = function ( rt_id )
52+ {
53+ return this . rt_map . hasOwnProperty ( rt_id ) &&
54+ ( ! this . rt_map [ rt_id ] || ( this . expanded_map [ rt_id ] &&
55+ this . expanded_map [ rt_id ] . length === 0 ) ) ;
56+ } ;
57+
58+ this . check_is_updated = function ( )
59+ {
60+ if ( this . rt_id_list . every ( this . _check_rt ) )
61+ this . _cb ( this ) ;
62+ } ;
63+
64+ this . _init = function ( rt_id_list , cb )
65+ {
66+ this . rt_id_list = rt_id_list ;
67+ this . rt_map = { } ;
68+ this . win_id_map = { } ;
69+ this . expanded_map = { } ;
70+ this . handle_expand_listener = this . _handle_expand_listener . bind ( this ) ;
71+ this . _check_rt = this . _check_rt . bind ( this ) ;
72+ this . _cb = cb ;
73+ } ;
74+ } ;
75+
1876cls . EvenetListeners = function ( view )
1977{
2078 this . _init ( view ) ;
@@ -33,31 +91,17 @@ cls.EvenetListeners.prototype = new function()
3391
3492 var SUCCESS = 0 ;
3593 var SEARCH_TYPE_EVENT = 5 ;
94+ var DELAY = 150 ;
95+ var GET_RT_ID = function ( rt ) { return rt . rt_id } ;
3696
3797 /*
38- data structure
98+ data structure:
3999
40- this._rts =
41- [
42- {
43- rt_id: <rt-id>,
44- obj_id: <obj-id>,
45- event_names:
46- [
47- {
48- name: <name>,
49- is_expanded: <boolean>,
50- },
51- ...
52- ]
53- },
54- ...
55- ]
56-
100+ this._rts = [{rt_id: <rt-id>,
101+ obj_id: <obj-id>,
102+ event_names: [<EventName>, ...]}, ...]
57103 */
58104
59- var DELAY = 150 ;
60-
61105 this . _on_new_rts = function ( )
62106 {
63107 if ( ! this . _on_new_rts_timeout )
@@ -67,7 +111,7 @@ cls.EvenetListeners.prototype = new function()
67111 this . _handle_new_rts = function ( )
68112 {
69113 var rt_ids = window . runtimes . get_dom_runtime_ids ( ) ;
70- var cur_rt_ids = this . _rts . map ( this . _get_rt_id ) ;
114+ var cur_rt_ids = this . _rts . map ( GET_RT_ID ) ;
71115 var new_rt_ids = rt_ids . filter ( function ( id ) { return ! cur_rt_ids . contains ( id ) ; } ) ;
72116 var live_rts = this . _rts . filter ( function ( rt ) { return rt_ids . contains ( rt . rt_id ) ; } ) ;
73117 if ( live_rts . length != this . _rts . length )
@@ -81,15 +125,21 @@ cls.EvenetListeners.prototype = new function()
81125 this . _on_new_rts_timeout = 0 ;
82126 } ;
83127
84- this . _get_rt_id = function ( rt ) { return rt . rt_id } ;
85-
86128 this . _update_rt_list = function ( rt_id_list )
87129 {
88- var ctx = { rt_id_list : rt_id_list , rt_map : { } , win_id_map : { } , expanded_map : { } } ;
89- ctx . handle_expand_listener = this . _handle_expand_listener_on_update . bind ( this , ctx ) ;
130+ var ctx = new cls . RTListUpdateCTX ( rt_id_list , this . on_rt_list_update_bound ) ;
90131 rt_id_list . forEach ( this . _get_window_ids . bind ( this , ctx ) ) ;
91132 } ;
92133
134+ this . _on_rt_list_update = function ( ctx )
135+ {
136+ for ( var i = 0 , id ; id = ctx . rt_id_list [ i ] ; i ++ )
137+ {
138+ this . _rts [ this . _get_rt_index ( id ) ] = ctx . rt_map [ id ] ;
139+ }
140+ this . _view . update ( ) ;
141+ } ;
142+
93143 this . _get_window_ids = function ( ctx , rt_id )
94144 {
95145 var sel_rt_id = window . runtimes . getSelectedRuntimeId ( ) ;
@@ -110,7 +160,7 @@ cls.EvenetListeners.prototype = new function()
110160 var STATUS = 0 ;
111161 var OBJECT_VALUE = 3 ;
112162 var OBJECT_ID = 0 ;
113- if ( status === SUCCESS && message [ STATUS ] == "completed" && message [ OBJECT_VALUE ] )
163+ if ( status === SUCCESS && message [ STATUS ] === "completed" && message [ OBJECT_VALUE ] )
114164 {
115165 this . _win_id_map [ rt_id ] = ctx . win_id_map [ rt_id ] = message [ OBJECT_VALUE ] [ OBJECT_ID ] ;
116166 if ( ctx . rt_id_list . every ( function ( rt_id ) { return ctx . win_id_map [ rt_id ] ; } ) )
@@ -150,13 +200,10 @@ cls.EvenetListeners.prototype = new function()
150200 if ( this . is_expanded ( rt_id , name ) )
151201 {
152202 ctx . expanded_map [ rt_id ] . push ( name ) ;
153- ev_n_obj . rt_id = rt_id ;
154- ev_n_obj . obj_id = obj_id ;
155- ev_n_obj . model = new cls . InspectableDOMNode ( rt_id , obj_id ) ;
156203 var search_cb = this . _handle_dom_search . bind ( this ,
157204 ev_n_obj ,
158205 ctx . handle_expand_listener ) ;
159- ev_n_obj . model . search ( name , SEARCH_TYPE_EVENT , 0 , 0 , search_cb ) ;
206+ ev_n_obj . search_dom ( rt_id , obj_id , name , search_cb ) ;
160207 }
161208 return ev_n_obj ;
162209 } , this ) ;
@@ -165,44 +212,13 @@ cls.EvenetListeners.prototype = new function()
165212 rt_listeners . event_names = [ ] ;
166213
167214 ctx . rt_map [ rt_id ] = rt_listeners ;
168- this . _check_update_ctx ( ctx ) ;
215+ ctx . check_is_updated ( ) ;
169216 }
170217 else
171218 opera . postError ( ui_strings . S_DRAGONFLY_INFO_MESSAGE +
172219 "failed to retrieve the event names in cls.EvenetListeners." )
173220 } ;
174221
175- this . _handle_expand_listener_on_update = function ( ctx , ev_name_obj )
176- {
177- var list = ctx . expanded_map [ ev_name_obj . rt_id ] ;
178- var index = list . indexOf ( ev_name_obj . name ) ;
179- if ( index > - 1 )
180- list . splice ( index , 1 ) ;
181- else
182- opera . postError ( ui_strings . S_DRAGONFLY_INFO_MESSAGE +
183- "_handle_expand_listener_on_update failed in cls.EvenetListeners." )
184-
185- this . _check_update_ctx ( ctx ) ;
186- } ;
187-
188- this . _check_update_ctx = function ( ctx )
189- {
190- var check_rt = function ( rt_id )
191- {
192- return ctx . rt_map . hasOwnProperty ( rt_id ) &&
193- ( ! ctx . rt_map [ rt_id ] || ( ctx . expanded_map [ rt_id ] &&
194- ctx . expanded_map [ rt_id ] . length === 0 ) ) ;
195- } ;
196- if ( ctx . rt_id_list . every ( check_rt ) )
197- {
198- for ( var i = 0 , id ; id = ctx . rt_id_list [ i ] ; i ++ )
199- {
200- this . _rts [ this . _get_rt_index ( id ) ] = ctx . rt_map [ id ] ;
201- }
202- this . _view . update ( ) ;
203- }
204- } ;
205-
206222 this . _handle_dom_search = function ( ev_name_obj , cb )
207223 {
208224 var tag = this . _tagman . set_callback ( this , this . _handle_obj_search , [ ev_name_obj , cb ] ) ;
@@ -295,14 +311,11 @@ cls.EvenetListeners.prototype = new function()
295311
296312 this . expand_listeners = function ( rt_id , obj_id , ev_name , cb )
297313 {
298- var ev_n = this . _get_ev_name_obj ( rt_id , ev_name ) ;
299- if ( ev_n )
314+ var ev_n_obj = this . _get_ev_name_obj ( rt_id , ev_name ) ;
315+ if ( ev_n_obj )
300316 {
301- ev_n . rt_id = rt_id ;
302- ev_n . obj_id = obj_id ;
303- ev_n . model = new cls . InspectableDOMNode ( rt_id , obj_id ) ;
304- var search_cb = this . _handle_dom_search . bind ( this , ev_n , cb ) ;
305- ev_n . model . search ( ev_name , SEARCH_TYPE_EVENT , 0 , 0 , search_cb ) ;
317+ var search_cb = this . _handle_dom_search . bind ( this , ev_n_obj , cb ) ;
318+ ev_n_obj . search_dom ( rt_id , obj_id , ev_name , search_cb ) ;
306319 }
307320 else
308321 opera . postError ( ui_strings . S_DRAGONFLY_INFO_MESSAGE +
@@ -335,6 +348,7 @@ cls.EvenetListeners.prototype = new function()
335348 {
336349 this . _on_new_rts_timeout = 0 ;
337350 this . _handle_new_rts_bound = this . _handle_new_rts . bind ( this ) ;
351+ this . on_rt_list_update_bound = this . _on_rt_list_update . bind ( this ) ;
338352 this . _rts = [ ] ;
339353 this . _win_id_map = { } ;
340354 this . _expand_tree = { } ;
@@ -344,5 +358,4 @@ cls.EvenetListeners.prototype = new function()
344358 window . messages . add_listener ( "active-tab" , this . _on_new_rts . bind ( this ) ) ;
345359 } ;
346360
347-
348361} ;
0 commit comments