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

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

Issue 2406163004: Simplify the usage of PositionWithAffinity (Closed)
Patch Set: 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) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
3 * reserved. 3 * 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 static PositionWithAffinityTemplate<Strategy> honorEditingBoundaryAtOrBefore( 175 static PositionWithAffinityTemplate<Strategy> honorEditingBoundaryAtOrBefore(
176 const PositionWithAffinityTemplate<Strategy>& pos, 176 const PositionWithAffinityTemplate<Strategy>& pos,
177 const PositionTemplate<Strategy>& anchor) { 177 const PositionTemplate<Strategy>& anchor) {
178 if (pos.isNull()) 178 if (pos.isNull())
179 return pos; 179 return pos;
180 180
181 ContainerNode* highestRoot = highestEditableRoot(anchor); 181 ContainerNode* highestRoot = highestEditableRoot(anchor);
182 182
183 // Return empty position if |pos| is not somewhere inside the editable 183 // Return empty position if |pos| is not somewhere inside the editable
184 // region containing this position 184 // region containing this position
185 if (highestRoot && !pos.position().anchorNode()->isDescendantOf(highestRoot)) 185 if (highestRoot && !pos.anchorNode()->isDescendantOf(highestRoot))
186 return PositionWithAffinityTemplate<Strategy>(); 186 return PositionWithAffinityTemplate<Strategy>();
187 187
188 // Return |pos| itself if the two are from the very same editable region, or 188 // Return |pos| itself if the two are from the very same editable region, or
189 // both are non-editable 189 // both are non-editable
190 // TODO(yosin) In the non-editable case, just because the new position is 190 // TODO(yosin) In the non-editable case, just because the new position is
191 // non-editable doesn't mean movement to it is allowed. 191 // non-editable doesn't mean movement to it is allowed.
192 // |VisibleSelection::adjustForEditableContent()| has this problem too. 192 // |VisibleSelection::adjustForEditableContent()| has this problem too.
193 if (highestEditableRoot(pos.position()) == highestRoot) 193 if (highestEditableRoot(pos.position()) == highestRoot)
194 return pos; 194 return pos;
195 195
(...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 const VisiblePositionInFlatTree& currentPosition) { 1423 const VisiblePositionInFlatTree& currentPosition) {
1424 return logicalEndOfLineAlgorithm<EditingInFlatTreeStrategy>(currentPosition); 1424 return logicalEndOfLineAlgorithm<EditingInFlatTreeStrategy>(currentPosition);
1425 } 1425 }
1426 1426
1427 template <typename Strategy> 1427 template <typename Strategy>
1428 bool inSameLineAlgorithm( 1428 bool inSameLineAlgorithm(
1429 const PositionWithAffinityTemplate<Strategy>& position1, 1429 const PositionWithAffinityTemplate<Strategy>& position1,
1430 const PositionWithAffinityTemplate<Strategy>& position2) { 1430 const PositionWithAffinityTemplate<Strategy>& position2) {
1431 if (position1.isNull() || position2.isNull()) 1431 if (position1.isNull() || position2.isNull())
1432 return false; 1432 return false;
1433 DCHECK_EQ(position1.position().document(), position2.position().document()); 1433 DCHECK_EQ(position1.document(), position2.document());
1434 DCHECK(!position1.position().document()->needsLayoutTreeUpdate()); 1434 DCHECK(!position1.document()->needsLayoutTreeUpdate());
1435 1435
1436 PositionWithAffinityTemplate<Strategy> startOfLine1 = startOfLine(position1); 1436 PositionWithAffinityTemplate<Strategy> startOfLine1 = startOfLine(position1);
1437 PositionWithAffinityTemplate<Strategy> startOfLine2 = startOfLine(position2); 1437 PositionWithAffinityTemplate<Strategy> startOfLine2 = startOfLine(position2);
1438 if (startOfLine1 == startOfLine2) 1438 if (startOfLine1 == startOfLine2)
1439 return true; 1439 return true;
1440 PositionTemplate<Strategy> canonicalized1 = 1440 PositionTemplate<Strategy> canonicalized1 =
1441 canonicalPositionOf(startOfLine1.position()); 1441 canonicalPositionOf(startOfLine1.position());
1442 if (canonicalized1 == startOfLine2.position()) 1442 if (canonicalized1 == startOfLine2.position())
1443 return true; 1443 return true;
1444 return canonicalized1 == canonicalPositionOf(startOfLine2.position()); 1444 return canonicalized1 == canonicalPositionOf(startOfLine2.position());
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2637 TextAffinity affinity, 2637 TextAffinity affinity,
2638 TextDirection primaryDirection) { 2638 TextDirection primaryDirection) {
2639 return computeInlineBoxPositionTemplate<EditingInFlatTreeStrategy>( 2639 return computeInlineBoxPositionTemplate<EditingInFlatTreeStrategy>(
2640 position, affinity, primaryDirection); 2640 position, affinity, primaryDirection);
2641 } 2641 }
2642 2642
2643 template <typename Strategy> 2643 template <typename Strategy>
2644 LayoutRect localCaretRectOfPositionTemplate( 2644 LayoutRect localCaretRectOfPositionTemplate(
2645 const PositionWithAffinityTemplate<Strategy>& position, 2645 const PositionWithAffinityTemplate<Strategy>& position,
2646 LayoutObject*& layoutObject) { 2646 LayoutObject*& layoutObject) {
2647 if (position.position().isNull()) { 2647 if (position.isNull()) {
2648 layoutObject = nullptr; 2648 layoutObject = nullptr;
2649 return LayoutRect(); 2649 return LayoutRect();
2650 } 2650 }
2651 Node* node = position.position().anchorNode(); 2651 Node* node = position.anchorNode();
2652 2652
2653 layoutObject = node->layoutObject(); 2653 layoutObject = node->layoutObject();
2654 if (!layoutObject) 2654 if (!layoutObject)
2655 return LayoutRect(); 2655 return LayoutRect();
2656 2656
2657 InlineBoxPosition boxPosition = 2657 InlineBoxPosition boxPosition =
2658 computeInlineBoxPosition(position.position(), position.affinity()); 2658 computeInlineBoxPosition(position.position(), position.affinity());
2659 2659
2660 if (boxPosition.inlineBox) 2660 if (boxPosition.inlineBox)
2661 layoutObject = LineLayoutAPIShim::layoutObjectFrom( 2661 layoutObject = LineLayoutAPIShim::layoutObjectFrom(
(...skipping 1344 matching lines...) Expand 10 before | Expand all | Expand 10 after
4006 if (visiblePosition.isNull()) 4006 if (visiblePosition.isNull())
4007 return VisiblePositionInFlatTree(); 4007 return VisiblePositionInFlatTree();
4008 visiblePosition.deepEquivalent() 4008 visiblePosition.deepEquivalent()
4009 .document() 4009 .document()
4010 ->updateStyleAndLayoutIgnorePendingStylesheets(); 4010 ->updateStyleAndLayoutIgnorePendingStylesheets();
4011 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>( 4011 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>(
4012 visiblePosition.deepEquivalent(), rule); 4012 visiblePosition.deepEquivalent(), rule);
4013 } 4013 }
4014 4014
4015 } // namespace blink 4015 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698