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

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

Issue 2950053002: Make Position::BeforeNode() to take const Node& instead of Node* (Closed)
Patch Set: 2017-06-21T17:56:36 Created 3 years, 6 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 return PositionTemplate<Strategy>(anchor_node, 80 return PositionTemplate<Strategy>(anchor_node,
81 PositionAnchorType::kBeforeAnchor); 81 PositionAnchorType::kBeforeAnchor);
82 82
83 // Note: |offset| can be >= 1, if |anchorNode| have child nodes, e.g. 83 // Note: |offset| can be >= 1, if |anchorNode| have child nodes, e.g.
84 // using Node.appendChild() to add a child node TEXTAREA. 84 // using Node.appendChild() to add a child node TEXTAREA.
85 DCHECK_GE(offset, 1); 85 DCHECK_GE(offset, 1);
86 return PositionTemplate<Strategy>(anchor_node, 86 return PositionTemplate<Strategy>(anchor_node,
87 PositionAnchorType::kAfterAnchor); 87 PositionAnchorType::kAfterAnchor);
88 } 88 }
89 89
90 // TODO(editing-dev): Once we change type of |anchor_node_| to
91 // |Member<const Node>|, we should get rid of |const_cast<Node*>()|.
92 // See http://crbug.com/735327
90 template <typename Strategy> 93 template <typename Strategy>
91 PositionTemplate<Strategy>::PositionTemplate(Node* anchor_node, 94 PositionTemplate<Strategy>::PositionTemplate(const Node* anchor_node,
92 PositionAnchorType anchor_type) 95 PositionAnchorType anchor_type)
93 : anchor_node_(anchor_node), offset_(0), anchor_type_(anchor_type) { 96 : anchor_node_(const_cast<Node*>(anchor_node)),
97 offset_(0),
98 anchor_type_(anchor_type) {
94 if (!anchor_node_) { 99 if (!anchor_node_) {
95 anchor_type_ = PositionAnchorType::kOffsetInAnchor; 100 anchor_type_ = PositionAnchorType::kOffsetInAnchor;
96 return; 101 return;
97 } 102 }
98 if (anchor_node_->IsTextNode()) { 103 if (anchor_node_->IsTextNode()) {
99 DCHECK(anchor_type_ == PositionAnchorType::kBeforeAnchor || 104 DCHECK(anchor_type_ == PositionAnchorType::kBeforeAnchor ||
100 anchor_type_ == PositionAnchorType::kAfterAnchor); 105 anchor_type_ == PositionAnchorType::kAfterAnchor);
101 return; 106 return;
102 } 107 }
103 if (anchor_node_->IsDocumentNode()) { 108 if (anchor_node_->IsDocumentNode()) {
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 PositionTemplate<Strategy> PositionTemplate<Strategy>::InParentAfterNode( 459 PositionTemplate<Strategy> PositionTemplate<Strategy>::InParentAfterNode(
455 const Node& node) { 460 const Node& node) {
456 DCHECK(node.parentNode()) << node; 461 DCHECK(node.parentNode()) << node;
457 return PositionTemplate<Strategy>(Strategy::Parent(node), 462 return PositionTemplate<Strategy>(Strategy::Parent(node),
458 Strategy::Index(node) + 1); 463 Strategy::Index(node) + 1);
459 } 464 }
460 465
461 // static 466 // static
462 template <typename Strategy> 467 template <typename Strategy>
463 PositionTemplate<Strategy> PositionTemplate<Strategy>::BeforeNode( 468 PositionTemplate<Strategy> PositionTemplate<Strategy>::BeforeNode(
464 Node* anchor_node) { 469 const Node& anchor_node) {
465 DCHECK(anchor_node); 470 return PositionTemplate<Strategy>(&anchor_node,
466 return PositionTemplate<Strategy>(anchor_node,
467 PositionAnchorType::kBeforeAnchor); 471 PositionAnchorType::kBeforeAnchor);
468 } 472 }
469 473
470 // static 474 // static
471 template <typename Strategy> 475 template <typename Strategy>
472 PositionTemplate<Strategy> PositionTemplate<Strategy>::AfterNode( 476 PositionTemplate<Strategy> PositionTemplate<Strategy>::AfterNode(
473 Node* anchor_node) { 477 Node* anchor_node) {
474 DCHECK(anchor_node); 478 DCHECK(anchor_node);
475 return PositionTemplate<Strategy>(anchor_node, 479 return PositionTemplate<Strategy>(anchor_node,
476 PositionAnchorType::kAfterAnchor); 480 PositionAnchorType::kAfterAnchor);
(...skipping 27 matching lines...) Expand all
504 return PositionTemplate<Strategy>(anchor_node, 508 return PositionTemplate<Strategy>(anchor_node,
505 PositionAnchorType::kAfterChildren); 509 PositionAnchorType::kAfterChildren);
506 } 510 }
507 511
508 // static 512 // static
509 template <typename Strategy> 513 template <typename Strategy>
510 PositionTemplate<Strategy> 514 PositionTemplate<Strategy>
511 PositionTemplate<Strategy>::FirstPositionInOrBeforeNode(Node* node) { 515 PositionTemplate<Strategy>::FirstPositionInOrBeforeNode(Node* node) {
512 if (!node) 516 if (!node)
513 return PositionTemplate<Strategy>(); 517 return PositionTemplate<Strategy>();
514 return EditingIgnoresContent(*node) ? BeforeNode(node) 518 return EditingIgnoresContent(*node) ? BeforeNode(*node)
515 : FirstPositionInNode(node); 519 : FirstPositionInNode(node);
516 } 520 }
517 521
518 // static 522 // static
519 template <typename Strategy> 523 template <typename Strategy>
520 PositionTemplate<Strategy> 524 PositionTemplate<Strategy>
521 PositionTemplate<Strategy>::LastPositionInOrAfterNode(Node* node) { 525 PositionTemplate<Strategy>::LastPositionInOrAfterNode(Node* node) {
522 if (!node) 526 if (!node)
523 return PositionTemplate<Strategy>(); 527 return PositionTemplate<Strategy>();
524 return EditingIgnoresContent(*node) ? AfterNode(node) 528 return EditingIgnoresContent(*node) ? AfterNode(node)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 594
591 switch (position.AnchorType()) { 595 switch (position.AnchorType()) {
592 case PositionAnchorType::kAfterChildren: 596 case PositionAnchorType::kAfterChildren:
593 // FIXME: When anchorNode is <img>, assertion fails in the constructor. 597 // FIXME: When anchorNode is <img>, assertion fails in the constructor.
594 return Position(anchor_node, PositionAnchorType::kAfterChildren); 598 return Position(anchor_node, PositionAnchorType::kAfterChildren);
595 case PositionAnchorType::kAfterAnchor: 599 case PositionAnchorType::kAfterAnchor:
596 return Position::AfterNode(anchor_node); 600 return Position::AfterNode(anchor_node);
597 case PositionAnchorType::kBeforeChildren: 601 case PositionAnchorType::kBeforeChildren:
598 return Position(anchor_node, PositionAnchorType::kBeforeChildren); 602 return Position(anchor_node, PositionAnchorType::kBeforeChildren);
599 case PositionAnchorType::kBeforeAnchor: 603 case PositionAnchorType::kBeforeAnchor:
600 return Position::BeforeNode(anchor_node); 604 return Position::BeforeNode(*anchor_node);
601 case PositionAnchorType::kOffsetInAnchor: { 605 case PositionAnchorType::kOffsetInAnchor: {
602 int offset = position.OffsetInContainerNode(); 606 int offset = position.OffsetInContainerNode();
603 if (anchor_node->IsCharacterDataNode()) 607 if (anchor_node->IsCharacterDataNode())
604 return Position(anchor_node, offset); 608 return Position(anchor_node, offset);
605 Node* child = FlatTreeTraversal::ChildAt(*anchor_node, offset); 609 Node* child = FlatTreeTraversal::ChildAt(*anchor_node, offset);
606 if (child) 610 if (child)
607 return Position(child->parentNode(), child->NodeIndex()); 611 return Position(child->parentNode(), child->NodeIndex());
608 if (!position.OffsetInContainerNode()) 612 if (!position.OffsetInContainerNode())
609 return Position(anchor_node, PositionAnchorType::kBeforeChildren); 613 return Position(anchor_node, PositionAnchorType::kBeforeChildren);
610 614
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 } 715 }
712 716
713 void showTree(const blink::Position* pos) { 717 void showTree(const blink::Position* pos) {
714 if (pos) 718 if (pos)
715 pos->ShowTreeForThis(); 719 pos->ShowTreeForThis();
716 else 720 else
717 LOG(INFO) << "Cannot showTree for <null>"; 721 LOG(INFO) << "Cannot showTree for <null>";
718 } 722 }
719 723
720 #endif 724 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/Position.h ('k') | third_party/WebKit/Source/core/editing/PositionIterator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698