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

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

Issue 2949763002: Introduce Position constructor with const Node& (Closed)
Patch Set: 2017-06-20T13:43:23 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 DCHECK(IsBeforeChildren() || IsAfterChildren()) << anchor_type_; 106 DCHECK(IsBeforeChildren() || IsAfterChildren()) << anchor_type_;
107 return; 107 return;
108 } 108 }
109 #if DCHECK_IS_ON() 109 #if DCHECK_IS_ON()
110 DCHECK(CanBeAnchorNode<Strategy>(anchor_node_.Get())) << anchor_node_; 110 DCHECK(CanBeAnchorNode<Strategy>(anchor_node_.Get())) << anchor_node_;
111 #endif 111 #endif
112 DCHECK_NE(anchor_type_, PositionAnchorType::kOffsetInAnchor); 112 DCHECK_NE(anchor_type_, PositionAnchorType::kOffsetInAnchor);
113 } 113 }
114 114
115 template <typename Strategy> 115 template <typename Strategy>
116 PositionTemplate<Strategy>::PositionTemplate(Node* anchor_node, int offset) 116 PositionTemplate<Strategy>::PositionTemplate(const Node* anchor_node,
117 : anchor_node_(anchor_node), 117 int offset)
118 : anchor_node_(const_cast<Node*>(anchor_node)),
Xiaocheng 2017/06/20 17:58:10 I'm not a fan of this... It makes code less intuit
yosin_UTC9 2017/06/21 04:27:02 Discuss offline. We agree on |Position| is constan
118 offset_(offset), 119 offset_(offset),
119 anchor_type_(PositionAnchorType::kOffsetInAnchor) { 120 anchor_type_(PositionAnchorType::kOffsetInAnchor) {
120 if (anchor_node_) 121 if (anchor_node_)
121 DCHECK_GE(offset, 0); 122 DCHECK_GE(offset, 0);
122 else 123 else
123 DCHECK_EQ(offset, 0); 124 DCHECK_EQ(offset, 0);
124 #if DCHECK_IS_ON() 125 #if DCHECK_IS_ON()
125 DCHECK(CanBeAnchorNode<Strategy>(anchor_node_.Get())) << anchor_node_; 126 DCHECK(CanBeAnchorNode<Strategy>(anchor_node_.Get())) << anchor_node_;
126 #endif 127 #endif
127 } 128 }
128 129
129 template <typename Strategy> 130 template <typename Strategy>
131 PositionTemplate<Strategy>::PositionTemplate(const Node& anchor_node,
132 int offset)
133 : PositionTemplate(&anchor_node, offset) {}
134
135 template <typename Strategy>
130 PositionTemplate<Strategy>::PositionTemplate(const PositionTemplate& other) 136 PositionTemplate<Strategy>::PositionTemplate(const PositionTemplate& other)
131 : anchor_node_(other.anchor_node_), 137 : anchor_node_(other.anchor_node_),
132 offset_(other.offset_), 138 offset_(other.offset_),
133 anchor_type_(other.anchor_type_) {} 139 anchor_type_(other.anchor_type_) {}
134 140
135 // -- 141 // --
136 142
137 template <typename Strategy> 143 template <typename Strategy>
138 Node* PositionTemplate<Strategy>::ComputeContainerNode() const { 144 Node* PositionTemplate<Strategy>::ComputeContainerNode() const {
139 if (!anchor_node_) 145 if (!anchor_node_)
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 } 710 }
705 711
706 void showTree(const blink::Position* pos) { 712 void showTree(const blink::Position* pos) {
707 if (pos) 713 if (pos)
708 pos->ShowTreeForThis(); 714 pos->ShowTreeForThis();
709 else 715 else
710 LOG(INFO) << "Cannot showTree for <null>"; 716 LOG(INFO) << "Cannot showTree for <null>";
711 } 717 }
712 718
713 #endif 719 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/Position.h ('k') | third_party/WebKit/Source/core/editing/SelectionEditor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698