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

Side by Side Diff: Source/core/editing/EditingStyle.cpp

Issue 1245843003: [CodeHealth] Use Position::anchorNode instead of deprecatedNode. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « Source/core/editing/DragCaretController.cpp ('k') | Source/core/editing/Editor.cpp » ('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) 2007, 2008, 2009 Apple Computer, Inc. 2 * Copyright (C) 2007, 2008, 2009 Apple Computer, Inc.
3 * Copyright (C) 2010, 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2010, 2011 Google 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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 : m_isMonospaceFont(false) 356 : m_isMonospaceFont(false)
357 , m_fontSizeDelta(NoFontDelta) 357 , m_fontSizeDelta(NoFontDelta)
358 { 358 {
359 init(node, propertiesToInclude); 359 init(node, propertiesToInclude);
360 } 360 }
361 361
362 EditingStyle::EditingStyle(const Position& position, PropertiesToInclude propert iesToInclude) 362 EditingStyle::EditingStyle(const Position& position, PropertiesToInclude propert iesToInclude)
363 : m_isMonospaceFont(false) 363 : m_isMonospaceFont(false)
364 , m_fontSizeDelta(NoFontDelta) 364 , m_fontSizeDelta(NoFontDelta)
365 { 365 {
366 init(position.deprecatedNode(), propertiesToInclude); 366 init(position.anchorNode(), propertiesToInclude);
367 } 367 }
368 368
369 EditingStyle::EditingStyle(const StylePropertySet* style) 369 EditingStyle::EditingStyle(const StylePropertySet* style)
370 : m_mutableStyle(style ? style->mutableCopy() : nullptr) 370 : m_mutableStyle(style ? style->mutableCopy() : nullptr)
371 , m_isMonospaceFont(false) 371 , m_isMonospaceFont(false)
372 , m_fontSizeDelta(NoFontDelta) 372 , m_fontSizeDelta(NoFontDelta)
373 { 373 {
374 extractFontSizeDelta(); 374 extractFontSizeDelta();
375 } 375 }
376 376
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 TriState EditingStyle::triStateOfStyle(const VisibleSelection& selection) const 736 TriState EditingStyle::triStateOfStyle(const VisibleSelection& selection) const
737 { 737 {
738 if (!selection.isCaretOrRange()) 738 if (!selection.isCaretOrRange())
739 return FalseTriState; 739 return FalseTriState;
740 740
741 if (selection.isCaret()) 741 if (selection.isCaret())
742 return triStateOfStyle(EditingStyle::styleAtSelectionStart(selection).ge t()); 742 return triStateOfStyle(EditingStyle::styleAtSelectionStart(selection).ge t());
743 743
744 TriState state = FalseTriState; 744 TriState state = FalseTriState;
745 bool nodeIsStart = true; 745 bool nodeIsStart = true;
746 for (Node& node : NodeTraversal::startsAt(selection.start().deprecatedNode() )) { 746 for (Node& node : NodeTraversal::startsAt(selection.start().anchorNode())) {
747 if (node.layoutObject() && node.hasEditableStyle()) { 747 if (node.layoutObject() && node.hasEditableStyle()) {
748 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> nodeStyle = CSSCompu tedStyleDeclaration::create(&node); 748 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> nodeStyle = CSSCompu tedStyleDeclaration::create(&node);
749 if (nodeStyle) { 749 if (nodeStyle) {
750 TriState nodeState = triStateOfStyle(nodeStyle.get(), node.isTex tNode() ? EditingStyle::DoNotIgnoreTextOnlyProperties : EditingStyle::IgnoreText OnlyProperties); 750 TriState nodeState = triStateOfStyle(nodeStyle.get(), node.isTex tNode() ? EditingStyle::DoNotIgnoreTextOnlyProperties : EditingStyle::IgnoreText OnlyProperties);
751 if (nodeIsStart) { 751 if (nodeIsStart) {
752 state = nodeState; 752 state = nodeState;
753 nodeIsStart = false; 753 nodeIsStart = false;
754 } else if (state != nodeState && node.isTextNode()) { 754 } else if (state != nodeState && node.isTextNode()) {
755 state = MixedTriState; 755 state = MixedTriState;
756 break; 756 break;
757 } 757 }
758 } 758 }
759 } 759 }
760 if (&node == selection.end().deprecatedNode()) 760 if (&node == selection.end().anchorNode())
761 break; 761 break;
762 } 762 }
763 763
764 return state; 764 return state;
765 } 765 }
766 766
767 bool EditingStyle::conflictsWithInlineStyleOfElement(HTMLElement* element, Editi ngStyle* extractedStyle, Vector<CSSPropertyID>* conflictingProperties) const 767 bool EditingStyle::conflictsWithInlineStyleOfElement(HTMLElement* element, Editi ngStyle* extractedStyle, Vector<CSSPropertyID>* conflictingProperties) const
768 { 768 {
769 ASSERT(element); 769 ASSERT(element);
770 ASSERT(!conflictingProperties || conflictingProperties->isEmpty()); 770 ASSERT(!conflictingProperties || conflictingProperties->isEmpty());
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 1340
1341 WritingDirection EditingStyle::textDirectionForSelection(const VisibleSelection& selection, EditingStyle* typingStyle, bool& hasNestedOrMultipleEmbeddings) 1341 WritingDirection EditingStyle::textDirectionForSelection(const VisibleSelection& selection, EditingStyle* typingStyle, bool& hasNestedOrMultipleEmbeddings)
1342 { 1342 {
1343 hasNestedOrMultipleEmbeddings = true; 1343 hasNestedOrMultipleEmbeddings = true;
1344 1344
1345 if (selection.isNone()) 1345 if (selection.isNone())
1346 return NaturalWritingDirection; 1346 return NaturalWritingDirection;
1347 1347
1348 Position position = selection.start().downstream(); 1348 Position position = selection.start().downstream();
1349 1349
1350 Node* node = position.deprecatedNode(); 1350 Node* node = position.anchorNode();
1351 if (!node) 1351 if (!node)
1352 return NaturalWritingDirection; 1352 return NaturalWritingDirection;
1353 1353
1354 Position end; 1354 Position end;
1355 if (selection.isRange()) { 1355 if (selection.isRange()) {
1356 end = selection.end().upstream(); 1356 end = selection.end().upstream();
1357 1357
1358 ASSERT(end.document()); 1358 ASSERT(end.document());
1359 Node* pastLast = Range::create(*end.document(), position.parentAnchoredE quivalent(), end.parentAnchoredEquivalent())->pastLastNode(); 1359 Node* pastLast = Range::create(*end.document(), position.parentAnchoredE quivalent(), end.parentAnchoredEquivalent())->pastLastNode();
1360 for (Node* n = node; n && n != pastLast; n = NodeTraversal::next(*n)) { 1360 for (Node* n = node; n && n != pastLast; n = NodeTraversal::next(*n)) {
(...skipping 10 matching lines...) Expand all
1371 return NaturalWritingDirection; 1371 return NaturalWritingDirection;
1372 } 1372 }
1373 } 1373 }
1374 1374
1375 if (selection.isCaret()) { 1375 if (selection.isCaret()) {
1376 WritingDirection direction; 1376 WritingDirection direction;
1377 if (typingStyle && typingStyle->textDirection(direction)) { 1377 if (typingStyle && typingStyle->textDirection(direction)) {
1378 hasNestedOrMultipleEmbeddings = false; 1378 hasNestedOrMultipleEmbeddings = false;
1379 return direction; 1379 return direction;
1380 } 1380 }
1381 node = selection.visibleStart().deepEquivalent().deprecatedNode(); 1381 node = selection.visibleStart().deepEquivalent().anchorNode();
1382 } 1382 }
1383 1383
1384 // The selection is either a caret with no typing attributes or a range in w hich no embedding is added, so just use the start position 1384 // The selection is either a caret with no typing attributes or a range in w hich no embedding is added, so just use the start position
1385 // to decide. 1385 // to decide.
1386 Node* block = enclosingBlock(node); 1386 Node* block = enclosingBlock(node);
1387 WritingDirection foundDirection = NaturalWritingDirection; 1387 WritingDirection foundDirection = NaturalWritingDirection;
1388 1388
1389 for (; node != block; node = node->parentNode()) { 1389 for (; node != block; node = node->parentNode()) {
1390 if (!node->isStyledElement()) 1390 if (!node->isStyledElement())
1391 continue; 1391 continue;
(...skipping 17 matching lines...) Expand all
1409 continue; 1409 continue;
1410 1410
1411 int directionValue = toCSSPrimitiveValue(direction.get())->getValueID(); 1411 int directionValue = toCSSPrimitiveValue(direction.get())->getValueID();
1412 if (directionValue != CSSValueLtr && directionValue != CSSValueRtl) 1412 if (directionValue != CSSValueLtr && directionValue != CSSValueRtl)
1413 continue; 1413 continue;
1414 1414
1415 if (foundDirection != NaturalWritingDirection) 1415 if (foundDirection != NaturalWritingDirection)
1416 return NaturalWritingDirection; 1416 return NaturalWritingDirection;
1417 1417
1418 // In the range case, make sure that the embedding element persists unti l the end of the range. 1418 // In the range case, make sure that the embedding element persists unti l the end of the range.
1419 if (selection.isRange() && !end.deprecatedNode()->isDescendantOf(element )) 1419 if (selection.isRange() && !end.anchorNode()->isDescendantOf(element))
1420 return NaturalWritingDirection; 1420 return NaturalWritingDirection;
1421 1421
1422 foundDirection = directionValue == CSSValueLtr ? LeftToRightWritingDirec tion : RightToLeftWritingDirection; 1422 foundDirection = directionValue == CSSValueLtr ? LeftToRightWritingDirec tion : RightToLeftWritingDirection;
1423 } 1423 }
1424 hasNestedOrMultipleEmbeddings = false; 1424 hasNestedOrMultipleEmbeddings = false;
1425 return foundDirection; 1425 return foundDirection;
1426 } 1426 }
1427 1427
1428 DEFINE_TRACE(EditingStyle) 1428 DEFINE_TRACE(EditingStyle)
1429 { 1429 {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyle = position.ens ureComputedStyle(); 1462 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyle = position.ens ureComputedStyle();
1463 // FIXME: take care of background-color in effect 1463 // FIXME: take care of background-color in effect
1464 RefPtrWillBeRawPtr<MutableStylePropertySet> mutableStyle = getPropertiesNotI n(style->style(), computedStyle.get()); 1464 RefPtrWillBeRawPtr<MutableStylePropertySet> mutableStyle = getPropertiesNotI n(style->style(), computedStyle.get());
1465 ASSERT(mutableStyle); 1465 ASSERT(mutableStyle);
1466 1466
1467 reconcileTextDecorationProperties(mutableStyle.get()); 1467 reconcileTextDecorationProperties(mutableStyle.get());
1468 if (!document->frame()->editor().shouldStyleWithCSS()) 1468 if (!document->frame()->editor().shouldStyleWithCSS())
1469 extractTextStyles(document, mutableStyle.get(), computedStyle->isMonospa ceFont()); 1469 extractTextStyles(document, mutableStyle.get(), computedStyle->isMonospa ceFont());
1470 1470
1471 // Changing the whitespace style in a tab span would collapse the tab into a space. 1471 // Changing the whitespace style in a tab span would collapse the tab into a space.
1472 if (isTabHTMLSpanElementTextNode(position.deprecatedNode()) || isTabHTMLSpan Element((position.deprecatedNode()))) 1472 if (isTabHTMLSpanElementTextNode(position.anchorNode()) || isTabHTMLSpanElem ent((position.anchorNode())))
1473 mutableStyle->removeProperty(CSSPropertyWhiteSpace); 1473 mutableStyle->removeProperty(CSSPropertyWhiteSpace);
1474 1474
1475 // If unicode-bidi is present in mutableStyle and direction is not, then add direction to mutableStyle. 1475 // If unicode-bidi is present in mutableStyle and direction is not, then add direction to mutableStyle.
1476 // FIXME: Shouldn't this be done in getPropertiesNotIn? 1476 // FIXME: Shouldn't this be done in getPropertiesNotIn?
1477 if (mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi) && !style->sty le()->getPropertyCSSValue(CSSPropertyDirection)) 1477 if (mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi) && !style->sty le()->getPropertyCSSValue(CSSPropertyDirection))
1478 mutableStyle->setProperty(CSSPropertyDirection, style->style()->getPrope rtyValue(CSSPropertyDirection)); 1478 mutableStyle->setProperty(CSSPropertyDirection, style->style()->getPrope rtyValue(CSSPropertyDirection));
1479 1479
1480 // Save the result for later 1480 // Save the result for later
1481 m_cssStyle = mutableStyle->asText().stripWhiteSpace(); 1481 m_cssStyle = mutableStyle->asText().stripWhiteSpace();
1482 } 1482 }
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 { 1708 {
1709 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { 1709 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
1710 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSCompu tedStyleDeclaration::create(ancestor); 1710 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSCompu tedStyleDeclaration::create(ancestor);
1711 if (!hasTransparentBackgroundColor(ancestorStyle.get())) 1711 if (!hasTransparentBackgroundColor(ancestorStyle.get()))
1712 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor ); 1712 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor );
1713 } 1713 }
1714 return nullptr; 1714 return nullptr;
1715 } 1715 }
1716 1716
1717 } 1717 }
OLDNEW
« no previous file with comments | « Source/core/editing/DragCaretController.cpp ('k') | Source/core/editing/Editor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698