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

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

Issue 2229463003: Make toPositionInFlatTree() to handle a position anchored by shadow root (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-08-09T14:04:01 Created 4 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 | third_party/WebKit/Source/core/editing/PositionTest.cpp » ('j') | 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) 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 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 } 506 }
507 507
508 fprintf(stderr, "Position [%s]: %s [%p] %s at %d\n", msg, anchorNode()->node Name().utf8().data(), anchorNode(), anchorType, m_offset); 508 fprintf(stderr, "Position [%s]: %s [%p] %s at %d\n", msg, anchorNode()->node Name().utf8().data(), anchorNode(), anchorType, m_offset);
509 } 509 }
510 510
511 PositionInFlatTree toPositionInFlatTree(const Position& pos) 511 PositionInFlatTree toPositionInFlatTree(const Position& pos)
512 { 512 {
513 if (pos.isNull()) 513 if (pos.isNull())
514 return PositionInFlatTree(); 514 return PositionInFlatTree();
515 515
516 Node* const anchor = pos.anchorNode();
516 if (pos.isOffsetInAnchor()) { 517 if (pos.isOffsetInAnchor()) {
517 Node* anchor = pos.anchorNode();
518 if (anchor->isCharacterDataNode()) 518 if (anchor->isCharacterDataNode())
519 return PositionInFlatTree(anchor, pos.computeOffsetInContainerNode() ); 519 return PositionInFlatTree(anchor, pos.computeOffsetInContainerNode() );
520 DCHECK(!anchor->isSlotOrActiveInsertionPoint()); 520 DCHECK(!anchor->isSlotOrActiveInsertionPoint());
521 int offset = pos.computeOffsetInContainerNode(); 521 int offset = pos.computeOffsetInContainerNode();
522 Node* child = NodeTraversal::childAt(*anchor, offset); 522 Node* child = NodeTraversal::childAt(*anchor, offset);
523 if (!child) { 523 if (!child) {
524 if (anchor->isShadowRoot()) 524 if (anchor->isShadowRoot())
525 return PositionInFlatTree(anchor->shadowHost(), PositionAnchorTy pe::AfterChildren); 525 return PositionInFlatTree(anchor->shadowHost(), PositionAnchorTy pe::AfterChildren);
526 return PositionInFlatTree(anchor, PositionAnchorType::AfterChildren) ; 526 return PositionInFlatTree(anchor, PositionAnchorType::AfterChildren) ;
527 } 527 }
528 child->updateDistribution(); 528 child->updateDistribution();
529 if (child->isSlotOrActiveInsertionPoint()) { 529 if (child->isSlotOrActiveInsertionPoint()) {
530 if (anchor->isShadowRoot()) 530 if (anchor->isShadowRoot())
531 return PositionInFlatTree(anchor->shadowHost(), offset); 531 return PositionInFlatTree(anchor->shadowHost(), offset);
532 return PositionInFlatTree(anchor, offset); 532 return PositionInFlatTree(anchor, offset);
533 } 533 }
534 if (Node* parent = FlatTreeTraversal::parent(*child)) 534 if (Node* parent = FlatTreeTraversal::parent(*child))
535 return PositionInFlatTree(parent, FlatTreeTraversal::index(*child)); 535 return PositionInFlatTree(parent, FlatTreeTraversal::index(*child));
536 // When |pos| isn't appeared in flat tree, we map |pos| to after 536 // When |pos| isn't appeared in flat tree, we map |pos| to after
537 // children of shadow host. 537 // children of shadow host.
538 // e.g. "foo",0 in <progress>foo</progress> 538 // e.g. "foo",0 in <progress>foo</progress>
539 if (anchor->isShadowRoot()) 539 if (anchor->isShadowRoot())
540 return PositionInFlatTree(anchor->shadowHost(), PositionAnchorType:: AfterChildren); 540 return PositionInFlatTree(anchor->shadowHost(), PositionAnchorType:: AfterChildren);
541 return PositionInFlatTree(anchor, PositionAnchorType::AfterChildren); 541 return PositionInFlatTree(anchor, PositionAnchorType::AfterChildren);
542 } 542 }
543 543
544 return PositionInFlatTree(pos.anchorNode(), pos.anchorType()); 544 if (anchor->isShadowRoot())
545 return PositionInFlatTree(anchor->shadowHost(), pos.anchorType());
546 // TODO(yosin): Once we have a test case for SLOT or active insertion point,
547 // this function should handle it.
548 return PositionInFlatTree(anchor, pos.anchorType());
545 } 549 }
546 550
547 Position toPositionInDOMTree(const Position& position) 551 Position toPositionInDOMTree(const Position& position)
548 { 552 {
549 return position; 553 return position;
550 } 554 }
551 555
552 Position toPositionInDOMTree(const PositionInFlatTree& position) 556 Position toPositionInDOMTree(const PositionInFlatTree& position)
553 { 557 {
554 if (position.isNull()) 558 if (position.isNull())
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 707
704 void showTree(const blink::Position* pos) 708 void showTree(const blink::Position* pos)
705 { 709 {
706 if (pos) 710 if (pos)
707 pos->showTreeForThis(); 711 pos->showTreeForThis();
708 else 712 else
709 fprintf(stderr, "Cannot showTree for (nil)\n"); 713 fprintf(stderr, "Cannot showTree for (nil)\n");
710 } 714 }
711 715
712 #endif 716 #endif
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/PositionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698