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

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

Issue 1847483002: Cleanup leadingWhitespacePosition() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-03-31T14:52:38 Created 4 years, 8 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 | « third_party/WebKit/Source/core/editing/EditingUtilities.h ('k') | no next file » | 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) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007 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 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 if (isBlockFlowElement(node)) 723 if (isBlockFlowElement(node))
724 return const_cast<Element*>(&toElement(node)); 724 return const_cast<Element*>(&toElement(node));
725 725
726 for (Node* n = node.parentNode(); n; n = n->parentNode()) { 726 for (Node* n = node.parentNode(); n; n = n->parentNode()) {
727 if (isBlockFlowElement(*n) || isHTMLBodyElement(*n)) 727 if (isBlockFlowElement(*n) || isHTMLBodyElement(*n))
728 return toElement(n); 728 return toElement(n);
729 } 729 }
730 return nullptr; 730 return nullptr;
731 } 731 }
732 732
733 bool inSameContainingBlockFlowElement(Node* a, Node* b)
734 {
735 return a && b && enclosingBlockFlowElement(*a) == enclosingBlockFlowElement( *b);
736 }
737
738 bool nodeIsUserSelectAll(const Node* node) 733 bool nodeIsUserSelectAll(const Node* node)
739 { 734 {
740 return RuntimeEnabledFeatures::userSelectAllEnabled() && node && node->layou tObject() && node->layoutObject()->style()->userSelect() == SELECT_ALL; 735 return RuntimeEnabledFeatures::userSelectAllEnabled() && node && node->layou tObject() && node->layoutObject()->style()->userSelect() == SELECT_ALL;
741 736
742 } 737 }
743 738
744 template <typename Strategy> 739 template <typename Strategy>
745 TextDirection directionOfEnclosingBlockAlgorithm(const PositionTemplate<Strategy >& position) 740 TextDirection directionOfEnclosingBlockAlgorithm(const PositionTemplate<Strategy >& position)
746 { 741 {
747 Element* enclosingBlockElement = enclosingBlock(PositionTemplate<Strategy>:: firstPositionInOrBeforeNode(position.computeContainerNode()), CannotCrossEditing Boundary); 742 Element* enclosingBlockElement = enclosingBlock(PositionTemplate<Strategy>:: firstPositionInOrBeforeNode(position.computeContainerNode()), CannotCrossEditing Boundary);
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 // This assumes that it starts in editable content. 1365 // This assumes that it starts in editable content.
1371 Position leadingWhitespacePosition(const Position& position, TextAffinity affini ty, WhitespacePositionOption option) 1366 Position leadingWhitespacePosition(const Position& position, TextAffinity affini ty, WhitespacePositionOption option)
1372 { 1367 {
1373 ASSERT(isEditablePosition(position, ContentIsEditable, DoNotUpdateStyle)); 1368 ASSERT(isEditablePosition(position, ContentIsEditable, DoNotUpdateStyle));
1374 if (position.isNull()) 1369 if (position.isNull())
1375 return Position(); 1370 return Position();
1376 1371
1377 if (isHTMLBRElement(*mostBackwardCaretPosition(position).anchorNode())) 1372 if (isHTMLBRElement(*mostBackwardCaretPosition(position).anchorNode()))
1378 return Position(); 1373 return Position();
1379 1374
1380 Position prev = previousCharacterPosition(position, affinity); 1375 const Position& prev = previousCharacterPosition(position, affinity);
1381 if (prev != position && inSameContainingBlockFlowElement(prev.anchorNode(), position.anchorNode()) && prev.anchorNode()->isTextNode()) { 1376 if (prev == position)
1382 String string = toText(prev.anchorNode())->data(); 1377 return Position();
1383 UChar previousCharacter = string[prev.computeOffsetInContainerNode()]; 1378 const Node* const anchorNode = prev.anchorNode();
1384 bool isSpace = option == ConsiderNonCollapsibleWhitespace ? (isSpaceOrNe wline(previousCharacter) || previousCharacter == noBreakSpaceCharacter) : isColl apsibleWhitespace(previousCharacter); 1379 if (!anchorNode || !anchorNode->isTextNode())
1385 if (isSpace && isEditablePosition(prev)) 1380 return Position();
1386 return prev; 1381 if (enclosingBlockFlowElement(*anchorNode) != enclosingBlockFlowElement(*pos ition.anchorNode()))
1387 } 1382 return Position();
1388 1383 if (!anchorNode->isTextNode())
1389 return Position(); 1384 return Position();
1385 const String& string = toText(anchorNode)->data();
1386 const UChar previousCharacter = string[prev.computeOffsetInContainerNode()];
1387 const bool isSpace = option == ConsiderNonCollapsibleWhitespace ? (isSpaceOr Newline(previousCharacter) || previousCharacter == noBreakSpaceCharacter) : isCo llapsibleWhitespace(previousCharacter);
1388 if (!isSpace || !isEditablePosition(prev))
1389 return Position();
1390 return prev;
1390 } 1391 }
1391 1392
1392 // This assumes that it starts in editable content. 1393 // This assumes that it starts in editable content.
1393 Position trailingWhitespacePosition(const Position& position, TextAffinity, Whit espacePositionOption option) 1394 Position trailingWhitespacePosition(const Position& position, TextAffinity, Whit espacePositionOption option)
1394 { 1395 {
1395 ASSERT(isEditablePosition(position, ContentIsEditable, DoNotUpdateStyle)); 1396 ASSERT(isEditablePosition(position, ContentIsEditable, DoNotUpdateStyle));
1396 if (position.isNull()) 1397 if (position.isNull())
1397 return Position(); 1398 return Position();
1398 1399
1399 VisiblePosition visiblePosition = createVisiblePosition(position); 1400 VisiblePosition visiblePosition = createVisiblePosition(position);
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 // instead of possibly at the end of the last node before the selection 1678 // instead of possibly at the end of the last node before the selection
1678 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); 1679 return mostForwardCaretPosition(visiblePosition.deepEquivalent());
1679 } 1680 }
1680 1681
1681 bool isTextSecurityNode(const Node* node) 1682 bool isTextSecurityNode(const Node* node)
1682 { 1683 {
1683 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE; 1684 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE;
1684 } 1685 }
1685 1686
1686 } // namespace blink 1687 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/EditingUtilities.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698