| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/HTMLNames.h" | 6 #include "core/HTMLNames.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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 void AffectedByFocusTest::SetUp() | 46 void AffectedByFocusTest::SetUp() |
| 47 { | 47 { |
| 48 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); | 48 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); |
| 49 m_document = toHTMLDocument(&m_dummyPageHolder->document()); | 49 m_document = toHTMLDocument(&m_dummyPageHolder->document()); |
| 50 ASSERT(m_document); | 50 ASSERT(m_document); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void AffectedByFocusTest::setHtmlInnerHTML(const char* htmlContent) | 53 void AffectedByFocusTest::setHtmlInnerHTML(const char* htmlContent) |
| 54 { | 54 { |
| 55 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent), AS
SERT_NO_EXCEPTION); | 55 document().documentElement()->setInnerHTML(String::fromUTF8(htmlContent), AS
SERT_NO_EXCEPTION); |
| 56 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 56 document().view()->updateLayoutAndStyleForPainting(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void AffectedByFocusTest::checkElements(ElementResult expected[], unsigned expec
tedCount) const | 59 void AffectedByFocusTest::checkElements(ElementResult expected[], unsigned expec
tedCount) const |
| 60 { | 60 { |
| 61 unsigned i = 0; | 61 unsigned i = 0; |
| 62 HTMLElement* element = document().body(); | 62 HTMLElement* element = document().body(); |
| 63 | 63 |
| 64 for (; element && i < expectedCount; element = Traversal<HTMLElement>::next(
*element), ++i) { | 64 for (; element && i < expectedCount; element = Traversal<HTMLElement>::next(
*element), ++i) { |
| 65 ASSERT_TRUE(element->hasTagName(expected[i].tag)); | 65 ASSERT_TRUE(element->hasTagName(expected[i].tag)); |
| 66 ASSERT(element->computedStyle()); | 66 ASSERT(element->computedStyle()); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 "<div></div>" | 201 "<div></div>" |
| 202 "<div></div>" | 202 "<div></div>" |
| 203 "<div></div>" | 203 "<div></div>" |
| 204 "<div></div>" | 204 "<div></div>" |
| 205 "<div></div>" | 205 "<div></div>" |
| 206 "<div></div>" | 206 "<div></div>" |
| 207 "<div></div>" | 207 "<div></div>" |
| 208 "<div></div>" | 208 "<div></div>" |
| 209 "</div>"); | 209 "</div>"); |
| 210 | 210 |
| 211 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 211 document().view()->updateLayoutAndStyleForPainting(); |
| 212 | 212 |
| 213 unsigned startCount = document().styleEngine().resolverAccessCount(); | 213 unsigned startCount = document().styleEngine().resolverAccessCount(); |
| 214 | 214 |
| 215 document().getElementById("d")->focus(); | 215 document().getElementById("d")->focus(); |
| 216 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 216 document().view()->updateLayoutAndStyleForPainting(); |
| 217 | 217 |
| 218 unsigned accessCount = document().styleEngine().resolverAccessCount() - star
tCount; | 218 unsigned accessCount = document().styleEngine().resolverAccessCount() - star
tCount; |
| 219 | 219 |
| 220 ASSERT_EQ(1U, accessCount); | 220 ASSERT_EQ(1U, accessCount); |
| 221 } | 221 } |
| 222 | 222 |
| 223 TEST_F(AffectedByFocusTest, ChildrenOrSiblingsAffectedByFocusUpdate) | 223 TEST_F(AffectedByFocusTest, ChildrenOrSiblingsAffectedByFocusUpdate) |
| 224 { | 224 { |
| 225 // Check that when focussing the outer div in the document below, you get a | 225 // Check that when focussing the outer div in the document below, you get a |
| 226 // style recalc for the whole subtree. | 226 // style recalc for the whole subtree. |
| 227 | 227 |
| 228 setHtmlInnerHTML("<style>:focus div { border: 1px solid lime; }</style>" | 228 setHtmlInnerHTML("<style>:focus div { border: 1px solid lime; }</style>" |
| 229 "<div id=d tabIndex=1>" | 229 "<div id=d tabIndex=1>" |
| 230 "<div></div>" | 230 "<div></div>" |
| 231 "<div></div>" | 231 "<div></div>" |
| 232 "<div></div>" | 232 "<div></div>" |
| 233 "<div></div>" | 233 "<div></div>" |
| 234 "<div></div>" | 234 "<div></div>" |
| 235 "<div></div>" | 235 "<div></div>" |
| 236 "<div></div>" | 236 "<div></div>" |
| 237 "<div></div>" | 237 "<div></div>" |
| 238 "<div></div>" | 238 "<div></div>" |
| 239 "<div></div>" | 239 "<div></div>" |
| 240 "</div>"); | 240 "</div>"); |
| 241 | 241 |
| 242 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 242 document().view()->updateLayoutAndStyleForPainting(); |
| 243 | 243 |
| 244 unsigned startCount = document().styleEngine().resolverAccessCount(); | 244 unsigned startCount = document().styleEngine().resolverAccessCount(); |
| 245 | 245 |
| 246 document().getElementById("d")->focus(); | 246 document().getElementById("d")->focus(); |
| 247 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 247 document().view()->updateLayoutAndStyleForPainting(); |
| 248 | 248 |
| 249 unsigned accessCount = document().styleEngine().resolverAccessCount() - star
tCount; | 249 unsigned accessCount = document().styleEngine().resolverAccessCount() - star
tCount; |
| 250 | 250 |
| 251 ASSERT_EQ(11U, accessCount); | 251 ASSERT_EQ(11U, accessCount); |
| 252 } | 252 } |
| 253 | 253 |
| 254 TEST_F(AffectedByFocusTest, InvalidationSetFocusUpdate) | 254 TEST_F(AffectedByFocusTest, InvalidationSetFocusUpdate) |
| 255 { | 255 { |
| 256 // Check that when focussing the outer div in the document below, you get a | 256 // Check that when focussing the outer div in the document below, you get a |
| 257 // style recalc for the outer div and the class=a div only. | 257 // style recalc for the outer div and the class=a div only. |
| 258 | 258 |
| 259 setHtmlInnerHTML("<style>:focus .a { border: 1px solid lime; }</style>" | 259 setHtmlInnerHTML("<style>:focus .a { border: 1px solid lime; }</style>" |
| 260 "<div id=d tabIndex=1>" | 260 "<div id=d tabIndex=1>" |
| 261 "<div></div>" | 261 "<div></div>" |
| 262 "<div></div>" | 262 "<div></div>" |
| 263 "<div></div>" | 263 "<div></div>" |
| 264 "<div></div>" | 264 "<div></div>" |
| 265 "<div></div>" | 265 "<div></div>" |
| 266 "<div></div>" | 266 "<div></div>" |
| 267 "<div></div>" | 267 "<div></div>" |
| 268 "<div></div>" | 268 "<div></div>" |
| 269 "<div></div>" | 269 "<div></div>" |
| 270 "<div class='a'></div>" | 270 "<div class='a'></div>" |
| 271 "</div>"); | 271 "</div>"); |
| 272 | 272 |
| 273 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 273 document().view()->updateLayoutAndStyleForPainting(); |
| 274 | 274 |
| 275 unsigned startCount = document().styleEngine().resolverAccessCount(); | 275 unsigned startCount = document().styleEngine().resolverAccessCount(); |
| 276 | 276 |
| 277 document().getElementById("d")->focus(); | 277 document().getElementById("d")->focus(); |
| 278 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 278 document().view()->updateLayoutAndStyleForPainting(); |
| 279 | 279 |
| 280 unsigned accessCount = document().styleEngine().resolverAccessCount() - star
tCount; | 280 unsigned accessCount = document().styleEngine().resolverAccessCount() - star
tCount; |
| 281 | 281 |
| 282 ASSERT_EQ(2U, accessCount); | 282 ASSERT_EQ(2U, accessCount); |
| 283 } | 283 } |
| 284 | 284 |
| 285 TEST_F(AffectedByFocusTest, NoInvalidationSetFocusUpdate) | 285 TEST_F(AffectedByFocusTest, NoInvalidationSetFocusUpdate) |
| 286 { | 286 { |
| 287 // Check that when focussing the outer div in the document below, you get a | 287 // Check that when focussing the outer div in the document below, you get a |
| 288 // style recalc for the outer div only. The invalidation set for :focus will | 288 // style recalc for the outer div only. The invalidation set for :focus will |
| 289 // include 'a', but the id=d div should be affectedByFocus, not childrenOrSi
blingsAffectedByFocus. | 289 // include 'a', but the id=d div should be affectedByFocus, not childrenOrSi
blingsAffectedByFocus. |
| 290 | 290 |
| 291 setHtmlInnerHTML("<style>#nomatch:focus .a { border: 1px solid lime; }</styl
e>" | 291 setHtmlInnerHTML("<style>#nomatch:focus .a { border: 1px solid lime; }</styl
e>" |
| 292 "<div id=d tabIndex=1>" | 292 "<div id=d tabIndex=1>" |
| 293 "<div></div>" | 293 "<div></div>" |
| 294 "<div></div>" | 294 "<div></div>" |
| 295 "<div></div>" | 295 "<div></div>" |
| 296 "<div></div>" | 296 "<div></div>" |
| 297 "<div></div>" | 297 "<div></div>" |
| 298 "<div></div>" | 298 "<div></div>" |
| 299 "<div></div>" | 299 "<div></div>" |
| 300 "<div></div>" | 300 "<div></div>" |
| 301 "<div></div>" | 301 "<div></div>" |
| 302 "<div class='a'></div>" | 302 "<div class='a'></div>" |
| 303 "</div>"); | 303 "</div>"); |
| 304 | 304 |
| 305 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 305 document().view()->updateLayoutAndStyleForPainting(); |
| 306 | 306 |
| 307 unsigned startCount = document().styleEngine().resolverAccessCount(); | 307 unsigned startCount = document().styleEngine().resolverAccessCount(); |
| 308 | 308 |
| 309 document().getElementById("d")->focus(); | 309 document().getElementById("d")->focus(); |
| 310 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 310 document().view()->updateLayoutAndStyleForPainting(); |
| 311 | 311 |
| 312 unsigned accessCount = document().styleEngine().resolverAccessCount() - star
tCount; | 312 unsigned accessCount = document().styleEngine().resolverAccessCount() - star
tCount; |
| 313 | 313 |
| 314 ASSERT_EQ(1U, accessCount); | 314 ASSERT_EQ(1U, accessCount); |
| 315 } | 315 } |
| 316 | 316 |
| 317 } // namespace | 317 } // namespace |
| OLD | NEW |