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

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

Issue 2390543002: Reflow comments in core/dom/. (Closed)
Patch Set: Reformat comments in core/dom/. Created 4 years, 2 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
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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 return elementsFromHitTestResult(result); 317 return elementsFromHitTestResult(result);
318 } 318 }
319 319
320 DOMSelection* TreeScope::getSelection() const { 320 DOMSelection* TreeScope::getSelection() const {
321 if (!rootNode().document().frame()) 321 if (!rootNode().document().frame())
322 return nullptr; 322 return nullptr;
323 323
324 if (m_selection) 324 if (m_selection)
325 return m_selection.get(); 325 return m_selection.get();
326 326
327 // FIXME: The correct selection in Shadow DOM requires that Position can have a ShadowRoot 327 // FIXME: The correct selection in Shadow DOM requires that Position can have
328 // as a container. 328 // a ShadowRoot as a container. See
329 // See https://bugs.webkit.org/show_bug.cgi?id=82697 329 // https://bugs.webkit.org/show_bug.cgi?id=82697
330 m_selection = DOMSelection::create(this); 330 m_selection = DOMSelection::create(this);
331 return m_selection.get(); 331 return m_selection.get();
332 } 332 }
333 333
334 Element* TreeScope::findAnchor(const String& name) { 334 Element* TreeScope::findAnchor(const String& name) {
335 if (name.isEmpty()) 335 if (name.isEmpty())
336 return nullptr; 336 return nullptr;
337 if (Element* element = getElementById(AtomicString(name))) 337 if (Element* element = getElementById(AtomicString(name)))
338 return element; 338 return element;
339 for (HTMLAnchorElement& anchor : 339 for (HTMLAnchorElement& anchor :
340 Traversal<HTMLAnchorElement>::startsAfter(rootNode())) { 340 Traversal<HTMLAnchorElement>::startsAfter(rootNode())) {
341 if (rootNode().document().inQuirksMode()) { 341 if (rootNode().document().inQuirksMode()) {
342 // Quirks mode, case insensitive comparison of names. 342 // Quirks mode, case insensitive comparison of names.
343 if (equalIgnoringCase(anchor.name(), name)) 343 if (equalIgnoringCase(anchor.name(), name))
344 return &anchor; 344 return &anchor;
345 } else { 345 } else {
346 // Strict mode, names need to match exactly. 346 // Strict mode, names need to match exactly.
347 if (anchor.name() == name) 347 if (anchor.name() == name)
348 return &anchor; 348 return &anchor;
349 } 349 }
350 } 350 }
351 return nullptr; 351 return nullptr;
352 } 352 }
353 353
354 void TreeScope::adoptIfNeeded(Node& node) { 354 void TreeScope::adoptIfNeeded(Node& node) {
355 // Script is forbidden to protect against event handlers firing in the middle of rescoping 355 // Script is forbidden to protect against event handlers firing in the middle
356 // in |didMoveToNewDocument| callbacks. See https://crbug.com/605766 and https ://crbug.com/606651. 356 // of rescoping in |didMoveToNewDocument| callbacks. See
357 // https://crbug.com/605766 and https://crbug.com/606651.
357 ScriptForbiddenScope forbidScript; 358 ScriptForbiddenScope forbidScript;
358 DCHECK(this); 359 DCHECK(this);
359 DCHECK(!node.isDocumentNode()); 360 DCHECK(!node.isDocumentNode());
360 TreeScopeAdopter adopter(node, *this); 361 TreeScopeAdopter adopter(node, *this);
361 if (adopter.needsScopeChange()) 362 if (adopter.needsScopeChange())
362 adopter.execute(); 363 adopter.execute();
363 } 364 }
364 365
365 Element* TreeScope::retarget(const Element& target) const { 366 Element* TreeScope::retarget(const Element& target) const {
366 for (const Element* ancestor = &target; ancestor; 367 for (const Element* ancestor = &target; ancestor;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 return toElement(eventPath->at(i).target()->toNode()); 399 return toElement(eventPath->at(i).target()->toNode());
399 } 400 }
400 } 401 }
401 return nullptr; 402 return nullptr;
402 } 403 }
403 404
404 Element* TreeScope::adjustedElement(const Element& target) const { 405 Element* TreeScope::adjustedElement(const Element& target) const {
405 const Element* adjustedTarget = &target; 406 const Element* adjustedTarget = &target;
406 for (const Element* ancestor = &target; ancestor; 407 for (const Element* ancestor = &target; ancestor;
407 ancestor = ancestor->ownerShadowHost()) { 408 ancestor = ancestor->ownerShadowHost()) {
408 // This adjustment is done only for V1 shadows, and is skipped for V0 or UA shadows, 409 // This adjustment is done only for V1 shadows, and is skipped for V0 or UA
409 // because .pointerLockElement and .(webkit)fullscreenElement is not availab le for 410 // shadows, because .pointerLockElement and .(webkit)fullscreenElement is
410 // non-V1 shadow roots. 411 // not available for non-V1 shadow roots.
411 // TODO(kochi): Once V0 code is removed, use the same logic as .activeElemen t for V1. 412 // TODO(kochi): Once V0 code is removed, use the same logic as
413 // .activeElement for V1.
412 if (ancestor->shadowRootIfV1()) 414 if (ancestor->shadowRootIfV1())
413 adjustedTarget = ancestor; 415 adjustedTarget = ancestor;
414 if (this == ancestor->treeScope()) 416 if (this == ancestor->treeScope())
415 return const_cast<Element*>(adjustedTarget); 417 return const_cast<Element*>(adjustedTarget);
416 } 418 }
417 return nullptr; 419 return nullptr;
418 } 420 }
419 421
420 unsigned short TreeScope::comparePosition(const TreeScope& otherScope) const { 422 unsigned short TreeScope::comparePosition(const TreeScope& otherScope) const {
421 if (otherScope == this) 423 if (otherScope == this)
(...skipping 27 matching lines...) Expand all
449 toShadowRoot(child2->rootNode()).olderShadowRoot(); 451 toShadowRoot(child2->rootNode()).olderShadowRoot();
450 child; child = child->olderShadowRoot()) { 452 child; child = child->olderShadowRoot()) {
451 if (child == child1) 453 if (child == child1)
452 return Node::kDocumentPositionFollowing; 454 return Node::kDocumentPositionFollowing;
453 } 455 }
454 456
455 return Node::kDocumentPositionPreceding; 457 return Node::kDocumentPositionPreceding;
456 } 458 }
457 } 459 }
458 460
459 // There was no difference between the two parent chains, i.e., one was a subs et of the other. The shorter 461 // There was no difference between the two parent chains, i.e., one was a
460 // chain is the ancestor. 462 // subset of the other. The shorter chain is the ancestor.
461 return index1 < index2 463 return index1 < index2
462 ? Node::kDocumentPositionFollowing | 464 ? Node::kDocumentPositionFollowing |
463 Node::kDocumentPositionContainedBy 465 Node::kDocumentPositionContainedBy
464 : Node::kDocumentPositionPreceding | 466 : Node::kDocumentPositionPreceding |
465 Node::kDocumentPositionContains; 467 Node::kDocumentPositionContains;
466 } 468 }
467 469
468 const TreeScope* TreeScope::commonAncestorTreeScope( 470 const TreeScope* TreeScope::commonAncestorTreeScope(
469 const TreeScope& other) const { 471 const TreeScope& other) const {
470 HeapVector<Member<const TreeScope>, 16> thisChain; 472 HeapVector<Member<const TreeScope>, 16> thisChain;
471 for (const TreeScope* tree = this; tree; tree = tree->parentTreeScope()) 473 for (const TreeScope* tree = this; tree; tree = tree->parentTreeScope())
472 thisChain.append(tree); 474 thisChain.append(tree);
473 475
474 HeapVector<Member<const TreeScope>, 16> otherChain; 476 HeapVector<Member<const TreeScope>, 16> otherChain;
475 for (const TreeScope* tree = &other; tree; tree = tree->parentTreeScope()) 477 for (const TreeScope* tree = &other; tree; tree = tree->parentTreeScope())
476 otherChain.append(tree); 478 otherChain.append(tree);
477 479
478 // Keep popping out the last elements of these chains until a mismatched pair is found. If |this| and |other| 480 // Keep popping out the last elements of these chains until a mismatched pair
479 // belong to different documents, null will be returned. 481 // is found. If |this| and |other| belong to different documents, null will be
482 // returned.
480 const TreeScope* lastAncestor = nullptr; 483 const TreeScope* lastAncestor = nullptr;
481 while (!thisChain.isEmpty() && !otherChain.isEmpty() && 484 while (!thisChain.isEmpty() && !otherChain.isEmpty() &&
482 thisChain.last() == otherChain.last()) { 485 thisChain.last() == otherChain.last()) {
483 lastAncestor = thisChain.last(); 486 lastAncestor = thisChain.last();
484 thisChain.removeLast(); 487 thisChain.removeLast();
485 otherChain.removeLast(); 488 otherChain.removeLast();
486 } 489 }
487 return lastAncestor; 490 return lastAncestor;
488 } 491 }
489 492
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 visitor->trace(m_parentTreeScope); 541 visitor->trace(m_parentTreeScope);
539 visitor->trace(m_idTargetObserverRegistry); 542 visitor->trace(m_idTargetObserverRegistry);
540 visitor->trace(m_selection); 543 visitor->trace(m_selection);
541 visitor->trace(m_elementsById); 544 visitor->trace(m_elementsById);
542 visitor->trace(m_imageMapsByName); 545 visitor->trace(m_imageMapsByName);
543 visitor->trace(m_scopedStyleResolver); 546 visitor->trace(m_scopedStyleResolver);
544 visitor->trace(m_radioButtonGroupScope); 547 visitor->trace(m_radioButtonGroupScope);
545 } 548 }
546 549
547 } // namespace blink 550 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/TreeScope.h ('k') | third_party/WebKit/Source/core/dom/TreeScopeAdopter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698