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

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/ApplyStyleCommand.cpp

Issue 1932523003: Introduce NodeTraversal::ancestorsOf() and inclusiveAncestors() for range-based for loop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-04-28T18:38:12 Created 4 years, 7 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) 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2008, 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 { 474 {
475 // We are allowed to leave the highest ancestor with unicode-bidi unsplit if it is unicode-bidi: embed and direction: allowedDirection. 475 // We are allowed to leave the highest ancestor with unicode-bidi unsplit if it is unicode-bidi: embed and direction: allowedDirection.
476 // In that case, we return the unsplit ancestor. Otherwise, we return 0. 476 // In that case, we return the unsplit ancestor. Otherwise, we return 0.
477 Element* block = enclosingBlock(node); 477 Element* block = enclosingBlock(node);
478 if (!block) 478 if (!block)
479 return 0; 479 return 0;
480 480
481 ContainerNode* highestAncestorWithUnicodeBidi = nullptr; 481 ContainerNode* highestAncestorWithUnicodeBidi = nullptr;
482 ContainerNode* nextHighestAncestorWithUnicodeBidi = nullptr; 482 ContainerNode* nextHighestAncestorWithUnicodeBidi = nullptr;
483 int highestAncestorUnicodeBidi = 0; 483 int highestAncestorUnicodeBidi = 0;
484 for (ContainerNode* n = node->parentNode(); n != block; n = n->parentNode()) { 484 for (Node& runner : NodeTraversal::ancestorsOf(*node)) {
485 int unicodeBidi = getIdentifierValue(CSSComputedStyleDeclaration::create (n), CSSPropertyUnicodeBidi); 485 if (runner == block)
486 break;
487 int unicodeBidi = getIdentifierValue(CSSComputedStyleDeclaration::create (&runner), CSSPropertyUnicodeBidi);
486 if (unicodeBidi && unicodeBidi != CSSValueNormal) { 488 if (unicodeBidi && unicodeBidi != CSSValueNormal) {
487 highestAncestorUnicodeBidi = unicodeBidi; 489 highestAncestorUnicodeBidi = unicodeBidi;
488 nextHighestAncestorWithUnicodeBidi = highestAncestorWithUnicodeBidi; 490 nextHighestAncestorWithUnicodeBidi = highestAncestorWithUnicodeBidi;
489 highestAncestorWithUnicodeBidi = n; 491 highestAncestorWithUnicodeBidi = static_cast<ContainerNode*>(&runner );
490 } 492 }
491 } 493 }
492 494
493 if (!highestAncestorWithUnicodeBidi) 495 if (!highestAncestorWithUnicodeBidi)
494 return 0; 496 return 0;
495 497
496 HTMLElement* unsplitAncestor = 0; 498 HTMLElement* unsplitAncestor = 0;
497 499
498 WritingDirection highestAncestorDirection; 500 WritingDirection highestAncestorDirection;
499 if (allowedDirection != NaturalWritingDirection 501 if (allowedDirection != NaturalWritingDirection
(...skipping 20 matching lines...) Expand all
520 } 522 }
521 return unsplitAncestor; 523 return unsplitAncestor;
522 } 524 }
523 525
524 void ApplyStyleCommand::removeEmbeddingUpToEnclosingBlock(Node* node, HTMLElemen t* unsplitAncestor, EditingState* editingState) 526 void ApplyStyleCommand::removeEmbeddingUpToEnclosingBlock(Node* node, HTMLElemen t* unsplitAncestor, EditingState* editingState)
525 { 527 {
526 Element* block = enclosingBlock(node); 528 Element* block = enclosingBlock(node);
527 if (!block) 529 if (!block)
528 return; 530 return;
529 531
530 for (ContainerNode* n = node->parentNode(); n != block && n != unsplitAncest or; n = n->parentNode()) { 532 for (Node& runner : NodeTraversal::ancestorsOf(*node)) {
531 if (!n->isStyledElement()) 533 if (runner == block || runner == unsplitAncestor)
534 break;
535 if (!runner.isStyledElement())
532 continue; 536 continue;
533 537
534 Element* element = toElement(n); 538 Element* element = toElement(&runner);
535 int unicodeBidi = getIdentifierValue(CSSComputedStyleDeclaration::create (element), CSSPropertyUnicodeBidi); 539 int unicodeBidi = getIdentifierValue(CSSComputedStyleDeclaration::create (element), CSSPropertyUnicodeBidi);
536 if (!unicodeBidi || unicodeBidi == CSSValueNormal) 540 if (!unicodeBidi || unicodeBidi == CSSValueNormal)
537 continue; 541 continue;
538 542
539 // FIXME: This code should really consider the mapped attribute 'dir', t he inline style declaration, 543 // FIXME: This code should really consider the mapped attribute 'dir', t he inline style declaration,
540 // and all matching style rules in order to determine how to best set th e unicode-bidi property to 'normal'. 544 // and all matching style rules in order to determine how to best set th e unicode-bidi property to 'normal'.
541 // For now, it assumes that if the 'dir' attribute is present, then remo ving it will suffice, and 545 // For now, it assumes that if the 'dir' attribute is present, then remo ving it will suffice, and
542 // otherwise it sets the property in the inline style declaration. 546 // otherwise it sets the property in the inline style declaration.
543 if (element->hasAttribute(dirAttr)) { 547 if (element->hasAttribute(dirAttr)) {
544 // FIXME: If this is a BDO element, we should probably just remove i t if it has no 548 // FIXME: If this is a BDO element, we should probably just remove i t if it has no
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 DEFINE_TRACE(ApplyStyleCommand) 1721 DEFINE_TRACE(ApplyStyleCommand)
1718 { 1722 {
1719 visitor->trace(m_style); 1723 visitor->trace(m_style);
1720 visitor->trace(m_start); 1724 visitor->trace(m_start);
1721 visitor->trace(m_end); 1725 visitor->trace(m_end);
1722 visitor->trace(m_styledInlineElement); 1726 visitor->trace(m_styledInlineElement);
1723 CompositeEditCommand::trace(visitor); 1727 CompositeEditCommand::trace(visitor);
1724 } 1728 }
1725 1729
1726 } // namespace blink 1730 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698