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

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

Issue 1675163002: Rename ComposedTree to FlatTree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wip Created 4 years, 10 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, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2009 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 return child; 276 return child;
277 return Strategy::nextSkippingChildren(*m_anchorNode); 277 return Strategy::nextSkippingChildren(*m_anchorNode);
278 } 278 }
279 279
280 template <typename Strategy> 280 template <typename Strategy>
281 Node* PositionTemplate<Strategy>::commonAncestorContainer(const PositionTemplate <Strategy>& other) const 281 Node* PositionTemplate<Strategy>::commonAncestorContainer(const PositionTemplate <Strategy>& other) const
282 { 282 {
283 return Strategy::commonAncestor(*computeContainerNode(), *other.computeConta inerNode()); 283 return Strategy::commonAncestor(*computeContainerNode(), *other.computeConta inerNode());
284 } 284 }
285 285
286 int comparePositions(const PositionInComposedTree& positionA, const PositionInCo mposedTree& positionB) 286 int comparePositions(const PositionInFlatTree& positionA, const PositionInFlatTr ee& positionB)
287 { 287 {
288 ASSERT(positionA.isNotNull()); 288 ASSERT(positionA.isNotNull());
289 ASSERT(positionB.isNotNull()); 289 ASSERT(positionB.isNotNull());
290 290
291 positionA.anchorNode()->updateDistribution(); 291 positionA.anchorNode()->updateDistribution();
292 Node* containerA = positionA.computeContainerNode(); 292 Node* containerA = positionA.computeContainerNode();
293 positionB.anchorNode()->updateDistribution(); 293 positionB.anchorNode()->updateDistribution();
294 Node* containerB = positionB.computeContainerNode(); 294 Node* containerB = positionB.computeContainerNode();
295 int offsetA = positionA.computeOffsetInContainerNode(); 295 int offsetA = positionA.computeOffsetInContainerNode();
296 int offsetB = positionB.computeOffsetInContainerNode(); 296 int offsetB = positionB.computeOffsetInContainerNode();
297 return comparePositionsInComposedTree(containerA, offsetA, containerB, offse tB); 297 return comparePositionsInFlatTree(containerA, offsetA, containerB, offsetB);
298 } 298 }
299 299
300 template <typename Strategy> 300 template <typename Strategy>
301 int PositionTemplate<Strategy>::compareTo(const PositionTemplate<Strategy>& othe r) const 301 int PositionTemplate<Strategy>::compareTo(const PositionTemplate<Strategy>& othe r) const
302 { 302 {
303 return comparePositions(*this, other); 303 return comparePositions(*this, other);
304 } 304 }
305 305
306 template <typename Strategy> 306 template <typename Strategy>
307 bool PositionTemplate<Strategy>::atFirstEditingPositionForNode() const 307 bool PositionTemplate<Strategy>::atFirstEditingPositionForNode() const
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 376
377 const char* anchorType = anchorTypes[std::min(static_cast<size_t>(m_anchorTy pe), WTF_ARRAY_LENGTH(anchorTypes) - 1)]; 377 const char* anchorType = anchorTypes[std::min(static_cast<size_t>(m_anchorTy pe), WTF_ARRAY_LENGTH(anchorTypes) - 1)];
378 if (m_anchorNode->isTextNode()) { 378 if (m_anchorNode->isTextNode()) {
379 fprintf(stderr, "Position [%s]: %s [%p] %s, (%s) at %d\n", msg, anchorNo de()->nodeName().utf8().data(), anchorNode(), anchorType, m_anchorNode->nodeValu e().utf8().data(), m_offset); 379 fprintf(stderr, "Position [%s]: %s [%p] %s, (%s) at %d\n", msg, anchorNo de()->nodeName().utf8().data(), anchorNode(), anchorType, m_anchorNode->nodeValu e().utf8().data(), m_offset);
380 return; 380 return;
381 } 381 }
382 382
383 fprintf(stderr, "Position [%s]: %s [%p] %s at %d\n", msg, anchorNode()->node Name().utf8().data(), anchorNode(), anchorType, m_offset); 383 fprintf(stderr, "Position [%s]: %s [%p] %s at %d\n", msg, anchorNode()->node Name().utf8().data(), anchorNode(), anchorType, m_offset);
384 } 384 }
385 385
386 PositionInComposedTree toPositionInComposedTree(const Position& pos) 386 PositionInFlatTree toPositionInFlatTree(const Position& pos)
387 { 387 {
388 if (pos.isNull()) 388 if (pos.isNull())
389 return PositionInComposedTree(); 389 return PositionInFlatTree();
390 390
391 if (pos.isOffsetInAnchor()) { 391 if (pos.isOffsetInAnchor()) {
392 Node* anchor = pos.anchorNode(); 392 Node* anchor = pos.anchorNode();
393 if (anchor->offsetInCharacters()) 393 if (anchor->offsetInCharacters())
394 return PositionInComposedTree(anchor, pos.computeOffsetInContainerNo de()); 394 return PositionInFlatTree(anchor, pos.computeOffsetInContainerNode() );
395 ASSERT(!anchor->isSlotOrActiveInsertionPoint()); 395 ASSERT(!anchor->isSlotOrActiveInsertionPoint());
396 int offset = pos.computeOffsetInContainerNode(); 396 int offset = pos.computeOffsetInContainerNode();
397 Node* child = NodeTraversal::childAt(*anchor, offset); 397 Node* child = NodeTraversal::childAt(*anchor, offset);
398 if (!child) { 398 if (!child) {
399 if (anchor->isShadowRoot()) 399 if (anchor->isShadowRoot())
400 return PositionInComposedTree(anchor->shadowHost(), PositionAnch orType::AfterChildren); 400 return PositionInFlatTree(anchor->shadowHost(), PositionAnchorTy pe::AfterChildren);
401 return PositionInComposedTree(anchor, PositionAnchorType::AfterChild ren); 401 return PositionInFlatTree(anchor, PositionAnchorType::AfterChildren) ;
402 } 402 }
403 child->updateDistribution(); 403 child->updateDistribution();
404 if (child->isSlotOrActiveInsertionPoint()) { 404 if (child->isSlotOrActiveInsertionPoint()) {
405 if (anchor->isShadowRoot()) 405 if (anchor->isShadowRoot())
406 return PositionInComposedTree(anchor->shadowHost(), offset); 406 return PositionInFlatTree(anchor->shadowHost(), offset);
407 return PositionInComposedTree(anchor, offset); 407 return PositionInFlatTree(anchor, offset);
408 } 408 }
409 if (Node* parent = ComposedTreeTraversal::parent(*child)) 409 if (Node* parent = FlatTreeTraversal::parent(*child))
410 return PositionInComposedTree(parent, ComposedTreeTraversal::index(* child)); 410 return PositionInFlatTree(parent, FlatTreeTraversal::index(*child));
411 // When |pos| isn't appeared in composed tree, we map |pos| to after 411 // When |pos| isn't appeared in flat tree, we map |pos| to after
412 // children of shadow host. 412 // children of shadow host.
413 // e.g. "foo",0 in <progress>foo</progress> 413 // e.g. "foo",0 in <progress>foo</progress>
414 if (anchor->isShadowRoot()) 414 if (anchor->isShadowRoot())
415 return PositionInComposedTree(anchor->shadowHost(), PositionAnchorTy pe::AfterChildren); 415 return PositionInFlatTree(anchor->shadowHost(), PositionAnchorType:: AfterChildren);
416 return PositionInComposedTree(anchor, PositionAnchorType::AfterChildren) ; 416 return PositionInFlatTree(anchor, PositionAnchorType::AfterChildren);
417 } 417 }
418 418
419 return PositionInComposedTree(pos.anchorNode(), pos.anchorType()); 419 return PositionInFlatTree(pos.anchorNode(), pos.anchorType());
420 } 420 }
421 421
422 Position toPositionInDOMTree(const Position& position) 422 Position toPositionInDOMTree(const Position& position)
423 { 423 {
424 return position; 424 return position;
425 } 425 }
426 426
427 Position toPositionInDOMTree(const PositionInComposedTree& position) 427 Position toPositionInDOMTree(const PositionInFlatTree& position)
428 { 428 {
429 if (position.isNull()) 429 if (position.isNull())
430 return Position(); 430 return Position();
431 431
432 Node* anchorNode = position.anchorNode(); 432 Node* anchorNode = position.anchorNode();
433 433
434 switch (position.anchorType()) { 434 switch (position.anchorType()) {
435 case PositionAnchorType::AfterChildren: 435 case PositionAnchorType::AfterChildren:
436 // FIXME: When anchorNode is <img>, assertion fails in the constructor. 436 // FIXME: When anchorNode is <img>, assertion fails in the constructor.
437 return Position(anchorNode, PositionAnchorType::AfterChildren); 437 return Position(anchorNode, PositionAnchorType::AfterChildren);
438 case PositionAnchorType::AfterAnchor: 438 case PositionAnchorType::AfterAnchor:
439 return positionAfterNode(anchorNode); 439 return positionAfterNode(anchorNode);
440 case PositionAnchorType::BeforeChildren: 440 case PositionAnchorType::BeforeChildren:
441 return Position(anchorNode, PositionAnchorType::BeforeChildren); 441 return Position(anchorNode, PositionAnchorType::BeforeChildren);
442 case PositionAnchorType::BeforeAnchor: 442 case PositionAnchorType::BeforeAnchor:
443 return positionBeforeNode(anchorNode); 443 return positionBeforeNode(anchorNode);
444 case PositionAnchorType::OffsetInAnchor: { 444 case PositionAnchorType::OffsetInAnchor: {
445 int offset = position.offsetInContainerNode(); 445 int offset = position.offsetInContainerNode();
446 if (anchorNode->offsetInCharacters()) 446 if (anchorNode->offsetInCharacters())
447 return Position(anchorNode, offset); 447 return Position(anchorNode, offset);
448 Node* child = ComposedTreeTraversal::childAt(*anchorNode, offset); 448 Node* child = FlatTreeTraversal::childAt(*anchorNode, offset);
449 if (child) 449 if (child)
450 return Position(child->parentNode(), child->nodeIndex()); 450 return Position(child->parentNode(), child->nodeIndex());
451 if (!position.offsetInContainerNode()) 451 if (!position.offsetInContainerNode())
452 return Position(anchorNode, PositionAnchorType::BeforeChildren); 452 return Position(anchorNode, PositionAnchorType::BeforeChildren);
453 453
454 // |child| is null when the position is at the end of the children. 454 // |child| is null when the position is at the end of the children.
455 // <div>foo|</div> 455 // <div>foo|</div>
456 return Position(anchorNode, PositionAnchorType::AfterChildren); 456 return Position(anchorNode, PositionAnchorType::AfterChildren);
457 } 457 }
458 default: 458 default:
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 template <typename Strategy> 508 template <typename Strategy>
509 void PositionTemplate<Strategy>::showTreeForThis() const 509 void PositionTemplate<Strategy>::showTreeForThis() const
510 { 510 {
511 if (!anchorNode()) 511 if (!anchorNode())
512 return; 512 return;
513 anchorNode()->showTreeForThis(); 513 anchorNode()->showTreeForThis();
514 showAnchorTypeAndOffset(); 514 showAnchorTypeAndOffset();
515 } 515 }
516 516
517 template <typename Strategy> 517 template <typename Strategy>
518 void PositionTemplate<Strategy>::showTreeForThisInComposedTree() const 518 void PositionTemplate<Strategy>::showTreeForThisInFlatTree() const
519 { 519 {
520 if (!anchorNode()) 520 if (!anchorNode())
521 return; 521 return;
522 anchorNode()->showTreeForThisInComposedTree(); 522 anchorNode()->showTreeForThisInFlatTree();
523 showAnchorTypeAndOffset(); 523 showAnchorTypeAndOffset();
524 } 524 }
525 525
526 #endif 526 #endif
527 527
528 template class CORE_TEMPLATE_EXPORT PositionTemplate<EditingStrategy>; 528 template class CORE_TEMPLATE_EXPORT PositionTemplate<EditingStrategy>;
529 template class CORE_TEMPLATE_EXPORT PositionTemplate<EditingInComposedTreeStrate gy>; 529 template class CORE_TEMPLATE_EXPORT PositionTemplate<EditingInFlatTreeStrategy>;
530 530
531 } // namespace blink 531 } // namespace blink
532 532
533 #ifndef NDEBUG 533 #ifndef NDEBUG
534 534
535 void showTree(const blink::Position& pos) 535 void showTree(const blink::Position& pos)
536 { 536 {
537 pos.showTreeForThis(); 537 pos.showTreeForThis();
538 } 538 }
539 539
540 void showTree(const blink::Position* pos) 540 void showTree(const blink::Position* pos)
541 { 541 {
542 if (pos) 542 if (pos)
543 pos->showTreeForThis(); 543 pos->showTreeForThis();
544 else 544 else
545 fprintf(stderr, "Cannot showTree for (nil)\n"); 545 fprintf(stderr, "Cannot showTree for (nil)\n");
546 } 546 }
547 547
548 #endif 548 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698