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

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

Issue 2728493002: Re-format PositionIterator.cpp to be PRESUBMIT friendly (Closed)
Patch Set: Created 3 years, 9 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 ? 0 266 ? 0
267 : Strategy::lastOffsetForEditing(m_anchorNode); 267 : Strategy::lastOffsetForEditing(m_anchorNode);
268 // Decrement depth initializing with -1 because 268 // Decrement depth initializing with -1 because
269 // |m_nodeAfterPositionInAnchor| is null so still unneeded. 269 // |m_nodeAfterPositionInAnchor| is null so still unneeded.
270 if (m_depthToAnchorNode >= m_offsetsInAnchorNode.size()) 270 if (m_depthToAnchorNode >= m_offsetsInAnchorNode.size())
271 m_offsetsInAnchorNode.push_back(kInvalidOffset); 271 m_offsetsInAnchorNode.push_back(kInvalidOffset);
272 else 272 else
273 m_offsetsInAnchorNode[m_depthToAnchorNode] = kInvalidOffset; 273 m_offsetsInAnchorNode[m_depthToAnchorNode] = kInvalidOffset;
274 ++m_depthToAnchorNode; 274 ++m_depthToAnchorNode;
275 return; 275 return;
276 } else {
277 if (m_offsetInAnchor && m_anchorNode->layoutObject()) {
278 // Case #3-a. This is a reverse of increment()::Case#2.
279 // In this case |anchor| is a leaf(E,F,C,G or H) and
280 // |m_offsetInAnchor| is not on the beginning of |anchor|.
281 // Then just decrement |m_offsetInAnchor|.
282 m_offsetInAnchor =
283 previousGraphemeBoundaryOf(m_anchorNode, m_offsetInAnchor);
284 return;
285 } else {
286 // Case #3-b. This is a reverse of increment()::Case#1.
287 // In this case |anchor| is a leaf(E,F,C,G or H) and
288 // |m_offsetInAnchor| is on the beginning of |anchor|.
289 // Let |anchor| is E,
290 // next |anchor| is B and |child| is E.
291 m_nodeAfterPositionInAnchor = m_anchorNode;
292 m_anchorNode = Strategy::parent(*m_anchorNode);
293 if (!m_anchorNode)
294 return;
295 DCHECK_GT(m_depthToAnchorNode, 0u);
296 --m_depthToAnchorNode;
297 if (m_offsetsInAnchorNode[m_depthToAnchorNode] == kInvalidOffset)
298 m_offsetsInAnchorNode[m_depthToAnchorNode] =
299 Strategy::index(*m_nodeAfterPositionInAnchor);
300 }
301 } 276 }
277
278 if (m_offsetInAnchor && m_anchorNode->layoutObject()) {
279 // Case #3-a. This is a reverse of increment()::Case#2.
280 // In this case |anchor| is a leaf(E,F,C,G or H) and
281 // |m_offsetInAnchor| is not on the beginning of |anchor|.
282 // Then just decrement |m_offsetInAnchor|.
283 m_offsetInAnchor =
284 previousGraphemeBoundaryOf(m_anchorNode, m_offsetInAnchor);
285 return;
286 }
287 // Case #3-b. This is a reverse of increment()::Case#1.
288 // In this case |anchor| is a leaf(E,F,C,G or H) and
289 // |m_offsetInAnchor| is on the beginning of |anchor|.
290 // Let |anchor| is E,
291 // next |anchor| is B and |child| is E.
292 m_nodeAfterPositionInAnchor = m_anchorNode;
293 m_anchorNode = Strategy::parent(*m_anchorNode);
294 if (!m_anchorNode)
295 return;
296 DCHECK_GT(m_depthToAnchorNode, 0u);
297 --m_depthToAnchorNode;
298 if (m_offsetsInAnchorNode[m_depthToAnchorNode] != kInvalidOffset)
299 return;
300 m_offsetsInAnchorNode[m_depthToAnchorNode] =
301 Strategy::index(*m_nodeAfterPositionInAnchor);
302 } 302 }
303 303
304 template <typename Strategy> 304 template <typename Strategy>
305 bool PositionIteratorAlgorithm<Strategy>::atStart() const { 305 bool PositionIteratorAlgorithm<Strategy>::atStart() const {
306 DCHECK(isValid()); 306 DCHECK(isValid());
307 if (!m_anchorNode) 307 if (!m_anchorNode)
308 return true; 308 return true;
309 if (Strategy::parent(*m_anchorNode)) 309 if (Strategy::parent(*m_anchorNode))
310 return false; 310 return false;
311 return (!Strategy::hasChildren(*m_anchorNode) && !m_offsetInAnchor) || 311 return (!Strategy::hasChildren(*m_anchorNode) && !m_offsetInAnchor) ||
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 if (m_nodeAfterPositionInAnchor) 343 if (m_nodeAfterPositionInAnchor)
344 return false; 344 return false;
345 return Strategy::hasChildren(*m_anchorNode) || 345 return Strategy::hasChildren(*m_anchorNode) ||
346 m_offsetInAnchor >= Strategy::lastOffsetForEditing(m_anchorNode); 346 m_offsetInAnchor >= Strategy::lastOffsetForEditing(m_anchorNode);
347 } 347 }
348 348
349 template class PositionIteratorAlgorithm<EditingStrategy>; 349 template class PositionIteratorAlgorithm<EditingStrategy>;
350 template class PositionIteratorAlgorithm<EditingInFlatTreeStrategy>; 350 template class PositionIteratorAlgorithm<EditingInFlatTreeStrategy>;
351 351
352 } // namespace blink 352 } // 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