OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/HTMLNames.h" | 5 #include "core/HTMLNames.h" |
6 #include "core/dom/Document.h" | 6 #include "core/dom/Document.h" |
7 #include "core/dom/Element.h" | 7 #include "core/dom/Element.h" |
8 #include "core/dom/ElementTraversal.h" | 8 #include "core/dom/ElementTraversal.h" |
9 #include "core/dom/NodeComputedStyle.h" | 9 #include "core/dom/NodeComputedStyle.h" |
10 #include "core/dom/StyleEngine.h" | 10 #include "core/dom/StyleEngine.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 element->computedStyle()->affectedByFocus()); | 65 element->computedStyle()->affectedByFocus()); |
66 ASSERT_EQ(expected[i].childrenOrSiblingsAffectedBy, | 66 ASSERT_EQ(expected[i].childrenOrSiblingsAffectedBy, |
67 element->childrenOrSiblingsAffectedByFocus()); | 67 element->childrenOrSiblingsAffectedByFocus()); |
68 } | 68 } |
69 | 69 |
70 ASSERT(!element && i == expectedCount); | 70 ASSERT(!element && i == expectedCount); |
71 } | 71 } |
72 | 72 |
73 // A global :focus rule in html.css currently causes every single element to be | 73 // A global :focus rule in html.css currently causes every single element to be |
74 // affectedByFocus. Check that all elements in a document with no :focus rules | 74 // affectedByFocus. Check that all elements in a document with no :focus rules |
75 // gets the affectedByFocus set on ComputedStyle and not childrenOrSiblingsAffec
tedByFocus. | 75 // gets the affectedByFocus set on ComputedStyle and not |
| 76 // childrenOrSiblingsAffectedByFocus. |
76 TEST_F(AffectedByFocusTest, UAUniversalFocusRule) { | 77 TEST_F(AffectedByFocusTest, UAUniversalFocusRule) { |
77 ElementResult expected[] = {{bodyTag, true, false}, | 78 ElementResult expected[] = {{bodyTag, true, false}, |
78 {divTag, true, false}, | 79 {divTag, true, false}, |
79 {divTag, true, false}, | 80 {divTag, true, false}, |
80 {divTag, true, false}, | 81 {divTag, true, false}, |
81 {spanTag, true, false}}; | 82 {spanTag, true, false}}; |
82 | 83 |
83 setHtmlInnerHTML( | 84 setHtmlInnerHTML( |
84 "<body>" | 85 "<body>" |
85 "<div><div></div></div>" | 86 "<div><div></div></div>" |
86 "<div><span></span></div>" | 87 "<div><span></span></div>" |
87 "</body>"); | 88 "</body>"); |
88 | 89 |
89 checkElements(expected, sizeof(expected) / sizeof(ElementResult)); | 90 checkElements(expected, sizeof(expected) / sizeof(ElementResult)); |
90 } | 91 } |
91 | 92 |
92 // ":focus div" will mark ascendants of all divs with childrenOrSiblingsAffected
ByFocus. | 93 // ":focus div" will mark ascendants of all divs with |
| 94 // childrenOrSiblingsAffectedByFocus. |
93 TEST_F(AffectedByFocusTest, FocusedAscendant) { | 95 TEST_F(AffectedByFocusTest, FocusedAscendant) { |
94 ElementResult expected[] = {{bodyTag, true, true}, | 96 ElementResult expected[] = {{bodyTag, true, true}, |
95 {divTag, true, true}, | 97 {divTag, true, true}, |
96 {divTag, true, false}, | 98 {divTag, true, false}, |
97 {divTag, true, false}, | 99 {divTag, true, false}, |
98 {spanTag, true, false}}; | 100 {spanTag, true, false}}; |
99 | 101 |
100 setHtmlInnerHTML( | 102 setHtmlInnerHTML( |
101 "<head>" | 103 "<head>" |
102 "<style>:focus div { background-color: pink }</style>" | 104 "<style>:focus div { background-color: pink }</style>" |
103 "</head>" | 105 "</head>" |
104 "<body>" | 106 "<body>" |
105 "<div><div></div></div>" | 107 "<div><div></div></div>" |
106 "<div><span></span></div>" | 108 "<div><span></span></div>" |
107 "</body>"); | 109 "</body>"); |
108 | 110 |
109 checkElements(expected, sizeof(expected) / sizeof(ElementResult)); | 111 checkElements(expected, sizeof(expected) / sizeof(ElementResult)); |
110 } | 112 } |
111 | 113 |
112 // "body:focus div" will mark the body element with childrenOrSiblingsAffectedBy
Focus. | 114 // "body:focus div" will mark the body element with |
| 115 // childrenOrSiblingsAffectedByFocus. |
113 TEST_F(AffectedByFocusTest, FocusedAscendantWithType) { | 116 TEST_F(AffectedByFocusTest, FocusedAscendantWithType) { |
114 ElementResult expected[] = {{bodyTag, true, true}, | 117 ElementResult expected[] = {{bodyTag, true, true}, |
115 {divTag, true, false}, | 118 {divTag, true, false}, |
116 {divTag, true, false}, | 119 {divTag, true, false}, |
117 {divTag, true, false}, | 120 {divTag, true, false}, |
118 {spanTag, true, false}}; | 121 {spanTag, true, false}}; |
119 | 122 |
120 setHtmlInnerHTML( | 123 setHtmlInnerHTML( |
121 "<head>" | 124 "<head>" |
122 "<style>body:focus div { background-color: pink }</style>" | 125 "<style>body:focus div { background-color: pink }</style>" |
123 "</head>" | 126 "</head>" |
124 "<body>" | 127 "<body>" |
125 "<div><div></div></div>" | 128 "<div><div></div></div>" |
126 "<div><span></span></div>" | 129 "<div><span></span></div>" |
127 "</body>"); | 130 "</body>"); |
128 | 131 |
129 checkElements(expected, sizeof(expected) / sizeof(ElementResult)); | 132 checkElements(expected, sizeof(expected) / sizeof(ElementResult)); |
130 } | 133 } |
131 | 134 |
132 // ":not(body):focus div" should not mark the body element with childrenOrSiblin
gsAffectedByFocus. | 135 // ":not(body):focus div" should not mark the body element with |
133 // Note that currently ":focus:not(body)" does not do the same. Then the :focus
is | 136 // childrenOrSiblingsAffectedByFocus. |
134 // checked and the childrenOrSiblingsAffectedByFocus flag set before the negated
type selector | 137 // Note that currently ":focus:not(body)" does not do the same. Then the :focus |
135 // is found. | 138 // is checked and the childrenOrSiblingsAffectedByFocus flag set before the |
| 139 // negated type selector is found. |
136 TEST_F(AffectedByFocusTest, FocusedAscendantWithNegatedType) { | 140 TEST_F(AffectedByFocusTest, FocusedAscendantWithNegatedType) { |
137 ElementResult expected[] = {{bodyTag, true, false}, | 141 ElementResult expected[] = {{bodyTag, true, false}, |
138 {divTag, true, true}, | 142 {divTag, true, true}, |
139 {divTag, true, false}, | 143 {divTag, true, false}, |
140 {divTag, true, false}, | 144 {divTag, true, false}, |
141 {spanTag, true, false}}; | 145 {spanTag, true, false}}; |
142 | 146 |
143 setHtmlInnerHTML( | 147 setHtmlInnerHTML( |
144 "<head>" | 148 "<head>" |
145 "<style>:not(body):focus div { background-color: pink }</style>" | 149 "<style>:not(body):focus div { background-color: pink }</style>" |
146 "</head>" | 150 "</head>" |
147 "<body>" | 151 "<body>" |
148 "<div><div></div></div>" | 152 "<div><div></div></div>" |
149 "<div><span></span></div>" | 153 "<div><span></span></div>" |
150 "</body>"); | 154 "</body>"); |
151 | 155 |
152 checkElements(expected, sizeof(expected) / sizeof(ElementResult)); | 156 checkElements(expected, sizeof(expected) / sizeof(ElementResult)); |
153 } | 157 } |
154 | 158 |
155 // Checking current behavior for ":focus + div", but this is a BUG or at best | 159 // Checking current behavior for ":focus + div", but this is a BUG or at best |
156 // sub-optimal. The focused element will also in this case get childrenOrSibling
sAffectedByFocus | 160 // sub-optimal. The focused element will also in this case get |
157 // even if it's really a sibling. Effectively, the whole sub-tree of the focused | 161 // childrenOrSiblingsAffectedByFocus even if it's really a sibling. Effectively, |
158 // element will have styles recalculated even though none of the children are | 162 // the whole sub-tree of the focused element will have styles recalculated even |
159 // affected. There are other mechanisms that makes sure the sibling also gets it
s | 163 // though none of the children are affected. There are other mechanisms that |
160 // styles recalculated. | 164 // makes sure the sibling also gets its styles recalculated. |
161 TEST_F(AffectedByFocusTest, FocusedSibling) { | 165 TEST_F(AffectedByFocusTest, FocusedSibling) { |
162 ElementResult expected[] = {{bodyTag, true, false}, | 166 ElementResult expected[] = {{bodyTag, true, false}, |
163 {divTag, true, true}, | 167 {divTag, true, true}, |
164 {spanTag, true, false}, | 168 {spanTag, true, false}, |
165 {divTag, true, false}}; | 169 {divTag, true, false}}; |
166 | 170 |
167 setHtmlInnerHTML( | 171 setHtmlInnerHTML( |
168 "<head>" | 172 "<head>" |
169 "<style>:focus + div { background-color: pink }</style>" | 173 "<style>:focus + div { background-color: pink }</style>" |
170 "</head>" | 174 "</head>" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 274 |
271 unsigned elementCount = | 275 unsigned elementCount = |
272 document().styleEngine().styleForElementCount() - startCount; | 276 document().styleEngine().styleForElementCount() - startCount; |
273 | 277 |
274 ASSERT_EQ(2U, elementCount); | 278 ASSERT_EQ(2U, elementCount); |
275 } | 279 } |
276 | 280 |
277 TEST_F(AffectedByFocusTest, NoInvalidationSetFocusUpdate) { | 281 TEST_F(AffectedByFocusTest, NoInvalidationSetFocusUpdate) { |
278 // Check that when focussing the outer div in the document below, you get a | 282 // Check that when focussing the outer div in the document below, you get a |
279 // style recalc for the outer div only. The invalidation set for :focus will | 283 // style recalc for the outer div only. The invalidation set for :focus will |
280 // include 'a', but the id=d div should be affectedByFocus, not childrenOrSibl
ingsAffectedByFocus. | 284 // include 'a', but the id=d div should be affectedByFocus, not |
| 285 // childrenOrSiblingsAffectedByFocus. |
281 | 286 |
282 setHtmlInnerHTML( | 287 setHtmlInnerHTML( |
283 "<style>#nomatch:focus .a { border: 1px solid lime; }</style>" | 288 "<style>#nomatch:focus .a { border: 1px solid lime; }</style>" |
284 "<div id=d tabIndex=1>" | 289 "<div id=d tabIndex=1>" |
285 "<div></div>" | 290 "<div></div>" |
286 "<div></div>" | 291 "<div></div>" |
287 "<div></div>" | 292 "<div></div>" |
288 "<div></div>" | 293 "<div></div>" |
289 "<div></div>" | 294 "<div></div>" |
290 "<div></div>" | 295 "<div></div>" |
(...skipping 10 matching lines...) Expand all Loading... |
301 document().getElementById("d")->focus(); | 306 document().getElementById("d")->focus(); |
302 document().view()->updateAllLifecyclePhases(); | 307 document().view()->updateAllLifecyclePhases(); |
303 | 308 |
304 unsigned elementCount = | 309 unsigned elementCount = |
305 document().styleEngine().styleForElementCount() - startCount; | 310 document().styleEngine().styleForElementCount() - startCount; |
306 | 311 |
307 ASSERT_EQ(1U, elementCount); | 312 ASSERT_EQ(1U, elementCount); |
308 } | 313 } |
309 | 314 |
310 } // namespace blink | 315 } // namespace blink |
OLD | NEW |