@@ -14,14 +14,15 @@ import 'package:angular/core/module.dart' show Scope, RootScope;
14
14
import 'package:angular/core/annotation.dart' show Visibility, DirectiveBinder;
15
15
import 'package:angular/core_dom/module_internal.dart'
16
16
show Animate, View, ViewFactory, BoundViewFactory, ViewPort, NodeAttrs, ElementProbe,
17
- NgElement, ContentPort , TemplateLoader, ShadowRootEventHandler, EventHandler;
17
+ NgElement, DestinationLightDom, SourceLightDom, LightDom , TemplateLoader, ShadowRootEventHandler, EventHandler;
18
18
19
19
var _TAG_GET = new UserTag ('DirectiveInjector.get()' );
20
20
var _TAG_INSTANTIATE = new UserTag ('DirectiveInjector.instantiate()' );
21
21
22
22
final DIRECTIVE_INJECTOR_KEY = new Key (DirectiveInjector );
23
23
final COMPONENT_DIRECTIVE_INJECTOR_KEY = new Key (ComponentDirectiveInjector );
24
- final CONTENT_PORT_KEY = new Key (ContentPort );
24
+ final DESTINATION_LIGHT_DOM_KEY = new Key (DestinationLightDom );
25
+ final SOURCE_LIGHT_DOM_KEY = new Key (SourceLightDom );
25
26
final TEMPLATE_LOADER_KEY = new Key (TemplateLoader );
26
27
final SHADOW_ROOT_KEY = new Key (ShadowRoot );
27
28
@@ -31,26 +32,27 @@ const int VISIBILITY_LOCAL = -1;
31
32
const int VISIBILITY_DIRECT_CHILD = - 2 ;
32
33
const int VISIBILITY_CHILDREN = - 3 ;
33
34
34
- const int UNDEFINED_ID = 0 ;
35
- const int INJECTOR_KEY_ID = 1 ;
36
- const int DIRECTIVE_INJECTOR_KEY_ID = 2 ;
37
- const int NODE_KEY_ID = 3 ;
38
- const int ELEMENT_KEY_ID = 4 ;
39
- const int NODE_ATTRS_KEY_ID = 5 ;
40
- const int ANIMATE_KEY_ID = 6 ;
41
- const int SCOPE_KEY_ID = 7 ;
42
- const int VIEW_KEY_ID = 8 ;
43
- const int VIEW_PORT_KEY_ID = 9 ;
44
- const int VIEW_FACTORY_KEY_ID = 10 ;
45
- const int NG_ELEMENT_KEY_ID = 11 ;
46
- const int BOUND_VIEW_FACTORY_KEY_ID = 12 ;
47
- const int ELEMENT_PROBE_KEY_ID = 13 ;
48
- const int TEMPLATE_LOADER_KEY_ID = 14 ;
49
- const int SHADOW_ROOT_KEY_ID = 15 ;
50
- const int CONTENT_PORT_KEY_ID = 16 ;
51
- const int EVENT_HANDLER_KEY_ID = 17 ;
52
- const int COMPONENT_DIRECTIVE_INJECTOR_KEY_ID = 18 ;
53
- const int KEEP_ME_LAST = 19 ;
35
+ const int UNDEFINED_ID = 0 ;
36
+ const int INJECTOR_KEY_ID = 1 ;
37
+ const int DIRECTIVE_INJECTOR_KEY_ID = 2 ;
38
+ const int NODE_KEY_ID = 3 ;
39
+ const int ELEMENT_KEY_ID = 4 ;
40
+ const int NODE_ATTRS_KEY_ID = 5 ;
41
+ const int ANIMATE_KEY_ID = 6 ;
42
+ const int SCOPE_KEY_ID = 7 ;
43
+ const int VIEW_KEY_ID = 8 ;
44
+ const int VIEW_PORT_KEY_ID = 9 ;
45
+ const int VIEW_FACTORY_KEY_ID = 10 ;
46
+ const int NG_ELEMENT_KEY_ID = 11 ;
47
+ const int BOUND_VIEW_FACTORY_KEY_ID = 12 ;
48
+ const int ELEMENT_PROBE_KEY_ID = 13 ;
49
+ const int TEMPLATE_LOADER_KEY_ID = 14 ;
50
+ const int SHADOW_ROOT_KEY_ID = 15 ;
51
+ const int DESTINATION_LIGHT_DOM_KEY_ID = 16 ;
52
+ const int SOURCE_LIGHT_DOM_KEY_ID = 17 ;
53
+ const int EVENT_HANDLER_KEY_ID = 18 ;
54
+ const int COMPONENT_DIRECTIVE_INJECTOR_KEY_ID = 19 ;
55
+ const int KEEP_ME_LAST = 20 ;
54
56
55
57
EventHandler eventHandler (DirectiveInjector di) => di._eventHandler;
56
58
@@ -59,23 +61,24 @@ class DirectiveInjector implements DirectiveBinder {
59
61
static initUID () {
60
62
if (_isInit) return ;
61
63
_isInit = true ;
62
- INJECTOR_KEY .uid = INJECTOR_KEY_ID ;
63
- DIRECTIVE_INJECTOR_KEY .uid = DIRECTIVE_INJECTOR_KEY_ID ;
64
- NODE_KEY .uid = NODE_KEY_ID ;
65
- ELEMENT_KEY .uid = ELEMENT_KEY_ID ;
66
- NODE_ATTRS_KEY .uid = NODE_ATTRS_KEY_ID ;
67
- SCOPE_KEY .uid = SCOPE_KEY_ID ;
68
- VIEW_KEY .uid = VIEW_KEY_ID ;
69
- VIEW_PORT_KEY .uid = VIEW_PORT_KEY_ID ;
70
- VIEW_FACTORY_KEY .uid = VIEW_FACTORY_KEY_ID ;
71
- NG_ELEMENT_KEY .uid = NG_ELEMENT_KEY_ID ;
72
- BOUND_VIEW_FACTORY_KEY .uid = BOUND_VIEW_FACTORY_KEY_ID ;
73
- ELEMENT_PROBE_KEY .uid = ELEMENT_PROBE_KEY_ID ;
74
- TEMPLATE_LOADER_KEY .uid = TEMPLATE_LOADER_KEY_ID ;
75
- SHADOW_ROOT_KEY .uid = SHADOW_ROOT_KEY_ID ;
76
- CONTENT_PORT_KEY .uid = CONTENT_PORT_KEY_ID ;
77
- EVENT_HANDLER_KEY .uid = EVENT_HANDLER_KEY_ID ;
78
- ANIMATE_KEY .uid = ANIMATE_KEY_ID ;
64
+ INJECTOR_KEY .uid = INJECTOR_KEY_ID ;
65
+ DIRECTIVE_INJECTOR_KEY .uid = DIRECTIVE_INJECTOR_KEY_ID ;
66
+ NODE_KEY .uid = NODE_KEY_ID ;
67
+ ELEMENT_KEY .uid = ELEMENT_KEY_ID ;
68
+ NODE_ATTRS_KEY .uid = NODE_ATTRS_KEY_ID ;
69
+ SCOPE_KEY .uid = SCOPE_KEY_ID ;
70
+ VIEW_KEY .uid = VIEW_KEY_ID ;
71
+ VIEW_PORT_KEY .uid = VIEW_PORT_KEY_ID ;
72
+ VIEW_FACTORY_KEY .uid = VIEW_FACTORY_KEY_ID ;
73
+ NG_ELEMENT_KEY .uid = NG_ELEMENT_KEY_ID ;
74
+ BOUND_VIEW_FACTORY_KEY .uid = BOUND_VIEW_FACTORY_KEY_ID ;
75
+ ELEMENT_PROBE_KEY .uid = ELEMENT_PROBE_KEY_ID ;
76
+ TEMPLATE_LOADER_KEY .uid = TEMPLATE_LOADER_KEY_ID ;
77
+ SHADOW_ROOT_KEY .uid = SHADOW_ROOT_KEY_ID ;
78
+ DESTINATION_LIGHT_DOM_KEY .uid = DESTINATION_LIGHT_DOM_KEY_ID ;
79
+ SOURCE_LIGHT_DOM_KEY .uid = SOURCE_LIGHT_DOM_KEY_ID ;
80
+ EVENT_HANDLER_KEY .uid = EVENT_HANDLER_KEY_ID ;
81
+ ANIMATE_KEY .uid = ANIMATE_KEY_ID ;
79
82
COMPONENT_DIRECTIVE_INJECTOR_KEY .uid = COMPONENT_DIRECTIVE_INJECTOR_KEY_ID ;
80
83
for (var i = 1 ; i < KEEP_ME_LAST ; i++ ) {
81
84
if (_KEYS [i].uid != i) throw 'MISSORDERED KEYS ARRAY: ${_KEYS } at $i ' ;
@@ -98,7 +101,8 @@ class DirectiveInjector implements DirectiveBinder {
98
101
, ELEMENT_PROBE_KEY
99
102
, TEMPLATE_LOADER_KEY
100
103
, SHADOW_ROOT_KEY
101
- , CONTENT_PORT_KEY
104
+ , DESTINATION_LIGHT_DOM_KEY
105
+ , SOURCE_LIGHT_DOM_KEY
102
106
, EVENT_HANDLER_KEY
103
107
, COMPONENT_DIRECTIVE_INJECTOR_KEY
104
108
, KEEP_ME_LAST
@@ -110,6 +114,7 @@ class DirectiveInjector implements DirectiveBinder {
110
114
final NodeAttrs _nodeAttrs;
111
115
final Animate _animate;
112
116
final EventHandler _eventHandler;
117
+ LightDom lightDom;
113
118
Scope scope; //TODO(misko): this should be final after we get rid of controller
114
119
final View _view;
115
120
@@ -282,24 +287,19 @@ class DirectiveInjector implements DirectiveBinder {
282
287
283
288
Object _getById (int keyId) {
284
289
switch (keyId) {
285
- case INJECTOR_KEY_ID : return _appInjector;
286
- case DIRECTIVE_INJECTOR_KEY_ID : return this ;
287
- case NODE_KEY_ID : return _node;
288
- case ELEMENT_KEY_ID : return _node;
289
- case NODE_ATTRS_KEY_ID : return _nodeAttrs;
290
- case ANIMATE_KEY_ID : return _animate;
291
- case SCOPE_KEY_ID : return scope;
292
- case ELEMENT_PROBE_KEY_ID : return elementProbe;
293
- case NG_ELEMENT_KEY_ID : return ngElement;
294
- case EVENT_HANDLER_KEY_ID : return _eventHandler;
295
- case CONTENT_PORT_KEY_ID :
296
- var currentInjector = _parent;
297
- while (currentInjector != null ) {
298
- if (currentInjector is ComponentDirectiveInjector ) return currentInjector._contentPort;
299
- currentInjector = currentInjector._parent;
300
- }
301
- return null ;
302
- case VIEW_KEY_ID : return _view;
290
+ case INJECTOR_KEY_ID : return _appInjector;
291
+ case DIRECTIVE_INJECTOR_KEY_ID : return this ;
292
+ case NODE_KEY_ID : return _node;
293
+ case ELEMENT_KEY_ID : return _node;
294
+ case NODE_ATTRS_KEY_ID : return _nodeAttrs;
295
+ case ANIMATE_KEY_ID : return _animate;
296
+ case SCOPE_KEY_ID : return scope;
297
+ case ELEMENT_PROBE_KEY_ID : return elementProbe;
298
+ case NG_ELEMENT_KEY_ID : return ngElement;
299
+ case EVENT_HANDLER_KEY_ID : return _eventHandler;
300
+ case DESTINATION_LIGHT_DOM_KEY_ID : return _destLightDom;
301
+ case SOURCE_LIGHT_DOM_KEY_ID : return _sourceLightDom;
302
+ case VIEW_KEY_ID : return _view;
303
303
default : new NoProviderError (_KEYS [keyId]);
304
304
}
305
305
}
@@ -367,10 +367,20 @@ class DirectiveInjector implements DirectiveBinder {
367
367
368
368
NgElement get ngElement {
369
369
if (_ngElement == null ) {
370
- _ngElement = new NgElement (_node, scope, _animate);
370
+ _ngElement = new NgElement (_node, scope, _animate, _destLightDom );
371
371
}
372
372
return _ngElement;
373
373
}
374
+
375
+ SourceLightDom get _sourceLightDom {
376
+ var curr = _parent;
377
+ while (curr != null && curr is ! ComponentDirectiveInjector ) {
378
+ curr = curr.parent;
379
+ }
380
+ return curr == null || curr.parent == null ? null : curr.parent.lightDom;
381
+ }
382
+
383
+ DestinationLightDom get _destLightDom => _parent == null ? null : _parent.lightDom;
374
384
}
375
385
376
386
class TemplateDirectiveInjector extends DirectiveInjector {
@@ -388,29 +398,35 @@ class TemplateDirectiveInjector extends DirectiveInjector {
388
398
switch (keyId) {
389
399
case VIEW_FACTORY_KEY_ID : return _viewFactory;
390
400
case VIEW_PORT_KEY_ID : return ((_viewPort) == null ) ?
391
- _viewPort = new ViewPort ( this , scope, _node, _animate ) : _viewPort;
401
+ _viewPort = _createViewPort ( ) : _viewPort;
392
402
case BOUND_VIEW_FACTORY_KEY_ID : return (_boundViewFactory == null ) ?
393
403
_boundViewFactory = _viewFactory.bind (_parent) : _boundViewFactory;
394
404
default : return super ._getById (keyId);
395
405
}
396
406
}
397
407
408
+ ViewPort _createViewPort () {
409
+ final viewPort = new ViewPort (this , scope, _node, _animate, _destLightDom);
410
+ if (_destLightDom != null ) _destLightDom.addViewPort (viewPort);
411
+ return viewPort;
412
+ }
413
+
398
414
}
399
415
400
416
class ComponentDirectiveInjector extends DirectiveInjector {
401
417
402
418
final TemplateLoader _templateLoader;
403
419
final ShadowRoot _shadowRoot;
404
- final ContentPort _contentPort;
405
420
406
421
ComponentDirectiveInjector (DirectiveInjector parent, Injector appInjector,
407
422
EventHandler eventHandler, Scope scope,
408
- this ._templateLoader, this ._shadowRoot, this ._contentPort , [View view])
423
+ this ._templateLoader, this ._shadowRoot, LightDom lightDom , [View view])
409
424
: super (parent, appInjector, parent._node, parent._nodeAttrs, eventHandler, scope,
410
425
parent._animate, view) {
411
426
// A single component creates a ComponentDirectiveInjector and its DirectiveInjector parent,
412
427
// so parent should never be null.
413
428
assert (parent != null );
429
+ _parent.lightDom = lightDom;
414
430
}
415
431
416
432
Object _getById (int keyId) {
@@ -435,4 +451,3 @@ class ComponentDirectiveInjector extends DirectiveInjector {
435
451
// For example, a local directive is visible from its component injector children.
436
452
num _getDepth (int visType) => super ._getDepth (visType) + 1 ;
437
453
}
438
-
0 commit comments