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

Side by Side Diff: Source/core/dom/PositionIterator.cpp

Issue 1189543002: Do not traverse nodes not having a layout object while searching editable visible position. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix a crash caused by m_anchorNode being null Created 5 years, 4 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 | « no previous file | 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) 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 return PositionAlgorithm<Strategy>::createLegacyEditingPosition(m_anchorNode , m_offsetInAnchor); 64 return PositionAlgorithm<Strategy>::createLegacyEditingPosition(m_anchorNode , m_offsetInAnchor);
65 } 65 }
66 66
67 template <typename Strategy> 67 template <typename Strategy>
68 PositionAlgorithm<Strategy> PositionIteratorAlgorithm<Strategy>::computePosition () const 68 PositionAlgorithm<Strategy> PositionIteratorAlgorithm<Strategy>::computePosition () const
69 { 69 {
70 if (m_nodeAfterPositionInAnchor) { 70 if (m_nodeAfterPositionInAnchor) {
71 ASSERT(Strategy::parent(*m_nodeAfterPositionInAnchor) == m_anchorNode); 71 ASSERT(Strategy::parent(*m_nodeAfterPositionInAnchor) == m_anchorNode);
72 return PositionAlgorithm<Strategy>::inParentBeforeNode(*m_nodeAfterPosit ionInAnchor); 72 return PositionAlgorithm<Strategy>::inParentBeforeNode(*m_nodeAfterPosit ionInAnchor);
73 } 73 }
74 if (Strategy::hasChildren(*m_anchorNode)) 74 if (m_anchorNode && Strategy::hasChildren(*m_anchorNode))
yosin_UTC9 2015/07/31 06:37:01 Could you remove |m_anchorNode|? |computePosition(
75 return PositionAlgorithm<Strategy>::lastPositionInOrAfterNode(m_anchorNo de); 75 return PositionAlgorithm<Strategy>::lastPositionInOrAfterNode(m_anchorNo de);
76 if (m_anchorNode->isTextNode()) 76 if (m_anchorNode && m_anchorNode->isTextNode())
yosin_UTC9 2015/07/31 06:37:01 Could you remove |m_anchorNode|? |computePosition(
77 return PositionAlgorithm<Strategy>(m_anchorNode, m_offsetInAnchor); 77 return PositionAlgorithm<Strategy>(m_anchorNode, m_offsetInAnchor);
78 if (m_offsetInAnchor) 78 if (m_offsetInAnchor)
79 return PositionAlgorithm<Strategy>(m_anchorNode, PositionAnchorType::Aft erAnchor); 79 return PositionAlgorithm<Strategy>(m_anchorNode, PositionAnchorType::Aft erAnchor);
80 return PositionAlgorithm<Strategy>(m_anchorNode, PositionAnchorType::BeforeA nchor); 80 return PositionAlgorithm<Strategy>(m_anchorNode, PositionAnchorType::BeforeA nchor);
81 } 81 }
82 82
83 template <typename Strategy> 83 template <typename Strategy>
84 void PositionIteratorAlgorithm<Strategy>::increment() 84 void PositionIteratorAlgorithm<Strategy>::increment()
85 { 85 {
86 if (!m_anchorNode) 86 if (!m_anchorNode)
87 return; 87 return;
88 88
89 if (m_nodeAfterPositionInAnchor) { 89 if (m_nodeAfterPositionInAnchor) {
90 m_anchorNode = m_nodeAfterPositionInAnchor; 90 m_anchorNode = m_nodeAfterPositionInAnchor;
91 m_nodeAfterPositionInAnchor = Strategy::firstChild(*m_anchorNode); 91 m_nodeAfterPositionInAnchor = Strategy::firstChild(*m_anchorNode);
92 m_offsetInAnchor = 0; 92 m_offsetInAnchor = 0;
93 return; 93 return;
94 } 94 }
95 95
96 if (!Strategy::hasChildren(*m_anchorNode) && m_offsetInAnchor < Strategy::la stOffsetForEditing(m_anchorNode)) { 96 if (m_anchorNode->layoutObject() && !Strategy::hasChildren(*m_anchorNode) && m_offsetInAnchor < Strategy::lastOffsetForEditing(m_anchorNode)) {
97 m_offsetInAnchor = PositionAlgorithm<Strategy>::uncheckedNextOffset(m_an chorNode, m_offsetInAnchor); 97 m_offsetInAnchor = PositionAlgorithm<Strategy>::uncheckedNextOffset(m_an chorNode, m_offsetInAnchor);
98 } else { 98 } else {
99 m_nodeAfterPositionInAnchor = m_anchorNode; 99 m_nodeAfterPositionInAnchor = m_anchorNode;
100 m_anchorNode = Strategy::parent(*m_nodeAfterPositionInAnchor); 100 m_anchorNode = Strategy::parent(*m_nodeAfterPositionInAnchor);
101 m_nodeAfterPositionInAnchor = Strategy::nextSibling(*m_nodeAfterPosition InAnchor); 101 m_nodeAfterPositionInAnchor = Strategy::nextSibling(*m_nodeAfterPosition InAnchor);
102 m_offsetInAnchor = 0; 102 m_offsetInAnchor = 0;
103 } 103 }
104 } 104 }
105 105
106 template <typename Strategy> 106 template <typename Strategy>
(...skipping 12 matching lines...) Expand all
119 m_anchorNode = Strategy::parent(*m_nodeAfterPositionInAnchor); 119 m_anchorNode = Strategy::parent(*m_nodeAfterPositionInAnchor);
120 m_offsetInAnchor = 0; 120 m_offsetInAnchor = 0;
121 } 121 }
122 return; 122 return;
123 } 123 }
124 124
125 if (Strategy::hasChildren(*m_anchorNode)) { 125 if (Strategy::hasChildren(*m_anchorNode)) {
126 m_anchorNode = Strategy::lastChild(*m_anchorNode); 126 m_anchorNode = Strategy::lastChild(*m_anchorNode);
127 m_offsetInAnchor = Strategy::hasChildren(*m_anchorNode)? 0 : Strategy::l astOffsetForEditing(m_anchorNode); 127 m_offsetInAnchor = Strategy::hasChildren(*m_anchorNode)? 0 : Strategy::l astOffsetForEditing(m_anchorNode);
128 } else { 128 } else {
129 if (m_offsetInAnchor) { 129 if (m_offsetInAnchor && m_anchorNode->layoutObject()) {
130 m_offsetInAnchor = PositionAlgorithm<Strategy>::uncheckedPreviousOff set(m_anchorNode, m_offsetInAnchor); 130 m_offsetInAnchor = PositionAlgorithm<Strategy>::uncheckedPreviousOff set(m_anchorNode, m_offsetInAnchor);
131 } else { 131 } else {
132 m_nodeAfterPositionInAnchor = m_anchorNode; 132 m_nodeAfterPositionInAnchor = m_anchorNode;
133 m_anchorNode = Strategy::parent(*m_anchorNode); 133 m_anchorNode = Strategy::parent(*m_anchorNode);
134 } 134 }
135 } 135 }
136 } 136 }
137 137
138 template <typename Strategy> 138 template <typename Strategy>
139 bool PositionIteratorAlgorithm<Strategy>::atStart() const 139 bool PositionIteratorAlgorithm<Strategy>::atStart() const
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 return true; 172 return true;
173 if (m_nodeAfterPositionInAnchor) 173 if (m_nodeAfterPositionInAnchor)
174 return false; 174 return false;
175 return Strategy::hasChildren(*m_anchorNode) || m_offsetInAnchor >= Strategy: :lastOffsetForEditing(m_anchorNode); 175 return Strategy::hasChildren(*m_anchorNode) || m_offsetInAnchor >= Strategy: :lastOffsetForEditing(m_anchorNode);
176 } 176 }
177 177
178 template class PositionIteratorAlgorithm<EditingStrategy>; 178 template class PositionIteratorAlgorithm<EditingStrategy>;
179 template class PositionIteratorAlgorithm<EditingInComposedTreeStrategy>; 179 template class PositionIteratorAlgorithm<EditingInComposedTreeStrategy>;
180 180
181 } // namespace blink 181 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698