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

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

Issue 1878473002: ASSERT -> DCHECK in core/editing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 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 24 matching lines...) Expand all
35 { 35 {
36 for (Node* runner = node; runner; runner = FlatTreeTraversal::parent(*runner )) { 36 for (Node* runner = node; runner; runner = FlatTreeTraversal::parent(*runner )) {
37 if (isShadowHost(runner)) 37 if (isShadowHost(runner))
38 return runner; 38 return runner;
39 } 39 }
40 return nullptr; 40 return nullptr;
41 } 41 }
42 42
43 bool isEnclosedBy(const PositionInFlatTree& position, const Node& node) 43 bool isEnclosedBy(const PositionInFlatTree& position, const Node& node)
44 { 44 {
45 ASSERT(position.isNotNull()); 45 DCHECK(position.isNotNull());
46 Node* anchorNode = position.anchorNode(); 46 Node* anchorNode = position.anchorNode();
47 if (anchorNode == node) 47 if (anchorNode == node)
48 return !position.isAfterAnchor() && !position.isBeforeAnchor(); 48 return !position.isAfterAnchor() && !position.isBeforeAnchor();
49 49
50 return FlatTreeTraversal::isDescendantOf(*anchorNode, node); 50 return FlatTreeTraversal::isDescendantOf(*anchorNode, node);
51 } 51 }
52 52
53 bool isSelectionBoundary(const Node& node) 53 bool isSelectionBoundary(const Node& node)
54 { 54 {
55 return isHTMLTextAreaElement(node) || isHTMLInputElement(node) || isHTMLSele ctElement(node); 55 return isHTMLTextAreaElement(node) || isHTMLInputElement(node) || isHTMLSele ctElement(node);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // and selection painting uses anchor nodes. 94 // and selection painting uses anchor nodes.
95 if (Node* firstChild = FlatTreeTraversal::firstChild(*shadowHost)) 95 if (Node* firstChild = FlatTreeTraversal::firstChild(*shadowHost))
96 return PositionInFlatTree::beforeNode(firstChild); 96 return PositionInFlatTree::beforeNode(firstChild);
97 return PositionInFlatTree(); 97 return PositionInFlatTree();
98 } 98 }
99 99
100 Position adjustPositionForEnd(const Position& currentPosition, Node* startContai nerNode) 100 Position adjustPositionForEnd(const Position& currentPosition, Node* startContai nerNode)
101 { 101 {
102 TreeScope& treeScope = startContainerNode->treeScope(); 102 TreeScope& treeScope = startContainerNode->treeScope();
103 103
104 ASSERT(currentPosition.computeContainerNode()->treeScope() != treeScope); 104 DCHECK(currentPosition.computeContainerNode()->treeScope() != treeScope);
105 105
106 if (Node* ancestor = treeScope.ancestorInThisScope(currentPosition.computeCo ntainerNode())) { 106 if (Node* ancestor = treeScope.ancestorInThisScope(currentPosition.computeCo ntainerNode())) {
107 if (ancestor->contains(startContainerNode)) 107 if (ancestor->contains(startContainerNode))
108 return positionAfterNode(ancestor); 108 return positionAfterNode(ancestor);
109 return positionBeforeNode(ancestor); 109 return positionBeforeNode(ancestor);
110 } 110 }
111 111
112 if (Node* lastChild = treeScope.rootNode().lastChild()) 112 if (Node* lastChild = treeScope.rootNode().lastChild())
113 return positionAfterNode(lastChild); 113 return positionAfterNode(lastChild);
114 114
(...skipping 13 matching lines...) Expand all
128 // and selection painting uses anchor nodes. 128 // and selection painting uses anchor nodes.
129 if (Node* lastChild = FlatTreeTraversal::lastChild(*shadowHost)) 129 if (Node* lastChild = FlatTreeTraversal::lastChild(*shadowHost))
130 return PositionInFlatTree::afterNode(lastChild); 130 return PositionInFlatTree::afterNode(lastChild);
131 return PositionInFlatTree(); 131 return PositionInFlatTree();
132 } 132 }
133 133
134 Position adjustPositionForStart(const Position& currentPosition, Node* endContai nerNode) 134 Position adjustPositionForStart(const Position& currentPosition, Node* endContai nerNode)
135 { 135 {
136 TreeScope& treeScope = endContainerNode->treeScope(); 136 TreeScope& treeScope = endContainerNode->treeScope();
137 137
138 ASSERT(currentPosition.computeContainerNode()->treeScope() != treeScope); 138 DCHECK(currentPosition.computeContainerNode()->treeScope() == treeScope);
yosin_UTC9 2016/04/12 01:45:23 s/==/!=/ This is the reason of webkit_unit_tests
kotenkov 2016/04/12 06:05:24 Thanks for catching this!
139 139
140 if (Node* ancestor = treeScope.ancestorInThisScope(currentPosition.computeCo ntainerNode())) { 140 if (Node* ancestor = treeScope.ancestorInThisScope(currentPosition.computeCo ntainerNode())) {
141 if (ancestor->contains(endContainerNode)) 141 if (ancestor->contains(endContainerNode))
142 return positionBeforeNode(ancestor); 142 return positionBeforeNode(ancestor);
143 return positionAfterNode(ancestor); 143 return positionAfterNode(ancestor);
144 } 144 }
145 145
146 if (Node* firstChild = treeScope.rootNode().firstChild()) 146 if (Node* firstChild = treeScope.rootNode().firstChild())
147 return positionBeforeNode(firstChild); 147 return positionBeforeNode(firstChild);
148 148
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 selection->m_start = position2; 224 selection->m_start = position2;
225 selection->m_end = position1; 225 selection->m_end = position1;
226 } 226 }
227 selection->updateSelectionType(); 227 selection->updateSelectionType();
228 selection->didChange(); 228 selection->didChange();
229 } 229 }
230 230
231 void SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries(VisibleSe lection* selection) 231 void SelectionAdjuster::adjustSelectionToAvoidCrossingShadowBoundaries(VisibleSe lection* selection)
232 { 232 {
233 // Note: |m_selectionType| isn't computed yet. 233 // Note: |m_selectionType| isn't computed yet.
234 ASSERT(selection->base().isNotNull()); 234 DCHECK(selection->base().isNotNull());
235 ASSERT(selection->extent().isNotNull()); 235 DCHECK(selection->extent().isNotNull());
236 ASSERT(selection->start().isNotNull()); 236 DCHECK(selection->start().isNotNull());
237 ASSERT(selection->end().isNotNull()); 237 DCHECK(selection->end().isNotNull());
238 238
239 // TODO(hajimehoshi): Checking treeScope is wrong when a node is 239 // TODO(hajimehoshi): Checking treeScope is wrong when a node is
240 // distributed, but we leave it as it is for backward compatibility. 240 // distributed, but we leave it as it is for backward compatibility.
241 if (selection->start().anchorNode()->treeScope() == selection->end().anchorN ode()->treeScope()) 241 if (selection->start().anchorNode()->treeScope() == selection->end().anchorN ode()->treeScope())
242 return; 242 return;
243 243
244 if (selection->isBaseFirst()) { 244 if (selection->isBaseFirst()) {
245 const Position& newEnd = adjustPositionForEnd(selection->end(), selectio n->start().computeContainerNode()); 245 const Position& newEnd = adjustPositionForEnd(selection->end(), selectio n->start().computeContainerNode());
246 selection->m_extent = newEnd; 246 selection->m_extent = newEnd;
247 selection->m_end = newEnd; 247 selection->m_end = newEnd;
(...skipping 22 matching lines...) Expand all
270 selection->m_end = newEnd; 270 selection->m_end = newEnd;
271 return; 271 return;
272 } 272 }
273 Node* const shadowHost = shadowHostEnd ? shadowHostEnd : shadowHostStart; 273 Node* const shadowHost = shadowHostEnd ? shadowHostEnd : shadowHostStart;
274 const PositionInFlatTree& newStart = adjustPositionInFlatTreeForStart(select ion->start(), shadowHost); 274 const PositionInFlatTree& newStart = adjustPositionInFlatTreeForStart(select ion->start(), shadowHost);
275 selection->m_extent = newStart; 275 selection->m_extent = newStart;
276 selection->m_start = newStart; 276 selection->m_start = newStart;
277 } 277 }
278 278
279 } // namespace blink 279 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698