Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Side by Side Diff: third_party/WebKit/LayoutTests/shadow-dom/offsetParent.html

Issue 2051703002: Implement closed shadow adjustment for Element.offsetParent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: *ForBinding Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <script src='../resources/testharness.js'></script>
3 <script src='../resources/testharnessreport.js'></script>
4 <script src='resources/shadow-dom.js'></script>
5 <style>
6 .container { position: relative; }
7 </style>
8
9 <!--
10 When both the context object and the real offset parent is in the same
11 node tree, offsetParent doesn't perform any adjustment.
12 -->
13 <div id='host_open0'>
14 <template data-mode='open' data-expose-as='root_open0'>
15 <style>.container { position: relative; }</style>
16 <div id='container' class='container'>
17 <div id='inner_node'>X</div>
18 </div>
19 </template>
20 </div>
21
22 <div id='host_closed0'>
23 <template data-mode='closed' data-expose-as='root_closed0'>
24 <style>.container { position: relative; }</style>
25 <div id='container' class='container'>
26 <div id='inner_node'>X</div>
27 </div>
28 </template>
29 </div>
30
31 <script>
32 test(() => {
33 convertTemplatesToShadowRootsWithin(host_open0);
34 let container = root_open0.querySelector('#container');
35 let inner_node = root_open0.querySelector('#inner_node');
36 assert_equals(inner_node.offsetParent, container);
37 }, 'offsetParent should return node in the same node tree in open shadow root.') ;
38
39 test(() => {
40 convertTemplatesToShadowRootsWithin(host_closed0);
41 let container = root_closed0.querySelector('#container');
42 let inner_node = root_closed0.querySelector('#inner_node');
43 assert_equals(inner_node.offsetParent, container);
44 }, 'offsetParent should return node in the same node tree in closed shadow root. ');
45 </script>
46
47 <!--
48 Even when the real offsetParent is in a closed shadow tree,
49 if it is unclosed to the context object, that parent should be returned.
50 -->
51 <div id='host_open1'>
52 <template data-mode='open' data-expose-as='root_open1'>
53 <style>.container { position: relative; }</style>
54 <div id='inner_host' class='container'>
55 <template data-mode='closed' data-expose-as='root_closed_inner1'>
56 <div id='inner_node'>X</div>
57 </template>
58 </div>
59 </template>
60 </div>
61
62 <div id='host_closed1'>
63 <template data-mode='closed' data-expose-as='root_closed1'>
64 <style>.container { position: relative; }</style>
65 <div id='inner_host' class='container'>
66 <template data-mode='open' data-expose-as='root_open_inner1'>
67 <div id='inner_node'>X</div>
68 </template>
69 </div>
70 </template>
71 </div>
72
73 <script>
74 test(() => {
75 convertTemplatesToShadowRootsWithin(host_open1);
76 let inner_host = root_open1.querySelector('#inner_host');
77 let inner_node = root_closed_inner1.querySelector('#inner_node');
78 assert_equals(inner_node.offsetParent, inner_host);
79 }, 'offsetParent should return an unclosed node in a open shadow from closed sha dow.');
80
81 test(() => {
82 convertTemplatesToShadowRootsWithin(host_closed1);
83 let inner_host = root_closed1.querySelector('#inner_host');
84 let inner_node = root_open_inner1.querySelector('#inner_node');
85 assert_equals(inner_node.offsetParent, inner_host);
86 }, 'offsetParent should return an unclosed node in a closed shadow from open sha dow.');
87 </script>
88
89 <!--
90 #host_open2 and #host_closed2 have the same structure, and #target_open2 /
91 #target_closed2 are slotted into each shadow slot, then real offsetParent would
92 be in the shadow. For the closed shadow, such element should not leak to the
93 light DOM, so it is adjusted to the nearest unclosed offsetParent.
94
95 See also
96 https://github.com/w3c/webcomponents/issues/497
97 https://github.com/w3c/csswg-drafts/issues/159
98 -->
99 <div id='host_open2' class='container'>
100 <template data-mode='open' data-expose-as='root_open2'>
101 <style>.container { position: relative; color: green; }</style>
102 <div id='container_open' class='container'>
103 <slot name='x'></slot>
104 </div>
105 </template>
106 <span id='target_open2' slot='x'>X</span>
107 </div>
108
109 <div id='host_closed2' class='container'>
110 <template data-mode='closed' data-expose-as='root_closed2'>
111 <style>.container { position: relative; color: red; }</style>
112 <div id='container_closed' class='container'>
113 <slot name='x'></slot>
114 </div>
115 </template>
116 <span id='target_closed2' slot='x'>X</span>
117 </div>
118
119 <script>
120 test(() => {
121 convertTemplatesToShadowRootsWithin(host_open2);
122 convertTemplatesToShadowRootsWithin(host_closed2);
123
124 assert_equals(target_open2.offsetParent.id, 'container_open');
125 assert_equals(target_closed2.offsetParent.id, 'host_closed2');
126 }, 'offsetParent should return an unclosed node.');
127 </script>
128
129 <!--
130 Check if offsetParent can properly traverse up to find unclosed node.
131 In the following example, #target_closed3 will distributed to slot y,
132 but its offsetParent should neither return #inner_node nor #inner_host.
133 -->
134 <div id='host_closed3' class='container'>
135 <template data-mode='closed' data-expose-as='root_closed3'>
136 <style>.container { position: relative; }</style>
137 <div id='inner_host' class='container'>
138 <template data-mode='closed' data-expose-as='root_closed_inner3'>
139 <style>.container { position: relative; }</style>
140 <div id='inner_node' class='container'>
141 <slot name='y'></slot>
142 </div>
143 </template>
144 <slot name='x' slot='y'></slot>
145 </div>
146 </template>
147 <span id='target_closed3' slot='x'>Z</span>
148 </div>
149
150 <script>
151 test(() => {
152 convertTemplatesToShadowRootsWithin(host_closed3);
153 let slot_y = root_closed_inner3.querySelector('slot[name=y]');
154 assert_array_equals(slot_y.assignedNodes({flatten: true}), [target_closed3]);
155 assert_equals(target_closed3.offsetParent.id, 'host_closed3');
156 }, 'offsetParent should skip any non-unclosed nodes.');
157 </script>
158
159 <!--
160 Yet another test case if the check for unclosed node is working as expected.
161 #inner_node is inside slotted closed shadow tree, but #container should be
162 unclosed to #inner_node.
163 -->
164 <div id='host_open4'>
165 <template data-mode='open' data-expose-as='root_open4'>
166 <style>.container { position: relative; }</style>
167 <div id='container' class='container'>
168 <slot name='x'></slot>
169 </div>
170 </template>
171 <div id='host_closed4' slot='x'>
172 <template data-mode='closed' data-expose-as='root_closed4'>
173 <style>.container { position: relative; }</style>
174 <div id='inner_node'>Y</div>
175 </template>
176 </div>
177 </div>
178
179 <script>
180 test(() => {
181 convertTemplatesToShadowRootsWithin(host_open4);
182 let container = root_open4.querySelector('#container');
183 let inner_node = root_closed4.querySelector('#inner_node');
184 assert_equals(inner_node.offsetParent, container);
hayato 2016/06/22 03:58:34 It looks innerNode.offsetParent should be host_clo
hayato 2016/06/22 04:45:35 I understand. Its position is static. That should
kochi 2016/06/22 06:33:12 This test was added to make sure Node.isUnclosedNo
185 }, 'offsetParent should return node in the open shadow root because it is unclos ed.');
186 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698