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

Side by Side Diff: Source/core/dom/TreeScope.cpp

Issue 23890025: WIP (Introduce WTF::NonNullPtr<T>.) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/TreeScope.h ('k') | Source/core/dom/TreeScopeAdopter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All Rights Reserved. 2 * Copyright (C) 2011 Google Inc. All Rights Reserved.
3 * Copyright (C) 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2012 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 { 163 {
164 if (!m_elementsById) 164 if (!m_elementsById)
165 return; 165 return;
166 m_elementsById->remove(elementId.impl(), element); 166 m_elementsById->remove(elementId.impl(), element);
167 m_idTargetObserverRegistry->notifyObservers(elementId); 167 m_idTargetObserverRegistry->notifyObservers(elementId);
168 } 168 }
169 169
170 Node* TreeScope::ancestorInThisScope(Node* node) const 170 Node* TreeScope::ancestorInThisScope(Node* node) const
171 { 171 {
172 while (node) { 172 while (node) {
173 if (&node->treeScope() == this) 173 if (node->treeScope() == this)
174 return node; 174 return node;
175 if (!node->isInShadowTree()) 175 if (!node->isInShadowTree())
176 return 0; 176 return 0;
177 177
178 node = node->shadowHost(); 178 node = node->shadowHost();
179 } 179 }
180 180
181 return 0; 181 return 0;
182 } 182 }
183 183
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 return toElement(targetStack.last()); 372 return toElement(targetStack.last());
373 } 373 }
374 if (node->isShadowRoot()) { 374 if (node->isShadowRoot()) {
375 ASSERT(!targetStack.isEmpty()); 375 ASSERT(!targetStack.isEmpty());
376 targetStack.removeLast(); 376 targetStack.removeLast();
377 } 377 }
378 } 378 }
379 return 0; 379 return 0;
380 } 380 }
381 381
382 unsigned short TreeScope::comparePosition(const TreeScope& otherScope) const 382 unsigned short TreeScope::comparePosition(NonNullPtr<const TreeScope> otherScope ) const
383 { 383 {
384 if (&otherScope == this) 384 if (otherScope == this)
385 return Node::DOCUMENT_POSITION_EQUIVALENT; 385 return Node::DOCUMENT_POSITION_EQUIVALENT;
386 386
387 Vector<const TreeScope*, 16> chain1; 387 Vector<const TreeScope*, 16> chain1;
388 Vector<const TreeScope*, 16> chain2; 388 Vector<const TreeScope*, 16> chain2;
389 const TreeScope* current; 389 const TreeScope* current;
390 for (current = this; current; current = current->parentTreeScope()) 390 for (current = this; current; current = current->parentTreeScope())
391 chain1.append(current); 391 chain1.append(current);
392 for (current = &otherScope; current; current = current->parentTreeScope()) 392 for (current = otherScope.get(); current; current = current->parentTreeScope ())
393 chain2.append(current); 393 chain2.append(current);
394 394
395 unsigned index1 = chain1.size(); 395 unsigned index1 = chain1.size();
396 unsigned index2 = chain2.size(); 396 unsigned index2 = chain2.size();
397 if (chain1[index1 - 1] != chain2[index2 - 1]) 397 if (chain1[index1 - 1] != chain2[index2 - 1])
398 return Node::DOCUMENT_POSITION_DISCONNECTED | Node::DOCUMENT_POSITION_IM PLEMENTATION_SPECIFIC; 398 return Node::DOCUMENT_POSITION_DISCONNECTED | Node::DOCUMENT_POSITION_IM PLEMENTATION_SPECIFIC;
399 399
400 for (unsigned i = std::min(index1, index2); i; --i) { 400 for (unsigned i = std::min(index1, index2); i; --i) {
401 const TreeScope* child1 = chain1[--index1]; 401 const TreeScope* child1 = chain1[--index1];
402 const TreeScope* child2 = chain2[--index2]; 402 const TreeScope* child2 = chain2[--index2];
(...skipping 14 matching lines...) Expand all
417 // There was no difference between the two parent chains, i.e., one was a su bset of the other. The shorter 417 // There was no difference between the two parent chains, i.e., one was a su bset of the other. The shorter
418 // chain is the ancestor. 418 // chain is the ancestor.
419 return index1 < index2 ? 419 return index1 < index2 ?
420 Node::DOCUMENT_POSITION_FOLLOWING | Node::DOCUMENT_POSITION_CONTAINED_BY : 420 Node::DOCUMENT_POSITION_FOLLOWING | Node::DOCUMENT_POSITION_CONTAINED_BY :
421 Node::DOCUMENT_POSITION_PRECEDING | Node::DOCUMENT_POSITION_CONTAINS; 421 Node::DOCUMENT_POSITION_PRECEDING | Node::DOCUMENT_POSITION_CONTAINS;
422 } 422 }
423 423
424 static void listTreeScopes(Node* node, Vector<TreeScope*, 5>& treeScopes) 424 static void listTreeScopes(Node* node, Vector<TreeScope*, 5>& treeScopes)
425 { 425 {
426 while (true) { 426 while (true) {
427 treeScopes.append(&node->treeScope()); 427 treeScopes.append(node->treeScope().get());
428 Element* ancestor = node->shadowHost(); 428 Element* ancestor = node->shadowHost();
429 if (!ancestor) 429 if (!ancestor)
430 break; 430 break;
431 node = ancestor; 431 node = ancestor;
432 } 432 }
433 } 433 }
434 434
435 TreeScope* commonTreeScope(Node* nodeA, Node* nodeB) 435 TreeScope* commonTreeScope(Node* nodeA, Node* nodeB)
436 { 436 {
437 if (!nodeA || !nodeB) 437 if (!nodeA || !nodeB)
438 return 0; 438 return 0;
439 439
440 if (&nodeA->treeScope() == &nodeB->treeScope()) 440 if (nodeA->treeScope() == nodeB->treeScope())
441 return &nodeA->treeScope(); 441 return nodeA->treeScope().get();
442 442
443 Vector<TreeScope*, 5> treeScopesA; 443 Vector<TreeScope*, 5> treeScopesA;
444 listTreeScopes(nodeA, treeScopesA); 444 listTreeScopes(nodeA, treeScopesA);
445 445
446 Vector<TreeScope*, 5> treeScopesB; 446 Vector<TreeScope*, 5> treeScopesB;
447 listTreeScopes(nodeB, treeScopesB); 447 listTreeScopes(nodeB, treeScopesB);
448 448
449 size_t indexA = treeScopesA.size(); 449 size_t indexA = treeScopesA.size();
450 size_t indexB = treeScopesB.size(); 450 size_t indexB = treeScopesB.size();
451 451
(...skipping 15 matching lines...) Expand all
467 } 467 }
468 #endif 468 #endif
469 469
470 int TreeScope::refCount() const 470 int TreeScope::refCount() const
471 { 471 {
472 if (Node* root = rootNode()) 472 if (Node* root = rootNode())
473 return root->refCount(); 473 return root->refCount();
474 return 0; 474 return 0;
475 } 475 }
476 476
477 bool TreeScope::isInclusiveAncestorOf(const TreeScope& scope) const 477 bool TreeScope::isInclusiveAncestorOf(NonNullPtr<const TreeScope> scope) const
478 { 478 {
479 for (const TreeScope* current = &scope; current; current = current->parentTr eeScope()) { 479 for (const TreeScope* current = scope.get(); current; current = current->par entTreeScope()) {
480 if (current == this) 480 if (current == this)
481 return true; 481 return true;
482 } 482 }
483 return false; 483 return false;
484 } 484 }
485 485
486 Element* TreeScope::getElementByAccessKey(const String& key) const 486 Element* TreeScope::getElementByAccessKey(const String& key) const
487 { 487 {
488 if (key.isEmpty()) 488 if (key.isEmpty())
489 return 0; 489 return 0;
490 Element* result = 0; 490 Element* result = 0;
491 Node* root = rootNode(); 491 Node* root = rootNode();
492 for (Element* element = ElementTraversal::firstWithin(root); element; elemen t = ElementTraversal::next(element, root)) { 492 for (Element* element = ElementTraversal::firstWithin(root); element; elemen t = ElementTraversal::next(element, root)) {
493 if (element->fastGetAttribute(accesskeyAttr) == key) 493 if (element->fastGetAttribute(accesskeyAttr) == key)
494 result = element; 494 result = element;
495 for (ShadowRoot* shadowRoot = element->youngestShadowRoot(); shadowRoot; shadowRoot = shadowRoot->olderShadowRoot()) { 495 for (ShadowRoot* shadowRoot = element->youngestShadowRoot(); shadowRoot; shadowRoot = shadowRoot->olderShadowRoot()) {
496 if (Element* shadowResult = shadowRoot->getElementByAccessKey(key)) 496 if (Element* shadowResult = shadowRoot->getElementByAccessKey(key))
497 result = shadowResult; 497 result = shadowResult;
498 } 498 }
499 } 499 }
500 return result; 500 return result;
501 } 501 }
502 502
503 } // namespace WebCore 503 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/TreeScope.h ('k') | Source/core/dom/TreeScopeAdopter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698